Added the feature to send policy and tunnel information to other onos core using hazelcast channel
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/PolicyNotification.java b/src/main/java/net/onrc/onos/apps/segmentrouting/PolicyNotification.java
new file mode 100644
index 0000000..6fbcc07
--- /dev/null
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/PolicyNotification.java
@@ -0,0 +1,70 @@
+package net.onrc.onos.apps.segmentrouting;
+
+import java.io.Serializable;
+
+import net.onrc.onos.apps.segmentrouting.SegmentRoutingPolicy.PolicyType;
+import net.onrc.onos.core.matchaction.match.PacketMatch;
+
+public class PolicyNotification implements Serializable {
+
+    private String policyId;
+    private String policyType;
+    private int priority;
+    private PacketMatch match;
+    private String tunnelId;  // XXX need to define PolicyTunnelNotification
+    /**
+     *
+     */
+    private static final long serialVersionUID = 1L;
+
+    protected PolicyNotification() {
+
+    }
+
+    public PolicyNotification(String pid) {
+        this.policyId = pid;
+    }
+
+    public PolicyNotification(SegmentRoutingPolicy srPolicy) {
+        this.policyId = srPolicy.getPolicyId();
+        this.policyType = srPolicy.getType().toString();
+        this.priority = srPolicy.getPriority();
+        this.match = srPolicy.getMatch();
+
+        // XXX need to be processed in PolicyTunnelNotification
+        if (PolicyType.valueOf(policyType) == PolicyType.TUNNEL_FLOW) {
+            this.tunnelId = ((SegmentRoutingPolicyTunnel)srPolicy).getTunnelId();
+        }
+    }
+
+
+
+    public String getPolicyId() {
+        return policyId;
+    }
+
+    public String getPolicyType() {
+        return policyType;
+    }
+
+    public int getPriority() {
+        return priority;
+    }
+
+    public PacketMatch getPacketMatch() {
+        return match;
+    }
+
+    public String toString() {
+        return "Policy-ID:" + policyId;
+    }
+
+    public void setTunnelId(String tid) {
+        this.tunnelId = tid;
+    }
+
+    public String getTunnelId() {
+        return tunnelId;
+    }
+
+}
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 7bfc003..216c3c9 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
@@ -34,20 +34,18 @@
 import net.onrc.onos.api.packet.IPacketListener;
 import net.onrc.onos.api.packet.IPacketService;
 import net.onrc.onos.apps.segmentrouting.SegmentRoutingPolicy.PolicyType;
-import net.onrc.onos.apps.segmentrouting.SegmentRoutingTunnel.TunnelRouteInfo;
 import net.onrc.onos.apps.segmentrouting.web.SegmentRoutingWebRoutable;
+import net.onrc.onos.core.datagrid.IDatagridService;
+import net.onrc.onos.core.datagrid.IEventChannel;
+import net.onrc.onos.core.datagrid.IEventChannelListener;
 import net.onrc.onos.core.drivermanager.OFSwitchImplDellOSR;
 import net.onrc.onos.core.flowprogrammer.IFlowPusherService;
 import net.onrc.onos.core.intent.Path;
 import net.onrc.onos.core.main.config.IConfigInfoService;
 import net.onrc.onos.core.matchaction.MatchAction;
-import net.onrc.onos.core.matchaction.MatchActionFloodlightService;
 import net.onrc.onos.core.matchaction.MatchActionId;
 import net.onrc.onos.core.matchaction.MatchActionOperationEntry;
-import net.onrc.onos.core.matchaction.MatchActionOperations;
 import net.onrc.onos.core.matchaction.MatchActionOperations.Operator;
-import net.onrc.onos.core.matchaction.MatchActionOperationsId;
-import net.onrc.onos.core.matchaction.MatchActionService;
 import net.onrc.onos.core.matchaction.action.Action;
 import net.onrc.onos.core.matchaction.action.CopyTtlInAction;
 import net.onrc.onos.core.matchaction.action.CopyTtlOutAction;
@@ -68,6 +66,7 @@
 import net.onrc.onos.core.packet.ARP;
 import net.onrc.onos.core.packet.Ethernet;
 import net.onrc.onos.core.packet.IPv4;
+import net.onrc.onos.core.registry.IControllerRegistryService;
 import net.onrc.onos.core.topology.ITopologyListener;
 import net.onrc.onos.core.topology.ITopologyService;
 import net.onrc.onos.core.topology.Link;
@@ -78,10 +77,12 @@
 import net.onrc.onos.core.topology.PortData;
 import net.onrc.onos.core.topology.Switch;
 import net.onrc.onos.core.topology.SwitchData;
+import net.onrc.onos.core.topology.TopologyEvent;
 import net.onrc.onos.core.topology.TopologyEvents;
+import net.onrc.onos.core.topology.TopologyManager;
 import net.onrc.onos.core.util.Dpid;
 import net.onrc.onos.core.util.IPv4Net;
-import net.onrc.onos.core.util.IdGenerator;
+import net.onrc.onos.core.util.OnosInstanceId;
 import net.onrc.onos.core.util.PortNumber;
 import net.onrc.onos.core.util.SwitchPort;
 
@@ -101,8 +102,11 @@
             .getLogger(SegmentRoutingManager.class);
 
     private ITopologyService topologyService;
+    private IDatagridService datagridService;
+    private IControllerRegistryService registryService;
+    private IEventChannel<Long, PolicyNotification> policyEventChannel;
+    private IEventChannel<Long, TunnelNotification> tunnelEventChannel;
     private IPacketService packetService;
-    private MatchActionService matchActionService;
     private MutableTopology mutableTopology;
     private ConcurrentLinkedQueue<IPv4> ipPacketQueue;
     private IRestApiService restApi;
@@ -124,6 +128,9 @@
     private HashMap<String, SegmentRoutingTunnel> tunnelTable;
     private HashMap<Integer, HashMap<Integer, List<Integer>>> adjacencySidTable;
     private HashMap<String, HashMap<Integer, Integer>> adjcencyGroupIdTable;
+    private List<String> switchDpidListWithMastership;
+    private PolicyEventHandler policyEventHandler;
+    private TunnelEventHandler tunnelEventHandler;
 
     private int operationMode = 0;
 
@@ -135,13 +142,13 @@
     private int numOfEvents = 0;
     private int numOfEventProcess = 0;
     private int numOfPopulation = 0;
-    // private long matchActionId = 0L;
-    private IdGenerator<MatchActionId> maIdGenerator;
-    private IdGenerator<MatchActionOperationsId> maoIdGenerator;
-    private List<String> switchDpidListWithMastership;
+    private long matchActionId = 0L;
+
+
+    private static final String SR_POLICY_CHANNEL_NAME = "onos.sr_policy";
+    private static final String SR_TUNNEL_CHANNEL_NAME = "onos.sr_tunnel";
 
     private final int DELAY_TO_ADD_LINK = 10;
-    private final int MAX_NUM_LABELS = 3;
 
     private final int POLICY_ADD1 = 1;
     private final int POLICY_ADD2 = 2;
@@ -180,9 +187,6 @@
         l.add(IFlowPusherService.class);
         l.add(ITopologyService.class);
         l.add(IRestApiService.class);
-        // l.add(MatchActionModule.class);
-        // l.add(MatchActionComponent.class);
-        l.add(MatchActionFloodlightService.class);
 
         return l;
 
@@ -191,6 +195,8 @@
     @Override
     public void init(FloodlightModuleContext context) throws FloodlightModuleException {
         floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class);
+        datagridService = context.getServiceImpl(IDatagridService.class);
+        registryService = context.getServiceImpl(IControllerRegistryService.class);
         arpHandler = new ArpHandler(context, this);
         icmpHandler = new IcmpHandler(context, this);
         ipHandler = new GenericIpHandler(context, this);
@@ -204,13 +210,14 @@
         linksToAdd = new HashMap<String, LinkData>();
         topologyEventQueue = new ConcurrentLinkedQueue<TopologyEvents>();
         packetService = context.getServiceImpl(IPacketService.class);
-        matchActionService = context.getServiceImpl(MatchActionFloodlightService.class);
         restApi = context.getServiceImpl(IRestApiService.class);
         policyTable = new HashMap<String, SegmentRoutingPolicy>();
         tunnelTable = new HashMap<String, SegmentRoutingTunnel>();
         adjacencySidTable = new HashMap<Integer,HashMap<Integer, List<Integer>>>();
         adjcencyGroupIdTable = new HashMap<String, HashMap<Integer, Integer>>();
         switchDpidListWithMastership = new ArrayList<String>();
+        policyEventHandler = new PolicyEventHandler();
+        tunnelEventHandler = new TunnelEventHandler();
 
         packetService.registerPacketListener(this);
         topologyService.addListener(this, false);
@@ -219,12 +226,19 @@
 
     @Override
     public void startUp(FloodlightModuleContext context) throws FloodlightModuleException {
-        maIdGenerator = matchActionService.getMatchActionIdGenerator();
-        maoIdGenerator = matchActionService.getMatchActionOperationsIdGenerator();
-
         ScheduledExecutorService ses = threadPool.getScheduledExecutor();
         restApi.addRestletRoutable(new SegmentRoutingWebRoutable());
 
+        policyEventChannel = datagridService.addListener(SR_POLICY_CHANNEL_NAME,
+                policyEventHandler,
+                Long.class,
+                PolicyNotification.class);
+
+        tunnelEventChannel = datagridService.addListener(SR_TUNNEL_CHANNEL_NAME,
+                tunnelEventHandler,
+                Long.class,
+                TunnelNotification.class);
+
         discoveryTask = new SingletonTask(ses, new Runnable() {
             @Override
             public void run() {
@@ -266,6 +280,60 @@
         }
     }
 
+    private class PolicyEventHandler implements
+    IEventChannelListener<Long, PolicyNotification> {
+
+        @Override
+        public void entryAdded(PolicyNotification policyNotication) {
+            log.debug("Policy entry {} was added", policyNotication);
+            if (PolicyType.valueOf(policyNotication.getPolicyType()) ==
+                    PolicyType.TUNNEL_FLOW) {
+                SegmentRoutingPolicyTunnel srPolicy =
+                        new SegmentRoutingPolicyTunnel(policyNotication);
+                policyTable.put(srPolicy.getPolicyId(), srPolicy);
+            }
+        }
+
+        @Override
+        public void entryRemoved(PolicyNotification value) {
+            log.debug("Policy entry {} was removed", value);
+
+        }
+
+        @Override
+        public void entryUpdated(PolicyNotification value) {
+            log.debug("Policy entry {} was updatged", value);
+
+        }
+
+    }
+
+    private class TunnelEventHandler implements
+    IEventChannelListener<Long, TunnelNotification> {
+
+        @Override
+        public void entryAdded(TunnelNotification tunnelNotification) {
+            SegmentRoutingTunnel srTunnel =
+                    new SegmentRoutingTunnel(tunnelNotification);
+            tunnelTable.put(srTunnel.getTunnelId(), srTunnel);
+        }
+
+        @Override
+        public void entryRemoved(TunnelNotification value) {
+            // TODO Auto-generated method stub
+
+        }
+
+        @Override
+        public void entryUpdated(TunnelNotification value) {
+            // TODO Auto-generated method stub
+
+        }
+
+    }
+
+
+
 
     // ************************************
     // Topology event handlers
@@ -284,32 +352,20 @@
             processMastershipAdded(topologyEvents.getAddedMastershipDataEntries());
         }
         else {
+
             if (operationMode == 0) {
                 discoveryTask.reschedule(20, TimeUnit.SECONDS);
                 operationMode = 1; // Wait until all switches are up ..
             }
-            else if (operationMode == 1) { // waiting for all switches to be up
+            else if (operationMode == 1){ // waiting for all switches to be up
                 // Do nothing
             }
-            else if (operationMode == 2) { // all switches are up and we need to
-                                           // handle events quickly.
+            else if (operationMode == 2) { // all switches are up and we need to handle events quickly.
                 topologyEventQueue.add(topologyEvents);
                 discoveryTask.reschedule(100, TimeUnit.MILLISECONDS);
             }
-
-            // discoveryTask.reschedule(100, TimeUnit.MILLISECONDS);
-            // log.debug("A task is scheduled to handle events {}",
-            // topologyEvents);
         }
-    }
 
-    private void processMastershipAdded(
-            Collection<MastershipData> mastershipAdded) {
-        for (MastershipData mastershipData : mastershipAdded) {
-            String dpid = mastershipData.getDpid().toString();
-            if (!switchDpidListWithMastership.contains(dpid))
-                switchDpidListWithMastership.add(dpid);
-        }
     }
 
     /**
@@ -422,6 +478,17 @@
                 numOfPopulation);
     }
 
+
+
+    private void processMastershipAdded(
+            Collection<MastershipData> mastershipAdded) {
+        for (MastershipData mastershipData: mastershipAdded) {
+            String dpid = mastershipData.getDpid().toString();
+            if (!switchDpidListWithMastership.contains(dpid))
+                switchDpidListWithMastership.add(dpid);
+        }
+    }
+
     /**
      * Process the SwitchAdded events from topologyMananger.
      * It does nothing. When a switch is added, then link will be added too.
@@ -638,14 +705,17 @@
      * @param modified if true, it "modifies" the rules
      */
     private void populateEcmpRoutingRules(boolean modified) {
+
+        printAllLinks();
+
         graphs.clear();
         Iterable<Switch> switches = mutableTopology.getSwitches();
         for (Switch sw : switches) {
             if (switchDpidListWithMastership.contains(sw.getDpid().toString())) {
                 ECMPShortestPathGraph ecmpSPG = new ECMPShortestPathGraph(sw);
                 graphs.put(sw, ecmpSPG);
-                // log.debug("ECMPShortestPathGraph is computed for switch {}",
-                // HexString.toHexString(sw.getDpid().value()));
+                //log.debug("ECMPShortestPathGraph is computed for switch {}",
+                //        HexString.toHexString(sw.getDpid().value()));
                 populateEcmpRoutingRulesForPath(sw, ecmpSPG, modified);
 
                 // Set adjacency routing rule for all switches
@@ -660,6 +730,7 @@
         numOfPopulation++;
     }
 
+
     /**
      * populate the MPLS rules to handle Adjacency IDs
      *
@@ -793,12 +864,6 @@
 
     }
 
-    public void executeMatchActionOpEntry(MatchActionOperationEntry maEntry) {
-        MatchActionOperations mao = new MatchActionOperations(maoIdGenerator.getNewId());
-        mao.addOperation(maEntry);
-        matchActionService.executeOperations(mao);
-    }
-
     /**
      * Push the MPLS rule for Adjacency ID
      *
@@ -847,24 +912,23 @@
             actions.add(groupAction);
         }
 
-        MatchAction matchAction = new MatchAction(maIdGenerator.getNewId(),
-                new SwitchPort(sw.getDpid().value(), (short) 0), mplsMatch, actions);
+        MatchAction matchAction = new MatchAction(new MatchActionId(matchActionId++),
+                new SwitchPort((long) 0, (short) 0), mplsMatch, actions);
         Operator operator = Operator.ADD;
         MatchActionOperationEntry maEntry =
                 new MatchActionOperationEntry(operator, matchAction);
-        executeMatchActionOpEntry(maEntry);
 
-        /* IOF13Switch sw13 = (IOF13Switch) floodlightProvider.getMasterSwitch(
-                 sw.getDpid().value());
+        IOF13Switch sw13 = (IOF13Switch) floodlightProvider.getMasterSwitch(
+                sw.getDpid().value());
 
-         if (sw13 != null) {
-             try {
-                 //printMatchActionOperationEntry(sw, maEntry);
-                 sw13.pushFlow(maEntry);
-             } catch (IOException e) {
-                 e.printStackTrace();
-             }
-         }*/
+        if (sw13 != null) {
+            try {
+                //printMatchActionOperationEntry(sw, maEntry);
+                sw13.pushFlow(maEntry);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
     }
 
     /**
@@ -1002,14 +1066,6 @@
         }
 
         if (!entries.isEmpty()) {
-            MatchActionOperations mao = new MatchActionOperations(
-                    maoIdGenerator.getNewId());
-            for (MatchActionOperationEntry maEntry : entries)
-                mao.addOperation(maEntry);
-            matchActionService.executeOperations(mao);
-        }
-
-        /*if (!entries.isEmpty()) {
             IOF13Switch sw13 = (IOF13Switch) floodlightProvider.getMasterSwitch(
                     targetSw.getDpid().value());
 
@@ -1020,7 +1076,7 @@
                     e.printStackTrace();
                 }
             }
-        }*/
+        }
 
     }
 
@@ -1082,8 +1138,8 @@
         }
         actions.add(groupAction);
 
-        MatchAction matchAction = new MatchAction(maIdGenerator.getNewId(),
-                new SwitchPort(sw.getDpid().value(), (short) 0), ipMatch, actions);
+        MatchAction matchAction = new MatchAction(new MatchActionId(matchActionId++),
+                new SwitchPort((long) 0, (short) 0), ipMatch, actions);
 
         Operator operator = null;
         if (modified)
@@ -1094,22 +1150,21 @@
         MatchActionOperationEntry maEntry =
                 new MatchActionOperationEntry(operator, matchAction);
 
+        IOF13Switch sw13 = (IOF13Switch) floodlightProvider.getMasterSwitch(sw.getDpid().value());
         //        getSwId(sw.getDpid().toString()));
 
-        if (entries != null)
-            entries.add(maEntry);
-        else {
-            executeMatchActionOpEntry(maEntry);
-            /*IOF13Switch sw13 = (IOF13Switch)
-                    floodlightProvider.getMasterSwitch(sw.getDpid().value());
-            if (sw13 != null) {
-                try {
+        if (sw13 != null) {
+            try {
+                //printMatchActionOperationEntry(sw, maEntry);
+                if (entries != null)
+                    entries.add(maEntry);
+                else
                     sw13.pushFlow(maEntry);
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
-            }*/
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
         }
+
     }
 
     /**
@@ -1147,12 +1202,7 @@
             maEntries.add(buildMAEntry(sw, mplsLabel, fwdSws, false, true));
             maEntries.add(buildMAEntry(sw, mplsLabel, fwdSws, false, false));
         }
-        MatchActionOperations mao = new MatchActionOperations(
-                maoIdGenerator.getNewId());
-        for (MatchActionOperationEntry maEntry : maEntries)
-            mao.addOperation(maEntry);
-        matchActionService.executeOperations(mao);
-        /*IOF13Switch sw13 = (IOF13Switch) floodlightProvider.getMasterSwitch(
+        IOF13Switch sw13 = (IOF13Switch) floodlightProvider.getMasterSwitch(
                 sw.getDpid().value());
 
         if (sw13 != null) {
@@ -1162,7 +1212,7 @@
             } catch (IOException e) {
                 e.printStackTrace();
             }
-        }*/
+        }
     }
 
 
@@ -1230,6 +1280,10 @@
                 new SegmentRoutingTunnel(this, tunnelId, labelIds);
         if (srTunnel.createTunnel()) {
             tunnelTable.put(tunnelId, srTunnel);
+            TunnelNotification tunnelNotification =
+                    new TunnelNotification(srTunnel);
+            tunnelEventChannel.addTransientEntry(Long.valueOf(1),
+                    tunnelNotification);
             return true;
         }
         else {
@@ -1295,9 +1349,14 @@
                            priority, tid);
             if (srPolicy.createPolicy()) {
                 policyTable.put(pid, srPolicy);
+                PolicyNotification policyNotification =
+                        new PolicyNotification(srPolicy);
+                policyEventChannel.addTransientEntry(Long.valueOf(1),
+                        policyNotification);
                 return true;
             }
-            else {                log.warn("Failed to create a policy");
+            else {
+                log.warn("Failed to create a policy");
                 return false;
             }
         }
@@ -1417,9 +1476,9 @@
      *
      * @return MatchAction ID
      */
-    // public long getNextMatchActionID() {
-    // return this.matchActionId++;
-    // }
+    public long getNextMatchActionID() {
+        return this.matchActionId++;
+    }
 
     /**
      * Get ports for the adjacency SID given
@@ -1613,8 +1672,8 @@
             actions.add(groupAction);
         }
 
-        MatchAction matchAction = new MatchAction(maIdGenerator.getNewId(),
-                new SwitchPort(sw.getDpid().value(), (short) 0), mplsMatch, actions);
+        MatchAction matchAction = new MatchAction(new MatchActionId(matchActionId++),
+                new SwitchPort((long) 0, (short) 0), mplsMatch, actions);
         Operator operator = Operator.ADD;
         MatchActionOperationEntry maEntry =
                 new MatchActionOperationEntry(operator, matchAction);
@@ -1946,7 +2005,37 @@
     }
 
     public MatchActionId getMatchActionId() {
-        return maIdGenerator.getNewId();
+        return new MatchActionId(matchActionId++);
+    }
+
+    private void printAllLinks() {
+
+        int i = 1;
+        for (Switch sw: mutableTopology.getSwitches()) {
+            log.debug("Switch {} : {}", i++, sw.getDpid().toString());
+        }
+        i = 1;
+        for (Link link: mutableTopology.getLinks()) {
+            log.debug("Link {} : {}", i++, link.toString());
+        }
+
+    }
+
+    public IEventChannel<byte[], TopologyEvent> getEventChannel() {
+
+        return datagridService.createChannel(
+                TopologyManager.EVENT_CHANNEL_NAME,
+                byte[].class,
+                TopologyEvent.class);
+    }
+
+    /**
+     * Gets the ONOS Instance ID.
+     *
+     * @return the ONOS Instance ID.
+     */
+    public OnosInstanceId getOnosInstanceId() {
+        return registryService.getOnosInstanceId();
     }
 
     // ************************************
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicy.java b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicy.java
index 9906d74..86c0009 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicy.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicy.java
@@ -39,6 +39,14 @@
         this.type = type;
     }
 
+    public SegmentRoutingPolicy(
+            PolicyNotification policyNotication) {
+        this.policyId = policyNotication.getPolicyId();
+        this.match = policyNotication.getPacketMatch();
+        this.priority = policyNotication.getPriority();
+        this.type = PolicyType.valueOf(policyNotication.getPolicyType());
+    }
+
     /**
      * Get the policy ID
      *
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 c3f3428..0409f33 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicyTunnel.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingPolicyTunnel.java
@@ -5,8 +5,8 @@
 import java.util.List;
 
 import net.floodlightcontroller.core.IOF13Switch;
-import net.onrc.onos.apps.segmentrouting.SegmentRoutingTunnel.TunnelRouteInfo;
 import net.onrc.onos.core.matchaction.MatchAction;
+import net.onrc.onos.core.matchaction.MatchActionId;
 import net.onrc.onos.core.matchaction.MatchActionOperationEntry;
 import net.onrc.onos.core.matchaction.MatchActionOperations.Operator;
 import net.onrc.onos.core.matchaction.action.Action;
@@ -25,6 +25,8 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.esotericsoftware.minlog.Log;
+
 public class SegmentRoutingPolicyTunnel extends SegmentRoutingPolicy {
 
     private static final Logger log = LoggerFactory
@@ -38,6 +40,11 @@
         this.tunnelId = tid;
     }
 
+    public SegmentRoutingPolicyTunnel(PolicyNotification policyNotication) {
+        super(policyNotication);
+        this.tunnelId = policyNotication.getTunnelId();
+    }
+
     @Override
     public boolean createPolicy() {
 
@@ -81,15 +88,14 @@
                 actions.add(groupAction);
             }
 
-            MatchAction matchAction = new MatchAction(
-                    srManager.getMatchActionId(),
+            MatchAction matchAction = new MatchAction(new MatchActionId(
+                    srManager.getNextMatchActionID()),
                     new SwitchPort((long) 0, (short) 0), match, priority,
                     actions);
             MatchActionOperationEntry maEntry =
                     new MatchActionOperationEntry(Operator.ADD, matchAction);
-            srManager.executeMatchActionOpEntry(maEntry);
 
-            /*IOF13Switch sw13 = srManager.getIOF13Switch(route.getSrcSwDpid());
+            IOF13Switch sw13 = srManager.getIOF13Switch(route.getSrcSwDpid());
 
             if (sw13 != null) {
                 srManager.printMatchActionOperationEntry(sw13, maEntry);
@@ -103,7 +109,7 @@
             else {
                 Log.warn("Cannot find the target switch {}", route.getSrcSwDpid());
                 return false;
-            }*/
+            }
         }
 
         return true;
@@ -118,8 +124,8 @@
         groupAction.setGroupId(gropuId);
         actions.add(groupAction);
 
-        MatchAction matchAction = new MatchAction(
-                srManager.getMatchActionId(),
+        MatchAction matchAction = new MatchAction(new MatchActionId(
+                srManager.getNextMatchActionID()),
                 new SwitchPort((long) 0, (short) 0), match, priority,
                 actions);
         MatchActionOperationEntry maEntry =
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 91acfe5..6ad05bc 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingTunnel.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingTunnel.java
@@ -41,6 +41,12 @@
         this.routes = new ArrayList<TunnelRouteInfo>();
     }
 
+    public SegmentRoutingTunnel(TunnelNotification tunnelNotification) {
+        this.tunnelId = tunnelNotification.getTunnelId();
+        this.labelIds = tunnelNotification.getLabelIds();
+        this.routes = tunnelNotification.getRouteInfo();
+    }
+
     /**
      * Get tunnel ID
      *
@@ -567,49 +573,5 @@
 
     }
 
-    public class TunnelRouteInfo {
-
-        private String srcSwDpid;
-        private List<Dpid> fwdSwDpids;
-        private List<String> route;
-        private int gropuId;
-
-        public TunnelRouteInfo() {
-            fwdSwDpids = new ArrayList<Dpid>();
-            route = new ArrayList<String>();
-        }
-
-        private void setSrcDpid(String dpid) {
-            this.srcSwDpid = dpid;
-        }
-
-        private void setFwdSwDpid(List<Dpid> dpid) {
-            this.fwdSwDpids = dpid;
-        }
-
-        private void addRoute(String id) {
-            route.add(id);
-        }
-
-        private void setGroupId(int groupId) {
-            this.gropuId = groupId;
-        }
-
-        public String getSrcSwDpid() {
-            return this.srcSwDpid;
-        }
-
-        public List<Dpid> getFwdSwDpid() {
-            return this.fwdSwDpids;
-        }
-
-        public List<String> getRoute() {
-            return this.route;
-        }
-
-        public int getGroupId() {
-            return this.gropuId;
-        }
-    }
 
 }
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/TunnelNotification.java b/src/main/java/net/onrc/onos/apps/segmentrouting/TunnelNotification.java
new file mode 100644
index 0000000..f0cd9d8
--- /dev/null
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/TunnelNotification.java
@@ -0,0 +1,40 @@
+package net.onrc.onos.apps.segmentrouting;
+
+import java.io.Serializable;
+import java.util.List;
+
+public class TunnelNotification implements Serializable {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = 1L;
+
+    private String tunnelId;
+    private List<Integer> labelIds;
+    private List<TunnelRouteInfo> routes;
+
+    public TunnelNotification() {
+
+    }
+
+    public TunnelNotification(SegmentRoutingTunnel srTunnel) {
+        this.tunnelId = srTunnel.getTunnelId();
+        this.labelIds = srTunnel.getLabelids();
+        this.routes = srTunnel.getRoutes();
+    }
+
+    public String getTunnelId() {
+        return tunnelId;
+    }
+
+    public List<Integer> getLabelIds() {
+        return labelIds;
+    }
+
+    public List<TunnelRouteInfo> getRouteInfo() {
+        return routes;
+    }
+
+
+}
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/TunnelRouteInfo.java b/src/main/java/net/onrc/onos/apps/segmentrouting/TunnelRouteInfo.java
new file mode 100644
index 0000000..b298b26
--- /dev/null
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/TunnelRouteInfo.java
@@ -0,0 +1,51 @@
+package net.onrc.onos.apps.segmentrouting;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.onrc.onos.core.util.Dpid;
+
+public class TunnelRouteInfo {
+
+    public String srcSwDpid;
+    public List<Dpid> fwdSwDpids;
+    public List<String> route;
+    public int gropuId;
+
+    public TunnelRouteInfo() {
+        fwdSwDpids = new ArrayList<Dpid>();
+        route = new ArrayList<String>();
+    }
+
+    public void setSrcDpid(String dpid) {
+        this.srcSwDpid = dpid;
+    }
+
+    public void setFwdSwDpid(List<Dpid> dpid) {
+        this.fwdSwDpids = dpid;
+    }
+
+    public void addRoute(String id) {
+        route.add(id);
+    }
+
+    public void setGroupId(int groupId) {
+        this.gropuId = groupId;
+    }
+
+    public String getSrcSwDpid() {
+        return this.srcSwDpid;
+    }
+
+    public List<Dpid> getFwdSwDpid() {
+        return this.fwdSwDpids;
+    }
+
+    public List<String> getRoute() {
+        return this.route;
+    }
+
+    public int getGroupId() {
+        return this.gropuId;
+    }
+}
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterTunnelResource.java b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterTunnelResource.java
index a56b59d..efaed12 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterTunnelResource.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/web/SegmentRouterTunnelResource.java
@@ -12,7 +12,7 @@
 import net.onrc.onos.apps.segmentrouting.SegmentRoutingPolicy.PolicyType;
 import net.onrc.onos.apps.segmentrouting.SegmentRoutingPolicyTunnel;
 import net.onrc.onos.apps.segmentrouting.SegmentRoutingTunnel;
-import net.onrc.onos.apps.segmentrouting.SegmentRoutingTunnel.TunnelRouteInfo;
+import net.onrc.onos.apps.segmentrouting.TunnelRouteInfo;
 
 import org.codehaus.jackson.map.ObjectMapper;
 import org.restlet.resource.Delete;
@@ -110,7 +110,7 @@
                Integer gId = segmentRoutingService.getTunnelGroupId(tunnelId,
                        label.getSrcSwDpid());
                dpidGroup.add(label.getSrcSwDpid()+"("
-                       + segmentRoutingService.getMplsLabel(label.getSrcSwDpid())+ ")" 
+                       + segmentRoutingService.getMplsLabel(label.getSrcSwDpid())+ ")"
                        + "/"+ gId
                        );
            }
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java b/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java
index 8e9b000..61c1e78 100644
--- a/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java
+++ b/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java
@@ -14,8 +14,6 @@
 import javax.annotation.concurrent.ThreadSafe;
 
 import net.floodlightcontroller.core.IFloodlightProviderService.Role;
-import net.floodlightcontroller.core.IOF13Switch.NeighborSet;
-import net.floodlightcontroller.core.IOF13Switch.NeighborSet.groupPktType;
 import net.floodlightcontroller.util.MACAddress;
 import net.onrc.onos.api.batchoperation.BatchOperationEntry;
 import net.onrc.onos.api.flowmanager.FlowBatchOperation;
@@ -39,6 +37,9 @@
 import net.onrc.onos.api.newintent.SinglePointToMultiPointIntent;
 import net.onrc.onos.apps.proxyarp.ArpCacheNotification;
 import net.onrc.onos.apps.proxyarp.ArpReplyNotification;
+import net.onrc.onos.apps.segmentrouting.PolicyNotification;
+import net.onrc.onos.apps.segmentrouting.TunnelNotification;
+import net.onrc.onos.apps.segmentrouting.TunnelRouteInfo;
 import net.onrc.onos.core.hostmanager.Host;
 import net.onrc.onos.core.intent.ConstrainedShortestPathIntent;
 import net.onrc.onos.core.intent.ErrorIntent;
@@ -57,23 +58,10 @@
 import net.onrc.onos.core.matchaction.MatchActionOperationsState;
 import net.onrc.onos.core.matchaction.SwitchResult;
 import net.onrc.onos.core.matchaction.SwitchResultList;
-import net.onrc.onos.core.matchaction.action.CopyTtlInAction;
-import net.onrc.onos.core.matchaction.action.CopyTtlOutAction;
-import net.onrc.onos.core.matchaction.action.DecMplsTtlAction;
-import net.onrc.onos.core.matchaction.action.DecNwTtlAction;
-import net.onrc.onos.core.matchaction.action.GroupAction;
 import net.onrc.onos.core.matchaction.action.ModifyDstMacAction;
 import net.onrc.onos.core.matchaction.action.ModifySrcMacAction;
 import net.onrc.onos.core.matchaction.action.NullAction;
 import net.onrc.onos.core.matchaction.action.OutputAction;
-import net.onrc.onos.core.matchaction.action.PopMplsAction;
-import net.onrc.onos.core.matchaction.action.PushMplsAction;
-import net.onrc.onos.core.matchaction.action.SetDAAction;
-import net.onrc.onos.core.matchaction.action.SetMplsBosAction;
-import net.onrc.onos.core.matchaction.action.SetMplsIdAction;
-import net.onrc.onos.core.matchaction.action.SetSAAction;
-import net.onrc.onos.core.matchaction.match.Ipv4Match;
-import net.onrc.onos.core.matchaction.match.MplsMatch;
 import net.onrc.onos.core.matchaction.match.PacketMatch;
 import net.onrc.onos.core.newintent.IntentCompilationResult;
 import net.onrc.onos.core.newintent.PathFlowIntent;
@@ -81,7 +69,6 @@
 import net.onrc.onos.core.newintent.SingleSrcTreeFlowIntent;
 import net.onrc.onos.core.newintent.TestIntent;
 import net.onrc.onos.core.newintent.TestSubclassIntent;
-import net.onrc.onos.core.packet.MPLS;
 import net.onrc.onos.core.packetservice.BroadcastPacketOutNotification;
 import net.onrc.onos.core.packetservice.PacketOutNotification;
 import net.onrc.onos.core.packetservice.SinglePacketOutNotification;
@@ -213,7 +200,6 @@
         kryo.register(Dpid.class);
         kryo.register(IPv4.class);
         kryo.register(IPv4Net.class);
-        kryo.register(MPLS.class);
         kryo.register(IPv6.class);
         kryo.register(IPv6Net.class);
         kryo.register(byte[].class);
@@ -296,22 +282,9 @@
         kryo.register(MatchAction.class);
         kryo.register(MatchActionId.class);
         kryo.register(PacketMatch.class);
-        kryo.register(Ipv4Match.class);
-        kryo.register(MplsMatch.class);
         kryo.register(OutputAction.class);
         kryo.register(ModifyDstMacAction.class);
         kryo.register(ModifySrcMacAction.class);
-        kryo.register(CopyTtlInAction.class);
-        kryo.register(CopyTtlOutAction.class);
-        kryo.register(DecMplsTtlAction.class);
-        kryo.register(DecNwTtlAction.class);
-        kryo.register(GroupAction.class);
-        kryo.register(PopMplsAction.class);
-        kryo.register(PushMplsAction.class);
-        kryo.register(SetDAAction.class);
-        kryo.register(SetSAAction.class);
-        kryo.register(SetMplsBosAction.class);
-        kryo.register(SetMplsIdAction.class);
         kryo.register(MatchActionOperations.class);
         kryo.register(MatchActionOperations.Operator.class);
         kryo.register(MatchActionOperationsId.class);
@@ -338,8 +311,10 @@
         kryo.register(InetAddress.class);
         kryo.register(Inet4Address.class);
 
-        kryo.register(NeighborSet.class);
-        kryo.register(groupPktType.class);
+        // SegmentRouting classes
+        kryo.register(PolicyNotification.class);
+        kryo.register(TunnelNotification.class);
+        kryo.register(TunnelRouteInfo.class);
 
         return kryo;
     }