use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class FlowRuleIntentInstaller method createIngressToEgressDeviceList.
/**
* Create a list of devices ordered from the ingress to the egress of a path.
* @param resources the resources of the intent
* @return a list of devices
*/
private List<DeviceId> createIngressToEgressDeviceList(Collection<NetworkResource> resources) {
List<DeviceId> deviceIds = Lists.newArrayList();
List<Link> links = Lists.newArrayList();
for (NetworkResource resource : resources) {
if (resource instanceof Link) {
Link linkToAdd = (Link) resource;
if (linkToAdd.type() != Link.Type.EDGE) {
links.add(linkToAdd);
}
}
}
Collections.sort(links, LINK_COMPARATOR);
int i = 0;
for (Link orderedLink : links) {
deviceIds.add(orderedLink.src().deviceId());
if (i == resources.size() - 1) {
deviceIds.add(orderedLink.dst().deviceId());
}
i++;
}
return deviceIds;
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class HostToHostIntentCompiler method createLinkCollectionIntent.
private Intent createLinkCollectionIntent(Path path, Host src, Host dst, HostToHostIntent intent) {
// Try to allocate bandwidth
List<ConnectPoint> pathCPs = path.links().stream().flatMap(l -> Stream.of(l.src(), l.dst())).collect(Collectors.toList());
allocateBandwidth(intent, pathCPs);
Link ingressLink = path.links().get(0);
Link egressLink = path.links().get(path.links().size() - 1);
FilteredConnectPoint ingressPoint = getFilteredPointFromLink(ingressLink);
FilteredConnectPoint egressPoint = getFilteredPointFromLink(egressLink);
TrafficSelector selector = builder(intent.selector()).matchEthSrc(src.mac()).matchEthDst(dst.mac()).build();
/*
* The path contains also the edge links, these are not necessary
* for the LinkCollectionIntent.
*/
Set<Link> coreLinks = path.links().stream().filter(link -> !link.type().equals(EDGE)).collect(Collectors.toSet());
return LinkCollectionIntent.builder().key(intent.key()).appId(intent.appId()).selector(selector).treatment(intent.treatment()).links(coreLinks).filteredIngressPoints(ImmutableSet.of(ingressPoint)).filteredEgressPoints(ImmutableSet.of(egressPoint)).applyTreatmentOnEgress(true).constraints(intent.constraints()).priority(intent.priority()).resourceGroup(intent.resourceGroup()).build();
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class OplinkHandshakerUtil method removeLink.
// Remove incoming link with port if there are any.
private void removeLink(PortNumber portNumber) {
ConnectPoint dst = new ConnectPoint(driver.handler().data().deviceId(), portNumber);
// Check so only incoming links are removed
Set<Link> links = driver.handler().get(LinkService.class).getIngressLinks(dst);
// If link exists, remove it, otherwise return
if (links.isEmpty()) {
return;
}
log.debug("Remove link for {}.", dst);
driver.handler().get(OpticalAdjacencyLinkService.class).linksVanished(dst);
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class OplinkHandshakerUtil method addLink.
// Add incoming link with port
private void addLink(PortNumber portNumber, OplinkPortAdjacency neighbor) {
ConnectPoint dst = new ConnectPoint(driver.handler().data().deviceId(), portNumber);
Set<Link> links = driver.handler().get(LinkService.class).getIngressLinks(dst);
// find out if the new report link is the same as before
for (Link link : links) {
if (link.src().port().equals(neighbor.getPort())) {
return;
}
}
OpticalAdjacencyLinkService adService = driver.handler().get(OpticalAdjacencyLinkService.class);
// remove the old link of destination connect point
if (!links.isEmpty()) {
log.debug("Remove link of destination {}.", dst);
adService.linksVanished(dst);
}
// add the new link
ConnectPoint src = new ConnectPoint(neighbor.getDeviceId(), neighbor.getPort());
log.debug("Add link from {} to {}.", src, dst);
adService.linkDetected(new DefaultLinkDescription(src, dst, Link.Type.OPTICAL));
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class OplinkSwitchProtection method getPeerId.
private DeviceId getPeerId() {
ConnectPoint dstCp = new ConnectPoint(data().deviceId(), PortNumber.portNumber(VIRTUAL_PORT));
Set<Link> links = handler().get(LinkService.class).getIngressLinks(dstCp);
for (Link l : links) {
if (l.type() == Link.Type.VIRTUAL) {
// this device is the destination and peer is the source.
return l.src().deviceId();
}
}
return data().deviceId();
}
Aggregations