Search in sources :

Example 6 with NetconfDevice

use of org.onosproject.netconf.NetconfDevice in project onos by opennetworkinglab.

the class NetconfSessionUtility method getNetconfSession.

/**
 * Returns the NetconfSession with the device for which the method was called.
 *
 * @param deviceId   device identifier
 * @param controller NetconfController
 * @return The netconf session or null
 */
public static NetconfSession getNetconfSession(DeviceId deviceId, NetconfController controller) {
    log.debug("Inside getNetconfSession () method for device : {}", deviceId);
    NetconfDevice ncdev = controller.getDevicesMap().get(deviceId);
    if (ncdev == null) {
        log.trace("No netconf device, returning null session");
        return null;
    }
    return ncdev.getSession();
}
Also used : NetconfDevice(org.onosproject.netconf.NetconfDevice)

Example 7 with NetconfDevice

use of org.onosproject.netconf.NetconfDevice in project onos by opennetworkinglab.

the class OpenRoadmNetconfHandlerBehaviour method getNetconfDevice.

/**
 * Get the device instance for which the methods apply.
 *
 * @return The device instance
 */
protected NetconfDevice getNetconfDevice() {
    NetconfController controller = checkNotNull(handler().get(NetconfController.class));
    NetconfDevice ncDevice = controller.getDevicesMap().get(did());
    return ncDevice;
}
Also used : NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfController(org.onosproject.netconf.NetconfController)

Example 8 with NetconfDevice

use of org.onosproject.netconf.NetconfDevice in project onos by opennetworkinglab.

the class FujitsuNetconfControllerMock method setUp.

/**
 * Sets up initial test environment.
 *
 * @param listener listener to be added
 * @return driver handler
 * @throws NetconfException when there is a problem
 */
public FujitsuDriverHandlerAdapter setUp(FujitsuNetconfSessionListenerTest listener) throws NetconfException {
    try {
        NetconfDeviceInfo deviceInfo = new NetconfDeviceInfo(VOLT_DEVICE_USERNAME, VOLT_DEVICE_PASSWORD, IpAddress.valueOf(VOLT_DEVICE_IP), VOLT_DEVICE_PORT);
        NetconfDevice netconfDevice = connectDevice(deviceInfo.getDeviceId());
        FujitsuNetconfSessionMock session = (FujitsuNetconfSessionMock) netconfDevice.getSession();
        session.setListener(listener);
        DeviceId deviceId = deviceInfo.getDeviceId();
        DefaultDriver driver = new DefaultDriver(VOLT_DRIVER_NAME, new ArrayList<>(), "Fujitsu", "1.0", "1.0", ImmutableMap.of(), ImmutableMap.of());
        DefaultDriverData driverData = new DefaultDriverData(driver, deviceId);
        FujitsuDriverHandlerAdapter driverHandler;
        driverHandler = new FujitsuDriverHandlerAdapter(driverData);
        driverHandler.setUp(this);
        return driverHandler;
    } catch (NetconfException e) {
        throw new NetconfException("Cannot create a device ", e);
    }
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfDeviceInfo(org.onosproject.netconf.NetconfDeviceInfo) DeviceId(org.onosproject.net.DeviceId) DefaultDriver(org.onosproject.net.driver.DefaultDriver) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData)

Example 9 with NetconfDevice

use of org.onosproject.netconf.NetconfDevice in project onos by opennetworkinglab.

the class TerminalDevicePowerConfig method getNetconfSession.

/**
 * Returns the NetconfSession with the device for which the method was called.
 *
 * @param deviceId device indetifier
 * @param userName username to access the device
 * @param passwd password to access the device
 * @return The netconf session or null
 */
public NetconfSession getNetconfSession(DeviceId deviceId, String userName, String passwd) {
    NetconfController controller = handler().get(NetconfController.class);
    NetconfDevice ncdev = controller.getDevicesMap().get(deviceId);
    if (ncdev == null) {
        log.trace("No netconf device, returning null session");
        return null;
    }
    return ncdev.getSession();
}
Also used : NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfController(org.onosproject.netconf.NetconfController)

Example 10 with NetconfDevice

use of org.onosproject.netconf.NetconfDevice in project onos by opennetworkinglab.

the class OpenRoadmDeviceDescription method discoverDeviceDetails.

/**
 * Returns a DeviceDescription with Device info.
 *
 * @return DeviceDescription or null
 */
@Override
public DeviceDescription discoverDeviceDetails() {
    boolean defaultAvailable = true;
    NetconfDevice ncDevice = getNetconfDevice();
    if (ncDevice == null) {
        log.error("ONOS Error: Device reachable, deviceID {} is not in Map", did());
        return null;
    }
    DefaultAnnotations.Builder annotationsBuilder = DefaultAnnotations.builder();
    // Some defaults
    String vendor = "UNKNOWN";
    String hwVersion = "2.2.0";
    String swVersion = "2.2.0";
    String serialNumber = "0x0000";
    String chassisId = "0";
    String nodeType = "rdm";
    // Get the session, if null, at least we can use the defaults.
    NetconfSession session = getNetconfSession(did());
    if (session != null) {
        try {
            String reply = session.rpc(getDeviceDetailsBuilder()).get();
            XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
            String nodeId = xconf.getString("data.org-openroadm-device.info.node-id", "");
            if (nodeId.equals("")) {
                log.error("[OPENROADM] {} org-openroadm-device node-id undefined, returning", did());
                return null;
            }
            annotationsBuilder.set(AnnotationKeys.OPENROADM_NODEID, nodeId);
            nodeType = xconf.getString("data.org-openroadm-device.info.node-type", "");
            if (nodeType.equals("")) {
                log.error("[OPENROADM] {} empty node-type", did());
                return null;
            }
            vendor = xconf.getString("data.org-openroadm-device.info.vendor", vendor);
            hwVersion = xconf.getString("data.org-openroadm-device.info.model", hwVersion);
            swVersion = xconf.getString("data.org-openroadm-device.info.softwareVersion", swVersion);
            serialNumber = xconf.getString("data.org-openroadm-device.info.serial-id", serialNumber);
            chassisId = xconf.getString("data.org-openroadm-device.info.node-number", chassisId);
            // GEOLOCATION
            String longitudeStr = xconf.getString("data.org-openroadm-device.info.geoLocation.longitude");
            String latitudeStr = xconf.getString("data.org-openroadm-device.info.geoLocation.latitude");
            if (longitudeStr != null && latitudeStr != null) {
                annotationsBuilder.set(org.onosproject.net.AnnotationKeys.LONGITUDE, longitudeStr).set(org.onosproject.net.AnnotationKeys.LATITUDE, latitudeStr);
            }
        } catch (NetconfException | InterruptedException | ExecutionException e) {
            log.error("[OPENROADM] {} exception", did());
            return null;
        }
    } else {
        log.debug("[OPENROADM] - No  session {}", did());
    }
    log.debug("[OPENROADM] {} - VENDOR {} HWVERSION {} SWVERSION {} SERIAL {} CHASSIS {}", did(), vendor, hwVersion, swVersion, serialNumber, chassisId);
    ChassisId cid = new ChassisId(Long.valueOf(chassisId, 10));
    /*
         * OpenROADM defines multiple devices (node types). This driver has been tested with
         * ROADMS, (node type, "rdm"). Other devices can also be discovered, and this code is here
         * for future developments - untested - it is likely that the XML documents
         * are model specific.
         */
    org.onosproject.net.Device.Type type;
    if (nodeType.equals("rdm")) {
        type = org.onosproject.net.Device.Type.ROADM;
    } else if (nodeType.equals("ila")) {
        type = org.onosproject.net.Device.Type.OPTICAL_AMPLIFIER;
    } else if (nodeType.equals("xpdr")) {
        type = org.onosproject.net.Device.Type.TERMINAL_DEVICE;
    } else if (nodeType.equals("extplug")) {
        type = org.onosproject.net.Device.Type.OTHER;
    } else {
        log.error("[OPENROADM] {} unsupported node-type", did());
        return null;
    }
    DeviceDescription desc = new DefaultDeviceDescription(did().uri(), type, vendor, hwVersion, swVersion, serialNumber, cid, defaultAvailable, annotationsBuilder.build());
    return desc;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) ChassisId(org.onlab.packet.ChassisId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) NetconfDevice(org.onosproject.netconf.NetconfDevice) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) NetconfException(org.onosproject.netconf.NetconfException) NetconfDevice(org.onosproject.netconf.NetconfDevice) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

NetconfDevice (org.onosproject.netconf.NetconfDevice)37 NetconfController (org.onosproject.netconf.NetconfController)20 NetconfException (org.onosproject.netconf.NetconfException)13 DeviceId (org.onosproject.net.DeviceId)8 NetconfSession (org.onosproject.netconf.NetconfSession)6 Test (org.junit.Test)5 NetconfDeviceInfo (org.onosproject.netconf.NetconfDeviceInfo)5 ExecutionException (java.util.concurrent.ExecutionException)4 NetconfDeviceConfig (org.onosproject.netconf.config.NetconfDeviceConfig)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 TimeoutException (java.util.concurrent.TimeoutException)2 Lock (java.util.concurrent.locks.Lock)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 IpAddress (org.onlab.packet.IpAddress)2 MastershipService (org.onosproject.mastership.MastershipService)2 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)2 DeviceDescription (org.onosproject.net.device.DeviceDescription)2 DefaultDriver (org.onosproject.net.driver.DefaultDriver)2 DefaultDriverData (org.onosproject.net.driver.DefaultDriverData)2 DriverHandler (org.onosproject.net.driver.DriverHandler)2