alshabib

Refactored driver to use new FlowRule api.

Deprecated transition with table types and added api for transition with table ids.

Change-Id: Ifcf2d87d16810666d992e4d9f5ddca3d0da460be
......@@ -289,7 +289,7 @@ public class DefaultFlowRule implements FlowRule {
return new Builder();
}
private static final class Builder implements FlowRule.Builder {
public static final class Builder implements FlowRule.Builder {
private FlowId flowId;
private Integer priority;
......
......@@ -328,7 +328,12 @@ public final class DefaultTrafficTreatment implements TrafficTreatment {
@Override
public Builder transition(FlowRule.Type type) {
return add(Instructions.transition(type));
return add(Instructions.transition(type.ordinal()));
}
@Override
public Builder transition(Integer tableId) {
return add(Instructions.transition(tableId));
}
@Override
......
......@@ -230,9 +230,19 @@ public interface TrafficTreatment {
* @param type the table type
* @return a treatement builder
*/
@Deprecated
public Builder transition(FlowRule.Type type);
/**
* Sets the next table id to transition to.
*
* @param tableId the table table
* @return a treatement builder
*/
public Builder transition(Integer tableId);
/**
* Pops outermost VLAN tag.
*
* @return a treatment builder.
......
......@@ -22,11 +22,8 @@ import org.onlab.packet.MplsLabel;
import org.onlab.packet.VlanId;
import org.onosproject.core.GroupId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.instructions.L0ModificationInstruction.L0SubType;
import org.onosproject.net.flow.instructions.L0ModificationInstruction.ModLambdaInstruction;
import org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType;
import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
......@@ -36,12 +33,6 @@ import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction;
import static org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsTtlInstruction;
import static org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction;
import static org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction;
import static org.onosproject.net.flow.instructions.L2ModificationInstruction.PopVlanInstruction;
import static org.onosproject.net.flow.instructions.L2ModificationInstruction.PushHeaderInstructions;
/**
* Factory class for creating various traffic treatment instructions.
......@@ -103,7 +94,8 @@ public final class Instructions {
*/
public static L2ModificationInstruction modL2Src(MacAddress addr) {
checkNotNull(addr, "Src l2 address cannot be null");
return new ModEtherInstruction(L2SubType.ETH_SRC, addr);
return new L2ModificationInstruction.ModEtherInstruction(
L2ModificationInstruction.L2SubType.ETH_SRC, addr);
}
/**
......@@ -114,7 +106,8 @@ public final class Instructions {
*/
public static L2ModificationInstruction modL2Dst(MacAddress addr) {
checkNotNull(addr, "Dst l2 address cannot be null");
return new ModEtherInstruction(L2SubType.ETH_DST, addr);
return new L2ModificationInstruction.ModEtherInstruction(
L2ModificationInstruction.L2SubType.ETH_DST, addr);
}
/**
......@@ -125,7 +118,7 @@ public final class Instructions {
*/
public static L2ModificationInstruction modVlanId(VlanId vlanId) {
checkNotNull(vlanId, "VLAN id cannot be null");
return new ModVlanIdInstruction(vlanId);
return new L2ModificationInstruction.ModVlanIdInstruction(vlanId);
}
/**
......@@ -136,7 +129,7 @@ public final class Instructions {
*/
public static L2ModificationInstruction modVlanPcp(Byte vlanPcp) {
checkNotNull(vlanPcp, "VLAN Pcp cannot be null");
return new ModVlanPcpInstruction(vlanPcp);
return new L2ModificationInstruction.ModVlanPcpInstruction(vlanPcp);
}
/**
......@@ -147,7 +140,7 @@ public final class Instructions {
*/
public static L2ModificationInstruction modMplsLabel(MplsLabel mplsLabel) {
checkNotNull(mplsLabel, "MPLS label cannot be null");
return new ModMplsLabelInstruction(mplsLabel);
return new L2ModificationInstruction.ModMplsLabelInstruction(mplsLabel);
}
/**
......@@ -156,7 +149,7 @@ public final class Instructions {
* @return a L2 Modification
*/
public static L2ModificationInstruction decMplsTtl() {
return new ModMplsTtlInstruction();
return new L2ModificationInstruction.ModMplsTtlInstruction();
}
/**
......@@ -246,7 +239,8 @@ public final class Instructions {
* @return a L2 modification.
*/
public static Instruction pushMpls() {
return new PushHeaderInstructions(L2SubType.MPLS_PUSH,
return new L2ModificationInstruction.PushHeaderInstructions(
L2ModificationInstruction.L2SubType.MPLS_PUSH,
Ethernet.MPLS_UNICAST);
}
......@@ -256,7 +250,8 @@ public final class Instructions {
* @return a L2 modification.
*/
public static Instruction popMpls() {
return new PushHeaderInstructions(L2SubType.MPLS_POP,
return new L2ModificationInstruction.PushHeaderInstructions(
L2ModificationInstruction.L2SubType.MPLS_POP,
Ethernet.MPLS_UNICAST);
}
......@@ -268,7 +263,8 @@ public final class Instructions {
*/
public static Instruction popMpls(Short etherType) {
checkNotNull(etherType, "Ethernet type cannot be null");
return new PushHeaderInstructions(L2SubType.MPLS_POP, etherType);
return new L2ModificationInstruction.PushHeaderInstructions(
L2ModificationInstruction.L2SubType.MPLS_POP, etherType);
}
/**
......@@ -277,7 +273,8 @@ public final class Instructions {
* @return a L2 modification
*/
public static Instruction popVlan() {
return new PopVlanInstruction(L2SubType.VLAN_POP);
return new L2ModificationInstruction.PopVlanInstruction(
L2ModificationInstruction.L2SubType.VLAN_POP);
}
/**
......@@ -286,18 +283,19 @@ public final class Instructions {
* @return a L2 modification
*/
public static Instruction pushVlan() {
return new PushHeaderInstructions(L2SubType.VLAN_PUSH, Ethernet.TYPE_VLAN);
return new L2ModificationInstruction.PushHeaderInstructions(
L2ModificationInstruction.L2SubType.VLAN_PUSH, Ethernet.TYPE_VLAN);
}
/**
* Sends the packet to the table described in 'type'.
* Sends the packet to the table id.
*
* @param type flow rule table type
* @param tableId flow rule table id
* @return table type transition instruction
*/
public static Instruction transition(FlowRule.Type type) {
checkNotNull(type, "Table type cannot be null");
return new TableTypeTransition(type);
public static Instruction transition(Integer tableId) {
checkNotNull(tableId, "Table id cannot be null");
return new TableTypeTransition(tableId);
}
/**
......@@ -421,13 +419,12 @@ public final class Instructions {
}
}
// FIXME: Temporary support for this. This should probably become it's own
// type like other instructions.
public static class TableTypeTransition implements Instruction {
private final FlowRule.Type tableType;
private final Integer tableId;
TableTypeTransition(FlowRule.Type type) {
this.tableType = type;
TableTypeTransition(Integer tableId) {
this.tableId = tableId;
}
@Override
......@@ -435,19 +432,19 @@ public final class Instructions {
return Type.TABLE;
}
public FlowRule.Type tableType() {
return this.tableType;
public Integer tableId() {
return this.tableId;
}
@Override
public String toString() {
return toStringHelper(type().toString())
.add("tableType", this.tableType).toString();
.add("tableId", this.tableId).toString();
}
@Override
public int hashCode() {
return Objects.hash(type(), tableType);
return Objects.hash(type(), tableId);
}
@Override
......@@ -457,7 +454,7 @@ public final class Instructions {
}
if (obj instanceof TableTypeTransition) {
TableTypeTransition that = (TableTypeTransition) obj;
return Objects.equals(tableType, that.tableType);
return Objects.equals(tableId, that.tableId);
}
return false;
......
......@@ -36,7 +36,6 @@ import org.onosproject.net.flow.instructions.L2ModificationInstruction.PushHeade
import org.onosproject.net.flow.instructions.L3ModificationInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
import org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction;
import org.onosproject.openflow.controller.OpenFlowSwitch;
import org.projectfloodlight.openflow.protocol.OFFactory;
import org.projectfloodlight.openflow.protocol.OFFlowAdd;
import org.projectfloodlight.openflow.protocol.OFFlowDelete;
......@@ -238,38 +237,10 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
private OFInstruction buildTableGoto(Instructions.TableTypeTransition i) {
OFInstruction instruction = factory().instructions().gotoTable(
TableId.of(getTableType(i.tableType()).ordinal()));
TableId.of(i.tableId()));
return instruction;
}
// FIXME: this has to go as well perhaps when we implement the SelectorService.
private OpenFlowSwitch.TableType getTableType(FlowRule.Type type) {
switch (type) {
case DEFAULT:
return OpenFlowSwitch.TableType.NONE;
case IP:
return OpenFlowSwitch.TableType.IP;
case MPLS:
return OpenFlowSwitch.TableType.MPLS;
case ACL:
return OpenFlowSwitch.TableType.ACL;
case VLAN_MPLS:
return OpenFlowSwitch.TableType.VLAN_MPLS;
case VLAN:
return OpenFlowSwitch.TableType.VLAN;
case ETHER:
return OpenFlowSwitch.TableType.ETHER;
case COS:
return OpenFlowSwitch.TableType.COS;
case FIRST:
return OpenFlowSwitch.TableType.FIRST;
default:
return OpenFlowSwitch.TableType.NONE;
}
}
private OFAction buildL0Modification(Instruction i) {
L0ModificationInstruction l0m = (L0ModificationInstruction) i;
switch (l0m.subtype()) {
......