Search in sources :

Example 11 with NetconfSession

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

the class OplinkNetconfUtility method netconfEditConfig.

/**
 * Retrieves session reply information for edit config operation.
 *
 * @param handler parent driver handler
 * @param mode selected mode to change the configuration
 * @param cfg the new configuration to be set
 * @return the reply string
 */
public static boolean netconfEditConfig(DriverHandler handler, String mode, String cfg) {
    NetconfController controller = checkNotNull(handler.get(NetconfController.class));
    NetconfSession session = controller.getNetconfDevice(handler.data().deviceId()).getSession();
    boolean reply = false;
    try {
        reply = session.editConfig(DatastoreId.RUNNING, mode, cfg);
    } catch (NetconfException e) {
        throw new IllegalStateException(new NetconfException("Failed to edit configuration.", e));
    }
    return reply;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) NetconfController(org.onosproject.netconf.NetconfController)

Example 12 with NetconfSession

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

the class OplinkNetconfUtility method netconfGetConfig.

/**
 * Retrieves session reply information for get config operation.
 *
 * @param handler parent driver handler
 * @param filter the filter string of xml content
 * @return the reply string
 */
public static String netconfGetConfig(DriverHandler handler, String filter) {
    NetconfController controller = checkNotNull(handler.get(NetconfController.class));
    NetconfSession session = controller.getNetconfDevice(handler.data().deviceId()).getSession();
    String reply;
    try {
        reply = session.getConfig(DatastoreId.RUNNING, filter);
    } catch (NetconfException e) {
        throw new IllegalStateException(new NetconfException("Failed to retrieve configuration.", e));
    }
    return reply;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) NetconfController(org.onosproject.netconf.NetconfController)

Example 13 with NetconfSession

use of org.onosproject.netconf.NetconfSession 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 14 with NetconfSession

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

the class ClientLineTerminalDeviceDiscovery method discoverDeviceDetails.

/**
 * Returns a DeviceDescription with Device info.
 *
 * @return DeviceDescription or null
 *
 * //CHECKSTYLE:OFF
 * <pre>{@code
 * <data>
 * <components xmlns="http://openconfig.net/yang/platform">
 *  <component>
 *   <state>
 *     <name>FIRMWARE</name>
 *     <type>oc-platform-types:OPERATING_SYSTEM</type>
 *     <description>CTTC METRO-HAUL Emulated OpenConfig TerminalDevice</description>
 *     <version>0.0.1</version>
 *   </state>
 *  </component>
 * </components>
 * </data>
 *}</pre>
 * //CHECKSTYLE:ON
 */
@Override
public DeviceDescription discoverDeviceDetails() {
    boolean defaultAvailable = true;
    SparseAnnotations annotations = DefaultAnnotations.builder().build();
    log.debug("ClientLineTerminalDeviceDiscovery::discoverDeviceDetails device {}", did());
    // Other option "OTN" or "OTHER", we use TERMINAL_DEVICE
    org.onosproject.net.Device.Type type = Device.Type.TERMINAL_DEVICE;
    // Some defaults
    String vendor = "NOVENDOR";
    String serialNumber = "0xCAFEBEEF";
    String hwVersion = "0.2.1";
    String swVersion = "0.2.1";
    String chassisId = "128";
    // Get the session,
    NetconfSession session = getNetconfSession(did());
    try {
        String reply = session.get(getDeviceDetailsBuilder());
        log.debug("REPLY to DeviceDescription {}", reply);
        // <rpc-reply> as root node, software hardare version requires openconfig >= 2018
        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
        vendor = xconf.getString("data.components.component.state.mfg-name", vendor);
        serialNumber = xconf.getString("data.components.component.state.serial-no", serialNumber);
        swVersion = xconf.getString("data.components.component.state.software-version", swVersion);
        hwVersion = xconf.getString("data.components.component.state.hardware-version", hwVersion);
    } catch (Exception e) {
        log.error("ClientLineTerminalDeviceDiscovery::discoverDeviceDetails - Failed to retrieve session {}", did());
        throw new IllegalStateException(new NetconfException("Failed to retrieve version info.", e));
    }
    ChassisId cid = new ChassisId(Long.valueOf(chassisId, 10));
    log.info("Device retrieved details");
    log.info("VENDOR    {}", vendor);
    log.info("HWVERSION {}", hwVersion);
    log.info("SWVERSION {}", swVersion);
    log.info("SERIAL    {}", serialNumber);
    log.info("CHASSISID {}", chassisId);
    return new DefaultDeviceDescription(did().uri(), type, vendor, hwVersion, swVersion, serialNumber, cid, defaultAvailable, annotations);
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) ChassisId(org.onlab.packet.ChassisId) Device(org.onosproject.net.Device) NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfException(org.onosproject.netconf.NetconfException) SparseAnnotations(org.onosproject.net.SparseAnnotations) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) NetconfException(org.onosproject.netconf.NetconfException) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 15 with NetconfSession

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

the class ClientLineTerminalDeviceDiscovery method discoverPortDetails.

/**
 * Returns a list of PortDescriptions for the device.
 *
 * @return a list of descriptions.
 *
 * The RPC reply follows the following pattern:
 * //CHECKSTYLE:OFF
 * <pre>{@code
 * <?xml version="1.0" encoding="UTF-8"?>
 * <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="7">
 * <data>
 *   <components xmlns="http://openconfig.net/yang/platform">
 *     <component>....
 *     </component>
 *     <component>....
 *     </component>
 *   </components>
 * </data>
 * </rpc-reply>
 * }</pre>
 * //CHECKSTYLE:ON
 */
@Override
public List<PortDescription> discoverPortDetails() {
    try {
        XPathExpressionEngine xpe = new XPathExpressionEngine();
        NetconfSession session = getNetconfSession(did());
        if (session == null) {
            log.error("discoverPortDetails called with null session for {}", did());
            return ImmutableList.of();
        }
        CompletableFuture<String> fut = session.rpc(getDeviceComponentsBuilder());
        String rpcReply = fut.get();
        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
        xconf.setExpressionEngine(xpe);
        log.debug("REPLY {}", rpcReply);
        HierarchicalConfiguration components = xconf.configurationAt("data/components");
        return parsePorts(components);
    } catch (Exception e) {
        log.error("Exception discoverPortDetails() {}", did(), e);
        return ImmutableList.of();
    }
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) XPathExpressionEngine(org.apache.commons.configuration.tree.xpath.XPathExpressionEngine) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) NetconfException(org.onosproject.netconf.NetconfException)

Aggregations

NetconfSession (org.onosproject.netconf.NetconfSession)87 NetconfException (org.onosproject.netconf.NetconfException)72 NetconfController (org.onosproject.netconf.NetconfController)44 DeviceId (org.onosproject.net.DeviceId)32 XPath (javax.xml.xpath.XPath)22 XPathExpressionException (javax.xml.xpath.XPathExpressionException)18 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)18 Node (org.w3c.dom.Node)18 ArrayList (java.util.ArrayList)16 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)16 ByteArrayInputStream (java.io.ByteArrayInputStream)15 DeviceService (org.onosproject.net.device.DeviceService)13 Device (org.onosproject.net.Device)12 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)11 ChassisId (org.onlab.packet.ChassisId)10 FlowRule (org.onosproject.net.flow.FlowRule)10 HashMap (java.util.HashMap)9 PortDescription (org.onosproject.net.device.PortDescription)9 NodeList (org.w3c.dom.NodeList)9 ConnectPoint (org.onosproject.net.ConnectPoint)8