Removing references to a prior branded controller
[controller.git] / opendaylight / routing / dijkstra_implementation / src / main / java / org / opendaylight / controller / routing / dijkstra_implementation / internal / DijkstraImplementation.java
index 386b226567c7e938545d4b05d609a7d03bf68127..6f1dc3f9d707bd49016a67005ef88799349bd64f 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,15 +57,16 @@ 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;
 
-    public void setLIstenRoutingUpdates(IListenRoutingUpdates i) {
+    public void setListenRoutingUpdates(IListenRoutingUpdates i) {
         if (this.routingAware == null) {
             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) {
@@ -151,10 +140,8 @@ public class DijkstraImplementation implements IRouting, IListenTopoUpdates {
                             : avlDstThruPut;
 
                     if (avlThruPut <= 0) {
-                        log
-                                .trace(
-                                        "Edge {}: Available Throughput {} is Zero/Negative",
-                                        e, avlThruPut);
+                        log.debug("Edge {}: Available Throughput {} <= 0!",
+                                         e, avlThruPut);
                         return (double) -1;
                     }
                     return (double) (Bandwidth.BW1Pbps / avlThruPut);
@@ -188,8 +175,7 @@ public class DijkstraImplementation implements IRouting, IListenTopoUpdates {
     @Override
     public synchronized Path getMaxThroughputRoute(Node src, Node dst) {
         if (mtp == null) {
-            log
-                    .error("Max Throughput Path Calculation has not been Initialized!");
+            log.error("Max Throughput Path Calculation Uninitialized!");
             return null;
         }
 
@@ -197,16 +183,16 @@ public class DijkstraImplementation implements IRouting, IListenTopoUpdates {
         try {
             path = mtp.getMaxThroughputPath(src, dst);
         } catch (IllegalArgumentException ie) {
-            log.debug("A vertex is yet not known between " + src.toString()
-                    + " " + dst.toString());
+            log.debug("A vertex is yet not known between {} {}", src.toString(),
+                          dst.toString());
             return null;
         }
         Path res;
         try {
             res = new Path(path);
         } catch (ConstructionException e) {
-            log.debug("A vertex is yet not known between " + src.toString()
-                    + " " + dst.toString());
+            log.debug("A vertex is yet not known between {} {}", src.toString(),
+                         dst.toString());
             return null;
         }
         return res;
@@ -221,16 +207,16 @@ public class DijkstraImplementation implements IRouting, IListenTopoUpdates {
         try {
             path = spt.getPath(src, dst);
         } catch (IllegalArgumentException ie) {
-            log.debug("A vertex is yet not known between " + src.toString()
-                    + " " + dst.toString());
+               log.debug("A vertex is yet not known between {} {}", src.toString(),
+                          dst.toString());
             return null;
         }
         Path res;
         try {
             res = new Path(path);
         } catch (ConstructionException e) {
-            log.debug("A vertex is yet not known between " + src.toString()
-                    + " " + dst.toString());
+               log.debug("A vertex is yet not known between {} {}", src.toString(),
+                          dst.toString());
             return null;
         }
         return res;
@@ -309,14 +295,14 @@ public class DijkstraImplementation implements IRouting, IListenTopoUpdates {
                 if (topo.containsVertex(src.getNode())
                         && topo.inDegree(src.getNode()) == 0
                         && topo.outDegree(src.getNode()) == 0) {
-                    log.debug("Removing vertex " + src);
+                    log.debug("Removing vertex {}", src);
                     topo.removeVertex(src.getNode());
                 }
 
                 if (topo.containsVertex(dst.getNode())
                         && topo.inDegree(dst.getNode()) == 0
                         && topo.outDegree(dst.getNode()) == 0) {
-                    log.debug("Removing vertex " + dst);
+                    log.debug("Removing vertex {}", dst);
                     topo.removeVertex(dst.getNode());
                 }
             }
@@ -325,8 +311,7 @@ public class DijkstraImplementation implements IRouting, IListenTopoUpdates {
                 clearMaxThroughput();
             }
         } else {
-            log.error("Cannot find topology for BW " + bw
-                    + " this is unexpected!");
+            log.error("Cannot find topology for BW {} this is unexpected!", bw);
         }
         return edgePresentInGraph;
     }
@@ -359,7 +344,7 @@ public class DijkstraImplementation implements IRouting, IListenTopoUpdates {
         if (props != null)
             props.remove(bw);
 
-        log.debug("edgeUpdate: " + e.toString() + " bw: " + bw.getValue());
+        log.debug("edgeUpdate: {} bw: {}", e.toString(), bw.getValue());
 
         Short baseBW = Short.valueOf((short) 0);
         boolean add = (type == UpdateType.ADDED) ? true : false;
@@ -371,7 +356,6 @@ public class DijkstraImplementation implements IRouting, IListenTopoUpdates {
                 updateTopo(e, (short) bw.getValue(), add);
             }
             if (this.routingAware != null) {
-                log.info("Invoking routingAware listeners");
                 for (IListenRoutingUpdates ra : this.routingAware) {
                     try {
                         ra.recalculateDone();
@@ -383,14 +367,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 +458,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;
+       }
+    }
 }