Committed by
Gerrit Code Review
[ONOS-4258] Initial implementation of supporting extension in REST
- Support Nicira extension Change-Id: I62bf4417e43459727ce7d4b1ac929c6cf0b7826f
Showing
27 changed files
with
1028 additions
and
18 deletions
1 | +/* | ||
2 | + * Copyright 2016-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; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
19 | +import org.onosproject.net.driver.HandlerBehaviour; | ||
20 | +import org.onosproject.net.flow.criteria.ExtensionSelector; | ||
21 | + | ||
22 | +/** | ||
23 | + * Interface for encode and decode extension selector. | ||
24 | + */ | ||
25 | +public interface ExtensionSelectorCodec extends HandlerBehaviour { | ||
26 | + | ||
27 | + /** | ||
28 | + * Encodes an extension selector to an JSON object. | ||
29 | + * | ||
30 | + * @param extensionSelector extension selector | ||
31 | + * @param context encoding context | ||
32 | + * @return JSON object | ||
33 | + */ | ||
34 | + default ObjectNode encode(ExtensionSelector extensionSelector, CodecContext context) { | ||
35 | + return null; | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * Decodes an JSON object to an extension selector. | ||
40 | + * | ||
41 | + * @param objectNode JSON object | ||
42 | + * @param context decoding context | ||
43 | + * @return extension selector | ||
44 | + */ | ||
45 | + default ExtensionSelector decode(ObjectNode objectNode, CodecContext context) { | ||
46 | + return null; | ||
47 | + } | ||
48 | +} |
1 | +/* | ||
2 | + * Copyright 2016-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; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
19 | +import org.onosproject.net.driver.HandlerBehaviour; | ||
20 | +import org.onosproject.net.flow.instructions.ExtensionTreatment; | ||
21 | + | ||
22 | +/** | ||
23 | + * Interface for encode and decode extension treatment. | ||
24 | + */ | ||
25 | +public interface ExtensionTreatmentCodec extends HandlerBehaviour { | ||
26 | + | ||
27 | + /** | ||
28 | + * Encodes an extension treatment to an JSON object. | ||
29 | + * | ||
30 | + * @param extensionTreatment extension treatment | ||
31 | + * @param context encoding context | ||
32 | + * @return JSON object | ||
33 | + */ | ||
34 | + default ObjectNode encode(ExtensionTreatment extensionTreatment, CodecContext context) { | ||
35 | + return null; | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * Decodes an JSON object to an extension treatment. | ||
40 | + * | ||
41 | + * @param objectNode JSON object | ||
42 | + * @param context decoding context | ||
43 | + * @return extension treatment | ||
44 | + */ | ||
45 | + default ExtensionTreatment decode(ObjectNode objectNode, CodecContext context) { | ||
46 | + return null; | ||
47 | + } | ||
48 | +} |
... | @@ -79,6 +79,15 @@ public final class ExtensionTreatmentType { | ... | @@ -79,6 +79,15 @@ public final class ExtensionTreatmentType { |
79 | this.type = type; | 79 | this.type = type; |
80 | } | 80 | } |
81 | 81 | ||
82 | + /** | ||
83 | + * Returns extension treatment type. | ||
84 | + * | ||
85 | + * @return extension treatment type | ||
86 | + */ | ||
87 | + public int type() { | ||
88 | + return type; | ||
89 | + } | ||
90 | + | ||
82 | @Override | 91 | @Override |
83 | public int hashCode() { | 92 | public int hashCode() { |
84 | return Objects.hash(type); | 93 | return Objects.hash(type); | ... | ... |
... | @@ -15,20 +15,28 @@ | ... | @@ -15,20 +15,28 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.codec.impl; | 16 | package org.onosproject.codec.impl; |
17 | 17 | ||
18 | +import com.fasterxml.jackson.databind.JsonNode; | ||
18 | import com.fasterxml.jackson.databind.node.ObjectNode; | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
20 | +import org.onlab.osgi.DefaultServiceDirectory; | ||
21 | +import org.onlab.osgi.ServiceDirectory; | ||
19 | import org.onlab.packet.IpAddress; | 22 | import org.onlab.packet.IpAddress; |
20 | import org.onlab.packet.MacAddress; | 23 | import org.onlab.packet.MacAddress; |
21 | import org.onlab.packet.MplsLabel; | 24 | import org.onlab.packet.MplsLabel; |
22 | import org.onlab.packet.TpPort; | 25 | import org.onlab.packet.TpPort; |
23 | import org.onlab.packet.VlanId; | 26 | import org.onlab.packet.VlanId; |
24 | import org.onlab.util.HexString; | 27 | import org.onlab.util.HexString; |
28 | +import org.onosproject.codec.ExtensionTreatmentCodec; | ||
25 | import org.onosproject.core.DefaultGroupId; | 29 | import org.onosproject.core.DefaultGroupId; |
26 | import org.onosproject.core.GroupId; | 30 | import org.onosproject.core.GroupId; |
27 | import org.onosproject.net.ChannelSpacing; | 31 | import org.onosproject.net.ChannelSpacing; |
32 | +import org.onosproject.net.Device; | ||
33 | +import org.onosproject.net.DeviceId; | ||
28 | import org.onosproject.net.GridType; | 34 | import org.onosproject.net.GridType; |
29 | import org.onosproject.net.OchSignal; | 35 | import org.onosproject.net.OchSignal; |
30 | import org.onosproject.net.OduSignalId; | 36 | import org.onosproject.net.OduSignalId; |
31 | import org.onosproject.net.PortNumber; | 37 | import org.onosproject.net.PortNumber; |
38 | +import org.onosproject.net.device.DeviceService; | ||
39 | +import org.onosproject.net.flow.instructions.ExtensionTreatment; | ||
32 | import org.onosproject.net.flow.instructions.Instruction; | 40 | import org.onosproject.net.flow.instructions.Instruction; |
33 | import org.onosproject.net.flow.instructions.Instructions; | 41 | import org.onosproject.net.flow.instructions.Instructions; |
34 | import org.onosproject.net.flow.instructions.L0ModificationInstruction; | 42 | import org.onosproject.net.flow.instructions.L0ModificationInstruction; |
... | @@ -37,13 +45,16 @@ import org.onosproject.net.flow.instructions.L2ModificationInstruction; | ... | @@ -37,13 +45,16 @@ import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
37 | import org.onosproject.net.flow.instructions.L3ModificationInstruction; | 45 | import org.onosproject.net.flow.instructions.L3ModificationInstruction; |
38 | import org.onosproject.net.flow.instructions.L4ModificationInstruction; | 46 | import org.onosproject.net.flow.instructions.L4ModificationInstruction; |
39 | import org.onosproject.net.meter.MeterId; | 47 | import org.onosproject.net.meter.MeterId; |
48 | +import org.slf4j.Logger; | ||
40 | 49 | ||
41 | import static org.onlab.util.Tools.nullIsIllegal; | 50 | import static org.onlab.util.Tools.nullIsIllegal; |
51 | +import static org.slf4j.LoggerFactory.getLogger; | ||
42 | 52 | ||
43 | /** | 53 | /** |
44 | * Decoding portion of the instruction codec. | 54 | * Decoding portion of the instruction codec. |
45 | */ | 55 | */ |
46 | public final class DecodeInstructionCodecHelper { | 56 | public final class DecodeInstructionCodecHelper { |
57 | + protected static final Logger log = getLogger(DecodeInstructionCodecHelper.class); | ||
47 | private final ObjectNode json; | 58 | private final ObjectNode json; |
48 | 59 | ||
49 | /** | 60 | /** |
... | @@ -227,6 +238,45 @@ public final class DecodeInstructionCodecHelper { | ... | @@ -227,6 +238,45 @@ public final class DecodeInstructionCodecHelper { |
227 | } | 238 | } |
228 | 239 | ||
229 | /** | 240 | /** |
241 | + * Decodes a extension instruction. | ||
242 | + * | ||
243 | + * @return extension treatment | ||
244 | + */ | ||
245 | + private Instruction decodeExtension() { | ||
246 | + ObjectNode node = (ObjectNode) json.get(InstructionCodec.EXTENSION); | ||
247 | + if (node != null) { | ||
248 | + DeviceId deviceId = getDeviceId(); | ||
249 | + | ||
250 | + ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); | ||
251 | + DeviceService deviceService = serviceDirectory.get(DeviceService.class); | ||
252 | + Device device = deviceService.getDevice(deviceId); | ||
253 | + | ||
254 | + if (device.is(ExtensionTreatmentCodec.class)) { | ||
255 | + ExtensionTreatmentCodec treatmentCodec = device.as(ExtensionTreatmentCodec.class); | ||
256 | + ExtensionTreatment treatment = treatmentCodec.decode(node, null); | ||
257 | + return Instructions.extension(treatment, deviceId); | ||
258 | + } else { | ||
259 | + log.warn("There is no codec to decode extension for device {}", deviceId.toString()); | ||
260 | + } | ||
261 | + } | ||
262 | + return null; | ||
263 | + } | ||
264 | + | ||
265 | + /** | ||
266 | + * Returns device identifier. | ||
267 | + * | ||
268 | + * @return device identifier | ||
269 | + * @throws IllegalArgumentException if the JSON is invalid | ||
270 | + */ | ||
271 | + private DeviceId getDeviceId() { | ||
272 | + JsonNode deviceIdNode = json.get(InstructionCodec.DEVICE_ID); | ||
273 | + if (deviceIdNode != null) { | ||
274 | + return DeviceId.deviceId(deviceIdNode.asText()); | ||
275 | + } | ||
276 | + throw new IllegalArgumentException("Empty device identifier"); | ||
277 | + } | ||
278 | + | ||
279 | + /** | ||
230 | * Extracts port number of the given json node. | 280 | * Extracts port number of the given json node. |
231 | * | 281 | * |
232 | * @param jsonNode json node | 282 | * @param jsonNode json node |
... | @@ -290,6 +340,8 @@ public final class DecodeInstructionCodecHelper { | ... | @@ -290,6 +340,8 @@ public final class DecodeInstructionCodecHelper { |
290 | return decodeL3(); | 340 | return decodeL3(); |
291 | } else if (type.equals(Instruction.Type.L4MODIFICATION.name())) { | 341 | } else if (type.equals(Instruction.Type.L4MODIFICATION.name())) { |
292 | return decodeL4(); | 342 | return decodeL4(); |
343 | + } else if (type.equals(Instruction.Type.EXTENSION.name())) { | ||
344 | + return decodeExtension(); | ||
293 | } | 345 | } |
294 | throw new IllegalArgumentException("Instruction type " | 346 | throw new IllegalArgumentException("Instruction type " |
295 | + type + " is not supported"); | 347 | + type + " is not supported"); | ... | ... |
... | @@ -16,10 +16,16 @@ | ... | @@ -16,10 +16,16 @@ |
16 | package org.onosproject.codec.impl; | 16 | package org.onosproject.codec.impl; |
17 | 17 | ||
18 | import com.fasterxml.jackson.databind.node.ObjectNode; | 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
19 | +import org.onlab.osgi.DefaultServiceDirectory; | ||
20 | +import org.onlab.osgi.ServiceDirectory; | ||
19 | import org.onlab.util.HexString; | 21 | import org.onlab.util.HexString; |
20 | import org.onosproject.codec.CodecContext; | 22 | import org.onosproject.codec.CodecContext; |
23 | +import org.onosproject.codec.ExtensionTreatmentCodec; | ||
24 | +import org.onosproject.net.Device; | ||
25 | +import org.onosproject.net.DeviceId; | ||
21 | import org.onosproject.net.OchSignal; | 26 | import org.onosproject.net.OchSignal; |
22 | import org.onosproject.net.OduSignalId; | 27 | import org.onosproject.net.OduSignalId; |
28 | +import org.onosproject.net.device.DeviceService; | ||
23 | import org.onosproject.net.flow.instructions.Instruction; | 29 | import org.onosproject.net.flow.instructions.Instruction; |
24 | import org.onosproject.net.flow.instructions.Instructions; | 30 | import org.onosproject.net.flow.instructions.Instructions; |
25 | import org.onosproject.net.flow.instructions.L0ModificationInstruction; | 31 | import org.onosproject.net.flow.instructions.L0ModificationInstruction; |
... | @@ -28,13 +34,14 @@ import org.onosproject.net.flow.instructions.L2ModificationInstruction; | ... | @@ -28,13 +34,14 @@ import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
28 | import org.onosproject.net.flow.instructions.L3ModificationInstruction; | 34 | import org.onosproject.net.flow.instructions.L3ModificationInstruction; |
29 | import org.onosproject.net.flow.instructions.L4ModificationInstruction; | 35 | import org.onosproject.net.flow.instructions.L4ModificationInstruction; |
30 | import org.slf4j.Logger; | 36 | import org.slf4j.Logger; |
31 | -import org.slf4j.LoggerFactory; | 37 | + |
38 | +import static org.slf4j.LoggerFactory.getLogger; | ||
32 | 39 | ||
33 | /** | 40 | /** |
34 | * JSON encoding of Instructions. | 41 | * JSON encoding of Instructions. |
35 | */ | 42 | */ |
36 | public final class EncodeInstructionCodecHelper { | 43 | public final class EncodeInstructionCodecHelper { |
37 | - protected static final Logger log = LoggerFactory.getLogger(EncodeInstructionCodecHelper.class); | 44 | + protected static final Logger log = getLogger(EncodeInstructionCodecHelper.class); |
38 | private final Instruction instruction; | 45 | private final Instruction instruction; |
39 | private final CodecContext context; | 46 | private final CodecContext context; |
40 | 47 | ||
... | @@ -219,14 +226,29 @@ public final class EncodeInstructionCodecHelper { | ... | @@ -219,14 +226,29 @@ public final class EncodeInstructionCodecHelper { |
219 | } | 226 | } |
220 | } | 227 | } |
221 | 228 | ||
229 | + | ||
222 | /** | 230 | /** |
223 | - * Encode a extension instruction. | 231 | + * Encodes a extension instruction. |
224 | * | 232 | * |
225 | * @param result json node that the instruction attributes are added to | 233 | * @param result json node that the instruction attributes are added to |
226 | */ | 234 | */ |
227 | private void encodeExtension(ObjectNode result) { | 235 | private void encodeExtension(ObjectNode result) { |
228 | - // TODO Support extension in REST API | 236 | + final Instructions.ExtensionInstructionWrapper extensionInstruction = |
229 | - log.info("Cannot convert instruction type of EXTENSION"); | 237 | + (Instructions.ExtensionInstructionWrapper) instruction; |
238 | + | ||
239 | + DeviceId deviceId = extensionInstruction.deviceId(); | ||
240 | + | ||
241 | + ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); | ||
242 | + DeviceService deviceService = serviceDirectory.get(DeviceService.class); | ||
243 | + Device device = deviceService.getDevice(deviceId); | ||
244 | + | ||
245 | + if (device.is(ExtensionTreatmentCodec.class)) { | ||
246 | + ExtensionTreatmentCodec treatmentCodec = device.as(ExtensionTreatmentCodec.class); | ||
247 | + ObjectNode node = treatmentCodec.encode(extensionInstruction.extensionInstruction(), context); | ||
248 | + result.set(InstructionCodec.EXTENSION, node); | ||
249 | + } else { | ||
250 | + log.warn("There is no codec to encode extension for device {}", deviceId.toString()); | ||
251 | + } | ||
230 | } | 252 | } |
231 | 253 | ||
232 | /** | 254 | /** | ... | ... |
... | @@ -57,6 +57,8 @@ public final class InstructionCodec extends JsonCodec<Instruction> { | ... | @@ -57,6 +57,8 @@ public final class InstructionCodec extends JsonCodec<Instruction> { |
57 | protected static final String TRIBUTARY_PORT_NUMBER = "tributaryPortNumber"; | 57 | protected static final String TRIBUTARY_PORT_NUMBER = "tributaryPortNumber"; |
58 | protected static final String TRIBUTARY_SLOT_LEN = "tributarySlotLength"; | 58 | protected static final String TRIBUTARY_SLOT_LEN = "tributarySlotLength"; |
59 | protected static final String TRIBUTARY_SLOT_BITMAP = "tributarySlotBitmap"; | 59 | protected static final String TRIBUTARY_SLOT_BITMAP = "tributarySlotBitmap"; |
60 | + protected static final String EXTENSION = "extension"; | ||
61 | + protected static final String DEVICE_ID = "deviceId"; | ||
60 | 62 | ||
61 | protected static final String MISSING_MEMBER_MESSAGE = | 63 | protected static final String MISSING_MEMBER_MESSAGE = |
62 | " member is required in Instruction"; | 64 | " member is required in Instruction"; | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016-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.driver; | ||
17 | + | ||
18 | +import org.apache.felix.scr.annotations.Activate; | ||
19 | +import org.apache.felix.scr.annotations.Component; | ||
20 | +import org.apache.felix.scr.annotations.Deactivate; | ||
21 | +import org.apache.felix.scr.annotations.Reference; | ||
22 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
23 | +import org.onosproject.codec.CodecService; | ||
24 | +import org.onosproject.driver.extensions.MoveExtensionTreatment; | ||
25 | +import org.onosproject.driver.extensions.NiciraMatchNshSi; | ||
26 | +import org.onosproject.driver.extensions.NiciraMatchNshSpi; | ||
27 | +import org.onosproject.driver.extensions.NiciraResubmit; | ||
28 | +import org.onosproject.driver.extensions.NiciraResubmitTable; | ||
29 | +import org.onosproject.driver.extensions.NiciraSetNshContextHeader; | ||
30 | +import org.onosproject.driver.extensions.NiciraSetNshSi; | ||
31 | +import org.onosproject.driver.extensions.NiciraSetNshSpi; | ||
32 | +import org.onosproject.driver.extensions.NiciraSetTunnelDst; | ||
33 | +import org.onosproject.driver.extensions.codec.MoveExtensionTreatmentCodec; | ||
34 | +import org.onosproject.driver.extensions.codec.NiciraMatchNshSiCodec; | ||
35 | +import org.onosproject.driver.extensions.codec.NiciraMatchNshSpiCodec; | ||
36 | +import org.onosproject.driver.extensions.codec.NiciraResubmitCodec; | ||
37 | +import org.onosproject.driver.extensions.codec.NiciraResubmitTableCodec; | ||
38 | +import org.onosproject.driver.extensions.codec.NiciraSetNshContextHeaderCodec; | ||
39 | +import org.onosproject.driver.extensions.codec.NiciraSetNshSiCodec; | ||
40 | +import org.onosproject.driver.extensions.codec.NiciraSetNshSpiCodec; | ||
41 | +import org.onosproject.driver.extensions.codec.NiciraSetTunnelDstCodec; | ||
42 | +import org.slf4j.Logger; | ||
43 | + | ||
44 | +import static org.slf4j.LoggerFactory.getLogger; | ||
45 | + | ||
46 | +/** | ||
47 | + * Codec register for default drivers. | ||
48 | + */ | ||
49 | +@Component(immediate = true) | ||
50 | +public class DefaultCodecRegister { | ||
51 | + | ||
52 | + private final Logger log = getLogger(getClass()); | ||
53 | + | ||
54 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
55 | + protected CodecService codecService; | ||
56 | + | ||
57 | + @Activate | ||
58 | + public void activate() { | ||
59 | + codecService.registerCodec(MoveExtensionTreatment.class, new MoveExtensionTreatmentCodec()); | ||
60 | + codecService.registerCodec(NiciraMatchNshSi.class, new NiciraMatchNshSiCodec()); | ||
61 | + codecService.registerCodec(NiciraMatchNshSpi.class, new NiciraMatchNshSpiCodec()); | ||
62 | + codecService.registerCodec(NiciraResubmit.class, new NiciraResubmitCodec()); | ||
63 | + codecService.registerCodec(NiciraResubmitTable.class, new NiciraResubmitTableCodec()); | ||
64 | + codecService.registerCodec(NiciraSetNshSi.class, new NiciraSetNshSiCodec()); | ||
65 | + codecService.registerCodec(NiciraSetNshSpi.class, new NiciraSetNshSpiCodec()); | ||
66 | + codecService.registerCodec(NiciraSetTunnelDst.class, new NiciraSetTunnelDstCodec()); | ||
67 | + codecService.registerCodec(NiciraSetNshContextHeader.class, new NiciraSetNshContextHeaderCodec()); | ||
68 | + log.info("Registered default driver codecs."); | ||
69 | + } | ||
70 | + | ||
71 | + @Deactivate | ||
72 | + public void deactivate() { | ||
73 | + codecService.unregisterCodec(MoveExtensionTreatment.class); | ||
74 | + codecService.unregisterCodec(NiciraMatchNshSi.class); | ||
75 | + codecService.unregisterCodec(NiciraMatchNshSpi.class); | ||
76 | + codecService.unregisterCodec(NiciraResubmit.class); | ||
77 | + codecService.unregisterCodec(NiciraResubmitTable.class); | ||
78 | + codecService.unregisterCodec(NiciraSetNshSi.class); | ||
79 | + codecService.unregisterCodec(NiciraSetNshSpi.class); | ||
80 | + codecService.unregisterCodec(NiciraSetTunnelDst.class); | ||
81 | + codecService.unregisterCodec(NiciraSetNshContextHeader.class); | ||
82 | + log.info("Unregistered default driver codecs."); | ||
83 | + } | ||
84 | +} |
... | @@ -16,6 +16,8 @@ | ... | @@ -16,6 +16,8 @@ |
16 | 16 | ||
17 | package org.onosproject.driver.extensions; | 17 | package org.onosproject.driver.extensions; |
18 | 18 | ||
19 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
20 | +import org.onosproject.codec.CodecContext; | ||
19 | import org.onosproject.net.behaviour.ExtensionSelectorResolver; | 21 | import org.onosproject.net.behaviour.ExtensionSelectorResolver; |
20 | import org.onosproject.net.driver.AbstractHandlerBehaviour; | 22 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
21 | import org.onosproject.net.flow.criteria.ExtensionSelector; | 23 | import org.onosproject.net.flow.criteria.ExtensionSelector; |
... | @@ -99,4 +101,16 @@ public class NiciraExtensionSelectorInterpreter | ... | @@ -99,4 +101,16 @@ public class NiciraExtensionSelectorInterpreter |
99 | } | 101 | } |
100 | return null; | 102 | return null; |
101 | } | 103 | } |
104 | + | ||
105 | + @Override | ||
106 | + public ObjectNode encode(ExtensionSelector extensionSelector, CodecContext context) { | ||
107 | + // TODO | ||
108 | + return null; | ||
109 | + } | ||
110 | + | ||
111 | + @Override | ||
112 | + public ExtensionSelector decode(ObjectNode json, CodecContext context) { | ||
113 | + // TODO | ||
114 | + return null; | ||
115 | + } | ||
102 | } | 116 | } | ... | ... |
... | @@ -16,7 +16,9 @@ | ... | @@ -16,7 +16,9 @@ |
16 | 16 | ||
17 | package org.onosproject.driver.extensions; | 17 | package org.onosproject.driver.extensions; |
18 | 18 | ||
19 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
19 | import org.onlab.packet.Ip4Address; | 20 | import org.onlab.packet.Ip4Address; |
21 | +import org.onosproject.codec.CodecContext; | ||
20 | import org.onosproject.net.PortNumber; | 22 | import org.onosproject.net.PortNumber; |
21 | import org.onosproject.net.behaviour.ExtensionTreatmentResolver; | 23 | import org.onosproject.net.behaviour.ExtensionTreatmentResolver; |
22 | import org.onosproject.net.driver.AbstractHandlerBehaviour; | 24 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
... | @@ -35,6 +37,9 @@ import org.projectfloodlight.openflow.protocol.oxm.OFOxm; | ... | @@ -35,6 +37,9 @@ import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
35 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmTunnelIpv4Dst; | 37 | import org.projectfloodlight.openflow.protocol.oxm.OFOxmTunnelIpv4Dst; |
36 | import org.projectfloodlight.openflow.types.IPv4Address; | 38 | import org.projectfloodlight.openflow.types.IPv4Address; |
37 | 39 | ||
40 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
41 | +import static org.onlab.util.Tools.nullIsIllegal; | ||
42 | + | ||
38 | /** | 43 | /** |
39 | * Interpreter for Nicira OpenFlow treatment extensions. | 44 | * Interpreter for Nicira OpenFlow treatment extensions. |
40 | */ | 45 | */ |
... | @@ -50,6 +55,18 @@ public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviou | ... | @@ -50,6 +55,18 @@ public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviou |
50 | private static final int SUB_TYPE_RESUBMIT = 1; | 55 | private static final int SUB_TYPE_RESUBMIT = 1; |
51 | private static final int SUB_TYPE_MOVE = 6; | 56 | private static final int SUB_TYPE_MOVE = 6; |
52 | 57 | ||
58 | + private static final String TUNNEL_DST = "tunnelDst"; | ||
59 | + private static final String RESUBMIT = "resubmit"; | ||
60 | + private static final String RESUBMIT_TABLE = "resubmitTable"; | ||
61 | + private static final String NICIRA_NSH_SPI = "niciraNshSpi"; | ||
62 | + private static final String NICIRA_NSH_SI = "niciraNshSi"; | ||
63 | + private static final String NICIRA_NSH_CH = "niciraNshCh"; | ||
64 | + private static final String NICIRA_MOVE = "niciraMove"; | ||
65 | + | ||
66 | + private static final String TYPE = "type"; | ||
67 | + | ||
68 | + private static final String MISSING_MEMBER_MESSAGE = " member is required in NiciraExtensionTreatmentInterpreter"; | ||
69 | + | ||
53 | @Override | 70 | @Override |
54 | public boolean supported(ExtensionTreatmentType extensionTreatmentType) { | 71 | public boolean supported(ExtensionTreatmentType extensionTreatmentType) { |
55 | if (extensionTreatmentType.equals( | 72 | if (extensionTreatmentType.equals( |
... | @@ -250,4 +267,106 @@ public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviou | ... | @@ -250,4 +267,106 @@ public class NiciraExtensionTreatmentInterpreter extends AbstractHandlerBehaviou |
250 | throw new UnsupportedOperationException( | 267 | throw new UnsupportedOperationException( |
251 | "Driver does not support extension type " + type.toString()); | 268 | "Driver does not support extension type " + type.toString()); |
252 | } | 269 | } |
270 | + | ||
271 | + @Override | ||
272 | + public ObjectNode encode(ExtensionTreatment extensionTreatment, CodecContext context) { | ||
273 | + checkNotNull(extensionTreatment, "Extension treatment cannot be null"); | ||
274 | + ExtensionTreatmentType type = extensionTreatment.type(); | ||
275 | + ObjectNode root = context.mapper().createObjectNode(); | ||
276 | + | ||
277 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { | ||
278 | + NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionTreatment; | ||
279 | + root.set(TUNNEL_DST, context.codec(NiciraSetTunnelDst.class).encode(tunnelDst, context)); | ||
280 | + } | ||
281 | + | ||
282 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { | ||
283 | + NiciraResubmit resubmit = (NiciraResubmit) extensionTreatment; | ||
284 | + root.set(RESUBMIT, context.codec(NiciraResubmit.class).encode(resubmit, context)); | ||
285 | + } | ||
286 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { | ||
287 | + NiciraResubmitTable resubmitTable = (NiciraResubmitTable) extensionTreatment; | ||
288 | + root.set(RESUBMIT_TABLE, context.codec(NiciraResubmitTable.class).encode(resubmitTable, context)); | ||
289 | + } | ||
290 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { | ||
291 | + NiciraSetNshSpi niciraNshSpi = (NiciraSetNshSpi) extensionTreatment; | ||
292 | + root.set(NICIRA_NSH_SPI, context.codec(NiciraSetNshSpi.class).encode(niciraNshSpi, context)); | ||
293 | + } | ||
294 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { | ||
295 | + NiciraSetNshSi niciraNshSi = (NiciraSetNshSi) extensionTreatment; | ||
296 | + root.set(NICIRA_NSH_SI, context.codec(NiciraSetNshSi.class).encode(niciraNshSi, context)); | ||
297 | + } | ||
298 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) { | ||
299 | + NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; | ||
300 | + root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context)); | ||
301 | + } | ||
302 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) { | ||
303 | + NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; | ||
304 | + root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context)); | ||
305 | + } | ||
306 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) { | ||
307 | + NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; | ||
308 | + root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context)); | ||
309 | + } | ||
310 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { | ||
311 | + NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment; | ||
312 | + root.set(NICIRA_NSH_CH, context.codec(NiciraSetNshContextHeader.class).encode(niciraNshch, context)); | ||
313 | + } | ||
314 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type()) | ||
315 | + || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type()) | ||
316 | + || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type()) | ||
317 | + || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { | ||
318 | + MoveExtensionTreatment mov = (MoveExtensionTreatment) extensionTreatment; | ||
319 | + root.set(NICIRA_MOVE, context.codec(MoveExtensionTreatment.class).encode(mov, context)); | ||
320 | + } | ||
321 | + | ||
322 | + return root; | ||
323 | + } | ||
324 | + | ||
325 | + @Override | ||
326 | + public ExtensionTreatment decode(ObjectNode json, CodecContext context) { | ||
327 | + if (json == null || !json.isObject()) { | ||
328 | + return null; | ||
329 | + } | ||
330 | + | ||
331 | + // parse extension type | ||
332 | + int typeInt = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asInt(); | ||
333 | + ExtensionTreatmentType type = new ExtensionTreatmentType(typeInt); | ||
334 | + | ||
335 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { | ||
336 | + return context.codec(NiciraSetTunnelDst.class).decode(json, context); | ||
337 | + } | ||
338 | + | ||
339 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) { | ||
340 | + return context.codec(NiciraResubmit.class).decode(json, context); | ||
341 | + } | ||
342 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) { | ||
343 | + return context.codec(NiciraResubmitTable.class).decode(json, context); | ||
344 | + } | ||
345 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) { | ||
346 | + return context.codec(NiciraSetNshSpi.class).decode(json, context); | ||
347 | + } | ||
348 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) { | ||
349 | + return context.codec(NiciraSetNshSi.class).decode(json, context); | ||
350 | + } | ||
351 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) { | ||
352 | + return context.codec(NiciraSetNshContextHeader.class).decode(json, context); | ||
353 | + } | ||
354 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) { | ||
355 | + return context.codec(NiciraSetNshContextHeader.class).decode(json, context); | ||
356 | + } | ||
357 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) { | ||
358 | + return context.codec(NiciraSetNshContextHeader.class).decode(json, context); | ||
359 | + } | ||
360 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) { | ||
361 | + return context.codec(NiciraSetNshContextHeader.class).decode(json, context); | ||
362 | + } | ||
363 | + if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type()) | ||
364 | + || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type()) | ||
365 | + || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type()) | ||
366 | + || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type())) { | ||
367 | + return context.codec(MoveExtensionTreatment.class).decode(json, context); | ||
368 | + } | ||
369 | + throw new UnsupportedOperationException( | ||
370 | + "Driver does not support extension type " + type.toString()); | ||
371 | + } | ||
253 | } | 372 | } | ... | ... |
... | @@ -15,15 +15,15 @@ | ... | @@ -15,15 +15,15 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.driver.extensions; | 16 | package org.onosproject.driver.extensions; |
17 | 17 | ||
18 | -import static com.google.common.base.MoreObjects.toStringHelper; | ||
19 | - | ||
20 | -import java.util.Objects; | ||
21 | - | ||
22 | import org.onlab.util.KryoNamespace; | 18 | import org.onlab.util.KryoNamespace; |
23 | import org.onosproject.net.NshServiceIndex; | 19 | import org.onosproject.net.NshServiceIndex; |
24 | import org.onosproject.net.flow.AbstractExtension; | 20 | import org.onosproject.net.flow.AbstractExtension; |
25 | import org.onosproject.net.flow.criteria.ExtensionSelector; | 21 | import org.onosproject.net.flow.criteria.ExtensionSelector; |
26 | import org.onosproject.net.flow.criteria.ExtensionSelectorType; | 22 | import org.onosproject.net.flow.criteria.ExtensionSelectorType; |
23 | + | ||
24 | +import java.util.Objects; | ||
25 | + | ||
26 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
27 | /** | 27 | /** |
28 | * Implementation of NSH Service Index(SI). | 28 | * Implementation of NSH Service Index(SI). |
29 | */ | 29 | */ |
... | @@ -42,6 +42,15 @@ public final class NiciraMatchNshSi extends AbstractExtension implements Extensi | ... | @@ -42,6 +42,15 @@ public final class NiciraMatchNshSi extends AbstractExtension implements Extensi |
42 | } | 42 | } |
43 | 43 | ||
44 | /** | 44 | /** |
45 | + * Creates an instance with initialized Nsh Service Index. | ||
46 | + * | ||
47 | + * @param nshSi nsh service index | ||
48 | + */ | ||
49 | + public NiciraMatchNshSi(NshServiceIndex nshSi) { | ||
50 | + this.nshSi = nshSi; | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
45 | * Gets the nsh service index to match. | 54 | * Gets the nsh service index to match. |
46 | * | 55 | * |
47 | * @return the si to match | 56 | * @return the si to match | ... | ... |
... | @@ -41,6 +41,15 @@ public final class NiciraMatchNshSpi extends AbstractExtension implements Extens | ... | @@ -41,6 +41,15 @@ public final class NiciraMatchNshSpi extends AbstractExtension implements Extens |
41 | } | 41 | } |
42 | 42 | ||
43 | /** | 43 | /** |
44 | + * Creates an instance with initialized Nsh Service Path ID. | ||
45 | + * | ||
46 | + * @param nshSpi nsh service path ID | ||
47 | + */ | ||
48 | + public NiciraMatchNshSpi(NshServicePathId nshSpi) { | ||
49 | + this.nshSpi = nshSpi; | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
44 | * Gets the network service path id to match. | 53 | * Gets the network service path id to match. |
45 | * | 54 | * |
46 | * @return the nshSpi to match | 55 | * @return the nshSpi to match | ... | ... |
... | @@ -53,7 +53,7 @@ public class NiciraSetNshContextHeader extends AbstractExtension implements | ... | @@ -53,7 +53,7 @@ public class NiciraSetNshContextHeader extends AbstractExtension implements |
53 | * @param nshCh nsh context header | 53 | * @param nshCh nsh context header |
54 | * @param type extension treatment type | 54 | * @param type extension treatment type |
55 | */ | 55 | */ |
56 | - NiciraSetNshContextHeader(NshContextHeader nshCh, ExtensionTreatmentType type) { | 56 | + public NiciraSetNshContextHeader(NshContextHeader nshCh, ExtensionTreatmentType type) { |
57 | this.nshCh = nshCh; | 57 | this.nshCh = nshCh; |
58 | this.type = type; | 58 | this.type = type; |
59 | } | 59 | } | ... | ... |
... | @@ -48,7 +48,7 @@ public class NiciraSetNshSi extends AbstractExtension implements | ... | @@ -48,7 +48,7 @@ public class NiciraSetNshSi extends AbstractExtension implements |
48 | * | 48 | * |
49 | * @param nshSi nsh service index | 49 | * @param nshSi nsh service index |
50 | */ | 50 | */ |
51 | - NiciraSetNshSi(NshServiceIndex nshSi) { | 51 | + public NiciraSetNshSi(NshServiceIndex nshSi) { |
52 | this.nshSi = nshSi; | 52 | this.nshSi = nshSi; |
53 | } | 53 | } |
54 | 54 | ... | ... |
... | @@ -48,7 +48,7 @@ public class NiciraSetNshSpi extends AbstractExtension implements | ... | @@ -48,7 +48,7 @@ public class NiciraSetNshSpi extends AbstractExtension implements |
48 | * | 48 | * |
49 | * @param nshSpi nsh service path id | 49 | * @param nshSpi nsh service path id |
50 | */ | 50 | */ |
51 | - NiciraSetNshSpi(NshServicePathId nshSpi) { | 51 | + public NiciraSetNshSpi(NshServicePathId nshSpi) { |
52 | this.nshSpi = nshSpi; | 52 | this.nshSpi = nshSpi; |
53 | } | 53 | } |
54 | 54 | ... | ... |
... | @@ -54,7 +54,7 @@ public class NiciraSetTunnelDst extends AbstractExtension implements | ... | @@ -54,7 +54,7 @@ public class NiciraSetTunnelDst extends AbstractExtension implements |
54 | * | 54 | * |
55 | * @param tunnelDst tunnel destination IPv4 address | 55 | * @param tunnelDst tunnel destination IPv4 address |
56 | */ | 56 | */ |
57 | - NiciraSetTunnelDst(Ip4Address tunnelDst) { | 57 | + public NiciraSetTunnelDst(Ip4Address tunnelDst) { |
58 | checkNotNull(tunnelDst); | 58 | checkNotNull(tunnelDst); |
59 | this.tunnelDst = tunnelDst; | 59 | this.tunnelDst = tunnelDst; |
60 | } | 60 | } | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016-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.driver.extensions.codec; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
19 | +import org.onosproject.codec.CodecContext; | ||
20 | +import org.onosproject.codec.JsonCodec; | ||
21 | +import org.onosproject.driver.extensions.DefaultMoveExtensionTreatment; | ||
22 | +import org.onosproject.driver.extensions.MoveExtensionTreatment; | ||
23 | +import org.onosproject.net.flow.instructions.ExtensionTreatmentType; | ||
24 | + | ||
25 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
26 | +import static org.onlab.util.Tools.nullIsIllegal; | ||
27 | + | ||
28 | +/** | ||
29 | + * JSON Codec for MoveExtensionTreatment class. | ||
30 | + */ | ||
31 | +public final class MoveExtensionTreatmentCodec extends JsonCodec<MoveExtensionTreatment> { | ||
32 | + | ||
33 | + private static final String SRC_OFS = "srcOfs"; | ||
34 | + private static final String DST_OFS = "dstOfs"; | ||
35 | + private static final String N_BITS = "nBits"; | ||
36 | + private static final String SRC = "src"; | ||
37 | + private static final String DST = "dst"; | ||
38 | + private static final String TYPE = "type"; | ||
39 | + | ||
40 | + private static final String MISSING_MEMBER_MESSAGE = " member is required in MoveExtensionTreatment"; | ||
41 | + | ||
42 | + @Override | ||
43 | + public ObjectNode encode(MoveExtensionTreatment moveExtensionTreatment, CodecContext context) { | ||
44 | + checkNotNull(moveExtensionTreatment, "Move Extension Treatment cannot be null"); | ||
45 | + ObjectNode root = context.mapper().createObjectNode() | ||
46 | + .put(SRC_OFS, moveExtensionTreatment.srcOffset()) | ||
47 | + .put(DST_OFS, moveExtensionTreatment.dstOffset()) | ||
48 | + .put(N_BITS, moveExtensionTreatment.nBits()) | ||
49 | + .put(SRC, moveExtensionTreatment.src()) | ||
50 | + .put(DST, moveExtensionTreatment.dst()); | ||
51 | + return root; | ||
52 | + } | ||
53 | + | ||
54 | + @Override | ||
55 | + public MoveExtensionTreatment decode(ObjectNode json, CodecContext context) { | ||
56 | + if (json == null || !json.isObject()) { | ||
57 | + return null; | ||
58 | + } | ||
59 | + | ||
60 | + // parse extension treatment type | ||
61 | + ExtensionTreatmentType type = new ExtensionTreatmentType(nullIsIllegal(json.get(TYPE), | ||
62 | + TYPE + MISSING_MEMBER_MESSAGE).asInt()); | ||
63 | + | ||
64 | + // parse src off set | ||
65 | + int srcOfs = nullIsIllegal(json.get(SRC_OFS), SRC_OFS + MISSING_MEMBER_MESSAGE).asInt(); | ||
66 | + | ||
67 | + // parse dst off set | ||
68 | + int dstOfs = nullIsIllegal(json.get(DST_OFS), DST_OFS + MISSING_MEMBER_MESSAGE).asInt(); | ||
69 | + | ||
70 | + // parse n bits | ||
71 | + int nBits = nullIsIllegal(json.get(N_BITS), N_BITS + MISSING_MEMBER_MESSAGE).asInt(); | ||
72 | + | ||
73 | + // parse src | ||
74 | + int src = nullIsIllegal(json.get(SRC), SRC + MISSING_MEMBER_MESSAGE).asInt(); | ||
75 | + | ||
76 | + // parse dst | ||
77 | + int dst = nullIsIllegal(json.get(DST), DST + MISSING_MEMBER_MESSAGE).asInt(); | ||
78 | + | ||
79 | + MoveExtensionTreatment moveExtensionTreatment = | ||
80 | + new DefaultMoveExtensionTreatment(srcOfs, dstOfs, nBits, src, dst, type); | ||
81 | + | ||
82 | + return moveExtensionTreatment; | ||
83 | + } | ||
84 | +} |
drivers/default/src/main/java/org/onosproject/driver/extensions/codec/NiciraMatchNshSiCodec.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-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.driver.extensions.codec; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
19 | +import org.onosproject.codec.CodecContext; | ||
20 | +import org.onosproject.codec.JsonCodec; | ||
21 | +import org.onosproject.driver.extensions.NiciraMatchNshSi; | ||
22 | +import org.onosproject.net.NshServiceIndex; | ||
23 | + | ||
24 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
25 | +import static org.onlab.util.Tools.nullIsIllegal; | ||
26 | + | ||
27 | +/** | ||
28 | + * JSON Codec for NiciraMatchNshSi class. | ||
29 | + */ | ||
30 | +public final class NiciraMatchNshSiCodec extends JsonCodec<NiciraMatchNshSi> { | ||
31 | + | ||
32 | + private static final String NSH_SERVICE_INDEX = "nsi"; | ||
33 | + | ||
34 | + private static final String MISSING_MEMBER_MESSAGE = " member is required in NiciraMatchNshSi"; | ||
35 | + | ||
36 | + @Override | ||
37 | + public ObjectNode encode(NiciraMatchNshSi niciraMatchNshSi, CodecContext context) { | ||
38 | + checkNotNull(niciraMatchNshSi, "Nicira Match Nsh Si cannot be null"); | ||
39 | + ObjectNode root = context.mapper().createObjectNode() | ||
40 | + .put(NSH_SERVICE_INDEX, niciraMatchNshSi.nshSi().serviceIndex()); | ||
41 | + return root; | ||
42 | + } | ||
43 | + | ||
44 | + @Override | ||
45 | + public NiciraMatchNshSi decode(ObjectNode json, CodecContext context) { | ||
46 | + if (json == null || !json.isObject()) { | ||
47 | + return null; | ||
48 | + } | ||
49 | + | ||
50 | + // parse nsh service index | ||
51 | + short nshSiShort = (short) nullIsIllegal(json.get(NSH_SERVICE_INDEX), | ||
52 | + NSH_SERVICE_INDEX + MISSING_MEMBER_MESSAGE).asInt(); | ||
53 | + NshServiceIndex nshSi = NshServiceIndex.of(nshSiShort); | ||
54 | + | ||
55 | + NiciraMatchNshSi niciraMatchNshSi = new NiciraMatchNshSi(nshSi); | ||
56 | + | ||
57 | + return niciraMatchNshSi; | ||
58 | + } | ||
59 | +} |
drivers/default/src/main/java/org/onosproject/driver/extensions/codec/NiciraMatchNshSpiCodec.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-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.driver.extensions.codec; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
19 | +import org.onosproject.codec.CodecContext; | ||
20 | +import org.onosproject.codec.JsonCodec; | ||
21 | +import org.onosproject.driver.extensions.NiciraMatchNshSpi; | ||
22 | +import org.onosproject.net.NshServicePathId; | ||
23 | + | ||
24 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
25 | +import static org.onlab.util.Tools.nullIsIllegal; | ||
26 | + | ||
27 | +/** | ||
28 | + * JSON Codec for NiciraMatchNshSpi class. | ||
29 | + */ | ||
30 | +public final class NiciraMatchNshSpiCodec extends JsonCodec<NiciraMatchNshSpi> { | ||
31 | + | ||
32 | + private static final String NSH_PATH_ID = "nsp"; | ||
33 | + | ||
34 | + private static final String MISSING_MEMBER_MESSAGE = " member is required in NiciraMatchNshSpi"; | ||
35 | + | ||
36 | + @Override | ||
37 | + public ObjectNode encode(NiciraMatchNshSpi niciraMatchNshSpi, CodecContext context) { | ||
38 | + checkNotNull(niciraMatchNshSpi, "Nicira Match Nsh Spi cannot be null"); | ||
39 | + ObjectNode root = context.mapper().createObjectNode() | ||
40 | + .put(NSH_PATH_ID, niciraMatchNshSpi.nshSpi().servicePathId()); | ||
41 | + return root; | ||
42 | + } | ||
43 | + | ||
44 | + @Override | ||
45 | + public NiciraMatchNshSpi decode(ObjectNode json, CodecContext context) { | ||
46 | + if (json == null || !json.isObject()) { | ||
47 | + return null; | ||
48 | + } | ||
49 | + | ||
50 | + // parse nsh path id | ||
51 | + int nshSpiInt = nullIsIllegal(json.get(NSH_PATH_ID), | ||
52 | + NSH_PATH_ID + MISSING_MEMBER_MESSAGE).asInt(); | ||
53 | + NshServicePathId nshSpi = NshServicePathId.of(nshSpiInt); | ||
54 | + | ||
55 | + NiciraMatchNshSpi niciraMatchNshSpi = new NiciraMatchNshSpi(nshSpi); | ||
56 | + | ||
57 | + return niciraMatchNshSpi; | ||
58 | + } | ||
59 | +} |
drivers/default/src/main/java/org/onosproject/driver/extensions/codec/NiciraResubmitCodec.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-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.driver.extensions.codec; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
19 | +import org.onosproject.codec.CodecContext; | ||
20 | +import org.onosproject.codec.JsonCodec; | ||
21 | +import org.onosproject.driver.extensions.NiciraResubmit; | ||
22 | +import org.onosproject.net.PortNumber; | ||
23 | + | ||
24 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
25 | +import static org.onlab.util.Tools.nullIsIllegal; | ||
26 | + | ||
27 | +/** | ||
28 | + * JSON Codec for NiciraResubmit class. | ||
29 | + */ | ||
30 | +public final class NiciraResubmitCodec extends JsonCodec<NiciraResubmit> { | ||
31 | + | ||
32 | + private static final String RESUBMIT_PORT = "inPort"; | ||
33 | + private static final String RESUBMIT_TABLE = "table"; | ||
34 | + | ||
35 | + private static final String MISSING_MEMBER_MESSAGE = " member is required in NiciraResubmit"; | ||
36 | + | ||
37 | + @Override | ||
38 | + public ObjectNode encode(NiciraResubmit niciraResubmit, CodecContext context) { | ||
39 | + checkNotNull(niciraResubmit, "Nicira Resubmit cannot be null"); | ||
40 | + ObjectNode root = context.mapper().createObjectNode() | ||
41 | + .put(RESUBMIT_PORT, niciraResubmit.inPort().toLong()) | ||
42 | + .put(RESUBMIT_TABLE, niciraResubmit.table()); | ||
43 | + return root; | ||
44 | + } | ||
45 | + | ||
46 | + @Override | ||
47 | + public NiciraResubmit decode(ObjectNode json, CodecContext context) { | ||
48 | + if (json == null || !json.isObject()) { | ||
49 | + return null; | ||
50 | + } | ||
51 | + | ||
52 | + // parse in port number | ||
53 | + long portNumberLong = nullIsIllegal(json.get(RESUBMIT_PORT), RESUBMIT_PORT + MISSING_MEMBER_MESSAGE).asLong(); | ||
54 | + PortNumber portNumber = PortNumber.portNumber(portNumberLong); | ||
55 | + | ||
56 | + NiciraResubmit niciraResubmit = new NiciraResubmit(portNumber); | ||
57 | + | ||
58 | + return niciraResubmit; | ||
59 | + } | ||
60 | +} |
drivers/default/src/main/java/org/onosproject/driver/extensions/codec/NiciraResubmitTableCodec.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-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.driver.extensions.codec; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
19 | +import org.onosproject.codec.CodecContext; | ||
20 | +import org.onosproject.codec.JsonCodec; | ||
21 | +import org.onosproject.driver.extensions.NiciraResubmitTable; | ||
22 | +import org.onosproject.net.PortNumber; | ||
23 | + | ||
24 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
25 | +import static org.onlab.util.Tools.nullIsIllegal; | ||
26 | + | ||
27 | +/** | ||
28 | + * JSON Codec for NiciraResubmitTable class. | ||
29 | + */ | ||
30 | +public final class NiciraResubmitTableCodec extends JsonCodec<NiciraResubmitTable> { | ||
31 | + | ||
32 | + private static final String RESUBMIT_PORT = "inPort"; | ||
33 | + private static final String RESUBMIT_TABLE = "table"; | ||
34 | + | ||
35 | + private static final String MISSING_MEMBER_MESSAGE = " member is required in NiciraResubmitTable"; | ||
36 | + | ||
37 | + @Override | ||
38 | + public ObjectNode encode(NiciraResubmitTable niciraResubmitTable, CodecContext context) { | ||
39 | + checkNotNull(niciraResubmitTable, "Nicira Resubmit Table cannot be null"); | ||
40 | + ObjectNode root = context.mapper().createObjectNode() | ||
41 | + .put(RESUBMIT_PORT, niciraResubmitTable.inPort().toLong()) | ||
42 | + .put(RESUBMIT_TABLE, niciraResubmitTable.table()); | ||
43 | + return root; | ||
44 | + } | ||
45 | + | ||
46 | + @Override | ||
47 | + public NiciraResubmitTable decode(ObjectNode json, CodecContext context) { | ||
48 | + if (json == null || !json.isObject()) { | ||
49 | + return null; | ||
50 | + } | ||
51 | + | ||
52 | + // parse in port number | ||
53 | + long portNumberLong = nullIsIllegal(json.get(RESUBMIT_PORT), | ||
54 | + RESUBMIT_PORT + MISSING_MEMBER_MESSAGE).asLong(); | ||
55 | + PortNumber portNumber = PortNumber.portNumber(portNumberLong); | ||
56 | + | ||
57 | + // parse table id | ||
58 | + short tableId = (short) nullIsIllegal(json.get(RESUBMIT_TABLE), | ||
59 | + RESUBMIT_TABLE + MISSING_MEMBER_MESSAGE).asInt(); | ||
60 | + | ||
61 | + NiciraResubmitTable niciraResubmitTable = new NiciraResubmitTable(portNumber, tableId); | ||
62 | + | ||
63 | + return niciraResubmitTable; | ||
64 | + } | ||
65 | +} |
1 | +/* | ||
2 | + * Copyright 2016-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.driver.extensions.codec; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
19 | +import org.onosproject.codec.CodecContext; | ||
20 | +import org.onosproject.codec.JsonCodec; | ||
21 | +import org.onosproject.driver.extensions.NiciraSetNshContextHeader; | ||
22 | +import org.onosproject.net.NshContextHeader; | ||
23 | +import org.onosproject.net.flow.instructions.ExtensionTreatmentType; | ||
24 | + | ||
25 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
26 | +import static org.onlab.util.Tools.nullIsIllegal; | ||
27 | + | ||
28 | +/** | ||
29 | + * JSON Codec for NiciraSetNshContextHeader class. | ||
30 | + */ | ||
31 | +public class NiciraSetNshContextHeaderCodec extends JsonCodec<NiciraSetNshContextHeader> { | ||
32 | + | ||
33 | + private static final String NSH_CONTEXT_HEADER = "nshch"; | ||
34 | + private static final String TYPE = "type"; | ||
35 | + | ||
36 | + private static final String MISSING_MEMBER_MESSAGE = " member is required in NiciraSetNshContextHeader"; | ||
37 | + | ||
38 | + @Override | ||
39 | + public ObjectNode encode(NiciraSetNshContextHeader niciraSetNshContextHeader, CodecContext context) { | ||
40 | + checkNotNull(niciraSetNshContextHeader, "Nicira Set Nsh Context Header cannot be null"); | ||
41 | + ObjectNode root = context.mapper().createObjectNode() | ||
42 | + .put(NSH_CONTEXT_HEADER, niciraSetNshContextHeader.nshCh().nshContextHeader()) | ||
43 | + .put(TYPE, niciraSetNshContextHeader.type().type()); | ||
44 | + return root; | ||
45 | + } | ||
46 | + | ||
47 | + @Override | ||
48 | + public NiciraSetNshContextHeader decode(ObjectNode json, CodecContext context) { | ||
49 | + if (json == null || !json.isObject()) { | ||
50 | + return null; | ||
51 | + } | ||
52 | + | ||
53 | + // parse nsh context header | ||
54 | + int contextHeaderInt = nullIsIllegal(json.get(NSH_CONTEXT_HEADER), | ||
55 | + NSH_CONTEXT_HEADER + MISSING_MEMBER_MESSAGE).asInt(); | ||
56 | + | ||
57 | + NshContextHeader contextHeader = NshContextHeader.of(contextHeaderInt); | ||
58 | + | ||
59 | + // parse type | ||
60 | + int extensionTypeInt = nullIsIllegal(json.get(TYPE), | ||
61 | + TYPE + MISSING_MEMBER_MESSAGE).asInt(); | ||
62 | + | ||
63 | + ExtensionTreatmentType type = new ExtensionTreatmentType(extensionTypeInt); | ||
64 | + | ||
65 | + NiciraSetNshContextHeader niciraSetNshContextHeader = | ||
66 | + new NiciraSetNshContextHeader(contextHeader, type); | ||
67 | + | ||
68 | + return niciraSetNshContextHeader; | ||
69 | + } | ||
70 | +} |
drivers/default/src/main/java/org/onosproject/driver/extensions/codec/NiciraSetNshSiCodec.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-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.driver.extensions.codec; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
19 | +import org.onosproject.codec.CodecContext; | ||
20 | +import org.onosproject.codec.JsonCodec; | ||
21 | +import org.onosproject.driver.extensions.NiciraSetNshSi; | ||
22 | +import org.onosproject.net.NshServiceIndex; | ||
23 | + | ||
24 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
25 | +import static org.onlab.util.Tools.nullIsIllegal; | ||
26 | + | ||
27 | +/** | ||
28 | + * JSON Codec for NiciraSetNshSi class. | ||
29 | + */ | ||
30 | +public final class NiciraSetNshSiCodec extends JsonCodec<NiciraSetNshSi> { | ||
31 | + | ||
32 | + private static final String NSH_SERVICE_INDEX = "setNsi"; | ||
33 | + | ||
34 | + private static final String MISSING_MEMBER_MESSAGE = " member is required in NiciraSetNshSi"; | ||
35 | + | ||
36 | + @Override | ||
37 | + public ObjectNode encode(NiciraSetNshSi niciraSetNshSi, CodecContext context) { | ||
38 | + checkNotNull(niciraSetNshSi, "Nicira Set Nsh Si cannot be null"); | ||
39 | + ObjectNode root = context.mapper().createObjectNode() | ||
40 | + .put(NSH_SERVICE_INDEX, niciraSetNshSi.nshSi().serviceIndex()); | ||
41 | + return root; | ||
42 | + } | ||
43 | + | ||
44 | + @Override | ||
45 | + public NiciraSetNshSi decode(ObjectNode json, CodecContext context) { | ||
46 | + if (json == null || !json.isObject()) { | ||
47 | + return null; | ||
48 | + } | ||
49 | + | ||
50 | + // parse service index port | ||
51 | + short serviceIndexShort = (short) nullIsIllegal(json.get(NSH_SERVICE_INDEX), | ||
52 | + NSH_SERVICE_INDEX + MISSING_MEMBER_MESSAGE).asInt(); | ||
53 | + | ||
54 | + NshServiceIndex index = NshServiceIndex.of(serviceIndexShort); | ||
55 | + | ||
56 | + NiciraSetNshSi niciraSetNshSi = new NiciraSetNshSi(index); | ||
57 | + | ||
58 | + return niciraSetNshSi; | ||
59 | + } | ||
60 | +} |
drivers/default/src/main/java/org/onosproject/driver/extensions/codec/NiciraSetNshSpiCodec.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-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.driver.extensions.codec; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
19 | +import org.onosproject.codec.CodecContext; | ||
20 | +import org.onosproject.codec.JsonCodec; | ||
21 | +import org.onosproject.driver.extensions.NiciraSetNshSpi; | ||
22 | +import org.onosproject.net.NshServicePathId; | ||
23 | + | ||
24 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
25 | +import static org.onlab.util.Tools.nullIsIllegal; | ||
26 | + | ||
27 | +/** | ||
28 | + * JSON Codec for NiciraSetNshSpi class. | ||
29 | + */ | ||
30 | +public final class NiciraSetNshSpiCodec extends JsonCodec<NiciraSetNshSpi> { | ||
31 | + | ||
32 | + private static final String NSH_PATH_ID = "setNsp"; | ||
33 | + | ||
34 | + private static final String MISSING_MEMBER_MESSAGE = " member is required in NiciraSetNshSpi"; | ||
35 | + | ||
36 | + @Override | ||
37 | + public ObjectNode encode(NiciraSetNshSpi niciraSetNshSpi, CodecContext context) { | ||
38 | + checkNotNull(niciraSetNshSpi, "Nicira Set Nsh Spi cannot be null"); | ||
39 | + ObjectNode root = context.mapper().createObjectNode() | ||
40 | + .put(NSH_PATH_ID, niciraSetNshSpi.nshSpi().servicePathId()); | ||
41 | + return root; | ||
42 | + } | ||
43 | + | ||
44 | + @Override | ||
45 | + public NiciraSetNshSpi decode(ObjectNode json, CodecContext context) { | ||
46 | + if (json == null || !json.isObject()) { | ||
47 | + return null; | ||
48 | + } | ||
49 | + | ||
50 | + // parse service path id | ||
51 | + int servicePathIdInt = nullIsIllegal(json.get(NSH_PATH_ID), | ||
52 | + NSH_PATH_ID + MISSING_MEMBER_MESSAGE).asInt(); | ||
53 | + | ||
54 | + NshServicePathId pathId = NshServicePathId.of(servicePathIdInt); | ||
55 | + | ||
56 | + NiciraSetNshSpi niciraSetNshSpi = new NiciraSetNshSpi(pathId); | ||
57 | + | ||
58 | + return niciraSetNshSpi; | ||
59 | + } | ||
60 | +} |
drivers/default/src/main/java/org/onosproject/driver/extensions/codec/NiciraSetTunnelDstCodec.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-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.driver.extensions.codec; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.node.ObjectNode; | ||
19 | +import org.onlab.packet.Ip4Address; | ||
20 | +import org.onosproject.codec.CodecContext; | ||
21 | +import org.onosproject.codec.JsonCodec; | ||
22 | +import org.onosproject.driver.extensions.NiciraSetTunnelDst; | ||
23 | + | ||
24 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
25 | +import static org.onlab.util.Tools.nullIsIllegal; | ||
26 | + | ||
27 | +/** | ||
28 | + * JSON Codec for NiciraSetTunnelDst class. | ||
29 | + */ | ||
30 | +public final class NiciraSetTunnelDstCodec extends JsonCodec<NiciraSetTunnelDst> { | ||
31 | + | ||
32 | + private static final String TUNNEL_DST = "tunnelDst"; | ||
33 | + | ||
34 | + private static final String MISSING_MEMBER_MESSAGE = " member is required in NiciraSetTunnelDst"; | ||
35 | + | ||
36 | + @Override | ||
37 | + public ObjectNode encode(NiciraSetTunnelDst niciraSetTunnelDst, CodecContext context) { | ||
38 | + checkNotNull(niciraSetTunnelDst, "Nicira Set Tunnel DST cannot be null"); | ||
39 | + ObjectNode root = context.mapper().createObjectNode() | ||
40 | + .put(TUNNEL_DST, niciraSetTunnelDst.tunnelDst().toString()); | ||
41 | + return root; | ||
42 | + } | ||
43 | + | ||
44 | + @Override | ||
45 | + public NiciraSetTunnelDst decode(ObjectNode json, CodecContext context) { | ||
46 | + if (json == null || !json.isObject()) { | ||
47 | + return null; | ||
48 | + } | ||
49 | + | ||
50 | + // parse tunnel destination IP address | ||
51 | + String dstIp = nullIsIllegal(json.get(TUNNEL_DST), TUNNEL_DST + MISSING_MEMBER_MESSAGE).asText(); | ||
52 | + | ||
53 | + Ip4Address tunnelDst = Ip4Address.valueOf(dstIp); | ||
54 | + | ||
55 | + NiciraSetTunnelDst niciraSetTunnelDst = new NiciraSetTunnelDst(tunnelDst); | ||
56 | + | ||
57 | + return niciraSetTunnelDst; | ||
58 | + } | ||
59 | +} |
1 | +/* | ||
2 | + * Copyright 2016-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 | +/** | ||
17 | + * Implementations of the codec broker and NICIRA and OFDPA extension JSON codecs. | ||
18 | + */ | ||
19 | +package org.onosproject.driver.extensions.codec; |
... | @@ -17,7 +17,7 @@ | ... | @@ -17,7 +17,7 @@ |
17 | package org.onosproject.openflow.controller; | 17 | package org.onosproject.openflow.controller; |
18 | 18 | ||
19 | import com.google.common.annotations.Beta; | 19 | import com.google.common.annotations.Beta; |
20 | -import org.onosproject.net.driver.HandlerBehaviour; | 20 | +import org.onosproject.codec.ExtensionSelectorCodec; |
21 | import org.onosproject.net.flow.criteria.ExtensionSelector; | 21 | import org.onosproject.net.flow.criteria.ExtensionSelector; |
22 | import org.onosproject.net.flow.criteria.ExtensionSelectorType; | 22 | import org.onosproject.net.flow.criteria.ExtensionSelectorType; |
23 | import org.projectfloodlight.openflow.protocol.OFFactory; | 23 | import org.projectfloodlight.openflow.protocol.OFFactory; |
... | @@ -27,7 +27,7 @@ import org.projectfloodlight.openflow.protocol.oxm.OFOxm; | ... | @@ -27,7 +27,7 @@ import org.projectfloodlight.openflow.protocol.oxm.OFOxm; |
27 | * Interprets extension selectors and converts them to/from OpenFlow objects. | 27 | * Interprets extension selectors and converts them to/from OpenFlow objects. |
28 | */ | 28 | */ |
29 | @Beta | 29 | @Beta |
30 | -public interface ExtensionSelectorInterpreter extends HandlerBehaviour { | 30 | +public interface ExtensionSelectorInterpreter extends ExtensionSelectorCodec { |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Returns true if the given extension selector is supported by this | 33 | * Returns true if the given extension selector is supported by this | ... | ... |
... | @@ -17,7 +17,7 @@ | ... | @@ -17,7 +17,7 @@ |
17 | package org.onosproject.openflow.controller; | 17 | package org.onosproject.openflow.controller; |
18 | 18 | ||
19 | import com.google.common.annotations.Beta; | 19 | import com.google.common.annotations.Beta; |
20 | -import org.onosproject.net.driver.HandlerBehaviour; | 20 | +import org.onosproject.codec.ExtensionTreatmentCodec; |
21 | import org.onosproject.net.flow.instructions.ExtensionTreatment; | 21 | import org.onosproject.net.flow.instructions.ExtensionTreatment; |
22 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; | 22 | import org.onosproject.net.flow.instructions.ExtensionTreatmentType; |
23 | import org.projectfloodlight.openflow.protocol.OFFactory; | 23 | import org.projectfloodlight.openflow.protocol.OFFactory; |
... | @@ -27,7 +27,7 @@ import org.projectfloodlight.openflow.protocol.action.OFAction; | ... | @@ -27,7 +27,7 @@ import org.projectfloodlight.openflow.protocol.action.OFAction; |
27 | * Interprets extension treatments and converts them to/from OpenFlow objects. | 27 | * Interprets extension treatments and converts them to/from OpenFlow objects. |
28 | */ | 28 | */ |
29 | @Beta | 29 | @Beta |
30 | -public interface ExtensionTreatmentInterpreter extends HandlerBehaviour { | 30 | +public interface ExtensionTreatmentInterpreter extends ExtensionTreatmentCodec { |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Returns true if the given extension treatment is supported by this | 33 | * Returns true if the given extension treatment is supported by this |
... | @@ -55,5 +55,4 @@ public interface ExtensionTreatmentInterpreter extends HandlerBehaviour { | ... | @@ -55,5 +55,4 @@ public interface ExtensionTreatmentInterpreter extends HandlerBehaviour { |
55 | * @throws UnsupportedOperationException if driver does not support extension type | 55 | * @throws UnsupportedOperationException if driver does not support extension type |
56 | */ | 56 | */ |
57 | ExtensionTreatment mapAction(OFAction action) throws UnsupportedOperationException; | 57 | ExtensionTreatment mapAction(OFAction action) throws UnsupportedOperationException; |
58 | - | ||
59 | } | 58 | } | ... | ... |
-
Please register or login to post a comment