use of org.onosproject.net.intent.IntentInstallationContext in project onos by opennetworkinglab.
the class DomainIntentInstallerTest method testUninstall.
/**
* Uninstall domain Intents.
*/
@Test
public void testUninstall() {
List<Intent> intentsToUninstall = createDomainIntents();
List<Intent> intentsToInstall = Lists.newArrayList();
IntentData toUninstall = new IntentData(createP2PIntent(), IntentState.WITHDRAWING, new WallClockTimestamp());
IntentData toInstall = null;
toUninstall = IntentData.compiled(toUninstall, intentsToUninstall);
IntentOperationContext<DomainIntent> operationContext;
IntentInstallationContext context = new IntentInstallationContext(toUninstall, toInstall);
operationContext = new IntentOperationContext(intentsToUninstall, intentsToInstall, context);
installer.apply(operationContext);
assertEquals(intentInstallCoordinator.successContext, operationContext);
}
use of org.onosproject.net.intent.IntentInstallationContext in project onos by opennetworkinglab.
the class FlowRuleIntentInstallerTest method testUninstallOnly.
/**
* Uninstalls Intents only, no Intents to be install.
*/
@Test
public void testUninstallOnly() {
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);
flowRuleService.load(operationContext.intentsToUninstall());
installer.apply(operationContext);
IntentOperationContext successContext = intentInstallCoordinator.successContext;
assertEquals(successContext, operationContext);
Set<FlowRule> expectedFlowRules = intentsToUninstall.stream().map(intent -> (FlowRuleIntent) intent).map(FlowRuleIntent::flowRules).flatMap(Collection::stream).collect(Collectors.toSet());
assertEquals(expectedFlowRules, flowRuleService.flowRulesRemove);
}
use of org.onosproject.net.intent.IntentInstallationContext in project onos by opennetworkinglab.
the class FlowRuleIntentInstallerTest method testUninstallAndInstallUnchanged.
/**
* Do both install and uninstall Intents with same flow rules.
*/
@Test
public void testUninstallAndInstallUnchanged() {
List<Intent> intentsToInstall = createFlowRuleIntents();
List<Intent> intentsToUninstall = createFlowRuleIntents();
IntentData toInstall = new IntentData(createP2PIntent(), IntentState.INSTALLING, new WallClockTimestamp());
toInstall = IntentData.compiled(toInstall, intentsToInstall);
IntentData toUninstall = new IntentData(createP2PIntent(), IntentState.INSTALLED, new WallClockTimestamp());
toUninstall = IntentData.compiled(toUninstall, intentsToUninstall);
IntentOperationContext<FlowRuleIntent> operationContext;
IntentInstallationContext context = new IntentInstallationContext(toUninstall, toInstall);
operationContext = new IntentOperationContext(intentsToUninstall, intentsToInstall, context);
flowRuleService.load(operationContext.intentsToUninstall());
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());
}
use of org.onosproject.net.intent.IntentInstallationContext 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.IntentInstallationContext in project onos by opennetworkinglab.
the class FlowRuleIntentInstallerTest method testInstallOnly.
/**
* Installs Intents only, no Intents to be uninstall.
*/
@Test
public void testInstallOnly() {
List<Intent> intentsToUninstall = Lists.newArrayList();
List<Intent> intentsToInstall = createFlowRuleIntents();
IntentData toUninstall = null;
IntentData toInstall = new IntentData(createP2PIntent(), IntentState.INSTALLING, new WallClockTimestamp());
toInstall = IntentData.compiled(toInstall, intentsToInstall);
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);
Set<FlowRule> expectedFlowRules = intentsToInstall.stream().map(intent -> (FlowRuleIntent) intent).map(FlowRuleIntent::flowRules).flatMap(Collection::stream).collect(Collectors.toSet());
assertEquals(expectedFlowRules, flowRuleService.flowRulesAdd);
}
Aggregations