Jonathan Hart

Fix bugs in extension treatment REST API

Change-Id: If47f5ffce634617200e765be72c7898d984b0786
......@@ -25,6 +25,7 @@ import org.onlab.packet.MplsLabel;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onlab.util.HexString;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.ExtensionTreatmentCodec;
import org.onosproject.core.DefaultGroupId;
import org.onosproject.core.GroupId;
......@@ -56,14 +57,16 @@ import static org.slf4j.LoggerFactory.getLogger;
public final class DecodeInstructionCodecHelper {
protected static final Logger log = getLogger(DecodeInstructionCodecHelper.class);
private final ObjectNode json;
private final CodecContext context;
/**
* Creates a decode instruction codec object.
*
* @param json JSON object to decode
*/
public DecodeInstructionCodecHelper(ObjectNode json) {
public DecodeInstructionCodecHelper(ObjectNode json, CodecContext context) {
this.json = json;
this.context = context;
}
/**
......@@ -251,12 +254,17 @@ public final class DecodeInstructionCodecHelper {
DeviceService deviceService = serviceDirectory.get(DeviceService.class);
Device device = deviceService.getDevice(deviceId);
if (device == null) {
throw new IllegalArgumentException("Device not found");
}
if (device.is(ExtensionTreatmentCodec.class)) {
ExtensionTreatmentCodec treatmentCodec = device.as(ExtensionTreatmentCodec.class);
ExtensionTreatment treatment = treatmentCodec.decode(node, null);
ExtensionTreatment treatment = treatmentCodec.decode(node, context);
return Instructions.extension(treatment, deviceId);
} else {
log.warn("There is no codec to decode extension for device {}", deviceId.toString());
throw new IllegalArgumentException(
"There is no codec to decode extension for device " + deviceId.toString());
}
}
return null;
......
......@@ -241,12 +241,17 @@ public final class EncodeInstructionCodecHelper {
DeviceService deviceService = serviceDirectory.get(DeviceService.class);
Device device = deviceService.getDevice(deviceId);
if (device == null) {
throw new IllegalArgumentException("Device not found");
}
if (device.is(ExtensionTreatmentCodec.class)) {
ExtensionTreatmentCodec treatmentCodec = device.as(ExtensionTreatmentCodec.class);
ObjectNode node = treatmentCodec.encode(extensionInstruction.extensionInstruction(), context);
result.set(InstructionCodec.EXTENSION, node);
} else {
log.warn("There is no codec to encode extension for device {}", deviceId.toString());
throw new IllegalArgumentException(
"There is no codec to encode extension for device " + deviceId.toString());
}
}
......
......@@ -77,6 +77,6 @@ public final class InstructionCodec extends JsonCodec<Instruction> {
return null;
}
return new DecodeInstructionCodecHelper(json).decode();
return new DecodeInstructionCodecHelper(json, context).decode();
}
}
......
......@@ -30,10 +30,14 @@
impl="org.onosproject.driver.extensions.NiciraExtensionTreatmentInterpreter" />
<behaviour api="org.onosproject.net.behaviour.ExtensionTreatmentResolver"
impl="org.onosproject.driver.extensions.NiciraExtensionTreatmentInterpreter" />
<behaviour api="org.onosproject.codec.ExtensionTreatmentCodec"
impl="org.onosproject.driver.extensions.NiciraExtensionTreatmentInterpreter" />
<behaviour api="org.onosproject.openflow.controller.ExtensionSelectorInterpreter"
impl="org.onosproject.driver.extensions.NiciraExtensionSelectorInterpreter" />
<behaviour api="org.onosproject.net.behaviour.ExtensionSelectorResolver"
impl="org.onosproject.driver.extensions.NiciraExtensionSelectorInterpreter" />
<behaviour api="org.onosproject.codec.ExtensionSelectorCodec"
impl="org.onosproject.driver.extensions.NiciraExtensionSelectorInterpreter" />
<behaviour api="org.onosproject.net.behaviour.VlanQuery"
impl="org.onosproject.driver.query.FullVlanAvailable" />
<behaviour api="org.onosproject.net.behaviour.MplsQuery"
......