Fix the bug of segment stitching

Change-Id: I3ab2a04786212a165c189c1546710aec17510016
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 c29fc65..f8bfc11 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
@@ -1095,7 +1095,6 @@
             log.debug("Failed to get the policy rule.");
             return false;
         }
-        //HashMap<String, Integer> switchGroupPair = new HashMap<String, Integer>();
         for (TunnelRouteInfo route: stitchingRule) {
 
             IOF13Switch targetSw = (IOF13Switch) floodlightProvider.getMasterSwitch(
@@ -1112,11 +1111,8 @@
 
             printTunnelInfo(targetSw, tunnelId, route.getRoute(), ns);
             targetSw.createTunnel(tunnelId, route.getRoute(), ns);
-            //switchGroupPair.put(route.srcSwDpid.toString(), groupId);
-
         }
 
-        //tunnelGroupMap.put(tunnelId, switchGroupPair);
         TunnelInfo tunnelInfo = new TunnelInfo(tunnelId, labelIds, stitchingRule);
         tunnelTable.put(tunnelId, tunnelInfo);
 
@@ -1214,7 +1210,7 @@
             TunnelRouteInfo routeInfo = new TunnelRouteInfo();
             routeInfo.setSrcDpid(srcSw.getDpid().toString());
             String nodeId = route.get(1);
-            List<Dpid> fwdSwDpids = getForwardingSwitchForNodeId(srcSw, route.get(1));
+            List<Dpid> fwdSwDpids = getForwardingSwitchForNodeId(srcSw, nodeId);
             for (Dpid dpid: fwdSwDpids) {
                 if (getMplsLabel(dpid.toString()).toString().equals(nodeId)) {
                     List<Dpid> fwdSws = new ArrayList<Dpid>();
@@ -1374,7 +1370,7 @@
 
         // Check if the tunnel is used for any policy
         for (PolicyInfo policyInfo: policyTable.values()) {
-            if (policyInfo.tunnelId == tunnelId) {
+            if (policyInfo.tunnelId.equals(tunnelId)) {
                 log.debug("Tunnel {} is still used for the policy {}.",
                         policyInfo.policyId, tunnelId);
                 return false;
@@ -1442,7 +1438,8 @@
                             fwdSws.add(destSw.getDpid());
                         }
                         else {
-                            fwdSws.add(via.get(0));
+                            Dpid firstVia = via.get(via.size()-1);
+                            fwdSws.add(firstVia);
                         }
                     }
                 }