X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Frouting%2Fdijkstra_implementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Frouting%2Fdijkstra_implementation%2Finternal%2FDijkstraImplementation.java;h=26ae86243b7b83279443b2a2a2b477aa85a4e179;hp=1fed3e1c036d53b89c2bb9ee6689128f3d937234;hb=e2f7aaa41e482815ca1d4495eb85c8653cd903ab;hpb=dcd741d1fd2e408f49f2f8e484d6761a39d6eb3f diff --git a/opendaylight/routing/dijkstra_implementation/src/main/java/org/opendaylight/controller/routing/dijkstra_implementation/internal/DijkstraImplementation.java b/opendaylight/routing/dijkstra_implementation/src/main/java/org/opendaylight/controller/routing/dijkstra_implementation/internal/DijkstraImplementation.java index 1fed3e1c03..26ae86243b 100644 --- a/opendaylight/routing/dijkstra_implementation/src/main/java/org/opendaylight/controller/routing/dijkstra_implementation/internal/DijkstraImplementation.java +++ b/opendaylight/routing/dijkstra_implementation/src/main/java/org/opendaylight/controller/routing/dijkstra_implementation/internal/DijkstraImplementation.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -27,7 +26,9 @@ import org.opendaylight.controller.sal.core.Property; import org.opendaylight.controller.sal.core.UpdateType; 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.TopoEdgeUpdate; import org.opendaylight.controller.switchmanager.ISwitchManager; import org.opendaylight.controller.topologymanager.ITopologyManager; import org.opendaylight.controller.topologymanager.ITopologyManagerAware; @@ -41,6 +42,7 @@ import java.lang.IllegalArgumentException; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.ArrayList; import java.util.Set; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -54,14 +56,14 @@ public class DijkstraImplementation implements IRouting, ITopologyManagerAware { .getLogger(DijkstraImplementation.class); private ConcurrentMap> topologyBWAware; private ConcurrentMap> sptBWAware; - DijkstraShortestPath mtp; //Max Throughput Path + DijkstraShortestPath mtp; // Max Throughput Path private Set 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(); } @@ -71,7 +73,7 @@ public class DijkstraImplementation implements IRouting, ITopologyManagerAware { } } - public void unsetRoutingUpdates(IListenRoutingUpdates i) { + public void unsetListenRoutingUpdates(IListenRoutingUpdates i) { if (this.routingAware == null) { return; } @@ -111,22 +113,20 @@ public class DijkstraImplementation implements IRouting, ITopologyManagerAware { .getNodeConnectorProp(dstNC, Bandwidth.BandwidthPropName); - if ((bwSrc == null) || (bwDst == null)) { - log.error("bwSrc:{} or bwDst:{} is null", bwSrc, bwDst); - return (double) -1; - } - - long srcLinkSpeed = bwSrc.getValue(); - if (srcLinkSpeed == 0) { - log.trace("Edge {}: srcLinkSpeed is 0. Setting to {}!", - e, DEFAULT_LINK_SPEED); + long srcLinkSpeed = 0, dstLinkSpeed = 0; + if ((bwSrc == null) + || ((srcLinkSpeed = bwSrc.getValue()) == 0)) { + log.debug( + "srcNC: {} - Setting srcLinkSpeed to Default!", + srcNC); srcLinkSpeed = DEFAULT_LINK_SPEED; } - long dstLinkSpeed = bwDst.getValue(); - if (dstLinkSpeed == 0) { - log.trace("Edge {}: dstLinkSpeed is 0. Setting to {}!", - e, DEFAULT_LINK_SPEED); + if ((bwDst == null) + || ((dstLinkSpeed = bwDst.getValue()) == 0)) { + log.debug( + "dstNC: {} - Setting dstLinkSpeed to Default!", + dstNC); dstLinkSpeed = DEFAULT_LINK_SPEED; } @@ -135,13 +135,14 @@ public class DijkstraImplementation implements IRouting, ITopologyManagerAware { long avlDstThruPut = dstLinkSpeed - readService.getTransmitRate(dstNC); - //Use lower of the 2 available thruput as the available thruput + // Use lower of the 2 available thruput as the available + // thruput long avlThruPut = avlSrcThruPut < avlDstThruPut ? avlSrcThruPut : avlDstThruPut; if (avlThruPut <= 0) { - log.debug("Edge {}: Available Throughput {} <= 0!", - e, avlThruPut); + log.debug("Edge {}: Available Throughput {} <= 0!", e, + avlThruPut); return (double) -1; } return (double) (Bandwidth.BW1Pbps / avlThruPut); @@ -155,7 +156,7 @@ public class DijkstraImplementation implements IRouting, ITopologyManagerAware { }; } Short baseBW = Short.valueOf((short) 0); - //Initialize mtp also using the default topo + // Initialize mtp also using the default topo Graph g = this.topologyBWAware.get(baseBW); if (g == null) { log.error("Default Topology Graph is null"); @@ -183,16 +184,14 @@ public class DijkstraImplementation implements IRouting, ITopologyManagerAware { 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, dst); 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, dst); return null; } return res; @@ -207,16 +206,14 @@ public class DijkstraImplementation implements IRouting, ITopologyManagerAware { 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, dst); 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, dst); return null; } return res; @@ -237,11 +234,11 @@ public class DijkstraImplementation implements IRouting, ITopologyManagerAware { @Override public synchronized void clearMaxThroughput() { if (mtp != null) { - mtp.reset(); //reset maxthruput path + mtp.reset(); // reset maxthruput path } } - @SuppressWarnings( { "rawtypes", "unchecked" }) + @SuppressWarnings({ "rawtypes", "unchecked" }) private synchronized boolean updateTopo(Edge edge, Short bw, boolean added) { Graph topo = this.topologyBWAware.get(bw); DijkstraShortestPath spt = this.sptBWAware.get(bw); @@ -273,20 +270,19 @@ public class DijkstraImplementation implements IRouting, ITopologyManagerAware { edgePresentInGraph = topo.containsEdge(edge); if (edgePresentInGraph == false) { try { - topo.addEdge(new Edge(src, dst), src - .getNode(), dst - .getNode(), EdgeType.DIRECTED); + topo.addEdge(new Edge(src, dst), src.getNode(), + dst.getNode(), EdgeType.DIRECTED); } catch (ConstructionException e) { - e.printStackTrace(); + log.error("", e); return edgePresentInGraph; } } } else { - //Remove the edge + // Remove the edge try { topo.removeEdge(new Edge(src, dst)); } catch (ConstructionException e) { - e.printStackTrace(); + log.error("", e); return edgePresentInGraph; } @@ -316,26 +312,25 @@ public class DijkstraImplementation implements IRouting, ITopologyManagerAware { return edgePresentInGraph; } - @Override - public void edgeUpdate(Edge e, UpdateType type, Set props) { + private boolean edgeUpdate(Edge e, UpdateType type, Set props) { String srcType = null; String dstType = null; if (e == null || type == null) { log.error("Edge or Update type are null!"); - return; + return false; } else { srcType = e.getTailNodeConnector().getType(); dstType = e.getHeadNodeConnector().getType(); if (srcType.equals(NodeConnector.NodeConnectorIDType.PRODUCTION)) { log.debug("Skip updates for {}", e); - return; + return false; } if (dstType.equals(NodeConnector.NodeConnectorIDType.PRODUCTION)) { log.debug("Skip updates for {}", e); - return; + return false; } } @@ -344,7 +339,9 @@ public class DijkstraImplementation implements IRouting, ITopologyManagerAware { if (props != null) props.remove(bw); - log.debug("edgeUpdate: {} bw: {}", e.toString(), bw.getValue()); + if (log.isDebugEnabled()) { + log.debug("edgeUpdate: {} bw: {}", e, bw.getValue()); + } Short baseBW = Short.valueOf((short) 0); boolean add = (type == UpdateType.ADDED) ? true : false; @@ -355,13 +352,27 @@ public class DijkstraImplementation implements IRouting, ITopologyManagerAware { // Update BW topo updateTopo(e, (short) bw.getValue(), add); } - if (this.routingAware != null) { - for (IListenRoutingUpdates ra : this.routingAware) { - try { - ra.recalculateDone(); - } catch (Exception ex) { - log.error("Exception on routingAware listener call", e); - } + } + return newEdge; + } + + @Override + public void edgeUpdate(List topoedgeupdateList) { + boolean callListeners = false; + for (int i = 0; i < topoedgeupdateList.size(); i++) { + Edge e = topoedgeupdateList.get(i).getEdge(); + Set p = topoedgeupdateList.get(i).getProperty(); + UpdateType type = topoedgeupdateList.get(i).getUpdateType(); + if ((edgeUpdate(e, type, p)) && (!callListeners)) { + callListeners = true; + } + } + if ((callListeners) && (this.routingAware != null)) { + for (IListenRoutingUpdates ra : this.routingAware) { + try { + ra.recalculateDone(); + } catch (Exception ex) { + log.error("Exception on routingAware listener call", ex); } } } @@ -370,62 +381,67 @@ public class DijkstraImplementation implements IRouting, ITopologyManagerAware { /** * 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>) new ConcurrentHashMap(); - this.sptBWAware = (ConcurrentMap>) new ConcurrentHashMap(); - // Now create the default topology, which doesn't consider the - // BW, also create the corresponding Dijkstra calculation - Graph 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 + log.debug("Routing init() is called"); + this.topologyBWAware = (ConcurrentMap>) new ConcurrentHashMap(); + this.sptBWAware = (ConcurrentMap>) new ConcurrentHashMap(); + // Now create the default topology, which doesn't consider the + // BW, also create the corresponding Dijkstra calculation + Graph 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 } + /** * 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"); + 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 - * + * 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> edges = topologyManager.getEdges(); - if (edges.isEmpty()) { - return; - } - log.debug("Creating routing database from the topology"); - for (Iterator>> i = edges.entrySet().iterator(); i.hasNext();) { - Map.Entry> entry = i.next(); - Edge e = entry.getKey(); - Set props = entry.getValue(); - edgeUpdate(e, UpdateType.ADDED, props); - } - } + void start() { + log.debug("Routing start() is called"); + // build the routing database from the topology if it exists. + Map> edges = topologyManager.getEdges(); + if (edges.isEmpty()) { + return; + } + List topoedgeupdateList = new ArrayList(); + log.debug("Creating routing database from the topology"); + for (Iterator>> i = edges.entrySet() + .iterator(); i.hasNext();) { + Map.Entry> entry = i.next(); + Edge e = entry.getKey(); + Set props = entry.getValue(); + TopoEdgeUpdate topoedgeupdate = new TopoEdgeUpdate(e, props, + UpdateType.ADDED); + topoedgeupdateList.add(topoedgeupdate); + } + edgeUpdate(topoedgeupdateList); + } /** * 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"); - } + public void stop() { + log.debug("Routing stop() is called"); + } @Override public void edgeOverUtilized(Edge edge) { @@ -458,14 +474,14 @@ public class DijkstraImplementation implements IRouting, ITopologyManagerAware { this.readService = null; } } - + public void setTopologyManager(ITopologyManager tm) { - this.topologyManager = tm; + this.topologyManager = tm; } - + public void unsetTopologyManager(ITopologyManager tm) { - if (this.topologyManager == tm) { - this.topologyManager = null; - } + if (this.topologyManager == tm) { + this.topologyManager = null; + } } }