*
* @author Michael Vorburger
*/
-public abstract class AbstractActionInfoList {
-
+public class ActionInfoList {
private final List<ActionInfo> actionInfos = new ArrayList<>();
- protected AbstractActionInfoList(List<ActionInfo> actionInfos) {
- super();
+ public ActionInfoList(List<ActionInfo> actionInfos) {
if (actionInfos != null) {
this.actionInfos.addAll(actionInfos);
}
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
- AbstractActionInfoList that = (AbstractActionInfoList) o;
+ ActionInfoList that = (ActionInfoList) o;
return actionInfos != null ? actionInfos.equals(that.actionInfos) : that.actionInfos == null;
}
public int hashCode() {
return actionInfos != null ? actionInfos.hashCode() : 0;
}
+
+ @Override
+ public String toString() {
+ return "ActionInfoList" + actionInfos.toString();
+ }
}
import java.util.Objects;
import org.opendaylight.yangtools.util.EvenMoreObjects;
-public class BucketInfo extends AbstractActionInfoList implements Serializable {
+public class BucketInfo extends ActionInfoList implements Serializable {
private static final long serialVersionUID = 1L;
*/
package org.opendaylight.genius.mdsalutil;
-import com.google.common.base.MoreObjects;
import java.io.Serializable;
-import java.math.BigInteger;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Objects;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
-import org.opendaylight.yangtools.util.EvenMoreObjects;
-public class InstructionInfo extends AbstractActionInfoList implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private final InstructionType m_instructionType;
- private final long[] m_alInstructionValues;
- private final BigInteger[] m_alBigInstructionValues;
-
- // This constructor should be used incase of clearAction
- @Deprecated
- public InstructionInfo(InstructionType instructionType) {
- super(null);
- m_instructionType = instructionType;
- m_alInstructionValues = null;
- m_alBigInstructionValues = null;
- }
-
- @Deprecated
- public InstructionInfo(InstructionType instructionType, long[] instructionValues) {
- super(null);
- m_instructionType = instructionType;
- m_alInstructionValues = instructionValues;
- m_alBigInstructionValues = null;
- }
-
- @Deprecated
- public InstructionInfo(InstructionType instructionType, BigInteger[] instructionValues) {
- super(null);
- m_instructionType = instructionType;
- m_alInstructionValues = null;
- m_alBigInstructionValues = instructionValues;
- }
-
- @Deprecated
- public InstructionInfo(InstructionType instructionType, List<ActionInfo> actionInfos) {
- super(actionInfos);
- m_instructionType = instructionType;
- m_alInstructionValues = null;
- m_alBigInstructionValues = null;
- }
-
- public Instruction buildInstruction(int instructionKey) {
- return m_instructionType.buildInstruction(this, instructionKey);
- }
-
- public InstructionType getInstructionType() {
- return m_instructionType;
- }
-
- public long[] getInstructionValues() {
- return m_alInstructionValues;
- }
-
- public BigInteger[] getBigInstructionValues() {
- return m_alBigInstructionValues;
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(this).omitNullValues().add("instructionType", m_instructionType)
- .add("instructionValues", Arrays.toString(m_alInstructionValues))
- .add("bigInstructionValues", Arrays.deepToString(m_alBigInstructionValues))
- .add("actionInfos", getActionInfos()).toString();
- }
-
- @Override
- public int hashCode() {
- // BEWARE, Caveat Emptor: Array ([]) type fields must use
- // Arrays.hashCode(). deepHashCode() would have to be used for nested
- // arrays.
- return Objects.hash(m_instructionType, Arrays.hashCode(m_alInstructionValues),
- Arrays.hashCode(m_alBigInstructionValues), getActionInfos());
- }
-
- @Override
- public boolean equals(Object obj) {
- // BEWARE, Caveat Emptor: Array ([]) type fields must use
- // Arrays.equals(). deepEquals() would have to be used for nested
- // arrays. Use == only for primitive types; if ever changing
- // those field types, must change to Objects.equals.
- return EvenMoreObjects.equalsHelper(this, obj,
- (self, other) -> Objects.equals(self.m_instructionType, other.m_instructionType)
- && Arrays.equals(self.m_alInstructionValues, other.m_alInstructionValues)
- && Arrays.equals(self.m_alBigInstructionValues, other.m_alBigInstructionValues)
- && Objects.equals(self.getActionInfos(), other.getActionInfos()));
- }
+public interface InstructionInfo extends Serializable {
+ Instruction buildInstruction(int instructionKey);
}
+++ /dev/null
-/*
- * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.genius.mdsalutil;
-
-import org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions;
-import org.opendaylight.genius.mdsalutil.instructions.InstructionClearActions;
-import org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable;
-import org.opendaylight.genius.mdsalutil.instructions.InstructionWriteActions;
-import org.opendaylight.genius.mdsalutil.instructions.InstructionWriteMetadata;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
-
-@Deprecated
-public enum InstructionType {
- @Deprecated
- apply_actions {
- @Override
- public Instruction buildInstruction(InstructionInfo instructionInfo, int instructionKey) {
- return new InstructionApplyActions(instructionInfo.getActionInfos()).buildInstruction(instructionKey);
- }
- },
-
- @Deprecated
- goto_table {
- @Override
- public Instruction buildInstruction(InstructionInfo instructionInfo, int instructionKey) {
- return new InstructionGotoTable((short) instructionInfo.getInstructionValues()[0]).buildInstruction(
- instructionKey);
- }
- },
-
- @Deprecated
- write_actions {
- @Override
- public Instruction buildInstruction(InstructionInfo instructionInfo, int instructionKey) {
- return new InstructionWriteActions(instructionInfo.getActionInfos()).buildInstruction(instructionKey);
- }
- },
-
- @Deprecated
- clear_actions {
- @Override
- public Instruction buildInstruction(InstructionInfo instructionInfo, int instructionKey) {
- return new InstructionClearActions().buildInstruction(instructionKey);
- }
- },
-
- @Deprecated
- write_metadata {
- @Override
- public Instruction buildInstruction(InstructionInfo instructionInfo, int instructionKey) {
- return new InstructionWriteMetadata(instructionInfo.getBigInstructionValues()[0],
- instructionInfo.getBigInstructionValues()[1]).buildInstruction(instructionKey);
- }
- };
-
- @Deprecated
- public abstract Instruction buildInstruction(InstructionInfo instructionInfo, int instructionKey);
-}
package org.opendaylight.genius.mdsalutil.instructions;
import java.util.List;
+import org.opendaylight.genius.mdsalutil.ActionInfoList;
import org.opendaylight.genius.mdsalutil.ActionInfo;
import org.opendaylight.genius.mdsalutil.InstructionInfo;
-import org.opendaylight.genius.mdsalutil.InstructionType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
/**
* Apply actions instruction.
*/
-public class InstructionApplyActions extends InstructionInfo {
+public class InstructionApplyActions implements InstructionInfo {
+ private final ActionInfoList actions;
+
public InstructionApplyActions(List<ActionInfo> actionsInfos) {
- super(InstructionType.apply_actions, actionsInfos);
+ this.actions = new ActionInfoList(actionsInfos);
}
@Override
return new InstructionBuilder()
.setInstruction(new ApplyActionsCaseBuilder()
.setApplyActions(new ApplyActionsBuilder()
- .setAction(buildActions())
+ .setAction(actions.buildActions())
.build()
)
.build()
.setKey(new InstructionKey(instructionKey))
.build();
}
+
+ public List<ActionInfo> getActionInfos() {
+ return actions.getActionInfos();
+ }
}
package org.opendaylight.genius.mdsalutil.instructions;
import org.opendaylight.genius.mdsalutil.InstructionInfo;
-import org.opendaylight.genius.mdsalutil.InstructionType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
/**
* Clear actions instruction.
*/
-public class InstructionClearActions extends InstructionInfo {
- public InstructionClearActions() {
- super(InstructionType.clear_actions);
- }
-
+public class InstructionClearActions implements InstructionInfo {
@Override
public Instruction buildInstruction(int instructionKey) {
return new InstructionBuilder()
package org.opendaylight.genius.mdsalutil.instructions;
import org.opendaylight.genius.mdsalutil.InstructionInfo;
-import org.opendaylight.genius.mdsalutil.InstructionType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
/**
* Goto table instruction.
*/
-public class InstructionGotoTable extends InstructionInfo {
+public class InstructionGotoTable implements InstructionInfo {
private final short tableId;
public InstructionGotoTable(short tableId) {
- super(InstructionType.goto_table, new long[] {tableId});
this.tableId = tableId;
}
import java.util.List;
import org.opendaylight.genius.mdsalutil.ActionInfo;
+import org.opendaylight.genius.mdsalutil.ActionInfoList;
import org.opendaylight.genius.mdsalutil.InstructionInfo;
-import org.opendaylight.genius.mdsalutil.InstructionType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActionsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
/**
* Write actions instruction.
*/
-public class InstructionWriteActions extends InstructionInfo {
+public class InstructionWriteActions implements InstructionInfo {
+ private final ActionInfoList actions;
+
public InstructionWriteActions(List<ActionInfo> actionInfos) {
- super(InstructionType.write_actions, actionInfos);
+ this.actions = new ActionInfoList(actionInfos);
}
@Override
return new InstructionBuilder()
.setInstruction(new WriteActionsCaseBuilder()
.setWriteActions(new WriteActionsBuilder()
- .setAction(buildActions())
+ .setAction(actions.buildActions())
.build()
)
.build()
import java.math.BigInteger;
import org.opendaylight.genius.mdsalutil.InstructionInfo;
-import org.opendaylight.genius.mdsalutil.InstructionType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadataBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
/**
* Write metadata instruction.
*/
-public class InstructionWriteMetadata extends InstructionInfo {
+public class InstructionWriteMetadata implements InstructionInfo {
private final BigInteger metadata;
private final BigInteger mask;
public InstructionWriteMetadata(BigInteger metadata, BigInteger mask) {
- super(InstructionType.write_metadata, new BigInteger[] {metadata, mask});
this.metadata = metadata;
this.mask = mask;
}
import java.util.List;
import org.junit.Test;
import org.opendaylight.genius.mdsalutil.InstructionInfo;
-import org.opendaylight.genius.mdsalutil.InstructionType;
import org.opendaylight.genius.mdsalutil.actions.ActionGroup;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
* Test for {@link InstructionApplyActions}.
*/
public class InstructionApplyActionsTest {
- @Test
- public void backwardsCompatibleInstruction() {
- verifyInstructionInfo(
- new InstructionInfo(InstructionType.apply_actions, Collections.singletonList(new ActionGroup(1L))));
- }
-
@Test
public void newInstruction() {
verifyInstructionInfo(new InstructionApplyActions(Collections.singletonList(new ActionGroup(1L))));
import org.junit.Test;
import org.opendaylight.genius.mdsalutil.InstructionInfo;
-import org.opendaylight.genius.mdsalutil.InstructionType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
* Test for {@link InstructionClearActions}.
*/
public class InstructionClearActionsTest {
- @Test
- public void backwardsCompatibleInstruction() {
- verifyInstructionInfo(new InstructionInfo(InstructionType.clear_actions));
- }
-
@Test
public void newInstruction() {
verifyInstructionInfo(new InstructionClearActions());
import org.junit.Test;
import org.opendaylight.genius.mdsalutil.InstructionInfo;
-import org.opendaylight.genius.mdsalutil.InstructionType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
* Test for {@link InstructionGotoTable}.
*/
public class InstructionGotoTableTest {
- @Test
- public void backwardsCompatibleInstruction() {
- verifyInstructionInfo(new InstructionInfo(InstructionType.goto_table, new long[] {1L}));
- }
-
@Test
public void newInstruction() {
verifyInstructionInfo(new InstructionGotoTable((short) 1));
import java.util.List;
import org.junit.Test;
import org.opendaylight.genius.mdsalutil.InstructionInfo;
-import org.opendaylight.genius.mdsalutil.InstructionType;
import org.opendaylight.genius.mdsalutil.actions.ActionGroup;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
* Test for {@link InstructionWriteActions}.
*/
public class InstructionWriteActionsTest {
- @Test
- public void backwardsCompatibleInstruction() {
- verifyInstructionInfo(
- new InstructionInfo(InstructionType.write_actions, Collections.singletonList(new ActionGroup(1L))));
- }
-
@Test
public void newInstruction() {
verifyInstructionInfo(new InstructionWriteActions(Collections.singletonList(new ActionGroup(1L))));
import java.math.BigInteger;
import org.junit.Test;
import org.opendaylight.genius.mdsalutil.InstructionInfo;
-import org.opendaylight.genius.mdsalutil.InstructionType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadata;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
* Test for {@link InstructionWriteMetadata}.
*/
public class InstructionWriteMetadataTest {
- @Test
- public void backwardsCompatibleInstruction() {
- verifyInstructionInfo(
- new InstructionInfo(InstructionType.write_metadata, new BigInteger[] {BigInteger.ONE, BigInteger.TEN}));
- }
-
@Test
public void newInstruction() {
verifyInstructionInfo(new InstructionWriteMetadata(BigInteger.ONE, BigInteger.TEN));
List<ActionInfo> actionInfos = new ArrayList<>();
actionInfos.add(actionInfo);
flowEntity.getInstructionInfoList().add(new InstructionApplyActions(actionInfos));
- assertEquals(27, flowEntity.getInstructionInfoList().get(0).getActionInfos().get(0).getActionKey());
+ assertEquals(27, ((InstructionApplyActions) flowEntity.getInstructionInfoList().get(0)).getActionInfos().get(
+ 0).getActionKey());
flowEntity.getFlowBuilder();
- assertEquals(27, flowEntity.getInstructionInfoList().get(0).getActionInfos().get(0).getActionKey());
+ assertEquals(27, ((InstructionApplyActions) flowEntity.getInstructionInfoList().get(0)).getActionInfos().get(
+ 0).getActionKey());
flowEntity.getFlowBuilder();
- assertEquals(27, flowEntity.getInstructionInfoList().get(0).getActionInfos().get(0).getActionKey());
+ assertEquals(27, ((InstructionApplyActions) flowEntity.getInstructionInfoList().get(0)).getActionInfos().get(
+ 0).getActionKey());
}
}