Search in sources :

Example 6 with NetconfController

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

the class PolatisLinkDiscovery method checkPeer.

private boolean checkPeer(ConnectPoint nearEndCP, ConnectPoint peerCP, DriverHandler handler, boolean direct) {
    // check peerCP exists and is available (either via device service or direct from device)
    DeviceId peerDeviceID = peerCP.deviceId();
    boolean result = false;
    DeviceService deviceService = checkNotNull(handler.get(DeviceService.class));
    if (deviceService.isAvailable(peerDeviceID)) {
        log.trace("Peer device {} exists", peerDeviceID.toString());
        Device device = deviceService.getDevice(peerDeviceID);
        int numInputPorts = Integer.parseInt(device.annotations().value(KEY_INPUTPORTS));
        int numOutputPorts = Integer.parseInt(device.annotations().value(KEY_OUTPUTPORTS));
        List<Port> ports = deviceService.getPorts(peerDeviceID);
        PortNumber farEndPortNum = peerCP.port();
        Port port = deviceService.getPort(peerCP);
        if (port != null) {
            if (port.isEnabled()) {
                log.trace("Peer port {} exists", port.number().toLong());
                // check far end peer-port entry (use device service or retrieve direct from switch)
                Port peerPort = deviceService.getPort(peerDeviceID, farEndPortNum);
                String farEndPortPeerportData = peerPort.annotations().value(KEY_PORTPEER);
                if (direct) {
                    log.trace("Checking device {} DIRECT", handler.data().deviceId());
                    // A bit of a cludge it seems but temporarily open a new NETCONF session to far-end device
                    NetconfController controller = checkNotNull(handler.get(NetconfController.class));
                    NetconfSession farEndDeviceSession = controller.getDevicesMap().get(peerDeviceID).getSession();
                    String reply = netconfGet(farEndDeviceSession, getPortFilter(farEndPortNum));
                    PortDescription peerPortDescDirect = parsePorts(reply, numInputPorts, numOutputPorts).get(0);
                    log.trace("peerPortDesc from device: " + peerPortDescDirect.toString());
                    String farEndPortPeerportDataDirect = peerPortDescDirect.annotations().value(KEY_PORTPEER);
                    farEndPortPeerportData = farEndPortPeerportDataDirect;
                }
                if (!farEndPortPeerportData.equals("")) {
                    if (farEndPortPeerportData.charAt(0) == '{') {
                        log.trace("Far-end peer-port value:" + farEndPortPeerportData);
                        ObjectMapper mapper = new ObjectMapper();
                        ConnectPoint checkNearEndCP = null;
                        try {
                            checkNearEndCP = parsePeerportDataForCP(mapper.readTree(farEndPortPeerportData));
                        } catch (JsonProcessingException jpe) {
                            log.trace("Error processing peer-port JSON: {}", jpe.toString());
                        }
                        if (nearEndCP.equals(checkNearEndCP)) {
                            log.trace("Reciprocal peer port entries match: nearEnd={}, farEnd={}", nearEndCP, checkNearEndCP);
                            result = true;
                        } else {
                            log.trace("Peer-port entry for far-end port ({}) does not match near-end " + "port number ({})", checkNearEndCP, nearEndCP);
                        }
                    }
                } else {
                    log.trace("Null peer-port entry for far-end port ({})", peerCP);
                }
            } else {
                log.trace("Peer port {} is DISABLED", port);
            }
        } else {
            log.trace("Peer port {} does not exist", port);
        }
    } else {
        log.trace("Far end device does not exist or is not available");
    }
    return result;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) PortDescription(org.onosproject.net.device.PortDescription) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfController(org.onosproject.netconf.NetconfController) PortNumber(org.onosproject.net.PortNumber) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with NetconfController

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

the class PolatisAlarmConsumer method consumeAlarms.

@Override
public List<Alarm> consumeAlarms() {
    DriverHandler handler = handler();
    NetconfController controller = handler.get(NetconfController.class);
    checkNotNull(controller, "Netconf controller is null");
    MastershipService mastershipService = handler.get(MastershipService.class);
    deviceId = handler.data().deviceId();
    List<Alarm> alarms = new ArrayList<>();
    if (!mastershipService.isLocalMaster(deviceId)) {
        log.warn("Not master for {} Use {} to execute command", deviceId, mastershipService.getMasterFor(deviceId));
        return ImmutableList.copyOf(alarms);
    }
    try {
        String request = xmlEmpty(KEY_SYSTEMALARMS_XMLNS);
        String reply = controller.getDevicesMap().get(deviceId).getSession().get(request, null);
        if (reply != null) {
            alarms = parseAlarms(reply);
        }
    } catch (NetconfException e) {
        log.error("Error reading alarms for device {} exception {}", deviceId, e);
    }
    return ImmutableList.copyOf(alarms);
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) DriverHandler(org.onosproject.net.driver.DriverHandler) ArrayList(java.util.ArrayList) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController)

Example 8 with NetconfController

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

use of org.onosproject.netconf.NetconfController 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 10 with NetconfController

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

Aggregations

NetconfController (org.onosproject.netconf.NetconfController)80 NetconfException (org.onosproject.netconf.NetconfException)61 DeviceId (org.onosproject.net.DeviceId)42 NetconfSession (org.onosproject.netconf.NetconfSession)39 DriverHandler (org.onosproject.net.driver.DriverHandler)22 MastershipService (org.onosproject.mastership.MastershipService)20 NetconfDevice (org.onosproject.netconf.NetconfDevice)20 XPath (javax.xml.xpath.XPath)16 XPathExpressionException (javax.xml.xpath.XPathExpressionException)16 Node (org.w3c.dom.Node)16 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 ConnectPoint (org.onosproject.net.ConnectPoint)9 NodeList (org.w3c.dom.NodeList)8 DeviceService (org.onosproject.net.device.DeviceService)7 Device (org.onosproject.net.Device)6 PortDescription (org.onosproject.net.device.PortDescription)5 HashSet (java.util.HashSet)4 DefaultPortStatistics (org.onosproject.net.device.DefaultPortStatistics)4