Search in sources :

Example 21 with IntentInstallationContext

use of org.onosproject.net.intent.IntentInstallationContext in project onos by opennetworkinglab.

the class FlowRuleIntentInstallerTest method testUninstallAndInstall.

/**
 * Do both install and uninstall Intents with different flow rules.
 */
@Test
public void testUninstallAndInstall() {
    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);
    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);
    expectedFlowRules = intentsToInstall.stream().map(intent -> (FlowRuleIntent) intent).map(FlowRuleIntent::flowRules).flatMap(Collection::stream).collect(Collectors.toSet());
    assertEquals(expectedFlowRules, flowRuleService.flowRulesAdd);
}
Also used : REMOVE(org.onosproject.net.flow.FlowRuleOperation.Type.REMOVE) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) IntentState(org.onosproject.net.intent.IntentState) FlowEntry(org.onosproject.net.flow.FlowEntry) EasyMock.mock(org.easymock.EasyMock.mock) FlowRuleServiceAdapter(org.onosproject.net.flow.FlowRuleServiceAdapter) IntentData(org.onosproject.net.intent.IntentData) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) After(org.junit.After) Map(java.util.Map) Intent(org.onosproject.net.intent.Intent) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) FlowRuleOperation(org.onosproject.net.flow.FlowRuleOperation) ADD(org.onosproject.net.flow.FlowRuleOperation.Type.ADD) Before(org.junit.Before) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) PathIntent(org.onosproject.net.intent.PathIntent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) NetworkResource(org.onosproject.net.NetworkResource) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) SimpleIntentStore(org.onosproject.store.trivial.SimpleIntentStore) IntentInstallationContext(org.onosproject.net.intent.IntentInstallationContext) DeviceId(org.onosproject.net.DeviceId) Assert.assertEquals(org.junit.Assert.assertEquals) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) IntentInstallationContext(org.onosproject.net.intent.IntentInstallationContext) Collection(java.util.Collection) 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) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Test(org.junit.Test)

Example 22 with IntentInstallationContext

use of org.onosproject.net.intent.IntentInstallationContext in project onos by opennetworkinglab.

the class DomainIntentInstallerTest method testInstall.

/**
 * Installs domain Intents.
 */
@Test
public void testInstall() {
    List<Intent> intentsToUninstall = Lists.newArrayList();
    List<Intent> intentsToInstall = createDomainIntents();
    IntentData toUninstall = null;
    IntentData toInstall = new IntentData(createP2PIntent(), IntentState.INSTALLING, new WallClockTimestamp());
    toInstall = IntentData.compiled(toInstall, intentsToInstall);
    IntentOperationContext<DomainIntent> operationContext;
    IntentInstallationContext context = new IntentInstallationContext(toUninstall, toInstall);
    operationContext = new IntentOperationContext(intentsToUninstall, intentsToInstall, context);
    installer.apply(operationContext);
    assertEquals(intentInstallCoordinator.successContext, operationContext);
}
Also used : WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) IntentInstallationContext(org.onosproject.net.intent.IntentInstallationContext) DomainPointToPointIntent(org.onosproject.net.domain.DomainPointToPointIntent) DomainIntent(org.onosproject.net.domain.DomainIntent) Intent(org.onosproject.net.intent.Intent) DomainIntent(org.onosproject.net.domain.DomainIntent) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext) Test(org.junit.Test)

Example 23 with IntentInstallationContext

use of org.onosproject.net.intent.IntentInstallationContext in project onos by opennetworkinglab.

the class DomainIntentInstallerTest method testUninstallAndInstall.

/**
 * Do both uninstall and install domain Intents.
 */
@Test
public void testUninstallAndInstall() {
    List<Intent> intentsToUninstall = createDomainIntents();
    List<Intent> intentsToInstall = createAnotherDomainIntents();
    IntentData toUninstall = new IntentData(createP2PIntent(), IntentState.INSTALLED, new WallClockTimestamp());
    toUninstall = IntentData.compiled(toUninstall, intentsToUninstall);
    IntentData toInstall = new IntentData(createP2PIntent(), IntentState.INSTALLING, new WallClockTimestamp());
    toInstall = IntentData.compiled(toInstall, intentsToInstall);
    IntentOperationContext<DomainIntent> operationContext;
    IntentInstallationContext context = new IntentInstallationContext(toUninstall, toInstall);
    operationContext = new IntentOperationContext(intentsToUninstall, intentsToInstall, context);
    installer.apply(operationContext);
    assertEquals(intentInstallCoordinator.successContext, operationContext);
}
Also used : WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) IntentInstallationContext(org.onosproject.net.intent.IntentInstallationContext) DomainPointToPointIntent(org.onosproject.net.domain.DomainPointToPointIntent) DomainIntent(org.onosproject.net.domain.DomainIntent) Intent(org.onosproject.net.intent.Intent) DomainIntent(org.onosproject.net.domain.DomainIntent) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext) Test(org.junit.Test)

Example 24 with IntentInstallationContext

use of org.onosproject.net.intent.IntentInstallationContext in project onos by opennetworkinglab.

the class DomainIntentInstallerTest method testInstallFailed.

/**
 * Test if domain Intent installation operations failed.
 */
@Test
public void testInstallFailed() {
    domainIntentService = new TestFailedDomainIntentService();
    installer.domainIntentService = domainIntentService;
    List<Intent> intentsToUninstall = Lists.newArrayList();
    List<Intent> intentsToInstall = createDomainIntents();
    IntentData toUninstall = null;
    IntentData toInstall = new IntentData(createP2PIntent(), IntentState.INSTALLING, new WallClockTimestamp());
    toInstall = IntentData.compiled(toInstall, intentsToInstall);
    IntentOperationContext<DomainIntent> operationContext;
    IntentInstallationContext context = new IntentInstallationContext(toUninstall, toInstall);
    operationContext = new IntentOperationContext(intentsToUninstall, intentsToInstall, context);
    installer.apply(operationContext);
    assertEquals(intentInstallCoordinator.failedContext, operationContext);
}
Also used : WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) IntentInstallationContext(org.onosproject.net.intent.IntentInstallationContext) DomainPointToPointIntent(org.onosproject.net.domain.DomainPointToPointIntent) DomainIntent(org.onosproject.net.domain.DomainIntent) Intent(org.onosproject.net.intent.Intent) DomainIntent(org.onosproject.net.domain.DomainIntent) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext) Test(org.junit.Test)

Example 25 with IntentInstallationContext

use of org.onosproject.net.intent.IntentInstallationContext 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)

Aggregations

IntentInstallationContext (org.onosproject.net.intent.IntentInstallationContext)36 IntentOperationContext (org.onosproject.net.intent.IntentOperationContext)32 IntentData (org.onosproject.net.intent.IntentData)30 Test (org.junit.Test)28 Intent (org.onosproject.net.intent.Intent)28 WallClockTimestamp (org.onosproject.store.service.WallClockTimestamp)26 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)14 PathIntent (org.onosproject.net.intent.PathIntent)13 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)5 FlowRule (org.onosproject.net.flow.FlowRule)5 ProtectionEndpointIntent (org.onosproject.net.intent.ProtectionEndpointIntent)5 Collection (java.util.Collection)4 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)4 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)4 TrafficSelector (org.onosproject.net.flow.TrafficSelector)4 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)4 ImmutableList (com.google.common.collect.ImmutableList)3 Lists (com.google.common.collect.Lists)3 Maps (com.google.common.collect.Maps)3 Sets (com.google.common.collect.Sets)3