Search in sources :

Example 1 with FlowRuleIntent

use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.

the class OpticalOduIntentCompiler method compile.

@Override
public List<Intent> compile(OpticalOduIntent intent, List<Intent> installable) {
    // Check if ports are OduClt ports
    ConnectPoint src = intent.getSrc();
    ConnectPoint dst = intent.getDst();
    Port srcPort = deviceService.getPort(src.deviceId(), src.port());
    Port dstPort = deviceService.getPort(dst.deviceId(), dst.port());
    checkArgument(srcPort instanceof OduCltPort);
    checkArgument(dstPort instanceof OduCltPort);
    log.debug("Compiling optical ODU intent between {} and {}", src, dst);
    // Release of intent resources here is only a temporary solution for handling the
    // case of recompiling due to intent restoration (when intent state is FAILED).
    // TODO: try to release intent resources in IntentManager.
    resourceService.release(intent.key());
    // Check OduClt ports availability
    Resource srcPortResource = Resources.discrete(src.deviceId(), src.port()).resource();
    Resource dstPortResource = Resources.discrete(dst.deviceId(), dst.port()).resource();
    // If ports are not available, compilation fails
    if (!Stream.of(srcPortResource, dstPortResource).allMatch(resourceService::isAvailable)) {
        throw new OpticalIntentCompilationException("Ports for the intent are not available. Intent: " + intent);
    }
    List<Resource> intentResources = new ArrayList<>();
    intentResources.add(srcPortResource);
    intentResources.add(dstPortResource);
    // Calculate available light paths
    Set<Path> paths = getOpticalPaths(intent);
    if (paths.isEmpty()) {
        throw new OpticalIntentCompilationException("Unable to find suitable lightpath for intent " + intent);
    }
    // Use first path that can be successfully reserved
    for (Path path : paths) {
        // Find available Tributary Slots on both directions of path
        Map<LinkKey, Set<TributarySlot>> slotsMap = findAvailableTributarySlots(intent, path);
        if (slotsMap.isEmpty()) {
            continue;
        }
        List<Resource> tributarySlotResources = convertToResources(slotsMap);
        if (!tributarySlotResources.stream().allMatch(resourceService::isAvailable)) {
            continue;
        }
        intentResources.addAll(tributarySlotResources);
        allocateResources(intent, intentResources);
        List<FlowRule> rules = new LinkedList<>();
        // Create rules for forward and reverse path
        rules = createRules(intent, intent.getSrc(), intent.getDst(), path, slotsMap, false);
        if (intent.isBidirectional()) {
            rules.addAll(createRules(intent, intent.getDst(), intent.getSrc(), path, slotsMap, true));
        }
        return Collections.singletonList(new FlowRuleIntent(appId, intent.key(), rules, ImmutableSet.copyOf(path.links()), PathIntent.ProtectionType.PRIMARY, intent.resourceGroup()));
    }
    throw new OpticalIntentCompilationException("Unable to find suitable lightpath for intent " + intent);
}
Also used : Path(org.onosproject.net.Path) LinkKey(org.onosproject.net.LinkKey) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Port(org.onosproject.net.Port) OduCltPort(org.onosproject.net.optical.OduCltPort) OtuPort(org.onosproject.net.optical.OtuPort) OduCltPort(org.onosproject.net.optical.OduCltPort) Resource(org.onosproject.net.resource.Resource) ArrayList(java.util.ArrayList) ConnectPoint(org.onosproject.net.ConnectPoint) LinkedList(java.util.LinkedList) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 2 with FlowRuleIntent

use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.

the class OpticalCircuitIntentCompiler method compile.

private List<Intent> compile(OpticalCircuitIntent intent, ConnectPoint src, ConnectPoint dst, Optional<OpticalConnectivityIntent> existingConnectivity, List<Resource> resources, boolean supportsMultiplexing) {
    OpticalConnectivityIntent connectivityIntent;
    List<Resource> required;
    if (existingConnectivity.isPresent()) {
        connectivityIntent = existingConnectivity.get();
        required = resources;
    } else {
        // Find OCh ports with available resources
        Pair<OchPort, OchPort> ochPorts = findPorts(intent.getSrc(), intent.getDst(), intent.getSignalType());
        if (ochPorts == null) {
            throw new OpticalIntentCompilationException("Unable to find suitable OCH ports for intent " + intent);
        }
        ConnectPoint srcCP = new ConnectPoint(src.elementId(), ochPorts.getLeft().number());
        ConnectPoint dstCP = new ConnectPoint(dst.elementId(), ochPorts.getRight().number());
        // Create optical connectivity intent
        // In this case the channel and path optionally specified in this circuit intent
        // are used to create the connectivity intent
        connectivityIntent = OpticalConnectivityIntent.builder().appId(appId).src(srcCP).dst(dstCP).priority(OPTICAL_CONNECTIVITY_INTENT_PRIORITY).signalType(ochPorts.getLeft().signalType()).bidirectional(intent.isBidirectional()).ochSignal(intent.ochSignal()).suggestedPath(intent.suggestedPath()).resourceGroup(intent.resourceGroup()).build();
        if (!supportsMultiplexing) {
            required = resources;
        } else {
            List<Resource> slots = availableSlotResources(srcCP, dstCP, intent.getSignalType());
            if (slots.isEmpty()) {
                throw new OpticalIntentCompilationException("Unable to find Tributary Slots for intent " + intent);
            }
            required = ImmutableList.<Resource>builder().addAll(resources).addAll(slots).build();
        }
    }
    if (resourceService.allocate(intent.key(), required).isEmpty()) {
        throw new OpticalIntentCompilationException("Unable to allocate resources for intent " + intent + ": resources=" + required);
    }
    intentService.submit(connectivityIntent);
    // Save circuit to connectivity intent mapping
    intentSetMultimap.allocateMapping(connectivityIntent.id(), intent.id());
    FlowRuleIntent circuitIntent = createFlowRule(intent, connectivityIntent, required.stream().flatMap(x -> Tools.stream(x.valueAs(TributarySlot.class))).collect(Collectors.toSet()));
    return ImmutableList.of(circuitIntent);
}
Also used : Resource(org.onosproject.net.resource.Resource) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) ConnectPoint(org.onosproject.net.ConnectPoint) OchPort(org.onosproject.net.optical.OchPort) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 3 with FlowRuleIntent

use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.

the class OpticalPathIntentCompiler method compile.

@Override
public List<Intent> compile(OpticalPathIntent intent, List<Intent> installable) {
    log.debug("Compiling optical path intent between {} and {}", intent.src(), intent.dst());
    // Create rules for forward and reverse path
    List<FlowRule> rules = createRules(intent);
    if (intent.isBidirectional()) {
        rules.addAll(createReverseRules(intent));
    }
    return Collections.singletonList(new FlowRuleIntent(appId, intent.key(), rules, intent.resources(), PathIntent.ProtectionType.PRIMARY, intent.resourceGroup()));
}
Also used : DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 4 with FlowRuleIntent

use of org.onosproject.net.intent.FlowRuleIntent 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 5 with FlowRuleIntent

use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.

the class OpticalCircuitIntentCompilerTest method test10GbeMultiplexOverOdu2.

/**
 * Tests compile of OpticalCircuitIntent with allocation of TributarySlots.
 * Compile two ODUCLT ports (with CLT_10GBE), over OCH ports (with ODU2):
 *   - All TributarySlots are used
 */
@Test
public void test10GbeMultiplexOverOdu2() {
    // Use driver with TributarySlotQuery Behaviour
    sut.driverService = new MockDriverServiceWithTs();
    ConnectPoint oduCltSrcCP = new ConnectPoint(device1.id(), D1P3.number());
    ConnectPoint oduCltDstCP = new ConnectPoint(device2.id(), D2P3.number());
    ConnectPoint ochSrcCP = new ConnectPoint(device1.id(), D1P2.number());
    ConnectPoint ochDstCP = new ConnectPoint(device2.id(), D2P2.number());
    intent = OpticalCircuitIntent.builder().appId(APP_ID).key(KEY1).src(oduCltSrcCP).dst(oduCltDstCP).signalType(D1P3.signalType()).bidirectional(false).build();
    sut.activate(null);
    List<Intent> compiled = sut.compile(intent, Collections.emptyList());
    assertThat(compiled, hasSize(1));
    assertThat("key is inherited", compiled.stream().map(Intent::key).collect(Collectors.toList()), everyItem(is(intent.key())));
    Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
    FlowRule rule1 = rules.stream().filter(x -> x.deviceId().equals(device1.id())).findFirst().get();
    // validate SRC selector
    TrafficSelector.Builder selectorBuilder1 = DefaultTrafficSelector.builder();
    selectorBuilder1.matchInPort(oduCltSrcCP.port());
    selectorBuilder1.add(Criteria.matchOduSignalType(OduSignalType.ODU2));
    assertThat(rule1.selector(), is(selectorBuilder1.build()));
    // validate SRC treatment (without OduSignalId, i.e. All TributarySlots are used)
    TrafficTreatment.Builder treatmentBuilder1 = DefaultTrafficTreatment.builder();
    treatmentBuilder1.setOutput(ochSrcCP.port());
    assertThat(rule1.treatment(), is(treatmentBuilder1.build()));
    FlowRule rule2 = rules.stream().filter(x -> x.deviceId().equals(device2.id())).findFirst().get();
    // validate DST selector (without OduSignalId, i.e. All TributarySlots are used)
    TrafficSelector.Builder selectorBuilder2 = DefaultTrafficSelector.builder();
    selectorBuilder2.matchInPort(ochDstCP.port());
    selectorBuilder2.add(Criteria.matchOduSignalType(OduSignalType.ODU2));
    assertThat(rule2.selector(), is(selectorBuilder2.build()));
    // validate DST treatment
    assertThat(rule2.treatment(), is(DefaultTrafficTreatment.builder().setOutput(oduCltDstCP.port()).build()));
    rules.forEach(rule -> assertEquals("FlowRule priority is incorrect", intent.priority(), rule.priority()));
    sut.deactivate();
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Intent(org.onosproject.net.intent.Intent) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Aggregations

FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)111 Intent (org.onosproject.net.intent.Intent)103 FlowRule (org.onosproject.net.flow.FlowRule)91 Test (org.junit.Test)89 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)67 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)67 List (java.util.List)58 DeviceId (org.onosproject.net.DeviceId)58 Collection (java.util.Collection)57 Collectors (java.util.stream.Collectors)55 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)55 VlanId (org.onlab.packet.VlanId)54 Before (org.junit.Before)52 Collections (java.util.Collections)51 CoreService (org.onosproject.core.CoreService)50 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)50 EasyMock (org.easymock.EasyMock)49 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)49 ComponentConfigAdapter (org.onosproject.cfg.ComponentConfigAdapter)49 IntentExtensionService (org.onosproject.net.intent.IntentExtensionService)49