Search in sources :

Example 51 with Link

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

the class OpticalPathProvisioner method activate.

@Activate
protected void activate(ComponentContext context) {
    deviceService = opticalView(deviceService);
    appId = coreService.registerApplication("org.onosproject.newoptical");
    idCounter = storageService.getAtomicCounter(OPTICAL_CONNECTIVITY_ID_COUNTER);
    linkPathMap = storageService.<PacketLinkRealizedByOptical, OpticalConnectivity>consistentMapBuilder().withSerializer(Serializer.using(LINKPATH_SERIALIZER.build())).withName(LINKPATH_MAP_NAME).withApplicationId(appId).build();
    connectivityMap = storageService.<OpticalConnectivityId, OpticalConnectivity>consistentMapBuilder().withSerializer(Serializer.using(CONNECTIVITY_SERIALIZER.build())).withName(CONNECTIVITY_MAP_NAME).withApplicationId(appId).build();
    usedCrossConnectLinkSet = storageService.<Link>setBuilder().withSerializer(Serializer.using(CROSSCONNECTLINKS_SERIALIZER.build())).withName(CROSSCONNECTLINK_SET_NAME).withApplicationId(appId).build().asDistributedSet();
    eventDispatcher.addSink(OpticalPathEvent.class, listenerRegistry);
    listeners = new ListenerTracker();
    listeners.addListener(linkService, new InternalLinkListener()).addListener(intentService, new InternalIntentListener());
    linkPathMap.addListener(storeListener);
    readComponentConfiguration(context);
    log.info("Started");
}
Also used : ListenerTracker(org.onosproject.event.ListenerTracker) Link(org.onosproject.net.Link) Activate(org.osgi.service.component.annotations.Activate)

Example 52 with Link

use of org.onosproject.net.Link 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 53 with Link

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

the class OpticalOduIntentCompiler method createRules.

/**
 * Create rules for the forward (or the reverse) path of the intent.
 *
 * @param intent OpticalOduIntent intent
 * @param path path found for intent
 * @param slotsMap Map of LinkKey and TributarySlots resources
 * @return list of flow rules
 */
private List<FlowRule> createRules(OpticalOduIntent intent, ConnectPoint src, ConnectPoint dst, Path path, Map<LinkKey, Set<TributarySlot>> slotsMap, boolean reverse) {
    // Build the ingress OTN rule
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    selector.matchInPort(src.port());
    OduSignalType oduCltPortOduSignalType = OduSignalUtils.mappingCltSignalTypeToOduSignalType(intent.getSignalType());
    selector.add(Criteria.matchOduSignalType(oduCltPortOduSignalType));
    List<FlowRule> rules = new LinkedList<>();
    ConnectPoint current = src;
    List<Link> links = ((!reverse) ? path.links() : Lists.reverse(path.links()));
    for (Link link : links) {
        Set<TributarySlot> slots = slotsMap.get(linkKey(link));
        OtuPort otuPort = (OtuPort) (deviceService.getPort(link.src().deviceId(), link.src().port()));
        OduSignalType otuPortOduSignalType = OduSignalUtils.mappingOtuSignalTypeToOduSignalType(otuPort.signalType());
        TrafficTreatment.Builder treat = DefaultTrafficTreatment.builder();
        OduSignalId oduSignalId = null;
        // use Instruction of OduSignalId only in case of ODU Multiplexing
        if (oduCltPortOduSignalType != otuPortOduSignalType) {
            oduSignalId = OduSignalUtils.buildOduSignalId(otuPortOduSignalType, slots);
            treat.add(Instructions.modL1OduSignalId(oduSignalId));
        }
        ConnectPoint next = ((!reverse) ? link.src() : link.dst());
        treat.setOutput(next.port());
        FlowRule rule = createFlowRule(intent, current.deviceId(), selector.build(), treat.build());
        rules.add(rule);
        current = ((!reverse) ? link.dst() : link.src());
        selector = DefaultTrafficSelector.builder();
        selector.matchInPort(current.port());
        selector.add(Criteria.matchOduSignalType(oduCltPortOduSignalType));
        // use Criteria of OduSignalId only in case of ODU Multiplexing
        if (oduCltPortOduSignalType != otuPortOduSignalType) {
            selector.add(Criteria.matchOduSignalId(oduSignalId));
        }
    }
    // Build the egress OTN rule
    TrafficTreatment.Builder treatLast = DefaultTrafficTreatment.builder();
    treatLast.setOutput(dst.port());
    FlowRule rule = createFlowRule(intent, dst.deviceId(), selector.build(), treatLast.build());
    rules.add(rule);
    return rules;
}
Also used : OduSignalType(org.onosproject.net.OduSignalType) OtuPort(org.onosproject.net.optical.OtuPort) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) LinkedList(java.util.LinkedList) TributarySlot(org.onosproject.net.TributarySlot) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) OduSignalId(org.onosproject.net.OduSignalId) Link(org.onosproject.net.Link)

Example 54 with Link

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

the class OpticalPathIntentCompiler method createRules.

/**
 * Create rules for the forward path of the intent.
 *
 * @param intent the intent
 * @return list of flow rules
 */
private List<FlowRule> createRules(OpticalPathIntent intent) {
    TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
    selectorBuilder.matchInPort(intent.src().port());
    List<FlowRule> rules = new LinkedList<>();
    /*
         * especial case for 0 hop when srcDeviceId = dstDeviceId
         * and path contain only one fake default path.
         */
    if (intent.src().deviceId().equals(intent.dst().deviceId()) && intent.path().links().size() == 1) {
        log.debug("handling 0 hop case for intent {}", intent);
        TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
        if (!isTransparent(intent.src().deviceId())) {
            treatmentBuilder.add(Instructions.modL0Lambda(intent.lambda()));
        }
        treatmentBuilder.setOutput(intent.dst().port());
        FlowRule rule = DefaultFlowRule.builder().forDevice(intent.src().deviceId()).withSelector(selectorBuilder.build()).withTreatment(treatmentBuilder.build()).withPriority(intent.priority()).fromApp(appId).makePermanent().build();
        rules.add(rule);
        return rules;
    }
    ConnectPoint current = intent.src();
    for (Link link : intent.path().links()) {
        TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
        if (!isTransparent(current.deviceId())) {
            treatmentBuilder.add(Instructions.modL0Lambda(intent.lambda()));
        }
        treatmentBuilder.setOutput(link.src().port());
        FlowRule rule = DefaultFlowRule.builder().forDevice(current.deviceId()).withSelector(selectorBuilder.build()).withTreatment(treatmentBuilder.build()).withPriority(intent.priority()).fromApp(appId).makePermanent().build();
        selectorBuilder = DefaultTrafficSelector.builder();
        if (!isNoFlowRule(current.deviceId())) {
            rules.add(rule);
        }
        current = link.dst();
        selectorBuilder.matchInPort(link.dst().port());
        if (!isTransparent(current.deviceId())) {
            selectorBuilder.add(Criteria.matchLambda(intent.lambda()));
            selectorBuilder.add(Criteria.matchOchSignalType(intent.signalType()));
        }
    }
    // Build the egress ROADM rule
    TrafficTreatment.Builder treatmentLast = DefaultTrafficTreatment.builder();
    treatmentLast.setOutput(intent.dst().port());
    FlowRule rule = new DefaultFlowRule.Builder().forDevice(intent.dst().deviceId()).withSelector(selectorBuilder.build()).withTreatment(treatmentLast.build()).withPriority(intent.priority()).fromApp(appId).makePermanent().build();
    if (!isNoFlowRule(intent.dst().deviceId())) {
        rules.add(rule);
    }
    return rules;
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) LinkedList(java.util.LinkedList) Link(org.onosproject.net.Link)

Example 55 with Link

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

the class LinkCollectionIntentCompilerTest method testFilteredConnectPointForMp.

/**
 * Multi point to single point intent with filtered connect point.
 * Scenario is the follow:
 *
 * -1 of1 2-1 of2 2-1 of4 2-
 *             3
 * -1 of3 2---/
 *
 * We test the proper compilation of mp2sp intents with trivial selector,
 * trivial treatment and different filtered point.
 */
@Test
public void testFilteredConnectPointForMp() {
    sut.activate();
    Set<Link> testlinks = ImmutableSet.of(DefaultLink.builder().providerId(PID).src(of1p2).dst(of2p1).type(DIRECT).build(), DefaultLink.builder().providerId(PID).src(of3p2).dst(of2p3).type(DIRECT).build(), DefaultLink.builder().providerId(PID).src(of2p2).dst(of4p1).type(DIRECT).build());
    Set<FilteredConnectPoint> ingress = ImmutableSet.of(new FilteredConnectPoint(of1p1, vlan100Selector), new FilteredConnectPoint(of3p1, vlan100Selector));
    Set<FilteredConnectPoint> egress = ImmutableSet.of(new FilteredConnectPoint(of4p2, vlan200Selector));
    TrafficSelector expectOf1Selector = DefaultTrafficSelector.builder(vlan100Selector).matchInPort(PortNumber.portNumber(1)).build();
    TrafficTreatment expectOf1Treatment = DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId("200")).setOutput(PortNumber.portNumber(2)).build();
    TrafficSelector expectOf2Selector1 = DefaultTrafficSelector.builder(vlan200Selector).matchInPort(PortNumber.portNumber(1)).build();
    TrafficSelector expectOf2Selector2 = DefaultTrafficSelector.builder(vlan200Selector).matchInPort(PortNumber.portNumber(3)).build();
    TrafficTreatment expectOf2Treatment = DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(2)).build();
    TrafficSelector expectOf3Selector = DefaultTrafficSelector.builder(vlan100Selector).matchInPort(PortNumber.portNumber(1)).build();
    TrafficTreatment expectOf3Treatment = DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId("200")).setOutput(PortNumber.portNumber(2)).build();
    TrafficSelector expectOf4Selector = DefaultTrafficSelector.builder(vlan100Selector).matchInPort(PortNumber.portNumber(1)).matchVlanId(VlanId.vlanId("200")).build();
    TrafficTreatment expectOf4Treatment = DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(2)).build();
    intent = LinkCollectionIntent.builder().appId(APP_ID).filteredIngressPoints(ingress).filteredEgressPoints(egress).treatment(treatment).links(testlinks).build();
    List<Intent> result = sut.compile(intent, Collections.emptyList());
    assertThat(result, is(notNullValue()));
    assertThat(result, hasSize(1));
    Intent resultIntent = result.get(0);
    assertThat(resultIntent, instanceOf(FlowRuleIntent.class));
    if (resultIntent instanceof FlowRuleIntent) {
        FlowRuleIntent frIntent = (FlowRuleIntent) resultIntent;
        assertThat(frIntent.flowRules(), hasSize(5));
        List<FlowRule> deviceFlowRules;
        FlowRule flowRule;
        // Of1
        deviceFlowRules = getFlowRulesByDevice(of1Id, frIntent.flowRules());
        assertThat(deviceFlowRules, hasSize(1));
        flowRule = deviceFlowRules.get(0);
        assertThat(flowRule.selector(), is(expectOf1Selector));
        assertThat(flowRule.treatment(), is(expectOf1Treatment));
        // Of2 (has 2 flows)
        deviceFlowRules = getFlowRulesByDevice(of2Id, frIntent.flowRules());
        assertThat(deviceFlowRules, hasSize(2));
        flowRule = deviceFlowRules.get(0);
        assertThat(flowRule.selector(), is(expectOf2Selector1));
        assertThat(flowRule.treatment(), is(expectOf2Treatment));
        flowRule = deviceFlowRules.get(1);
        assertThat(flowRule.selector(), is(expectOf2Selector2));
        assertThat(flowRule.treatment(), is(expectOf2Treatment));
        // Of3
        deviceFlowRules = getFlowRulesByDevice(of3Id, frIntent.flowRules());
        assertThat(deviceFlowRules, hasSize(1));
        flowRule = deviceFlowRules.get(0);
        assertThat(flowRule.selector(), is(expectOf3Selector));
        assertThat(flowRule.treatment(), is(expectOf3Treatment));
        // Of4
        deviceFlowRules = getFlowRulesByDevice(of4Id, frIntent.flowRules());
        assertThat(deviceFlowRules, hasSize(1));
        flowRule = deviceFlowRules.get(0);
        assertThat(flowRule.selector(), is(expectOf4Selector));
        assertThat(flowRule.treatment(), is(expectOf4Treatment));
    }
    sut.deactivate();
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Intent(org.onosproject.net.intent.Intent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test)

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