use of org.onosproject.net.flow.FlowRule 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);
}
use of org.onosproject.net.flow.FlowRule 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.flow.FlowRule in project onos by opennetworkinglab.
the class FlowRuleIntentInstallerTest method createAnotherFlowRuleIntentsNonDisruptive.
/**
* Generates another FlowRuleIntent, going through a different path, for testing non-disruptive reallocation.
*
* @return the FlowRuleIntents for test
*/
public List<Intent> createAnotherFlowRuleIntentsNonDisruptive() {
Map<ConnectPoint, ConnectPoint> portsAssociation = Maps.newHashMap();
portsAssociation.put(CP1, CP3);
portsAssociation.put(CP3_1, CP3_2);
portsAssociation.put(CP4_3, 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_S3, S3_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.flow.FlowRule in project onos by opennetworkinglab.
the class FlowRuleIntentInstallerTest method testUninstallAndInstallMissing.
/**
* Do both install and uninstall Intents with different flow rules. However, the flow rules do not exist
* in the FlowRuleService.
*/
@Test
public void testUninstallAndInstallMissing() {
List<Intent> intentsToInstall = createAnotherFlowRuleIntents();
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);
installer.apply(operationContext);
IntentOperationContext successContext = intentInstallCoordinator.successContext;
assertEquals(successContext, operationContext);
Set<FlowRule> expectedFlowRules = Sets.newHashSet();
assertEquals(expectedFlowRules, flowRuleService.flowRulesRemove);
expectedFlowRules = intentsToInstall.stream().map(intent -> (FlowRuleIntent) intent).map(FlowRuleIntent::flowRules).flatMap(Collection::stream).collect(Collectors.toSet());
assertEquals(expectedFlowRules, flowRuleService.flowRulesAdd);
}
use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.
the class FlowRuleIntentInstallerTest method createFlowRuleIntentsWithSameMatch.
/**
* Generates FlowRuleIntents for test. Flow rules in Intent should have same
* match as we created by createFlowRuleIntents method, but action will be
* different.
*
* @return the FlowRuleIntents for test
*/
public List<Intent> createFlowRuleIntentsWithSameMatch() {
TrafficSelector selector = DefaultTrafficSelector.builder().matchInPhyPort(CP1.port()).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().punt().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;
}
Aggregations