use of org.onlab.osgi.DefaultServiceDirectory in project onos by opennetworkinglab.
the class EncodeInstructionCodecHelper method encodeExtension.
/**
* Encodes a extension instruction.
*
* @param result json node that the instruction attributes are added to
*/
private void encodeExtension(ObjectNode result) {
final Instructions.ExtensionInstructionWrapper extensionInstruction = (Instructions.ExtensionInstructionWrapper) instruction;
DeviceId deviceId = extensionInstruction.deviceId();
ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
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)) {
// for extension instructions, encoding device id is needed for the corresponding decoder
result.put("deviceId", deviceId.toString());
ExtensionTreatmentCodec treatmentCodec = device.as(ExtensionTreatmentCodec.class);
ObjectNode node = treatmentCodec.encode(extensionInstruction.extensionInstruction(), context);
result.set(InstructionCodec.EXTENSION, node);
} else {
throw new IllegalArgumentException("There is no codec to encode extension for device " + deviceId.toString());
}
}
use of org.onlab.osgi.DefaultServiceDirectory in project onos by opennetworkinglab.
the class DecodeInstructionCodecHelper method decodeExtension.
/**
* Decodes a extension instruction.
*
* @return extension treatment
*/
private Instruction decodeExtension() {
ObjectNode node = (ObjectNode) json.get(InstructionCodec.EXTENSION);
if (node != null) {
DeviceId deviceId = getDeviceId();
ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
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, context);
return Instructions.extension(treatment, deviceId);
} else {
throw new IllegalArgumentException("There is no codec to decode extension for device " + deviceId.toString());
}
}
return null;
}
use of org.onlab.osgi.DefaultServiceDirectory in project onos by opennetworkinglab.
the class NullProviders method setUp.
// Sets up the topology simulation and all providers.
private void setUp() {
simulator = selectSimulator(topoShape);
simulator.init(topoShape, deviceCount, hostCount, new DefaultServiceDirectory(), deviceProviderService, hostProviderService, linkProviderService);
flowRuleProvider.start(flowRuleProviderService);
groupProvider.start(groupProviderService);
packetProvider.start(packetRate, hostService, deviceService, packetProviderService);
simulator.setUpTopology();
groupProvider.initDevicesGroupTable(simulator.deviceIds);
topologyMutationDriver.start(mutationRate, linkService, deviceService, linkProviderService, deviceProviderService, simulator);
}
Aggregations