Search in sources :

Example 6 with NetconfException

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

the class NetconfDeviceProvider method initiateConnection.

// initiating the SSh connection the a given device.
private void initiateConnection(DeviceId deviceId) {
    if (!isReachable(deviceId)) {
        log.warn("Can't connect to device {}", deviceId);
        return;
    }
    try {
        NetconfDevice deviceNetconf = controller.connectDevice(deviceId);
        if (deviceNetconf != null) {
            // storeDeviceKey(config.sshKey(), config.username(), config.password(), deviceId);
            NetconfDeviceConfig config = cfgService.getConfig(deviceId, NetconfDeviceConfig.class);
            // getting the device description
            DeviceDescription deviceDescription = getDeviceDescription(deviceId, config);
            // connecting device to ONOS
            log.debug("Connected NETCONF device {}, on {}:{} {} with username {}", deviceId, config.ip(), config.port(), (config.path().isPresent() ? "/" + config.path().get() : ""), config.username());
            providerService.deviceConnected(deviceId, deviceDescription);
        } else {
            mastershipService.relinquishMastership(deviceId);
            deviceKeyAdminService.removeKey(DeviceKeyId.deviceKeyId(deviceId.toString()));
            log.error("Can't connect to NETCONF device {}", deviceId);
        }
    } catch (Exception e) {
        mastershipService.relinquishMastership(deviceId);
        deviceKeyAdminService.removeKey(DeviceKeyId.deviceKeyId(deviceId.toString()));
        throw new IllegalStateException(new NetconfException("Can't connect to NETCONF device " + deviceId, e));
    }
}
Also used : DeviceDescription(org.onosproject.net.device.DeviceDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) NetconfException(org.onosproject.netconf.NetconfException) NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfDeviceConfig(org.onosproject.netconf.config.NetconfDeviceConfig) NetconfException(org.onosproject.netconf.NetconfException) CancellationException(java.util.concurrent.CancellationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with NetconfException

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

the class NetconfAlarmProvider method deactivate.

@Deactivate
public void deactivate() {
    providerRegistry.unregister(this);
    idNotificationListenerMap.forEach((id, listener) -> {
        NetconfDevice device = controller.getNetconfDevice(id);
        if (device.isMasterSession()) {
            try {
                device.getSession().removeDeviceOutputListener(listener);
            } catch (NetconfException e) {
                log.error("RemoveDeviceOutputListener Error {}", e.getMessage());
            }
        }
    });
    controller.removeDeviceListener(deviceListener);
    providerService = null;
    log.info("NetconfAlarmProvider Stopped");
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) NetconfDevice(org.onosproject.netconf.NetconfDevice) Deactivate(org.osgi.service.component.annotations.Deactivate)

Example 8 with NetconfException

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

the class Ciena5162PortAdmin method setAdminState.

/**
 * Sets the administrative state of the given port to the given value.
 *
 * @param number
 *            port number
 * @param value
 *            state, true for enabled, false for disabled
 * @return true if successfully set
 */
private CompletableFuture<Boolean> setAdminState(PortNumber number, Boolean value) {
    NetconfController controller = checkNotNull(handler().get(NetconfController.class));
    NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
    try {
        Map<String, Object> templateContext = new HashMap<String, Object>();
        templateContext.put("port-number", number.toLong());
        templateContext.put("admin-state", value.toString());
        Node req = (Node) TEMPLATE_MANAGER.doRequest(session, "port-admin-state", templateContext, "/", XPathConstants.NODE);
        XPath xp = XPathFactory.newInstance().newXPath();
        // If OK element exists then it worked.
        Node ok = (Node) xp.evaluate("/rpc-reply/ok", req, XPathConstants.NODE);
        return CompletableFuture.completedFuture(ok != null);
    } catch (XPathExpressionException | NetconfException e) {
        log.error("Unable to set port admin state for port {} to {}", number, handler().data().deviceId(), value, e);
    }
    return CompletableFuture.completedFuture(false);
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XPath(javax.xml.xpath.XPath) NetconfException(org.onosproject.netconf.NetconfException) HashMap(java.util.HashMap) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) NetconfController(org.onosproject.netconf.NetconfController)

Example 9 with NetconfException

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

the class Ciena5170PortAdmin method isEnabled.

@Override
public CompletableFuture<Boolean> isEnabled(PortNumber number) {
    NetconfController controller = checkNotNull(handler().get(NetconfController.class));
    NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
    try {
        Map<String, Object> templateContext = new HashMap<String, Object>();
        templateContext.put("port-number", number.toString());
        Node port = TEMPLATE_MANAGER.doRequest(session, "logicalPort", templateContext);
        XPath xp = XPathFactory.newInstance().newXPath();
        return CompletableFuture.completedFuture(Boolean.valueOf(xp.evaluate("admin-status/text()", port)));
    } catch (XPathExpressionException | NetconfException e) {
        log.error("Unable to query port state for port {} from device {}", number, handler().data().deviceId(), e);
    }
    return CompletableFuture.completedFuture(false);
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XPath(javax.xml.xpath.XPath) NetconfException(org.onosproject.netconf.NetconfException) HashMap(java.util.HashMap) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) NetconfController(org.onosproject.netconf.NetconfController)

Example 10 with NetconfException

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

the class FujitsuT100DeviceDescription method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    NetconfController controller = checkNotNull(handler().get(NetconfController.class));
    NetconfSession session = controller.getDevicesMap().get(handler().data().deviceId()).getSession();
    String reply;
    try {
        reply = session.get(requestBuilder());
    } catch (NetconfException e) {
        log.error("Failed to retrieve port details for device {}", handler().data().deviceId());
        return ImmutableList.of();
    }
    List<PortDescription> descriptions = parseFujitsuT100Ports(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes())));
    return ImmutableList.copyOf(descriptions);
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) ByteArrayInputStream(java.io.ByteArrayInputStream) OchPortHelper.ochPortDescription(org.onosproject.net.optical.device.OchPortHelper.ochPortDescription) PortDescription(org.onosproject.net.device.PortDescription) OduCltPortHelper.oduCltPortDescription(org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription) NetconfController(org.onosproject.netconf.NetconfController)

Aggregations

NetconfException (org.onosproject.netconf.NetconfException)120 NetconfController (org.onosproject.netconf.NetconfController)65 NetconfSession (org.onosproject.netconf.NetconfSession)65 DeviceId (org.onosproject.net.DeviceId)50 XPath (javax.xml.xpath.XPath)23 DriverHandler (org.onosproject.net.driver.DriverHandler)22 XPathExpressionException (javax.xml.xpath.XPathExpressionException)19 Node (org.w3c.dom.Node)19 ByteArrayInputStream (java.io.ByteArrayInputStream)18 ArrayList (java.util.ArrayList)18 NetconfDevice (org.onosproject.netconf.NetconfDevice)18 MastershipService (org.onosproject.mastership.MastershipService)17 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)15 ExecutionException (java.util.concurrent.ExecutionException)12 Device (org.onosproject.net.Device)12 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)12 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)11 DeviceService (org.onosproject.net.device.DeviceService)11 ChassisId (org.onlab.packet.ChassisId)10 HashMap (java.util.HashMap)9