Search in sources :

Example 16 with NetconfSession

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

the class OpenconfigBitErrorRateState method getPreFecBer.

/**
 * Get the BER value pre FEC.
 *
 * @param deviceId the device identifier
 * @param port     the port identifier
 * @return the decimal value of BER
 */
@Override
public Optional<Double> getPreFecBer(DeviceId deviceId, PortNumber port) {
    NetconfSession session = NetconfSessionUtility.getNetconfSession(deviceId, getController());
    checkNotNull(session);
    String preFecBerFilter = generateBerFilter(deviceId, port, PRE_FEC_BER_TAG);
    String rpcRequest = getConfigOperation(preFecBerFilter);
    log.debug("RPC call for fetching Pre FEC BER : {}", rpcRequest);
    XMLConfiguration xconf = NetconfSessionUtility.executeRpc(session, rpcRequest);
    if (xconf == null) {
        log.error("Error in executing Pre FEC BER RPC");
        return Optional.empty();
    }
    try {
        HierarchicalConfiguration config = xconf.configurationAt("data/components/component/transceiver/state/" + PRE_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)

Example 17 with NetconfSession

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

the class AbstractTerminalDeviceFlowRuleProgrammable method removeFlowRules.

/**
 * Remove the specified flow rules.
 *
 * @param rules A collection of Flow Rules to be removed
 * @return The collection of removed Flow Entries
 */
@Override
public Collection<FlowRule> removeFlowRules(Collection<FlowRule> rules) {
    NetconfSession session = getNetconfSession();
    if (session == null) {
        openConfigError("null session");
        return ImmutableList.of();
    }
    List<FlowRule> removed = new ArrayList<>();
    for (FlowRule r : rules) {
        try {
            String connectionId = removeFlowRule(session, r);
            getConnectionCache().remove(did(), connectionId);
            removed.add(r);
        } catch (Exception e) {
            openConfigError("Error {}", e);
            continue;
        }
    }
    openConfigLog("removedFlowRules removed {}", 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 18 with NetconfSession

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

the class ClientLineTerminalDeviceFlowRuleProgrammable method fetchClientConnectionFromDevice.

private List<FlowRule> fetchClientConnectionFromDevice(PortNumber clientPortNumber, PortNumber linePortNumber) {
    List<FlowRule> confirmedRules = new ArrayList<>();
    FlowRule cacheAddRule;
    FlowRule cacheDropRule;
    NetconfSession session = getNetconfSession();
    // Build the corresponding flow rule as expected
    // Selector including port
    // Treatment including port
    log.debug("fetchClientConnectionsFromDevice {} client {} line {}", did(), clientPortNumber, linePortNumber);
    TrafficSelector selectorDrop = DefaultTrafficSelector.builder().matchInPort(linePortNumber).build();
    TrafficTreatment treatmentDrop = DefaultTrafficTreatment.builder().setOutput(clientPortNumber).build();
    TrafficSelector selectorAdd = DefaultTrafficSelector.builder().matchInPort(clientPortNumber).build();
    TrafficTreatment treatmentAdd = DefaultTrafficTreatment.builder().setOutput(linePortNumber).build();
    // Retrieved rules and cached rules are considered equal if both selector and treatment are equal
    cacheAddRule = null;
    cacheDropRule = null;
    if (getConnectionCache().size(did()) != 0) {
        cacheDropRule = getConnectionCache().get(did()).stream().filter(r -> (r.selector().equals(selectorDrop) && r.treatment().equals(treatmentDrop))).findFirst().orElse(null);
        cacheAddRule = getConnectionCache().get(did()).stream().filter(r -> (r.selector().equals(selectorAdd) && r.treatment().equals(treatmentAdd))).findFirst().orElse(null);
    }
    // Include the DROP rule to the retrieved rules if found in cache
    if ((cacheDropRule != null)) {
        confirmedRules.add(cacheDropRule);
        log.debug("fetchClientConnectionsFromDevice {} DROP CLIENT rule in the cache {}", did(), cacheDropRule);
    } else {
        log.warn("fetchClientConnectionsFromDevice {} DROP CLIENT rule not found in cache", did());
    }
    // Include the ADD rule to the retrieved rules if found in cache
    if ((cacheAddRule != null)) {
        confirmedRules.add(cacheAddRule);
        log.debug("fetchClientConnectionsFromDevice {} ADD CLIENT rule in the cache {}", did(), cacheAddRule);
    } else {
        log.warn("fetchClientConnectionsFromDevice {} ADD CLIENT rule not found in cache", did());
    }
    if ((cacheDropRule == null) && (cacheAddRule == null)) {
        log.warn("fetchClientConnectionsFromDevice {} ADD and DROP rule not included in the cache", did());
        FlowRule deviceDropRule = DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selectorDrop).withTreatment(treatmentDrop).withCookie(DEFAULT_RULE_COOKIE).withPriority(DEFAULT_RULE_PRIORITY).build();
        FlowRule deviceAddRule = DefaultFlowRule.builder().forDevice(data().deviceId()).makePermanent().withSelector(selectorAdd).withTreatment(treatmentAdd).withCookie(DEFAULT_RULE_COOKIE).withPriority(DEFAULT_RULE_PRIORITY).build();
        try {
            // TODO this is not required if allowExternalFlowRules
            TerminalDeviceFlowRule addRule = new TerminalDeviceFlowRule(deviceAddRule, getLinePorts());
            removeFlowRule(session, addRule);
            TerminalDeviceFlowRule dropRule = new TerminalDeviceFlowRule(deviceDropRule, getLinePorts());
            removeFlowRule(session, dropRule);
        } catch (NetconfException e) {
            openConfigError("Error removing CLIENT rule from device", e);
        }
    }
    return confirmedRules;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) GridType(org.onosproject.net.GridType) XPath(javax.xml.xpath.XPath) FlowRuleProgrammable(org.onosproject.net.flow.FlowRuleProgrammable) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) FlowEntry(org.onosproject.net.flow.FlowEntry) Spectrum(org.onlab.util.Spectrum) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) NetconfSession(org.onosproject.netconf.NetconfSession) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) ArrayList(java.util.ArrayList) Frequency(org.onlab.util.Frequency) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) ByteArrayInputStream(java.io.ByteArrayInputStream) NetconfController(org.onosproject.netconf.NetconfController) Document(org.w3c.dom.Document) NamespaceContext(javax.xml.namespace.NamespaceContext) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OchSignalType(org.onosproject.net.OchSignalType) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) InputSource(org.xml.sax.InputSource) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) XmlConfigParser(org.onosproject.drivers.utilities.XmlConfigParser) OdtnDeviceDescriptionDiscovery(org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery) Collectors(java.util.stream.Collectors) DeviceConnectionCache(org.onosproject.drivers.odtn.impl.DeviceConnectionCache) OchSignal(org.onosproject.net.OchSignal) DatastoreId(org.onosproject.netconf.DatastoreId) XPathFactory(javax.xml.xpath.XPathFactory) List(java.util.List) StringReader(java.io.StringReader) FlowRuleParser(org.onosproject.drivers.odtn.impl.FlowRuleParser) FlowRule(org.onosproject.net.flow.FlowRule) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ChannelSpacing(org.onosproject.net.ChannelSpacing) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DeviceId(org.onosproject.net.DeviceId) NetconfException(org.onosproject.netconf.NetconfException) ArrayList(java.util.ArrayList) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 19 with NetconfSession

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

the class OpenRoadmDeviceDescription method discoverPortDetails.

/**
 * Returns a list of PortDescriptions for the device.
 *
 * @return a list of descriptions.
 */
/*
     * Assumptions: ROADM degree ports are Oms carrying 80 lambdas (should be
     *              configurable)
     *              ROADM SRG (client) ports are OCh carrying ODU4 (should be
     *              configurable)
     */
@Override
public List<PortDescription> discoverPortDetails() {
    NetconfSession session = getNetconfSession(did());
    if (session == null) {
        log.error("discoverPortDetails null session for {}", did());
        return ImmutableList.of();
    }
    if (!getDevice().annotations().keys().contains("openroadm-node-id")) {
        log.error("Unable to run PortDiscovery: missing openroadm-node-id annotation." + " Probable failure during DeviceDiscovery. Aborting!");
        return ImmutableList.of();
    }
    List<HierarchicalConfiguration> externalLinks = getExternalLinks(session);
    List<PortDescription> list = new ArrayList<PortDescription>();
    discoverDegreePorts(session, list, externalLinks);
    discoverSrgPorts(session, list, externalLinks);
    return list;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) ArrayList(java.util.ArrayList) PortDescription(org.onosproject.net.device.PortDescription) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 20 with NetconfSession

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

the class OpenRoadmDeviceDescription method discoverDeviceDetails.

/**
 * Returns a DeviceDescription with Device info.
 *
 * @return DeviceDescription or null
 */
@Override
public DeviceDescription discoverDeviceDetails() {
    boolean defaultAvailable = true;
    NetconfDevice ncDevice = getNetconfDevice();
    if (ncDevice == null) {
        log.error("ONOS Error: Device reachable, deviceID {} is not in Map", did());
        return null;
    }
    DefaultAnnotations.Builder annotationsBuilder = DefaultAnnotations.builder();
    // Some defaults
    String vendor = "UNKNOWN";
    String hwVersion = "2.2.0";
    String swVersion = "2.2.0";
    String serialNumber = "0x0000";
    String chassisId = "0";
    String nodeType = "rdm";
    // Get the session, if null, at least we can use the defaults.
    NetconfSession session = getNetconfSession(did());
    if (session != null) {
        try {
            String reply = session.rpc(getDeviceDetailsBuilder()).get();
            XMLConfiguration xconf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
            String nodeId = xconf.getString("data.org-openroadm-device.info.node-id", "");
            if (nodeId.equals("")) {
                log.error("[OPENROADM] {} org-openroadm-device node-id undefined, returning", did());
                return null;
            }
            annotationsBuilder.set(AnnotationKeys.OPENROADM_NODEID, nodeId);
            nodeType = xconf.getString("data.org-openroadm-device.info.node-type", "");
            if (nodeType.equals("")) {
                log.error("[OPENROADM] {} empty node-type", did());
                return null;
            }
            vendor = xconf.getString("data.org-openroadm-device.info.vendor", vendor);
            hwVersion = xconf.getString("data.org-openroadm-device.info.model", hwVersion);
            swVersion = xconf.getString("data.org-openroadm-device.info.softwareVersion", swVersion);
            serialNumber = xconf.getString("data.org-openroadm-device.info.serial-id", serialNumber);
            chassisId = xconf.getString("data.org-openroadm-device.info.node-number", chassisId);
            // GEOLOCATION
            String longitudeStr = xconf.getString("data.org-openroadm-device.info.geoLocation.longitude");
            String latitudeStr = xconf.getString("data.org-openroadm-device.info.geoLocation.latitude");
            if (longitudeStr != null && latitudeStr != null) {
                annotationsBuilder.set(org.onosproject.net.AnnotationKeys.LONGITUDE, longitudeStr).set(org.onosproject.net.AnnotationKeys.LATITUDE, latitudeStr);
            }
        } catch (NetconfException | InterruptedException | ExecutionException e) {
            log.error("[OPENROADM] {} exception", did());
            return null;
        }
    } else {
        log.debug("[OPENROADM] - No  session {}", did());
    }
    log.debug("[OPENROADM] {} - VENDOR {} HWVERSION {} SWVERSION {} SERIAL {} CHASSIS {}", did(), vendor, hwVersion, swVersion, serialNumber, chassisId);
    ChassisId cid = new ChassisId(Long.valueOf(chassisId, 10));
    /*
         * OpenROADM defines multiple devices (node types). This driver has been tested with
         * ROADMS, (node type, "rdm"). Other devices can also be discovered, and this code is here
         * for future developments - untested - it is likely that the XML documents
         * are model specific.
         */
    org.onosproject.net.Device.Type type;
    if (nodeType.equals("rdm")) {
        type = org.onosproject.net.Device.Type.ROADM;
    } else if (nodeType.equals("ila")) {
        type = org.onosproject.net.Device.Type.OPTICAL_AMPLIFIER;
    } else if (nodeType.equals("xpdr")) {
        type = org.onosproject.net.Device.Type.TERMINAL_DEVICE;
    } else if (nodeType.equals("extplug")) {
        type = org.onosproject.net.Device.Type.OTHER;
    } else {
        log.error("[OPENROADM] {} unsupported node-type", did());
        return null;
    }
    DeviceDescription desc = new DefaultDeviceDescription(did().uri(), type, vendor, hwVersion, swVersion, serialNumber, cid, defaultAvailable, annotationsBuilder.build());
    return desc;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) ChassisId(org.onlab.packet.ChassisId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) NetconfDevice(org.onosproject.netconf.NetconfDevice) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) NetconfException(org.onosproject.netconf.NetconfException) NetconfDevice(org.onosproject.netconf.NetconfDevice) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) ExecutionException(java.util.concurrent.ExecutionException)

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