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());
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;
}
@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) {
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 {
|| 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,
}
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();
private Map<String, nodeStatistic> nodeStatisticData = null;
private ListenerRegistration<DataChangeListener> portListener = null;
+
public NetworkPortStatisticsServiceImpl(DataBroker dataBroker) {
this.logger.info("NetworkPortStatisticsServiceImpl initial.");
this.dataBroker = dataBroker;
} 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;
}
}
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();
}