Search in sources :

Example 61 with NetconfSession

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

the class Ciena5162PortAdmin 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 62 with NetconfSession

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

the class ControllerConfigJuniperImpl method retrieveResultCommand.

private String retrieveResultCommand(String command) {
    NetconfSession session = getSession();
    String reply;
    if (session == null) {
        log.error("Cannot get session : {}", command);
        return null;
    }
    try {
        reply = session.requestSync(command).trim();
        log.debug(reply);
    } catch (NetconfException e) {
        log.debug(e.getMessage());
        return null;
    }
    return reply;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException)

Example 63 with NetconfSession

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

the class FlowRuleJuniperImpl method commit.

private boolean commit() {
    NetconfSession session = lookupNetconfSession(handler().data().deviceId());
    String replay;
    try {
        replay = session.get(commitBuilder());
    } catch (NetconfException e) {
        throw new IllegalStateException(new NetconfException("Failed to retrieve configuration.", e));
    }
    return replay != null && replay.contains(OK);
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString)

Example 64 with NetconfSession

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

the class DeviceDiscoveryJuniperImpl method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    DeviceId devId = handler().data().deviceId();
    NetconfSession session = lookupNetconfSession(devId);
    String reply;
    try {
        reply = session.get(requestBuilder(REQ_IF_INFO));
    } catch (NetconfException e) {
        log.warn("Failed to retrieve interface-information for device {}", devId);
        return ImmutableList.of();
    }
    log.trace("Device {} interface-information {}", devId, reply);
    List<PortDescription> descriptions = JuniperUtils.parseJuniperPorts(loadXmlString(reply));
    log.debug("Device {} Discovered ports {}", devId, descriptions);
    return descriptions;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) PortDescription(org.onosproject.net.device.PortDescription) XmlConfigParser.loadXmlString(org.onosproject.drivers.utilities.XmlConfigParser.loadXmlString)

Example 65 with NetconfSession

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

the class FlowRuleJuniperImpl method manageRules.

private Collection<FlowRule> manageRules(Collection<FlowRule> rules, OperationType type) {
    DeviceId deviceId = this.data().deviceId();
    log.debug("{} flow entries to NETCONF device {}", type, deviceId);
    NetconfSession session = lookupNetconfSession(deviceId);
    Collection<FlowRule> managedRules = new HashSet<>();
    for (FlowRule flowRule : rules) {
        Optional<IPCriterion> ipCriterion = getIpCriterion(flowRule);
        if (!ipCriterion.isPresent()) {
            log.error("Currently not supported: IPv4 destination match must be used");
            continue;
        }
        Optional<OutputInstruction> output = getOutput(flowRule);
        if (!output.isPresent()) {
            log.error("Currently not supported: the output action is needed");
            continue;
        }
        getStaticRoute(deviceId, ipCriterion.get(), output.get(), flowRule.priority()).ifPresent(staticRoute -> {
            // If the static route is not local, the driver tries to install
            if (!staticRoute.isLocalRoute()) {
                // FlowRule as installed.
                if (editRoute(session, type, staticRoute)) {
                    managedRules.add(flowRule);
                }
            // If static route are local, they are not installed
            // because are not required. Directly connected routes
            // are automatically forwarded.
            } else {
                managedRules.add(flowRule);
            }
        });
    }
    return rules;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) DeviceId(org.onosproject.net.DeviceId) FlowRule(org.onosproject.net.flow.FlowRule) HashSet(java.util.HashSet)

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