Search in sources :

Example 11 with EncapsulationConstraint

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

the class LinkCollectionIntentCompiler method compile.

@Override
public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable) {
    SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create();
    SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();
    Map<ConnectPoint, Identifier<?>> labels = ImmutableMap.of();
    Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent);
    computePorts(intent, inputPorts, outputPorts);
    if (encapConstraint.isPresent()) {
        labels = labelAllocator.assignLabelToPorts(intent.links(), intent.key(), encapConstraint.get().encapType(), encapConstraint.get().suggestedIdentifier());
    }
    ImmutableList.Builder<Intent> intentList = ImmutableList.builder();
    if (this.isDomainProcessingEnabled(intent)) {
        intentList.addAll(this.getDomainIntents(intent, domainService));
    }
    List<FlowRule> rules = new ArrayList<>();
    for (DeviceId deviceId : outputPorts.keySet()) {
        // add only flows that are not inside of a domain
        if (LOCAL.equals(domainService.getDomain(deviceId))) {
            rules.addAll(createRules(intent, deviceId, inputPorts.get(deviceId), outputPorts.get(deviceId), labels));
        }
    }
    // if any rules have been created
    if (!rules.isEmpty()) {
        intentList.add(new FlowRuleIntent(appId, intent.key(), rules, intent.resources(), PathIntent.ProtectionType.PRIMARY, null));
    }
    return intentList.build();
}
Also used : EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) DeviceId(org.onosproject.net.DeviceId) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) ConnectPoint(org.onosproject.net.ConnectPoint) Identifier(org.onlab.util.Identifier) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 12 with EncapsulationConstraint

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

the class LinkCollectionIntentCompiler method createRules.

@Override
protected List<FlowRule> createRules(LinkCollectionIntent intent, DeviceId deviceId, Set<PortNumber> inPorts, Set<PortNumber> outPorts, Map<ConnectPoint, Identifier<?>> labels) {
    List<FlowRule> rules = new ArrayList<>(inPorts.size());
    /*
         * Looking for the encapsulation constraint
         */
    Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent);
    inPorts.forEach(inport -> {
        ForwardingInstructions instructions = this.createForwardingInstruction(encapConstraint, intent, inport, outPorts, deviceId, labels);
        if (optimizeInstructions) {
            TrafficTreatment compactedTreatment = compactActions(instructions.treatment());
            instructions = new ForwardingInstructions(compactedTreatment, instructions.selector());
        }
        FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(instructions.selector()).withTreatment(instructions.treatment()).withPriority(intent.priority()).fromApp(appId).makePermanent().build();
        rules.add(rule);
    });
    return rules;
}
Also used : EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) ArrayList(java.util.ArrayList) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 13 with EncapsulationConstraint

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

the class LinkCollectionIntentFlowObjectiveCompiler method compile.

@Override
public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable) {
    SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create();
    SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create();
    Map<ConnectPoint, Identifier<?>> labels = ImmutableMap.of();
    Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent);
    computePorts(intent, inputPorts, outputPorts);
    if (encapConstraint.isPresent()) {
        labels = labelAllocator.assignLabelToPorts(intent.links(), intent.key(), encapConstraint.get().encapType(), encapConstraint.get().suggestedIdentifier());
    }
    ImmutableList.Builder<Intent> intentList = ImmutableList.builder();
    if (this.isDomainProcessingEnabled(intent)) {
        intentList.addAll(this.getDomainIntents(intent, domainService));
    }
    List<Objective> objectives = new ArrayList<>();
    List<DeviceId> devices = new ArrayList<>();
    for (DeviceId deviceId : outputPorts.keySet()) {
        // add only objectives that are not inside of a domain
        if (LOCAL.equals(domainService.getDomain(deviceId))) {
            List<Objective> deviceObjectives = createRules(intent, deviceId, inputPorts.get(deviceId), outputPorts.get(deviceId), labels);
            deviceObjectives.forEach(objective -> {
                objectives.add(objective);
                devices.add(deviceId);
            });
        }
    }
    // if any objectives have been created
    if (!objectives.isEmpty()) {
        intentList.add(new FlowObjectiveIntent(appId, intent.key(), devices, objectives, intent.resources(), intent.resourceGroup()));
    }
    return intentList.build();
}
Also used : EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) DeviceId(org.onosproject.net.DeviceId) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) Intent(org.onosproject.net.intent.Intent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Objective(org.onosproject.net.flowobjective.Objective) Identifier(org.onlab.util.Identifier) PortNumber(org.onosproject.net.PortNumber)

Example 14 with EncapsulationConstraint

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

the class LinkCollectionIntentFlowObjectiveCompiler method createRules.

@Override
protected List<Objective> createRules(LinkCollectionIntent intent, DeviceId deviceId, Set<PortNumber> inPorts, Set<PortNumber> outPorts, Map<ConnectPoint, Identifier<?>> labels) {
    List<Objective> objectives = new ArrayList<>(inPorts.size() * 2);
    /*
         * Looking for the encapsulation constraint
         */
    Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent);
    inPorts.forEach(inPort -> {
        ForwardingInstructions instructions = this.createForwardingInstruction(encapConstraint, intent, inPort, outPorts, deviceId, labels);
        Set<TrafficTreatment> treatmentsWithDifferentPort = Sets.newHashSet();
        TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
        for (Instruction inst : instructions.treatment().allInstructions()) {
            if (inst.type() == OUTPUT) {
                treatmentBuilder.add(inst);
                treatmentsWithDifferentPort.add(treatmentBuilder.build());
                treatmentBuilder = DefaultTrafficTreatment.builder();
            } else {
                treatmentBuilder.add(inst);
            }
        }
        EthCriterion ethDst = (EthCriterion) intent.selector().getCriterion(Criterion.Type.ETH_DST);
        boolean broadcastObjective = ethDst != null && (ethDst.mac().isBroadcast() || ethDst.mac().isMulticast());
        FilteringObjective filteringObjective = buildFilteringObjective(intent, instructions.selector(), deviceId, inPort);
        if (filteringObjective != null) {
            objectives.add(filteringObjective);
        }
        if (treatmentsWithDifferentPort.size() < 2 && !broadcastObjective) {
            objectives.addAll(createSimpleNextObjective(instructions, intent));
        } else {
            objectives.addAll(createBroadcastObjective(instructions, treatmentsWithDifferentPort, intent));
        }
    });
    return objectives;
}
Also used : EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) ArrayList(java.util.ArrayList) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instruction(org.onosproject.net.flow.instructions.Instruction) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Objective(org.onosproject.net.flowobjective.Objective) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective)

Example 15 with EncapsulationConstraint

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

the class LinkCollectionIntentFlowObjectiveCompilerTest method testFilteredConnectPointForSpWithEncap.

/**
 * Single point to multi point case. Scenario is the follow:
 *
 * -1 of1 2-1 of2 2--1 of3 2-
 *             3
 *             `-1 of4 2-
 *
 * We test the proper compilation constraint of sp2mp
 * with encapsulation, trivial selector, empty treatment and points.
 */
@Test
public void testFilteredConnectPointForSpWithEncap() throws Exception {
    LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
    Set<Link> testLinks = ImmutableSet.of(DefaultLink.builder().providerId(PID).src(of1p2).dst(of2p1).type(DIRECT).build(), DefaultLink.builder().providerId(PID).src(of2p2).dst(of3p1).type(DIRECT).build(), DefaultLink.builder().providerId(PID).src(of2p3).dst(of4p1).type(DIRECT).build());
    Set<FilteredConnectPoint> ingress = ImmutableSet.of(new FilteredConnectPoint(of1p1, vlan100Selector));
    Set<FilteredConnectPoint> egress = ImmutableSet.of(new FilteredConnectPoint(of3p2, vlan100Selector), new FilteredConnectPoint(of4p2, vlan100Selector));
    TrafficSelector broadcastSelector = DefaultTrafficSelector.builder().matchEthDst(MacAddress.BROADCAST).build();
    EncapsulationConstraint constraint = new EncapsulationConstraint(EncapsulationType.VLAN);
    LinkCollectionIntent intent = LinkCollectionIntent.builder().appId(appId).selector(broadcastSelector).treatment(treatment).links(testLinks).filteredIngressPoints(ingress).filteredEgressPoints(egress).applyTreatmentOnEgress(true).resourceGroup(resourceGroup1).constraints(ImmutableList.of(constraint)).build();
    List<Intent> result = compiler.compile(intent, Collections.emptyList());
    assertThat(result, hasSize(1));
    assertThat(result.get(0), instanceOf(FlowObjectiveIntent.class));
    FlowObjectiveIntent foIntent = (FlowObjectiveIntent) result.get(0);
    List<Objective> objectives = foIntent.objectives();
    assertThat(objectives, hasSize(12));
    /*
         * First set of objective
         */
    filteringObjective = (FilteringObjective) objectives.get(0);
    forwardingObjective = (ForwardingObjective) objectives.get(1);
    nextObjective = (NextObjective) objectives.get(2);
    // expect selector and treatment
    TrafficSelector expectSelector = DefaultTrafficSelector.builder().matchInPort(PortNumber.portNumber(1)).matchVlanId(VLAN_100).matchEthDst(MacAddress.BROADCAST).build();
    List<TrafficTreatment> expectTreatments = ImmutableList.of(DefaultTrafficTreatment.builder().setVlanId(VLAN_1).setOutput(PortNumber.portNumber(2)).build());
    TrafficSelector filteringSelector = vlan100Selector;
    PortCriterion inPortCriterion = (PortCriterion) expectSelector.getCriterion(Criterion.Type.IN_PORT);
    // test case for first filtering objective
    checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, filteringSelector.criteria());
    // test case for first next objective
    checkNext(nextObjective, BROADCAST, expectTreatments, expectSelector, ADD);
    // test case for first forwarding objective
    checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
    /*
         * Second set of objective
         */
    filteringObjective = (FilteringObjective) objectives.get(3);
    forwardingObjective = (ForwardingObjective) objectives.get(4);
    nextObjective = (NextObjective) objectives.get(5);
    expectSelector = DefaultTrafficSelector.builder().matchInPort(PortNumber.portNumber(1)).matchVlanId(VLAN_1).build();
    expectTreatments = ImmutableList.of(DefaultTrafficTreatment.builder().setVlanId(VLAN_100).setOutput(PortNumber.portNumber(2)).build());
    filteringSelector = vlan1Selector;
    inPortCriterion = (PortCriterion) expectSelector.getCriterion(Criterion.Type.IN_PORT);
    // test case for first filtering objective
    checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, filteringSelector.criteria());
    // test case for second next objective
    checkNext(nextObjective, BROADCAST, expectTreatments, expectSelector, ADD);
    // test case for second forwarding objective
    checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
    /*
         * 3rd set of objective
         */
    filteringObjective = (FilteringObjective) objectives.get(6);
    forwardingObjective = (ForwardingObjective) objectives.get(7);
    nextObjective = (NextObjective) objectives.get(8);
    inPortCriterion = (PortCriterion) expectSelector.getCriterion(Criterion.Type.IN_PORT);
    // test case for first filtering objective
    checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, filteringSelector.criteria());
    // test case for 3rd next objective
    checkNext(nextObjective, BROADCAST, expectTreatments, expectSelector, ADD);
    // test case for 3rd forwarding objective
    checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
    /*
         * 4th set of objective
         */
    filteringObjective = (FilteringObjective) objectives.get(9);
    forwardingObjective = (ForwardingObjective) objectives.get(10);
    nextObjective = (NextObjective) objectives.get(11);
    inPortCriterion = (PortCriterion) expectSelector.getCriterion(Criterion.Type.IN_PORT);
    // test case for first filtering objective
    checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, filteringSelector.criteria());
    // test case for 3rd next objective
    expectTreatments = ImmutableList.of(DefaultTrafficTreatment.builder().setVlanId(VLAN_1).setOutput(PortNumber.portNumber(2)).build(), DefaultTrafficTreatment.builder().setVlanId(VLAN_1).setOutput(PortNumber.portNumber(3)).build());
    checkNext(nextObjective, BROADCAST, expectTreatments, expectSelector, ADD);
    // test case for 3rd forwarding objective
    checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
}
Also used : EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) Intent(org.onosproject.net.intent.Intent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Objective(org.onosproject.net.flowobjective.Objective) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Test(org.junit.Test)

Aggregations

EncapsulationConstraint (org.onosproject.net.intent.constraint.EncapsulationConstraint)24 ConnectPoint (org.onosproject.net.ConnectPoint)16 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)16 TrafficSelector (org.onosproject.net.flow.TrafficSelector)16 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)16 ImmutableList (com.google.common.collect.ImmutableList)15 EncapsulationType (org.onosproject.net.EncapsulationType)15 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)15 Intent (org.onosproject.net.intent.Intent)15 List (java.util.List)14 Set (java.util.Set)14 VlanId (org.onlab.packet.VlanId)13 ApplicationId (org.onosproject.core.ApplicationId)13 CoreService (org.onosproject.core.CoreService)13 ArrayList (java.util.ArrayList)12 DeviceId (org.onosproject.net.DeviceId)12 Test (org.junit.Test)11 Ethernet (org.onlab.packet.Ethernet)11 Collectors (java.util.stream.Collectors)9 Collection (java.util.Collection)8