Search in sources :

Example 31 with WallClockTimestamp

use of org.onosproject.store.service.WallClockTimestamp in project onos by opennetworkinglab.

the class InstallCoordinatorTest method testUninstallIntent.

/**
 * Uninstalls test Intents.
 */
@Test
public void testUninstallIntent() {
    IntentData toUninstall = new IntentData(createTestIntent(), IntentState.WITHDRAWING, new WallClockTimestamp());
    List<Intent> intents = Lists.newArrayList();
    IntStream.range(0, 10).forEach(val -> {
        intents.add(new TestInstallableIntent(val));
    });
    toUninstall = IntentData.compiled(toUninstall, intents);
    installCoordinator.installIntents(Optional.of(toUninstall), Optional.empty());
    Intent toUninstallIntent = toUninstall.intent();
    TestTools.assertAfter(INSTALL_DELAY, INSTALL_DURATION, () -> {
        IntentData newData = intentStore.newData;
        assertEquals(toUninstallIntent, newData.intent());
        assertEquals(IntentState.WITHDRAWN, newData.state());
        assertEquals(ImmutableList.of(), newData.installables());
    });
}
Also used : TestInstallableIntent(org.onosproject.net.intent.TestInstallableIntent) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) TestInstallableIntent(org.onosproject.net.intent.TestInstallableIntent) Intent(org.onosproject.net.intent.Intent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 32 with WallClockTimestamp

use of org.onosproject.store.service.WallClockTimestamp in project onos by opennetworkinglab.

the class InstallCoordinatorTest method testInstallIntent.

/**
 * Installs test Intents.
 */
@Test
public void testInstallIntent() {
    IntentData toInstall = new IntentData(createTestIntent(), IntentState.INSTALLING, new WallClockTimestamp());
    List<Intent> intents = Lists.newArrayList();
    IntStream.range(0, 10).forEach(val -> {
        intents.add(new TestInstallableIntent(val));
    });
    toInstall = IntentData.compiled(toInstall, intents);
    installCoordinator.installIntents(Optional.empty(), Optional.of(toInstall));
    Intent toInstallIntent = toInstall.intent();
    TestTools.assertAfter(INSTALL_DELAY, INSTALL_DURATION, () -> {
        IntentData newData = intentStore.newData;
        assertEquals(toInstallIntent, newData.intent());
        assertEquals(IntentState.INSTALLED, newData.state());
        assertEquals(intents, newData.installables());
    });
}
Also used : TestInstallableIntent(org.onosproject.net.intent.TestInstallableIntent) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) TestInstallableIntent(org.onosproject.net.intent.TestInstallableIntent) Intent(org.onosproject.net.intent.Intent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 33 with WallClockTimestamp

use of org.onosproject.store.service.WallClockTimestamp in project onos by opennetworkinglab.

the class IntentCleanup method cleanup.

/**
 * Iterates through corrupt, failed and pending intents and
 * re-submit/withdraw appropriately.
 */
private void cleanup() {
    int corruptCount = 0, failedCount = 0, stuckCount = 0, pendingCount = 0, skipped = 0;
    // will add items to the pending map.
    for (IntentData intentData : store.getPendingData(true, periodMs)) {
        log.debug("Resubmit Pending Intent: key {}, state {}, request {}", intentData.key(), intentData.state(), intentData.request());
        resubmitPendingRequest(intentData);
        pendingCount++;
    }
    for (IntentData intentData : store.getIntentData(true, periodMs)) {
        IntentData pendingIntentData = store.getPendingData(intentData.key());
        if (pendingIntentData != null) {
            continue;
        }
        switch(intentData.state()) {
            case FAILED:
                log.debug("Resubmit Failed Intent: key {}, state {}, request {}", intentData.key(), intentData.state(), intentData.request());
                resubmitCorrupt(intentData, false);
                failedCount++;
                break;
            case CORRUPT:
                log.debug("Resubmit Corrupt Intent: key {}, state {}, request {}", intentData.key(), intentData.state(), intentData.request());
                resubmitCorrupt(intentData, false);
                corruptCount++;
                break;
            // FALLTHROUGH
            case INSTALLING:
            case WITHDRAWING:
                // Instances can have different clocks and potentially we can have problems
                // An Intent can be submitted again before the real period of the stuck intents
                final WallClockTimestamp time = new WallClockTimestamp(System.currentTimeMillis() - periodMsForStuck);
                if (intentData.version().isOlderThan(time)) {
                    resubmitPendingRequest(intentData);
                    stuckCount++;
                } else {
                    skipped++;
                }
                break;
            default:
                // NOOP
                break;
        }
    }
    if (corruptCount + failedCount + stuckCount + pendingCount > 0) {
        log.debug("Intent cleanup ran and resubmitted {} corrupt, {} failed, {} stuck, and {} pending intents", corruptCount, failedCount, stuckCount, pendingCount);
    }
    if (skipped > 0) {
        log.debug("Intent cleanup skipped {} intents", skipped);
    }
}
Also used : WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) IntentData(org.onosproject.net.intent.IntentData)

Example 34 with WallClockTimestamp

use of org.onosproject.store.service.WallClockTimestamp in project onos by opennetworkinglab.

the class DistributedMasterElectionIdStore method activate.

@Activate
public void activate() {
    listeners = Maps.newConcurrentMap();
    masterElectionIds = storageService.<Pair<DeviceId, Long>, BigInteger>eventuallyConsistentMapBuilder().withName("p4runtime-master-election-ids").withSerializer(SERIALIZER).withTimestampProvider((k, v) -> new WallClockTimestamp()).build();
    masterElectionIds.addListener(mapListener);
    log.info("Started");
}
Also used : WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) DeviceId(org.onosproject.net.DeviceId) Activate(org.osgi.service.component.annotations.Activate)

Example 35 with WallClockTimestamp

use of org.onosproject.store.service.WallClockTimestamp in project onos by opennetworkinglab.

the class DomainIntentInstallerTest method testUninstallAndInstall.

/**
 * Do both uninstall and install domain Intents.
 */
@Test
public void testUninstallAndInstall() {
    List<Intent> intentsToUninstall = createDomainIntents();
    List<Intent> intentsToInstall = createAnotherDomainIntents();
    IntentData toUninstall = new IntentData(createP2PIntent(), IntentState.INSTALLED, new WallClockTimestamp());
    toUninstall = IntentData.compiled(toUninstall, intentsToUninstall);
    IntentData toInstall = new IntentData(createP2PIntent(), IntentState.INSTALLING, new WallClockTimestamp());
    toInstall = IntentData.compiled(toInstall, intentsToInstall);
    IntentOperationContext<DomainIntent> operationContext;
    IntentInstallationContext context = new IntentInstallationContext(toUninstall, toInstall);
    operationContext = new IntentOperationContext(intentsToUninstall, intentsToInstall, context);
    installer.apply(operationContext);
    assertEquals(intentInstallCoordinator.successContext, operationContext);
}
Also used : WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) IntentInstallationContext(org.onosproject.net.intent.IntentInstallationContext) DomainPointToPointIntent(org.onosproject.net.domain.DomainPointToPointIntent) DomainIntent(org.onosproject.net.domain.DomainIntent) Intent(org.onosproject.net.intent.Intent) DomainIntent(org.onosproject.net.domain.DomainIntent) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext) Test(org.junit.Test)

Aggregations

WallClockTimestamp (org.onosproject.store.service.WallClockTimestamp)48 IntentData (org.onosproject.net.intent.IntentData)34 Intent (org.onosproject.net.intent.Intent)33 Test (org.junit.Test)28 IntentInstallationContext (org.onosproject.net.intent.IntentInstallationContext)26 IntentOperationContext (org.onosproject.net.intent.IntentOperationContext)26 Activate (org.osgi.service.component.annotations.Activate)15 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)13 PathIntent (org.onosproject.net.intent.PathIntent)13 Collection (java.util.Collection)8 KryoNamespace (org.onlab.util.KryoNamespace)8 ImmutableList (com.google.common.collect.ImmutableList)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 ComponentConfigService (org.onosproject.cfg.ComponentConfigService)5 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)5 FlowRule (org.onosproject.net.flow.FlowRule)5 IntentState (org.onosproject.net.intent.IntentState)5 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)4 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)4