Support bandwidth in ECS 84/35984/3
authorSheldenShen <shenxvdong1@gmail.com>
Wed, 9 Mar 2016 11:55:57 +0000 (19:55 +0800)
committerKai GAO <gaok12@mails.tsinghua.edu.cn>
Thu, 31 Mar 2016 10:32:36 +0000 (18:32 +0800)
Change-Id: Ib04494e8b92a86f371735948744192435aa4074e
Signed-off-by: SheldenShen <shenxvdong1@gmail.com>
alto-basic/endpointcostservice/impl/src/main/java/org/opendaylight/alto/basic/endpointcostservice/flow/FlowTableMatcher.java
alto-basic/endpointcostservice/impl/src/main/java/org/opendaylight/alto/basic/endpointcostservice/impl/BasicECSImplementation.java
alto-basic/endpointcostservice/impl/src/main/java/org/opendaylight/alto/basic/endpointcostservice/suportservice/impl/NetworkFlowCapableNodeImpl.java
alto-basic/endpointcostservice/impl/src/main/java/org/opendaylight/alto/basic/endpointcostservice/suportservice/impl/NetworkPortStatisticsServiceImpl.java
alto-basic/endpointcostservice/impl/src/main/java/org/opendaylight/alto/basic/endpointcostservice/suportservice/impl/RoutingServiceImpl.java

index 4e2b71aebc07d116380c2fcc535a4a4bcf3e2c06..a49b8f1f7ce27116c281ce6a8b6c9f67a9ab1d35 100644 (file)
@@ -53,14 +53,13 @@ public class FlowTableMatcher {
     public class FlowTableLookUpResult {
         public List<Uri> outputNodeConnectors = new ArrayList<Uri>();
         public boolean sendToController = false;
-        public long meterId = -1;
+        public Long meterId = -1L;
     }
 
     private void prepare(FlowCapableNode node) {
         applyActions.clear();
         pipelineActions.clear();
-        //meterId = null;
-        meterId = 123L;
+        meterId = null;
         indexTables.clear();
         indexTables = indexByTableId(node.getTable());
         indexedGroups = indexByGroupId(node.getGroup());
index df5b71ef96b03f3dcd25e88850327ef9add912ce..1be8147836dec81e70e74ea7d5ce4ca88050b0f8 100644 (file)
@@ -79,13 +79,43 @@ public class BasicECSImplementation extends BaseECSImplementation{
             return null;
         }else if(costMetric.getValue().toString().equals(new String("bandwidth"))){
              log.info("bandwidth");
-//            Numerical cost = computeBandwidthECS(head);
-//            return (cost == null) ? null : cost;
-            return null;
+            Numerical cost = computeBandwidthECS(head);
+            return (cost == null) ? null : cost;
         }
         return null;
     }
 
+    private Numerical computeBandwidthECS(LinkNode head) {
+        //// TODO: 16-3-3
+        Long result = null;
+        LinkedList<LinkNode> queue = new LinkedList<>();
+        Map<LinkNode, Long> maxBw = new HashMap<LinkNode, Long>();
+        queue.addLast(head);
+        maxBw.put(head, head.availableBandwidth());
+        while (!queue.isEmpty()) {
+            LinkNode now = queue.pop();
+            Long topBw = maxBw.get(now)==null?0L:maxBw.get(now);
+            if (now.isDestHost()) {
+                result = maxBw.get(now);
+            }
+            for (LinkNode child : now.children()) {
+                Long bw = (child.availableBandwidth() > topBw) ? child.availableBandwidth() : topBw;
+                if (maxBw.containsKey(child)) {
+                    Long currentBw = maxBw.get(child);
+                    if (bw > currentBw) {
+                        maxBw.put(child, bw);
+                        queue.addLast(child);
+                    }
+                } else {
+                    maxBw.put(child, bw);
+                    queue.addLast(child);
+                }
+            }
+        }
+        NumericalBuilder re = new NumericalBuilder();
+        return (result == null) ? null : re.setCost(new BigDecimal(-result/500)).build();
+    }
+
     private boolean hasLoop(LinkNode head, Map<LinkNode, Integer> status) {
         if (status.containsKey(head)) {
             return status.get(head) == -1;
index 01be96c0778cca529203ce0f0dc3c99352ebaed9..6f68aa966f999de55a6981f856d066f1fb0809fc 100644 (file)
@@ -35,10 +35,12 @@ public class NetworkFlowCapableNodeImpl implements NetworkFlowCapableNodeService
     }
 
     @Override
-    public void addFlowCapableNode(FlowCapableNode node) {}
+    public void addFlowCapableNode(FlowCapableNode node) {//// TODO: 16-3-2
+    }
 
     @Override
-    public void deleteFlowCapableNode(FlowCapableNode node) {}
+    public void deleteFlowCapableNode(FlowCapableNode node) {//TODO: 16-3-2
+    }
 
     @Override
     public FlowCapableNode getFlowCapableNode(String nodeId) {
@@ -111,11 +113,22 @@ public class NetworkFlowCapableNodeImpl implements NetworkFlowCapableNodeService
         return getCapacity(nodeConnector, readMeter(tpId, meterId));
     }
 
-    private long getConsumedBandwidth(String tpId, boolean isHalfDuplex) {
-        long transmitted = portStatistics.getCurrentTxSpeed(tpId, NetworkPortStatisticsService.Metric.BITSPERSECOND)
-                / 1000;
-        long received = portStatistics.getCurrentRxSpeed(tpId, NetworkPortStatisticsService.Metric.BITSPERSECOND)
-                / 1000;
+    private Long getConsumedBandwidth(String tpId, boolean isHalfDuplex) {
+        Long transmitted,received;
+        if(portStatistics.getCurrentRxSpeed(tpId,NetworkPortStatisticsService.Metric.BITSPERSECOND) != null){
+            transmitted = portStatistics.getCurrentTxSpeed(tpId, NetworkPortStatisticsService.Metric.BITSPERSECOND)
+                    / 1000;
+        }
+        else {
+            transmitted = 0L;
+        }
+        if(portStatistics.getCurrentRxSpeed(tpId, NetworkPortStatisticsService.Metric.BITSPERSECOND) != null){
+            received = portStatistics.getCurrentRxSpeed(tpId, NetworkPortStatisticsService.Metric.BITSPERSECOND)
+                    / 1000;
+        }
+        else {
+            received = 0L;
+        }
         if (isHalfDuplex) {
             return transmitted + received;
         } else {
@@ -130,7 +143,7 @@ public class NetworkFlowCapableNodeImpl implements NetworkFlowCapableNodeService
                 || portFeatures[NetworkServiceConstants.PORT_FEATURES.get(NetworkServiceConstants.ONE_GB_HD)];
     }
 
-    private Meter readMeter(String tpId, long meterId) {
+    private Meter readMeter(String tpId, Long meterId) {
         String nodeId = NameConverter.extractNodeId(tpId);
         try {
             return DataStoreHelper.readOperational(this.dataBroker,
@@ -144,9 +157,9 @@ public class NetworkFlowCapableNodeImpl implements NetworkFlowCapableNodeService
     }
     private Long getCapacity(FlowCapableNodeConnector nodeConnector, Meter meter) {
         if (nodeConnector == null) return null;
-        long currentSpeed = nodeConnector.getCurrentSpeed();
+        Long currentSpeed = nodeConnector.getCurrentSpeed();
         if (meter == null) return currentSpeed;
-        long bandRate = -1;
+        Long bandRate = -1L;
         for (MeterBandHeader band : meter.getMeterBandHeaders().getMeterBandHeader()) {
             if (bandRate > band.getBandRate() && bandRate < currentSpeed) {
                 bandRate = band.getBandRate();
index ee2c46b20b19646d28825d0b97e75f6f7caf08fc..b333167d37ca8a5464b441a2683bab8619832a06 100644 (file)
@@ -54,6 +54,7 @@ public class NetworkPortStatisticsServiceImpl implements NetworkPortStatisticsSe
 
     private Map<String, nodeStatistic> nodeStatisticData = null;
     private ListenerRegistration<DataChangeListener> portListener = null;
+
     public NetworkPortStatisticsServiceImpl(DataBroker dataBroker) {
         this.logger.info("NetworkPortStatisticsServiceImpl initial.");
         this.dataBroker = dataBroker;
index 73afcffc3b6e09b4458091b2162d1077bc4215f9..a1261c71dd061054e46e4db890e644d8a1f2690c 100644 (file)
@@ -125,10 +125,9 @@ public class RoutingServiceImpl implements RoutingService {
         } else {
             LinkNode node = new LinkNode(link);
             String srcTpId = link.getSource().getSourceTp().getValue();
-            //Long bandwidth = this.flowCapableNodeService.getAvailableBandwidth(srcTpId, meterId);
-            //log.info("createLinkNode: " + link + ":" + bandwidth);
-            //node.setAvailableBandwidth(bandwidth);
-            node.setAvailableBandwidth(123L);
+            Long bandwidth = this.flowCapableNodeService.getAvailableBandwidth(srcTpId, meterId);
+            log.info("createLinkNode: " + link + ":" + bandwidth);
+            node.setAvailableBandwidth(bandwidth);
             return node;
         }
     }
@@ -139,7 +138,6 @@ public class RoutingServiceImpl implements RoutingService {
         pathStack.add(head);
         while (!pathStack.isEmpty()) {
             LinkNode top = pathStack.remove(pathStack.size() - 1);
-            //////////////////////////
             if(top.children().size() == 0 && top.getLink().getDestination().getDestTp().equals(getLinkByHostIp(matchFields.dstIp).getSource().getSourceTp())){
                 top.setAsDestHost();
             }