Search in sources :

Example 16 with NetconfException

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

the class CassiniTerminalDevicePowerConfigExt method executeRpc.

/**
 * Execute RPC request.
 * @param session Netconf session
 * @param message Netconf message in XML format
 * @return XMLConfiguration object
 */
private XMLConfiguration executeRpc(NetconfSession session, String message) {
    try {
        CompletableFuture<String> fut = session.rpc(message);
        String rpcReply = fut.get();
        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
        xconf.setExpressionEngine(new XPathExpressionEngine());
        return xconf;
    } catch (NetconfException ne) {
        log.error("Exception on Netconf protocol: {}.", ne);
    } catch (InterruptedException ie) {
        log.error("Interrupted Exception: {}.", ie);
    } catch (ExecutionException ee) {
        log.error("Concurrent Exception while executing Netconf operation: {}.", ee);
    }
    return null;
}
Also used : XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) NetconfException(org.onosproject.netconf.NetconfException) XPathExpressionEngine(org.apache.commons.configuration.tree.xpath.XPathExpressionEngine) ExecutionException(java.util.concurrent.ExecutionException)

Example 17 with NetconfException

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

the class NetconfConfigSetter method setConfiguration.

@Override
public String setConfiguration(String filePath) {
    DriverHandler handler = handler();
    NetconfController controller = handler.get(NetconfController.class);
    DeviceId deviceId = handler.data().deviceId();
    Preconditions.checkNotNull(controller, "Netconf controller is null");
    String request;
    try {
        request = new String(Files.readAllBytes(Paths.get(filePath)));
    } catch (IOException e) {
        log.error("Cannot read configuration file", e);
        return UNABLE_TO_READ_FILE;
    }
    try {
        return controller.getDevicesMap().get(deviceId).getSession().requestSync(request);
    } catch (NetconfException e) {
        log.error("Configuration could not be set", e);
    }
    return UNABLE_TO_SET_CONFIG;
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) IOException(java.io.IOException) NetconfController(org.onosproject.netconf.NetconfController)

Example 18 with NetconfException

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

the class AbstractOdtnTerminalDeviceDriver method configureDevice.

protected void configureDevice(DeviceId did, Document doc) {
    NetconfController ctr = getService(NetconfController.class);
    Optional.ofNullable(ctr.getNetconfDevice(did)).map(NetconfDevice::getSession).ifPresent(session -> {
        try {
            session.rpc(toCharSequence(doc).toString()).join();
        } catch (NetconfException e) {
            log.error("Exception thrown", e);
        }
    });
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) NetconfController(org.onosproject.netconf.NetconfController)

Example 19 with NetconfException

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

the class ControllerConfigJuniperImpl method requestCommand.

private boolean requestCommand(String command) {
    NetconfSession session = getSession();
    if (session == null) {
        log.error("Cannot get session : {}", command);
        return false;
    }
    try {
        String reply = session.requestSync(command).trim();
        log.debug(reply);
        if (!isOK(reply)) {
            log.error("discard changes {}", reply);
            session.requestSync(buildDiscardChanges());
            return false;
        }
        reply = session.requestSync(buildCommit()).trim();
        log.debug("reply : {}", reply);
    } catch (NetconfException e) {
        log.debug(e.getMessage());
        return false;
    }
    return true;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException)

Example 20 with NetconfException

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

the class DeviceDiscoveryJuniperImpl method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    DeviceId devId = handler().data().deviceId();
    NetconfSession session = lookupNetconfSession(devId);
    String sysInfo;
    String chassisMacAddresses;
    try {
        sysInfo = session.get(requestBuilder(REQ_SYS_INFO));
        chassisMacAddresses = session.get(requestBuilder(REQ_MAC_ADD_INFO));
    } catch (NetconfException e) {
        log.warn("Failed to retrieve device details for {}", devId);
        return null;
    }
    log.trace("Device {} system-information {}", devId, sysInfo);
    DeviceDescription description = JuniperUtils.parseJuniperDescription(devId, loadXmlString(sysInfo), chassisMacAddresses);
    log.debug("Device {} description {}", devId, description);
    return description;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) DeviceDescription(org.onosproject.net.device.DeviceDescription) NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString)

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