Search in sources :

Example 76 with NetconfSession

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

the class AdvaTerminalDeviceDiscovery 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 {
        NetconfSession session = getNetconfSession(did());
        if (session == null) {
            log.error("discoverPortDetails called with null session for {}", did());
            return ImmutableList.of();
        }
        CompletableFuture<String> fut = session.rpc(getTerminalDeviceBuilder());
        String rpcReply = fut.get();
        XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(rpcReply);
        xconf.setExpressionEngine(new XPathExpressionEngine());
        HierarchicalConfiguration logicalChannels = xconf.configurationAt("data/terminal-device/logical-channels");
        return parseLogicalChannels(logicalChannels);
    } 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)

Example 77 with NetconfSession

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

the class NokiaOpenConfigDeviceDiscovery method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    DeviceId did = data().deviceId();
    NetconfSession ns = getNetconfSessionAndLogin(did, USER_NAME, PASSWORD);
    if (ns == null) {
        log.error("DiscoverDeviceDetails called with null session for {}", did);
        return null;
    }
    log.info("Discovering device details {}", handler().data().deviceId());
    String hwVersion = "1830", swVersion = "OpenAgent";
    try {
        String reply = ns.requestSync(buildGetSystemSoftwareRpc());
        XMLConfiguration cfg = (XMLConfiguration) XmlConfigParser.loadXmlString(getDataOfRpcReply(reply));
        hwVersion = cfg.getString("components.component.state.description");
        swVersion = cfg.getString("components.component.state.version");
    } catch (NetconfException e) {
        log.error("Error discovering device details on {}", data().deviceId(), e);
    }
    return new DefaultDeviceDescription(handler().data().deviceId().uri(), Device.Type.ROADM_OTN, "NOKIA", hwVersion, swVersion, "", new ChassisId("1"));
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) ChassisId(org.onlab.packet.ChassisId) NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 78 with NetconfSession

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

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

the class OpenConfigDeviceDiscovery method discoverPorts.

private List<PortDescription> discoverPorts() throws ConfigurationException, IOException {
    DeviceId did = data().deviceId();
    NetconfSession ns = Optional.ofNullable(handler().get(NetconfController.class)).map(c -> c.getNetconfDevice(did)).map(NetconfDevice::getSession).orElseThrow(() -> new IllegalStateException("No NetconfSession found for " + did));
    // TODO convert this method into non-blocking form?
    String reply = ns.asyncGet().join().toString();
    // workaround until asyncGet().join() start failing exceptionally
    String data = null;
    if (reply.startsWith("<data")) {
        data = reply;
    }
    if (data == null) {
        log.error("No valid response found from {}:\n{}", did, reply);
        return ImmutableList.of();
    }
    XMLConfiguration cfg = new XMLConfiguration();
    cfg.load(CharSource.wrap(data).openStream());
    return discoverPorts(cfg);
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) DeviceId(org.onosproject.net.DeviceId)

Example 80 with NetconfSession

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

the class OpenconfigBitErrorRateState method getPostFecBer.

/**
 * Get the BER value post FEC.
 *
 * @param deviceId the device identifier
 * @param port     the port identifier
 * @return the decimal value of BER
 */
@Override
public Optional<Double> getPostFecBer(DeviceId deviceId, PortNumber port) {
    NetconfSession session = NetconfSessionUtility.getNetconfSession(deviceId, getController());
    checkNotNull(session);
    String postFecBerFilter = generateBerFilter(deviceId, port, POST_FEC_BER_TAG);
    String rpcRequest = getConfigOperation(postFecBerFilter);
    log.debug("RPC call for fetching Post FEC BER : {}", rpcRequest);
    XMLConfiguration xconf = NetconfSessionUtility.executeRpc(session, rpcRequest);
    if (xconf == null) {
        log.error("Error in executing Post FEC BER RPC");
        return Optional.empty();
    }
    try {
        HierarchicalConfiguration config = xconf.configurationAt("data/components/component/transceiver/state/" + POST_FEC_BER_TAG);
        if (config == null || config.getString("instant") == null) {
            return Optional.empty();
        }
        double ber = Float.valueOf(config.getString("instant")).doubleValue();
        return Optional.of(ber);
    } catch (IllegalArgumentException e) {
        log.error("Error in fetching configuration : {}", e.getMessage());
        return Optional.empty();
    }
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

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