- Use setDA,setSA,output actions instead of using group for policy (but, it is NOT required)
 - Do not set DecNWTTL when setting ACL for policy (only for DELL)
 - Use 2 as Max number of MPLS labels (temporarily) - Need to be fixed

Change-Id: I31436c1c9beec9dec21319e46c50d738e8f60cba
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
index 5d5de8c..899caf3 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
@@ -1548,9 +1548,9 @@
                     MacAddress.of(destSwitch.getStringAttribute("routerMac"));
             SetSAAction setSAAction = new SetSAAction(srcMac);
             SetDAAction setDAAction = new SetDAAction(dstMac);
-            actions.add(outputAction);
             actions.add(setSAAction);
             actions.add(setDAAction);
+            actions.add(outputAction);
         } else {
             GroupAction groupAction = new GroupAction();
             for (String dpid: fwdSws)
@@ -1575,7 +1575,7 @@
      * @param fwdSwDpids neighbor set of the switch
      * @return PortNumber connected to one of the neighbors
      */
-    private PortNumber pickOnePort(Switch sw, List<String> fwdSwDpids) {
+    public PortNumber pickOnePort(Switch sw, List<String> fwdSwDpids) {
         for (Link link: sw.getOutgoingLinks()) {
             if (link.getDstSwitch().getDpid().toString().equals(fwdSwDpids.get(0)))
                 return link.getSrcPort().getNumber();
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicyTunnel.java b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicyTunnel.java
index 5ea9b13..30a7493 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicyTunnel.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicyTunnel.java
@@ -11,11 +11,17 @@
 import net.onrc.onos.core.matchaction.MatchActionOperationEntry;
 import net.onrc.onos.core.matchaction.MatchActionOperations.Operator;
 import net.onrc.onos.core.matchaction.action.Action;
-import net.onrc.onos.core.matchaction.action.DecNwTtlAction;
 import net.onrc.onos.core.matchaction.action.GroupAction;
+import net.onrc.onos.core.matchaction.action.OutputAction;
+import net.onrc.onos.core.matchaction.action.SetDAAction;
+import net.onrc.onos.core.matchaction.action.SetSAAction;
 import net.onrc.onos.core.matchaction.match.PacketMatch;
+import net.onrc.onos.core.topology.Switch;
+import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.PortNumber;
 import net.onrc.onos.core.util.SwitchPort;
 
+import org.projectfloodlight.openflow.types.MacAddress;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,14 +52,36 @@
 
             // Check PHP was done by stitching
             // If no MPLS label is added, then NW TTL needs to be decremented
-            if (route.getRoute().isEmpty()) {
-                DecNwTtlAction decNwTtlAction = new DecNwTtlAction(1);
-                actions.add(decNwTtlAction);
-            }
 
-            GroupAction groupAction = new GroupAction();
-            groupAction.setGroupId(route.getGroupId());
-            actions.add(groupAction);
+            if (route.getRoute().isEmpty()) {
+                // XXX
+                //DecNwTtlAction decNwTtlAction = new DecNwTtlAction(1);
+                //actions.add(decNwTtlAction);
+
+                Switch srcSw = srManager.getSwitch(route.getSrcSwDpid());
+                Switch destSwitch = srManager.getSwitch(route.getFwdSwDpid().get(0).toString());
+                MacAddress srcMac =
+                        MacAddress.of(srcSw.getStringAttribute("routerMac"));
+                MacAddress dstMac =
+                        MacAddress.of(destSwitch.getStringAttribute("routerMac"));
+                SetSAAction setSAAction = new SetSAAction(srcMac);
+                SetDAAction setDAAction = new SetDAAction(dstMac);
+                actions.add(setSAAction);
+                actions.add(setDAAction);
+
+                List<String> fwdSwDpids = new ArrayList<String>();
+                for (Dpid dpid: route.getFwdSwDpid()) {
+                    fwdSwDpids.add(dpid.toString());
+                }
+                PortNumber port = srManager.pickOnePort(srcSw, fwdSwDpids);
+                OutputAction outputAction = new OutputAction(port);
+                actions.add(outputAction);
+            }
+            else {
+                GroupAction groupAction = new GroupAction();
+                groupAction.setGroupId(route.getGroupId());
+                actions.add(groupAction);
+            }
 
             MatchAction matchAction = new MatchAction(new MatchActionId(
                     srManager.getNextMatchActionID()),
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingTunnel.java b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingTunnel.java
index e48ab0c..dd76a50 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingTunnel.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingTunnel.java
@@ -24,7 +24,7 @@
     private List<TunnelRouteInfo> routes;
     private SegmentRoutingManager srManager;
 
-    private final int MAX_NUM_LABELS = 3;
+    private final int MAX_NUM_LABELS = 2;
 
     /**
      * Constructor