Search in sources :

Example 21 with LinkService

use of org.onosproject.net.link.LinkService in project onos by opennetworkinglab.

the class OpticalIntentsWebResource method decode.

private Intent decode(ObjectNode json) {
    JsonNode ingressJson = json.get(INGRESS_POINT);
    if (!ingressJson.isObject()) {
        throw new IllegalArgumentException(JSON_INVALID);
    }
    ConnectPoint ingress = codec(ConnectPoint.class).decode((ObjectNode) ingressJson, this);
    JsonNode egressJson = json.get(EGRESS_POINT);
    if (!egressJson.isObject()) {
        throw new IllegalArgumentException(JSON_INVALID);
    }
    ConnectPoint egress = codec(ConnectPoint.class).decode((ObjectNode) egressJson, this);
    JsonNode bidirectionalJson = json.get(BIDIRECTIONAL);
    boolean bidirectional = bidirectionalJson != null ? bidirectionalJson.asBoolean() : false;
    JsonNode signalJson = json.get(SIGNAL);
    OchSignal signal = null;
    if (signalJson != null) {
        if (!signalJson.isObject()) {
            throw new IllegalArgumentException(JSON_INVALID);
        } else {
            signal = OchSignalCodec.decode((ObjectNode) signalJson);
        }
    }
    String appIdString = nullIsIllegal(json.get(APP_ID), APP_ID + MISSING_MEMBER_MESSAGE).asText();
    CoreService service = getService(CoreService.class);
    ApplicationId appId = nullIsNotFound(service.getAppId(appIdString), E_APP_ID_NOT_FOUND);
    Key key = null;
    DeviceService deviceService = get(DeviceService.class);
    JsonNode suggestedPathJson = json.get(SUGGESTEDPATH);
    DefaultPath suggestedPath = null;
    LinkService linkService = get(LinkService.class);
    if (suggestedPathJson != null) {
        if (!suggestedPathJson.isObject()) {
            throw new IllegalArgumentException(JSON_INVALID);
        } else {
            ArrayNode linksJson = nullIsIllegal((ArrayNode) suggestedPathJson.get("links"), "Suggested path specified without links");
            List<Link> listLinks = new ArrayList<>();
            for (JsonNode node : linksJson) {
                String srcString = node.get("src").asText();
                String dstString = node.get("dst").asText();
                ConnectPoint srcConnectPoint = ConnectPoint.fromString(srcString);
                ConnectPoint dstConnectPoint = ConnectPoint.fromString(dstString);
                Link link = linkService.getLink(srcConnectPoint, dstConnectPoint);
                if (link == null) {
                    throw new IllegalArgumentException("Not existing link in the suggested path");
                }
                listLinks.add(link);
            }
            if ((!listLinks.get(0).src().deviceId().equals(ingress.deviceId())) || (!listLinks.get(0).src().port().equals(ingress.port())) || (!listLinks.get(listLinks.size() - 1).dst().deviceId().equals(egress.deviceId())) || (!listLinks.get(listLinks.size() - 1).dst().port().equals(egress.port()))) {
                throw new IllegalArgumentException("Suggested path not compatible with ingress or egress connect points");
            }
            if (!isPathContiguous(listLinks)) {
                throw new IllegalArgumentException("Links specified in the suggested path are not contiguous");
            }
            suggestedPath = new DefaultPath(PROVIDER_ID, listLinks, new ScalarWeight(1));
            log.debug("OpticalIntent along suggestedPath {}", suggestedPath);
        }
    }
    return createExplicitOpticalIntent(ingress, egress, deviceService, key, appId, bidirectional, signal, suggestedPath);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceService(org.onosproject.net.device.DeviceService) ArrayList(java.util.ArrayList) OchSignal(org.onosproject.net.OchSignal) CoreService(org.onosproject.core.CoreService) JsonNode(com.fasterxml.jackson.databind.JsonNode) ConnectPoint(org.onosproject.net.ConnectPoint) ScalarWeight(org.onlab.graph.ScalarWeight) DefaultPath(org.onosproject.net.DefaultPath) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ApplicationId(org.onosproject.core.ApplicationId) LinkService(org.onosproject.net.link.LinkService) Key(org.onosproject.net.intent.Key) Link(org.onosproject.net.Link)

Example 22 with LinkService

use of org.onosproject.net.link.LinkService in project trellis-control by opennetworkinglab.

the class LinkHandler method lastUplink.

/**
 * Returns true if given link was the last active uplink from src-device of
 * link. An uplink is defined as a unidirectional link with src as
 * edgeRouter and dst as non-edgeRouter.
 *
 * @param link
 * @return true if given link was the last uplink from the src device
 */
private boolean lastUplink(Link link) {
    DeviceConfiguration devConfig = srManager.deviceConfiguration;
    try {
        if (!devConfig.isEdgeDevice(link.src().deviceId()) || devConfig.isEdgeDevice(link.dst().deviceId())) {
            return false;
        }
        // note that using linkservice here would cause race conditions as
        // more links can show up while the app is still processing the first one
        Set<Link> devLinks = seenLinks.entrySet().stream().filter(entry -> entry.getKey().src().deviceId().equals(link.src().deviceId())).filter(entry -> entry.getValue()).filter(entry -> !entry.getKey().equals(link)).map(entry -> entry.getKey()).collect(Collectors.toSet());
        for (Link l : devLinks) {
            if (devConfig.isEdgeDevice(l.dst().deviceId())) {
                continue;
            }
            log.debug("Found another active uplink {}", l);
            return false;
        }
        log.debug("No active uplink found");
        return true;
    } catch (DeviceConfigNotFoundException e) {
        log.warn("Unable to determine if link was the last uplink" + e.getMessage());
    }
    return false;
}
Also used : DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) Logger(org.slf4j.Logger) HostLocation(org.onosproject.net.HostLocation) Device(org.onosproject.net.Device) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PortNumber(org.onosproject.net.PortNumber) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) EventuallyConsistentMapBuilder(org.onosproject.store.service.EventuallyConsistentMapBuilder) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Collectors(java.util.stream.Collectors) Link(org.onosproject.net.Link) Sets(com.google.common.collect.Sets) ConnectPoint(org.onosproject.net.ConnectPoint) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) DefaultGroupHandler(org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler) Map(java.util.Map) Entry(java.util.Map.Entry) LinkService(org.onosproject.net.link.LinkService) EventuallyConsistentMap(org.onosproject.store.service.EventuallyConsistentMap) DeviceId(org.onosproject.net.DeviceId) Link(org.onosproject.net.Link) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)

Aggregations

LinkService (org.onosproject.net.link.LinkService)22 ConnectPoint (org.onosproject.net.ConnectPoint)12 Test (org.junit.Test)9 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)9 Link (org.onosproject.net.Link)9 DeviceService (org.onosproject.net.device.DeviceService)5 Collectors (java.util.stream.Collectors)4 Collections (java.util.Collections)3 List (java.util.List)3 Set (java.util.Set)3 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)3 DeviceId (org.onosproject.net.DeviceId)3 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Optional (java.util.Optional)2 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)2 ConnectPoint.deviceConnectPoint (org.onosproject.net.ConnectPoint.deviceConnectPoint)2