Search in sources :

Example 6 with IntentData

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

the class IntentCleanupTestMock method installingPoll.

/**
 * Trigger resubmit of intent in INSTALLING for too long.
 */
@Test
@Ignore("The implementation is dependent on the SimpleStore")
public void installingPoll() {
    IntentStoreDelegate mockDelegate = new IntentStoreDelegate() {

        @Override
        public void process(IntentData intentData) {
            intentData.setState(INSTALLING);
            store.write(intentData);
        }

        @Override
        public void notify(IntentEvent event) {
            cleanup.event(event);
        }
    };
    store.setDelegate(mockDelegate);
    Intent intent = new MockIntent(1L);
    Timestamp version = new SystemClockTimestamp(1L);
    IntentData data = new IntentData(intent, INSTALL_REQ, version);
    store.addPending(data);
    service.addPending(data);
    expectLastCall().once();
    replay(service);
    cleanup.run();
    verify(service);
    reset(service);
}
Also used : IntentStoreDelegate(org.onosproject.net.intent.IntentStoreDelegate) SystemClockTimestamp(org.onosproject.store.trivial.SystemClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) Intent(org.onosproject.net.intent.Intent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) SystemClockTimestamp(org.onosproject.store.trivial.SystemClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) IntentEvent(org.onosproject.net.intent.IntentEvent) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 7 with IntentData

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

the class IntentCleanupTestMock method corruptEvent.

/**
 * Verify resubmit in response to CORRUPT event.
 */
@Test
public void corruptEvent() {
    IntentStoreDelegate mockDelegate = new IntentStoreDelegate() {

        @Override
        public void process(IntentData intentData) {
            intentData.setState(CORRUPT);
            store.write(intentData);
        }

        @Override
        public void notify(IntentEvent event) {
            cleanup.event(event);
        }
    };
    store.setDelegate(mockDelegate);
    Intent intent = new MockIntent(1L);
    IntentData data = new IntentData(intent, INSTALL_REQ, null);
    service.submit(intent);
    expectLastCall().once();
    replay(service);
    store.addPending(data);
    verify(service);
    reset(service);
}
Also used : IntentStoreDelegate(org.onosproject.net.intent.IntentStoreDelegate) IntentData(org.onosproject.net.intent.IntentData) Intent(org.onosproject.net.intent.Intent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) IntentEvent(org.onosproject.net.intent.IntentEvent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 8 with IntentData

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

the class GossipIntentStoreTest method testPending.

/**
 * Tests the operation of the APIs for the pending map.
 */
@Test
public void testPending() {
    // crete a new intent and add it as pending
    Intent intent = builder1.build();
    IntentData installed = new IntentData(intent, IntentState.INSTALLED, new IntentTestsMocks.MockTimestamp(11));
    intentStore.addPending(installed);
    // check that the getPending() API returns the new pending intent
    Iterable<Intent> pendingIntentIteratorAll = intentStore.getPending();
    assertThat(pendingIntentIteratorAll.iterator().hasNext(), is(true));
    pendingIntentIteratorAll.forEach(data -> assertThat(data, is(intent)));
    // check that the getPendingData() API returns the IntentData for the
    // new pending intent
    Iterable<IntentData> pendingDataIteratorAll = intentStore.getPendingData();
    assertThat(pendingDataIteratorAll.iterator().hasNext(), is(true));
    pendingDataIteratorAll.forEach(data -> assertThat(data, is(installed)));
    // check that the new pending intent is returned by the getPendingData()
    // API when a time stamp is provided
    Iterable<IntentData> pendingDataIteratorSelected = intentStore.getPendingData(true, 10L);
    assertThat(pendingDataIteratorSelected.iterator().hasNext(), is(true));
    pendingDataIteratorSelected.forEach(data -> assertThat(data, is(installed)));
    // check that the new pending intent is returned by the getPendingData()
    // API when a time stamp is provided
    Iterable<IntentData> pendingDataIteratorAllFromTimestamp = intentStore.getPendingData(false, 0L);
    assertThat(pendingDataIteratorAllFromTimestamp.iterator().hasNext(), is(true));
    pendingDataIteratorSelected.forEach(data -> assertThat(data, is(installed)));
}
Also used : IntentData(org.onosproject.net.intent.IntentData) 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 9 with IntentData

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

the class DomainIntentInstaller method apply.

@Override
public void apply(IntentOperationContext<DomainIntent> context) {
    Optional<IntentData> toUninstall = context.toUninstall();
    Optional<IntentData> toInstall = context.toInstall();
    List<DomainIntent> uninstallIntents = context.intentsToUninstall();
    List<DomainIntent> 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()));
    }
    // Generate domain Intent operations
    DomainIntentOperations.Builder builder = DomainIntentOperations.builder();
    DomainIntentOperationsContext domainOperationsContext;
    uninstallIntents.forEach(builder::remove);
    installIntents.forEach(builder::add);
    domainOperationsContext = new DomainIntentOperationsContext() {

        @Override
        public void onSuccess(DomainIntentOperations idops) {
            intentInstallCoordinator.intentInstallSuccess(context);
        }

        @Override
        public void onError(DomainIntentOperations idos) {
            intentInstallCoordinator.intentInstallFailed(context);
        }
    };
    log.debug("submitting domain intent {} -> {}", toUninstall.map(x -> x.key().toString()).orElse("<empty>"), toInstall.map(x -> x.key().toString()).orElse("<empty>"));
    // Submit domain Inten operations with domain context
    domainIntentService.sumbit(builder.build(domainOperationsContext));
}
Also used : DomainIntentOperationsContext(org.onosproject.net.domain.DomainIntentOperationsContext) DomainIntentOperations(org.onosproject.net.domain.DomainIntentOperations) IntentData(org.onosproject.net.intent.IntentData) DomainIntent(org.onosproject.net.domain.DomainIntent)

Example 10 with IntentData

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

the class PurgeRequest 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)

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