Search in sources :

Example 1 with IntentInstallationContext

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

the class VirtualIntentInstallCoordinator method failed.

/**
 * Handles failed operation context.
 *
 * @param context the operation context
 */
public void failed(IntentOperationContext context) {
    IntentInstallationContext intentInstallationContext = context.intentInstallationContext();
    intentInstallationContext.addErrorContext(context);
    intentInstallationContext.removePendingContext(context);
    if (intentInstallationContext.isPendingContextsEmpty()) {
        finish(intentInstallationContext);
    }
}
Also used : IntentInstallationContext(org.onosproject.net.intent.IntentInstallationContext)

Example 2 with IntentInstallationContext

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

the class VirtualIntentInstallCoordinator method installIntents.

/**
 * Applies Intent data to be uninstalled and to be installed.
 *
 * @param toUninstall Intent data to be uninstalled
 * @param toInstall Intent data to be installed
 */
public void installIntents(Optional<IntentData> toUninstall, Optional<IntentData> toInstall) {
    // If no any Intents to be uninstalled or installed, ignore it.
    if (!toUninstall.isPresent() && !toInstall.isPresent()) {
        return;
    }
    // Classify installable Intents to different installers.
    ArrayListMultimap<IntentInstaller, Intent> uninstallInstallers;
    ArrayListMultimap<IntentInstaller, Intent> installInstallers;
    Set<IntentInstaller> allInstallers = Sets.newHashSet();
    if (toUninstall.isPresent()) {
        uninstallInstallers = getInstallers(toUninstall.get());
        allInstallers.addAll(uninstallInstallers.keySet());
    } else {
        uninstallInstallers = ArrayListMultimap.create();
    }
    if (toInstall.isPresent()) {
        installInstallers = getInstallers(toInstall.get());
        allInstallers.addAll(installInstallers.keySet());
    } else {
        installInstallers = ArrayListMultimap.create();
    }
    // Generates an installation context for the high level Intent.
    IntentInstallationContext installationContext = new IntentInstallationContext(toUninstall.orElse(null), toInstall.orElse(null));
    // Generates different operation context for different installable Intents.
    Map<IntentInstaller, IntentOperationContext> contexts = Maps.newHashMap();
    allInstallers.forEach(installer -> {
        List<Intent> intentsToUninstall = uninstallInstallers.get(installer);
        List<Intent> intentsToInstall = installInstallers.get(installer);
        // Connect context to high level installation context
        IntentOperationContext context = new IntentOperationContext(intentsToUninstall, intentsToInstall, installationContext);
        installationContext.addPendingContext(context);
        contexts.put(installer, context);
    });
    // Apply contexts to installers
    contexts.forEach((installer, context) -> {
        installer.apply(context);
    });
}
Also used : IntentInstaller(org.onosproject.net.intent.IntentInstaller) IntentInstallationContext(org.onosproject.net.intent.IntentInstallationContext) Intent(org.onosproject.net.intent.Intent) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext)

Example 3 with IntentInstallationContext

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

the class InstallCoordinator method failed.

/**
 * Handles failed operation context.
 *
 * @param context the operation context
 */
public void failed(IntentOperationContext context) {
    IntentInstallationContext intentInstallationContext = context.intentInstallationContext();
    intentInstallationContext.addErrorContext(context);
    intentInstallationContext.removePendingContext(context);
    if (intentInstallationContext.isPendingContextsEmpty()) {
        finish(intentInstallationContext);
    }
}
Also used : IntentInstallationContext(org.onosproject.net.intent.IntentInstallationContext)

Example 4 with IntentInstallationContext

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

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

the class FlowObjectiveIntentInstallerTest method testNoAnyIntentToApply.

/**
 * Nothing to uninstall or install.
 */
@Test
public void testNoAnyIntentToApply() {
    IntentData toInstall = null;
    IntentData toUninstall = null;
    IntentOperationContext<FlowObjectiveIntent> operationContext;
    IntentInstallationContext context = new IntentInstallationContext(toUninstall, toInstall);
    operationContext = new IntentOperationContext<>(ImmutableList.of(), ImmutableList.of(), context);
    installer.apply(operationContext);
    IntentOperationContext successContext = intentInstallCoordinator.successContext;
    assertEquals(successContext, operationContext);
}
Also used : IntentData(org.onosproject.net.intent.IntentData) IntentInstallationContext(org.onosproject.net.intent.IntentInstallationContext) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext) 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