mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-18 10:51:04 +02:00
Adding SinglePointToMultiPointIntentCodec for support SP2MP intent over REST
Change-Id: Ic04529520ad1719f3d241b3a79d8e0602bfeac4e
This commit is contained in:
parent
ecc7ce938b
commit
a8f69ff3fd
@ -63,6 +63,7 @@ import org.onosproject.net.intent.Constraint;
|
|||||||
import org.onosproject.net.intent.HostToHostIntent;
|
import org.onosproject.net.intent.HostToHostIntent;
|
||||||
import org.onosproject.net.intent.Intent;
|
import org.onosproject.net.intent.Intent;
|
||||||
import org.onosproject.net.intent.PointToPointIntent;
|
import org.onosproject.net.intent.PointToPointIntent;
|
||||||
|
import org.onosproject.net.intent.SinglePointToMultiPointIntent;
|
||||||
import org.onosproject.net.key.DeviceKey;
|
import org.onosproject.net.key.DeviceKey;
|
||||||
import org.onosproject.net.mcast.McastRoute;
|
import org.onosproject.net.mcast.McastRoute;
|
||||||
import org.onosproject.net.meter.Band;
|
import org.onosproject.net.meter.Band;
|
||||||
@ -108,6 +109,7 @@ public class CodecManager implements CodecService {
|
|||||||
registerCodec(HostLocation.class, new HostLocationCodec());
|
registerCodec(HostLocation.class, new HostLocationCodec());
|
||||||
registerCodec(HostToHostIntent.class, new HostToHostIntentCodec());
|
registerCodec(HostToHostIntent.class, new HostToHostIntentCodec());
|
||||||
registerCodec(PointToPointIntent.class, new PointToPointIntentCodec());
|
registerCodec(PointToPointIntent.class, new PointToPointIntentCodec());
|
||||||
|
registerCodec(SinglePointToMultiPointIntent.class, new SinglePointToMultiPointIntentCodec());
|
||||||
registerCodec(Intent.class, new IntentCodec());
|
registerCodec(Intent.class, new IntentCodec());
|
||||||
registerCodec(ConnectivityIntent.class, new ConnectivityIntentCodec());
|
registerCodec(ConnectivityIntent.class, new ConnectivityIntentCodec());
|
||||||
registerCodec(FlowEntry.class, new FlowEntryCodec());
|
registerCodec(FlowEntry.class, new FlowEntryCodec());
|
||||||
|
@ -19,12 +19,12 @@ import org.onosproject.codec.CodecContext;
|
|||||||
import org.onosproject.codec.JsonCodec;
|
import org.onosproject.codec.JsonCodec;
|
||||||
import org.onosproject.core.CoreService;
|
import org.onosproject.core.CoreService;
|
||||||
import org.onosproject.net.NetworkResource;
|
import org.onosproject.net.NetworkResource;
|
||||||
import org.onosproject.net.intent.HostToHostIntent;
|
import org.onosproject.net.intent.PointToPointIntent;
|
||||||
import org.onosproject.net.intent.Intent;
|
import org.onosproject.net.intent.Intent;
|
||||||
import org.onosproject.net.intent.IntentService;
|
import org.onosproject.net.intent.IntentService;
|
||||||
import org.onosproject.net.intent.IntentState;
|
import org.onosproject.net.intent.IntentState;
|
||||||
import org.onosproject.net.intent.PointToPointIntent;
|
import org.onosproject.net.intent.HostToHostIntent;
|
||||||
|
import org.onosproject.net.intent.SinglePointToMultiPointIntent;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
@ -83,6 +83,8 @@ public final class IntentCodec extends JsonCodec<Intent> {
|
|||||||
return context.codec(PointToPointIntent.class).decode(json, context);
|
return context.codec(PointToPointIntent.class).decode(json, context);
|
||||||
} else if (type.equals(HostToHostIntent.class.getSimpleName())) {
|
} else if (type.equals(HostToHostIntent.class.getSimpleName())) {
|
||||||
return context.codec(HostToHostIntent.class).decode(json, context);
|
return context.codec(HostToHostIntent.class).decode(json, context);
|
||||||
|
} else if (type.equals(SinglePointToMultiPointIntent.class.getSimpleName())) {
|
||||||
|
return context.codec(SinglePointToMultiPointIntent.class).decode(json, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalArgumentException("Intent type "
|
throw new IllegalArgumentException("Intent type "
|
||||||
|
@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015-present Open Networking Laboratory
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.onosproject.codec.impl;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
|
import org.onosproject.codec.CodecContext;
|
||||||
|
import org.onosproject.codec.JsonCodec;
|
||||||
|
import org.onosproject.net.ConnectPoint;
|
||||||
|
import org.onosproject.net.intent.ConnectivityIntent;
|
||||||
|
import org.onosproject.net.intent.SinglePointToMultiPointIntent;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static org.onlab.util.Tools.nullIsIllegal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Single Point to Multi Point intent codec.
|
||||||
|
*/
|
||||||
|
public class SinglePointToMultiPointIntentCodec extends JsonCodec<SinglePointToMultiPointIntent> {
|
||||||
|
private static final String INGRESS_POINT = "ingressPoint";
|
||||||
|
private static final String EGRESS_POINT = "egressPoint";
|
||||||
|
private static final String CP_POINTS = "connectPoints";
|
||||||
|
|
||||||
|
@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 ObjectNode result2 = context.mapper().createObjectNode();
|
||||||
|
final ArrayNode jsonconnectPoints = result2.putArray(CP_POINTS);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SinglePointToMultiPointIntent decode(ObjectNode json, CodecContext context) {
|
||||||
|
SinglePointToMultiPointIntent.Builder builder = SinglePointToMultiPointIntent.builder();
|
||||||
|
|
||||||
|
IntentCodec.intentAttributes(json, context, builder);
|
||||||
|
ConnectivityIntentCodec.intentAttributes(json, context, builder);
|
||||||
|
|
||||||
|
ObjectNode ingressJson = nullIsIllegal(get(json, INGRESS_POINT),
|
||||||
|
INGRESS_POINT + IntentCodec.MISSING_MEMBER_MESSAGE);
|
||||||
|
ConnectPoint ingress = context.codec(ConnectPoint.class)
|
||||||
|
.decode(ingressJson, context);
|
||||||
|
builder.ingressPoint(ingress);
|
||||||
|
|
||||||
|
ObjectNode egressJson = nullIsIllegal(get(json, EGRESS_POINT),
|
||||||
|
EGRESS_POINT + IntentCodec.MISSING_MEMBER_MESSAGE);
|
||||||
|
if (egressJson != null) {
|
||||||
|
final JsonCodec<ConnectPoint> connectPointCodec =
|
||||||
|
context.codec(ConnectPoint.class);
|
||||||
|
JsonNode connectPointsJson = get(json, EGRESS_POINT).get(CP_POINTS);
|
||||||
|
|
||||||
|
Set<ConnectPoint> egressCp = new HashSet<ConnectPoint>();
|
||||||
|
if (connectPointsJson != null) {
|
||||||
|
for (int i = 0; i < connectPointsJson.size(); i++) {
|
||||||
|
egressCp.add(connectPointCodec.decode(get(connectPointsJson, i),
|
||||||
|
context));
|
||||||
|
}
|
||||||
|
builder.egressPoints(egressCp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
}
|
@ -18,14 +18,15 @@ package org.onosproject.rest.resources;
|
|||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import org.onosproject.core.ApplicationId;
|
import org.onosproject.core.ApplicationId;
|
||||||
import org.onosproject.core.CoreService;
|
import org.onosproject.core.CoreService;
|
||||||
|
import org.onosproject.net.intent.SinglePointToMultiPointIntent;
|
||||||
|
import org.onosproject.net.intent.PointToPointIntent;
|
||||||
import org.onosproject.net.intent.HostToHostIntent;
|
import org.onosproject.net.intent.HostToHostIntent;
|
||||||
import org.onosproject.net.intent.Intent;
|
import org.onosproject.net.intent.Intent;
|
||||||
|
import org.onosproject.net.intent.IntentState;
|
||||||
import org.onosproject.net.intent.IntentEvent;
|
import org.onosproject.net.intent.IntentEvent;
|
||||||
import org.onosproject.net.intent.IntentListener;
|
import org.onosproject.net.intent.IntentListener;
|
||||||
import org.onosproject.net.intent.IntentService;
|
import org.onosproject.net.intent.IntentService;
|
||||||
import org.onosproject.net.intent.IntentState;
|
|
||||||
import org.onosproject.net.intent.Key;
|
import org.onosproject.net.intent.Key;
|
||||||
import org.onosproject.net.intent.PointToPointIntent;
|
|
||||||
import org.onosproject.rest.AbstractWebResource;
|
import org.onosproject.rest.AbstractWebResource;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
@ -108,6 +109,8 @@ public class IntentsWebResource extends AbstractWebResource {
|
|||||||
root = codec(HostToHostIntent.class).encode((HostToHostIntent) intent, this);
|
root = codec(HostToHostIntent.class).encode((HostToHostIntent) intent, this);
|
||||||
} else if (intent instanceof PointToPointIntent) {
|
} else if (intent instanceof PointToPointIntent) {
|
||||||
root = codec(PointToPointIntent.class).encode((PointToPointIntent) intent, this);
|
root = codec(PointToPointIntent.class).encode((PointToPointIntent) intent, this);
|
||||||
|
} else if (intent instanceof SinglePointToMultiPointIntent) {
|
||||||
|
root = codec(SinglePointToMultiPointIntent.class).encode((SinglePointToMultiPointIntent) intent, this);
|
||||||
} else {
|
} else {
|
||||||
root = codec(Intent.class).encode(intent, this);
|
root = codec(Intent.class).encode(intent, this);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user