Search in sources :

Example 6 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 7 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 8 with ConnectivityIntent

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

the class IntentJsonMatcher method matchConnectivityIntent.

/**
 * Matches the JSON representation of a connectivity intent. Calls the
 * matcher for the connectivity intent subtype.
 *
 * @param jsonIntent JSON representation of the intent
 * @param description Description object used for recording errors
 * @return true if the JSON matches the intent, false otherwise
 */
private boolean matchConnectivityIntent(JsonNode jsonIntent, Description description) {
    final ConnectivityIntent connectivityIntent = (ConnectivityIntent) intent;
    // check selector
    final JsonNode jsonSelector = jsonIntent.get("selector");
    final TrafficSelector selector = connectivityIntent.selector();
    final Set<Criterion> criteria = selector.criteria();
    final JsonNode jsonCriteria = jsonSelector.get("criteria");
    if (jsonCriteria.size() != criteria.size()) {
        description.appendText("size of criteria array is " + Integer.toString(jsonCriteria.size()));
        return false;
    }
    for (Criterion criterion : criteria) {
        boolean criterionFound = false;
        for (int criterionIndex = 0; criterionIndex < jsonCriteria.size(); criterionIndex++) {
            final CriterionJsonMatcher criterionMatcher = CriterionJsonMatcher.matchesCriterion(criterion);
            if (criterionMatcher.matches(jsonCriteria.get(criterionIndex))) {
                criterionFound = true;
                break;
            }
        }
        if (!criterionFound) {
            description.appendText("criterion not found " + criterion.toString());
            return false;
        }
    }
    // check treatment
    final JsonNode jsonTreatment = jsonIntent.get("treatment");
    final TrafficTreatment treatment = connectivityIntent.treatment();
    final List<Instruction> instructions = treatment.immediate();
    final JsonNode jsonInstructions = jsonTreatment.get("instructions");
    if (jsonInstructions.size() != instructions.size()) {
        description.appendText("size of instructions array is " + Integer.toString(jsonInstructions.size()));
        return false;
    }
    for (Instruction instruction : instructions) {
        boolean instructionFound = false;
        for (int instructionIndex = 0; instructionIndex < jsonInstructions.size(); instructionIndex++) {
            final InstructionJsonMatcher instructionMatcher = InstructionJsonMatcher.matchesInstruction(instruction);
            if (instructionMatcher.matches(jsonInstructions.get(instructionIndex))) {
                instructionFound = true;
                break;
            }
        }
        if (!instructionFound) {
            description.appendText("instruction not found " + instruction.toString());
            return false;
        }
    }
    // Check constraints
    final JsonNode jsonConstraints = jsonIntent.get("constraints");
    if (connectivityIntent.constraints() != null) {
        if (connectivityIntent.constraints().size() != jsonConstraints.size()) {
            description.appendText("constraints array size was " + Integer.toString(jsonConstraints.size()));
            return false;
        }
        for (final Constraint constraint : connectivityIntent.constraints()) {
            boolean constraintFound = false;
            for (int constraintIndex = 0; constraintIndex < jsonConstraints.size(); constraintIndex++) {
                final JsonNode value = jsonConstraints.get(constraintIndex);
                if (matchConstraint(constraint, value)) {
                    constraintFound = true;
                }
            }
            if (!constraintFound) {
                final String constraintString = constraint.toString();
                description.appendText("constraint missing " + constraintString);
                return false;
            }
        }
    } else if (jsonConstraints.size() != 0) {
        description.appendText("constraint array not empty");
        return false;
    }
    if (connectivityIntent instanceof HostToHostIntent) {
        return matchHostToHostIntent(jsonIntent, description);
    } else if (connectivityIntent instanceof PointToPointIntent) {
        return matchPointToPointIntent(jsonIntent, description);
    } else {
        description.appendText("class of connectivity intent is unknown");
        return false;
    }
}
Also used : WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) Constraint(org.onosproject.net.intent.Constraint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) LinkTypeConstraint(org.onosproject.net.intent.constraint.LinkTypeConstraint) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) JsonNode(com.fasterxml.jackson.databind.JsonNode) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instruction(org.onosproject.net.flow.instructions.Instruction) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) WaypointConstraint(org.onosproject.net.intent.constraint.WaypointConstraint) ObstacleConstraint(org.onosproject.net.intent.constraint.ObstacleConstraint) Constraint(org.onosproject.net.intent.Constraint) ConnectPoint(org.onosproject.net.ConnectPoint) AnnotationConstraint(org.onosproject.net.intent.constraint.AnnotationConstraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) LatencyConstraint(org.onosproject.net.intent.constraint.LatencyConstraint) LinkTypeConstraint(org.onosproject.net.intent.constraint.LinkTypeConstraint) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector)

Example 9 with ConnectivityIntent

use of org.onosproject.net.intent.ConnectivityIntent 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 10 with ConnectivityIntent

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

the class PointToPointIntentCodec method encode.

@Override
public ObjectNode encode(PointToPointIntent intent, CodecContext context) {
    checkNotNull(intent, "Point to point intent cannot be null");
    final JsonCodec<ConnectivityIntent> connectivityIntentCodec = context.codec(ConnectivityIntent.class);
    final ObjectNode result = connectivityIntentCodec.encode(intent, context);
    final JsonCodec<ConnectPoint> connectPointCodec = context.codec(ConnectPoint.class);
    final ObjectNode ingress = connectPointCodec.encode(intent.filteredIngressPoint().connectPoint(), context);
    final ObjectNode egress = connectPointCodec.encode(intent.filteredEgressPoint().connectPoint(), context);
    result.set(INGRESS_POINT, ingress);
    result.set(EGRESS_POINT, egress);
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

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