Search in sources :

Example 6 with NetconfSession

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

the class PolatisNetconfUtility method opticalRevision.

public static String opticalRevision(DriverHandler handler) {
    NetconfSession session = getNetconfSession(handler);
    Set<String> capabilities = session.getDeviceCapabilitiesSet();
    for (String c : capabilities) {
        if (c.startsWith(OPTICAL_CAPABILITY_PREFIX)) {
            return c.substring(OPTICAL_CAPABILITY_PREFIX.length());
        }
    }
    return null;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession)

Example 7 with NetconfSession

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

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

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

Example 10 with NetconfSession

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

the class OpenRoadmFlowRuleProgrammable method getDeviceConnections.

/**
 * Fetches list of connections from device.
 *
 * @return list of connections as XML hierarchy
 */
private List<HierarchicalConfiguration> getDeviceConnections() {
    NetconfSession session = getNetconfSession();
    if (session == null) {
        log.error("OPENROADM {}: session not found", did());
        return ImmutableList.of();
    }
    try {
        StringBuilder rb = new StringBuilder();
        rb.append(ORG_OPENROADM_DEVICE_OPEN_TAG);
        rb.append("  <roadm-connections/>");
        rb.append(ORG_OPENROADM_DEVICE_CLOSE_TAG);
        String reply = session.getConfig(DatastoreId.RUNNING, rb.toString());
        log.debug("REPLY to getDeviceConnections {}", reply);
        HierarchicalConfiguration cfg = XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes()));
        return cfg.configurationsAt("data.org-openroadm-device.roadm-connections");
    } catch (NetconfException e) {
        return ImmutableList.of();
    }
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) ByteArrayInputStream(java.io.ByteArrayInputStream) 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