private static final Logger log = LoggerFactory.getLogger(AltoProvider.class);
private ListenerRegistration<DataChangeListener> hostNodeListerRegistration;
-
+
private ListenerRegistration<DataChangeListener> linkListerRegistration;
private ListenerRegistration<DataChangeListener> topologyListerRegistration;
public AltoProvider() {
this.networkGraph = new SparseMultigraph<>();
this.shortestPath = new DijkstraShortestPath(this.networkGraph);
- this.ipSwitchIdMap = new HashMap<String, String>();
+ this.ipSwitchIdMap = new HashMap<String, String>();
this.linkAdded = new HashSet<>();
this.networkGraphFlag = new AtomicBoolean(false);
this.executor = Executors.newFixedThreadPool(1);
}
public void registerAsDataChangeListener() {
- InstanceIdentifier<HostNode> hostNodes = InstanceIdentifier
- .builder(NetworkTopology.class)//
- .child(Topology.class,
- new TopologyKey(new TopologyId("flow:1")))//
- .child(Node.class).augmentation(HostNode.class).build();
- this.hostNodeListerRegistration = dataProvider
- .registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
- hostNodes, this, DataChangeScope.BASE);
-
- InstanceIdentifier<Link> links = InstanceIdentifier
- .builder(NetworkTopology.class)//
- .child(Topology.class,
- new TopologyKey(new TopologyId("flow:1")))//
- .child(Link.class).build();
- this.linkListerRegistration = dataProvider.registerDataChangeListener(
- LogicalDatastoreType.OPERATIONAL, links, this,
- DataChangeScope.BASE);
-
- InstanceIdentifier<Topology> topology = InstanceIdentifier
- .builder(NetworkTopology.class)//
- .child(Topology.class,
- new TopologyKey(new TopologyId("flow:1"))).build();
+ InstanceIdentifier<HostNode> hostNodes = InstanceIdentifier
+ .builder(NetworkTopology.class)//
+ .child(Topology.class,
+ new TopologyKey(new TopologyId("flow:1")))//
+ .child(Node.class).augmentation(HostNode.class).build();
+ this.hostNodeListerRegistration = dataProvider
+ .registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
+ hostNodes, this, DataChangeScope.BASE);
+
+ InstanceIdentifier<Link> links = InstanceIdentifier
+ .builder(NetworkTopology.class)//
+ .child(Topology.class,
+ new TopologyKey(new TopologyId("flow:1")))//
+ .child(Link.class).build();
+ this.linkListerRegistration = dataProvider.registerDataChangeListener(
+ LogicalDatastoreType.OPERATIONAL, links, this,
+ DataChangeScope.BASE);
+
+ InstanceIdentifier<Topology> topology = InstanceIdentifier
+ .builder(NetworkTopology.class)//
+ .child(Topology.class,
+ new TopologyKey(new TopologyId("flow:1"))).build();
this.topologyListerRegistration = dataProvider.registerDataChangeListener(
- LogicalDatastoreType.OPERATIONAL, topology, this,
- DataChangeScope.BASE);
-
- ReadOnlyTransaction newReadOnlyTransaction = dataProvider
- .newReadOnlyTransaction();
-
- ListenableFuture<Optional<Topology>> dataFuture = newReadOnlyTransaction
- .read(LogicalDatastoreType.OPERATIONAL, topology);
- try {
- Topology get = dataFuture.get().get();
- } catch (InterruptedException | ExecutionException ex) {
- java.util.logging.Logger.getLogger(AltoProvider.class.getName())
- .log(Level.SEVERE, null, ex);
- }
- Futures.addCallback(dataFuture,
- new FutureCallback<Optional<Topology>>() {
- @Override
- public void onSuccess(final Optional<Topology> result) {
- if (result.isPresent()) {
- log.trace("Processing NEW NODE? " + result.get());
- processTopology(result.get());
- }
- }
-
- @Override
- public void onFailure(Throwable arg0) {
- }
- });
- }
-
+ LogicalDatastoreType.OPERATIONAL, topology, this,
+ DataChangeScope.BASE);
+
+ ReadOnlyTransaction newReadOnlyTransaction = dataProvider
+ .newReadOnlyTransaction();
+
+ ListenableFuture<Optional<Topology>> dataFuture = newReadOnlyTransaction
+ .read(LogicalDatastoreType.OPERATIONAL, topology);
+ try {
+ Topology get = dataFuture.get().get();
+ } catch (InterruptedException | ExecutionException ex) {
+ java.util.logging.Logger.getLogger(AltoProvider.class.getName())
+ .log(Level.SEVERE, null, ex);
+ }
+ Futures.addCallback(dataFuture,
+ new FutureCallback<Optional<Topology>>() {
+ @Override
+ public void onSuccess(final Optional<Topology> result) {
+ if (result.isPresent()) {
+ log.trace("Processing NEW NODE? " + result.get());
+ processTopology(result.get());
+ }
+ }
+
+ @Override
+ public void onFailure(Throwable arg0) {
+ }
+ });
+ }
+
public synchronized void addLinks(List<Link> links) {
- if (links == null || links.isEmpty()) {
- log.info("In addLinks: No link added as links is null or empty.");
- return;
- }
+ if (links == null || links.isEmpty()) {
+ log.info("In addLinks: No link added as links is null or empty.");
+ return;
+ }
- if (this.networkGraph == null) {
- this.networkGraph = new SparseMultigraph<>();
+ if (this.networkGraph == null) {
+ this.networkGraph = new SparseMultigraph<>();
networkGraphFlag.set(true);
- }
-
- for (Link link : links) {
- if (linkAlreadyAdded(link)) {
- continue;
- }
- NodeId sourceNodeId = link.getSource().getSourceNode();
- NodeId destinationNodeId = link.getDestination().getDestNode();
- this.networkGraph.addVertex(sourceNodeId);
- this.networkGraph.addVertex(destinationNodeId);
- this.networkGraph.addEdge(link, sourceNodeId, destinationNodeId,
- EdgeType.UNDIRECTED);
+ }
+
+ for (Link link : links) {
+ if (linkAlreadyAdded(link)) {
+ continue;
+ }
+ NodeId sourceNodeId = link.getSource().getSourceNode();
+ NodeId destinationNodeId = link.getDestination().getDestNode();
+ this.networkGraph.addVertex(sourceNodeId);
+ this.networkGraph.addVertex(destinationNodeId);
+ this.networkGraph.addEdge(link, sourceNodeId, destinationNodeId,
+ EdgeType.UNDIRECTED);
networkGraphFlag.set(true);
- }
-
- }
-
- private boolean linkAlreadyAdded(Link link) {
- String linkAddedKey = null;
- if (link.getDestination().getDestTp().hashCode() > link.getSource()
- .getSourceTp().hashCode()) {
- linkAddedKey = link.getSource().getSourceTp().getValue()
- + link.getDestination().getDestTp().getValue();
- } else {
- linkAddedKey = link.getDestination().getDestTp().getValue()
- + link.getSource().getSourceTp().getValue();
- }
- if (linkAdded.contains(linkAddedKey)) {
- return true;
- } else {
- linkAdded.add(linkAddedKey);
- return false;
- }
- }
-
- public void processTopology(Topology topology) {
- List<Node> nodeList = null;
+ }
+
+ }
+
+ private boolean linkAlreadyAdded(Link link) {
+ String linkAddedKey = null;
+ if (link.getDestination().getDestTp().hashCode() > link.getSource()
+ .getSourceTp().hashCode()) {
+ linkAddedKey = link.getSource().getSourceTp().getValue()
+ + link.getDestination().getDestTp().getValue();
+ } else {
+ linkAddedKey = link.getDestination().getDestTp().getValue()
+ + link.getSource().getSourceTp().getValue();
+ }
+ if (linkAdded.contains(linkAddedKey)) {
+ return true;
+ } else {
+ linkAdded.add(linkAddedKey);
+ return false;
+ }
+ }
+
+ public void processTopology(Topology topology) {
+ List<Node> nodeList = null;
if ((nodeList = topology.getNode()) != null) {
- for (int i = 0; i < nodeList.size(); ++i) {
- Node node = nodeList.get(i);
- HostNode hostNode = node.getAugmentation(HostNode.class);
- log.info("process node "+i+hostNode);
- processNode(hostNode);
- }
- List<Link> linkList = topology.getLink();
- addLinks(linkList);
+ for (int i = 0; i < nodeList.size(); ++i) {
+ Node node = nodeList.get(i);
+ HostNode hostNode = node.getAugmentation(HostNode.class);
+ log.info("process node "+i+hostNode);
+ processNode(hostNode);
+ }
+ List<Link> linkList = topology.getLink();
+ addLinks(linkList);
}
- }
+ }
- private void deleteHostNode(HostNode hostNode) {
- List<AttachmentPoints> attachmentPoints = hostNode
- .getAttachmentPoints();
+ private void deleteHostNode(HostNode hostNode) {
+ List<AttachmentPoints> attachmentPoints = hostNode
+ .getAttachmentPoints();
- TpId tpId = attachmentPoints.get(0).getTpId();
- String tpIdString = tpId.getValue();
+ TpId tpId = attachmentPoints.get(0).getTpId();
+ String tpIdString = tpId.getValue();
- String ipv4String = hostNode.getAddresses().get(0).getIp()
- .getIpv4Address().getValue();
+ String ipv4String = hostNode.getAddresses().get(0).getIp()
+ .getIpv4Address().getValue();
- this.ipSwitchIdMap.remove(ipv4String);
- }
+ this.ipSwitchIdMap.remove(ipv4String);
+ }
- private void processNode(HostNode hostNode) {
+ private void processNode(HostNode hostNode) {
if (this.networkGraph==null) {
- this.networkGraph = new SparseMultigraph<>();
+ this.networkGraph = new SparseMultigraph<>();
}
- if(hostNode==null)return;
- List<AttachmentPoints> attachmentPoints = hostNode
- .getAttachmentPoints();
+ if(hostNode==null)return;
+ List<AttachmentPoints> attachmentPoints = hostNode
+ .getAttachmentPoints();
+
+ TpId tpId = attachmentPoints.get(0).getTpId();
+ String tpIdString = tpId.getValue();
- TpId tpId = attachmentPoints.get(0).getTpId();
- String tpIdString = tpId.getValue();
+ String ipv4String = hostNode.getAddresses().get(0).getIp()
+ .getIpv4Address().getValue();
- String ipv4String = hostNode.getAddresses().get(0).getIp()
- .getIpv4Address().getValue();
+ this.ipSwitchIdMap.put(ipv4String, tpIdString);
+ }
- this.ipSwitchIdMap.put(ipv4String, tpIdString);
- }
-
@Override
public void onDataChanged(
final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
log.info("in Data Changed");
- if (change == null) {
- log.info("In onDataChanged: No processing done as change even is null.");
- return;
- }
- Map<InstanceIdentifier<?>, DataObject> updatedData = change
- .getUpdatedData();
- Map<InstanceIdentifier<?>, DataObject> createdData = change
- .getCreatedData();
- Map<InstanceIdentifier<?>, DataObject> originalData = change
- .getOriginalData();
- Set<InstanceIdentifier<?>> deletedData = change.getRemovedPaths();
-
- for (InstanceIdentifier<?> iid : deletedData) {
+ if (change == null) {
+ log.info("In onDataChanged: No processing done as change even is null.");
+ return;
+ }
+ Map<InstanceIdentifier<?>, DataObject> updatedData = change
+ .getUpdatedData();
+ Map<InstanceIdentifier<?>, DataObject> createdData = change
+ .getCreatedData();
+ Map<InstanceIdentifier<?>, DataObject> originalData = change
+ .getOriginalData();
+ Set<InstanceIdentifier<?>> deletedData = change.getRemovedPaths();
+
+ for (InstanceIdentifier<?> iid : deletedData) {
log.info("delete Data");
- if (iid.getTargetType().equals(HostNode.class)) {
+ if (iid.getTargetType().equals(HostNode.class)) {
log.info("delete hostnode");
- HostNode node = ((HostNode) originalData.get(iid));
- deleteHostNode(node);
- } else if (iid.getTargetType().equals(Link.class)) {
+ HostNode node = ((HostNode) originalData.get(iid));
+ deleteHostNode(node);
+ } else if (iid.getTargetType().equals(Link.class)) {
log.info("delete edge");
- String linkAddedKey = null;
+ String linkAddedKey = null;
Link link = (Link) originalData.get(iid);
- if (link.getDestination().getDestTp().hashCode() > link.getSource()
- .getSourceTp().hashCode()) {
- linkAddedKey = link.getSource().getSourceTp().getValue()
- + link.getDestination().getDestTp().getValue();
- } else {
- linkAddedKey = link.getDestination().getDestTp().getValue()
- + link.getSource().getSourceTp().getValue();
- }
- if (linkAdded.contains(linkAddedKey)) {
- linkAdded.remove(linkAddedKey);
- }
- this.networkGraph.removeEdge((Link) originalData.get(iid));
+ if (link.getDestination().getDestTp().hashCode() > link.getSource()
+ .getSourceTp().hashCode()) {
+ linkAddedKey = link.getSource().getSourceTp().getValue()
+ + link.getDestination().getDestTp().getValue();
+ } else {
+ linkAddedKey = link.getDestination().getDestTp().getValue()
+ + link.getSource().getSourceTp().getValue();
+ }
+ if (linkAdded.contains(linkAddedKey)) {
+ linkAdded.remove(linkAddedKey);
+ }
+ this.networkGraph.removeEdge((Link) originalData.get(iid));
networkGraphFlag.set(true);
-
- }
- }
-
- for (Map.Entry<InstanceIdentifier<?>, DataObject> entrySet : updatedData
- .entrySet()) {
-
- InstanceIdentifier<?> iiD = entrySet.getKey();
- final DataObject dataObject = entrySet.getValue();
- if (dataObject instanceof HostNode) {
+
+ }
+ }
+
+ for (Map.Entry<InstanceIdentifier<?>, DataObject> entrySet : updatedData
+ .entrySet()) {
+
+ InstanceIdentifier<?> iiD = entrySet.getKey();
+ final DataObject dataObject = entrySet.getValue();
+ if (dataObject instanceof HostNode) {
log.info("update hostnode data");
- processNode((HostNode) dataObject);
- }
- }
-
- for (Map.Entry<InstanceIdentifier<?>, DataObject> entrySet : createdData
- .entrySet()) {
- InstanceIdentifier<?> iiD = entrySet.getKey();
- final DataObject dataObject = entrySet.getValue();
- if (dataObject instanceof HostNode) {
+ processNode((HostNode) dataObject);
+ }
+ }
+
+ for (Map.Entry<InstanceIdentifier<?>, DataObject> entrySet : createdData
+ .entrySet()) {
+ InstanceIdentifier<?> iiD = entrySet.getKey();
+ final DataObject dataObject = entrySet.getValue();
+ if (dataObject instanceof HostNode) {
log.info("update HostNode");
- processNode((HostNode) dataObject);
- } else if (dataObject instanceof Link) {
+ processNode((HostNode) dataObject);
+ } else if (dataObject instanceof Link) {
log.info("update link");
- Link link = (Link) dataObject;
- if (!linkAlreadyAdded(link)) {
- NodeId sourceNodeId = link.getSource().getSourceNode();
- NodeId destinationNodeId = link.getDestination()
- .getDestNode();
- this.networkGraph.addVertex(sourceNodeId);
- this.networkGraph.addVertex(destinationNodeId);
- this.networkGraph.addEdge(link, sourceNodeId, destinationNodeId,
- EdgeType.UNDIRECTED);
+ Link link = (Link) dataObject;
+ if (!linkAlreadyAdded(link)) {
+ NodeId sourceNodeId = link.getSource().getSourceNode();
+ NodeId destinationNodeId = link.getDestination()
+ .getDestNode();
+ this.networkGraph.addVertex(sourceNodeId);
+ this.networkGraph.addVertex(destinationNodeId);
+ this.networkGraph.addEdge(link, sourceNodeId, destinationNodeId,
+ EdgeType.UNDIRECTED);
log.info("update link in networkGraph");
networkGraphFlag.set(true);
- }
- }
- }
-
-
+ }
+ }
+ }
+
+
}
public List<EndpointCostMap> hopcountNumerical(List<TypedEndpointAddress> srcs, List<TypedEndpointAddress> dsts) {
shortestPath = new DijkstraShortestPath(this.networkGraph);
networkGraphFlag.set(false);
}
- List<EndpointCostMap> result = new ArrayList<EndpointCostMap>();
- for (int i = 0; i < srcs.size(); ++i) {
- TypedEndpointAddress teaSrc = srcs.get(i);
- String ipv4SrcString = teaSrc.getTypedIpv4Address().getValue()
- .substring(5);
- String tpIdSrc = this.ipSwitchIdMap.get(ipv4SrcString);
- String[] tempi = tpIdSrc.split(":");
- String swSrcId = tempi[0] + ":" + tempi[1];
- List<DstCosts> dstCostsList = new ArrayList<DstCosts>();
-
- for (int j = 0; j < dsts.size(); ++j) {
- TypedEndpointAddress teaDst = dsts.get(j);
- String ipv4DstString = teaDst.getTypedIpv4Address().getValue()
- .substring(5);
- String tpIdDst = this.ipSwitchIdMap.get(ipv4DstString);
- String[] tempj = tpIdDst.split(":");
- String swDstId = tempj[0] + ":" + tempj[1];
-
- NodeId srcNodeId = new NodeId(swSrcId);
- NodeId dstNodeId = new NodeId(swDstId);
- Number number = shortestPath.getDistance(srcNodeId, dstNodeId);
+ List<EndpointCostMap> result = new ArrayList<EndpointCostMap>();
+ for (int i = 0; i < srcs.size(); ++i) {
+ TypedEndpointAddress teaSrc = srcs.get(i);
+ String ipv4SrcString = teaSrc.getTypedIpv4Address().getValue()
+ .substring(5);
+ String tpIdSrc = this.ipSwitchIdMap.get(ipv4SrcString);
+ String[] tempi = tpIdSrc.split(":");
+ String swSrcId = tempi[0] + ":" + tempi[1];
+ List<DstCosts> dstCostsList = new ArrayList<DstCosts>();
+
+ for (int j = 0; j < dsts.size(); ++j) {
+ TypedEndpointAddress teaDst = dsts.get(j);
+ String ipv4DstString = teaDst.getTypedIpv4Address().getValue()
+ .substring(5);
+ String tpIdDst = this.ipSwitchIdMap.get(ipv4DstString);
+ String[] tempj = tpIdDst.split(":");
+ String swDstId = tempj[0] + ":" + tempj[1];
+
+ NodeId srcNodeId = new NodeId(swSrcId);
+ NodeId dstNodeId = new NodeId(swDstId);
+ Number number = shortestPath.getDistance(srcNodeId, dstNodeId);
DstCosts1 dst1 = null;
if (number!=null) {
- dst1 = new DstCosts1Builder().setCostDefault(number.intValue()).build();
+ dst1 = new DstCosts1Builder().setCostDefault(number.intValue()).build();
}
else {
dst1 = new DstCosts1Builder().setCostDefault(Integer.MAX_VALUE).build();
}
- DstCosts dstCost = new DstCostsBuilder()
- .addAugmentation(DstCosts1.class, dst1).setDst(teaDst)
- .build();
- dstCostsList.add(dstCost);
- }
- EndpointCostMap ecp = new EndpointCostMapBuilder().setSrc(teaSrc)
- .setDstCosts(dstCostsList)
- .setKey(new EndpointCostMapKey(teaSrc)).build();
- result.add(ecp);
- }
- return result;
- }
-
+ DstCosts dstCost = new DstCostsBuilder()
+ .addAugmentation(DstCosts1.class, dst1).setDst(teaDst)
+ .build();
+ dstCostsList.add(dstCost);
+ }
+ EndpointCostMap ecp = new EndpointCostMapBuilder().setSrc(teaSrc)
+ .setDstCosts(dstCostsList)
+ .setKey(new EndpointCostMapKey(teaSrc)).build();
+ result.add(ecp);
+ }
+ return result;
+ }
+
@Override
public Future<RpcResult<EndpointCostServiceOutput>> endpointCostService(
EndpointCostServiceInput input) {
-
+
CostType costTypeInput = null;
List<Constraint> constraintsInput = null;
Endpoints endpointsInput = null;
-
+
RpcResultBuilder<EndpointCostServiceOutput> endpointCostServiceBuilder = null;
EndpointCostServiceOutput output = null;
-
+
if ((costTypeInput = input.getCostType()) == null) {
endpointCostServiceBuilder = RpcResultBuilder.<EndpointCostServiceOutput>failed().withError(ErrorType.APPLICATION, "Invalid cost-type value ", "Argument can not be null.");
}
endpointCostServiceBuilder = RpcResultBuilder.<EndpointCostServiceOutput>failed().withError(ErrorType.APPLICATION, "Invalid endpoints value ", "Argument can not be null.");
}
else {
- Endpoints endpoints = input.getEndpoints();
- List<TypedEndpointAddress> srcs = endpoints.getSrcs();
- List<TypedEndpointAddress> dsts = endpoints.getDsts();
+ Endpoints endpoints = input.getEndpoints();
+ List<TypedEndpointAddress> srcs = endpoints.getSrcs();
+ List<TypedEndpointAddress> dsts = endpoints.getDsts();
boolean srcDstFoundFlag = true;
- for (int i = 0; i < srcs.size(); ++i) {
- TypedEndpointAddress teaSrc = srcs.get(i);
- String ipv4SrcString = teaSrc.getTypedIpv4Address().getValue()
- .substring(5);
+ for (int i = 0; i < srcs.size(); ++i) {
+ TypedEndpointAddress teaSrc = srcs.get(i);
+ String ipv4SrcString = teaSrc.getTypedIpv4Address().getValue()
+ .substring(5);
if (this.ipSwitchIdMap.get(ipv4SrcString) == null) {
- endpointCostServiceBuilder = RpcResultBuilder.<EndpointCostServiceOutput>failed().withError(ErrorType.APPLICATION, "Invalid endpoints value ", "src IP:"+ipv4SrcString+ " can not be found. Or Topology has not been built.");
+ endpointCostServiceBuilder = RpcResultBuilder.<EndpointCostServiceOutput>failed().withError(ErrorType.APPLICATION, "Invalid endpoints value ", "src IP:"+ipv4SrcString+ " can not be found. Or Topology has not been built.");
srcDstFoundFlag = false;
return Futures.immediateFuture(endpointCostServiceBuilder.build());
- }
- }
- for (int j = 0; j < dsts.size(); ++j) {
- TypedEndpointAddress teaDst = dsts.get(j);
- String ipv4DstString = teaDst.getTypedIpv4Address().getValue()
- .substring(5);
- if (this.ipSwitchIdMap.get(ipv4DstString) == null) {
- endpointCostServiceBuilder = RpcResultBuilder.<EndpointCostServiceOutput>failed().withError(ErrorType.APPLICATION, "Invalid endpoints value ", "dst IP:"+ipv4DstString+" can not be found. Or Topology has not been built.");
+ }
+ }
+ for (int j = 0; j < dsts.size(); ++j) {
+ TypedEndpointAddress teaDst = dsts.get(j);
+ String ipv4DstString = teaDst.getTypedIpv4Address().getValue()
+ .substring(5);
+ if (this.ipSwitchIdMap.get(ipv4DstString) == null) {
+ endpointCostServiceBuilder = RpcResultBuilder.<EndpointCostServiceOutput>failed().withError(ErrorType.APPLICATION, "Invalid endpoints value ", "dst IP:"+ipv4DstString+" can not be found. Or Topology has not been built.");
srcDstFoundFlag = false;
return Futures.immediateFuture(endpointCostServiceBuilder.build());
- }
- }
+ }
+ }
CostMetric costMetric = costTypeInput.getCostMetric();
CostMode costMode = costTypeInput.getCostMode();
if (srcDstFoundFlag && costMode.equals(CostMode.Numerical) && (costMetric.getEnumeration() == CostMetric.Enumeration.Hopcount || costMetric.getString().equals("hopcount"))){
- org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.meta.CostType costType = new org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.meta.CostTypeBuilder()
- .setCostMetric(costMetric)
- .setCostMode(costMode).build();
- Meta meta = new MetaBuilder().setCostType(costType).build();
- List<EndpointCostMap> ecmList = hopcountNumerical(srcs, dsts);
- EndpointCostService ecs = new EndpointCostServiceBuilder().setMeta(meta).setEndpointCostMap(ecmList).build();
-
+ org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.meta.CostType costType = new org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.meta.CostTypeBuilder()
+ .setCostMetric(costMetric)
+ .setCostMode(costMode).build();
+ Meta meta = new MetaBuilder().setCostType(costType).build();
+ List<EndpointCostMap> ecmList = hopcountNumerical(srcs, dsts);
+ EndpointCostService ecs = new EndpointCostServiceBuilder().setMeta(meta).setEndpointCostMap(ecmList).build();
+
if ((output = new EndpointCostServiceOutputBuilder().setEndpointCostService(ecs).build()) != null) {
endpointCostServiceBuilder = RpcResultBuilder.success(output);
}
endpointCostServiceBuilder = RpcResultBuilder.<EndpointCostServiceOutput>failed().withError(ErrorType.APPLICATION, "Invalid output value", "Output is null.");
}
return Futures.immediateFuture(endpointCostServiceBuilder.build());
-
+
}
-
+
}
}
return Futures.immediateFuture(RpcResultBuilder.<EndpointCostServiceOutput>failed().withError(ErrorType.APPLICATION, "Invalid output value", "Output is null.").build());
-
+
}
@Override
@Override
public void close() throws ExecutionException, InterruptedException {
- this.hostNodeListerRegistration.close();
- this.linkListerRegistration.close();
- this.ipSwitchIdMap.clear();
- executor.shutdown();
+ this.hostNodeListerRegistration.close();
+ this.linkListerRegistration.close();
+ this.ipSwitchIdMap.clear();
+ executor.shutdown();
if (dataProvider != null) {
WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
tx.delete(LogicalDatastoreType.CONFIGURATION, ALTO_IID);
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.costdefault.rev150507.DstCosts1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.costdefault.rev150507.DstCosts1Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.TypedEndpointAddress;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.TypedEndpointAddressBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.TypedIpv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.host.tracker.rev140624.HostNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.host.tracker.rev140624.HostNodeBuilder;
import org.junit.Before;
import org.junit.Test;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.mock;
public class AltoProviderTest {
private DataBroker dataBroker;
private IpAddress ipAddress;
private MacAddress mac;
-
+
@Before
public void init(){
dataBroker = mock(DataBroker.class);
altoProvider = new AltoProvider();
}
-
+
@Test
public void onProcessTopology() throws Exception {
- IpAddress ipAddress1 = new IpAddress(new Ipv4Address("10.0.0.1"));
- MacAddress mac1 = new MacAddress("00:00:00:00:00:01");
- Addresses addrs1 = new AddressesBuilder().setIp(ipAddress1).setMac(mac1).build();
- List<Addresses> addrsList1 = new ArrayList<Addresses>();
- addrsList1.add(addrs1);
-
- AttachmentPoints ap1 = new AttachmentPointsBuilder().setTpId(new TpId("openflow:1:1")).build();
- List<AttachmentPoints> apList1 = new ArrayList<AttachmentPoints>();
- apList1.add(ap1);
- HostNode hostNode1 = new HostNodeBuilder().setAddresses(addrsList1).setAttachmentPoints(apList1).build();
-
- IpAddress ipAddress2 = new IpAddress(new Ipv4Address("10.0.0.2"));
- MacAddress mac2 = new MacAddress("00:00:00:00:00:02");
- Addresses addrs2 = new AddressesBuilder().setIp(ipAddress2).setMac(mac2).build();
- List<Addresses> addrsList2 = new ArrayList<Addresses>();
- addrsList2.add(addrs2);
-
- AttachmentPoints ap2 = new AttachmentPointsBuilder().setTpId(new TpId("openflow:2:1")).build();
- List<AttachmentPoints> apList2 = new ArrayList<AttachmentPoints>();
- apList2.add(ap2);
- HostNode hostNode2 = new HostNodeBuilder().setAddresses(addrsList2).setAttachmentPoints(apList2).build();
-
-
- Node node1 = new NodeBuilder().addAugmentation(HostNode.class, hostNode1).build();
- Node node2 = new NodeBuilder().addAugmentation(HostNode.class, hostNode2).build();
-
- Node sw1 = new NodeBuilder().setNodeId(new NodeId("openflow:1")).build();
- Node sw2 = new NodeBuilder().setNodeId(new NodeId("openflow:2")).build();
- Node sw3 = new NodeBuilder().setNodeId(new NodeId("openflow:3")).build();
-
- Destination SW1_2 = new DestinationBuilder().setDestNode(new NodeId("openflow:1"))
- .setDestTp(new TpId("openflow:1:2")).build();
- Source SW3_1 = new SourceBuilder().setSourceNode(new NodeId("openflow:3"))
- .setSourceTp(new TpId("openflow:3:1")).build();
- Link l1 = new LinkBuilder().setLinkId(new LinkId("link1"))
- .setDestination(SW1_2)
- .setSource(SW3_1).build();
-
- Destination SW1_3 = new DestinationBuilder().setDestNode(new NodeId("openflow:1"))
- .setDestTp(new TpId("openflow:1:3")).build();
- Source SW2_2 = new SourceBuilder().setSourceNode(new NodeId("openflow:2"))
- .setSourceTp(new TpId("openflow:2:2")).build();
- Link l2 = new LinkBuilder().setLinkId(new LinkId("link2"))
- .setDestination(SW1_3)
- .setSource(SW2_2).build();
-
- Destination SW3_2 = new DestinationBuilder().setDestNode(new NodeId("openflow:3"))
- .setDestTp(new TpId("openflow:3:2")).build();
- Source SW2_3 = new SourceBuilder().setSourceNode(new NodeId("openflow:2"))
- .setSourceTp(new TpId("openflow:2:3")).build();
- Link l3 = new LinkBuilder().setLinkId(new LinkId("link3"))
- .setDestination(SW3_2)
- .setSource(SW2_3).build();
-
- List<Node> nodeList = new ArrayList<Node>();
- nodeList.add(node1);
- nodeList.add(node2);
- nodeList.add(sw1);
- nodeList.add(sw2);
- nodeList.add(sw3);
-
- List<Link> linkList = new ArrayList<Link>();
- linkList.add(l1);
- linkList.add(l2);
- linkList.add(l3);
-
- Topology topology = new TopologyBuilder().setTopologyId(new TopologyId("flow:1"))
- .setLink(linkList)
- .setNode(nodeList).build();
-
- altoProvider.processTopology(topology);
-
- TypedIpv4Address ipv4_1 = new TypedIpv4Address("ipv4:10.0.0.1");
- TypedEndpointAddress tea1 = new TypedEndpointAddress(ipv4_1);
-
- List<TypedEndpointAddress> teaList1 = new ArrayList<TypedEndpointAddress>();
- teaList1.add(tea1);
-
- TypedIpv4Address ipv4_2 = new TypedIpv4Address("ipv4:10.0.0.2");
- TypedEndpointAddress tea2 = new TypedEndpointAddress(ipv4_2);
-
- List<TypedEndpointAddress> teaList2 = new ArrayList<TypedEndpointAddress>();
- teaList2.add(tea2);
-
- DstCosts1 dc1 = new DstCosts1Builder().setCostDefault(1).build();
- DstCosts dc = new DstCostsBuilder().setDst(tea2).addAugmentation(DstCosts1.class, dc1).build();
-
- List<DstCosts> dcList = new ArrayList<DstCosts>();
- dcList.add(dc);
-
- EndpointCostMap ecp = new EndpointCostMapBuilder().setSrc(tea1).setDstCosts(dcList).build();
- List<EndpointCostMap> ecpList = new ArrayList<EndpointCostMap>();
- ecpList.add(ecp);
-
- Assert.assertEquals(altoProvider.hopcountNumerical(teaList1, teaList2), ecpList);
+ IpAddress ipAddress1 = new IpAddress(new Ipv4Address("10.0.0.1"));
+ MacAddress mac1 = new MacAddress("00:00:00:00:00:01");
+ Addresses addrs1 = new AddressesBuilder().setIp(ipAddress1).setMac(mac1).build();
+ List<Addresses> addrsList1 = new ArrayList<Addresses>();
+ addrsList1.add(addrs1);
+
+ AttachmentPoints ap1 = new AttachmentPointsBuilder().setTpId(new TpId("openflow:1:1")).build();
+ List<AttachmentPoints> apList1 = new ArrayList<AttachmentPoints>();
+ apList1.add(ap1);
+ HostNode hostNode1 = new HostNodeBuilder().setAddresses(addrsList1).setAttachmentPoints(apList1).build();
+
+ IpAddress ipAddress2 = new IpAddress(new Ipv4Address("10.0.0.2"));
+ MacAddress mac2 = new MacAddress("00:00:00:00:00:02");
+ Addresses addrs2 = new AddressesBuilder().setIp(ipAddress2).setMac(mac2).build();
+ List<Addresses> addrsList2 = new ArrayList<Addresses>();
+ addrsList2.add(addrs2);
+
+ AttachmentPoints ap2 = new AttachmentPointsBuilder().setTpId(new TpId("openflow:2:1")).build();
+ List<AttachmentPoints> apList2 = new ArrayList<AttachmentPoints>();
+ apList2.add(ap2);
+ HostNode hostNode2 = new HostNodeBuilder().setAddresses(addrsList2).setAttachmentPoints(apList2).build();
+
+
+ Node node1 = new NodeBuilder().addAugmentation(HostNode.class, hostNode1).build();
+ Node node2 = new NodeBuilder().addAugmentation(HostNode.class, hostNode2).build();
+
+ Node sw1 = new NodeBuilder().setNodeId(new NodeId("openflow:1")).build();
+ Node sw2 = new NodeBuilder().setNodeId(new NodeId("openflow:2")).build();
+ Node sw3 = new NodeBuilder().setNodeId(new NodeId("openflow:3")).build();
+
+ Destination SW1_2 = new DestinationBuilder().setDestNode(new NodeId("openflow:1"))
+ .setDestTp(new TpId("openflow:1:2")).build();
+ Source SW3_1 = new SourceBuilder().setSourceNode(new NodeId("openflow:3"))
+ .setSourceTp(new TpId("openflow:3:1")).build();
+ Link l1 = new LinkBuilder().setLinkId(new LinkId("link1"))
+ .setDestination(SW1_2)
+ .setSource(SW3_1).build();
+
+ Destination SW1_3 = new DestinationBuilder().setDestNode(new NodeId("openflow:1"))
+ .setDestTp(new TpId("openflow:1:3")).build();
+ Source SW2_2 = new SourceBuilder().setSourceNode(new NodeId("openflow:2"))
+ .setSourceTp(new TpId("openflow:2:2")).build();
+ Link l2 = new LinkBuilder().setLinkId(new LinkId("link2"))
+ .setDestination(SW1_3)
+ .setSource(SW2_2).build();
+
+ Destination SW3_2 = new DestinationBuilder().setDestNode(new NodeId("openflow:3"))
+ .setDestTp(new TpId("openflow:3:2")).build();
+ Source SW2_3 = new SourceBuilder().setSourceNode(new NodeId("openflow:2"))
+ .setSourceTp(new TpId("openflow:2:3")).build();
+ Link l3 = new LinkBuilder().setLinkId(new LinkId("link3"))
+ .setDestination(SW3_2)
+ .setSource(SW2_3).build();
+
+ List<Node> nodeList = new ArrayList<Node>();
+ nodeList.add(node1);
+ nodeList.add(node2);
+ nodeList.add(sw1);
+ nodeList.add(sw2);
+ nodeList.add(sw3);
+
+ List<Link> linkList = new ArrayList<Link>();
+ linkList.add(l1);
+ linkList.add(l2);
+ linkList.add(l3);
+
+ Topology topology = new TopologyBuilder().setTopologyId(new TopologyId("flow:1"))
+ .setLink(linkList)
+ .setNode(nodeList).build();
+
+ altoProvider.processTopology(topology);
+
+ TypedIpv4Address ipv4_1 = new TypedIpv4Address("ipv4:10.0.0.1");
+ TypedEndpointAddress tea1 = new TypedEndpointAddress(ipv4_1);
+
+ List<TypedEndpointAddress> teaList1 = new ArrayList<TypedEndpointAddress>();
+ teaList1.add(tea1);
+
+ TypedIpv4Address ipv4_2 = new TypedIpv4Address("ipv4:10.0.0.2");
+ TypedEndpointAddress tea2 = new TypedEndpointAddress(ipv4_2);
+
+ List<TypedEndpointAddress> teaList2 = new ArrayList<TypedEndpointAddress>();
+ teaList2.add(tea2);
+
+ DstCosts1 dc1 = new DstCosts1Builder().setCostDefault(1).build();
+ DstCosts dc = new DstCostsBuilder().setDst(tea2).addAugmentation(DstCosts1.class, dc1).build();
+
+ List<DstCosts> dcList = new ArrayList<DstCosts>();
+ dcList.add(dc);
+
+ EndpointCostMap ecp = new EndpointCostMapBuilder().setSrc(tea1).setDstCosts(dcList).build();
+ List<EndpointCostMap> ecpList = new ArrayList<EndpointCostMap>();
+ ecpList.add(ecp);
+
+ Assert.assertEquals(altoProvider.hopcountNumerical(teaList1, teaList2), ecpList);
}
}