ONOS-958: Add a Group action to TrafficTreatment subsystem.
Change-Id: I2a377508b9721ee96a5a52b0bb2ed3a960c982ce
diff --git a/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java b/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java
index 90f8c4e..6b5af75 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java
@@ -20,6 +20,7 @@
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
+import org.onosproject.core.GroupId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.flow.instructions.Instructions;
@@ -241,6 +242,11 @@
}
@Override
+ public Builder group(GroupId groupId) {
+ return add(Instructions.createGroup(groupId));
+ }
+
+ @Override
public TrafficTreatment build() {
//If we are dropping should we just return an empty list?
diff --git a/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java b/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
index da682ee..91edcbf 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java
@@ -17,6 +17,7 @@
import java.util.List;
+import org.onosproject.core.GroupId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.instructions.Instruction;
import org.onlab.packet.IpAddress;
@@ -185,6 +186,14 @@
public Builder setLambda(short lambda);
/**
+ * Sets the group ID.
+ *
+ * @param groupId group ID
+ * @return a treatment builder
+ */
+ public Builder group(GroupId groupId);
+
+ /**
* Builds an immutable traffic treatment descriptor.
*
* @return traffic treatment
diff --git a/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java b/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
index 6f1281f..df4a695 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java
@@ -21,6 +21,7 @@
import java.util.Objects;
+import org.onosproject.core.GroupId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.instructions.L0ModificationInstruction.L0SubType;
import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction;
@@ -65,6 +66,17 @@
}
/**
+ * Creates a group instruction.
+ *
+ * @param groupId Group Id
+ * @return group instruction
+ */
+ public static GroupInstruction createGroup(final GroupId groupId) {
+ checkNotNull(groupId, "GroupId cannot be null");
+ return new GroupInstruction(groupId);
+ }
+
+ /**
* Creates a l0 modification.
* @param lambda the lambda to modify to.
* @return a l0 modification
@@ -207,7 +219,7 @@
}
/*
- * Output instructions
+ * Drop instructions
*/
public static final class DropInstruction implements Instruction {
@@ -241,6 +253,9 @@
}
}
+ /*
+ * Output Instruction
+ */
public static final class OutputInstruction implements Instruction {
private final PortNumber port;
@@ -282,6 +297,50 @@
}
}
+ /*
+ * Group Instruction
+ */
+
+ public static final class GroupInstruction implements Instruction {
+ private final GroupId groupId;
+
+ private GroupInstruction(GroupId groupId) {
+ this.groupId = groupId;
+ }
+
+ public GroupId groupId() {
+ return groupId;
+ }
+
+ @Override
+ public Type type() {
+ return Type.GROUP;
+ }
+ @Override
+ public String toString() {
+ return toStringHelper(type().toString())
+ .add("group ID", groupId.id()).toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(type(), groupId);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof GroupInstruction) {
+ GroupInstruction that = (GroupInstruction) obj;
+ return Objects.equals(groupId, that.groupId);
+
+ }
+ return false;
+ }
+ }
+
}
diff --git a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowEntryBuilder.java b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowEntryBuilder.java
index 5b0e1ef..5c445a8 100644
--- a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowEntryBuilder.java
+++ b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowEntryBuilder.java
@@ -22,6 +22,7 @@
import org.onlab.packet.Ip6Prefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
+import org.onosproject.core.DefaultGroupId;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.DefaultFlowEntry;
@@ -39,14 +40,10 @@
import org.projectfloodlight.openflow.protocol.OFInstructionType;
import org.projectfloodlight.openflow.protocol.action.OFAction;
import org.projectfloodlight.openflow.protocol.action.OFActionCircuit;
-import org.projectfloodlight.openflow.protocol.action.OFActionCopyTtlIn;
-import org.projectfloodlight.openflow.protocol.action.OFActionCopyTtlOut;
-import org.projectfloodlight.openflow.protocol.action.OFActionDecMplsTtl;
-import org.projectfloodlight.openflow.protocol.action.OFActionDecNwTtl;
import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
+import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
-import org.projectfloodlight.openflow.protocol.action.OFActionPushMpls;
import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
@@ -207,25 +204,24 @@
builder.popMpls((short) popMpls.getEthertype().getValue());
break;
case PUSH_MPLS:
- OFActionPushMpls pushMpls = (OFActionPushMpls) act;
builder.pushMpls();
break;
case COPY_TTL_IN:
- OFActionCopyTtlIn copyTtlIn = (OFActionCopyTtlIn) act;
builder.copyTtlIn();
break;
case COPY_TTL_OUT:
- OFActionCopyTtlOut copyTtlOut = (OFActionCopyTtlOut) act;
builder.copyTtlOut();
break;
case DEC_MPLS_TTL:
- OFActionDecMplsTtl decMplsTtl = (OFActionDecMplsTtl) act;
builder.decMplsTtl();
break;
case DEC_NW_TTL:
- OFActionDecNwTtl decNwTtl = (OFActionDecNwTtl) act;
builder.decNwTtl();
break;
+ case GROUP:
+ OFActionGroup group = (OFActionGroup) act;
+ builder.group(new DefaultGroupId(group.getGroup().getGroupNumber()));
+ break;
case SET_TP_DST:
case SET_TP_SRC:
case POP_PBB:
@@ -241,8 +237,6 @@
case SET_QUEUE:
case STRIP_VLAN:
case ENQUEUE:
-
- case GROUP:
default:
log.warn("Action type {} not yet implemented.", act.getType());
}
diff --git a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer13.java b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer13.java
index 905cee9..eec63fb 100644
--- a/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer13.java
+++ b/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer13.java
@@ -21,6 +21,7 @@
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.flow.instructions.Instruction;
import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
+import org.onosproject.net.flow.instructions.Instructions.GroupInstruction;
import org.onosproject.net.flow.instructions.L0ModificationInstruction;
import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction;
import org.onosproject.net.flow.instructions.L2ModificationInstruction;
@@ -37,6 +38,7 @@
import org.projectfloodlight.openflow.protocol.OFFlowMod;
import org.projectfloodlight.openflow.protocol.OFFlowModFlags;
import org.projectfloodlight.openflow.protocol.action.OFAction;
+import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
import org.projectfloodlight.openflow.protocol.match.Match;
import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
@@ -45,6 +47,7 @@
import org.projectfloodlight.openflow.types.IPv4Address;
import org.projectfloodlight.openflow.types.MacAddress;
import org.projectfloodlight.openflow.types.OFBufferId;
+import org.projectfloodlight.openflow.types.OFGroup;
import org.projectfloodlight.openflow.types.OFPort;
import org.projectfloodlight.openflow.types.OFVlanVidMatch;
import org.projectfloodlight.openflow.types.U32;
@@ -183,6 +186,11 @@
actions.add(action.build());
break;
case GROUP:
+ GroupInstruction group = (GroupInstruction) i;
+ OFActionGroup.Builder groupBuilder = factory().actions().buildGroup()
+ .setGroup(OFGroup.of(group.groupId().id()));
+ actions.add(groupBuilder.build());
+ break;
default:
log.warn("Instruction type {} not yet implemented.", i.type());
}