Search in sources :

Example 6 with WallClockTimestamp

use of org.onosproject.store.service.WallClockTimestamp in project onos by opennetworkinglab.

the class FlowObjectiveIntentInstallerTest method testUninstallAndInstallIntent.

/**
 * Do both uninstall and install flow objective Intents.
 */
@Test
public void testUninstallAndInstallIntent() {
    List<Intent> intentsToUninstall = createFlowObjectiveIntents();
    List<Intent> intentsToInstall = createAnotherFlowObjectiveIntents();
    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<FlowObjectiveIntent> operationContext;
    IntentInstallationContext context = new IntentInstallationContext(toUninstall, toInstall);
    operationContext = new IntentOperationContext(intentsToUninstall, intentsToInstall, context);
    installer.apply(operationContext);
    IntentOperationContext successContext = intentInstallCoordinator.successContext;
    assertEquals(successContext, operationContext);
}
Also used : WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) IntentInstallationContext(org.onosproject.net.intent.IntentInstallationContext) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) Intent(org.onosproject.net.intent.Intent) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext) Test(org.junit.Test)

Example 7 with WallClockTimestamp

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

Example 8 with WallClockTimestamp

use of org.onosproject.store.service.WallClockTimestamp in project onos by opennetworkinglab.

the class FlowRuleIntentInstallerTest method testUninstallOnlyMissing.

/**
 * Uninstalls Intents only, no Intents to be install.  However, the flow rules do not exist
 * in the FlowRuleService.
 */
@Test
public void testUninstallOnlyMissing() {
    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);
    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());
}
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 9 with WallClockTimestamp

use of org.onosproject.store.service.WallClockTimestamp 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 10 with WallClockTimestamp

use of org.onosproject.store.service.WallClockTimestamp in project onos by opennetworkinglab.

the class FlowRuleIntentInstallerTest method testUninstallAndInstallSame.

/**
 * Do both install and uninstall Intents with same flow rule Intent.
 */
@Test
public void testUninstallAndInstallSame() {
    List<Intent> intentsToInstall = createFlowRuleIntents();
    List<Intent> intentsToUninstall = intentsToInstall;
    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());
}
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

WallClockTimestamp (org.onosproject.store.service.WallClockTimestamp)48 IntentData (org.onosproject.net.intent.IntentData)34 Intent (org.onosproject.net.intent.Intent)33 Test (org.junit.Test)28 IntentInstallationContext (org.onosproject.net.intent.IntentInstallationContext)26 IntentOperationContext (org.onosproject.net.intent.IntentOperationContext)26 Activate (org.osgi.service.component.annotations.Activate)15 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)13 PathIntent (org.onosproject.net.intent.PathIntent)13 Collection (java.util.Collection)8 KryoNamespace (org.onlab.util.KryoNamespace)8 ImmutableList (com.google.common.collect.ImmutableList)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 ComponentConfigService (org.onosproject.cfg.ComponentConfigService)5 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)5 FlowRule (org.onosproject.net.flow.FlowRule)5 IntentState (org.onosproject.net.intent.IntentState)5 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)4 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)4