Search in sources :

Example 81 with Intent

use of org.onosproject.net.intent.Intent 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;
}
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) ConnectPoint(org.onosproject.net.ConnectPoint) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 82 with Intent

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

the class FlowRuleIntentInstallerTest method testUninstallAndInstallUnchangedMissing.

/**
 * Do both install and uninstall Intents with same flow rules.  However, the flow rules do not exist
 * in the FlowRuleService.
 */
@Test
public void testUninstallAndInstallUnchangedMissing() {
    List<Intent> intentsToInstall = createFlowRuleIntents();
    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);
    assertEquals(0, flowRuleService.flowRulesRemove.size());
    assertEquals(1, 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 83 with Intent

use of org.onosproject.net.intent.Intent 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);
}
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) 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 84 with Intent

use of org.onosproject.net.intent.Intent 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);
}
Also used : 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 85 with Intent

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

the class FlowRuleIntentInstallerTest method testUninstallOnly.

/**
 * Uninstalls Intents only, no Intents to be install.
 */
@Test
public void testUninstallOnly() {
    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);
    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);
}
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) 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)

Aggregations

Intent (org.onosproject.net.intent.Intent)282 Test (org.junit.Test)176 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)133 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)110 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)108 FlowRule (org.onosproject.net.flow.FlowRule)90 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)87 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)84 ConnectPoint (org.onosproject.net.ConnectPoint)78 DeviceId (org.onosproject.net.DeviceId)77 List (java.util.List)75 Collectors (java.util.stream.Collectors)71 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)70 PathIntent (org.onosproject.net.intent.PathIntent)70 Collection (java.util.Collection)60 VlanId (org.onlab.packet.VlanId)60 TrafficSelector (org.onosproject.net.flow.TrafficSelector)60 CoreService (org.onosproject.core.CoreService)59 Collections (java.util.Collections)57 ImmutableSet (com.google.common.collect.ImmutableSet)54