Search in sources :

Example 76 with NetconfController

use of org.onosproject.netconf.NetconfController 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 77 with NetconfController

use of org.onosproject.netconf.NetconfController 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 78 with NetconfController

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

the class NetconfGetCommand method doExecute.

@Override
protected void doExecute() {
    DeviceId deviceId = DeviceId.deviceId(uri);
    NetconfController controller = get(NetconfController.class);
    checkNotNull(controller, "Netconf controller is null");
    NetconfDevice device = controller.getDevicesMap().get(deviceId);
    if (device == null) {
        print("Netconf device object not found for %s", deviceId);
        return;
    }
    NetconfSession session = device.getSession();
    if (session == null) {
        print("Netconf session not found for %s", deviceId);
        return;
    }
    try {
        CharSequence res = session.asyncGet().get(timeoutSec, TimeUnit.SECONDS);
        print("%s", res);
    } catch (NetconfException | InterruptedException | ExecutionException | TimeoutException e) {
        log.error("Configuration could not be retrieved", e);
        print("Error occurred retrieving configuration");
    }
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) NetconfDevice(org.onosproject.netconf.NetconfDevice) DeviceId(org.onosproject.net.DeviceId) ExecutionException(java.util.concurrent.ExecutionException) NetconfController(org.onosproject.netconf.NetconfController) TimeoutException(java.util.concurrent.TimeoutException)

Example 79 with NetconfController

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

the class NetconfSubscriptionTestCommand method doExecute.

@Override
protected void doExecute() {
    NetconfController controller = get(NetconfController.class);
    DeviceId did = DeviceId.deviceId(uri);
    NetconfDevice netconfDevice = controller.getNetconfDevice(did);
    if (netconfDevice == null) {
        print("%s not found or not connected to this node", did);
        return;
    }
    if (!end) {
        try {
            netconfDevice.getSession().startSubscription();
        } catch (NetconfException e) {
            log.error("Exception thrown", e);
            print("starting subscription failed (see log for details)");
        }
    } else {
        try {
            netconfDevice.getSession().endSubscription();
        } catch (NetconfException e) {
            log.error("Exception thrown", e);
            print("ending subscription failed (see log for details)");
        }
    }
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) NetconfDevice(org.onosproject.netconf.NetconfDevice) DeviceId(org.onosproject.net.DeviceId) NetconfController(org.onosproject.netconf.NetconfController)

Example 80 with NetconfController

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

the class PolatisNetconfUtility method getNetconfSession.

/**
 * Returns the NETCONF session of the device.
 *
 * @return session
 */
private static NetconfSession getNetconfSession(DriverHandler handler) {
    NetconfController controller = checkNotNull(handler.get(NetconfController.class));
    NetconfSession session = controller.getNetconfDevice(handler.data().deviceId()).getSession();
    if (session == null) {
        throw new IllegalStateException(new NetconfException("Failed to retrieve the netconf device."));
    }
    return session;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) NetconfController(org.onosproject.netconf.NetconfController)

Aggregations

NetconfController (org.onosproject.netconf.NetconfController)80 NetconfException (org.onosproject.netconf.NetconfException)61 DeviceId (org.onosproject.net.DeviceId)42 NetconfSession (org.onosproject.netconf.NetconfSession)39 DriverHandler (org.onosproject.net.driver.DriverHandler)22 MastershipService (org.onosproject.mastership.MastershipService)20 NetconfDevice (org.onosproject.netconf.NetconfDevice)20 XPath (javax.xml.xpath.XPath)16 XPathExpressionException (javax.xml.xpath.XPathExpressionException)16 Node (org.w3c.dom.Node)16 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 ConnectPoint (org.onosproject.net.ConnectPoint)9 NodeList (org.w3c.dom.NodeList)8 DeviceService (org.onosproject.net.device.DeviceService)7 Device (org.onosproject.net.Device)6 PortDescription (org.onosproject.net.device.PortDescription)5 HashSet (java.util.HashSet)4 DefaultPortStatistics (org.onosproject.net.device.DefaultPortStatistics)4