[ONOS-7285][ONOS-7263] VLAN support by fabric.p4

Change-Id: I9ea460bca2698eb74f0d4988830a1e7cc7bc2768
diff --git a/pipelines/fabric/src/test/java/org/onosproject/pipelines/fabric/pipeliner/FabricNextPipelinerTest.java b/pipelines/fabric/src/test/java/org/onosproject/pipelines/fabric/pipeliner/FabricNextPipelinerTest.java
index a21ca2a..a797a83 100644
--- a/pipelines/fabric/src/test/java/org/onosproject/pipelines/fabric/pipeliner/FabricNextPipelinerTest.java
+++ b/pipelines/fabric/src/test/java/org/onosproject/pipelines/fabric/pipeliner/FabricNextPipelinerTest.java
@@ -44,11 +44,36 @@
 import static org.junit.Assert.assertTrue;
 import static org.onosproject.pipelines.fabric.FabricConstants.ACT_PRF_FABRICINGRESS_NEXT_ECMP_SELECTOR_ID;
 import static org.onosproject.pipelines.fabric.FabricConstants.TBL_HASHED_ID;
+import static org.onosproject.pipelines.fabric.FabricConstants.TBL_VLAN_META_ID;
 
 /**
  * Test cases for fabric.p4 pipeline next control block.
  */
 public class FabricNextPipelinerTest extends FabricPipelinerTest {
+    private FlowRule vlanMetaFlowRule;
+
+    public FabricNextPipelinerTest() {
+        PiCriterion nextIdCriterion = PiCriterion.builder()
+                .matchExact(FabricConstants.HF_FABRIC_METADATA_NEXT_ID_ID, NEXT_ID_1)
+                .build();
+        TrafficSelector selector = DefaultTrafficSelector.builder()
+                .matchPi(nextIdCriterion)
+                .build();
+        TrafficTreatment treatment = DefaultTrafficTreatment.builder()
+                .setVlanId(VLAN_100)
+                .build();
+
+        vlanMetaFlowRule = DefaultFlowRule.builder()
+                .withSelector(selector)
+                .withTreatment(treatment)
+                .forTable(TBL_VLAN_META_ID)
+                .makePermanent()
+                // FIXME: currently next objective doesn't support priority, ignore this
+                .withPriority(0)
+                .forDevice(DEVICE_ID)
+                .fromApp(APP_ID)
+                .build();
+    }
 
     /**
      * Test program output rule for Simple table.
@@ -86,10 +111,25 @@
         testSimple(treatment);
     }
 
+    /**
+     * Test program set mac, set vlan, and output rule for Simple table.
+     */
+    @Test
+    public void testSimpleOutputWithVlanAndMacTranslation() {
+        TrafficTreatment treatment = DefaultTrafficTreatment.builder()
+                .setEthSrc(ROUTER_MAC)
+                .setEthDst(HOST_MAC)
+                .setVlanId(VLAN_100)
+                .setOutput(PORT_1)
+                .build();
+        testSimple(treatment);
+    }
+
     private void testSimple(TrafficTreatment treatment) {
         NextObjective nextObjective = DefaultNextObjective.builder()
                 .withId(NEXT_ID_1)
                 .withPriority(PRIORITY)
+                .withMeta(VLAN_META)
                 .addTreatment(treatment)
                 .withType(NextObjective.Type.SIMPLE)
                 .makePermanent()
@@ -100,7 +140,7 @@
 
         List<FlowRule> flowRulesInstalled = (List<FlowRule>) result.flowRules();
         List<GroupDescription> groupsInstalled = (List<GroupDescription>) result.groups();
-        assertEquals(1, flowRulesInstalled.size());
+        assertEquals(2, flowRulesInstalled.size());
         assertTrue(groupsInstalled.isEmpty());
 
         // Simple table
@@ -110,7 +150,12 @@
         TrafficSelector nextIdSelector = DefaultTrafficSelector.builder()
                 .matchPi(nextIdCriterion)
                 .build();
+
+        // VLAN meta table
         FlowRule actualFlowRule = flowRulesInstalled.get(0);
+        assertTrue(actualFlowRule.exactMatch(vlanMetaFlowRule));
+
+        actualFlowRule = flowRulesInstalled.get(1);
         FlowRule expectedFlowRule = DefaultFlowRule.builder()
                 .forDevice(DEVICE_ID)
                 .fromApp(APP_ID)
@@ -143,6 +188,7 @@
         NextObjective nextObjective = DefaultNextObjective.builder()
                 .withId(NEXT_ID_1)
                 .withPriority(PRIORITY)
+                .withMeta(VLAN_META)
                 .addTreatment(treatment1)
                 .addTreatment(treatment2)
                 .withType(NextObjective.Type.HASHED)
@@ -155,7 +201,7 @@
         // Should generates 2 flows and 1 group
         List<FlowRule> flowRulesInstalled = (List<FlowRule>) result.flowRules();
         List<GroupDescription> groupsInstalled = (List<GroupDescription>) result.groups();
-        assertEquals(1, flowRulesInstalled.size());
+        assertEquals(2, flowRulesInstalled.size());
         assertEquals(1, groupsInstalled.size());
 
         // Hashed table
@@ -169,7 +215,12 @@
         TrafficTreatment treatment = DefaultTrafficTreatment.builder()
                 .piTableAction(actionGroupId)
                 .build();
+
+        // VLAN meta table
         FlowRule actualFlowRule = flowRulesInstalled.get(0);
+        assertTrue(actualFlowRule.exactMatch(vlanMetaFlowRule));
+
+        actualFlowRule = flowRulesInstalled.get(1);
         FlowRule expectedFlowRule = DefaultFlowRule.builder()
                 .forDevice(DEVICE_ID)
                 .fromApp(APP_ID)
diff --git a/pipelines/fabric/src/test/java/org/onosproject/pipelines/fabric/pipeliner/FabricPipelinerTest.java b/pipelines/fabric/src/test/java/org/onosproject/pipelines/fabric/pipeliner/FabricPipelinerTest.java
index 5414998..c605e99 100644
--- a/pipelines/fabric/src/test/java/org/onosproject/pipelines/fabric/pipeliner/FabricPipelinerTest.java
+++ b/pipelines/fabric/src/test/java/org/onosproject/pipelines/fabric/pipeliner/FabricPipelinerTest.java
@@ -30,6 +30,8 @@
 import org.onosproject.net.behaviour.PipelinerContext;
 import org.onosproject.net.driver.Driver;
 import org.onosproject.net.driver.DriverHandler;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.TrafficSelector;
 import org.onosproject.net.flow.criteria.PiCriterion;
 import org.onosproject.net.group.GroupService;
 import org.onosproject.pipelines.fabric.FabricConstants;
@@ -54,6 +56,9 @@
     static final IpPrefix IPV6_MCAST_ADDR = IpPrefix.valueOf("ff00::1/32");
     static final MplsLabel MPLS_10 = MplsLabel.mplsLabel(10);
     static final Integer NEXT_ID_1 = 1;
+    static final TrafficSelector VLAN_META = DefaultTrafficSelector.builder()
+            .matchVlanId(VLAN_100)
+            .build();
 
     // Forwarding types
     static final byte FWD_BRIDGING = 0;