Search in sources :

Example 16 with NetconfDevice

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);
        }
    }
}
Also used : NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfDeviceListener(org.onosproject.netconf.NetconfDeviceListener) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Example 17 with NetconfDevice

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();
}
Also used : NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfController(org.onosproject.netconf.NetconfController)

Example 18 with NetconfDevice

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));
    }
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) NetconfDevice(org.onosproject.netconf.NetconfDevice) ByteArrayInputStream(java.io.ByteArrayInputStream) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController)

Example 19 with NetconfDevice

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();
}
Also used : NetconfDevice(org.onosproject.netconf.NetconfDevice) DeviceId(org.onosproject.net.DeviceId) NetconfController(org.onosproject.netconf.NetconfController)

Example 20 with NetconfDevice

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);
        }
    }
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) Arrays(java.util.Arrays) DefaultDriver(org.onosproject.net.driver.DefaultDriver) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NetconfDevice(org.onosproject.netconf.NetconfDevice) Set(java.util.Set) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData) ArrayList(java.util.ArrayList) NetconfControllerImpl(org.onosproject.netconf.ctl.impl.NetconfControllerImpl) Map(java.util.Map) DeviceId(org.onosproject.net.DeviceId) NetconfDeviceInfo(org.onosproject.netconf.NetconfDeviceInfo) IpAddress(org.onlab.packet.IpAddress) NetconfException(org.onosproject.netconf.NetconfException) NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfDeviceInfo(org.onosproject.netconf.NetconfDeviceInfo)

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