use of org.onosproject.netconf.NetconfDevice in project onos by opennetworkinglab.
the class NetconfControllerImpl method stopDevice.
private void stopDevice(DeviceId deviceId, boolean remove) {
Lock mutex;
synchronized (netconfCreateMutex) {
mutex = netconfCreateMutex.remove(deviceId);
}
NetconfDevice nc;
if (mutex == null) {
log.warn("Unexpected stoping a device that has no lock");
nc = netconfDeviceMap.remove(deviceId);
} else {
mutex.lock();
try {
nc = netconfDeviceMap.remove(deviceId);
} finally {
mutex.unlock();
}
}
if (nc != null) {
nc.disconnect();
}
if (remove) {
for (NetconfDeviceListener l : netconfDeviceListeners) {
l.deviceRemoved(deviceId);
}
}
}
use of org.onosproject.netconf.NetconfDevice in project onos by opennetworkinglab.
the class CienaWaveserverAiDeviceDescription method getNetconfSession.
/**
* Returns the NETCONF session of the device.
*
* @return session
*/
private NetconfSession getNetconfSession() {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
NetconfDevice ncDevice = controller.getDevicesMap().get(handler().data().deviceId());
if (ncDevice == null) {
log.error("Internal ONOS Error. Device has been marked as reachable, " + "but deviceID {} is not in Devices Map. Continuing with empty description", handler().data().deviceId());
}
return controller.getDevicesMap().get(handler().data().deviceId()).getSession();
}
use of org.onosproject.netconf.NetconfDevice in project onos by opennetworkinglab.
the class NetconfControllerConfig method setControllers.
@Override
public void setControllers(List<ControllerInfo> controllers) {
DriverHandler handler = handler();
NetconfController controller = handler.get(NetconfController.class);
DeviceId deviceId = handler.data().deviceId();
Preconditions.checkNotNull(controller, "Netconf controller is null");
MastershipService mastershipService = handler.get(MastershipService.class);
if (mastershipService.isLocalMaster(deviceId)) {
try {
NetconfDevice device = controller.getNetconfDevice(deviceId);
String config = null;
try {
String reply = device.getSession().getConfig(DatastoreId.RUNNING);
log.info("reply XML {}", reply);
config = XmlConfigParser.createControllersConfig(XmlConfigParser.loadXml(getClass().getResourceAsStream("controllers.xml")), XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))), "running", "merge", "create", controllers);
} catch (NetconfException e) {
log.error("Cannot comunicate to device {} , exception {}", deviceId, e.getMessage());
return;
}
device.getSession().editConfig(config.substring(config.indexOf("-->") + 3));
} catch (NullPointerException e) {
log.warn("No NETCONF device with requested parameters " + e);
throw new NullPointerException("No NETCONF device with requested parameters " + e);
} catch (NetconfException e) {
log.error("Cannot comunicate to device {} , exception {}", deviceId, e.getMessage());
}
} else {
log.warn("I'm not master for {} please use master, {} to execute command", deviceId, mastershipService.getMasterFor(deviceId));
}
}
use of org.onosproject.netconf.NetconfDevice in project onos by opennetworkinglab.
the class ControllerConfigJuniperImpl method getSession.
private NetconfSession getSession() {
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
DeviceId deviceId = handler().data().deviceId();
NetconfDevice device = controller.getDevicesMap().get(deviceId);
if (device == null) {
log.error("Cannot find the netconf device : {}", deviceId);
return null;
}
return device.getSession();
}
use of org.onosproject.netconf.NetconfDevice in project onos by opennetworkinglab.
the class FujitsuNetconfControllerMock method connectDevice.
@Override
public NetconfDevice connectDevice(DeviceId deviceId) throws NetconfException {
if (netconfDeviceMap.containsKey(deviceId)) {
log.debug("Device {} is already present", deviceId);
return netconfDeviceMap.get(deviceId);
} else {
log.debug("Creating NETCONF device {}", deviceId);
String ip;
int port;
String[] info = deviceId.toString().split(":");
if (info.length == 3) {
ip = info[1];
port = Integer.parseInt(info[2]);
} else {
ip = Arrays.asList(info).stream().filter(el -> !el.equals(info[0]) && !el.equals(info[info.length - 1])).reduce((t, u) -> t + ":" + u).get();
log.debug("ip v6 {}", ip);
port = Integer.parseInt(info[info.length - 1]);
}
try {
NetconfDeviceInfo deviceInfo = new NetconfDeviceInfo(VOLT_DEVICE_USERNAME, VOLT_DEVICE_PASSWORD, IpAddress.valueOf(ip), port);
NetconfDevice netconfDevice = new FujitsuNetconfDeviceMock(deviceInfo);
netconfDeviceMap.put(deviceInfo.getDeviceId(), netconfDevice);
return netconfDevice;
} catch (NullPointerException e) {
throw new NetconfException("Cannot connect a device " + deviceId, e);
}
}
}
Aggregations