use of org.onosproject.net.Path in project onos by opennetworkinglab.
the class PathListCommand method doExecute.
@Override
protected void doExecute() {
init();
DeviceService deviceService = get(DeviceService.class);
DeviceId srcDid = deviceId(src);
if (deviceService.getDevice(srcDid) == null) {
print("Unknown device %s", src);
return;
}
DeviceId dstDid = deviceId(dst);
if (deviceService.getDevice(dstDid) == null) {
print("Unknown device %s", dst);
return;
}
Set<? extends Path> paths;
if (disjoint) {
paths = service.getDisjointPaths(topology, srcDid, dstDid);
} else {
paths = service.getPaths(topology, srcDid, dstDid);
}
if (outputJson()) {
print("%s", json(this, paths));
} else {
for (Path path : paths) {
print(pathString(path));
if (path instanceof DisjointPath) {
// print backup right after primary
print(pathString(((DisjointPath) path).backup()));
}
}
}
}
use of org.onosproject.net.Path in project onos by opennetworkinglab.
the class PointToPointIntentCompiler method createSinglePathIntent.
private List<Intent> createSinglePathIntent(ConnectPoint ingressPoint, ConnectPoint egressPoint, PointToPointIntent intent, List<Intent> installable) {
List<Link> links = new ArrayList<>();
Path onlyPath = getPathOrException(intent, ingressPoint.deviceId(), egressPoint.deviceId());
List<Intent> reusableIntents = null;
if (installable != null) {
reusableIntents = filterInvalidSubIntents(installable, intent);
if (reusableIntents.size() == installable.size()) {
// all old paths are still viable
return installable;
}
}
// return the intents that comprise it.
if (reusableIntents != null && reusableIntents.size() > 1) {
return reusableIntents;
} else {
// Allocate bandwidth if a bandwidth constraint is set
allocateIntentBandwidth(intent, onlyPath);
links.add(createEdgeLink(ingressPoint, true));
links.addAll(onlyPath.links());
links.add(createEdgeLink(egressPoint, false));
return asList(createPathIntent(new DefaultPath(PID, links, onlyPath.weight(), onlyPath.annotations()), intent, PathIntent.ProtectionType.PRIMARY));
}
}
use of org.onosproject.net.Path in project onos by opennetworkinglab.
the class PointToPointIntentCompiler method pathAvailable.
/**
* Checks suggested path availability.
* It checks:
* - single links availability;
* - that first and last device of the path are coherent with ingress and egress devices;
* - links contiguity.
*
* @param intent Intent with suggested path to check
* @return true if the suggested path is available
*/
private boolean pathAvailable(PointToPointIntent intent) {
// Check links availability
List<Link> suggestedPath = intent.suggestedPath();
for (Link link : suggestedPath) {
if (!(link instanceof EdgeLink) && !linkService.getLinks(link.src()).contains(link)) {
return false;
}
}
// Check that first and last device of the path are intent ingress and egress devices
if (!suggestedPath.get(0).src().deviceId().equals(intent.filteredIngressPoint().connectPoint().deviceId())) {
return false;
}
if (!suggestedPath.get(suggestedPath.size() - 1).dst().deviceId().equals(intent.filteredEgressPoint().connectPoint().deviceId())) {
return false;
}
// Check contiguity
List<Pair<Link, Link>> linkPairs = IntStream.range(0, suggestedPath.size() - 1).mapToObj(i -> Pair.of(suggestedPath.get(i), suggestedPath.get(i + 1))).collect(Collectors.toList());
for (Pair<Link, Link> linkPair : linkPairs) {
if (!linkPair.getKey().dst().deviceId().equals(linkPair.getValue().src().deviceId())) {
return false;
}
}
return true;
}
use of org.onosproject.net.Path in project onos by opennetworkinglab.
the class PointToPointIntentCompiler method createUnprotectedLinkCollectionIntent.
private List<Intent> createUnprotectedLinkCollectionIntent(PointToPointIntent intent) {
Path path = getPathOrException(intent, intent.filteredIngressPoint().connectPoint().deviceId(), intent.filteredEgressPoint().connectPoint().deviceId());
// Allocate bandwidth if a bandwidth constraint is set
allocateIntentBandwidth(intent, path);
return asList(createLinkCollectionIntent(ImmutableSet.copyOf(path.links()), path.cost(), intent));
}
use of org.onosproject.net.Path in project onos by opennetworkinglab.
the class ProtectedTransportIntentCompiler method createFreshProtectedPaths.
/**
* Creates new protected paths.
*
* @param intent original intention
* @param did1 identifier of first device
* @param did2 identifier of second device
* @return compilation result
* @throws IntentCompilationException when there's no satisfying path.
*/
private List<Intent> createFreshProtectedPaths(ProtectedTransportIntent intent, DeviceId did1, DeviceId did2) {
DisjointPath disjointPath = getDisjointPath(intent, did1, did2);
if (disjointPath == null || disjointPath.backup() == null) {
log.error("Unable to find disjoint path between {}, {}", did1, did2);
throw new IntentCompilationException("Unable to find disjoint paths.");
}
Path primary = disjointPath.primary();
Path secondary = disjointPath.backup();
String fingerprint = intent.key().toString();
// pick and allocate Vlan to use as S-tag
Pair<VlanId, VlanId> vlans = allocateEach(intent, primary, secondary, VlanId.class);
VlanId primaryVlan = vlans.getLeft();
VlanId secondaryVlan = vlans.getRight();
// Build edge Intents for head/tail
// resource for head/tail
Collection<NetworkResource> oneResources = new ArrayList<>();
Collection<NetworkResource> twoResources = new ArrayList<>();
List<TransportEndpointDescription> onePaths = new ArrayList<>();
onePaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(primary.src(), primaryVlan)).build());
onePaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(secondary.src(), secondaryVlan)).build());
List<TransportEndpointDescription> twoPaths = new ArrayList<>();
twoPaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(primary.dst(), primaryVlan)).build());
twoPaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(secondary.dst(), secondaryVlan)).build());
ProtectionEndpointIntent oneIntent = ProtectionEndpointIntent.builder().key(intent.key()).appId(intent.appId()).priority(intent.priority()).resources(oneResources).deviceId(did1).description(buildDescription(onePaths, did2, fingerprint)).build();
ProtectionEndpointIntent twoIntent = ProtectionEndpointIntent.builder().key(intent.key()).appId(intent.appId()).resources(twoResources).deviceId(did2).description(buildDescription(twoPaths, did1, fingerprint)).build();
// Build transit intent for primary/secondary path
Collection<NetworkResource> resources1 = ImmutableList.of(marker("protection1"));
Collection<NetworkResource> resources2 = ImmutableList.of(marker("protection2"));
ImmutableList<Intent> result = ImmutableList.<Intent>builder().addAll(createTransitIntent(intent, primary, primaryVlan, resources1)).addAll(createTransitIntent(intent, secondary, secondaryVlan, resources2)).add(oneIntent).add(twoIntent).build();
log.trace("createFreshProtectedPaths result: {}", result);
return result;
}
Aggregations