Search in sources :

Example 31 with ChassisId

use of org.onlab.packet.ChassisId in project onos by opennetworkinglab.

the class RestDeviceProvider method getDesc.

private DeviceDescription getDesc(RestSBDevice restSBDev) {
    DeviceId deviceId = restSBDev.deviceId();
    Driver driver = getDriver(restSBDev);
    if (restSBDev.isProxy()) {
        if (driver != null && driver.hasBehaviour(DevicesDiscovery.class)) {
            // Creates the driver to communicate with the server
            DevicesDiscovery devicesDiscovery = devicesDiscovery(restSBDev, driver);
            return devicesDiscovery.deviceDetails(deviceId);
        } else {
            log.warn("Driver not found for {}", restSBDev);
            return null;
        }
    } else if (driver != null && driver.hasBehaviour(DeviceDescriptionDiscovery.class)) {
        DriverHandler h = driverService.createHandler(deviceId);
        DeviceDescriptionDiscovery deviceDiscovery = h.behaviour(DeviceDescriptionDiscovery.class);
        return deviceDiscovery.discoverDeviceDetails();
    }
    ChassisId cid = new ChassisId();
    String ipAddress = restSBDev.ip().toString();
    SparseAnnotations annotations = DefaultAnnotations.builder().set(IPADDRESS, ipAddress).set(AnnotationKeys.PROTOCOL, REST.toUpperCase()).build();
    String manufacturer = UNKNOWN;
    String hwVersion = UNKNOWN;
    String swVersion = UNKNOWN;
    String serialNumber = UNKNOWN;
    Device device = deviceService.getDevice(deviceId);
    if (device != null) {
        manufacturer = device.manufacturer();
        hwVersion = device.hwVersion();
        swVersion = device.swVersion();
        serialNumber = device.serialNumber();
    }
    return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, manufacturer, hwVersion, swVersion, serialNumber, cid, annotations);
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) ChassisId(org.onlab.packet.ChassisId) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) DeviceId(org.onosproject.net.DeviceId) RestSBDevice(org.onosproject.protocol.rest.RestSBDevice) DefaultRestSBDevice(org.onosproject.protocol.rest.DefaultRestSBDevice) Device(org.onosproject.net.Device) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) DriverHandler(org.onosproject.net.driver.DriverHandler) Driver(org.onosproject.net.driver.Driver) DevicesDiscovery(org.onosproject.net.behaviour.DevicesDiscovery)

Example 32 with ChassisId

use of org.onlab.packet.ChassisId in project onos by opennetworkinglab.

the class XmppDeviceProvider method connectDevice.

private void connectDevice(XmppDeviceId xmppDeviceId) {
    DeviceId deviceId = DeviceId.deviceId(xmppDeviceId.id());
    String ipAddress = controller.getDevice(xmppDeviceId).getIpAddress().getAddress().getHostAddress();
    // Assumption: manufacturer is uniquely identified by domain part of JID
    String manufacturer = xmppDeviceId.getJid().getDomain();
    ChassisId cid = new ChassisId();
    SparseAnnotations annotations = DefaultAnnotations.builder().set(AnnotationKeys.PROTOCOL, XMPP.toUpperCase()).set("IpAddress", ipAddress).build();
    DeviceDescription deviceDescription = new DefaultDeviceDescription(deviceId.uri(), Device.Type.OTHER, manufacturer, HARDWARE_VERSION, SOFTWARE_VERSION, SERIAL_NUMBER, cid, true, annotations);
    if (deviceService.getDevice(deviceId) == null) {
        providerService.deviceConnected(deviceId, deviceDescription);
    }
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) ChassisId(org.onlab.packet.ChassisId) XmppDeviceId(org.onosproject.xmpp.core.XmppDeviceId) DeviceId(org.onosproject.net.DeviceId) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 33 with ChassisId

use of org.onlab.packet.ChassisId in project onos by opennetworkinglab.

the class TerminalDeviceDiscovery method discoverDeviceDetails.

/**
 * Returns a DeviceDescription with Device info.
 *
 * @return DeviceDescription or null
 *
 * //CHECKSTYLE:OFF
 * <pre>{@code
 * <data>
 * <components xmlns="http://openconfig.net/yang/platform">
 *  <component>
 *   <state>
 *     <name>FIRMWARE</name>
 *     <type>oc-platform-types:OPERATING_SYSTEM</type>
 *     <description>CTTC METRO-HAUL Emulated OpenConfig TerminalDevice</description>
 *     <version>0.0.1</version>
 *   </state>
 *  </component>
 * </components>
 * </data>
 *}</pre>
 * //CHECKSTYLE:ON
 */
@Override
public DeviceDescription discoverDeviceDetails() {
    log.info("TerminalDeviceDiscovery::discoverDeviceDetails device {}", did());
    boolean defaultAvailable = true;
    SparseAnnotations annotations = DefaultAnnotations.builder().build();
    // Other option "OTHER", we use ROADM for now
    org.onosproject.net.Device.Type type = Device.Type.TERMINAL_DEVICE;
    // Some defaults
    String vendor = "NOVENDOR";
    String hwVersion = "0.2.1";
    String swVersion = "0.2.1";
    String serialNumber = "0xCAFEBEEF";
    String chassisId = "128";
    // Get the session,
    NetconfSession session = getNetconfSession(did());
    if (session != null) {
        try {
            String reply = session.get(getDeviceDetailsBuilder());
            // <rpc-reply> as root node
            XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
            vendor = xconf.getString("data/components/component/state/mfg-name", vendor);
            serialNumber = xconf.getString("data/components/component/state/serial-no", serialNumber);
            // Requires OpenConfig >= 2018
            swVersion = xconf.getString("data/components/component/state/software-version", swVersion);
            hwVersion = xconf.getString("data/components/component/state/hardware-version", hwVersion);
        } catch (Exception e) {
            throw new IllegalStateException(new NetconfException("Failed to retrieve version info.", e));
        }
    } else {
        log.info("TerminalDeviceDiscovery::discoverDeviceDetails - No netconf session for {}", did());
    }
    log.info("VENDOR    {}", vendor);
    log.info("HWVERSION {}", hwVersion);
    log.info("SWVERSION {}", swVersion);
    log.info("SERIAL    {}", serialNumber);
    log.info("CHASSISID {}", chassisId);
    ChassisId cid = new ChassisId(Long.valueOf(chassisId, 10));
    return new DefaultDeviceDescription(did().uri(), type, vendor, hwVersion, swVersion, serialNumber, cid, defaultAvailable, annotations);
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) ChassisId(org.onlab.packet.ChassisId) Device(org.onosproject.net.Device) NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfException(org.onosproject.netconf.NetconfException) SparseAnnotations(org.onosproject.net.SparseAnnotations) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) NetconfException(org.onosproject.netconf.NetconfException) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 34 with ChassisId

use of org.onlab.packet.ChassisId in project onos by opennetworkinglab.

the class HostLocationProviderTest method removeHostByDeviceRemove.

@Test
public void removeHostByDeviceRemove() {
    provider.modified(CTX_FOR_REMOVE);
    testProcessor.process(new TestArpPacketContext(DEV1));
    testProcessor.process(new TestNaPacketContext(DEV4));
    Device device = new DefaultDevice(ProviderId.NONE, deviceId(DEV1), SWITCH, "m", "h", "s", "n", new ChassisId(0L));
    deviceService.listener.event(new DeviceEvent(DEVICE_REMOVED, device));
    assertEquals("incorrect remove count", 2, providerService.locationRemoveCount);
    device = new DefaultDevice(ProviderId.NONE, deviceId(DEV4), SWITCH, "m", "h", "s", "n", new ChassisId(0L));
    deviceService.listener.event(new DeviceEvent(DEVICE_REMOVED, device));
    assertEquals("incorrect remove count", 3, providerService.locationRemoveCount);
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) ChassisId(org.onlab.packet.ChassisId) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) DefaultDevice(org.onosproject.net.DefaultDevice) Test(org.junit.Test)

Example 35 with ChassisId

use of org.onlab.packet.ChassisId in project onos by opennetworkinglab.

the class HostLocationProviderTest method removeHostByDeviceOffline.

@Test
public void removeHostByDeviceOffline() {
    provider.modified(CTX_FOR_REMOVE);
    testProcessor.process(new TestArpPacketContext(DEV1));
    testProcessor.process(new TestArpPacketContext(DEV4));
    Device device = new DefaultDevice(ProviderId.NONE, deviceId(DEV1), SWITCH, "m", "h", "s", "n", new ChassisId(0L));
    deviceService.listener.event(new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device));
    assertEquals("incorrect remove count", 2, providerService.locationRemoveCount);
    device = new DefaultDevice(ProviderId.NONE, deviceId(DEV4), SWITCH, "m", "h", "s", "n", new ChassisId(0L));
    deviceService.listener.event(new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device));
    assertEquals("incorrect remove count", 3, providerService.locationRemoveCount);
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) ChassisId(org.onlab.packet.ChassisId) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) DefaultDevice(org.onosproject.net.DefaultDevice) Test(org.junit.Test)

Aggregations

ChassisId (org.onlab.packet.ChassisId)48 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)32 DeviceId (org.onosproject.net.DeviceId)24 Device (org.onosproject.net.Device)19 DefaultDevice (org.onosproject.net.DefaultDevice)13 DeviceDescription (org.onosproject.net.device.DeviceDescription)12 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)11 DeviceService (org.onosproject.net.device.DeviceService)11 Test (org.junit.Test)10 SparseAnnotations (org.onosproject.net.SparseAnnotations)10 NetconfException (org.onosproject.netconf.NetconfException)10 NetconfSession (org.onosproject.netconf.NetconfSession)10 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)6 Type (org.onosproject.net.Device.Type)6 ProviderId (org.onosproject.net.provider.ProviderId)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ArrayList (java.util.ArrayList)5 NetconfDevice (org.onosproject.netconf.NetconfDevice)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 IOException (java.io.IOException)4