Fixing metadata for FTTB flows

Change-Id: I76a46626a1b42b0e15d04d86405b1309be30ef8c
diff --git a/impl/src/main/java/org/opencord/olt/impl/OltFlowService.java b/impl/src/main/java/org/opencord/olt/impl/OltFlowService.java
index 3a2c818..ebe0505 100644
--- a/impl/src/main/java/org/opencord/olt/impl/OltFlowService.java
+++ b/impl/src/main/java/org/opencord/olt/impl/OltFlowService.java
@@ -615,6 +615,7 @@
         // side is still up as nothing changed, so no need to add/remove flows, when and if the UNI comes up
         // we will re-push the EAPOL flow to require the subscriber to auth again.
         // When the subscriber is admin removed from REST or CLI we ignore the port status.
+        // Check the admin Status of the port
         if (!isPortPresent || sub.port.isEnabled() || sub.status == DiscoveredSubscriber.Status.ADMIN_REMOVED) {
 
             handleSubscriberDhcpFlows(sub.device.id(), sub.port, FlowOperation.REMOVE, si);
@@ -1836,7 +1837,7 @@
         }
 
         VlanId innerVlan = null;
-
+        treatmentBuilder.setOutput(nniPort.number());
         if (serviceName.equals(FTTB_SERVICE_DPU_MGMT_TRAFFIC) || serviceName.equals(FTTB_SERVICE_DPU_ANCP_TRAFFIC)) {
             MacAddress mac = FttbUtils.getMacAddressFromDhcpEnabledUti(
                     hostService, si, deviceId, port);
@@ -1848,15 +1849,15 @@
             }
 
             selectorBuilder.matchEthSrc(mac);
-            innerVlan = VlanId.NONE;
+
+            treatmentBuilder.writeMetadata(OltFlowServiceUtils.createMetadata(VlanId.NONE,
+                    uti.getTechnologyProfileId(), nniPort.number()), 0L);
 
         } else if (serviceName.equals(FTTB_SERVICE_SUBSCRIBER_TRAFFIC)) {
-            innerVlan = VlanId.ANY;
+            treatmentBuilder.writeMetadata(OltFlowServiceUtils.createMetadata(VlanId.ANY,
+                    uti.getTechnologyProfileId(), nniPort.number()), 0L);
         }
 
-        treatmentBuilder.setOutput(nniPort.number()).writeMetadata(OltFlowServiceUtils.createMetadata(innerVlan,
-                uti.getTechnologyProfileId(), nniPort.number()), 0L);
-
         DefaultForwardingObjective.Builder flowBuilder = createForwardingObjectiveBuilder(selectorBuilder.build(),
                 treatmentBuilder.build(), MIN_PRIORITY,
                 annotationBuilder.build());
@@ -1909,16 +1910,17 @@
 
             selectorBuilder.matchEthDst(mac);
             innerVlan = VlanId.NONE;
+            treatmentBuilder.writeMetadata(OltFlowServiceUtils.createMetadata(innerVlan,
+                    uti.getTechnologyProfileId(),
+                    port.number()), 0);
 
         } else if (serviceName.equals(FTTB_SERVICE_SUBSCRIBER_TRAFFIC)) {
-            innerVlan = VlanId.ANY;
-            selectorBuilder.matchMetadata(uti.getPonSTag().toShort());
+            selectorBuilder.matchMetadata(uti.getPonCTag().toShort());
+            treatmentBuilder.writeMetadata(OltFlowServiceUtils.createMetadata(VlanId.ANY,
+                    uti.getTechnologyProfileId(),
+                    port.number()), 0);
         }
 
-        treatmentBuilder.writeMetadata(OltFlowServiceUtils.createMetadata(innerVlan,
-                uti.getTechnologyProfileId(),
-                port.number()), 0);
-
         DefaultForwardingObjective.Builder flowBuilder = createForwardingObjectiveBuilder(selectorBuilder.build(),
                 treatmentBuilder.build(), MIN_PRIORITY, annotationBuilder.build());
 
diff --git a/impl/src/test/java/org/opencord/olt/impl/OltFlowServiceTest.java b/impl/src/test/java/org/opencord/olt/impl/OltFlowServiceTest.java
index 4196f57..35474b7 100644
--- a/impl/src/test/java/org/opencord/olt/impl/OltFlowServiceTest.java
+++ b/impl/src/test/java/org/opencord/olt/impl/OltFlowServiceTest.java
@@ -1068,6 +1068,7 @@
                 .setVlanPcp((byte) dpuMgmtUti.getUsPonSTagPriority())
                 .setOutput(PortNumber.CONTROLLER)
                 .meter(usBpMeterId)
+                //TODO why tests use this one and not the other method ?
                 .writeMetadata(OltFlowServiceUtils.createTechProfValueForWriteMetadata(VlanId.NONE,
                         dpuMgmtUti.getTechnologyProfileId(), usOltBpMeterId), 0L).build();
 
@@ -1438,7 +1439,7 @@
                     case FTTB_FLOW_DOWNSTREAM:
                         expectedSelectorBuilder
                                 .matchInPort(nniPort.number())
-                                .matchMetadata(uti.getPonSTag().toShort())
+                                .matchMetadata(uti.getPonCTag().toShort())
                                 .matchVlanId(uti.getPonSTag());
 
                         expectedTreatment.setVlanId(uti.getPonCTag())
@@ -1541,7 +1542,7 @@
                     case FTTB_FLOW_DOWNSTREAM:
                         expectedSelectorBuilder
                                 .matchInPort(nniPort.number())
-                                .matchMetadata(uti.getPonSTag().toShort())
+                                .matchMetadata(uti.getPonCTag().toShort())
                                 .matchVlanId(uti.getPonSTag());
 
                         expectedTreatment.setVlanId(uti.getPonCTag())