Search in sources :

Example 16 with DefaultPath

use of org.onosproject.net.DefaultPath in project onos by opennetworkinglab.

the class AbstractPathService method edgeToEdgePath.

// Produces a direct edge-to-edge path.
private Path edgeToEdgePath(EdgeLink srcLink, EdgeLink dstLink, Path path, LinkWeigher weigher) {
    List<Link> links = Lists.newArrayListWithCapacity(2);
    Weight cost = weigher.getInitialWeight();
    // add the infrastructure path only if it is not null.
    if (srcLink != NOT_HOST) {
        links.add(srcLink);
        cost = cost.merge(weigher.weight(new DefaultTopologyEdge(null, null, srcLink)));
    }
    if (path != null) {
        links.addAll(path.links());
        cost = cost.merge(path.weight());
    }
    if (dstLink != NOT_HOST) {
        links.add(dstLink);
        cost = cost.merge(weigher.weight(new DefaultTopologyEdge(null, null, dstLink)));
    }
    return new DefaultPath(PID, links, cost);
}
Also used : DefaultPath(org.onosproject.net.DefaultPath) Link(org.onosproject.net.Link) DefaultEdgeLink(org.onosproject.net.DefaultEdgeLink) EdgeLink(org.onosproject.net.EdgeLink) Weight(org.onlab.graph.Weight)

Example 17 with DefaultPath

use of org.onosproject.net.DefaultPath in project onos by opennetworkinglab.

the class OpticalPathProvisionerTest method testSetupPath.

/**
 * Checks setupPath method works.
 */
@Test
public void testSetupPath() {
    Bandwidth bandwidth = Bandwidth.bps(100);
    Duration latency = Duration.ofMillis(10);
    List<Link> links = Stream.of(LINK1, LINK2, LINK3, LINK4, LINK5, LINK6).collect(Collectors.toList());
    Path path = new DefaultPath(PROVIDER_ID, links, new ScalarWeight(0));
    OpticalConnectivityId cid = target.setupPath(path, bandwidth, latency);
    assertNotNull(cid);
    // Checks intents are installed as expected
    assertEquals(1, intentService.submitted.size());
    assertEquals(OpticalConnectivityIntent.class, intentService.submitted.get(0).getClass());
    OpticalConnectivityIntent connIntent = (OpticalConnectivityIntent) intentService.submitted.get(0);
    assertEquals(CP31, connIntent.getSrc());
    assertEquals(CP52, connIntent.getDst());
}
Also used : DefaultPath(org.onosproject.net.DefaultPath) Path(org.onosproject.net.Path) OpticalConnectivityId(org.onosproject.newoptical.api.OpticalConnectivityId) Bandwidth(org.onlab.util.Bandwidth) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) Duration(java.time.Duration) DefaultPath(org.onosproject.net.DefaultPath) DefaultLink(org.onosproject.net.DefaultLink) Link(org.onosproject.net.Link) ScalarWeight(org.onlab.graph.ScalarWeight) Test(org.junit.Test)

Example 18 with DefaultPath

use of org.onosproject.net.DefaultPath 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 19 with DefaultPath

use of org.onosproject.net.DefaultPath 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;
}
Also used : Path(org.onosproject.net.Path) DefaultPath(org.onosproject.net.DefaultPath) DefaultLink(org.onosproject.net.DefaultLink) DeviceId(org.onosproject.net.DeviceId) Topology(org.onosproject.net.topology.Topology) TopologyEdge(org.onosproject.net.topology.TopologyEdge) ConnectPoint(org.onosproject.net.ConnectPoint) Annotations(org.onosproject.net.Annotations) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) LinkWeigher(org.onosproject.net.topology.LinkWeigher) DefaultPath(org.onosproject.net.DefaultPath) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink)

Aggregations

DefaultPath (org.onosproject.net.DefaultPath)19 Link (org.onosproject.net.Link)10 ArrayList (java.util.ArrayList)7 Before (org.junit.Before)7 Path (org.onosproject.net.Path)6 DefaultLink (org.onosproject.net.DefaultLink)5 ResourceContext (org.onosproject.net.intent.ResourceContext)5 ScalarWeight (org.onlab.graph.ScalarWeight)4 CoreService (org.onosproject.core.CoreService)4 DisjointPath (org.onosproject.net.DisjointPath)4 Test (org.junit.Test)3 Annotations (org.onosproject.net.Annotations)3 ConnectPoint (org.onosproject.net.ConnectPoint)3 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)3 DeviceId (org.onosproject.net.DeviceId)3 EdgeLink (org.onosproject.net.EdgeLink)3 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)3 Intent (org.onosproject.net.intent.Intent)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2