[SDFAB-522] Fix port type for pair ports

Additionally standardize the usage of the 64 bits carried in the metadata instruction.
Implements unit tests for different metadata configurations

Change-Id: I3382657c81876ec2eb0749f06f0fb9e96b2c0e6e
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 73039b5..5e126cc 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
@@ -46,11 +46,14 @@
 import static org.junit.Assert.assertEquals;
 import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.DEFAULT_PW_TRANSPORT_VLAN;
 import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.DEFAULT_VLAN;
+import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.EDGE_PORT;
 import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.ETH_TYPE_EXACT_MASK;
 import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.FWD_IPV4_ROUTING;
 import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.FWD_IPV6_ROUTING;
 import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.FWD_MPLS;
+import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.INFRA_PORT;
 import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.ONE;
+import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.PAIR_PORT;
 import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.PORT_TYPE_EDGE;
 import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.PORT_TYPE_INFRA;
 import static org.onosproject.pipelines.fabric.impl.behaviour.Constants.ZERO;
@@ -75,7 +78,7 @@
      */
     @Test
     public void testRouterMacAndVlanFilter() throws FabricPipelinerException {
-        FilteringObjective filteringObjective = buildFilteringObjective(ROUTER_MAC);
+        FilteringObjective filteringObjective = buildFilteringObjective(ROUTER_MAC, EDGE_PORT);
         ObjectiveTranslation actualTranslation = translator.translate(filteringObjective);
         Collection<FlowRule> expectedFlowRules = Lists.newArrayList();
         // in port vlan flow rule
@@ -137,6 +140,7 @@
         TrafficTreatment treatment = DefaultTrafficTreatment.builder()
                 .pushVlan()
                 .setVlanId(VLAN_100)
+                .writeMetadata(EDGE_PORT, 0xffffffffffffffffL)
                 .build();
         FilteringObjective filteringObjective = DefaultFilteringObjective.builder()
                 .permit()
@@ -182,6 +186,7 @@
         TrafficTreatment treatment = DefaultTrafficTreatment.builder()
                 .pushVlan()
                 .setVlanId(VLAN_100)
+                .writeMetadata(EDGE_PORT, 0xffffffffffffffffL)
                 .build();
         FilteringObjective filteringObjective = DefaultFilteringObjective.builder()
                 .permit()
@@ -223,7 +228,7 @@
      */
     @Test
     public void testFwdBridging() throws Exception {
-        FilteringObjective filteringObjective = buildFilteringObjective(null);
+        FilteringObjective filteringObjective = buildFilteringObjective(null, EDGE_PORT);
         ObjectiveTranslation actualTranslation = translator.translate(filteringObjective);
 
         // in port vlan flow rule
@@ -300,8 +305,9 @@
                 .withPriority(PRIORITY)
                 .fromApp(APP_ID)
                 .withMeta(DefaultTrafficTreatment.builder()
-                                  .popVlan()
-                                  .build())
+                        .popVlan()
+                        .writeMetadata(EDGE_PORT, 0xffffffffffffffffL)
+                        .build())
                 .permit()
                 .add();
         ObjectiveTranslation actualTranslation = translator.translate(filteringObjective);
@@ -369,7 +375,7 @@
                 .withPriority(PRIORITY)
                 .fromApp(APP_ID)
                 .withMeta(DefaultTrafficTreatment.builder()
-                        .writeMetadata(2, 0xffffffffffffffffL)
+                        .writeMetadata(10, 0xffffffffffffffffL)
                         .build())
                 .permit()
                 .add();
@@ -392,7 +398,7 @@
                 .withMeta(DefaultTrafficTreatment.builder()
                         .pushVlan()
                         .setVlanId(VLAN_200)
-                        .writeMetadata(2, 0xffffffffffffffffL)
+                        .writeMetadata(10, 0xffffffffffffffffL)
                         .build())
                 .permit()
                 .add();
@@ -418,7 +424,10 @@
                 .addCondition(Criteria.matchVlanId(VLAN_100))
                 .withPriority(PRIORITY)
                 .fromApp(APP_ID)
-                .withMeta(DefaultTrafficTreatment.builder().wipeDeferred().build())
+                .withMeta(DefaultTrafficTreatment.builder()
+                        .writeMetadata(EDGE_PORT, 0xffffffffffffffffL)
+                        .wipeDeferred()
+                        .build())
                 .permit()
                 .add();
         ObjectiveTranslation actualTranslation = translator.translate(filteringObjective);
@@ -464,6 +473,9 @@
                 .addCondition(Criteria.matchEthDst(ROUTER_MAC))
                 .addCondition(Criteria.matchVlanId(VlanId.vlanId((short) DEFAULT_PW_TRANSPORT_VLAN)))
                 .withPriority(PRIORITY)
+                .withMeta(DefaultTrafficTreatment.builder()
+                        .writeMetadata(INFRA_PORT, 0xffffffffffffffffL)
+                        .build())
                 .fromApp(APP_ID)
                 .permit()
                 .add();
@@ -505,6 +517,7 @@
                 .withMeta(DefaultTrafficTreatment.builder()
                         .pushVlan()
                         .setVlanId(VlanId.vlanId((short) DEFAULT_VLAN))
+                        .writeMetadata(INFRA_PORT, 0xffffffffffffffffL)
                         .build())
                 .permit()
                 .add();
@@ -536,6 +549,74 @@
         assertEquals(expectedTranslation, actualTranslation);
     }
 
+    /**
+     * Test is pair port scenarios for filtering objective.
+     */
+    @Test
+    public void testIsPairPort() throws FabricPipelinerException {
+        // Only pair port flag
+        FilteringObjective filteringObjective = DefaultFilteringObjective.builder()
+                .withKey(Criteria.matchInPort(PORT_1))
+                .addCondition(Criteria.matchEthDst(ROUTER_MAC))
+                .addCondition(Criteria.matchVlanId(VLAN_100))
+                .withPriority(PRIORITY)
+                .withMeta(DefaultTrafficTreatment.builder()
+                        .writeMetadata(PAIR_PORT, 0xffffffffffffffffL)
+                        .build())
+                .fromApp(APP_ID)
+                .permit()
+                .add();
+        ObjectiveTranslation actualTranslation = translator.translate(filteringObjective);
+
+        Collection<FlowRule> expectedFlowRules = Lists.newArrayList();
+        expectedFlowRules.add(buildExpectedVlanInPortRule(
+                PORT_1, VLAN_100, null, VlanId.NONE,
+                PORT_TYPE_INFRA, FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN));
+        expectedFlowRules.addAll(buildExpectedFwdClassifierRule(
+                PORT_1,
+                ROUTER_MAC,
+                null,
+                Ethernet.TYPE_IPV4,
+                FWD_IPV4_ROUTING));
+        expectedFlowRules.addAll(buildExpectedFwdClassifierRule(
+                PORT_1,
+                ROUTER_MAC,
+                null,
+                Ethernet.TYPE_IPV6,
+                FWD_IPV6_ROUTING));
+        expectedFlowRules.addAll(buildExpectedFwdClassifierRule(
+                PORT_1,
+                ROUTER_MAC,
+                null,
+                Ethernet.MPLS_UNICAST,
+                FWD_MPLS));
+
+        ObjectiveTranslation expectedTranslation = buildExpectedTranslation(expectedFlowRules);
+        assertEquals(expectedTranslation, actualTranslation);
+
+        // Pair port and config update flags
+        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()
+                        .writeMetadata(6, 0xffffffffffffffffL)
+                        .build())
+                .permit()
+                .add();
+
+        actualTranslation = translator.translate(filteringObjective);
+        expectedFlowRules = Lists.newArrayList();
+        // Ingress port vlan rule
+        expectedFlowRules.add(buildExpectedVlanInPortRule(
+                PORT_1, VLAN_100, null, VlanId.NONE, PORT_TYPE_INFRA,
+                FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN));
+        expectedTranslation = buildExpectedTranslation(expectedFlowRules);
+        assertEquals(expectedTranslation, actualTranslation);
+    }
+
     /* Utilities */
 
     private void assertError(ObjectiveError error, ObjectiveTranslation actualTranslation) {
@@ -543,10 +624,11 @@
         assertEquals(expectedTranslation, actualTranslation);
     }
 
-    private FilteringObjective buildFilteringObjective(MacAddress dstMac) {
+    private FilteringObjective buildFilteringObjective(MacAddress dstMac, long portType) {
         TrafficTreatment treatment = DefaultTrafficTreatment.builder()
                 .pushVlan()
                 .setVlanId(VLAN_100)
+                .writeMetadata(portType, 0xffffffffffffffffL)
                 .build();
         DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder()
                 .permit()