Search in sources :

Example 11 with ConnectivityIntent

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

the class SinglePointToMultiPointIntentCodec method encode.

@Override
public ObjectNode encode(SinglePointToMultiPointIntent intent, CodecContext context) {
    checkNotNull(intent, "Single Point to Multi 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.ingressPoint(), context);
    final ArrayNode jsonconnectPoints = context.mapper().createArrayNode();
    if (intent.egressPoints() != null) {
        for (final ConnectPoint cp : intent.egressPoints()) {
            jsonconnectPoints.add(connectPointCodec.encode(cp, context));
        }
        result.set(EGRESS_POINT, jsonconnectPoints);
    }
    result.set(INGRESS_POINT, ingress);
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 12 with ConnectivityIntent

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

the class IntentJsonMatcher method matchesSafely.

@Override
public boolean matchesSafely(JsonNode jsonIntent, Description description) {
    // check id
    final String jsonId = jsonIntent.get("id").asText();
    final String id = intent.id().toString();
    if (!jsonId.equals(id)) {
        description.appendText("id was " + jsonId);
        return false;
    }
    // check application id
    final JsonNode jsonAppIdNode = jsonIntent.get("appId");
    final String jsonAppId = jsonAppIdNode.asText();
    final String appId = intent.appId().name();
    if (!jsonAppId.equals(appId)) {
        description.appendText("appId was " + jsonAppId);
        return false;
    }
    // check intent type
    final String jsonType = jsonIntent.get("type").asText();
    final String type = intent.getClass().getSimpleName();
    if (!jsonType.equals(type)) {
        description.appendText("type was " + jsonType);
        return false;
    }
    // check resources array
    final JsonNode jsonResources = jsonIntent.get("resources");
    if (intent.resources() != null) {
        if (intent.resources().size() != jsonResources.size()) {
            description.appendText("resources array size was " + Integer.toString(jsonResources.size()));
            return false;
        }
        for (final NetworkResource resource : intent.resources()) {
            boolean resourceFound = false;
            final String resourceString = resource.toString();
            for (int resourceIndex = 0; resourceIndex < jsonResources.size(); resourceIndex++) {
                final JsonNode value = jsonResources.get(resourceIndex);
                if (value.asText().equals(resourceString)) {
                    resourceFound = true;
                }
            }
            if (!resourceFound) {
                description.appendText("resource missing " + resourceString);
                return false;
            }
        }
    } else if (jsonResources.size() != 0) {
        description.appendText("resources array empty");
        return false;
    }
    if (intent instanceof ConnectivityIntent) {
        return matchConnectivityIntent(jsonIntent, description);
    } else {
        description.appendText("class of intent is unknown");
        return false;
    }
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) JsonNode(com.fasterxml.jackson.databind.JsonNode) 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)

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