Refactor fabric.p4
minor refactor for coding style
Change-Id: I7b73b9c3f439c66ce435404cb42fdb38323845b3
diff --git a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java
index 4bb1d92..86a4a11 100644
--- a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java
+++ b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricConstants.java
@@ -118,6 +118,8 @@
PiCounterId.of("FabricIngress.forwarding.multicast_v4_counter");
public static final PiCounterId FABRIC_INGRESS_FORWARDING_UNICAST_V6_COUNTER =
PiCounterId.of("FabricIngress.forwarding.unicast_v6_counter");
+ public static final PiCounterId FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN_COUNTER =
+ PiCounterId.of("FabricEgress.egress_next.egress_vlan_counter");
public static final PiCounterId FABRIC_INGRESS_FORWARDING_UNICAST_V4_COUNTER =
PiCounterId.of("FabricIngress.forwarding.unicast_v4_counter");
public static final PiCounterId FABRIC_INGRESS_NEXT_SIMPLE_COUNTER =
@@ -129,44 +131,60 @@
public static final PiCounterId FABRIC_INGRESS_NEXT_HASHED_COUNTER =
PiCounterId.of("FabricIngress.next.hashed_counter");
// Action IDs
- public static final PiActionId FABRIC_INGRESS_FILTERING_DROP =
- PiActionId.of("FabricIngress.filtering.drop");
+ public static final PiActionId FABRIC_INGRESS_FORWARDING_SEND_TO_CONTROLLER =
+ PiActionId.of("FabricIngress.forwarding.send_to_controller");
+ public static final PiActionId FABRIC_INGRESS_NEXT_MPLS_ROUTING_V6_SIMPLE =
+ PiActionId.of("FabricIngress.next.mpls_routing_v6_simple");
+ public static final PiActionId FABRIC_INGRESS_FORWARDING_SET_NEXT_ID_BRIDGING =
+ PiActionId.of("FabricIngress.forwarding.set_next_id_bridging");
public static final PiActionId FABRIC_INGRESS_NEXT_SET_VLAN =
PiActionId.of("FabricIngress.next.set_vlan");
- public static final PiActionId FABRIC_INGRESS_FORWARDING_POP_MPLS_AND_NEXT =
- PiActionId.of("FabricIngress.forwarding.pop_mpls_and_next");
- public static final PiActionId FABRIC_EGRESS_EGRESS_NEXT_POP_VLAN =
- PiActionId.of("FabricEgress.egress_next.pop_vlan");
- public static final PiActionId FABRIC_INGRESS_FILTERING_SET_FORWARDING_TYPE =
- PiActionId.of("FabricIngress.filtering.set_forwarding_type");
- public static final PiActionId NOP = PiActionId.of("nop");
- public static final PiActionId FABRIC_INGRESS_FILTERING_SET_VLAN =
- PiActionId.of("FabricIngress.filtering.set_vlan");
- public static final PiActionId FABRIC_INGRESS_NEXT_MPLS_ROUTING_V6 =
- PiActionId.of("FabricIngress.next.mpls_routing_v6");
public static final PiActionId FABRIC_EGRESS_PKT_IO_EGRESS_POP_VLAN =
PiActionId.of("FabricEgress.pkt_io_egress.pop_vlan");
- public static final PiActionId FABRIC_INGRESS_NEXT_L3_ROUTING_VLAN =
- PiActionId.of("FabricIngress.next.l3_routing_vlan");
- public static final PiActionId NO_ACTION = PiActionId.of("NoAction");
+ public static final PiActionId FABRIC_INGRESS_FILTERING_SET_VLAN =
+ PiActionId.of("FabricIngress.filtering.set_vlan");
+ public static final PiActionId FABRIC_INGRESS_NEXT_L3_ROUTING_SIMPLE =
+ PiActionId.of("FabricIngress.next.l3_routing_simple");
public static final PiActionId FABRIC_INGRESS_NEXT_SET_MCAST_GROUP =
PiActionId.of("FabricIngress.next.set_mcast_group");
- public static final PiActionId FABRIC_INGRESS_FORWARDING_DUPLICATE_TO_CONTROLLER =
- PiActionId.of("FabricIngress.forwarding.duplicate_to_controller");
- public static final PiActionId FABRIC_INGRESS_NEXT_L3_ROUTING =
- PiActionId.of("FabricIngress.next.l3_routing");
- public static final PiActionId FABRIC_INGRESS_NEXT_MPLS_ROUTING_V4 =
- PiActionId.of("FabricIngress.next.mpls_routing_v4");
- public static final PiActionId FABRIC_INGRESS_NEXT_SET_VLAN_OUTPUT =
- PiActionId.of("FabricIngress.next.set_vlan_output");
- public static final PiActionId FABRIC_INGRESS_FORWARDING_SET_NEXT_ID =
- PiActionId.of("FabricIngress.forwarding.set_next_id");
public static final PiActionId FABRIC_INGRESS_FILTERING_PUSH_INTERNAL_VLAN =
PiActionId.of("FabricIngress.filtering.push_internal_vlan");
+ public static final PiActionId FABRIC_INGRESS_NEXT_MPLS_ROUTING_V6_HASHED =
+ PiActionId.of("FabricIngress.next.mpls_routing_v6_hashed");
+ public static final PiActionId FABRIC_INGRESS_FORWARDING_POP_MPLS_AND_NEXT =
+ PiActionId.of("FabricIngress.forwarding.pop_mpls_and_next");
+ public static final PiActionId FABRIC_INGRESS_NEXT_L3_ROUTING_HASHED =
+ PiActionId.of("FabricIngress.next.l3_routing_hashed");
+ public static final PiActionId FABRIC_EGRESS_EGRESS_NEXT_POP_VLAN =
+ PiActionId.of("FabricEgress.egress_next.pop_vlan");
+ public static final PiActionId FABRIC_INGRESS_NEXT_MPLS_ROUTING_V4_HASHED =
+ PiActionId.of("FabricIngress.next.mpls_routing_v4_hashed");
+ public static final PiActionId FABRIC_INGRESS_FORWARDING_SET_NEXT_ID_UNICAST_V6 =
+ PiActionId.of("FabricIngress.forwarding.set_next_id_unicast_v6");
+ public static final PiActionId FABRIC_INGRESS_FORWARDING_SET_NEXT_ID_UNICAST_V4 =
+ PiActionId.of("FabricIngress.forwarding.set_next_id_unicast_v4");
+ public static final PiActionId NOP = PiActionId.of("nop");
public static final PiActionId FABRIC_INGRESS_FORWARDING_DROP =
PiActionId.of("FabricIngress.forwarding.drop");
- public static final PiActionId FABRIC_INGRESS_NEXT_OUTPUT =
- PiActionId.of("FabricIngress.next.output");
+ public static final PiActionId FABRIC_INGRESS_NEXT_OUTPUT_SIMPLE =
+ PiActionId.of("FabricIngress.next.output_simple");
+ public static final PiActionId FABRIC_INGRESS_FILTERING_DROP =
+ PiActionId.of("FabricIngress.filtering.drop");
+ public static final PiActionId FABRIC_INGRESS_FILTERING_SET_FORWARDING_TYPE =
+ PiActionId.of("FabricIngress.filtering.set_forwarding_type");
+ public static final PiActionId FABRIC_INGRESS_NEXT_SET_VLAN_OUTPUT =
+ PiActionId.of("FabricIngress.next.set_vlan_output");
+ public static final PiActionId NO_ACTION = PiActionId.of("NoAction");
+ public static final PiActionId FABRIC_INGRESS_FORWARDING_SET_NEXT_ID_MULTICAST_V6 =
+ PiActionId.of("FabricIngress.forwarding.set_next_id_multicast_v6");
+ public static final PiActionId FABRIC_INGRESS_FORWARDING_SET_NEXT_ID_MULTICAST_V4 =
+ PiActionId.of("FabricIngress.forwarding.set_next_id_multicast_v4");
+ public static final PiActionId FABRIC_INGRESS_NEXT_MPLS_ROUTING_V4_SIMPLE =
+ PiActionId.of("FabricIngress.next.mpls_routing_v4_simple");
+ public static final PiActionId FABRIC_INGRESS_NEXT_L3_ROUTING_VLAN =
+ PiActionId.of("FabricIngress.next.l3_routing_vlan");
+ public static final PiActionId FABRIC_INGRESS_FORWARDING_SET_NEXT_ID_ACL =
+ PiActionId.of("FabricIngress.forwarding.set_next_id_acl");
// Action Param IDs
public static final PiActionParamId DMAC = PiActionParamId.of("dmac");
public static final PiActionParamId PORT_NUM =
diff --git a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricInterpreter.java b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricInterpreter.java
index 11f551e..8fbff96 100644
--- a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricInterpreter.java
+++ b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricInterpreter.java
@@ -164,13 +164,13 @@
throws PiInterpreterException {
if (FILTERING_CTRL_TBLS.contains(piTableId)) {
- return FabricTreatmentInterpreter.mapFilteringTreatment(treatment);
+ return FabricTreatmentInterpreter.mapFilteringTreatment(treatment, piTableId);
} else if (FORWARDING_CTRL_TBLS.contains(piTableId)) {
- return FabricTreatmentInterpreter.mapForwardingTreatment(treatment);
+ return FabricTreatmentInterpreter.mapForwardingTreatment(treatment, piTableId);
} else if (NEXT_CTRL_TBLS.contains(piTableId)) {
- return FabricTreatmentInterpreter.mapNextTreatment(treatment);
+ return FabricTreatmentInterpreter.mapNextTreatment(treatment, piTableId);
} else if (E_NEXT_CTRL_TBLS.contains(piTableId)) {
- return FabricTreatmentInterpreter.mapEgressNextTreatment(treatment);
+ return FabricTreatmentInterpreter.mapEgressNextTreatment(treatment, piTableId);
} else {
throw new PiInterpreterException(String.format("Table %s unsupported", piTableId));
}
diff --git a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricTreatmentInterpreter.java b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricTreatmentInterpreter.java
index 2c41985..921b5f4 100644
--- a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricTreatmentInterpreter.java
+++ b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/FabricTreatmentInterpreter.java
@@ -33,6 +33,7 @@
import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction;
import org.onosproject.net.pi.model.PiActionId;
import org.onosproject.net.pi.model.PiPipelineInterpreter.PiInterpreterException;
+import org.onosproject.net.pi.model.PiTableId;
import org.onosproject.net.pi.runtime.PiAction;
import org.onosproject.net.pi.runtime.PiActionParam;
import org.slf4j.Logger;
@@ -64,16 +65,16 @@
/*
* In Filtering block, we need to implement these actions:
- *
* push_internal_vlan
* set_vlan
* nop
*
* Unsupported, using PiAction directly:
* set_forwarding_type
+ * drop
*/
- static PiAction mapFilteringTreatment(TrafficTreatment treatment)
+ static PiAction mapFilteringTreatment(TrafficTreatment treatment, PiTableId tableId)
throws PiInterpreterException {
List<Instruction> instructions = treatment.allInstructions();
Instruction noActInst = Instructions.createNoAction();
@@ -122,15 +123,20 @@
/*
* In forwarding block, we need to implement these actions:
- * duplicate_to_controller
+ * send_to_controller
*
* Unsupported, using PiAction directly:
- * set_next_id
- * push_mpls_and_next_v4
- * push_mpls_and_next_v6
+ * set_next_id_bridging
+ * pop_mpls_and_next
+ * set_next_id_unicast_v4
+ * set_next_id_multicast_v4
+ * set_next_id_acl
+ * drop
+ * set_next_id_unicast_v6
+ * set_next_id_multicast_v6
*/
- public static PiAction mapForwardingTreatment(TrafficTreatment treatment)
+ public static PiAction mapForwardingTreatment(TrafficTreatment treatment, PiTableId tableId)
throws PiInterpreterException {
// Empty treatment, generate table entry with no action
if (treatment.equals(DefaultTrafficTreatment.emptyTreatment())) {
@@ -155,23 +161,31 @@
}
return PiAction.builder()
- .withId(FabricConstants.FABRIC_INGRESS_FORWARDING_DUPLICATE_TO_CONTROLLER)
+ .withId(FabricConstants.FABRIC_INGRESS_FORWARDING_SEND_TO_CONTROLLER)
.build();
}
/*
* In Next block, we need to implement these actions:
- * output
+ * set_vlan
* set_vlan_output
- * l3_routing
+ * output_simple
+ * output_hashed
+ * l3_routing_simple
* l3_routing_vlan
- * mpls_routing_v4
+ * l3_routing_hashed
+ * mpls_routing_v4_simple
+ * mpls_routing_v6_simple
+ * mpls_routing_v4_hashed
+ * mpls_routing_v6_hashed
*
* Unsupported, need to find a way to implement it
- * mpls_routing_v6
+ *
+ * set_mcast_group
+ *
*/
- public static PiAction mapNextTreatment(TrafficTreatment treatment)
+ public static PiAction mapNextTreatment(TrafficTreatment treatment, PiTableId tableId)
throws PiInterpreterException {
// TODO: refactor this method
List<Instruction> insts = treatment.allInstructions();
@@ -213,21 +227,21 @@
}
}
+ if (tableId.equals(FabricConstants.FABRIC_INGRESS_NEXT_VLAN_META) &&
+ modVlanIdInst != null) {
+ // set_vlan
+ VlanId vlanId = modVlanIdInst.vlanId();
+ PiActionParam newVlanParam =
+ new PiActionParam(FabricConstants.NEW_VLAN_ID,
+ ImmutableByteSequence.copyFrom(vlanId.toShort()));
+ return PiAction.builder()
+ .withId(FabricConstants.FABRIC_INGRESS_NEXT_SET_VLAN)
+ .withParameter(newVlanParam)
+ .build();
+ }
+
if (outInst == null) {
- // for vlan_meta table only
- if (modVlanIdInst != null) {
- // set_vlan
- VlanId vlanId = modVlanIdInst.vlanId();
- PiActionParam newVlanParam =
- new PiActionParam(FabricConstants.NEW_VLAN_ID,
- ImmutableByteSequence.copyFrom(vlanId.toShort()));
- return PiAction.builder()
- .withId(FabricConstants.FABRIC_INGRESS_NEXT_SET_VLAN)
- .withParameter(newVlanParam)
- .build();
- } else {
- throw new PiInterpreterException(format(INVALID_TREATMENT, "next", treatment));
- }
+ throw new PiInterpreterException(format(INVALID_TREATMENT, "next", treatment));
}
short portNum = (short) outInst.port().toLong();
@@ -239,15 +253,15 @@
PiActionParam vlanParam =
new PiActionParam(FabricConstants.NEW_VLAN_ID,
ImmutableByteSequence.copyFrom(vlanId.toShort()));
- // set_vlan_output
+ // set_vlan_output (simple table)
return PiAction.builder()
.withId(FabricConstants.FABRIC_INGRESS_NEXT_SET_VLAN_OUTPUT)
.withParameters(ImmutableList.of(portNumParam, vlanParam))
.build();
} else {
- // output
+ // output (simple or hashed table)
return PiAction.builder()
- .withId(FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT)
+ .withId(FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT_SIMPLE)
.withParameter(portNumParam)
.build();
}
@@ -268,9 +282,19 @@
ImmutableByteSequence mplsValue =
ImmutableByteSequence.copyFrom(mplsLabel.toInt()).fit(20);
PiActionParam mplsParam = new PiActionParam(FabricConstants.LABEL, mplsValue);
+
+ PiActionId actionId;
+ // FIXME: finds a way to determine v4 or v6
+ if (tableId.equals(FabricConstants.FABRIC_INGRESS_NEXT_SIMPLE)) {
+ actionId = FabricConstants.FABRIC_INGRESS_NEXT_MPLS_ROUTING_V4_SIMPLE;
+ } else if (tableId.equals(FabricConstants.FABRIC_INGRESS_NEXT_HASHED)) {
+ actionId = FabricConstants.FABRIC_INGRESS_NEXT_MPLS_ROUTING_V4_HASHED;
+ } else {
+ throw new PiInterpreterException(format(INVALID_TREATMENT, "next", treatment));
+ }
+
return PiAction.builder()
- // FIXME: fins a way to determine v4 or v6
- .withId(FabricConstants.FABRIC_INGRESS_NEXT_MPLS_ROUTING_V4)
+ .withId(actionId)
.withParameters(ImmutableList.of(portNumParam,
srcMacParam,
dstMacParam,
@@ -294,9 +318,18 @@
.withParameters(ImmutableList.of(srcMacParam, dstMacParam, portNumParam, vlanParam))
.build();
} else {
+ PiActionId actionId;
+ if (tableId.equals(FabricConstants.FABRIC_INGRESS_NEXT_SIMPLE)) {
+ actionId = FabricConstants.FABRIC_INGRESS_NEXT_L3_ROUTING_SIMPLE;
+ } else if (tableId.equals(FabricConstants.FABRIC_INGRESS_NEXT_HASHED)) {
+ actionId = FabricConstants.FABRIC_INGRESS_NEXT_L3_ROUTING_HASHED;
+ } else {
+ throw new PiInterpreterException(format(INVALID_TREATMENT, "next", treatment));
+ }
+
// L3 routing
return PiAction.builder()
- .withId(FabricConstants.FABRIC_INGRESS_NEXT_L3_ROUTING)
+ .withId(actionId)
.withParameters(ImmutableList.of(portNumParam,
srcMacParam,
dstMacParam))
@@ -307,7 +340,10 @@
throw new PiInterpreterException(format(INVALID_TREATMENT, "next", treatment));
}
- public static PiAction mapEgressNextTreatment(TrafficTreatment treatment) {
+ /*
+ * pop_vlan
+ */
+ public static PiAction mapEgressNextTreatment(TrafficTreatment treatment, PiTableId tableId) {
// Pop VLAN action for now, may add new action to this control block in the future.
return treatment.allInstructions()
.stream()
diff --git a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/pipeliner/FabricForwardingPipeliner.java b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/pipeliner/FabricForwardingPipeliner.java
index 785870e..c4ecdfd 100644
--- a/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/pipeliner/FabricForwardingPipeliner.java
+++ b/pipelines/fabric/src/main/java/org/onosproject/pipelines/fabric/pipeliner/FabricForwardingPipeliner.java
@@ -34,6 +34,7 @@
import org.onosproject.net.flow.criteria.VlanIdCriterion;
import org.onosproject.net.flowobjective.ForwardingObjective;
import org.onosproject.net.flowobjective.ObjectiveError;
+import org.onosproject.net.pi.model.PiActionId;
import org.onosproject.net.pi.runtime.PiAction;
import org.onosproject.net.pi.runtime.PiActionParam;
import org.onosproject.pipelines.fabric.FabricConstants;
@@ -178,7 +179,8 @@
.build();
TrafficTreatment treatment = fwd.treatment();
if (fwd.nextId() != null) {
- treatment = buildSetNextIdTreatment(fwd.nextId());
+ treatment = buildSetNextIdTreatment(fwd.nextId(),
+ FabricConstants.FABRIC_INGRESS_FORWARDING_SET_NEXT_ID_BRIDGING);
}
FlowRule flowRule = DefaultFlowRule.builder()
@@ -206,7 +208,8 @@
.build();
TrafficTreatment treatment = fwd.treatment();
if (fwd.nextId() != null) {
- treatment = buildSetNextIdTreatment(fwd.nextId());
+ treatment = buildSetNextIdTreatment(fwd.nextId(),
+ FabricConstants.FABRIC_INGRESS_FORWARDING_SET_NEXT_ID_BRIDGING);
}
FlowRule flowRule = DefaultFlowRule.builder()
.withSelector(selector)
@@ -229,7 +232,8 @@
.build();
TrafficTreatment treatment = fwd.treatment();
if (fwd.nextId() != null) {
- treatment = buildSetNextIdTreatment(fwd.nextId());
+ treatment = buildSetNextIdTreatment(fwd.nextId(),
+ FabricConstants.FABRIC_INGRESS_FORWARDING_SET_NEXT_ID_UNICAST_V4);
}
FlowRule flowRule = DefaultFlowRule.builder()
.withSelector(selector)
@@ -286,11 +290,11 @@
* @param nextId the next id for action
* @return treatment with set_next_id action; empty treatment if next id is null
*/
- private static TrafficTreatment buildSetNextIdTreatment(Integer nextId) {
+ private static TrafficTreatment buildSetNextIdTreatment(Integer nextId, PiActionId actionId) {
PiActionParam nextIdParam = new PiActionParam(FabricConstants.NEXT_ID,
ImmutableByteSequence.copyFrom(nextId.byteValue()));
PiAction nextIdAction = PiAction.builder()
- .withId(FabricConstants.FABRIC_INGRESS_FORWARDING_SET_NEXT_ID)
+ .withId(actionId)
.withParameter(nextIdParam)
.build();