Refactored DestinationSet and nextobj for pws.

- Removed the booleans in destination test set and refactored
  it to use a proper enumeration.
- Create a special next objective for pseudowire transport that
  does not pop the tag.
- Install special filtering rules for receiving trafffic for
  pseudowires in all devices.

Change-Id: I665a00d9a766e026d35799fe2f12d56419cb55cd
diff --git a/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java b/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
index 90da4b4..77103f1 100644
--- a/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
+++ b/app/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java
@@ -80,6 +80,8 @@
 import static org.onosproject.segmentrouting.SegmentRoutingManager.INTERNAL_VLAN;
 import static org.onosproject.segmentrouting.SegmentRoutingService.DEFAULT_PRIORITY;
 
+import static org.onosproject.segmentrouting.SegmentRoutingManager.PSEUDOWIRE_VLAN;
+
 /**
  * Populator of segment routing flow rules.
  */
@@ -539,6 +541,7 @@
         TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
         DestinationSet ds;
         TrafficTreatment treatment;
+        DestinationSet.DestinationSetType dsType;
 
         if (destSw2 == null) {
             // single dst - create destination set based on next-hop
@@ -547,18 +550,17 @@
             Set<DeviceId> nhd1 = nextHops.get(destSw1);
             if (nhd1.size() == 1 && nhd1.iterator().next().equals(destSw1)) {
                 tbuilder.immediate().decNwTtl();
-                ds = new DestinationSet(false, false, destSw1);
+                ds = DestinationSet.createTypePushNone(destSw1);
                 treatment = tbuilder.build();
             } else {
-                ds = new DestinationSet(false, false, segmentId1, destSw1);
+                ds = DestinationSet.createTypePushBos(segmentId1, destSw1);
                 treatment = null;
             }
         } else {
             // dst pair - IP rules for dst-pairs are always from other edge nodes
             // the destination set needs to have both destinations, even if there
             // are no next hops to one of them
-            ds = new DestinationSet(false, false, segmentId1, destSw1,
-                                    segmentId2, destSw2);
+            ds = DestinationSet.createTypePushBos(segmentId1, destSw1, segmentId2, destSw2);
             treatment = null;
         }
 
@@ -827,6 +829,7 @@
 
         TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
         DestinationSet ds = null;
+        DestinationSet.DestinationSetType dstType = null;
         boolean simple = false;
         if (phpRequired) {
             // php case - pop should always be flow-action
@@ -841,17 +844,15 @@
                 tbuilder.decNwTtl();
                 // standard case -> BoS == True; pop results in IP packet and forwarding
                 // is via an ECMP group
-                ds = new DestinationSet(false, false, destSw);
+                ds = DestinationSet.createTypePopBos(destSw);
             } else {
                 tbuilder.deferred().popMpls(EthType.EtherType.MPLS_UNICAST.ethType())
                     .decMplsTtl();
                 // double-label case -> BoS == False, pop results in MPLS packet
                 // depending on configuration we can ECMP this packet or choose one output
-                if (srManager.getMplsEcmp()) {
-                    ds = new DestinationSet(true, false, destSw);
-                } else {
-                    ds = new DestinationSet(true, false, destSw);
-                    simple = true;
+                ds = DestinationSet.createTypePopNotBos(destSw);
+                if (!srManager.getMplsEcmp()) {
+                   simple = true;
                 }
             }
         } else {
@@ -860,11 +861,10 @@
             tbuilder.deferred().decMplsTtl();
             // swap results in MPLS packet with same BoS bit regardless of bit value
             // depending on configuration we can ECMP this packet or choose one output
-            // XXX reconsider types
-            if (srManager.getMplsEcmp()) {
-                ds = new DestinationSet(false, true, segmentId, destSw);
-            } else {
-                ds = new DestinationSet(false, true, segmentId, destSw);
+            // differentiate here between swap with not bos or swap with bos
+            ds = isBos ? DestinationSet.createTypeSwapBos(segmentId, destSw) :
+                    DestinationSet.createTypeSwapNotBos(segmentId, destSw);
+            if (!srManager.getMplsEcmp()) {
                 simple = true;
             }
         }
@@ -975,6 +975,10 @@
             if (!processSinglePortFiltersInternal(deviceId, portnum, true, INTERNAL_VLAN, install)) {
                 return false;
             }
+            // Filter for receiveing pseudowire traffic
+            if (!processSinglePortFiltersInternal(deviceId, portnum, false, PSEUDOWIRE_VLAN, install)) {
+                return false;
+            }
         }
         return true;
     }