Search in sources :

Example 21 with ChassisId

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

the class LispDeviceProvider method connectDevice.

/**
 * Adds a LISP router into device store.
 */
private void connectDevice(LispRouterId routerId) {
    DeviceId deviceId = getDeviceId(routerId.id().toString());
    Preconditions.checkNotNull(deviceId, IS_NULL_MSG);
    // formulate LISP router object
    ChassisId cid = new ChassisId();
    String ipAddress = routerId.id().toString();
    SparseAnnotations annotations = DefaultAnnotations.builder().set(IPADDRESS, ipAddress).set(AnnotationKeys.PROTOCOL, SCHEME_NAME.toUpperCase()).build();
    DeviceDescription deviceDescription = new DefaultDeviceDescription(deviceId.uri(), Device.Type.ROUTER, MANUFACTURER, HARDWARE_VERSION, SOFTWARE_VERSION, SERIAL_NUMBER, cid, false, annotations);
    if (deviceService.getDevice(deviceId) == null) {
        providerService.deviceConnected(deviceId, deviceDescription);
    }
    checkAndUpdateDevice(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) DeviceId(org.onosproject.net.DeviceId) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 22 with ChassisId

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

the class CienaWaveserverAiDeviceDescription method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    log.debug("Adding description for Waveserver Ai device");
    NetconfSession session = getNetconfSession();
    Device device = getDevice(handler().data().deviceId());
    try {
        XPath xp = XPathFactory.newInstance().newXPath();
        Node node = TEMPLATE_MANAGER.doRequest(session, "discoverDeviceDetails");
        String chassisId = xp.evaluate("waveserver-chassis/mac-addresses/chassis/base/text()", node);
        chassisId = chassisId.replace(":", "");
        SparseAnnotations annotationDevice = DefaultAnnotations.builder().set("name", xp.evaluate("waveserver-system/host-name/current-host-name/text()", node)).build();
        return new DefaultDeviceDescription(device.id().uri(), Device.Type.OTN, "Ciena", "WaverserverAi", xp.evaluate("waveserver-software/status/active-version/text()", node), xp.evaluate("waveserver-chassis/identification/serial-number/text()", node), new ChassisId(Long.valueOf(chassisId, 16)), (SparseAnnotations) annotationDevice);
    } catch (NetconfException | XPathExpressionException e) {
        log.error("Unable to retrieve device information for device {}, {}", device.chassisId(), e);
    }
    return new DefaultDeviceDescription(device.id().uri(), Device.Type.OTN, "Ciena", "WaverserverAi", "unknown", "unknown", device.chassisId());
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XPath(javax.xml.xpath.XPath) SparseAnnotations(org.onosproject.net.SparseAnnotations) ChassisId(org.onlab.packet.ChassisId) NetconfException(org.onosproject.netconf.NetconfException) Device(org.onosproject.net.Device) NetconfDevice(org.onosproject.netconf.NetconfDevice) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 23 with ChassisId

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

the class CienaWaveserverAiDeviceDescriptionTest method testDiscoverDeviceDetails.

@Test
public void testDiscoverDeviceDetails() {
    XPath xp = XPathFactory.newInstance().newXPath();
    SparseAnnotations expectAnnotation = DefaultAnnotations.builder().set("hostname", "hostnameWaveServer").build();
    DefaultDeviceDescription expectResult = new DefaultDeviceDescription(mockDeviceId.uri(), Device.Type.OTN, "Ciena", "WaverserverAi", "waveserver-1.1.0.302", "M000", new ChassisId(0L), expectAnnotation);
    try {
        Node node = doRequest("/response/discoverDeviceDetails.xml", "/rpc-reply/data");
        SparseAnnotations annotationDevice = DefaultAnnotations.builder().set("hostname", xp.evaluate("waveserver-system/host-name/current-host-name/text()", node)).build();
        DefaultDeviceDescription result = new DefaultDeviceDescription(mockDeviceId.uri(), Device.Type.OTN, "Ciena", "WaverserverAi", xp.evaluate("waveserver-software/status/active-version/text()", node), xp.evaluate("waveserver-chassis/identification/serial-number/text()", node), new ChassisId(0L), annotationDevice);
        assertEquals(expectResult, result);
    } catch (XPathExpressionException e) {
        e.printStackTrace();
    }
}
Also used : XPath(javax.xml.xpath.XPath) SparseAnnotations(org.onosproject.net.SparseAnnotations) ChassisId(org.onlab.packet.ChassisId) XPathExpressionException(javax.xml.xpath.XPathExpressionException) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) Node(org.w3c.dom.Node) Test(org.junit.Test)

Example 24 with ChassisId

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

the class LumentumNetconfRoadmDiscovery method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    SparseAnnotations annotations = DefaultAnnotations.builder().build();
    log.debug("Lumentum NETCONF - starting discoverDeviceDetails");
    // Some defaults values
    String vendor = "Lumentum";
    String hwVersion = "not loaded";
    String swVersion = "not loaded";
    String serialNumber = "not loaded";
    String chassisData = "ne=1;chassis=10";
    ChassisId chassisId = null;
    DeviceId deviceId = handler().data().deviceId();
    NetconfSession session = getNetconfSession();
    if (session == null) {
        log.error("Lumentum NETCONF - session not found for {}", deviceId);
        return null;
    }
    // Retrieve system information from ietf-system
    StringBuilder systemRequestBuilder = new StringBuilder();
    systemRequestBuilder.append("<system-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-system\">");
    systemRequestBuilder.append("</system-state>");
    try {
        String reply = session.get(systemRequestBuilder.toString(), null);
        log.debug("Lumentum NETCONF - session.get reply {}", reply);
        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
        vendor = xconf.getString("data.system-state.platform.machine", vendor);
        swVersion = xconf.getString("data.system-state.platform.os-version", swVersion);
    } catch (NetconfException e) {
        log.error("Lumentum NETCONF error in session.get with filter <system-state>", e);
    }
    // Retrieve system information
    StringBuilder chassisRequestBuilder = new StringBuilder();
    chassisRequestBuilder.append("<chassis-list xmlns=\"http://www.lumentum.com/lumentum-ote-equipment\">");
    chassisRequestBuilder.append("</chassis-list>");
    try {
        String reply = session.get(chassisRequestBuilder.toString(), null);
        log.debug("Lumentum NETCONF - session.get reply {}", reply);
        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
        hwVersion = xconf.getString("data.chassis-list.chassis.state.loteq:hardware-rev", hwVersion);
        serialNumber = xconf.getString("data.chassis-list.chassis.state.loteq:serial-no", serialNumber);
        chassisData = xconf.getString("data.chassis-list.chassis.dn", chassisData);
        String[] parts = chassisData.split("chassis=");
        chassisId = new ChassisId(Long.valueOf(parts[1], 10));
    } catch (NetconfException e) {
        log.error("Lumentum NETCONF error in session.get", e);
    }
    // Upon connection of a new devices all pre-configured connections are removed
    // TODO consider a way to keep "external" FlowRules
    rpcRemoveAllConnections("1");
    rpcRemoveAllConnections("2");
    log.info("Lumentum ROADM20 - discovered details:");
    log.info("TYPE      {}", Device.Type.ROADM);
    log.info("VENDOR    {}", vendor);
    log.info("HWVERSION {}", hwVersion);
    log.info("SWVERSION {}", swVersion);
    log.info("SERIAL    {}", serialNumber);
    log.info("CHASSISID {}", chassisId);
    // Return the Device Description
    return new DefaultDeviceDescription(deviceId.uri(), Device.Type.ROADM, vendor, hwVersion, swVersion, serialNumber, chassisId, annotations);
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) NetconfSession(org.onosproject.netconf.NetconfSession) ChassisId(org.onlab.packet.ChassisId) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 25 with ChassisId

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

the class LumentumWaveReadyDiscovery method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    DeviceId deviceId = handler().data().deviceId();
    Tl1Controller ctrl = checkNotNull(handler().get(Tl1Controller.class));
    // Something reasonable, unavailable by default
    DeviceDescription defaultDescription = new DefaultDeviceDescription(deviceId.uri(), Device.Type.OTN, LUMENTUM, WAVEREADY, SWVERSION, SERIAL, new ChassisId(), false, DefaultAnnotations.EMPTY);
    Optional<Tl1Device> device = ctrl.getDevice(deviceId);
    if (!device.isPresent()) {
        return defaultDescription;
    }
    // Login
    Tl1Command loginCmd = DefaultTl1Command.builder().withVerb(ACT).withModifier(USER).withAid(device.get().username()).withCtag(100).withParameters(device.get().password()).build();
    Future<String> login = ctrl.sendMsg(deviceId, loginCmd);
    try {
        String loginResponse = login.get(TIMEOUT, TimeUnit.MILLISECONDS);
        if (loginResponse.contains("Access denied")) {
            log.error("Access denied: {}", loginResponse);
            return defaultDescription;
        }
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        log.error("Login failed", e);
        return defaultDescription;
    }
    // Fetch device description
    Tl1Command ddCmd = DefaultTl1Command.builder().withVerb(RTRV).withModifier(NETYPE).withCtag(101).build();
    Future<String> dd = ctrl.sendMsg(deviceId, ddCmd);
    try {
        String ddResponse = dd.get(TIMEOUT, TimeUnit.MILLISECONDS);
        return new DefaultDeviceDescription(defaultDescription, true, extractAnnotations(ddResponse));
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        log.error("Device description not found", e);
        return defaultDescription;
    }
}
Also used : DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) ChassisId(org.onlab.packet.ChassisId) Tl1Command(org.onosproject.tl1.Tl1Command) DefaultTl1Command(org.onosproject.tl1.DefaultTl1Command) DeviceId(org.onosproject.net.DeviceId) Tl1Controller(org.onosproject.tl1.Tl1Controller) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) Tl1Device(org.onosproject.tl1.Tl1Device) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

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