Search in sources :

Example 21 with NetconfSession

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

the class LumentumNetconfRoadmFlowRuleProgrammable method removeFlowRules.

@Override
public Collection<FlowRule> removeFlowRules(Collection<FlowRule> rules) {
    NetconfSession session = getNetconfSession();
    if (session == null) {
        log.error("Device {} null session", did());
        return ImmutableList.of();
    }
    // Remove the rules from the device and from the cache
    List<FlowRule> removed = new ArrayList<>();
    for (FlowRule r : rules) {
        try {
            LumentumFlowRule flowRule = new LumentumFlowRule(r, getLinePorts());
            rpcDeleteConnection(flowRule);
            getConnectionCache().remove(did(), r);
            removed.add(r);
        } catch (Exception e) {
            log.error("Device {} Error {}", did(), e);
            continue;
        }
    }
    // Print out number of removed rules from the device (without receiving errors)
    log.debug("Device {} removeFlowRules removed {}", did(), removed.size());
    return removed;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) ArrayList(java.util.ArrayList) FlowRule(org.onosproject.net.flow.FlowRule) NetconfException(org.onosproject.netconf.NetconfException)

Example 22 with NetconfSession

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

the class CassiniTerminalDeviceDiscoveryOld 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 23 with NetconfSession

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

the class NokiaOpenConfigDeviceDiscovery method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    DeviceId did = data().deviceId();
    XMLConfiguration cfg = new XMLConfiguration();
    NetconfSession ns = getNetconfSessionAndLogin(did, USER_NAME, PASSWORD);
    if (ns == null) {
        log.error("discoverPorts called with null session for {}", did);
        return ImmutableList.of();
    }
    log.info("Discovering ports details {}", handler().data().deviceId());
    try {
        String reply = ns.requestSync(buildGetPlatformComponentsRpc());
        String data = getDataOfRpcReply(reply);
        if (data == null) {
            log.error("No valid response found from {}:\n{}", did, reply);
            return ImmutableList.of();
        }
        cfg.load(CharSource.wrap(data).openStream());
        try {
            ns.startSubscription();
            log.info("Started subscription");
        } catch (NetconfException e) {
            log.error("NETCONF exception caught on {} when the subscription started \n {}", data().deviceId(), e);
        }
        return discoverPorts(cfg);
    } catch (Exception e) {
        log.error("Error discovering port details on {}", data().deviceId(), e);
        return ImmutableList.of();
    }
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) NetconfException(org.onosproject.netconf.NetconfException)

Example 24 with NetconfSession

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

the class GrooveOpenConfigDeviceDiscovery 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 25 with NetconfSession

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

the class InfineraOpenConfigDeviceDiscovery 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)

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