Search in sources :

Example 1 with IntentData

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

the class VirtualNetworkIntentManager method withdraw.

@Override
public void withdraw(Intent intent) {
    checkNotNull(intent, INTENT_NULL);
    IntentData data = IntentData.withdraw(intent);
    intentStore.addPending(networkId, data);
}
Also used : IntentData(org.onosproject.net.intent.IntentData)

Example 2 with IntentData

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

the class VirtualNetworkIntentManager method createInitialPhase.

private VirtualIntentProcessPhase createInitialPhase(IntentData data) {
    IntentData pending = intentStore.getPendingData(networkId, 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 VirtualIntentSkipped.getPhase();
    }
    IntentData current = intentStore.getIntentData(networkId, data.key());
    return newInitialPhase(networkId, processor, data, current);
}
Also used : IntentData(org.onosproject.net.intent.IntentData)

Example 3 with IntentData

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

the class VirtualIntentPurgeRequest method shouldAcceptPurge.

private boolean shouldAcceptPurge() {
    if (!stored.isPresent()) {
        log.info("Purge for intent {}, but intent is not present", data.key());
        return true;
    }
    IntentData storedData = stored.get();
    if (storedData.state() == IntentState.WITHDRAWN || storedData.state() == IntentState.FAILED) {
        return true;
    }
    log.info("Purge for intent {} is rejected because intent state is {}", data.key(), storedData.state());
    return false;
}
Also used : IntentData(org.onosproject.net.intent.IntentData)

Example 4 with IntentData

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

the class VirtualIntentInstallCoordinator 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 = IntentData.compiled(installData, installData.installables());
            installData.setState(INSTALLED);
            intentStore.write(networkId, installData);
        } else if (toUninstall.isPresent()) {
            IntentData uninstallData = toUninstall.get();
            uninstallData = IntentData.compiled(uninstallData, Collections.emptyList());
            log.debug("Completed withdrawing: {}", uninstallData.key());
            switch(uninstallData.request()) {
                case INSTALL_REQ:
                    log.warn("{} was requested to withdraw during installation?", uninstallData.intent());
                    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(networkId, uninstallData);
        }
    } else {
        // if toInstall was cause of error, then recompile (manage/increment counter, when exceeded -> CORRUPT)
        if (toInstall.isPresent()) {
            IntentData installData = toInstall.get();
            installData.setState(CORRUPT);
            installData.incrementErrorCount();
            intentStore.write(networkId, installData);
        }
        // if toUninstall was cause of error, then CORRUPT (another job will clean this up)
        if (toUninstall.isPresent()) {
            IntentData uninstallData = toUninstall.get();
            uninstallData.setState(CORRUPT);
            uninstallData.incrementErrorCount();
            intentStore.write(networkId, uninstallData);
        }
    }
}
Also used : IntentData(org.onosproject.net.intent.IntentData) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext)

Example 5 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