This commit fixes the followings 77/77/2
authorChi-Vien Ly <chivly@cisco.com>
Wed, 27 Mar 2013 18:39:20 +0000 (11:39 -0700)
committerChi-Vien Ly <chivly@cisco.com>
Wed, 27 Mar 2013 21:06:08 +0000 (14:06 -0700)
- Change routing.dijkstra_implementation to implement ITopologyManagerAware instead of IListenTopoUpdates
- Correct the bundle bringup sequence using the init(), start() called by dependency manager
- Add routing.dijkstra_implementation restartability through OSGI stop/start

Change-Id: Ia624ab4ea51f4d35c5ffe31d14b1aed58ca123c3
Signed-off-by: Chi-Vien Ly <chivly@cisco.com>
opendaylight/routing/dijkstra_implementation/pom.xml
opendaylight/routing/dijkstra_implementation/src/main/java/org/opendaylight/controller/routing/dijkstra_implementation/internal/Activator.java
opendaylight/routing/dijkstra_implementation/src/main/java/org/opendaylight/controller/routing/dijkstra_implementation/internal/DijkstraImplementation.java
opendaylight/routing/dijkstra_implementation/src/test/java/org/opendaylight/controller/routing/dijkstra_implementation/DijkstraTest.java
opendaylight/routing/dijkstra_implementation/src/test/java/org/opendaylight/controller/routing/dijkstra_implementation/MaxThruputTest.java
opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImpl.java

index 6c394cf5c9e34bea7727f23d6628f21c0ed94330..e89beb8c3695ef417c3ef271729e73415084026b 100644 (file)
           org.slf4j,
           org.opendaylight.controller.sal.routing,
           org.opendaylight.controller.sal.core,
-          org.opendaylight.controller.sal.topology,
           org.opendaylight.controller.sal.utils,
           org.opendaylight.controller.sal.reader,
           org.apache.commons.collections15,
           org.opendaylight.controller.switchmanager, 
+          org.opendaylight.controller.topologymanager, 
           edu.uci.ics.jung.graph,
           edu.uci.ics.jung.algorithms.shortestpath,
           edu.uci.ics.jung.graph.util,
       <artifactId>switchmanager</artifactId>
       <version>0.4.0-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>topologymanager</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+    </dependency>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
index 2137cda5b03ba958cb468f4b4c37b2d6a8490716..2ee1583af7ebebe7f089f2992220f69e25338ade 100644 (file)
@@ -18,9 +18,10 @@ import org.slf4j.LoggerFactory;
 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
 import org.opendaylight.controller.sal.routing.IListenRoutingUpdates;
 import org.opendaylight.controller.sal.routing.IRouting;
-import org.opendaylight.controller.sal.topology.IListenTopoUpdates;
 import org.opendaylight.controller.switchmanager.ISwitchManager;
 import org.opendaylight.controller.sal.reader.IReadService;
+import org.opendaylight.controller.topologymanager.ITopologyManager;
+import org.opendaylight.controller.topologymanager.ITopologyManagerAware;
 
 public class Activator extends ComponentActivatorAbstractBase {
     protected static final Logger logger = LoggerFactory
@@ -33,7 +34,6 @@ public class Activator extends ComponentActivatorAbstractBase {
      *
      */
     public void init() {
-        logger.debug("routing.dijkstra_implementation INIT called!");
     }
 
     /**
@@ -76,8 +76,8 @@ public class Activator extends ComponentActivatorAbstractBase {
         if (imp.equals(DijkstraImplementation.class)) {
             // export the service
             Dictionary<String, String> props = new Hashtable<String, String>();
-            props.put("salListenerName", "routing.Dijkstra");
-            c.setInterface(new String[] { IListenTopoUpdates.class.getName(),
+            props.put("topoListenerName", "routing.Dijkstra");
+            c.setInterface(new String[] { ITopologyManagerAware.class.getName(),
                     IRouting.class.getName() }, props);
 
             // Now lets add a service dependency to make sure the
@@ -91,6 +91,10 @@ public class Activator extends ComponentActivatorAbstractBase {
                     ISwitchManager.class).setCallbacks("setSwitchManager",
                     "unsetSwitchManager").setRequired(true));
 
+            c.add(createContainerServiceDependency(containerName).setService(
+                    ITopologyManager.class).setCallbacks("setTopologyManager",
+                    "unsetTopologyManager").setRequired(true));
+
             c.add(createContainerServiceDependency(containerName).setService(
                     IReadService.class).setCallbacks("setReadService",
                     "unsetReadService").setRequired(true));
index 386b226567c7e938545d4b05d609a7d03bf68127..77e6d95dc953c597158be0c734355f51f2663fee 100644 (file)
@@ -25,12 +25,12 @@ import org.opendaylight.controller.sal.core.NodeConnector;
 import org.opendaylight.controller.sal.core.Path;
 import org.opendaylight.controller.sal.core.Property;
 import org.opendaylight.controller.sal.core.UpdateType;
-import org.opendaylight.controller.sal.core.NodeConnector.NodeConnectorIDType;
 import org.opendaylight.controller.sal.reader.IReadService;
 import org.opendaylight.controller.sal.routing.IListenRoutingUpdates;
 import org.opendaylight.controller.sal.routing.IRouting;
-import org.opendaylight.controller.sal.topology.IListenTopoUpdates;
 import org.opendaylight.controller.switchmanager.ISwitchManager;
+import org.opendaylight.controller.topologymanager.ITopologyManager;
+import org.opendaylight.controller.topologymanager.ITopologyManagerAware;
 
 import edu.uci.ics.jung.algorithms.shortestpath.DijkstraShortestPath;
 import edu.uci.ics.jung.graph.Graph;
@@ -39,6 +39,7 @@ import edu.uci.ics.jung.graph.util.EdgeType;
 import java.lang.Exception;
 import java.lang.IllegalArgumentException;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 import java.util.Map;
@@ -48,7 +49,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.commons.collections15.Transformer;
 
-public class DijkstraImplementation implements IRouting, IListenTopoUpdates {
+public class DijkstraImplementation implements IRouting, ITopologyManagerAware {
     private static Logger log = LoggerFactory
             .getLogger(DijkstraImplementation.class);
     private ConcurrentMap<Short, Graph<Node, Edge>> topologyBWAware;
@@ -56,6 +57,7 @@ public class DijkstraImplementation implements IRouting, IListenTopoUpdates {
     DijkstraShortestPath<Node, Edge> mtp; //Max Throughput Path
     private Set<IListenRoutingUpdates> routingAware;
     private ISwitchManager switchManager;
+    private ITopologyManager topologyManager;
     private IReadService readService;
     private static final long DEFAULT_LINK_SPEED = Bandwidth.BW1Gbps;
 
@@ -64,7 +66,7 @@ public class DijkstraImplementation implements IRouting, IListenTopoUpdates {
             this.routingAware = new HashSet<IListenRoutingUpdates>();
         }
         if (this.routingAware != null) {
-            log.debug("Adding routingAware listener");
+            log.debug("Adding routingAware listener: " + i);
             this.routingAware.add(i);
         }
     }
@@ -81,19 +83,6 @@ public class DijkstraImplementation implements IRouting, IListenTopoUpdates {
         }
     }
 
-    @SuppressWarnings( { "unchecked", "rawtypes" })
-    public DijkstraImplementation() {
-        this.topologyBWAware = (ConcurrentMap<Short, Graph<Node, Edge>>) new ConcurrentHashMap();
-        this.sptBWAware = (ConcurrentMap<Short, DijkstraShortestPath<Node, Edge>>) new ConcurrentHashMap();
-        // Now create the default topology, which doesn't consider the
-        // BW, also create the corresponding Dijkstra calculation
-        Graph<Node, Edge> g = new SparseMultigraph();
-        Short sZero = Short.valueOf((short) 0);
-        this.topologyBWAware.put(sZero, g);
-        this.sptBWAware.put(sZero, new DijkstraShortestPath(g));
-        // Topologies for other BW will be added on a needed base
-    }
-
     @Override
     public synchronized void initMaxThroughput(
             final Map<Edge, Number> EdgeWeightMap) {
@@ -383,14 +372,66 @@ public class DijkstraImplementation implements IRouting, IListenTopoUpdates {
         }
     }
 
-    public void startUp() {
-        log.debug(this.getClass().getName() + ":startUp Method Called");
+    /**
+     * Function called by the dependency manager when all the required
+     * dependencies are satisfied
+     *
+     */
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    public void init() {
+       log.debug("Routing init() is called");
+       this.topologyBWAware = (ConcurrentMap<Short, Graph<Node, Edge>>) new ConcurrentHashMap();
+       this.sptBWAware = (ConcurrentMap<Short, DijkstraShortestPath<Node, Edge>>) new ConcurrentHashMap();
+       // Now create the default topology, which doesn't consider the
+       // BW, also create the corresponding Dijkstra calculation
+       Graph<Node, Edge> g = new SparseMultigraph();
+       Short sZero = Short.valueOf((short) 0);
+       this.topologyBWAware.put(sZero, g);
+       this.sptBWAware.put(sZero, new DijkstraShortestPath(g));
+       // Topologies for other BW will be added on a needed base
     }
-
-    public void shutDown() {
-        log.debug(this.getClass().getName() + ":shutDown Method Called");
+    /**
+     * Function called by the dependency manager when at least one dependency
+     * become unsatisfied or when the component is shutting down because for
+     * example bundle is being stopped.
+     *
+     */
+    void destroy() {
+       log.debug("Routing destroy() is called");
     }
 
+    /**
+     * Function called by dependency manager after "init ()" is called
+     * and after the services provided by the class are registered in
+     * the service registry
+     *
+     */
+   void start() {
+          log.debug("Routing start() is called");
+          // build the routing database from the topology if it exists.
+          Map<Edge, Set<Property>> edges = topologyManager.getEdges();
+          if (edges.isEmpty()) {
+                  return;
+          }
+          log.debug("Creating routing database from the topology");
+          for (Iterator<Map.Entry<Edge,Set<Property>>> i = edges.entrySet().iterator();  i.hasNext();) {
+                  Map.Entry<Edge, Set<Property>> entry = i.next();
+                  Edge e = entry.getKey();
+                  Set<Property> props = entry.getValue();
+                  edgeUpdate(e, UpdateType.ADDED, props);
+          }
+   }
+
+    /**
+     * Function called by the dependency manager before the services exported by
+     * the component are unregistered, this will be followed by a "destroy ()"
+     * calls
+     *
+     */
+   public void stop() {
+          log.debug("Routing stop() is called");
+   }
+
     @Override
     public void edgeOverUtilized(Edge edge) {
         // TODO Auto-generated method stub
@@ -422,4 +463,14 @@ public class DijkstraImplementation implements IRouting, IListenTopoUpdates {
             this.readService = null;
         }
     }
+    
+    public void setTopologyManager(ITopologyManager tm) {
+       this.topologyManager = tm;
+    }
+    
+    public void unsetTopologyManager(ITopologyManager tm) {
+       if (this.topologyManager == tm) {
+               this.topologyManager = null;
+       }
+    }
 }
index 45c75f1c066d838e53f7d00633dabdf414cb3815..2022601321f58f86cf186647cb85998cc00ab8ea 100644 (file)
@@ -34,6 +34,7 @@ public class DijkstraTest {
     @Test
     public void testSinglePathRouteNoBw() {
         DijkstraImplementation imp = new DijkstraImplementation();
+        imp.init();
         Node node1 = NodeCreator.createOFNode((long) 1);
         Node node2 = NodeCreator.createOFNode((long) 2);
         Node node3 = NodeCreator.createOFNode((long) 3);
@@ -84,6 +85,7 @@ public class DijkstraTest {
     @Test
     public void testShortestPathRouteNoBw() {
         DijkstraImplementation imp = new DijkstraImplementation();
+        imp.init();
         Node node1 = NodeCreator.createOFNode((long) 1);
         Node node2 = NodeCreator.createOFNode((long) 2);
         Node node3 = NodeCreator.createOFNode((long) 3);
@@ -149,6 +151,7 @@ public class DijkstraTest {
     @Test
     public void testShortestPathRouteNoBwAfterLinkDelete() {
         DijkstraImplementation imp = new DijkstraImplementation();
+        imp.init();
         Node node1 = NodeCreator.createOFNode((long) 1);
         Node node2 = NodeCreator.createOFNode((long) 2);
         Node node3 = NodeCreator.createOFNode((long) 3);
index 1bab0789590a1192e3c49e77aa2480fdbfa4699e..77c55f3c10185ba9869b19903806b962655d1a60 100644 (file)
@@ -35,6 +35,7 @@ public class MaxThruputTest {
     @Test
     public void testMaxThruPut() {
         DijkstraImplementation imp = new DijkstraImplementation();
+        imp.init();
         Node node1 = NodeCreator.createOFNode((long) 1);
         Node node2 = NodeCreator.createOFNode((long) 2);
         Node node3 = NodeCreator.createOFNode((long) 3);
index 92d0c391d3694deade3dd564a12eee62a22ef9aa..9d24cc6fa89994a7014b15458010631e6ebb74f5 100644 (file)
@@ -94,6 +94,7 @@ public class TopologyManagerImpl implements ITopologyManager,
 
     void setTopologyManagerAware(ITopologyManagerAware s) {
         if (this.topologyManagerAware != null) {
+               log.debug("Adding ITopologyManagerAware: " + s);
             this.topologyManagerAware.add(s);
         }
     }