use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class PathIntentCompilerTest method testRandomVlanSelection.
/**
* Tests the random selection of VLAN Ids in the PathCompiler.
* It can fail randomly (it is unlikely)
*/
@Test
public void testRandomVlanSelection() {
sut.activate();
List<Intent> compiled = sut.compile(constraintVlanIntent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(3));
FlowRule rule1 = rules.stream().filter(x -> x.deviceId().equals(d1p0.deviceId())).findFirst().get();
verifyIdAndPriority(rule1, d1p0.deviceId());
assertThat(rule1.selector(), is(DefaultTrafficSelector.builder(selector).matchInPort(d1p0.port()).build()));
VlanId vlanToEncap = verifyVlanEncapTreatment(rule1.treatment(), d1p1, true, false);
assertTrue(VlanId.NO_VID < vlanToEncap.toShort() && vlanToEncap.toShort() < VlanId.MAX_VLAN);
/*
* This second part is meant to test if the random selection is working properly.
* We are compiling the same intent in order to verify if the VLAN ID is different
* from the previous one.
*/
List<Intent> compiled2 = sut.compile(constraintVlanIntent, Collections.emptyList());
assertThat(compiled2, hasSize(1));
Collection<FlowRule> rules2 = ((FlowRuleIntent) compiled2.get(0)).flowRules();
assertThat(rules2, hasSize(3));
FlowRule rule2 = rules2.stream().filter(x -> x.deviceId().equals(d1p0.deviceId())).findFirst().get();
verifyIdAndPriority(rule2, d1p0.deviceId());
assertThat(rule2.selector(), is(DefaultTrafficSelector.builder(selector).matchInPort(d1p0.port()).build()));
VlanId vlanToEncap2 = verifyVlanEncapTreatment(rule2.treatment(), d1p1, true, false);
assertTrue(VlanId.NO_VID < vlanToEncap2.toShort() && vlanToEncap2.toShort() < VlanId.MAX_VLAN);
sut.deactivate();
}
use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class PathIntentCompilerTest method testVlanEncapCompileSingleHopDirectIngressVlan.
/**
* Tests the compilation behavior of the path intent compiler in case of
* VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
* and single-hop-direct-link scenario. Ingress VLAN. No egress VLAN.
*/
@Test
public void testVlanEncapCompileSingleHopDirectIngressVlan() {
sut.activate();
List<Intent> compiled = sut.compile(singleHopDirectIntentIngressVlan, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(1));
FlowRule rule = rules.stream().filter(x -> x.deviceId().equals(d2p4.deviceId())).findFirst().get();
verifyIdAndPriority(rule, d2p4.deviceId());
assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p4.port()).matchVlanId(ingressVlan).build()));
assertThat(rule.treatment(), is(DefaultTrafficTreatment.builder().setOutput(d2p5.port()).build()));
sut.deactivate();
}
use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class FlowRuleIntentInstallerTest method testUninstallAndInstallNonDisruptive.
/**
* Testing the non-disruptive reallocation.
*/
@Test
public void testUninstallAndInstallNonDisruptive() throws InterruptedException {
installer.flowRuleService = flowRuleServiceNonDisruptive;
List<Intent> intentsToInstall = createAnotherFlowRuleIntentsNonDisruptive();
List<Intent> intentsToUninstall = createFlowRuleIntentsNonDisruptive();
IntentData toInstall = new IntentData(createP2PIntentNonDisruptive(), IntentState.INSTALLING, new WallClockTimestamp());
toInstall = IntentData.compiled(toInstall, intentsToInstall);
IntentData toUninstall = new IntentData(createP2PIntentNonDisruptive(), IntentState.INSTALLED, new WallClockTimestamp());
toUninstall = IntentData.compiled(toUninstall, intentsToUninstall);
IntentOperationContext<FlowRuleIntent> operationContext;
IntentInstallationContext context = new IntentInstallationContext(toUninstall, toInstall);
operationContext = new IntentOperationContext(intentsToUninstall, intentsToInstall, context);
installer.apply(operationContext);
// A single FlowRule is evaluated for every non-disruptive stage
TrafficSelector selector = DefaultTrafficSelector.builder().matchInPhyPort(CP1.port()).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(CP3.port()).build();
FlowRule firstStageInstalledRule = DefaultFlowRule.builder().forDevice(CP1.deviceId()).withSelector(selector).withTreatment(treatment).fromApp(APP_ID).withPriority(DEFAULT_PRIORITY - 1).makePermanent().build();
// race conditions and failing builds
synchronized (flowRuleServiceNonDisruptive) {
while (!verifyFlowRule(ADD, firstStageInstalledRule)) {
flowRuleServiceNonDisruptive.wait();
}
}
assertTrue(flowRuleServiceNonDisruptive.flowRulesAdd.contains(firstStageInstalledRule));
selector = DefaultTrafficSelector.builder().matchInPhyPort(CP4_2.port()).build();
treatment = DefaultTrafficTreatment.builder().setOutput(CP4_1.port()).build();
FlowRule secondStageUninstalledRule = DefaultFlowRule.builder().forDevice(CP4_1.deviceId()).withSelector(selector).withTreatment(treatment).fromApp(APP_ID).withPriority(DEFAULT_PRIORITY).makePermanent().build();
synchronized (flowRuleServiceNonDisruptive) {
while (!verifyFlowRule(REMOVE, secondStageUninstalledRule)) {
flowRuleServiceNonDisruptive.wait();
}
}
assertTrue(flowRuleServiceNonDisruptive.flowRulesRemove.contains(secondStageUninstalledRule));
selector = DefaultTrafficSelector.builder().matchInPhyPort(CP4_3.port()).build();
treatment = DefaultTrafficTreatment.builder().setOutput(CP4_1.port()).build();
FlowRule thirdStageInstalledRule = DefaultFlowRule.builder().forDevice(CP4_1.deviceId()).withSelector(selector).withTreatment(treatment).fromApp(APP_ID).withPriority(DEFAULT_PRIORITY).makePermanent().build();
synchronized (flowRuleServiceNonDisruptive) {
while (!verifyFlowRule(ADD, thirdStageInstalledRule)) {
flowRuleServiceNonDisruptive.wait();
}
}
assertTrue(flowRuleServiceNonDisruptive.flowRulesAdd.contains(thirdStageInstalledRule));
selector = DefaultTrafficSelector.builder().matchInPhyPort(CP2_1.port()).build();
treatment = DefaultTrafficTreatment.builder().setOutput(CP2_2.port()).build();
FlowRule lastStageUninstalledRule = DefaultFlowRule.builder().forDevice(CP2_1.deviceId()).withSelector(selector).withTreatment(treatment).fromApp(APP_ID).withPriority(DEFAULT_PRIORITY).makePermanent().build();
synchronized (flowRuleServiceNonDisruptive) {
while (!verifyFlowRule(REMOVE, lastStageUninstalledRule)) {
flowRuleServiceNonDisruptive.wait();
}
}
assertTrue(flowRuleServiceNonDisruptive.flowRulesRemove.contains(lastStageUninstalledRule));
IntentOperationContext successContext = intentInstallCoordinator.successContext;
assertEquals(successContext, operationContext);
}
use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class FlowRuleIntentInstallerTest method createFlowRuleIntentsNonDisruptive.
/**
* Generates FlowRuleIntents for testing non-disruptive reallocation.
*
* @return the FlowRuleIntents for test
*/
public List<Intent> createFlowRuleIntentsNonDisruptive() {
Map<ConnectPoint, ConnectPoint> portsAssociation = Maps.newHashMap();
portsAssociation.put(CP1, CP2);
portsAssociation.put(CP2_1, CP2_2);
portsAssociation.put(CP4_2, CP4_1);
List<FlowRule> flowRules = Lists.newArrayList();
for (ConnectPoint srcPoint : portsAssociation.keySet()) {
TrafficSelector selector = DefaultTrafficSelector.builder().matchInPhyPort(srcPoint.port()).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(portsAssociation.get(srcPoint).port()).build();
FlowRule flowRule = DefaultFlowRule.builder().forDevice(srcPoint.deviceId()).withSelector(selector).withTreatment(treatment).fromApp(APP_ID).withPriority(DEFAULT_PRIORITY).makePermanent().build();
flowRules.add(flowRule);
}
List<NetworkResource> resources = ImmutableList.of(S1_S2, S2_S4);
FlowRuleIntent intent = new FlowRuleIntent(APP_ID, KEY1, flowRules, resources, PathIntent.ProtectionType.PRIMARY, RG1);
List<Intent> flowRuleIntents = Lists.newArrayList();
flowRuleIntents.add(intent);
return flowRuleIntents;
}
use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class FlowRuleIntentInstallerTest method testUninstallOnlyMissing.
/**
* Uninstalls Intents only, no Intents to be install. However, the flow rules do not exist
* in the FlowRuleService.
*/
@Test
public void testUninstallOnlyMissing() {
List<Intent> intentsToInstall = Lists.newArrayList();
List<Intent> intentsToUninstall = createFlowRuleIntents();
IntentData toInstall = null;
IntentData toUninstall = new IntentData(createP2PIntent(), IntentState.WITHDRAWING, new WallClockTimestamp());
toUninstall = IntentData.compiled(toUninstall, intentsToUninstall);
IntentOperationContext<FlowRuleIntent> operationContext;
IntentInstallationContext context = new IntentInstallationContext(toUninstall, toInstall);
operationContext = new IntentOperationContext(intentsToUninstall, intentsToInstall, context);
installer.apply(operationContext);
IntentOperationContext successContext = intentInstallCoordinator.successContext;
assertEquals(successContext, operationContext);
assertEquals(0, flowRuleService.flowRulesRemove.size());
assertEquals(0, flowRuleService.flowRulesAdd.size());
assertEquals(0, flowRuleService.flowRulesModify.size());
}
Aggregations