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;
}
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();
}
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;
}
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;
}
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();
}
}
Aggregations