Search in sources :

Example 46 with TrafficTreatment

use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.

the class PortLoadBalancerManager method nextObjBuilder.

private NextObjective.Builder nextObjBuilder(PortLoadBalancerId portLoadBalancerId, Set<PortNumber> ports, Integer nextId) {
    if (nextId == null) {
        nextId = flowObjService.allocateNextId();
    }
    // This metadata is used to pass the key to the driver.
    // Some driver, e.g. OF-DPA, will use that information while creating load balancing group.
    // TODO This is not an actual LAG port. In the future, we should extend metadata structure to carry
    // generic information. We should avoid using in_port in the metadata once generic metadata is available.
    TrafficSelector meta = DefaultTrafficSelector.builder().matchInPort(PortNumber.portNumber(portLoadBalancerId.key())).build();
    NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(nextId).withMeta(meta).withType(NextObjective.Type.HASHED).fromApp(appId);
    ports.forEach(port -> {
        TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(port).build();
        nextObjBuilder.addTreatment(DefaultNextTreatment.of(treatment));
    });
    return nextObjBuilder;
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 47 with TrafficTreatment

use of org.onosproject.net.flow.TrafficTreatment 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)

Example 48 with TrafficTreatment

use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.

the class LinkCollectionIntentFlowObjectiveCompilerTest method singleHopTestForMp.

/**
 * Multiple point to single point intent with only one switch.
 * We test the proper compilation of mp2sp with
 * trivial selector, trivial treatment and 1 hop.
 */
@Test
public void singleHopTestForMp() {
    Set<Link> testLinks = ImmutableSet.of();
    Set<FilteredConnectPoint> ingress = ImmutableSet.of(new FilteredConnectPoint(of1p1, vlan100Selector), new FilteredConnectPoint(of1p2, vlan100Selector));
    Set<FilteredConnectPoint> egress = ImmutableSet.of(new FilteredConnectPoint(of1p3, vlan100Selector));
    LinkCollectionIntent intent = LinkCollectionIntent.builder().appId(appId).selector(ethDstSelector).treatment(treatment).links(testLinks).filteredIngressPoints(ingress).filteredEgressPoints(egress).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(6));
    TrafficSelector expectSelector = DefaultTrafficSelector.builder(ethDstSelector).matchInPort(PortNumber.portNumber(1)).matchVlanId(VLAN_100).build();
    TrafficTreatment expectTreatment = DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(3)).build();
    /*
         * First set of objective
         */
    filteringObjective = (FilteringObjective) objectives.get(0);
    forwardingObjective = (ForwardingObjective) objectives.get(1);
    nextObjective = (NextObjective) objectives.get(2);
    PortCriterion inPortCriterion = (PortCriterion) expectSelector.getCriterion(Criterion.Type.IN_PORT);
    // test case for first filtering objective
    checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, vlan100Selector.criteria());
    // test case for first next objective
    checkNext(nextObjective, SIMPLE, expectTreatment, 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(ethDstSelector).matchInPort(PortNumber.portNumber(2)).matchVlanId(VLAN_100).build();
    inPortCriterion = (PortCriterion) expectSelector.getCriterion(Criterion.Type.IN_PORT);
    // test case for first filtering objective
    checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, vlan100Selector.criteria());
    // test case for first next objective
    checkNext(nextObjective, SIMPLE, expectTreatment, expectSelector, ADD);
    // test case for first forwarding objective
    checkForward(forwardingObjective, ADD, expectSelector, nextObjective.id(), SPECIFIC);
}
Also used : 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)

Example 49 with TrafficTreatment

use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.

the class LinkCollectionIntentFlowObjectiveCompilerTest method singleHopTestForSp.

/**
 * Single point to multiple point intent with only one switch.
 * We test the proper compilation of sp2mp with
 * trivial selector, trivial treatment and 1 hop.
 */
@Test
public void singleHopTestForSp() {
    Set<Link> testLinks = ImmutableSet.of();
    Set<FilteredConnectPoint> ingress = ImmutableSet.of(new FilteredConnectPoint(of1p1, vlan100Selector));
    Set<FilteredConnectPoint> egress = ImmutableSet.of(new FilteredConnectPoint(of1p2, vlan100Selector), new FilteredConnectPoint(of1p3, vlan100Selector));
    LinkCollectionIntent intent = LinkCollectionIntent.builder().appId(appId).selector(ethDstSelector).treatment(treatment).links(testLinks).filteredIngressPoints(ingress).filteredEgressPoints(egress).applyTreatmentOnEgress(true).resourceGroup(resourceGroup2).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(3));
    TrafficSelector expectSelector = DefaultTrafficSelector.builder(ethDstSelector).matchInPort(PortNumber.portNumber(1)).matchVlanId(VLAN_100).build();
    List<TrafficTreatment> expectTreatments = ImmutableList.of(DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(2)).build(), DefaultTrafficTreatment.builder().setOutput(PortNumber.portNumber(3)).build());
    /*
         * First set of objective
         */
    filteringObjective = (FilteringObjective) objectives.get(0);
    forwardingObjective = (ForwardingObjective) objectives.get(1);
    nextObjective = (NextObjective) objectives.get(2);
    PortCriterion inPortCriterion = (PortCriterion) expectSelector.getCriterion(Criterion.Type.IN_PORT);
    // test case for first filtering objective
    checkFiltering(filteringObjective, inPortCriterion, intent.priority(), null, appId, true, vlan100Selector.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);
}
Also used : 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)

Example 50 with TrafficTreatment

use of org.onosproject.net.flow.TrafficTreatment in project onos by opennetworkinglab.

the class PathIntentCompilerTest method verifyMplsEncapTreatment.

private MplsLabel verifyMplsEncapTreatment(TrafficTreatment trafficTreatment, ConnectPoint egress, boolean isIngress, boolean isEgress) {
    Set<Instructions.OutputInstruction> ruleOutput = trafficTreatment.allInstructions().stream().filter(treat -> treat instanceof Instructions.OutputInstruction).map(treat -> (Instructions.OutputInstruction) treat).collect(Collectors.toSet());
    assertThat(ruleOutput, hasSize(1));
    assertThat((ruleOutput.iterator().next()).port(), is(egress.port()));
    MplsLabel mplsToEncap = MplsLabel.mplsLabel(0);
    if (isIngress && !isEgress) {
        Set<L2ModificationInstruction.ModMplsLabelInstruction> mplsRules = trafficTreatment.allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModMplsLabelInstruction).map(x -> (L2ModificationInstruction.ModMplsLabelInstruction) x).collect(Collectors.toSet());
        assertThat(mplsRules, hasSize(1));
        L2ModificationInstruction.ModMplsLabelInstruction mplsRule = mplsRules.iterator().next();
        assertThat(mplsRule.label().toInt(), greaterThan(0));
        assertThat(mplsRule.label().toInt(), lessThan(MplsLabel.MAX_MPLS));
        mplsToEncap = mplsRule.label();
    } else if (!isIngress && !isEgress) {
        Set<L2ModificationInstruction.ModMplsLabelInstruction> mplsRules = trafficTreatment.allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModMplsLabelInstruction).map(x -> (L2ModificationInstruction.ModMplsLabelInstruction) x).collect(Collectors.toSet());
        assertThat(mplsRules, hasSize(1));
        L2ModificationInstruction.ModMplsLabelInstruction mplsRule = mplsRules.iterator().next();
        assertThat(mplsRule.label().toInt(), greaterThan(0));
        assertThat(mplsRule.label().toInt(), lessThan(MplsLabel.MAX_MPLS));
        mplsToEncap = mplsRule.label();
    } else {
        assertThat(trafficTreatment.allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModMplsLabelInstruction).collect(Collectors.toSet()), hasSize(0));
        assertThat(trafficTreatment.allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModMplsHeaderInstruction).collect(Collectors.toSet()), hasSize(1));
    }
    return mplsToEncap;
}
Also used : DIRECT(org.onosproject.net.Link.Type.DIRECT) Arrays(java.util.Arrays) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) TestApplicationId(org.onosproject.TestApplicationId) CoreService(org.onosproject.core.CoreService) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) INDIRECT(org.onosproject.net.Link.Type.INDIRECT) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) ApplicationId(org.onosproject.core.ApplicationId) DefaultPath(org.onosproject.net.DefaultPath) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Intent(org.onosproject.net.intent.Intent) OrderingComparison.greaterThan(org.hamcrest.number.OrderingComparison.greaterThan) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) MockResourceService(org.onosproject.net.resource.MockResourceService) Before(org.junit.Before) DefaultLink(org.onosproject.net.DefaultLink) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PathIntent(org.onosproject.net.intent.PathIntent) Instructions(org.onosproject.net.flow.instructions.Instructions) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) MplsLabel(org.onlab.packet.MplsLabel) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) EasyMock(org.easymock.EasyMock) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest) Collectors(java.util.stream.Collectors) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) NetTestTools(org.onosproject.net.NetTestTools) FlowRule(org.onosproject.net.flow.FlowRule) ScalarWeight(org.onlab.graph.ScalarWeight) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) Set(java.util.Set) MplsLabel(org.onlab.packet.MplsLabel) Instructions(org.onosproject.net.flow.instructions.Instructions) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction)

Aggregations

TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)395 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)369 TrafficSelector (org.onosproject.net.flow.TrafficSelector)257 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)236 FlowRule (org.onosproject.net.flow.FlowRule)93 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)86 PiAction (org.onosproject.net.pi.runtime.PiAction)79 Test (org.junit.Test)78 PortNumber (org.onosproject.net.PortNumber)70 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)56 Instruction (org.onosproject.net.flow.instructions.Instruction)52 DeviceId (org.onosproject.net.DeviceId)46 NextObjective (org.onosproject.net.flowobjective.NextObjective)45 ConnectPoint (org.onosproject.net.ConnectPoint)44 List (java.util.List)43 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)43 Ethernet (org.onlab.packet.Ethernet)40 Criterion (org.onosproject.net.flow.criteria.Criterion)39 GroupBucket (org.onosproject.net.group.GroupBucket)39 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)37