use of org.onosproject.net.Device 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.onosproject.net.Device in project onos by opennetworkinglab.
the class EdgeManagerTest method defaultPopulator.
/**
* @param numDevices the number of devices to populate.
* @param numInfraPorts the number of ports to be set as infrastructure on each device, numbered base 0, ports 0
* through numInfraPorts - 1
*/
private void defaultPopulator(int numDevices, int numInfraPorts) {
for (int device = 0; device < numDevices; device++) {
String str = Integer.toString(device);
Device deviceToAdd = NetTestTools.device(str);
devices.put(deviceToAdd.id(), deviceToAdd);
testDeviceManager.listener.event(new DeviceEvent(DEVICE_ADDED, deviceToAdd));
for (int port = 1; port <= numInfraPorts; port++) {
testLinkService.listener.event(new LinkEvent(LINK_ADDED, NetTestTools.link(str, port, "other", 1)));
infrastructurePorts.add(NetTestTools.connectPoint(str, port));
}
}
}
use of org.onosproject.net.Device in project onos by opennetworkinglab.
the class EdgeManagerTest method testEmit.
@Test
public void testEmit() {
byte[] arr = new byte[10];
Device referenceDevice;
DeviceEvent event;
int numDevices = 10;
int numInfraPorts = 5;
totalPorts = 10;
defaultPopulator(numDevices, numInfraPorts);
for (byte byteIndex = 0; byteIndex < arr.length; byteIndex++) {
arr[byteIndex] = byteIndex;
}
for (int i = 0; i < numDevices; i++) {
referenceDevice = NetTestTools.device(Integer.toString(i));
testDeviceManager.listener.event(new DeviceEvent(DEVICE_ADDED, referenceDevice, new DefaultPort(referenceDevice, PortNumber.portNumber(1), true)));
}
mgr.emitPacket(ByteBuffer.wrap(arr), Optional.empty());
assertEquals("There were an unexpected number of emitted packets", (totalPorts - numInfraPorts) * numDevices, packets.size());
Iterator<OutboundPacket> packetIter = packets.iterator();
OutboundPacket packet;
while (packetIter.hasNext()) {
packet = packetIter.next();
assertEquals("The packet had an incorrect payload.", arr, packet.data().array());
}
// Start testing emission to a specific device
packets.clear();
mgr.emitPacket(NetTestTools.did(Integer.toString(1)), ByteBuffer.wrap(arr), Optional.empty());
assertEquals("Unexpected number of outbound packets were emitted.", totalPorts - numInfraPorts, packets.size());
packetIter = packets.iterator();
while (packetIter.hasNext()) {
packet = packetIter.next();
assertEquals("The packet had an incorrect payload", arr, packet.data().array());
}
}
use of org.onosproject.net.Device in project onos by opennetworkinglab.
the class LumentumRoadmDiscovery method discoverDeviceDetails.
@Override
public DeviceDescription discoverDeviceDetails() {
// TODO get device description
DeviceService deviceService = checkNotNull(handler().get(DeviceService.class));
DeviceId deviceId = handler().data().deviceId();
Device device = deviceService.getDevice(deviceId);
return new DefaultDeviceDescription(device.id().uri(), Device.Type.ROADM, "Lumentum", "SDN ROADM", "1.0", "v1", device.chassisId(), (SparseAnnotations) device.annotations());
}
use of org.onosproject.net.Device in project onos by opennetworkinglab.
the class P4RuntimePacketProvider method emit.
@Override
public void emit(OutboundPacket packet) {
if (packet != null) {
DeviceId deviceId = packet.sendThrough();
Device device = deviceService.getDevice(deviceId);
if (device.is(PacketProgrammable.class) && mastershipService.isLocalMaster(deviceId)) {
PacketProgrammable packetProgrammable = device.as(PacketProgrammable.class);
packetProgrammable.emit(packet);
} else {
log.warn("No PacketProgrammable behavior for device {}", deviceId);
}
}
}
Aggregations