Search in sources :

Example 36 with Link

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;
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) DeviceId(org.onosproject.net.DeviceId) Link(org.onosproject.net.Link)

Example 37 with Link

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();
}
Also used : Arrays(java.util.Arrays) Host(org.onosproject.net.Host) AsymmetricPathConstraint(org.onosproject.net.intent.constraint.AsymmetricPathConstraint) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) Link(org.onosproject.net.Link) HostService(org.onosproject.net.host.HostService) ConnectPoint(org.onosproject.net.ConnectPoint) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) DefaultPath(org.onosproject.net.DefaultPath) Intent(org.onosproject.net.intent.Intent) Activate(org.osgi.service.component.annotations.Activate) DefaultLink(org.onosproject.net.DefaultLink) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) DefaultTrafficSelector.builder(org.onosproject.net.flow.DefaultTrafficSelector.builder) Collectors(java.util.stream.Collectors) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) EDGE(org.onosproject.net.Link.Type.EDGE) Path(org.onosproject.net.Path) Reference(org.osgi.service.component.annotations.Reference) DeviceId(org.onosproject.net.DeviceId) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 38 with Link

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);
}
Also used : OpticalAdjacencyLinkService(org.onosproject.drivers.optical.OpticalAdjacencyLinkService) ConnectPoint(org.onosproject.net.ConnectPoint) OpticalAdjacencyLinkService(org.onosproject.drivers.optical.OpticalAdjacencyLinkService) LinkService(org.onosproject.net.link.LinkService) Link(org.onosproject.net.Link)

Example 39 with Link

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));
}
Also used : OpticalAdjacencyLinkService(org.onosproject.drivers.optical.OpticalAdjacencyLinkService) ConnectPoint(org.onosproject.net.ConnectPoint) OpticalAdjacencyLinkService(org.onosproject.drivers.optical.OpticalAdjacencyLinkService) LinkService(org.onosproject.net.link.LinkService) Link(org.onosproject.net.Link) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription)

Example 40 with Link

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();
}
Also used : ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) LinkService(org.onosproject.net.link.LinkService) Link(org.onosproject.net.Link)

Aggregations

Link (org.onosproject.net.Link)210 ConnectPoint (org.onosproject.net.ConnectPoint)92 Test (org.junit.Test)66 DeviceId (org.onosproject.net.DeviceId)62 DefaultLink (org.onosproject.net.DefaultLink)50 Intent (org.onosproject.net.intent.Intent)40 List (java.util.List)38 Set (java.util.Set)33 Collectors (java.util.stream.Collectors)30 Device (org.onosproject.net.Device)30 TrafficSelector (org.onosproject.net.flow.TrafficSelector)30 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)29 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)28 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)28 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)26 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)26 ArrayList (java.util.ArrayList)24 Collections (java.util.Collections)24 Path (org.onosproject.net.Path)24 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)24