Search in sources :

Example 6 with Device

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());
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) DefaultServiceDirectory(org.onlab.osgi.DefaultServiceDirectory) ServiceDirectory(org.onlab.osgi.ServiceDirectory) Device(org.onosproject.net.Device) ExtensionTreatmentCodec(org.onosproject.net.flow.ExtensionTreatmentCodec) DeviceService(org.onosproject.net.device.DeviceService) Instructions(org.onosproject.net.flow.instructions.Instructions) DefaultServiceDirectory(org.onlab.osgi.DefaultServiceDirectory)

Example 7 with Device

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));
        }
    }
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) LinkEvent(org.onosproject.net.link.LinkEvent) Device(org.onosproject.net.Device) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 8 with Device

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());
    }
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) Device(org.onosproject.net.Device) ConnectPoint(org.onosproject.net.ConnectPoint) DefaultPort(org.onosproject.net.DefaultPort) OutboundPacket(org.onosproject.net.packet.OutboundPacket) Test(org.junit.Test)

Example 9 with Device

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());
}
Also used : DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceService(org.onosproject.net.device.DeviceService)

Example 10 with Device

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);
        }
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) PacketProgrammable(org.onosproject.net.packet.PacketProgrammable)

Aggregations

Device (org.onosproject.net.Device)344 DeviceService (org.onosproject.net.device.DeviceService)111 DeviceId (org.onosproject.net.DeviceId)106 Port (org.onosproject.net.Port)63 ConnectPoint (org.onosproject.net.ConnectPoint)62 List (java.util.List)53 PortNumber (org.onosproject.net.PortNumber)51 DefaultDevice (org.onosproject.net.DefaultDevice)50 Test (org.junit.Test)43 Set (java.util.Set)40 Logger (org.slf4j.Logger)40 DeviceEvent (org.onosproject.net.device.DeviceEvent)39 Link (org.onosproject.net.Link)37 TrafficSelector (org.onosproject.net.flow.TrafficSelector)35 ArrayList (java.util.ArrayList)34 Optional (java.util.Optional)32 Collectors (java.util.stream.Collectors)32 Map (java.util.Map)31 IpAddress (org.onlab.packet.IpAddress)31 ApplicationId (org.onosproject.core.ApplicationId)31