Search in sources :

Example 11 with IntentData

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

the class IntentManager method createInitialPhase.

private IntentProcessPhase createInitialPhase(IntentData data) {
    IntentData pending = store.getPendingData(data.key());
    if (pending == null || pending.version().isNewerThan(data.version())) {
        /*
                If the pending map is null, then this intent was compiled by a
                previous batch iteration, so we can skip it.
                If the pending map has a newer request, it will get compiled as
                part of the next batch, so we can skip it.
             */
        return Skipped.getPhase();
    }
    IntentData current = store.getIntentData(data.key());
    return newInitialPhase(processor, data, current);
}
Also used : IntentData(org.onosproject.net.intent.IntentData)

Example 12 with IntentData

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

the class IntentManager method submit.

@Override
public void submit(Intent intent) {
    checkPermission(INTENT_WRITE);
    checkNotNull(intent, INTENT_NULL);
    IntentData data = IntentData.submit(intent);
    store.addPending(data);
}
Also used : IntentData(org.onosproject.net.intent.IntentData)

Example 13 with IntentData

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

the class IntentManager method purge.

@Override
public void purge(Intent intent) {
    checkPermission(INTENT_WRITE);
    checkNotNull(intent, INTENT_NULL);
    IntentData data = IntentData.purge(intent);
    store.addPending(data);
    // remove associated group if there is one
    if (intent instanceof PointToPointIntent) {
        PointToPointIntent pointIntent = (PointToPointIntent) intent;
        DeviceId deviceId = pointIntent.filteredIngressPoint().connectPoint().deviceId();
        GroupKey groupKey = PointToPointIntentCompiler.makeGroupKey(intent.id());
        groupService.removeGroup(deviceId, groupKey, intent.appId());
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) IntentData(org.onosproject.net.intent.IntentData) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) GroupKey(org.onosproject.net.group.GroupKey)

Example 14 with IntentData

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

the class InstallCoordinator method finish.

/**
 * Completed the installation context and update the Intent store.
 *
 * @param intentInstallationContext the installation context
 */
private void finish(IntentInstallationContext intentInstallationContext) {
    Set<IntentOperationContext> errCtxs = intentInstallationContext.errorContexts();
    Optional<IntentData> toUninstall = intentInstallationContext.toUninstall();
    Optional<IntentData> toInstall = intentInstallationContext.toInstall();
    // Intent install success
    if (errCtxs == null || errCtxs.isEmpty()) {
        if (toInstall.isPresent()) {
            IntentData installData = toInstall.get();
            log.debug("Completed installing: {}:{}", installData.key(), installData.intent().id());
            installData = IntentData.compiled(installData, installData.installables());
            installData.setState(INSTALLED);
            intentStore.write(installData);
        } else if (toUninstall.isPresent()) {
            IntentData uninstallData = toUninstall.get();
            uninstallData = IntentData.compiled(uninstallData, Collections.emptyList());
            log.debug("Completed withdrawing: {}:{}", uninstallData.key(), uninstallData.intent().id());
            switch(uninstallData.request()) {
                case INSTALL_REQ:
                    // INSTALLED intent was damaged & clean up is now complete
                    uninstallData.setState(FAILED);
                    break;
                case WITHDRAW_REQ:
                default:
                    // TODO "default" case should not happen
                    uninstallData.setState(WITHDRAWN);
                    break;
            }
            // Intent has been withdrawn; we can clear the installables
            intentStore.write(uninstallData);
        }
    } else {
        // if toInstall was cause of error, then recompile (manage/increment counter, when exceeded -> CORRUPT)
        if (toInstall.isPresent()) {
            IntentData installData = toInstall.get();
            intentStore.write(IntentData.corrupt(installData));
        }
        // if toUninstall was cause of error, then CORRUPT (another job will clean this up)
        if (toUninstall.isPresent()) {
            IntentData uninstallData = toUninstall.get();
            intentStore.write(IntentData.corrupt(uninstallData));
        }
    }
}
Also used : IntentData(org.onosproject.net.intent.IntentData) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext)

Example 15 with IntentData

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

the class SimpleVirtualIntentStore method write.

@Override
public void write(NetworkId networkId, IntentData newData) {
    checkNotNull(newData);
    synchronized (this) {
        // TODO this could be refactored/cleaned up
        IntentData currentData = getCurrentMap(networkId).get(newData.key());
        IntentData pendingData = getPendingMap(networkId).get(newData.key());
        if (IntentData.isUpdateAcceptable(currentData, newData)) {
            if (pendingData != null) {
                if (pendingData.state() == PURGE_REQ) {
                    getCurrentMap(networkId).remove(newData.key(), newData);
                } else {
                    getCurrentMap(networkId).put(newData.key(), IntentData.copy(newData));
                }
                if (pendingData.version().compareTo(newData.version()) <= 0) {
                    // pendingData version is less than or equal to newData's
                    // Note: a new update for this key could be pending (it's version will be greater)
                    getPendingMap(networkId).remove(newData.key());
                }
            }
            IntentEvent.getEvent(newData).ifPresent(e -> notifyDelegate(networkId, e));
        }
    }
}
Also used : IntentData(org.onosproject.net.intent.IntentData)

Aggregations

IntentData (org.onosproject.net.intent.IntentData)79 Test (org.junit.Test)49 Intent (org.onosproject.net.intent.Intent)49 WallClockTimestamp (org.onosproject.store.service.WallClockTimestamp)34 IntentOperationContext (org.onosproject.net.intent.IntentOperationContext)33 IntentInstallationContext (org.onosproject.net.intent.IntentInstallationContext)30 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)21 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)16 IntentEvent (org.onosproject.net.intent.IntentEvent)15 IntentStoreDelegate (org.onosproject.net.intent.IntentStoreDelegate)15 PathIntent (org.onosproject.net.intent.PathIntent)13 MockIntent (org.onosproject.net.intent.IntentTestsMocks.MockIntent)12 Timestamp (org.onosproject.store.Timestamp)11 Collection (java.util.Collection)10 List (java.util.List)8 Collectors (java.util.stream.Collectors)7 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)7 FlowRule (org.onosproject.net.flow.FlowRule)7 Set (java.util.Set)6 DeviceId (org.onosproject.net.DeviceId)6