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;
}
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();
}
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);
}
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);
}
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;
}
Aggregations