Search in sources :

Example 26 with NetconfDevice

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

the class NokiaTerminalDevicePowerConfig method getNetconfSession.

/**
 * Login to the device by providing the correct user and password in order to configure the device
 * Returns the NetconfSession with the device for which the method was called.
 *
 * @param deviceId device identifier
 * @param userName username to access the device
 * @param passwd password to access the device
 * @return The netconf session or null
 */
@Override
public NetconfSession getNetconfSession(DeviceId deviceId, String userName, String passwd) {
    userName = USER_NAME;
    passwd = PASSWORD;
    NetconfController nc = handler().get(NetconfController.class);
    NetconfDevice ndev = nc.getDevicesMap().get(deviceId);
    if (ndev == null) {
        log.debug("NetConf device " + deviceId + " is not found, returning null session");
        return null;
    }
    NetconfSession ns = ndev.getSession();
    if (ns == null) {
        log.error("discoverPorts called with null session for \n {}", deviceId);
        return null;
    }
    try {
        String reply = ns.requestSync(buildLoginRpc(userName, passwd));
        if (reply.contains("<ok/>")) {
            return ns;
        } else {
            log.debug("Reply contains this: \n {}", reply);
            return null;
        }
    } catch (NetconfException e) {
        log.error("Can NOT login to the device", e);
    }
    return ns;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfController(org.onosproject.netconf.NetconfController)

Example 27 with NetconfDevice

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

the class AdvaTerminalDeviceDiscovery method getNetconfSession.

/**
 * Returns the NetconfSession with the device for which the method was called.
 *
 * @param deviceId device indetifier
 *
 * @return The netconf session or null
 */
private NetconfSession getNetconfSession(DeviceId deviceId) {
    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 28 with NetconfDevice

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

the class NokiaOpenConfigDeviceDiscovery method getNetconfSessionAndLogin.

/**
 * Login to the device by providing the correct user and password in order to configure the device
 * Returns the NetconfSession with the device for which the method was called.
 *
 * @param deviceId device indetifier
 * @param userName
 * @param passwd
 * @return The netconf session or null
 */
private NetconfSession getNetconfSessionAndLogin(DeviceId deviceId, String userName, String passwd) {
    NetconfController nc = handler().get(NetconfController.class);
    NetconfDevice ndev = nc.getDevicesMap().get(deviceId);
    if (ndev == null) {
        log.debug("netconf device " + deviceId + " is not found, returning null session");
        return null;
    }
    NetconfSession ns = ndev.getSession();
    if (ns == null) {
        log.error("discoverPorts called with null session for {}", deviceId);
        return null;
    }
    try {
        String reply = ns.requestSync(buildLoginRpc(userName, passwd));
        if (reply.contains("<ok/>")) {
            return ns;
        } else {
            log.debug(reply);
            return null;
        }
    } catch (NetconfException e) {
        log.error("can not login to device", e);
    }
    return ns;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfController(org.onosproject.netconf.NetconfController)

Example 29 with NetconfDevice

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

the class MockNetconfController method connectDevice.

@Override
public NetconfDevice connectDevice(DeviceId deviceId) throws NetconfException {
    NetconfDevice mockNetconfDevice = null;
    String[] nameParts = deviceId.uri().toASCIIString().split(":");
    IpAddress ipAddress = Ip4Address.valueOf(nameParts[1]);
    int port = Integer.parseInt(nameParts[2]);
    NetconfDeviceInfo ncdi = new NetconfDeviceInfo("mock", "mock", ipAddress, port, null);
    mockNetconfDevice = new MockNetconfDevice(ncdi);
    devicesMap.put(deviceId, mockNetconfDevice);
    return mockNetconfDevice;
}
Also used : NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfDeviceInfo(org.onosproject.netconf.NetconfDeviceInfo) IpAddress(org.onlab.packet.IpAddress)

Example 30 with NetconfDevice

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

the class NetconfControllerImpl method connectDevice.

@Override
public NetconfDevice connectDevice(DeviceId deviceId, boolean isMaster) throws NetconfException {
    NetconfDeviceConfig netCfg = netCfgService.getConfig(deviceId, NetconfDeviceConfig.class);
    NetconfDeviceInfo deviceInfo = null;
    /*
         * A bit of an ugly race condition can be found here. It is possible
         * that this method is called to create a connection to device A and
         * while that device is in the process of being created another call
         * to this method for A will be invoked. Since the first call to
         * create A has not been completed device A is not in the the
         * netconfDeviceMap yet.
         *
         * To prevent this situation a mutex is introduced so that the first
         * call will be allowed to complete before the second is processed.
         * The mutex is based on the device ID, so that it should be still
         * possible to connect to different devices concurrently.
         */
    Lock mutex;
    synchronized (netconfCreateMutex) {
        mutex = netconfCreateMutex.get(deviceId);
        if (mutex == null) {
            mutex = new ReentrantLock();
            netconfCreateMutex.put(deviceId, mutex);
        }
    }
    mutex.lock();
    try {
        if (netconfDeviceMap.containsKey(deviceId)) {
            // If not master or already has session: return, otherwise create device again.
            if (!isMaster || netconfDeviceMap.get(deviceId).isMasterSession()) {
                log.debug("Device {} is already present", deviceId);
                return netconfDeviceMap.get(deviceId);
            }
        }
        if (netCfg != null) {
            log.debug("Device {} is present in NetworkConfig", deviceId);
            deviceInfo = new NetconfDeviceInfo(netCfg, deviceId);
        } else {
            log.debug("Creating NETCONF device {}", deviceId);
            deviceInfo = createDeviceInfo(deviceId);
        }
        NetconfDevice netconfDevice = createDevice(deviceInfo, isMaster);
        if (isMaster) {
            netconfDevice.getSession().addDeviceOutputListener(downListener);
        }
        return netconfDevice;
    } finally {
        mutex.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfDeviceInfo(org.onosproject.netconf.NetconfDeviceInfo) NetconfDeviceConfig(org.onosproject.netconf.config.NetconfDeviceConfig) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

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