From bdf8ab73309cbe1937a347b8dc934b8542ffb9c0 Mon Sep 17 00:00:00 2001 From: Ryan Izard <ryan.izard@bigswitch.com> Date: Tue, 19 Jul 2016 09:54:15 -0400 Subject: [PATCH] Don't use statistics service to get link speed. This can be derived from the IOSwitchService more efficiently. Remove link speed function from IStatisticsService. --- .../statistics/IStatisticsService.java | 2 - .../statistics/StatisticsCollector.java | 4 - .../topology/TopologyInstance.java | 117 +++++++++++------- .../topology/TopologyManager.java | 16 ++- 4 files changed, 78 insertions(+), 61 deletions(-) diff --git a/src/main/java/net/floodlightcontroller/statistics/IStatisticsService.java b/src/main/java/net/floodlightcontroller/statistics/IStatisticsService.java index 7cc047233..9075d98d2 100644 --- a/src/main/java/net/floodlightcontroller/statistics/IStatisticsService.java +++ b/src/main/java/net/floodlightcontroller/statistics/IStatisticsService.java @@ -12,8 +12,6 @@ public interface IStatisticsService extends IFloodlightService { public SwitchPortBandwidth getBandwidthConsumption(DatapathId dpid, OFPort p); public Map<NodePortTuple, SwitchPortBandwidth> getBandwidthConsumption(); - - public long getLinkSpeed(NodePortTuple npt); public void collectStatistics(boolean collect); } diff --git a/src/main/java/net/floodlightcontroller/statistics/StatisticsCollector.java b/src/main/java/net/floodlightcontroller/statistics/StatisticsCollector.java index 50f441bd5..97bd54aef 100644 --- a/src/main/java/net/floodlightcontroller/statistics/StatisticsCollector.java +++ b/src/main/java/net/floodlightcontroller/statistics/StatisticsCollector.java @@ -242,10 +242,6 @@ public class StatisticsCollector implements IFloodlightModule, IStatisticsServic return Collections.unmodifiableMap(portStats); } - public long getLinkSpeed(NodePortTuple npt) { - return portStats.get(npt).getLinkSpeedBitsPerSec().getValue(); - } - @Override public synchronized void collectStatistics(boolean collect) { if (collect && !isEnabled) { diff --git a/src/main/java/net/floodlightcontroller/topology/TopologyInstance.java b/src/main/java/net/floodlightcontroller/topology/TopologyInstance.java index fbd6bf8a4..80a41d494 100644 --- a/src/main/java/net/floodlightcontroller/topology/TopologyInstance.java +++ b/src/main/java/net/floodlightcontroller/topology/TopologyInstance.java @@ -16,12 +16,16 @@ package net.floodlightcontroller.topology; +import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.core.types.NodePortTuple; import net.floodlightcontroller.linkdiscovery.Link; import net.floodlightcontroller.routing.BroadcastTree; import net.floodlightcontroller.routing.Path; import net.floodlightcontroller.routing.PathId; +import net.floodlightcontroller.statistics.SwitchPortBandwidth; import net.floodlightcontroller.util.ClusterDFS; + +import org.projectfloodlight.openflow.protocol.OFPortDesc; import org.projectfloodlight.openflow.types.DatapathId; import org.projectfloodlight.openflow.types.OFPort; import org.projectfloodlight.openflow.types.U64; @@ -643,92 +647,113 @@ public class TopologyInstance { */ public Map<Link,Integer> initLinkCostMap() { Map<Link, Integer> linkCost = new HashMap<Link, Integer>(); - long rawLinkSpeed; - int linkSpeedMBps; int tunnel_weight = portsWithLinks.size() + 1; - /* pathMetrics: - * 1: Hop Count (Default Metrics) - * 2: Hop Count (Treat Tunnels same as link) - * 3: Latency - * 4: Link Speed - */ switch (TopologyManager.getPathMetricInternal()){ case HOPCOUNT_AVOID_TUNNELS: - if(TopologyManager.collectStatistics == true){ - TopologyManager.statisticsService.collectStatistics(false); - TopologyManager.collectStatistics = false; - } - log.debug("Using Default: Hop Count with Tunnel Bias for Metrics"); + log.debug("Using hop count with tunnel bias for metrics"); for (NodePortTuple npt : portsTunnel) { - if (links.get(npt) == null) continue; + if (links.get(npt) == null) { + continue; + } for (Link link : links.get(npt)) { - if (link == null) continue; + if (link == null) { + continue; + } linkCost.put(link, tunnel_weight); } } return linkCost; case HOPCOUNT: - if(TopologyManager.collectStatistics == true){ - TopologyManager.statisticsService.collectStatistics(false); - TopologyManager.collectStatistics = false; - } - log.debug("Using Hop Count without Tunnel Bias for Metrics"); + log.debug("Using hop count w/o tunnel bias for metrics"); for (NodePortTuple npt : links.keySet()) { - if (links.get(npt) == null) continue; + if (links.get(npt) == null) { + continue; + } for (Link link : links.get(npt)) { - if (link == null) continue; + if (link == null) { + continue; + } linkCost.put(link,1); } } return linkCost; case LATENCY: - if(TopologyManager.collectStatistics == true){ - TopologyManager.statisticsService.collectStatistics(false); - TopologyManager.collectStatistics = false; - } - log.debug("Using Latency for Route Metrics"); + log.debug("Using latency for path metrics"); for (NodePortTuple npt : links.keySet()) { - if (links.get(npt) == null) continue; + if (links.get(npt) == null) { + continue; + } for (Link link : links.get(npt)) { - if (link == null) continue; - if((int)link.getLatency().getValue() < 0 || (int)link.getLatency().getValue() > MAX_LINK_WEIGHT) + if (link == null) { + continue; + } + if ((int)link.getLatency().getValue() < 0 || + (int)link.getLatency().getValue() > MAX_LINK_WEIGHT) { linkCost.put(link, MAX_LINK_WEIGHT); - else + } else { linkCost.put(link,(int)link.getLatency().getValue()); + } } } return linkCost; case LINK_SPEED: - if(TopologyManager.collectStatistics == false){ - TopologyManager.statisticsService.collectStatistics(true); - TopologyManager.collectStatistics = true; - } - log.debug("Using Link Speed for Route Metrics"); + TopologyManager.statisticsService.collectStatistics(true); + log.debug("Using link speed for path metrics"); for (NodePortTuple npt : links.keySet()) { - if (links.get(npt) == null) continue; - rawLinkSpeed = TopologyManager.statisticsService.getLinkSpeed(npt); + if (links.get(npt) == null) { + continue; + } + long rawLinkSpeed = 0; + IOFSwitch s = TopologyManager.switchService.getSwitch(npt.getNodeId()); + if (s != null) { + OFPortDesc p = s.getPort(npt.getPortId()); + if (p != null) { + rawLinkSpeed = p.getCurrSpeed(); + } + } for (Link link : links.get(npt)) { - if (link == null) continue; + if (link == null) { + continue; + } - if((rawLinkSpeed / 10^6) / 8 > 1){ - linkSpeedMBps = (int)(rawLinkSpeed / 10^6) / 8; + if ((rawLinkSpeed / 10^6) / 8 > 1) { + int linkSpeedMBps = (int)(rawLinkSpeed / 10^6) / 8; linkCost.put(link, (1/linkSpeedMBps)*1000); + } else { + linkCost.put(link, MAX_LINK_WEIGHT); } - else + } + } + return linkCost; + + case UTILIZATION: + TopologyManager.statisticsService.collectStatistics(true); + log.debug("Using utilization for path metrics"); + for (NodePortTuple npt : links.keySet()) { + if (links.get(npt) == null) continue; + SwitchPortBandwidth spb = TopologyManager.statisticsService + .getBandwidthConsumption(npt.getNodeId(), npt.getPortId()); + long bpsTx = spb.getBitsPerSecondTx().getValue(); + for (Link link : links.get(npt)) { + if (link == null) { + continue; + } + + if ((bpsTx / 10^6) / 8 > 1) { + int cost = (int) (bpsTx / 10^6) / 8; + linkCost.put(link, ((1/cost)*1000)); + } else { linkCost.put(link, MAX_LINK_WEIGHT); + } } } return linkCost; default: - if(TopologyManager.collectStatistics == true){ - TopologyManager.statisticsService.collectStatistics(false); - TopologyManager.collectStatistics = false; - } log.debug("Invalid Selection: Using Default Hop Count with Tunnel Bias for Metrics"); for (NodePortTuple npt : portsTunnel) { if (links.get(npt) == null) continue; diff --git a/src/main/java/net/floodlightcontroller/topology/TopologyManager.java b/src/main/java/net/floodlightcontroller/topology/TopologyManager.java index 67200db0e..77dcc9651 100644 --- a/src/main/java/net/floodlightcontroller/topology/TopologyManager.java +++ b/src/main/java/net/floodlightcontroller/topology/TopologyManager.java @@ -66,10 +66,7 @@ ITopologyManagerBackend, ILinkDiscoveryListener, IOFMessageListener { private static Logger log = LoggerFactory.getLogger(TopologyManager.class); public static final String MODULE_NAME = "topology"; - protected static IStatisticsService statisticsService; - protected static volatile PATH_METRIC pathMetric = PATH_METRIC.HOPCOUNT_AVOID_TUNNELS; //default: compute paths on hop count - protected static boolean collectStatistics = false; /** * Maximum number of route entries stored in memory. @@ -106,12 +103,13 @@ ITopologyManagerBackend, ILinkDiscoveryListener, IOFMessageListener { */ protected Set<NodePortTuple> tunnelPorts; - protected ILinkDiscoveryService linkDiscoveryService; - protected IThreadPoolService threadPoolService; - protected IFloodlightProviderService floodlightProviderService; - protected IOFSwitchService switchService; - protected IRestApiService restApiService; - protected IDebugCounterService debugCounterService; + protected static ILinkDiscoveryService linkDiscoveryService; + protected static IThreadPoolService threadPoolService; + protected static IFloodlightProviderService floodlightProviderService; + protected static IOFSwitchService switchService; + protected static IRestApiService restApiService; + protected static IDebugCounterService debugCounterService; + protected static IStatisticsService statisticsService; // Modules that listen to our updates protected ArrayList<ITopologyListener> topologyAware; -- GitLab