Search in sources :

Example 6 with IntentState

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

the class IntentsListCommand method detailsFormat.

/**
 * Returns detailed information text about a specific intent.
 *
 * @param intent to print
 * @param state of intent
 * @return detailed information or "" if {@code state} was null
 */
private StringBuilder detailsFormat(Intent intent, IntentState state) {
    StringBuilder builder = new StringBuilder();
    if (state == null) {
        return builder;
    }
    if (!intent.resources().isEmpty()) {
        builder.append('\n').append(format(RESOURCES, intent.resources()));
    }
    if (intent instanceof ConnectivityIntent) {
        ConnectivityIntent ci = (ConnectivityIntent) intent;
        if (!ci.selector().criteria().isEmpty()) {
            builder.append('\n').append(format(COMMON_SELECTOR, formatSelector(ci.selector())));
        }
        if (!ci.treatment().allInstructions().isEmpty()) {
            builder.append('\n').append(format(TREATMENT, ci.treatment().allInstructions()));
        }
        if (ci.constraints() != null && !ci.constraints().isEmpty()) {
            builder.append('\n').append(format(CONSTRAINTS, ci.constraints()));
        }
    }
    if (intent instanceof HostToHostIntent) {
        HostToHostIntent pi = (HostToHostIntent) intent;
        builder.append('\n').append(format(SRC + HOST, pi.one()));
        builder.append('\n').append(format(DST + HOST, pi.two()));
    } else if (intent instanceof PointToPointIntent) {
        PointToPointIntent pi = (PointToPointIntent) intent;
        builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredIngressPoint()), INGRESS));
        builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredEgressPoint()), EGRESS));
    } else if (intent instanceof MultiPointToSinglePointIntent) {
        MultiPointToSinglePointIntent pi = (MultiPointToSinglePointIntent) intent;
        builder.append('\n').append(formatFilteredCps(pi.filteredIngressPoints(), INGRESS));
        builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredEgressPoint()), EGRESS));
    } else if (intent instanceof SinglePointToMultiPointIntent) {
        SinglePointToMultiPointIntent pi = (SinglePointToMultiPointIntent) intent;
        builder.append('\n').append(formatFilteredCps(Sets.newHashSet(pi.filteredIngressPoint()), INGRESS));
        builder.append('\n').append(formatFilteredCps(pi.filteredEgressPoints(), EGRESS));
    } else if (intent instanceof PathIntent) {
        PathIntent pi = (PathIntent) intent;
        builder.append(format("path=%s, cost=%f", pi.path().links(), pi.path().cost()));
    } else if (intent instanceof LinkCollectionIntent) {
        LinkCollectionIntent li = (LinkCollectionIntent) intent;
        builder.append('\n').append(format("links=%s", li.links()));
        builder.append('\n').append(format(CP, li.egressPoints()));
    } else if (intent instanceof OpticalCircuitIntent) {
        OpticalCircuitIntent ci = (OpticalCircuitIntent) intent;
        builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
        builder.append('\n').append(format("signal type=%s", ci.getSignalType()));
        builder.append('\n').append(format("bidirectional=%s", ci.isBidirectional()));
    } else if (intent instanceof OpticalConnectivityIntent) {
        OpticalConnectivityIntent ci = (OpticalConnectivityIntent) intent;
        builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
        builder.append('\n').append(format("signal type=%s", ci.getSignalType()));
        builder.append('\n').append(format("bidirectional=%s", ci.isBidirectional()));
        builder.append('\n').append(format("ochSignal=%s", ci.ochSignal()));
    } else if (intent instanceof OpticalOduIntent) {
        OpticalOduIntent ci = (OpticalOduIntent) intent;
        builder.append('\n').append(format("src=%s, dst=%s", ci.getSrc(), ci.getDst()));
        builder.append('\n').append(format("signal type=%s", ci.getSignalType()));
        builder.append('\n').append(format("bidirectional=%s", ci.isBidirectional()));
    }
    List<Intent> installable = service.getInstallableIntents(intent.key()).stream().filter(i -> contentFilter.filter(i)).collect(Collectors.toList());
    if (showInstallable && installable != null && !installable.isEmpty()) {
        builder.append('\n').append(format(INSTALLABLE, installable));
    }
    return builder;
}
Also used : StringFilter(org.onlab.util.StringFilter) StringUtils(org.apache.commons.lang.StringUtils) Tools(org.onlab.util.Tools) IntentState(org.onosproject.net.intent.IntentState) HashMap(java.util.HashMap) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) ConnectPoint(org.onosproject.net.ConnectPoint) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) IntentService(org.onosproject.net.intent.IntentService) Map(java.util.Map) Intent(org.onosproject.net.intent.Intent) JsonNode(com.fasterxml.jackson.databind.JsonNode) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) Criterion(org.onosproject.net.flow.criteria.Criterion) NodeId(org.onosproject.cluster.NodeId) PathIntent(org.onosproject.net.intent.PathIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) WordUtils.uncapitalize(org.apache.commons.lang3.text.WordUtils.uncapitalize) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) Key(org.onosproject.net.intent.Key) List(java.util.List) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) Service(org.apache.karaf.shell.api.action.lifecycle.Service) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) OpticalOduIntent(org.onosproject.net.intent.OpticalOduIntent) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) Option(org.apache.karaf.shell.api.action.Option) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) PathIntent(org.onosproject.net.intent.PathIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) OpticalOduIntent(org.onosproject.net.intent.OpticalOduIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) OpticalOduIntent(org.onosproject.net.intent.OpticalOduIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) OpticalCircuitIntent(org.onosproject.net.intent.OpticalCircuitIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent)

Example 7 with IntentState

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

the class IntentCodec method encode.

@Override
public ObjectNode encode(Intent intent, CodecContext context) {
    checkNotNull(intent, "Intent cannot be null");
    final ObjectNode result = context.mapper().createObjectNode().put(TYPE, intent.getClass().getSimpleName()).put(ID, intent.id().toString()).put(KEY, intent.key().toString()).put(APP_ID, UrlEscapers.urlPathSegmentEscaper().escape(intent.appId().name()));
    if (intent.resourceGroup() != null) {
        result.put(RESOURCE_GROUP, intent.resourceGroup().toString());
    }
    final ArrayNode jsonResources = result.putArray(RESOURCES);
    intent.resources().forEach(resource -> {
        if (resource instanceof Link) {
            jsonResources.add(context.codec(Link.class).encode((Link) resource, context));
        } else {
            jsonResources.add(resource.toString());
        }
    });
    IntentService service = context.getService(IntentService.class);
    IntentState state = service.getIntentState(intent.key());
    if (state != null) {
        result.put(STATE, state.toString());
    }
    return result;
}
Also used : IntentService(org.onosproject.net.intent.IntentService) IntentState(org.onosproject.net.intent.IntentState) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Link(org.onosproject.net.Link)

Example 8 with IntentState

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

the class IntentsWebResource method deleteIntentById.

/**
 * Withdraws intent.
 * Withdraws the specified intent from the system.
 *
 * @param appId application identifier
 * @param key   intent key
 * @return 204 NO CONTENT
 */
@DELETE
@Path("{appId}/{key}")
public Response deleteIntentById(@PathParam("appId") String appId, @PathParam("key") String key) {
    final ApplicationId app = get(CoreService.class).getAppId(appId);
    nullIsNotFound(app, APP_ID_NOT_FOUND);
    Intent intent = get(IntentService.class).getIntent(Key.of(key, app));
    IntentService service = get(IntentService.class);
    if (intent == null) {
        intent = service.getIntent(Key.of(Long.decode(key), app));
    }
    if (intent == null) {
        // in this case.
        return Response.noContent().build();
    }
    Key k = intent.key();
    // set up latch and listener to track uninstall progress
    CountDownLatch latch = new CountDownLatch(1);
    IntentListener listener = new DeleteListener(k, latch);
    service.addListener(listener);
    try {
        // request the withdraw
        service.withdraw(intent);
        try {
            latch.await(WITHDRAW_EVENT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            log.info("REST Delete operation timed out waiting for intent {}", k);
            Thread.currentThread().interrupt();
        }
        // double check the state
        IntentState state = service.getIntentState(k);
        if (state == WITHDRAWN || state == FAILED) {
            service.purge(intent);
        }
    } finally {
        // clean up the listener
        service.removeListener(listener);
    }
    return Response.noContent().build();
}
Also used : IntentService(org.onosproject.net.intent.IntentService) IntentState(org.onosproject.net.intent.IntentState) CoreService(org.onosproject.core.CoreService) Intent(org.onosproject.net.intent.Intent) ApplicationId(org.onosproject.core.ApplicationId) CountDownLatch(java.util.concurrent.CountDownLatch) IntentListener(org.onosproject.net.intent.IntentListener) Key(org.onosproject.net.intent.Key) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 9 with IntentState

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

the class ServiceApplicationComponent method processTapiEvent.

/**
 * Process TAPI Event from NBI.
 *
 * @param config TAPI Connectivity config for the event
 */
public void processTapiEvent(TapiConnectivityConfig config) {
    checkNotNull(config, "Config can't be null");
    Key key = Key.of(config.uuid(), appId);
    // Setup the Intent
    if (config.isSetup()) {
        log.debug("TAPI config: {} to setup intent", config);
        Intent intent = createOpticalIntent(config.leftCp(), config.rightCp(), key, appId);
        intentService.submit(intent);
    } else {
        // Release the intent
        Intent intent = intentService.getIntent(key);
        if (intent == null) {
            log.error("Intent for uuid {} does not exist", config.uuid());
            return;
        }
        log.debug("TAPI config: {} to purge intent {}", config, intent);
        CountDownLatch latch = new CountDownLatch(1);
        IntentListener listener = new DeleteListener(key, latch);
        intentService.addListener(listener);
        try {
            /*
                 * RCAS: Note, withdraw is asynchronous. We cannot call purge
                 * directly, because at this point it remains in the "INSTALLED"
                 * state.
                 */
            intentService.withdraw(intent);
            /*
                 * org.onosproject.onos-core-net - 2.1.0.SNAPSHOT |
                 * Purge for intent 0x0 is rejected because intent state is INSTALLED
                 * intentService.purge(intent);
                 */
            try {
                latch.await(WITHDRAW_EVENT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
            // double check the state
            IntentState state = intentService.getIntentState(key);
            if (state == WITHDRAWN || state == FAILED) {
                intentService.purge(intent);
            }
        } finally {
            intentService.removeListener(listener);
        }
    }
}
Also used : IntentState(org.onosproject.net.intent.IntentState) Intent(org.onosproject.net.intent.Intent) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) CountDownLatch(java.util.concurrent.CountDownLatch) IntentListener(org.onosproject.net.intent.IntentListener) Key(org.onosproject.net.intent.Key)

Example 10 with IntentState

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

the class IntentSynchronizer method synchronizeIntents.

private void synchronizeIntents() {
    Map<Key, Intent> serviceIntents = new HashMap<>();
    intentService.getIntents().forEach(i -> {
        if (i.appId().equals(appId)) {
            serviceIntents.put(i.key(), i);
        }
    });
    List<Intent> intentsToAdd = new LinkedList<>();
    List<Intent> intentsToRemove = new LinkedList<>();
    for (Intent localIntent : intents.values()) {
        Intent serviceIntent = serviceIntents.remove(localIntent.key());
        if (serviceIntent == null) {
            intentsToAdd.add(localIntent);
        } else {
            IntentState state = intentService.getIntentState(serviceIntent.key());
            if (!IntentUtils.intentsAreEqual(serviceIntent, localIntent) || state == null || state == IntentState.WITHDRAW_REQ || state == IntentState.WITHDRAWING || state == IntentState.WITHDRAWN) {
                intentsToAdd.add(localIntent);
            }
        }
    }
    for (Intent serviceIntent : serviceIntents.values()) {
        IntentState state = intentService.getIntentState(serviceIntent.key());
        if (state != null && state != IntentState.WITHDRAW_REQ && state != IntentState.WITHDRAWING && state != IntentState.WITHDRAWN) {
            intentsToRemove.add(serviceIntent);
        }
    }
    log.debug("Intent Synchronizer: submitting {}, withdrawing {}", intentsToAdd.size(), intentsToRemove.size());
    // Withdraw Intents
    for (Intent intent : intentsToRemove) {
        intentService.withdraw(intent);
        log.trace("Intent Synchronizer: withdrawing intent: {}", intent);
    }
    if (!isElectedLeader) {
        log.debug("Intent Synchronizer: cannot withdraw intents: " + "not elected leader anymore");
        isActivatedLeader = false;
        return;
    }
    // Add Intents
    for (Intent intent : intentsToAdd) {
        intentService.submit(intent);
        log.trace("Intent Synchronizer: submitting intent: {}", intent);
    }
    if (!isElectedLeader) {
        log.debug("Intent Synchronizer: cannot submit intents: " + "not elected leader anymore");
        isActivatedLeader = false;
        return;
    }
    if (isElectedLeader) {
        // Allow push of Intents
        isActivatedLeader = true;
    } else {
        isActivatedLeader = false;
    }
    log.debug("Intent synchronization completed");
}
Also used : IntentState(org.onosproject.net.intent.IntentState) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Intent(org.onosproject.net.intent.Intent) Key(org.onosproject.net.intent.Key) LinkedList(java.util.LinkedList)

Aggregations

IntentState (org.onosproject.net.intent.IntentState)10 Intent (org.onosproject.net.intent.Intent)8 Key (org.onosproject.net.intent.Key)6 IntentService (org.onosproject.net.intent.IntentService)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 HashMap (java.util.HashMap)3 NodeId (org.onosproject.cluster.NodeId)3 HostToHostIntent (org.onosproject.net.intent.HostToHostIntent)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)2 Strings (com.google.common.base.Strings)2 Lists (com.google.common.collect.Lists)2 Sets (com.google.common.collect.Sets)2 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2