Search in sources :

Example 1 with ConnectivityIntent

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

the class IntentMonitorAndRerouteManager method startMonitorIntent.

@Override
public synchronized boolean startMonitorIntent(Key intentKey) {
    checkNotNull(intentKey, "Intent Key must not be null");
    log.debug("Start Monitor Intent: {}", intentKey.toString());
    toBeMonitoredIntents.add(intentKey);
    // Check if the requested intent is already present in the intent manager
    Intent installedIntent = intentService.getIntent(intentKey);
    if (!allowedIntent(installedIntent)) {
        return false;
    }
    // Check if the intent that is present in the intent subsystem is already installed
    if (intentService.getIntentState(intentKey) == IntentState.INSTALLED) {
        storeMonitoredIntent((ConnectivityIntent) installedIntent);
    }
    return true;
}
Also used : FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Intent(org.onosproject.net.intent.Intent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent)

Example 2 with ConnectivityIntent

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

the class IntentMonitorAndRerouteManager method applyPath.

@Override
public boolean applyPath(Route route) {
    checkNotNull(route, "Route to apply must be not null");
    checkNotNull(route.appId(), "Application id must be not null");
    checkNotNull(route.key(), "Intent key to apply must be not null");
    checkNotNull(route.paths(), "New path must be not null");
    checkArgument(route.paths().size() >= 1);
    ApplicationId appId = route.appId();
    Key key = route.key();
    // check if the app and the intent key are monitored
    if (!monitoredIntents.containsKey(appId)) {
        return false;
    }
    if (!monitoredIntents.get(appId).containsKey(key)) {
        return false;
    }
    // TODO: now we manage only the unsplittable routing
    Path currentPath = route.paths().stream().max(Comparator.comparing(Path::weight)).get();
    // in this case remove them from the list
    if (currentPath.path().get(0) instanceof HostId) {
        currentPath.path().remove(0);
    }
    if (currentPath.path().get(currentPath.path().size() - 1) instanceof HostId) {
        currentPath.path().remove(currentPath.path().size() - 1);
    }
    List<Link> links = createPathFromDeviceList(currentPath.path());
    // Generate the new Link collection intent, if not possible it will return the old intent
    ConnectivityIntent intent = generateLinkCollectionIntent(links, key, appId);
    storeMonitoredIntent(intent);
    intentService.submit(intent);
    return true;
}
Also used : Path(org.onosproject.imr.data.Path) ApplicationId(org.onosproject.core.ApplicationId) HostId(org.onosproject.net.HostId) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Key(org.onosproject.net.intent.Key) Link(org.onosproject.net.Link)

Example 3 with ConnectivityIntent

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

the class IntentMonitorAndRerouteManager method generateLinkCollectionIntent.

/**
 * Generates a new {@Link LinkCollectionIntent} applying the new path.
 * @param links List of links of the new path.
 * @param intentKey Key of the intent you want to re-route.
 * @param appId Application id that submits initially the intent.
 * @return The new intent, if not possibile it will return the old intent already installed.
 */
private ConnectivityIntent generateLinkCollectionIntent(List<Link> links, Key intentKey, ApplicationId appId) {
    checkNotNull(links);
    checkNotNull(appId);
    // Gets the oldIntent already installed
    ConnectivityIntent oldIntent = monitoredIntents.get(appId).get(intentKey);
    // Flush the statistics of the currently installed intent
    flushIntentStatStore(intentKey);
    // get the connect point of the old intent
    // Left element of the Pair is the ingress, right one is the egress
    Pair<Set<FilteredConnectPoint>, Set<FilteredConnectPoint>> cpPair = extractEndConnectPoints(oldIntent);
    if (cpPair == null) {
        return oldIntent;
    }
    // Now generate the new intent
    LinkCollectionIntent newIntent = LinkCollectionIntent.builder().appId(oldIntent.appId()).key(intentKey).selector(oldIntent.selector()).filteredIngressPoints(ImmutableSet.copyOf(cpPair.getLeft())).filteredEgressPoints(ImmutableSet.copyOf(cpPair.getRight())).treatment(oldIntent.treatment()).priority(oldIntent.priority()).constraints(oldIntent.constraints()).links(ImmutableSet.copyOf(links)).applyTreatmentOnEgress(true).build();
    return newIntent;
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) DistributedSet(org.onosproject.store.service.DistributedSet) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent)

Example 4 with ConnectivityIntent

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

the class ConnectivityIntentCodec method encode.

@Override
public ObjectNode encode(ConnectivityIntent intent, CodecContext context) {
    checkNotNull(intent, "Connectivity intent cannot be null");
    final JsonCodec<Intent> intentCodec = context.codec(Intent.class);
    final ObjectNode result = intentCodec.encode(intent, context);
    if (intent.selector() != null) {
        final JsonCodec<TrafficSelector> selectorCodec = context.codec(TrafficSelector.class);
        result.set(SELECTOR, selectorCodec.encode(intent.selector(), context));
    }
    if (intent.treatment() != null) {
        final JsonCodec<TrafficTreatment> treatmentCodec = context.codec(TrafficTreatment.class);
        result.set(TREATMENT, treatmentCodec.encode(intent.treatment(), context));
    }
    result.put(IntentCodec.PRIORITY, intent.priority());
    if (intent.constraints() != null) {
        final ArrayNode jsonConstraints = result.putArray(CONSTRAINTS);
        if (intent.constraints() != null) {
            final JsonCodec<Constraint> constraintCodec = context.codec(Constraint.class);
            for (final Constraint constraint : intent.constraints()) {
                final ObjectNode constraintNode = constraintCodec.encode(constraint, context);
                jsonConstraints.add(constraintNode);
            }
        }
    }
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Constraint(org.onosproject.net.intent.Constraint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Intent(org.onosproject.net.intent.Intent) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 5 with ConnectivityIntent

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

the class HostToHostIntentCodec method encode.

@Override
public ObjectNode encode(HostToHostIntent intent, CodecContext context) {
    checkNotNull(intent, "Host to host intent cannot be null");
    final JsonCodec<ConnectivityIntent> connectivityIntentCodec = context.codec(ConnectivityIntent.class);
    final ObjectNode result = connectivityIntentCodec.encode(intent, context);
    final String one = intent.one().toString();
    final String two = intent.two().toString();
    result.put(ONE, one);
    result.put(TWO, two);
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent)

Aggregations

ConnectivityIntent (org.onosproject.net.intent.ConnectivityIntent)12 ConnectPoint (org.onosproject.net.ConnectPoint)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)4 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)4 Constraint (org.onosproject.net.intent.Constraint)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Set (java.util.Set)3 TrafficSelector (org.onosproject.net.flow.TrafficSelector)3 Intent (org.onosproject.net.intent.Intent)3 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)3 Lists (com.google.common.collect.Lists)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)2 Criterion (org.onosproject.net.flow.criteria.Criterion)2 PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)2 BandwidthConstraint (org.onosproject.net.intent.constraint.BandwidthConstraint)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1