Search in sources :

Example 1 with DefaultPath

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

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

the class OpticalPathIntentCompilerTest method setUp.

@Before
public void setUp() {
    sut = new OpticalPathIntentCompiler();
    coreService = createMock(CoreService.class);
    expect(coreService.registerApplication("org.onosproject.net.intent")).andReturn(appId);
    sut.coreService = coreService;
    super.setUp();
    intent = OpticalPathIntent.builder().appId(appId).src(d1p1).dst(d3p1).path(new DefaultPath(PID, links, ScalarWeight.toWeight(hops))).lambda(createLambda()).signalType(OchSignalType.FIXED_GRID).build();
    intentExtensionService = createMock(IntentExtensionService.class);
    intentExtensionService.registerCompiler(OpticalPathIntent.class, sut);
    intentExtensionService.unregisterCompiler(OpticalPathIntent.class);
    sut.intentManager = intentExtensionService;
    replay(coreService, intentExtensionService);
}
Also used : IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) CoreService(org.onosproject.core.CoreService) DefaultPath(org.onosproject.net.DefaultPath) Before(org.junit.Before)

Example 3 with DefaultPath

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

the class LatencyConstraintTest method setUp.

@Before
public void setUp() {
    resourceContext = createMock(ResourceContext.class);
    Annotations annotations1 = DefaultAnnotations.builder().set(LATENCY, LATENCY1).build();
    Annotations annotations2 = DefaultAnnotations.builder().set(LATENCY, LATENCY2).build();
    link1 = DefaultLink.builder().providerId(PROVIDER_ID).src(cp(DID1, PN1)).dst(cp(DID2, PN2)).type(DIRECT).annotations(annotations1).build();
    link2 = DefaultLink.builder().providerId(PROVIDER_ID).src(cp(DID2, PN3)).dst(cp(DID3, PN4)).type(DIRECT).annotations(annotations2).build();
    path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), ScalarWeight.toWeight(10));
}
Also used : ResourceContext(org.onosproject.net.intent.ResourceContext) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) DefaultPath(org.onosproject.net.DefaultPath) Before(org.junit.Before)

Example 4 with DefaultPath

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

the class WaypointConstraintTest method setUp.

@Before
public void setUp() {
    resourceContext = createMock(ResourceContext.class);
    link1 = DefaultLink.builder().providerId(PROVIDER_ID).src(cp(DID1, PN1)).dst(cp(DID2, PN2)).type(DIRECT).build();
    link2 = DefaultLink.builder().providerId(PROVIDER_ID).src(cp(DID2, PN3)).dst(cp(DID3, PN4)).type(DIRECT).build();
    path = new DefaultPath(PROVIDER_ID, Arrays.asList(link1, link2), ScalarWeight.toWeight(10));
}
Also used : ResourceContext(org.onosproject.net.intent.ResourceContext) DefaultPath(org.onosproject.net.DefaultPath) Before(org.junit.Before)

Example 5 with DefaultPath

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

the class PointToPointIntentCompiler method createSinglePathIntent.

private List<Intent> createSinglePathIntent(ConnectPoint ingressPoint, ConnectPoint egressPoint, PointToPointIntent intent, List<Intent> installable) {
    List<Link> links = new ArrayList<>();
    Path onlyPath = getPathOrException(intent, ingressPoint.deviceId(), egressPoint.deviceId());
    List<Intent> reusableIntents = null;
    if (installable != null) {
        reusableIntents = filterInvalidSubIntents(installable, intent);
        if (reusableIntents.size() == installable.size()) {
            // all old paths are still viable
            return installable;
        }
    }
    // return the intents that comprise it.
    if (reusableIntents != null && reusableIntents.size() > 1) {
        return reusableIntents;
    } else {
        // Allocate bandwidth if a bandwidth constraint is set
        allocateIntentBandwidth(intent, onlyPath);
        links.add(createEdgeLink(ingressPoint, true));
        links.addAll(onlyPath.links());
        links.add(createEdgeLink(egressPoint, false));
        return asList(createPathIntent(new DefaultPath(PID, links, onlyPath.weight(), onlyPath.annotations()), intent, PathIntent.ProtectionType.PRIMARY));
    }
}
Also used : Path(org.onosproject.net.Path) DefaultPath(org.onosproject.net.DefaultPath) DisjointPath(org.onosproject.net.DisjointPath) ArrayList(java.util.ArrayList) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) DefaultPath(org.onosproject.net.DefaultPath) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) Link(org.onosproject.net.Link) EdgeLink(org.onosproject.net.EdgeLink)

Aggregations

DefaultPath (org.onosproject.net.DefaultPath)18 Link (org.onosproject.net.Link)9 Before (org.junit.Before)7 ArrayList (java.util.ArrayList)6 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 Path (org.onosproject.net.Path)4 Test (org.junit.Test)3 Annotations (org.onosproject.net.Annotations)3 ConnectPoint (org.onosproject.net.ConnectPoint)3 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)3 DefaultLink (org.onosproject.net.DefaultLink)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 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2