Search in sources :

Example 31 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class SimpleDeviceStoreTest method testRemoveDevice.

@Test
public final void testRemoveDevice() {
    putDevice(DID1, SW1, A1);
    List<PortDescription> pds = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).annotations(A2).build());
    deviceStore.updatePorts(PID, DID1, pds);
    putDevice(DID2, SW1);
    assertEquals(2, deviceStore.getDeviceCount());
    assertEquals(1, deviceStore.getPorts(DID1).size());
    assertAnnotationsEquals(deviceStore.getDevice(DID1).annotations(), A1);
    assertAnnotationsEquals(deviceStore.getPort(DID1, P1).annotations(), A2);
    DeviceEvent event = deviceStore.removeDevice(DID1);
    assertEquals(DEVICE_REMOVED, event.type());
    assertDevice(DID1, SW1, event.subject());
    assertEquals(1, deviceStore.getDeviceCount());
    assertEquals(0, deviceStore.getPorts(DID1).size());
    // putBack Device, Port w/o annotation
    putDevice(DID1, SW1);
    List<PortDescription> pds2 = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).build());
    deviceStore.updatePorts(PID, DID1, pds2);
    // annotations should not survive
    assertEquals(2, deviceStore.getDeviceCount());
    assertEquals(1, deviceStore.getPorts(DID1).size());
    assertAnnotationsEquals(deviceStore.getDevice(DID1).annotations());
    assertAnnotationsEquals(deviceStore.getPort(DID1, P1).annotations());
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) Test(org.junit.Test)

Example 32 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class SimpleDeviceStoreTest method testUpdatePortStatus.

@Test
public final void testUpdatePortStatus() {
    putDevice(DID1, SW1);
    List<PortDescription> pds = Arrays.asList(DefaultPortDescription.builder().withPortNumber(P1).isEnabled(true).build());
    deviceStore.updatePorts(PID, DID1, pds);
    DeviceEvent event = deviceStore.updatePortStatus(PID, DID1, DefaultPortDescription.builder().withPortNumber(P1).isEnabled(false).build());
    assertEquals(PORT_UPDATED, event.type());
    assertDevice(DID1, SW1, event.subject());
    assertEquals(P1, event.port().number());
    assertFalse("Port is disabled", event.port().isEnabled());
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) Test(org.junit.Test)

Example 33 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class ServerDevicesDiscovery method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    // Retrieve the device ID
    DeviceId deviceId = getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    // .. and object
    RestServerSBDevice device = null;
    try {
        device = (RestServerSBDevice) getDevice(deviceId);
    } catch (ClassCastException ccEx) {
        log.error("Failed to discover ports for device {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    if (device == null) {
        log.error("No device with ID {} is available for port discovery", deviceId);
        return Collections.EMPTY_LIST;
    }
    if ((device.nics() == null) || (device.nics().size() == 0)) {
        log.error("No ports available on {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    // List of port descriptions to return
    List<PortDescription> portDescriptions = Lists.newArrayList();
    // Sorted list of NIC ports
    Set<NicDevice> nics = new TreeSet(device.nics());
    // Iterate through the NICs of this device to populate the list
    for (NicDevice nic : nics) {
        // Include the name of this device as an annotation
        DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, nic.name());
        // Create a port description and add it to the list
        portDescriptions.add(DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(nic.portNumber())).isEnabled(nic.status()).type(nic.portType()).portSpeed(nic.speed()).annotations(annotations.build()).build());
        log.info("Port discovery on device {}: NIC {} is {} at {} Mbps", deviceId, nic.portNumber(), nic.status() ? "up" : "down", nic.speed());
    }
    return ImmutableList.copyOf(portDescriptions);
}
Also used : NicDevice(org.onosproject.drivers.server.devices.nic.NicDevice) DefaultNicDevice(org.onosproject.drivers.server.impl.devices.DefaultNicDevice) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DeviceId(org.onosproject.net.DeviceId) TreeSet(java.util.TreeSet) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) DefaultRestServerSBDevice(org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice)

Example 34 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class PolatisLinkDiscovery method checkPeer.

private boolean checkPeer(ConnectPoint nearEndCP, ConnectPoint peerCP, DriverHandler handler, boolean direct) {
    // check peerCP exists and is available (either via device service or direct from device)
    DeviceId peerDeviceID = peerCP.deviceId();
    boolean result = false;
    DeviceService deviceService = checkNotNull(handler.get(DeviceService.class));
    if (deviceService.isAvailable(peerDeviceID)) {
        log.trace("Peer device {} exists", peerDeviceID.toString());
        Device device = deviceService.getDevice(peerDeviceID);
        int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
        int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
        List<Port> ports = deviceService.getPorts(peerDeviceID);
        PortNumber farEndPortNum = peerCP.port();
        Port port = deviceService.getPort(peerCP);
        if (port != null) {
            if (port.isEnabled()) {
                log.trace("Peer port {} exists", port.number().toLong());
                // check far end peer-port entry (use device service or retrieve direct from switch)
                Port peerPort = deviceService.getPort(peerDeviceID, farEndPortNum);
                String farEndPortPeerportData = peerPort.annotations().value(KEY_PORTPEER);
                if (direct) {
                    log.trace("Checking device {} DIRECT", handler.data().deviceId());
                    // A bit of a cludge it seems but temporarily open a new NETCONF session to far-end device
                    NetconfController controller = checkNotNull(handler.get(NetconfController.class));
                    NetconfSession farEndDeviceSession = controller.getDevicesMap().get(peerDeviceID).getSession();
                    String reply = netconfGet(farEndDeviceSession, getPortFilter(farEndPortNum));
                    PortDescription peerPortDescDirect = parsePorts(reply, numInputPorts, numOutputPorts).get(0);
                    log.trace("peerPortDesc from device: " + peerPortDescDirect.toString());
                    String farEndPortPeerportDataDirect = peerPortDescDirect.annotations().value(KEY_PORTPEER);
                    farEndPortPeerportData = farEndPortPeerportDataDirect;
                }
                if (!farEndPortPeerportData.equals("")) {
                    if (farEndPortPeerportData.charAt(0) == '{') {
                        log.trace("Far-end peer-port value:" + farEndPortPeerportData);
                        ObjectMapper mapper = new ObjectMapper();
                        ConnectPoint checkNearEndCP = null;
                        try {
                            checkNearEndCP = parsePeerportDataForCP(mapper.readTree(farEndPortPeerportData));
                        } catch (JsonProcessingException jpe) {
                            log.trace("Error processing peer-port JSON: {}", jpe.toString());
                        }
                        if (nearEndCP.equals(checkNearEndCP)) {
                            log.trace("Reciprocal peer port entries match: nearEnd={}, farEnd={}", nearEndCP, checkNearEndCP);
                            result = true;
                        } else {
                            log.trace("Peer-port entry for far-end port ({}) does not match near-end " + "port number ({})", checkNearEndCP, nearEndCP);
                        }
                    }
                } else {
                    log.trace("Null peer-port entry for far-end port ({})", peerCP);
                }
            } else {
                log.trace("Peer port {} is DISABLED", port);
            }
        } else {
            log.trace("Peer port {} does not exist", port);
        }
    } else {
        log.trace("Far end device does not exist or is not available");
    }
    return result;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) PortDescription(org.onosproject.net.device.PortDescription) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfController(org.onosproject.netconf.NetconfController) PortNumber(org.onosproject.net.PortNumber) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 35 with PortDescription

use of org.onosproject.net.device.PortDescription in project onos by opennetworkinglab.

the class PolatisUtility method parsePorts.

/**
 * Returns a list of PortDescriptions from parsing the content of the reply to a get[-config] call to a
 * Polatis switch.
 *
 * @param content        XML to be parsed as string
 * @param numInputPorts  Number of input ports
 * @param numOutputPorts Number of output ports
 * @return               List of ports as PortDescription objects
 */
public static List<PortDescription> parsePorts(String content, int numInputPorts, int numOutputPorts) {
    List<HierarchicalConfiguration> subtrees = configsAt(content, KEY_DATA_PORTCONFIG);
    List<PortDescription> portDescriptions = new ArrayList<PortDescription>();
    for (HierarchicalConfiguration portConfig : subtrees) {
        PortDescription parsedPort = parsePort(portConfig, numInputPorts, numOutputPorts == 0 ? true : false);
        portDescriptions.add(parsedPort);
    }
    return portDescriptions;
}
Also used : ArrayList(java.util.ArrayList) OmsPortHelper.omsPortDescription(org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription) PortDescription(org.onosproject.net.device.PortDescription) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Aggregations

PortDescription (org.onosproject.net.device.PortDescription)82 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)42 Test (org.junit.Test)25 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)25 PortNumber (org.onosproject.net.PortNumber)25 DeviceId (org.onosproject.net.DeviceId)24 Port (org.onosproject.net.Port)23 ArrayList (java.util.ArrayList)22 DeviceEvent (org.onosproject.net.device.DeviceEvent)15 ProviderId (org.onosproject.net.provider.ProviderId)14 Device (org.onosproject.net.Device)13 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)11 DeviceService (org.onosproject.net.device.DeviceService)10 DefaultPort (org.onosproject.net.DefaultPort)9 NetconfSession (org.onosproject.netconf.NetconfSession)8 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 OduCltPortHelper.oduCltPortDescription (org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription)7 OmsPortHelper.omsPortDescription (org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription)7 ConnectPoint (org.onosproject.net.ConnectPoint)6