Fix bugs in extension treatment REST API
Change-Id: If47f5ffce634617200e765be72c7898d984b0786
Showing
4 changed files
with
22 additions
and
5 deletions
... | @@ -25,6 +25,7 @@ import org.onlab.packet.MplsLabel; | ... | @@ -25,6 +25,7 @@ import org.onlab.packet.MplsLabel; |
25 | import org.onlab.packet.TpPort; | 25 | import org.onlab.packet.TpPort; |
26 | import org.onlab.packet.VlanId; | 26 | import org.onlab.packet.VlanId; |
27 | import org.onlab.util.HexString; | 27 | import org.onlab.util.HexString; |
28 | +import org.onosproject.codec.CodecContext; | ||
28 | import org.onosproject.codec.ExtensionTreatmentCodec; | 29 | import org.onosproject.codec.ExtensionTreatmentCodec; |
29 | import org.onosproject.core.DefaultGroupId; | 30 | import org.onosproject.core.DefaultGroupId; |
30 | import org.onosproject.core.GroupId; | 31 | import org.onosproject.core.GroupId; |
... | @@ -56,14 +57,16 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -56,14 +57,16 @@ import static org.slf4j.LoggerFactory.getLogger; |
56 | public final class DecodeInstructionCodecHelper { | 57 | public final class DecodeInstructionCodecHelper { |
57 | protected static final Logger log = getLogger(DecodeInstructionCodecHelper.class); | 58 | protected static final Logger log = getLogger(DecodeInstructionCodecHelper.class); |
58 | private final ObjectNode json; | 59 | private final ObjectNode json; |
60 | + private final CodecContext context; | ||
59 | 61 | ||
60 | /** | 62 | /** |
61 | * Creates a decode instruction codec object. | 63 | * Creates a decode instruction codec object. |
62 | * | 64 | * |
63 | * @param json JSON object to decode | 65 | * @param json JSON object to decode |
64 | */ | 66 | */ |
65 | - public DecodeInstructionCodecHelper(ObjectNode json) { | 67 | + public DecodeInstructionCodecHelper(ObjectNode json, CodecContext context) { |
66 | this.json = json; | 68 | this.json = json; |
69 | + this.context = context; | ||
67 | } | 70 | } |
68 | 71 | ||
69 | /** | 72 | /** |
... | @@ -251,12 +254,17 @@ public final class DecodeInstructionCodecHelper { | ... | @@ -251,12 +254,17 @@ public final class DecodeInstructionCodecHelper { |
251 | DeviceService deviceService = serviceDirectory.get(DeviceService.class); | 254 | DeviceService deviceService = serviceDirectory.get(DeviceService.class); |
252 | Device device = deviceService.getDevice(deviceId); | 255 | Device device = deviceService.getDevice(deviceId); |
253 | 256 | ||
257 | + if (device == null) { | ||
258 | + throw new IllegalArgumentException("Device not found"); | ||
259 | + } | ||
260 | + | ||
254 | if (device.is(ExtensionTreatmentCodec.class)) { | 261 | if (device.is(ExtensionTreatmentCodec.class)) { |
255 | ExtensionTreatmentCodec treatmentCodec = device.as(ExtensionTreatmentCodec.class); | 262 | ExtensionTreatmentCodec treatmentCodec = device.as(ExtensionTreatmentCodec.class); |
256 | - ExtensionTreatment treatment = treatmentCodec.decode(node, null); | 263 | + ExtensionTreatment treatment = treatmentCodec.decode(node, context); |
257 | return Instructions.extension(treatment, deviceId); | 264 | return Instructions.extension(treatment, deviceId); |
258 | } else { | 265 | } else { |
259 | - log.warn("There is no codec to decode extension for device {}", deviceId.toString()); | 266 | + throw new IllegalArgumentException( |
267 | + "There is no codec to decode extension for device " + deviceId.toString()); | ||
260 | } | 268 | } |
261 | } | 269 | } |
262 | return null; | 270 | return null; | ... | ... |
... | @@ -241,12 +241,17 @@ public final class EncodeInstructionCodecHelper { | ... | @@ -241,12 +241,17 @@ public final class EncodeInstructionCodecHelper { |
241 | DeviceService deviceService = serviceDirectory.get(DeviceService.class); | 241 | DeviceService deviceService = serviceDirectory.get(DeviceService.class); |
242 | Device device = deviceService.getDevice(deviceId); | 242 | Device device = deviceService.getDevice(deviceId); |
243 | 243 | ||
244 | + if (device == null) { | ||
245 | + throw new IllegalArgumentException("Device not found"); | ||
246 | + } | ||
247 | + | ||
244 | if (device.is(ExtensionTreatmentCodec.class)) { | 248 | if (device.is(ExtensionTreatmentCodec.class)) { |
245 | ExtensionTreatmentCodec treatmentCodec = device.as(ExtensionTreatmentCodec.class); | 249 | ExtensionTreatmentCodec treatmentCodec = device.as(ExtensionTreatmentCodec.class); |
246 | ObjectNode node = treatmentCodec.encode(extensionInstruction.extensionInstruction(), context); | 250 | ObjectNode node = treatmentCodec.encode(extensionInstruction.extensionInstruction(), context); |
247 | result.set(InstructionCodec.EXTENSION, node); | 251 | result.set(InstructionCodec.EXTENSION, node); |
248 | } else { | 252 | } else { |
249 | - log.warn("There is no codec to encode extension for device {}", deviceId.toString()); | 253 | + throw new IllegalArgumentException( |
254 | + "There is no codec to encode extension for device " + deviceId.toString()); | ||
250 | } | 255 | } |
251 | } | 256 | } |
252 | 257 | ... | ... |
... | @@ -77,6 +77,6 @@ public final class InstructionCodec extends JsonCodec<Instruction> { | ... | @@ -77,6 +77,6 @@ public final class InstructionCodec extends JsonCodec<Instruction> { |
77 | return null; | 77 | return null; |
78 | } | 78 | } |
79 | 79 | ||
80 | - return new DecodeInstructionCodecHelper(json).decode(); | 80 | + return new DecodeInstructionCodecHelper(json, context).decode(); |
81 | } | 81 | } |
82 | } | 82 | } | ... | ... |
... | @@ -30,10 +30,14 @@ | ... | @@ -30,10 +30,14 @@ |
30 | impl="org.onosproject.driver.extensions.NiciraExtensionTreatmentInterpreter" /> | 30 | impl="org.onosproject.driver.extensions.NiciraExtensionTreatmentInterpreter" /> |
31 | <behaviour api="org.onosproject.net.behaviour.ExtensionTreatmentResolver" | 31 | <behaviour api="org.onosproject.net.behaviour.ExtensionTreatmentResolver" |
32 | impl="org.onosproject.driver.extensions.NiciraExtensionTreatmentInterpreter" /> | 32 | impl="org.onosproject.driver.extensions.NiciraExtensionTreatmentInterpreter" /> |
33 | + <behaviour api="org.onosproject.codec.ExtensionTreatmentCodec" | ||
34 | + impl="org.onosproject.driver.extensions.NiciraExtensionTreatmentInterpreter" /> | ||
33 | <behaviour api="org.onosproject.openflow.controller.ExtensionSelectorInterpreter" | 35 | <behaviour api="org.onosproject.openflow.controller.ExtensionSelectorInterpreter" |
34 | impl="org.onosproject.driver.extensions.NiciraExtensionSelectorInterpreter" /> | 36 | impl="org.onosproject.driver.extensions.NiciraExtensionSelectorInterpreter" /> |
35 | <behaviour api="org.onosproject.net.behaviour.ExtensionSelectorResolver" | 37 | <behaviour api="org.onosproject.net.behaviour.ExtensionSelectorResolver" |
36 | impl="org.onosproject.driver.extensions.NiciraExtensionSelectorInterpreter" /> | 38 | impl="org.onosproject.driver.extensions.NiciraExtensionSelectorInterpreter" /> |
39 | + <behaviour api="org.onosproject.codec.ExtensionSelectorCodec" | ||
40 | + impl="org.onosproject.driver.extensions.NiciraExtensionSelectorInterpreter" /> | ||
37 | <behaviour api="org.onosproject.net.behaviour.VlanQuery" | 41 | <behaviour api="org.onosproject.net.behaviour.VlanQuery" |
38 | impl="org.onosproject.driver.query.FullVlanAvailable" /> | 42 | impl="org.onosproject.driver.query.FullVlanAvailable" /> |
39 | <behaviour api="org.onosproject.net.behaviour.MplsQuery" | 43 | <behaviour api="org.onosproject.net.behaviour.MplsQuery" | ... | ... |
-
Please register or login to post a comment