Search in sources :

Example 16 with IntentService

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

the class IntentRemoveCommand method doExecute.

@Override
protected void doExecute() {
    IntentService intentService = get(IntentService.class);
    removeIntent(intentService.getIntents(), applicationIdString, keyString, purgeAfterRemove, sync);
}
Also used : IntentService(org.onosproject.net.intent.IntentService)

Example 17 with IntentService

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

the class IntentRemoveCommand method removeIntent.

/**
 * Removes the intents passed as argument, assuming these
 * belong to the application's ID provided (if any) and
 * contain a key string.
 *
 * If an application ID is provided, it will be used to further
 * filter the intents to be removed.
 *
 * @param intents list of intents to remove
 * @param applicationIdString application ID to filter intents
 * @param keyString string to filter intents
 * @param purgeAfterRemove states whether the intents should be also purged
 * @param sync states whether the cli should wait for the operation to finish
 *             before returning
 */
private void removeIntent(Iterable<Intent> intents, String applicationIdString, String keyString, boolean purgeAfterRemove, boolean sync) {
    IntentService intentService = get(IntentService.class);
    CoreService coreService = get(CoreService.class);
    this.applicationIdString = applicationIdString;
    this.keyString = keyString;
    this.purgeAfterRemove = purgeAfterRemove;
    this.sync = sync;
    if (purgeAfterRemove || sync) {
        print("Using \"sync\" to remove/purge intents - this may take a while...");
        print("Check \"summary\" to see remove/purge progress.");
    }
    ApplicationId appId = appId();
    if (!isNullOrEmpty(applicationIdString)) {
        appId = coreService.getAppId(applicationIdString);
        if (appId == null) {
            print("Cannot find application Id %s", applicationIdString);
            return;
        }
    }
    if (isNullOrEmpty(keyString)) {
        removeIntentsByAppId(intentService, intents, appId);
    } else {
        final Key key;
        if (keyString.startsWith("0x")) {
            // The intent uses a LongKey
            keyString = keyString.replaceFirst("0x", "");
            key = Key.of(new BigInteger(keyString, 16).longValue(), appId);
        } else {
            // The intent uses a StringKey
            key = Key.of(keyString, appId);
        }
        Intent intent = intentService.getIntent(key);
        if (intent != null) {
            removeIntent(intentService, intent);
        }
    }
}
Also used : IntentService(org.onosproject.net.intent.IntentService) CoreService(org.onosproject.core.CoreService) BigInteger(java.math.BigInteger) Intent(org.onosproject.net.intent.Intent) ApplicationId(org.onosproject.core.ApplicationId) Key(org.onosproject.net.intent.Key)

Example 18 with IntentService

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

Example 19 with IntentService

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

the class ApplicationIdWithIntentNameCompleter method complete.

@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    // Fetch our service and feed it's offerings to the string completer
    IntentService service = AbstractShellCommand.get(IntentService.class);
    SortedSet<String> strings = delegate.getStrings();
    service.getIntents().forEach(intent -> strings.add(intent.appId().name()));
    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
Also used : IntentService(org.onosproject.net.intent.IntentService) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter)

Example 20 with IntentService

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

the class AddHostToHostIntentCommand method doExecute.

@Override
protected void doExecute() {
    IntentService service = get(IntentService.class);
    HostId oneId = HostId.hostId(one);
    HostId twoId = HostId.hostId(two);
    TrafficSelector selector = buildTrafficSelector();
    TrafficTreatment treatment = buildTrafficTreatment();
    List<Constraint> constraints = buildConstraints();
    HostToHostIntent intent = HostToHostIntent.builder().appId(appId()).key(key()).one(oneId).two(twoId).selector(selector).treatment(treatment).constraints(constraints).priority(priority()).resourceGroup(resourceGroup()).build();
    service.submit(intent);
    print("Host to Host intent submitted:\n%s", intent.toString());
}
Also used : IntentService(org.onosproject.net.intent.IntentService) Constraint(org.onosproject.net.intent.Constraint) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) TrafficSelector(org.onosproject.net.flow.TrafficSelector) HostId(org.onosproject.net.HostId) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Aggregations

IntentService (org.onosproject.net.intent.IntentService)36 Intent (org.onosproject.net.intent.Intent)19 ApplicationId (org.onosproject.core.ApplicationId)8 ConnectPoint (org.onosproject.net.ConnectPoint)8 CoreService (org.onosproject.core.CoreService)7 Key (org.onosproject.net.intent.Key)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)6 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)5 Link (org.onosproject.net.Link)5 TrafficSelector (org.onosproject.net.flow.TrafficSelector)5 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)5 Constraint (org.onosproject.net.intent.Constraint)5 OpticalConnectivityIntent (org.onosproject.net.intent.OpticalConnectivityIntent)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 Consumes (javax.ws.rs.Consumes)3