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;
}
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;
}
}
Aggregations