Search in sources :

Example 6 with ProtectionEndpointIntent

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

the class TestProtectionEndpointIntentCommand method doExecute.

@Override
protected void doExecute() {
    fingerprint = Optional.ofNullable(fingerprint).orElse(DEFAULT_FINGERPRINT);
    intentService = get(IntentService.class);
    deviceService = get(DeviceService.class);
    DeviceId did = DeviceId.deviceId(deviceIdStr);
    DeviceId peer = DeviceId.deviceId(peerStr);
    ProtectedTransportEndpointDescription description;
    List<TransportEndpointDescription> paths = new ArrayList<>();
    paths.add(TransportEndpointDescription.builder().withOutput(output(did, portNumber1Str, vlan1Str)).build());
    paths.add(TransportEndpointDescription.builder().withOutput(output(did, portNumber2Str, vlan2Str)).build());
    description = ProtectedTransportEndpointDescription.of(paths, peer, fingerprint);
    ProtectionEndpointIntent intent;
    intent = ProtectionEndpointIntent.builder().key(Key.of(fingerprint, appId())).appId(appId()).deviceId(did).description(description).build();
    print("Submitting: %s", intent);
    intentService.submit(intent);
}
Also used : IntentService(org.onosproject.net.intent.IntentService) ProtectedTransportEndpointDescription(org.onosproject.net.behaviour.protection.ProtectedTransportEndpointDescription) TransportEndpointDescription(org.onosproject.net.behaviour.protection.TransportEndpointDescription) ProtectedTransportEndpointDescription(org.onosproject.net.behaviour.protection.ProtectedTransportEndpointDescription) DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService) ArrayList(java.util.ArrayList) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent)

Example 7 with ProtectionEndpointIntent

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

the class ProtectionEndpointIntentInstallerTest method createProtectionIntents.

/**
 * Creates protection endpoint Intents by givent output point.
 *
 * @param output the output point
 * @return the protection endpoint Intents
 */
private List<Intent> createProtectionIntents(ConnectPoint output) {
    FilteredConnectPoint filteredOutput = new FilteredConnectPoint(output);
    TransportEndpointDescription path = TransportEndpointDescription.builder().withOutput(filteredOutput).withEnabled(true).build();
    List<TransportEndpointDescription> paths = ImmutableList.of(path);
    ProtectedTransportEndpointDescription description = ProtectedTransportEndpointDescription.of(paths, CP2.deviceId(), FINGERPRINT);
    ProtectionEndpointIntent intent = ProtectionEndpointIntent.builder().appId(APP_ID).description(description).deviceId(CP1.deviceId()).key(KEY1).resourceGroup(RG1).build();
    return ImmutableList.of(intent);
}
Also used : ProtectedTransportEndpointDescription(org.onosproject.net.behaviour.protection.ProtectedTransportEndpointDescription) TransportEndpointDescription(org.onosproject.net.behaviour.protection.TransportEndpointDescription) ProtectedTransportEndpointDescription(org.onosproject.net.behaviour.protection.ProtectedTransportEndpointDescription) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 8 with ProtectionEndpointIntent

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

the class ProtectionEndpointIntentInstallerTest method testNoAnyIntentToApply.

/**
 * Nothing to uninstall or install.
 */
@Test
public void testNoAnyIntentToApply() {
    IntentData toInstall = null;
    IntentData toUninstall = null;
    IntentOperationContext<ProtectionEndpointIntent> operationContext;
    IntentInstallationContext context = new IntentInstallationContext(toUninstall, toInstall);
    operationContext = new IntentOperationContext<>(ImmutableList.of(), ImmutableList.of(), context);
    installer.apply(operationContext);
    IntentOperationContext successContext = intentInstallCoordinator.successContext;
    assertEquals(successContext, operationContext);
}
Also used : IntentData(org.onosproject.net.intent.IntentData) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent) IntentInstallationContext(org.onosproject.net.intent.IntentInstallationContext) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext) Test(org.junit.Test)

Example 9 with ProtectionEndpointIntent

use of org.onosproject.net.intent.ProtectionEndpointIntent 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)

Example 10 with ProtectionEndpointIntent

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

the class ProtectedIntentMonitor method protectedIntentHighlights.

// =======================================================================
// === Generate messages in JSON object node format
private Highlights protectedIntentHighlights() {
    Highlights highlights = new Highlights();
    TrafficLinkMap linkMap = new TrafficLinkMap();
    IntentService intentService = services.intent();
    if (selectedIntent != null) {
        List<Intent> installables = intentService.getInstallableIntents(selectedIntent.key());
        if (installables != null) {
            ProtectionEndpointIntent ep1 = installables.stream().filter(ProtectionEndpointIntent.class::isInstance).map(ProtectionEndpointIntent.class::cast).findFirst().orElse(null);
            ProtectionEndpointIntent ep2 = installables.stream().filter(ii -> !ii.equals(ep1)).filter(ProtectionEndpointIntent.class::isInstance).map(ProtectionEndpointIntent.class::cast).findFirst().orElse(null);
            if (ep1 == null || ep2 == null) {
                log.warn("Selected Intent {} didn't have 2 protection endpoints", selectedIntent.key());
                stopMonitoring();
                return highlights;
            }
            Set<Link> primary = new LinkedHashSet<>();
            Set<Link> backup = new LinkedHashSet<>();
            Map<Boolean, List<FlowRuleIntent>> transits = installables.stream().filter(FlowRuleIntent.class::isInstance).map(FlowRuleIntent.class::cast).collect(Collectors.groupingBy(this::isPrimary));
            // walk primary
            ConnectPoint primHead = ep1.description().paths().get(0).output().connectPoint();
            ConnectPoint primTail = ep2.description().paths().get(0).output().connectPoint();
            List<FlowRuleIntent> primTransit = transits.getOrDefault(true, ImmutableList.of());
            populateLinks(primary, primHead, primTail, primTransit);
            // walk backup
            ConnectPoint backHead = ep1.description().paths().get(1).output().connectPoint();
            ConnectPoint backTail = ep2.description().paths().get(1).output().connectPoint();
            List<FlowRuleIntent> backTransit = transits.getOrDefault(false, ImmutableList.of());
            populateLinks(backup, backHead, backTail, backTransit);
            // Add packet to optical links
            if (!usingBackup(primary)) {
                primary.addAll(protectedIntentMultiLayer(primHead, primTail));
            }
            backup.addAll(protectedIntentMultiLayer(backHead, backTail));
            boolean isOptical = selectedIntent instanceof OpticalConnectivityIntent;
            // Flavor is swapped so green is primary path.
            if (usingBackup(primary)) {
                // the backup becomes in use so we have a dotted line
                processLinks(linkMap, backup, Flavor.PRIMARY_HIGHLIGHT, isOptical, true, PROTECTED_MOD_BACKUP_SET);
            } else {
                processLinks(linkMap, primary, Flavor.PRIMARY_HIGHLIGHT, isOptical, true, PROTECTED_MOD_PRIMARY_SET);
                processLinks(linkMap, backup, Flavor.SECONDARY_HIGHLIGHT, isOptical, false, PROTECTED_MOD_BACKUP_SET);
            }
            updateHighlights(highlights, primary);
            updateHighlights(highlights, backup);
            colorLinks(highlights, linkMap);
            highlights.subdueAllElse(Highlights.Amount.MINIMALLY);
        } else {
            log.debug("Selected Intent has no installable intents");
        }
    } else {
        log.debug("Selected Intent is null");
    }
    return highlights;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IntentService(org.onosproject.net.intent.IntentService) Highlights(org.onosproject.ui.topo.Highlights) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) Intent(org.onosproject.net.intent.Intent) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent) ConnectPoint(org.onosproject.net.ConnectPoint) TrafficLinkMap(org.onosproject.ui.impl.topo.util.TrafficLinkMap) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) List(java.util.List) Link(org.onosproject.net.Link) TrafficLink(org.onosproject.ui.impl.topo.util.TrafficLink) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Aggregations

ProtectionEndpointIntent (org.onosproject.net.intent.ProtectionEndpointIntent)10 Intent (org.onosproject.net.intent.Intent)6 IntentData (org.onosproject.net.intent.IntentData)6 IntentOperationContext (org.onosproject.net.intent.IntentOperationContext)6 Test (org.junit.Test)5 IntentInstallationContext (org.onosproject.net.intent.IntentInstallationContext)5 WallClockTimestamp (org.onosproject.store.service.WallClockTimestamp)4 ArrayList (java.util.ArrayList)3 ProtectedTransportEndpointDescription (org.onosproject.net.behaviour.protection.ProtectedTransportEndpointDescription)3 TransportEndpointDescription (org.onosproject.net.behaviour.protection.TransportEndpointDescription)3 List (java.util.List)2 DeviceId (org.onosproject.net.DeviceId)2 IntentService (org.onosproject.net.intent.IntentService)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1