Search in sources :

Example 76 with FlowRuleIntent

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()));
}
Also used : WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) IntentInstallationContext(org.onosproject.net.intent.IntentInstallationContext) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test)

Example 77 with FlowRuleIntent

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);
}
Also used : WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) IntentInstallationContext(org.onosproject.net.intent.IntentInstallationContext) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test)

Example 78 with FlowRuleIntent

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;
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 79 with FlowRuleIntent

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;
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 80 with FlowRuleIntent

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()));
}
Also used : WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) IntentInstallationContext(org.onosproject.net.intent.IntentInstallationContext) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test)

Aggregations

FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)111 Intent (org.onosproject.net.intent.Intent)103 FlowRule (org.onosproject.net.flow.FlowRule)91 Test (org.junit.Test)89 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)67 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)67 List (java.util.List)58 DeviceId (org.onosproject.net.DeviceId)58 Collection (java.util.Collection)57 Collectors (java.util.stream.Collectors)55 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)55 VlanId (org.onlab.packet.VlanId)54 Before (org.junit.Before)52 Collections (java.util.Collections)51 CoreService (org.onosproject.core.CoreService)50 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)50 EasyMock (org.easymock.EasyMock)49 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)49 ComponentConfigAdapter (org.onosproject.cfg.ComponentConfigAdapter)49 IntentExtensionService (org.onosproject.net.intent.IntentExtensionService)49