package org.opendaylight.alto.provider;
+import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
-import java.util.logging.Level;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Level;
+
+import org.opendaylight.alto.commons.helper.NetworkMapIpPrefixHelper;
+import org.opendaylight.alto.commons.types.model150404.ModelCostMapMeta;
import org.opendaylight.controller.config.yang.config.alto_provider.impl.AltoProviderRuntimeMXBean;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+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.costdefault.rev150507.DstCosts2;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.AltoServiceService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.EndpointCostServiceInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.EndpointCostServiceOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.MetaBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.endpoint.cost.map.DstCosts;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.endpoint.cost.map.DstCostsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.Constraint;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.resources.CostMaps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.resources.IRD;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.resources.NetworkMaps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.resources.cost.maps.CostMap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.resources.cost.maps.CostMapKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.resources.network.maps.NetworkMap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.resources.network.maps.NetworkMapKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.CostMetric;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.CostMode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.PidName;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.ResourceId;
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.ird.meta.DefaultAltoNetworkMap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.host.tracker.rev140624.HostNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.host.tracker.rev140624.host.AttachmentPoints;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
-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.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import edu.uci.ics.jung.graph.SparseMultigraph;
import edu.uci.ics.jung.graph.util.EdgeType;
-public class AltoProvider implements
- AltoServiceService, DataChangeListener,
- AltoProviderRuntimeMXBean, AutoCloseable {
+public class AltoProvider implements AltoServiceService, DataChangeListener,
+ AltoProviderRuntimeMXBean, AutoCloseable {
- private static final Logger log = LoggerFactory.getLogger(AltoProvider.class);
+ private static final Logger log = LoggerFactory
+ .getLogger(AltoProvider.class);
private ListenerRegistration<DataChangeListener> hostNodeListerRegistration;
private ListenerRegistration<DataChangeListener> linkListerRegistration;
private ListenerRegistration<DataChangeListener> topologyListerRegistration;
+ private ListenerRegistration<DataChangeListener> defaultNetworkMapperRegistration;
+ private NetworkMapIpPrefixHelper ipHelper = new NetworkMapIpPrefixHelper();
+
private Map<String, String> ipSwitchIdMap = null;
Graph<NodeId, Link> networkGraph = null;
Set<String> linkAdded = null;
DijkstraShortestPath<NodeId, Link> shortestPath = null;
private AtomicBoolean networkGraphFlag;
- public static final InstanceIdentifier<Resources> ALTO_IID
- = InstanceIdentifier.builder(Resources.class).build();
+ public static final InstanceIdentifier<Resources> ALTO_IID = InstanceIdentifier
+ .builder(Resources.class).build();
private DataBroker dataProvider;
private final ExecutorService executor;
+ private InstanceIdentifier<DefaultAltoNetworkMap> DEFAULT_NETWORK_MAP_IID = InstanceIdentifier
+ .builder(Resources.class)
+ .child(IRD.class)
+ .child(org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.ird.Meta.class)
+ .child(DefaultAltoNetworkMap.class).build();
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
public AltoProvider() {
this.networkGraph = new SparseMultigraph<>();
this.shortestPath = new DijkstraShortestPath(this.networkGraph);
log.info(this.getClass().getName() + " data provider initiated");
}
+ private NetworkMap readNetworkMap(ResourceId rid)
+ throws InterruptedException, ExecutionException {
+ NetworkMapKey key = new NetworkMapKey(rid);
+ InstanceIdentifier<NetworkMap> iid = InstanceIdentifier
+ .builder(Resources.class).child(NetworkMaps.class)
+ .child(NetworkMap.class, key).build();
+ return readDataFromConfiguration(iid);
+ }
+
public void registerAsDataChangeListener() {
+ this.defaultNetworkMapperRegistration = dataProvider
+ .registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
+ this.DEFAULT_NETWORK_MAP_IID, this,
+ DataChangeScope.BASE);
+
InstanceIdentifier<HostNode> hostNodes = InstanceIdentifier
.builder(NetworkTopology.class)//
.child(Topology.class,
DataChangeScope.BASE);
InstanceIdentifier<Topology> topology = InstanceIdentifier
- .builder(NetworkTopology.class)//
+ .builder(NetworkTopology.class)
+ //
.child(Topology.class,
new TopologyKey(new TopologyId("flow:1"))).build();
- this.topologyListerRegistration = dataProvider.registerDataChangeListener(
- LogicalDatastoreType.OPERATIONAL, topology, this,
- DataChangeScope.BASE);
+ 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();
+ dataFuture.get().get();
} catch (InterruptedException | ExecutionException ex) {
java.util.logging.Logger.getLogger(AltoProvider.class.getName())
.log(Level.SEVERE, null, ex);
if (this.networkGraph == null) {
this.networkGraph = new SparseMultigraph<>();
- networkGraphFlag.set(true);
+ networkGraphFlag.set(true);
}
for (Link link : links) {
this.networkGraph.addVertex(destinationNodeId);
this.networkGraph.addEdge(link, sourceNodeId, destinationNodeId,
EdgeType.UNDIRECTED);
- networkGraphFlag.set(true);
+ networkGraphFlag.set(true);
}
}
public void processTopology(Topology topology) {
List<Node> nodeList = null;
- if ((nodeList = topology.getNode()) != 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);
+ 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();
-
- TpId tpId = attachmentPoints.get(0).getTpId();
- String tpIdString = tpId.getValue();
-
- String ipv4String = hostNode.getAddresses().get(0).getIp()
- .getIpv4Address().getValue();
-
- this.ipSwitchIdMap.remove(ipv4String);
+ String ipv4String = hostNode.getAddresses().get(0).getIp()
+ .getIpv4Address().getValue();
+ this.ipSwitchIdMap.remove(ipv4String);
}
private void processNode(HostNode hostNode) {
- if (this.networkGraph==null) {
- this.networkGraph = new SparseMultigraph<>();
- }
- if(hostNode==null)return;
+ if (this.networkGraph == null) {
+ this.networkGraph = new SparseMultigraph<>();
+ }
+ if (hostNode == null)
+ return;
List<AttachmentPoints> attachmentPoints = hostNode
.getAttachmentPoints();
@Override
public void onDataChanged(
final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
- log.info("in Data Changed");
+ log.info("in Data Changed");
if (change == null) {
log.info("In onDataChanged: No processing done as change even is null.");
return;
Set<InstanceIdentifier<?>> deletedData = change.getRemovedPaths();
for (InstanceIdentifier<?> iid : deletedData) {
- log.info("delete Data");
+ log.info("delete Data");
if (iid.getTargetType().equals(HostNode.class)) {
- log.info("delete hostnode");
+ log.info("delete hostnode");
HostNode node = ((HostNode) originalData.get(iid));
deleteHostNode(node);
} else if (iid.getTargetType().equals(Link.class)) {
- log.info("delete edge");
- 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);
- }
+ log.info("delete edge");
+ 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));
- networkGraphFlag.set(true);
+ networkGraphFlag.set(true);
+ } else if (iid.getTargetType().equals(DefaultAltoNetworkMap.class)) {
+ ipHelper.clear();
}
}
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");
+ log.info("update hostnode data");
processNode((HostNode) dataObject);
+ } else if (dataObject instanceof DefaultAltoNetworkMap) {
+ try {
+ DefaultAltoNetworkMap defaultMap = (DefaultAltoNetworkMap) dataObject;
+ NetworkMap networkMap = readNetworkMap(defaultMap
+ .getResourceId());
+ ipHelper.update(networkMap);
+ } catch (InterruptedException | ExecutionException
+ | UnknownHostException e) {
+ e.printStackTrace();
+ }
}
}
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");
+ log.info("update HostNode");
processNode((HostNode) dataObject);
} else if (dataObject instanceof Link) {
- log.info("update link");
+ log.info("update link");
Link link = (Link) dataObject;
if (!linkAlreadyAdded(link)) {
NodeId sourceNodeId = link.getSource().getSourceNode();
.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);
+ this.networkGraph.addEdge(link, sourceNodeId,
+ destinationNodeId, EdgeType.UNDIRECTED);
+ log.info("update link in networkGraph");
+ networkGraphFlag.set(true);
+ }
+ } else if (dataObject instanceof DefaultAltoNetworkMap) {
+ try {
+ DefaultAltoNetworkMap defaultMap = (DefaultAltoNetworkMap) dataObject;
+ NetworkMap networkMap = readNetworkMap(defaultMap
+ .getResourceId());
+ ipHelper.update(networkMap);
+ } catch (InterruptedException | ExecutionException
+ | UnknownHostException e) {
+ e.printStackTrace();
+ ipHelper.clear();
}
}
}
}
- public List<EndpointCostMap> hopcountNumerical(List<TypedEndpointAddress> srcs, List<TypedEndpointAddress> dsts) {
- if (networkGraphFlag.get()) {
- shortestPath = new DijkstraShortestPath(this.networkGraph);
- networkGraphFlag.set(false);
- }
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public List<EndpointCostMap> hopcountNumerical(
+ List<TypedEndpointAddress> srcs, List<TypedEndpointAddress> dsts) {
+ if (networkGraphFlag.get()) {
+ 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);
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();
- }
- else {
- dst1 = new DstCosts1Builder().setCostDefault(Integer.MAX_VALUE).build();
- }
+ DstCosts1 dst1 = null;
+ if (number != null) {
+ dst1 = new DstCosts1Builder().setCostDefault(
+ Integer.toString(number.intValue())).build();
+ } else {
+ dst1 = new DstCosts1Builder().setCostDefault(
+ Integer.toString(Integer.MAX_VALUE)).build();
+ }
DstCosts dstCost = new DstCostsBuilder()
.addAugmentation(DstCosts1.class, dst1).setDst(teaDst)
.build();
@Override
public Future<RpcResult<EndpointCostServiceOutput>> endpointCostService(
EndpointCostServiceInput input) {
+ RpcResultBuilder<EndpointCostServiceOutput> endpointCostServiceBuilder = null;
+ if (input.getCostType() == null) {
+ endpointCostServiceBuilder = RpcResultBuilder
+ .<EndpointCostServiceOutput> failed().withError(
+ ErrorType.APPLICATION, "Invalid cost-type value ",
+ "Argument can not be null.");
+ }
+
+ if (input.getEndpoints() == null) {
+ endpointCostServiceBuilder = RpcResultBuilder
+ .<EndpointCostServiceOutput> failed().withError(
+ ErrorType.APPLICATION, "Invalid endpoints value ",
+ "Argument can not be null.");
+ }
- CostType costTypeInput = null;
- List<Constraint> constraintsInput = null;
- Endpoints endpointsInput = null;
+ return hosttrackerNumericalHopCountImplementation(input, endpointCostServiceBuilder);
+ }
- RpcResultBuilder<EndpointCostServiceOutput> endpointCostServiceBuilder = null;
+ public ListenableFuture<RpcResult<EndpointCostServiceOutput>> interopECSImplementation(
+ EndpointCostServiceInput input,
+ RpcResultBuilder<EndpointCostServiceOutput> endpointCostServiceBuilder) {
+ if (!ipHelper.initiated()) {
+ return Futures.immediateFuture(RpcResultBuilder
+ .<EndpointCostServiceOutput> failed()
+ .withError(ErrorType.APPLICATION, "Default Map Error",
+ "Failed to parse default network map.").build());
+ }
+
+ Endpoints endpoints = input.getEndpoints();
+ CostMap costMap = getDefaultCostMap(input.getCostType());
+ if (costMap == null) {
+ return Futures.immediateFuture(RpcResultBuilder
+ .<EndpointCostServiceOutput> failed()
+ .withError(ErrorType.APPLICATION, "Cost Map Error",
+ "Failed to read data from cost map.").build());
+ }
EndpointCostServiceOutput output = null;
+ org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.meta.CostType eCostType = new org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.meta.CostTypeBuilder()
+ .setCostMetric(input.getCostType().getCostMetric())
+ .setCostMode(input.getCostType().getCostMode()).build();
+
+ Meta meta = new MetaBuilder().setCostType(eCostType).build();
+ List<TypedEndpointAddress> srcs = endpoints.getSrcs();
+ List<TypedEndpointAddress> dsts = endpoints.getDsts();
+ List<EndpointCostMap> ecmList = getEndpointCostListFromCostMap(
+ ipHelper, costMap, srcs, dsts);
+ EndpointCostService ecs = new EndpointCostServiceBuilder()
+ .setMeta(meta).setEndpointCostMap(ecmList).build();
+
+ if ((output = new EndpointCostServiceOutputBuilder()
+ .setEndpointCostService(ecs).build()) != null) {
+ endpointCostServiceBuilder = RpcResultBuilder.success(output);
+ } else {
+ endpointCostServiceBuilder = RpcResultBuilder
+ .<EndpointCostServiceOutput> failed().withError(
+ ErrorType.APPLICATION, "Invalid output value",
+ "Output is null.");
+ }
+
+ return Futures.immediateFuture(endpointCostServiceBuilder.build());
+ }
- if ((costTypeInput = input.getCostType()) == null) {
- endpointCostServiceBuilder = RpcResultBuilder.<EndpointCostServiceOutput>failed().withError(ErrorType.APPLICATION, "Invalid cost-type value ", "Argument can not be null.");
+ private CostMap getDefaultCostMap(CostType costType) {
+ CostMap costMap = null;
+ try {
+ String costMapRid = ModelCostMapMeta.getCostMapResourceId(
+ readDefaultNetworkMapId().getValue(), costType
+ .getCostMetric().getString(), costType
+ .getCostMode().name().toLowerCase());
+ InstanceIdentifier<CostMap> costMapNode = costMapIID(new ResourceId(
+ costMapRid));
+ costMap = readDataFromConfiguration(costMapNode);
+ } catch (InterruptedException | ExecutionException e) {
+ e.printStackTrace();
}
- else {
- if ((endpointsInput = input.getEndpoints()) == 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();
- boolean srcDstFoundFlag = true;
- 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.");
- srcDstFoundFlag = false;
- return Futures.immediateFuture(endpointCostServiceBuilder.build());
- }
+ return costMap;
+ }
+
+ private ResourceId readDefaultNetworkMapId() throws InterruptedException,
+ ExecutionException {
+ return readDataFromConfiguration(this.DEFAULT_NETWORK_MAP_IID)
+ .getResourceId();
+ }
+
+ private InstanceIdentifier<CostMap> costMapIID(ResourceId rid) {
+ return InstanceIdentifier.builder(Resources.class)
+ .child(CostMaps.class)
+ .child(CostMap.class, new CostMapKey(rid)).build();
+ }
+
+ public List<EndpointCostMap> getEndpointCostListFromCostMap(
+ NetworkMapIpPrefixHelper ipHelper, CostMap costMap,
+ List<TypedEndpointAddress> srcs, List<TypedEndpointAddress> dsts) {
+ Map<TypedEndpointAddress, PidName> srcPids = ipHelper
+ .getPIDsByEndpointAddresses(srcs);
+ Map<TypedEndpointAddress, PidName> dstPids = ipHelper
+ .getPIDsByEndpointAddresses(dsts);
+ Map<PidName, Map<PidName, DstCosts2>> costMaps = costMapListToMap(costMap
+ .getMap());
+
+ List<EndpointCostMap> ecmList = new ArrayList<EndpointCostMap>();
+ for (TypedEndpointAddress src : srcs) {
+ List<DstCosts> dstList = new ArrayList<DstCosts>();
+ for (TypedEndpointAddress dst : dsts) {
+ PidName srcPid = srcPids.get(src);
+ PidName dstPid = dstPids.get(dst);
+ String cost = getCostDefault(srcPid, dstPid, costMaps);
+ if (cost != null) {
+ DstCosts1 dstCost1 = new DstCosts1Builder().setCostDefault(
+ cost).build();
+ DstCosts dstCosts = new DstCostsBuilder()
+ .setDst(dst)
+ .setKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.endpoint.cost.service.output.endpoint.cost.service.endpoint.cost.map.DstCostsKey(
+ dst))
+ .addAugmentation(DstCosts1.class, dstCost1).build();
+ dstList.add(dstCosts);
}
- 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());
- }
+ }
+ if (dstList.size() > 0) {
+ ecmList.add(new EndpointCostMapBuilder().setDstCosts(dstList)
+ .setKey(new EndpointCostMapKey(src)).setSrc(src).build());
+ }
+ }
+ return ecmList;
+ }
+
+ private String getCostDefault(PidName srcPid, PidName dstPid,
+ Map<PidName, Map<PidName, DstCosts2>> costMaps) {
+ if (srcPid != null && dstPid != null) {
+ Map<PidName, DstCosts2> dstMap = costMaps.get(srcPid);
+ if (dstMap != null) {
+ DstCosts2 dstCost2 = dstMap.get(dstPid);
+ if (dstCost2 != null) {
+ return dstCost2.getCostDefault();
}
- 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();
-
- if ((output = new EndpointCostServiceOutputBuilder().setEndpointCostService(ecs).build()) != null) {
- endpointCostServiceBuilder = RpcResultBuilder.success(output);
- }
- else {
- endpointCostServiceBuilder = RpcResultBuilder.<EndpointCostServiceOutput>failed().withError(ErrorType.APPLICATION, "Invalid output value", "Output is null.");
- }
- return Futures.immediateFuture(endpointCostServiceBuilder.build());
+ }
+ }
+ return null;
+ }
+ private Map<PidName, Map<PidName, DstCosts2>> costMapListToMap(
+ List<org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.cost.map.Map> costMaps) {
+ Map<PidName, Map<PidName, DstCosts2>> resultCostMaps = new HashMap<PidName, Map<PidName, DstCosts2>>();
+ for (org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.cost.map.Map costMap : costMaps) {
+ Map<PidName, DstCosts2> resultCostMap = new HashMap<PidName, DstCosts2>();
+ for (org.opendaylight.yang.gen.v1.urn.opendaylight.alto.rev150404.cost.map.map.DstCosts dstCosts : costMap
+ .getDstCosts()) {
+ DstCosts2 cost = dstCosts.getAugmentation(DstCosts2.class);
+ if (cost != null) {
+ resultCostMap.put(dstCosts.getDst(), cost);
}
+ }
+ resultCostMaps.put(costMap.getSrc(), resultCostMap);
+ }
+ return resultCostMaps;
+ }
+
+ @SuppressWarnings("unused")
+ private ListenableFuture<RpcResult<EndpointCostServiceOutput>> hosttrackerNumericalHopCountImplementation(
+ EndpointCostServiceInput input,
+ RpcResultBuilder<EndpointCostServiceOutput> endpointCostServiceBuilder) {
+ Endpoints endpoints = input.getEndpoints();
+ List<TypedEndpointAddress> srcs = endpoints.getSrcs();
+ List<TypedEndpointAddress> dsts = endpoints.getDsts();
+ CostType costTypeInput = input.getCostType();
+ EndpointCostServiceOutput output = null;
+
+ boolean srcDstFoundFlag = true;
+ 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.");
+ 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.");
+ 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();
+
+ if ((output = new EndpointCostServiceOutputBuilder()
+ .setEndpointCostService(ecs).build()) != null) {
+ endpointCostServiceBuilder = RpcResultBuilder.success(output);
+ } else {
+ 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());
+ return Futures.immediateFuture(RpcResultBuilder
+ .<EndpointCostServiceOutput> failed()
+ .withError(ErrorType.APPLICATION, "Invalid output value",
+ "Output is null.").build());
}
@Override
this.hostNodeListerRegistration.close();
this.linkListerRegistration.close();
this.ipSwitchIdMap.clear();
+ this.defaultNetworkMapperRegistration.close();
+ this.topologyListerRegistration.close();
executor.shutdown();
if (dataProvider != null) {
WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
log.debug("Delete ALTO commit result: " + result);
}
- @Override
- public void onFailure(final Throwable t) {
- log.error("Delete of ALTO failed", t);
- }
+ @Override
+ public void onFailure(final Throwable t) {
+ log.error("Delete of ALTO failed", t);
+ }
});
}
}
+
+ private <T extends DataObject> T readDataFromConfiguration(
+ InstanceIdentifier<T> iid) throws InterruptedException,
+ ExecutionException {
+ ReadOnlyTransaction tx = this.dataProvider.newReadOnlyTransaction();
+ Optional<T> optional = tx.read(LogicalDatastoreType.CONFIGURATION, iid)
+ .get();
+ if (optional.isPresent()) {
+ return optional.get();
+ }
+ return null;
+ }
}