use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class FlowRuleIntentInstallerTest method testRuleModifyMissing.
/**
* Test intents with same match rules, should do modify instead of add. However, the flow rules do not exist
* in the FlowRuleService.
*/
@Test
public void testRuleModifyMissing() {
List<Intent> intentsToInstall = createFlowRuleIntents();
List<Intent> intentsToUninstall = createFlowRuleIntentsWithSameMatch();
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);
installer.apply(operationContext);
IntentOperationContext successContext = intentInstallCoordinator.successContext;
assertEquals(successContext, operationContext);
assertEquals(0, flowRuleService.flowRulesRemove.size());
assertEquals(1, flowRuleService.flowRulesAdd.size());
assertEquals(0, flowRuleService.flowRulesModify.size());
FlowRuleIntent installedIntent = (FlowRuleIntent) intentsToInstall.get(0);
assertEquals(flowRuleService.flowRulesAdd.size(), installedIntent.flowRules().size());
assertTrue(flowRuleService.flowRulesAdd.containsAll(installedIntent.flowRules()));
}
use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class FlowRuleIntentInstallerTest method testFailed.
/**
* Test if the flow installation failed.
*/
@Test
public void testFailed() {
installer.flowRuleService = new TestFailedFlowRuleService();
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 failedContext = intentInstallCoordinator.failedContext;
assertEquals(failedContext, operationContext);
}
use of org.onosproject.net.intent.FlowRuleIntent in project onos by opennetworkinglab.
the class FlowRuleIntentInstallerTest method createFlowRuleIntents.
/**
* Generates FlowRuleIntents for test.
*
* @return the FlowRuleIntents for test
*/
public List<Intent> createFlowRuleIntents() {
TrafficSelector selector = DefaultTrafficSelector.builder().matchInPhyPort(CP1.port()).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(CP2.port()).build();
FlowRule flowRule = DefaultFlowRule.builder().forDevice(CP1.deviceId()).withSelector(selector).withTreatment(treatment).fromApp(APP_ID).withPriority(DEFAULT_PRIORITY).makePermanent().build();
List<NetworkResource> resources = ImmutableList.of(CP1.deviceId());
FlowRuleIntent intent = new FlowRuleIntent(APP_ID, KEY1, ImmutableList.of(flowRule), 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 createAnotherFlowRuleIntents.
/**
* Generates another different FlowRuleIntents for test.
*
* @return the FlowRuleIntents for test
*/
public List<Intent> createAnotherFlowRuleIntents() {
TrafficSelector selector = DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId("100")).matchInPhyPort(CP1.port()).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(CP2.port()).build();
FlowRule flowRule = DefaultFlowRule.builder().forDevice(CP1.deviceId()).withSelector(selector).withTreatment(treatment).fromApp(APP_ID).withPriority(DEFAULT_PRIORITY).makePermanent().build();
List<NetworkResource> resources = ImmutableList.of(CP1.deviceId());
FlowRuleIntent intent = new FlowRuleIntent(APP_ID, KEY1, ImmutableList.of(flowRule), 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 testRuleModify.
/**
* Test intents with same match rules, should do modify instead of add.
*/
@Test
public void testRuleModify() {
List<Intent> intentsToInstall = createFlowRuleIntents();
List<Intent> intentsToUninstall = createFlowRuleIntentsWithSameMatch();
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(1, flowRuleService.flowRulesModify.size());
FlowRuleIntent installedIntent = (FlowRuleIntent) intentsToInstall.get(0);
assertEquals(flowRuleService.flowRulesModify.size(), installedIntent.flowRules().size());
assertTrue(flowRuleService.flowRulesModify.containsAll(installedIntent.flowRules()));
}
Aggregations