-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
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;
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;
.getLogger(DijkstraImplementation.class);
private ConcurrentMap<Short, Graph<Node, Edge>> topologyBWAware;
private ConcurrentMap<Short, DijkstraShortestPath<Node, Edge>> sptBWAware;
- DijkstraShortestPath<Node, Edge> mtp; //Max Throughput Path
+ DijkstraShortestPath<Node, Edge> mtp; // Max Throughput Path
private Set<IListenRoutingUpdates> routingAware;
private ISwitchManager switchManager;
private ITopologyManager topologyManager;
.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;
}
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);
};
}
Short baseBW = Short.valueOf((short) 0);
- //Initialize mtp also using the default topo
+ // Initialize mtp also using the default topo
Graph<Node, Edge> g = this.topologyBWAware.get(baseBW);
if (g == null) {
log.error("Default Topology Graph is null");
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;
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;
@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<Node, Edge> topo = this.topologyBWAware.get(bw);
DijkstraShortestPath<Node, Edge> spt = this.sptBWAware.get(bw);
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;
}
return edgePresentInGraph;
}
- @Override
- public void edgeUpdate(Edge e, UpdateType type, Set<Property> props) {
+ private boolean edgeUpdate(Edge e, UpdateType type, Set<Property> 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;
}
}
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;
// 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<TopoEdgeUpdate> topoedgeupdateList) {
+ boolean callListeners = false;
+ for (int i = 0; i < topoedgeupdateList.size(); i++) {
+ Edge e = topoedgeupdateList.get(i).getEdge();
+ Set<Property> 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);
}
}
}
/**
* 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
+ 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
}
+
/**
* 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<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);
- }
- }
+ 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;
+ }
+ List<TopoEdgeUpdate> topoedgeupdateList = new ArrayList<TopoEdgeUpdate>();
+ 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();
+ 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) {
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;
+ }
}
}