[SDFAB-102] Backport changes required for policies to fabric.p4
Change-Id: I1c9a66c548b5d5e1d3a92ff29208263fb6844c0c
diff --git a/pipelines/fabric/impl/src/test/java/org/onosproject/pipelines/fabric/impl/behaviour/FabricInterpreterTest.java b/pipelines/fabric/impl/src/test/java/org/onosproject/pipelines/fabric/impl/behaviour/FabricInterpreterTest.java
index 0ad8d02..2ea8b29 100644
--- a/pipelines/fabric/impl/src/test/java/org/onosproject/pipelines/fabric/impl/behaviour/FabricInterpreterTest.java
+++ b/pipelines/fabric/impl/src/test/java/org/onosproject/pipelines/fabric/impl/behaviour/FabricInterpreterTest.java
@@ -93,7 +93,7 @@
}
/**
- * Map treatment to permit action.
+ * Map empty treatment to permit action.
*/
@Test
public void testFilteringTreatmentPermit() throws Exception {
@@ -107,6 +107,40 @@
assertEquals(expectedAction, mappedAction);
}
+ /**
+ * Map empty treatment and wipeDeferred to permit action.
+ */
+ @Test
+ public void testFilteringTreatmentPermit2() throws Exception {
+ TrafficTreatment treatment = DefaultTrafficTreatment.builder()
+ .wipeDeferred()
+ .build();
+ PiAction mappedAction = interpreter.mapTreatment(treatment,
+ FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN);
+ PiAction expectedAction = PiAction.builder()
+ .withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT)
+ .build();
+
+ assertEquals(expectedAction, mappedAction);
+ }
+
+ /**
+ * Map popVlan to permit action.
+ */
+ @Test
+ public void testFilteringTreatmentPermit3() throws Exception {
+ TrafficTreatment treatment = DefaultTrafficTreatment.builder()
+ .popVlan()
+ .build();
+ PiAction mappedAction = interpreter.mapTreatment(treatment,
+ FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN);
+ PiAction expectedAction = PiAction.builder()
+ .withId(FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT)
+ .build();
+
+ assertEquals(expectedAction, mappedAction);
+ }
+
/* Forwarding control block */
/**
@@ -124,7 +158,7 @@
}
/**
- * Map empty treatment for ACL table.
+ * Map empty treatment to NOP for ACL table.
*/
@Test
public void testAclTreatmentEmpty() throws Exception {
@@ -137,6 +171,22 @@
assertEquals(expectedAction, mappedAction);
}
+ /**
+ * Map wipeDeferred treatment to DROP for ACL table.
+ */
+ @Test
+ public void testAclTreatmentWipeDeferred() throws Exception {
+ TrafficTreatment treatment = DefaultTrafficTreatment.builder()
+ .wipeDeferred()
+ .build();
+ PiAction mappedAction = interpreter.mapTreatment(
+ treatment, FabricConstants.FABRIC_INGRESS_ACL_ACL);
+ PiAction expectedAction = PiAction.builder()
+ .withId(FabricConstants.FABRIC_INGRESS_ACL_DROP)
+ .build();
+ assertEquals(expectedAction, mappedAction);
+ }
+
/* Next control block */
/**
diff --git a/pipelines/fabric/impl/src/test/java/org/onosproject/pipelines/fabric/impl/behaviour/pipeliner/FilteringObjectiveTranslatorTest.java b/pipelines/fabric/impl/src/test/java/org/onosproject/pipelines/fabric/impl/behaviour/pipeliner/FilteringObjectiveTranslatorTest.java
index 24300ea..71e45b1 100644
--- a/pipelines/fabric/impl/src/test/java/org/onosproject/pipelines/fabric/impl/behaviour/pipeliner/FilteringObjectiveTranslatorTest.java
+++ b/pipelines/fabric/impl/src/test/java/org/onosproject/pipelines/fabric/impl/behaviour/pipeliner/FilteringObjectiveTranslatorTest.java
@@ -395,6 +395,53 @@
assertEquals(expectedTranslation, actualTranslation);
}
+ /**
+ * Test no more ports scenario for filtering objective.
+ */
+ @Test
+ public void testNoMorePorts() throws FabricPipelinerException {
+ // Tagged port scenario
+ FilteringObjective filteringObjective = DefaultFilteringObjective.builder()
+ .withKey(Criteria.matchInPort(PORT_1))
+ .addCondition(Criteria.matchEthDst(ROUTER_MAC))
+ .addCondition(Criteria.matchVlanId(VLAN_100))
+ .withPriority(PRIORITY)
+ .fromApp(APP_ID)
+ .withMeta(DefaultTrafficTreatment.builder().wipeDeferred().build())
+ .permit()
+ .add();
+ ObjectiveTranslation actualTranslation = translator.translate(filteringObjective);
+ Collection<FlowRule> expectedFlowRules = Lists.newArrayList();
+ // Ingress port vlan rule
+ expectedFlowRules.add(buildExpectedVlanInPortRule(
+ PORT_1, VLAN_100, null, VlanId.NONE,
+ FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN));
+ // forwarding classifier ipv4
+ expectedFlowRules.addAll(buildExpectedFwdClassifierRule(
+ PORT_1,
+ ROUTER_MAC,
+ null,
+ Ethernet.TYPE_IPV4,
+ FilteringObjectiveTranslator.FWD_IPV4_ROUTING));
+ // forwarding classifier ipv6
+ expectedFlowRules.addAll(buildExpectedFwdClassifierRule(
+ PORT_1,
+ ROUTER_MAC,
+ null,
+ Ethernet.TYPE_IPV6,
+ FilteringObjectiveTranslator.FWD_IPV6_ROUTING));
+ // forwarding classifier mpls
+ expectedFlowRules.addAll(buildExpectedFwdClassifierRule(
+ PORT_1,
+ ROUTER_MAC,
+ null,
+ Ethernet.MPLS_UNICAST,
+ FilteringObjectiveTranslator.FWD_MPLS));
+
+ ObjectiveTranslation expectedTranslation = buildExpectedTranslation(expectedFlowRules);
+ assertEquals(expectedTranslation, actualTranslation);
+ }
+
/* Utilities */
private void assertError(ObjectiveError error, ObjectiveTranslation actualTranslation) {
diff --git a/pipelines/fabric/impl/src/test/java/org/onosproject/pipelines/fabric/impl/behaviour/pipeliner/ForwardingObjectiveTranslatorTest.java b/pipelines/fabric/impl/src/test/java/org/onosproject/pipelines/fabric/impl/behaviour/pipeliner/ForwardingObjectiveTranslatorTest.java
index e005cfd..14253e7 100644
--- a/pipelines/fabric/impl/src/test/java/org/onosproject/pipelines/fabric/impl/behaviour/pipeliner/ForwardingObjectiveTranslatorTest.java
+++ b/pipelines/fabric/impl/src/test/java/org/onosproject/pipelines/fabric/impl/behaviour/pipeliner/ForwardingObjectiveTranslatorTest.java
@@ -185,6 +185,96 @@
assertTrue(expectedFlowRule.exactMatch(actualFlowRule));
}
+/**
+ * Test versatile flag of forwarding objective with acl drop.
+ */
+ @Test
+ public void testAclDrop() {
+ TrafficTreatment treatment = DefaultTrafficTreatment.builder()
+ .wipeDeferred()
+ .build();
+ // ACL 8-tuples like
+ TrafficSelector selector = DefaultTrafficSelector.builder()
+ .matchIPDst(IPV4_UNICAST_ADDR)
+ .build();
+ ForwardingObjective fwd = DefaultForwardingObjective.builder()
+ .withSelector(selector)
+ .withPriority(PRIORITY)
+ .fromApp(APP_ID)
+ .makePermanent()
+ .withFlag(ForwardingObjective.Flag.VERSATILE)
+ .withTreatment(treatment)
+ .add();
+
+ ObjectiveTranslation result = translator.translate(fwd);
+
+ List<FlowRule> flowRulesInstalled = (List<FlowRule>) result.flowRules();
+ List<GroupDescription> groupsInstalled = (List<GroupDescription>) result.groups();
+ assertEquals(1, flowRulesInstalled.size());
+ assertTrue(groupsInstalled.isEmpty());
+
+ FlowRule actualFlowRule = flowRulesInstalled.get(0);
+ PiAction piAction = PiAction.builder()
+ .withId(FabricConstants.FABRIC_INGRESS_ACL_DROP)
+ .build();
+ FlowRule expectedFlowRule = DefaultFlowRule.builder()
+ .forDevice(DEVICE_ID)
+ .forTable(FabricConstants.FABRIC_INGRESS_ACL_ACL)
+ .withPriority(PRIORITY)
+ .makePermanent()
+ .withSelector(selector)
+ .withTreatment(DefaultTrafficTreatment.builder()
+ .piTableAction(piAction).build())
+ .fromApp(APP_ID)
+ .build();
+
+ assertTrue(expectedFlowRule.exactMatch(actualFlowRule));
+ }
+
+ /**
+ * Test versatile flag of forwarding objective with acl nop.
+ */
+ @Test
+ public void testAclNop() {
+ TrafficTreatment treatment = DefaultTrafficTreatment.builder()
+ .build();
+ // ACL 8-tuples like
+ TrafficSelector selector = DefaultTrafficSelector.builder()
+ .matchIPDst(IPV4_UNICAST_ADDR)
+ .build();
+ ForwardingObjective fwd = DefaultForwardingObjective.builder()
+ .withSelector(selector)
+ .withPriority(PRIORITY)
+ .fromApp(APP_ID)
+ .makePermanent()
+ .withFlag(ForwardingObjective.Flag.VERSATILE)
+ .withTreatment(treatment)
+ .add();
+
+ ObjectiveTranslation result = translator.translate(fwd);
+
+ List<FlowRule> flowRulesInstalled = (List<FlowRule>) result.flowRules();
+ List<GroupDescription> groupsInstalled = (List<GroupDescription>) result.groups();
+ assertEquals(1, flowRulesInstalled.size());
+ assertTrue(groupsInstalled.isEmpty());
+
+ FlowRule actualFlowRule = flowRulesInstalled.get(0);
+ PiAction piAction = PiAction.builder()
+ .withId(FabricConstants.FABRIC_INGRESS_ACL_NOP_ACL)
+ .build();
+ FlowRule expectedFlowRule = DefaultFlowRule.builder()
+ .forDevice(DEVICE_ID)
+ .forTable(FabricConstants.FABRIC_INGRESS_ACL_ACL)
+ .withPriority(PRIORITY)
+ .makePermanent()
+ .withSelector(selector)
+ .withTreatment(DefaultTrafficTreatment.builder()
+ .piTableAction(piAction).build())
+ .fromApp(APP_ID)
+ .build();
+
+ assertTrue(expectedFlowRule.exactMatch(actualFlowRule));
+ }
/**
* Test programming L2 unicast rule to bridging table.