sangho
Committed by Gerrit Code Review

ONOS-958: Add a Group action to TrafficTreatment subsystem.

Change-Id: I2a377508b9721ee96a5a52b0bb2ed3a960c982ce
......@@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableList;
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 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
}
@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?
......
......@@ -17,6 +17,7 @@ package org.onosproject.net.flow;
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 interface TrafficTreatment {
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
......
......@@ -21,6 +21,7 @@ import static org.onosproject.net.flow.instructions.L2ModificationInstruction.*;
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 @@ public final class Instructions {
}
/**
* 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 @@ public final class Instructions {
}
/*
* Output instructions
* Drop instructions
*/
public static final class DropInstruction implements Instruction {
......@@ -241,6 +253,9 @@ public final class Instructions {
}
}
/*
* Output Instruction
*/
public static final class OutputInstruction implements Instruction {
private final PortNumber port;
......@@ -282,6 +297,50 @@ public final class Instructions {
}
}
/*
* 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;
}
}
}
......
......@@ -22,6 +22,7 @@ import org.onlab.packet.Ip6Address;
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.OFFlowStatsEntry;
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 @@ public class FlowEntryBuilder {
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 @@ public class FlowEntryBuilder {
case SET_QUEUE:
case STRIP_VLAN:
case ENQUEUE:
case GROUP:
default:
log.warn("Action type {} not yet implemented.", act.getType());
}
......
......@@ -21,6 +21,7 @@ import org.onosproject.net.flow.FlowRule;
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.OFFlowDelete;
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.EthType;
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 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
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());
}
......