Search in sources :

Example 1 with ScalarWeight

use of org.onlab.graph.ScalarWeight in project onos by opennetworkinglab.

the class OpticalIntentsWebResource method getIntents.

/**
 * Get the optical intents on the network.
 *
 * @return 200 OK
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getIntents() {
    DeviceService deviceService = get(DeviceService.class);
    IntentService intentService = get(IntentService.class);
    Iterator intentItr = intentService.getIntents().iterator();
    ArrayNode arrayFlows = mapper().createArrayNode();
    while (intentItr.hasNext()) {
        Intent intent = (Intent) intentItr.next();
        if (intent instanceof OpticalConnectivityIntent) {
            OpticalConnectivityIntent opticalConnectivityIntent = (OpticalConnectivityIntent) intent;
            Device srcDevice = deviceService.getDevice(opticalConnectivityIntent.getSrc().deviceId());
            Device dstDevice = deviceService.getDevice(opticalConnectivityIntent.getDst().deviceId());
            String srcDeviceName = srcDevice.annotations().value(AnnotationKeys.NAME);
            String dstDeviceName = dstDevice.annotations().value(AnnotationKeys.NAME);
            ObjectNode objectNode = mapper().createObjectNode();
            objectNode.put("intent id", opticalConnectivityIntent.id().toString());
            objectNode.put("app id", opticalConnectivityIntent.appId().name());
            objectNode.put("state", intentService.getIntentState(opticalConnectivityIntent.key()).toString());
            objectNode.put("src", opticalConnectivityIntent.getSrc().toString());
            objectNode.put("dst", opticalConnectivityIntent.getDst().toString());
            objectNode.put("srcName", srcDeviceName);
            objectNode.put("dstName", dstDeviceName);
            // Only for INSTALLED intents
            if (intentService.getIntentState(intent.key()) == IntentState.INSTALLED) {
                // Retrieve associated FlowRuleIntent
                FlowRuleIntent installableIntent = (FlowRuleIntent) intentService.getInstallableIntents(opticalConnectivityIntent.key()).stream().filter(FlowRuleIntent.class::isInstance).findFirst().orElse(null);
                // TODO store utilized ochSignal in the intent resources
                if (installableIntent != null) {
                    OchSignal signal = installableIntent.flowRules().stream().filter(r -> r.selector().criteria().size() == NUM_CRITERIA_OPTICAL_CONNECTIVIY_RULE).map(r -> ((OchSignalCriterion) r.selector().getCriterion(Criterion.Type.OCH_SIGID)).lambda()).findFirst().orElse(null);
                    objectNode.put("ochSignal", signal.toString());
                    objectNode.put("centralFreq", signal.centralFrequency().asTHz() + " THz");
                }
                // Retrieve path and print it to REST
                if (installableIntent != null) {
                    String path = installableIntent.resources().stream().filter(Link.class::isInstance).map(Link.class::cast).map(r -> deviceService.getDevice(r.src().deviceId())).map(r -> r.annotations().value(AnnotationKeys.NAME)).collect(Collectors.joining(" -> "));
                    List<Link> pathLinks = installableIntent.resources().stream().filter(Link.class::isInstance).map(Link.class::cast).collect(Collectors.toList());
                    DefaultPath defaultPath = new DefaultPath(PROVIDER_ID, pathLinks, new ScalarWeight(1));
                    objectNode.put("path", defaultPath.toString());
                    objectNode.put("pathName", path + " -> " + dstDeviceName);
                }
            }
            arrayFlows.add(objectNode);
        }
    }
    ObjectNode root = this.mapper().createObjectNode().putPOJO("Intents", arrayFlows);
    return ok(root).build();
}
Also used : AbstractWebResource(org.onosproject.rest.AbstractWebResource) Produces(javax.ws.rs.Produces) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) IntentState(org.onosproject.net.intent.IntentState) Path(javax.ws.rs.Path) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) MediaType(javax.ws.rs.core.MediaType) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) Consumes(javax.ws.rs.Consumes) ApplicationId(org.onosproject.core.ApplicationId) JsonNode(com.fasterxml.jackson.databind.JsonNode) UriBuilder(javax.ws.rs.core.UriBuilder) Tools.nullIsIllegal(org.onlab.util.Tools.nullIsIllegal) DELETE(javax.ws.rs.DELETE) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Context(javax.ws.rs.core.Context) Tools.nullIsNotFound(org.onlab.util.Tools.nullIsNotFound) Device(org.onosproject.net.Device) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Key(org.onosproject.net.intent.Key) List(java.util.List) Response(javax.ws.rs.core.Response) LinkService(org.onosproject.net.link.LinkService) UriInfo(javax.ws.rs.core.UriInfo) DeviceId(org.onosproject.net.DeviceId) Tools.readTreeFromStream(org.onlab.util.Tools.readTreeFromStream) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) AnnotationKeys(org.onosproject.net.AnnotationKeys) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) OchSignalCodec(org.onosproject.net.optical.json.OchSignalCodec) ArrayList(java.util.ArrayList) IntentService(org.onosproject.net.intent.IntentService) DefaultPath(org.onosproject.net.DefaultPath) Intent(org.onosproject.net.intent.Intent) Criterion(org.onosproject.net.flow.criteria.Criterion) OpticalIntentUtility.createExplicitOpticalIntent(org.onosproject.net.optical.util.OpticalIntentUtility.createExplicitOpticalIntent) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) Iterator(java.util.Iterator) ProviderId(org.onosproject.net.provider.ProviderId) IOException(java.io.IOException) OchSignal(org.onosproject.net.OchSignal) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ScalarWeight(org.onlab.graph.ScalarWeight) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) InputStream(java.io.InputStream) IntentService(org.onosproject.net.intent.IntentService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) OchSignal(org.onosproject.net.OchSignal) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Intent(org.onosproject.net.intent.Intent) OpticalIntentUtility.createExplicitOpticalIntent(org.onosproject.net.optical.util.OpticalIntentUtility.createExplicitOpticalIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) ScalarWeight(org.onlab.graph.ScalarWeight) Iterator(java.util.Iterator) DefaultPath(org.onosproject.net.DefaultPath) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Link(org.onosproject.net.Link) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with ScalarWeight

use of org.onlab.graph.ScalarWeight 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 3 with ScalarWeight

use of org.onlab.graph.ScalarWeight 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 4 with ScalarWeight

use of org.onlab.graph.ScalarWeight in project onos by opennetworkinglab.

the class PointToPointIntentCompiler method compile.

@Override
public List<Intent> compile(PointToPointIntent intent, List<Intent> installable) {
    log.trace("compiling {} {}", intent, installable);
    ConnectPoint ingressPoint = intent.filteredIngressPoint().connectPoint();
    ConnectPoint egressPoint = intent.filteredEgressPoint().connectPoint();
    // Idea: use suggested path as primary and another path from path service as protection
    if (intent.suggestedPath() != null && intent.suggestedPath().size() > 0) {
        Path path = new DefaultPath(PID, intent.suggestedPath(), new ScalarWeight(1));
        // Check intent constraints against suggested path and suggested path availability
        if (checkPath(path, intent.constraints()) && pathAvailable(intent)) {
            allocateIntentBandwidth(intent, path);
            return asList(createLinkCollectionIntent(ImmutableSet.copyOf(intent.suggestedPath()), DEFAULT_COST, intent));
        }
    }
    if (ingressPoint.deviceId().equals(egressPoint.deviceId())) {
        return createZeroHopLinkCollectionIntent(intent);
    }
    // proceed with no protected paths
    if (!ProtectionConstraint.requireProtectedPath(intent)) {
        return createUnprotectedLinkCollectionIntent(intent);
    }
    try {
        // attempt to compute and implement backup path
        return createProtectedIntent(ingressPoint, egressPoint, intent, installable);
    } catch (PathNotFoundException e) {
        log.warn("Could not find disjoint Path for {}", intent);
        // no disjoint path extant -- maximum one path exists between devices
        return createSinglePathIntent(ingressPoint, egressPoint, intent, installable);
    }
}
Also used : Path(org.onosproject.net.Path) DefaultPath(org.onosproject.net.DefaultPath) DisjointPath(org.onosproject.net.DisjointPath) DefaultPath(org.onosproject.net.DefaultPath) PathNotFoundException(org.onosproject.net.intent.impl.PathNotFoundException) ConnectPoint(org.onosproject.net.ConnectPoint) ScalarWeight(org.onlab.graph.ScalarWeight)

Aggregations

ScalarWeight (org.onlab.graph.ScalarWeight)4 DefaultPath (org.onosproject.net.DefaultPath)4 ConnectPoint (org.onosproject.net.ConnectPoint)3 Link (org.onosproject.net.Link)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ArrayList (java.util.ArrayList)2 ApplicationId (org.onosproject.core.ApplicationId)2 CoreService (org.onosproject.core.CoreService)2 OchSignal (org.onosproject.net.OchSignal)2 Path (org.onosproject.net.Path)2 DeviceService (org.onosproject.net.device.DeviceService)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Duration (java.time.Duration)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Consumes (javax.ws.rs.Consumes)1