Search in sources :

Example 76 with IntentData

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

the class GossipIntentStoreTest method testAddAndWithdrawIntent.

/**
 * Tests adding and withdrawing an Intent.
 */
@Test
public void testAddAndWithdrawIntent() {
    // build and install one intent
    Intent intent = builder1.build();
    IntentData installed = new IntentData(intent, IntentState.INSTALLED, new IntentTestsMocks.MockTimestamp(12));
    intentStore.write(installed);
    // check that the intent count includes the new one
    assertThat(intentStore.getIntentCount(), is(1L));
    // check that the getIntents() API returns the new intent
    intentStore.getIntents().forEach(item -> assertThat(item, is(intent)));
    // check that the getInstallableIntents() API returns the new intent
    intentStore.getInstallableIntents(intent.key()).forEach(item -> assertThat(item, is(intent)));
    // check that the getIntent() API can find the new intent
    Intent queried = intentStore.getIntent(intent.key());
    assertThat(queried, is(intent));
    // check that the state of the new intent is correct
    IntentState state = intentStore.getIntentState(intent.key());
    assertThat(state, is(IntentState.INSTALLED));
    // check that the getIntentData() API returns the proper value for the
    // new intent
    IntentData dataByQuery = intentStore.getIntentData(intent.key());
    assertThat(dataByQuery, is(installed));
    // check that the getIntentData() API returns the new intent when given
    // a time stamp to look for
    Iterable<IntentData> dataIteratorByTime = intentStore.getIntentData(true, 10L);
    assertThat(dataIteratorByTime.iterator().hasNext(), is(true));
    dataIteratorByTime.forEach(data -> assertThat(data, is(installed)));
    // check that the getIntentData() API returns the new intent when asked to
    // find all intents
    Iterable<IntentData> dataIteratorAll = intentStore.getIntentData(false, 0L);
    assertThat(dataIteratorAll.iterator().hasNext(), is(true));
    dataIteratorAll.forEach(data -> assertThat(data, is(installed)));
    // now purge the intent that was created
    IntentData purgeAssigned = IntentData.assign(IntentData.purge(intent), new IntentTestsMocks.MockTimestamp(12), new NodeId("node-id"));
    intentStore.write(purgeAssigned);
    // check that no intents are left
    assertThat(intentStore.getIntentCount(), is(0L));
    // check that a getIntent() operation on the key of the purged intent
    // returns null
    Intent queriedAfterWithdrawal = intentStore.getIntent(intent.key());
    assertThat(queriedAfterWithdrawal, nullValue());
}
Also used : IntentState(org.onosproject.net.intent.IntentState) IntentData(org.onosproject.net.intent.IntentData) NodeId(org.onosproject.cluster.NodeId) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) Intent(org.onosproject.net.intent.Intent) IntentTestsMocks(org.onosproject.net.intent.IntentTestsMocks) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 77 with IntentData

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

the class ObjectiveTracker method trackIntent.

@Override
public void trackIntent(IntentData intentData) {
    // NOTE: This will be called for intents that are being added to the store
    // locally (i.e. every intent update)
    Key key = intentData.key();
    Intent intent = intentData.intent();
    boolean isLocal = intentService.isLocal(key);
    boolean isInstalled = intentData.state() == INSTALLING || intentData.state() == INSTALLED;
    List<Intent> installables = intentData.installables();
    if (log.isTraceEnabled()) {
        log.trace("intent {}, old: {}, new: {}, installableCount: {}, resourceCount: {}", key, intentsByDevice.values().contains(key), isLocal && isInstalled, installables.size(), intent.resources().size() + installables.stream().mapToLong(i -> i.resources().size()).sum());
    }
    if (isNullOrEmpty(installables) && intentData.state() == INSTALLED) {
        log.warn("Intent {} is INSTALLED with no installables", key);
    }
    // then when installing and when installed)
    if (isLocal && isInstalled) {
        addTrackedResources(key, intent.resources());
        for (Intent installable : installables) {
            addTrackedResources(key, installable.resources());
        }
    // FIXME check all resources against current topo service(s); recompile if necessary
    } else {
        removeTrackedResources(key, intent.resources());
        for (Intent installable : installables) {
            removeTrackedResources(key, installable.resources());
        }
    }
}
Also used : TopologyChangeDelegate(org.onosproject.net.intent.TopologyChangeDelegate) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) ElementId(org.onosproject.net.ElementId) TopologyService(org.onosproject.net.topology.TopologyService) Link(org.onosproject.net.Link) ResourceService(org.onosproject.net.resource.ResourceService) Tools.isNullOrEmpty(org.onlab.util.Tools.isNullOrEmpty) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) LINK_REMOVED(org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED) HashMultimap(com.google.common.collect.HashMultimap) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) INSTALLING(org.onosproject.net.intent.IntentState.INSTALLING) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) Event(org.onosproject.event.Event) LinkKey(org.onosproject.net.LinkKey) TopologyEvent(org.onosproject.net.topology.TopologyEvent) ImmutableSet(com.google.common.collect.ImmutableSet) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) Set(java.util.Set) NetworkResource(org.onosproject.net.NetworkResource) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) ReferencePolicy(org.osgi.service.component.annotations.ReferencePolicy) INSTALLED(org.onosproject.net.intent.IntentState.INSTALLED) Key(org.onosproject.net.intent.Key) List(java.util.List) DeviceEvent(org.onosproject.net.device.DeviceEvent) DeviceId(org.onosproject.net.DeviceId) LinkEvent(org.onosproject.net.link.LinkEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WorkPartitionEvent(org.onosproject.net.intent.WorkPartitionEvent) HostListener(org.onosproject.net.host.HostListener) HostService(org.onosproject.net.host.HostService) IntentData(org.onosproject.net.intent.IntentData) HashSet(java.util.HashSet) Component(org.osgi.service.component.annotations.Component) IntentService(org.onosproject.net.intent.IntentService) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Intent(org.onosproject.net.intent.Intent) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) LinkKey.linkKey(org.onosproject.net.LinkKey.linkKey) HostId(org.onosproject.net.HostId) ExecutorService(java.util.concurrent.ExecutorService) Multimaps.synchronizedSetMultimap(com.google.common.collect.Multimaps.synchronizedSetMultimap) LINK_UPDATED(org.onosproject.net.link.LinkEvent.Type.LINK_UPDATED) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) ResourceEvent(org.onosproject.net.resource.ResourceEvent) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) SetMultimap(com.google.common.collect.SetMultimap) ObjectiveTrackerService(org.onosproject.net.intent.ObjectiveTrackerService) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) ResourceListener(org.onosproject.net.resource.ResourceListener) WorkPartitionEventListener(org.onosproject.net.intent.WorkPartitionEventListener) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) TopologyListener(org.onosproject.net.topology.TopologyListener) Intent(org.onosproject.net.intent.Intent) LinkKey(org.onosproject.net.LinkKey) Key(org.onosproject.net.intent.Key) LinkKey.linkKey(org.onosproject.net.LinkKey.linkKey)

Example 78 with IntentData

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

the class FlowObjectiveIntentInstaller method apply.

@Override
public void apply(IntentOperationContext<FlowObjectiveIntent> intentOperationContext) {
    Objects.requireNonNull(intentOperationContext);
    Optional<IntentData> toUninstall = intentOperationContext.toUninstall();
    Optional<IntentData> toInstall = intentOperationContext.toInstall();
    List<FlowObjectiveIntent> uninstallIntents = intentOperationContext.intentsToUninstall();
    List<FlowObjectiveIntent> installIntents = intentOperationContext.intentsToInstall();
    if (!toInstall.isPresent() && !toUninstall.isPresent()) {
        intentInstallCoordinator.intentInstallSuccess(intentOperationContext);
        return;
    }
    if (toUninstall.isPresent()) {
        IntentData intentData = toUninstall.get();
        trackerService.removeTrackedResources(intentData.key(), intentData.intent().resources());
        uninstallIntents.forEach(installable -> trackerService.removeTrackedResources(intentData.intent().key(), installable.resources()));
    }
    if (toInstall.isPresent()) {
        IntentData intentData = toInstall.get();
        trackerService.addTrackedResources(intentData.key(), intentData.intent().resources());
        installIntents.forEach(installable -> trackerService.addTrackedResources(intentData.key(), installable.resources()));
    }
    FlowObjectiveIntentInstallationContext intentInstallationContext = new FlowObjectiveIntentInstallationContext(intentOperationContext);
    uninstallIntents.stream().map(intent -> buildObjectiveContexts(intent, REMOVE)).flatMap(Collection::stream).forEach(context -> {
        context.intentInstallationContext(intentInstallationContext);
        intentInstallationContext.addContext(context);
        intentInstallationContext.addPendingContext(context);
    });
    installIntents.stream().map(intent -> buildObjectiveContexts(intent, ADD)).flatMap(Collection::stream).forEach(context -> {
        context.intentInstallationContext(intentInstallationContext);
        intentInstallationContext.addContext(context);
        intentInstallationContext.addNextPendingContext(context);
    });
    intentInstallationContext.apply();
}
Also used : IntentData(org.onosproject.net.intent.IntentData) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent)

Example 79 with IntentData

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

the class ProtectionEndpointIntentInstaller method apply.

@Override
public void apply(IntentOperationContext<ProtectionEndpointIntent> context) {
    Optional<IntentData> toUninstall = context.toUninstall();
    Optional<IntentData> toInstall = context.toInstall();
    List<ProtectionEndpointIntent> uninstallIntents = context.intentsToUninstall();
    List<ProtectionEndpointIntent> installIntents = context.intentsToInstall();
    if (!toInstall.isPresent() && !toUninstall.isPresent()) {
        intentInstallCoordinator.intentInstallSuccess(context);
        return;
    }
    if (toUninstall.isPresent()) {
        IntentData intentData = toUninstall.get();
        trackerService.removeTrackedResources(intentData.key(), intentData.intent().resources());
        uninstallIntents.forEach(installable -> trackerService.removeTrackedResources(intentData.intent().key(), installable.resources()));
    }
    if (toInstall.isPresent()) {
        IntentData intentData = toInstall.get();
        trackerService.addTrackedResources(intentData.key(), intentData.intent().resources());
        installIntents.forEach(installable -> trackerService.addTrackedResources(intentData.key(), installable.resources()));
    }
    List<Stage> stages = new ArrayList<>();
    stages.add(new Stage(uninstallIntents.stream().map(i -> Pair.of(i, REMOVE)).collect(Collectors.toList())));
    stages.add(new Stage(installIntents.stream().map(i -> Pair.of(i, ADD)).collect(Collectors.toList())));
    for (Stage stage : stages) {
        log.debug("applying Stage {}", stage);
        try {
            // wait for stage completion
            stage.apply();
            stage.listeners().forEach(networkConfigService::removeListener);
        } catch (IntentException e) {
            log.error("Stage {} failed, reason: {}", stage, e.toString());
            intentInstallCoordinator.intentInstallFailed(context);
            return;
        }
    }
    // All stage success
    intentInstallCoordinator.intentInstallSuccess(context);
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) IntentData(org.onosproject.net.intent.IntentData) ArrayList(java.util.ArrayList) ADD(org.onosproject.net.intent.IntentInstaller.Direction.ADD) Component(org.osgi.service.component.annotations.Component) Pair(org.apache.commons.lang3.tuple.Pair) Activate(org.osgi.service.component.annotations.Activate) ProtectedTransportEndpointDescription(org.onosproject.net.behaviour.protection.ProtectedTransportEndpointDescription) IntentInstaller(org.onosproject.net.intent.IntentInstaller) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext) ProtectionConfig(org.onosproject.net.behaviour.protection.ProtectionConfig) IntentManager(org.onosproject.net.intent.impl.IntentManager) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) ObjectiveTrackerService(org.onosproject.net.intent.ObjectiveTrackerService) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) IntentException(org.onosproject.net.intent.IntentException) List(java.util.List) REMOVE(org.onosproject.net.intent.IntentInstaller.Direction.REMOVE) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) Reference(org.osgi.service.component.annotations.Reference) DeviceId(org.onosproject.net.DeviceId) IntentInstallCoordinator(org.onosproject.net.intent.IntentInstallCoordinator) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) Type(org.onosproject.net.config.NetworkConfigEvent.Type) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent) IntentException(org.onosproject.net.intent.IntentException) IntentData(org.onosproject.net.intent.IntentData) ArrayList(java.util.ArrayList) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent)

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