use of org.onosproject.net.topology.Topology in project onos by opennetworkinglab.
the class TopologyManagerTest method onDemandPath.
@Test
public void onDemandPath() {
submitTopologyGraph();
Topology topology = service.currentTopology();
LinkWeigher weight = new LinkWeigherAdapter(3.3);
Set<Path> paths = service.getPaths(topology, did("a"), did("c"), weight);
assertEquals("wrong path count", 2, paths.size());
Path path = paths.iterator().next();
assertEquals("wrong path length", 2, path.links().size());
assertEquals("wrong path cost", ScalarWeight.toWeight(6.6), path.weight());
}
use of org.onosproject.net.topology.Topology in project onos by opennetworkinglab.
the class TopologyManagerTest method structure.
@Test
public void structure() {
submitTopologyGraph();
Topology topology = service.currentTopology();
assertTrue("should be infrastructure point", service.isInfrastructure(topology, new ConnectPoint(did("a"), portNumber(1))));
assertFalse("should not be infrastructure point", service.isInfrastructure(topology, new ConnectPoint(did("a"), portNumber(3))));
assertTrue("should be broadcast point", service.isBroadcastPoint(topology, new ConnectPoint(did("a"), portNumber(3))));
}
use of org.onosproject.net.topology.Topology in project onos by opennetworkinglab.
the class DefaultVirtualNetworkProvider method isTraversable.
@Override
public boolean isTraversable(ConnectPoint src, ConnectPoint dst) {
final boolean[] foundSrc = new boolean[1];
final boolean[] foundDst = new boolean[1];
Topology topology = topologyService.currentTopology();
Set<Path> paths = topologyService.getPaths(topology, src.deviceId(), dst.deviceId());
paths.forEach(path -> {
foundDst[0] = false;
foundSrc[0] = false;
// Traverse the links in each path to determine if both the src and dst connection
// point are in the path, if so then this src/dst pair are traversable.
path.links().forEach(link -> {
if (link.src().equals(src)) {
foundSrc[0] = true;
}
if (link.dst().equals(dst)) {
foundDst[0] = true;
}
});
if (foundSrc[0] && foundDst[0]) {
return;
}
});
return foundSrc[0] && foundDst[0];
}
use of org.onosproject.net.topology.Topology in project onos by opennetworkinglab.
the class OpticalConnectivityIntentCompiler method getOpticalPaths.
/**
* Calculates optical paths in WDM topology.
*
* @param intent optical connectivity intent
* @return set of paths in WDM topology
*/
private Stream<Path> getOpticalPaths(OpticalConnectivityIntent intent) {
// Route in WDM topology
Topology topology = topologyService.currentTopology();
// TODO: refactor with LinkWeigher class Implementation
LinkWeigher weight = new LinkWeigher() {
@Override
public Weight getInitialWeight() {
return ScalarWeight.toWeight(0.0);
}
@Override
public Weight getNonViableWeight() {
return ScalarWeight.NON_VIABLE_WEIGHT;
}
/**
* @param edge edge to be weighed
* @return the metric retrieved from the annotations otherwise 1
*/
@Override
public Weight weight(TopologyEdge edge) {
log.debug("Link {} metric {}", edge.link(), edge.link().annotations().value("metric"));
// Disregard inactive or non-optical links
if (edge.link().state() == Link.State.INACTIVE) {
return ScalarWeight.toWeight(-1);
}
if (edge.link().type() != Link.Type.OPTICAL) {
return ScalarWeight.toWeight(-1);
}
// Adhere to static port mappings
DeviceId srcDeviceId = edge.link().src().deviceId();
if (srcDeviceId.equals(intent.getSrc().deviceId())) {
ConnectPoint srcStaticPort = staticPort(intent.getSrc());
if (srcStaticPort != null) {
return ScalarWeight.toWeight(srcStaticPort.equals(edge.link().src()) ? 1 : -1);
}
}
DeviceId dstDeviceId = edge.link().dst().deviceId();
if (dstDeviceId.equals(intent.getDst().deviceId())) {
ConnectPoint dstStaticPort = staticPort(intent.getDst());
if (dstStaticPort != null) {
return ScalarWeight.toWeight(dstStaticPort.equals(edge.link().dst()) ? 1 : -1);
}
}
Annotations annotations = edge.link().annotations();
if (annotations != null && annotations.value("metric") != null && !annotations.value("metric").isEmpty()) {
double metric = Double.parseDouble(annotations.value("metric"));
return ScalarWeight.toWeight(metric);
} else {
return ScalarWeight.toWeight(1);
}
}
};
ConnectPoint start = intent.getSrc();
ConnectPoint end = intent.getDst();
// 0 hop case
if (start.deviceId().equals(end.deviceId())) {
log.debug("install optical intent for 0 hop i.e srcDeviceId=dstDeviceId");
DefaultLink defaultLink = DefaultLink.builder().providerId(PROVIDER_ID).src(start).dst(end).state(Link.State.ACTIVE).type(Link.Type.DIRECT).isExpected(true).build();
List<Link> links = ImmutableList.<Link>builder().add(defaultLink).build();
Annotations annotations = DefaultAnnotations.builder().build();
DefaultPath defaultPath = new DefaultPath(PROVIDER_ID, links, null, annotations);
return ImmutableList.<Path>builder().add(defaultPath).build().stream();
}
// head link's src port should be same as intent src port and tail link dst port
// should be same as intent dst port in the path.
Stream<Path> paths = topologyService.getKShortestPaths(topology, start.deviceId(), end.deviceId(), weight).filter(p -> p.links().get(0).src().port().equals(start.port()) && p.links().get(p.links().size() - 1).dst().port().equals(end.port()));
if (log.isDebugEnabled()) {
return paths.map(path -> {
// no-op map stage to add debug logging
log.debug("Candidate path: {}", path.links().stream().map(lk -> lk.src() + "-" + lk.dst()).collect(Collectors.toList()));
return path;
});
}
return paths;
}
use of org.onosproject.net.topology.Topology in project onos by opennetworkinglab.
the class OpticalOduIntentCompiler method getOpticalPaths.
/**
* Calculates optical paths in OTU topology.
*
* @param intent optical ODU intent
* @return set of paths in OTU topology
*/
private Set<Path> getOpticalPaths(OpticalOduIntent intent) {
// Route in OTU topology
Topology topology = topologyService.currentTopology();
class Weigher implements LinkWeigher {
@Override
public Weight weight(TopologyEdge edge) {
if (edge.link().state() == Link.State.INACTIVE) {
return ScalarWeight.toWeight(-1);
}
if (edge.link().type() != Link.Type.OPTICAL) {
return ScalarWeight.toWeight(-1);
}
// Find path with available TributarySlots resources
if (!isAvailableTributarySlots(intent, edge.link())) {
return ScalarWeight.toWeight(-1);
}
return ScalarWeight.toWeight(1);
}
@Override
public Weight getInitialWeight() {
return null;
}
@Override
public Weight getNonViableWeight() {
return null;
}
}
LinkWeigher weigher = new Weigher();
ConnectPoint start = intent.getSrc();
ConnectPoint end = intent.getDst();
return topologyService.getPaths(topology, start.deviceId(), end.deviceId(), weigher);
}
Aggregations