Committed by
Gerrit Code Review
Adding SinglePointToMultiPointIntentCodec for support SP2MP intent over REST
Change-Id: Ic04529520ad1719f3d241b3a79d8e0602bfeac4e
Showing
4 changed files
with
112 additions
and
5 deletions
... | @@ -63,6 +63,7 @@ import org.onosproject.net.intent.Constraint; | ... | @@ -63,6 +63,7 @@ import org.onosproject.net.intent.Constraint; |
63 | import org.onosproject.net.intent.HostToHostIntent; | 63 | import org.onosproject.net.intent.HostToHostIntent; |
64 | import org.onosproject.net.intent.Intent; | 64 | import org.onosproject.net.intent.Intent; |
65 | import org.onosproject.net.intent.PointToPointIntent; | 65 | import org.onosproject.net.intent.PointToPointIntent; |
66 | +import org.onosproject.net.intent.SinglePointToMultiPointIntent; | ||
66 | import org.onosproject.net.key.DeviceKey; | 67 | import org.onosproject.net.key.DeviceKey; |
67 | import org.onosproject.net.mcast.McastRoute; | 68 | import org.onosproject.net.mcast.McastRoute; |
68 | import org.onosproject.net.meter.Band; | 69 | import org.onosproject.net.meter.Band; |
... | @@ -108,6 +109,7 @@ public class CodecManager implements CodecService { | ... | @@ -108,6 +109,7 @@ public class CodecManager implements CodecService { |
108 | registerCodec(HostLocation.class, new HostLocationCodec()); | 109 | registerCodec(HostLocation.class, new HostLocationCodec()); |
109 | registerCodec(HostToHostIntent.class, new HostToHostIntentCodec()); | 110 | registerCodec(HostToHostIntent.class, new HostToHostIntentCodec()); |
110 | registerCodec(PointToPointIntent.class, new PointToPointIntentCodec()); | 111 | registerCodec(PointToPointIntent.class, new PointToPointIntentCodec()); |
112 | + registerCodec(SinglePointToMultiPointIntent.class, new SinglePointToMultiPointIntentCodec()); | ||
111 | registerCodec(Intent.class, new IntentCodec()); | 113 | registerCodec(Intent.class, new IntentCodec()); |
112 | registerCodec(ConnectivityIntent.class, new ConnectivityIntentCodec()); | 114 | registerCodec(ConnectivityIntent.class, new ConnectivityIntentCodec()); |
113 | registerCodec(FlowEntry.class, new FlowEntryCodec()); | 115 | registerCodec(FlowEntry.class, new FlowEntryCodec()); | ... | ... |
... | @@ -19,12 +19,12 @@ import org.onosproject.codec.CodecContext; | ... | @@ -19,12 +19,12 @@ import org.onosproject.codec.CodecContext; |
19 | import org.onosproject.codec.JsonCodec; | 19 | import org.onosproject.codec.JsonCodec; |
20 | import org.onosproject.core.CoreService; | 20 | import org.onosproject.core.CoreService; |
21 | import org.onosproject.net.NetworkResource; | 21 | import org.onosproject.net.NetworkResource; |
22 | -import org.onosproject.net.intent.HostToHostIntent; | 22 | +import org.onosproject.net.intent.PointToPointIntent; |
23 | import org.onosproject.net.intent.Intent; | 23 | import org.onosproject.net.intent.Intent; |
24 | import org.onosproject.net.intent.IntentService; | 24 | import org.onosproject.net.intent.IntentService; |
25 | import org.onosproject.net.intent.IntentState; | 25 | import org.onosproject.net.intent.IntentState; |
26 | -import org.onosproject.net.intent.PointToPointIntent; | 26 | +import org.onosproject.net.intent.HostToHostIntent; |
27 | - | 27 | +import org.onosproject.net.intent.SinglePointToMultiPointIntent; |
28 | import com.fasterxml.jackson.databind.JsonNode; | 28 | import com.fasterxml.jackson.databind.JsonNode; |
29 | import com.fasterxml.jackson.databind.node.ArrayNode; | 29 | import com.fasterxml.jackson.databind.node.ArrayNode; |
30 | import com.fasterxml.jackson.databind.node.ObjectNode; | 30 | import com.fasterxml.jackson.databind.node.ObjectNode; |
... | @@ -83,6 +83,8 @@ public final class IntentCodec extends JsonCodec<Intent> { | ... | @@ -83,6 +83,8 @@ public final class IntentCodec extends JsonCodec<Intent> { |
83 | return context.codec(PointToPointIntent.class).decode(json, context); | 83 | return context.codec(PointToPointIntent.class).decode(json, context); |
84 | } else if (type.equals(HostToHostIntent.class.getSimpleName())) { | 84 | } else if (type.equals(HostToHostIntent.class.getSimpleName())) { |
85 | return context.codec(HostToHostIntent.class).decode(json, context); | 85 | return context.codec(HostToHostIntent.class).decode(json, context); |
86 | + } else if (type.equals(SinglePointToMultiPointIntent.class.getSimpleName())) { | ||
87 | + return context.codec(SinglePointToMultiPointIntent.class).decode(json, context); | ||
86 | } | 88 | } |
87 | 89 | ||
88 | throw new IllegalArgumentException("Intent type " | 90 | throw new IllegalArgumentException("Intent type " | ... | ... |
core/common/src/main/java/org/onosproject/codec/impl/SinglePointToMultiPointIntentCodec.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2015-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.codec.impl; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.JsonNode; | ||
19 | +import com.fasterxml.jackson.databind.node.ArrayNode; | ||
20 | +import org.onosproject.codec.CodecContext; | ||
21 | +import org.onosproject.codec.JsonCodec; | ||
22 | +import org.onosproject.net.ConnectPoint; | ||
23 | +import org.onosproject.net.intent.ConnectivityIntent; | ||
24 | +import org.onosproject.net.intent.SinglePointToMultiPointIntent; | ||
25 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
26 | + | ||
27 | +import java.util.HashSet; | ||
28 | +import java.util.Set; | ||
29 | + | ||
30 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
31 | +import static org.onlab.util.Tools.nullIsIllegal; | ||
32 | + | ||
33 | +/** | ||
34 | + * Single Point to Multi Point intent codec. | ||
35 | + */ | ||
36 | +public class SinglePointToMultiPointIntentCodec extends JsonCodec<SinglePointToMultiPointIntent> { | ||
37 | + private static final String INGRESS_POINT = "ingressPoint"; | ||
38 | + private static final String EGRESS_POINT = "egressPoint"; | ||
39 | + private static final String CP_POINTS = "connectPoints"; | ||
40 | + | ||
41 | + @Override | ||
42 | + public ObjectNode encode(SinglePointToMultiPointIntent intent, CodecContext context) { | ||
43 | + checkNotNull(intent, "Single Point to Multi Point intent cannot be null"); | ||
44 | + | ||
45 | + final JsonCodec<ConnectivityIntent> connectivityIntentCodec = | ||
46 | + context.codec(ConnectivityIntent.class); | ||
47 | + final ObjectNode result = connectivityIntentCodec.encode(intent, context); | ||
48 | + | ||
49 | + final JsonCodec<ConnectPoint> connectPointCodec = | ||
50 | + context.codec(ConnectPoint.class); | ||
51 | + final ObjectNode ingress = | ||
52 | + connectPointCodec.encode(intent.ingressPoint(), context); | ||
53 | + | ||
54 | + final ObjectNode result2 = context.mapper().createObjectNode(); | ||
55 | + final ArrayNode jsonconnectPoints = result2.putArray(CP_POINTS); | ||
56 | + | ||
57 | + if (intent.egressPoints() != null) { | ||
58 | + for (final ConnectPoint cp : intent.egressPoints()) { | ||
59 | + jsonconnectPoints.add(connectPointCodec.encode(cp, context)); | ||
60 | + } | ||
61 | + result.set(EGRESS_POINT, jsonconnectPoints); | ||
62 | + } | ||
63 | + result.set(INGRESS_POINT, ingress); | ||
64 | + | ||
65 | + return result; | ||
66 | + } | ||
67 | + | ||
68 | + @Override | ||
69 | + public SinglePointToMultiPointIntent decode(ObjectNode json, CodecContext context) { | ||
70 | + SinglePointToMultiPointIntent.Builder builder = SinglePointToMultiPointIntent.builder(); | ||
71 | + | ||
72 | + IntentCodec.intentAttributes(json, context, builder); | ||
73 | + ConnectivityIntentCodec.intentAttributes(json, context, builder); | ||
74 | + | ||
75 | + ObjectNode ingressJson = nullIsIllegal(get(json, INGRESS_POINT), | ||
76 | + INGRESS_POINT + IntentCodec.MISSING_MEMBER_MESSAGE); | ||
77 | + ConnectPoint ingress = context.codec(ConnectPoint.class) | ||
78 | + .decode(ingressJson, context); | ||
79 | + builder.ingressPoint(ingress); | ||
80 | + | ||
81 | + ObjectNode egressJson = nullIsIllegal(get(json, EGRESS_POINT), | ||
82 | + EGRESS_POINT + IntentCodec.MISSING_MEMBER_MESSAGE); | ||
83 | + if (egressJson != null) { | ||
84 | + final JsonCodec<ConnectPoint> connectPointCodec = | ||
85 | + context.codec(ConnectPoint.class); | ||
86 | + JsonNode connectPointsJson = get(json, EGRESS_POINT).get(CP_POINTS); | ||
87 | + | ||
88 | + Set<ConnectPoint> egressCp = new HashSet<ConnectPoint>(); | ||
89 | + if (connectPointsJson != null) { | ||
90 | + for (int i = 0; i < connectPointsJson.size(); i++) { | ||
91 | + egressCp.add(connectPointCodec.decode(get(connectPointsJson, i), | ||
92 | + context)); | ||
93 | + } | ||
94 | + builder.egressPoints(egressCp); | ||
95 | + } | ||
96 | + } | ||
97 | + | ||
98 | + return builder.build(); | ||
99 | + } | ||
100 | +} |
... | @@ -18,14 +18,15 @@ package org.onosproject.rest.resources; | ... | @@ -18,14 +18,15 @@ package org.onosproject.rest.resources; |
18 | import com.fasterxml.jackson.databind.node.ObjectNode; | 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
19 | import org.onosproject.core.ApplicationId; | 19 | import org.onosproject.core.ApplicationId; |
20 | import org.onosproject.core.CoreService; | 20 | import org.onosproject.core.CoreService; |
21 | +import org.onosproject.net.intent.SinglePointToMultiPointIntent; | ||
22 | +import org.onosproject.net.intent.PointToPointIntent; | ||
21 | import org.onosproject.net.intent.HostToHostIntent; | 23 | import org.onosproject.net.intent.HostToHostIntent; |
22 | import org.onosproject.net.intent.Intent; | 24 | import org.onosproject.net.intent.Intent; |
25 | +import org.onosproject.net.intent.IntentState; | ||
23 | import org.onosproject.net.intent.IntentEvent; | 26 | import org.onosproject.net.intent.IntentEvent; |
24 | import org.onosproject.net.intent.IntentListener; | 27 | import org.onosproject.net.intent.IntentListener; |
25 | import org.onosproject.net.intent.IntentService; | 28 | import org.onosproject.net.intent.IntentService; |
26 | -import org.onosproject.net.intent.IntentState; | ||
27 | import org.onosproject.net.intent.Key; | 29 | import org.onosproject.net.intent.Key; |
28 | -import org.onosproject.net.intent.PointToPointIntent; | ||
29 | import org.onosproject.rest.AbstractWebResource; | 30 | import org.onosproject.rest.AbstractWebResource; |
30 | import org.slf4j.Logger; | 31 | import org.slf4j.Logger; |
31 | 32 | ||
... | @@ -108,6 +109,8 @@ public class IntentsWebResource extends AbstractWebResource { | ... | @@ -108,6 +109,8 @@ public class IntentsWebResource extends AbstractWebResource { |
108 | root = codec(HostToHostIntent.class).encode((HostToHostIntent) intent, this); | 109 | root = codec(HostToHostIntent.class).encode((HostToHostIntent) intent, this); |
109 | } else if (intent instanceof PointToPointIntent) { | 110 | } else if (intent instanceof PointToPointIntent) { |
110 | root = codec(PointToPointIntent.class).encode((PointToPointIntent) intent, this); | 111 | root = codec(PointToPointIntent.class).encode((PointToPointIntent) intent, this); |
112 | + } else if (intent instanceof SinglePointToMultiPointIntent) { | ||
113 | + root = codec(SinglePointToMultiPointIntent.class).encode((SinglePointToMultiPointIntent) intent, this); | ||
111 | } else { | 114 | } else { |
112 | root = codec(Intent.class).encode(intent, this); | 115 | root = codec(Intent.class).encode(intent, this); |
113 | } | 116 | } | ... | ... |
-
Please register or login to post a comment