Search in sources :

Example 21 with NetconfException

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

the class OpenRoadmDeviceDescription method getCircuitPackByName.

/**
 * Get config and status info for a specific circuit pack as a
 * list of XML hierarchical configs.
 * @param session the NETConf session to the OpenROADM device.
 * @param cpName the name of the requested circuit-pack
 * @return the hierarchical conf. for the circuit pack.
 */
HierarchicalConfiguration getCircuitPackByName(NetconfSession session, String cpName) {
    try {
        String reply = session.rpc(getDeviceCircuitPackByNameBuilder(cpName)).get();
        XMLConfiguration cpConf = (XMLConfiguration) XmlConfigParser.loadXmlString(reply);
        cpConf.setExpressionEngine(new XPathExpressionEngine());
        List<HierarchicalConfiguration> cPacks = cpConf.configurationsAt("/data/org-openroadm-device/circuit-packs");
        // It shouldn't happen they are > 1
        if (cPacks.size() > 1) {
            log.warn("[OPENROADM] More than one circuit pack with the same name. Using first one");
        }
        return cPacks.get(0);
    } catch (NetconfException | InterruptedException | ExecutionException e) {
        log.error("[OPENROADM] {} exception getting circuit pack {}: {}", did(), cpName, e);
        return null;
    }
}
Also used : XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) NetconfException(org.onosproject.netconf.NetconfException) XPathExpressionEngine(org.apache.commons.configuration.tree.xpath.XPathExpressionEngine) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) ExecutionException(java.util.concurrent.ExecutionException)

Example 22 with NetconfException

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

Example 23 with NetconfException

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

the class ClientLineTerminalDeviceFlowRuleProgrammable method removeFlowRule.

protected boolean removeFlowRule(NetconfSession session, TerminalDeviceFlowRule rule) throws NetconfException {
    // --- disable the line port
    if (rule.type == TerminalDeviceFlowRule.Type.LINE_INGRESS || rule.type == TerminalDeviceFlowRule.Type.LINE_EGRESS) {
        FlowRuleParser frp = new FlowRuleParser(rule);
        String componentName = frp.getPortNumber().toString();
        log.info("Removing LINE FlowRule device {} line port {}", did(), componentName);
        try {
            setLogicalChannel(session, OPERATION_DISABLE, componentName);
        } catch (NetconfException e) {
            log.error("Error disabling the logical channel line side");
            return false;
        }
    }
    // --- disable the line port
    if (rule.type == TerminalDeviceFlowRule.Type.CLIENT_INGRESS || rule.type == TerminalDeviceFlowRule.Type.CLIENT_EGRESS) {
        String clientPortName;
        String linePortName;
        if (rule.type == TerminalDeviceFlowRule.Type.CLIENT_INGRESS) {
            clientPortName = rule.inPort().toString();
            linePortName = rule.outPort().toString();
        } else {
            clientPortName = rule.outPort().toString();
            linePortName = rule.inPort().toString();
        }
        log.debug("Removing CLIENT FlowRule device {} client port: {}, line port {}", did(), clientPortName, linePortName);
        try {
            setLogicalChannelAssignment(session, OPERATION_DISABLE, clientPortName, linePortName, DEFAULT_ASSIGNMENT_INDEX, DEFAULT_ALLOCATION_INDEX);
        } catch (NetconfException e) {
            log.error("Error disabling the logical channel assignment");
            return false;
        }
    }
    return true;
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) FlowRuleParser(org.onosproject.drivers.odtn.impl.FlowRuleParser)

Example 24 with NetconfException

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

the class ClientLineTerminalDeviceFlowRuleProgrammable method fetchLineConnectionFromDevice.

private List<FlowRule> fetchLineConnectionFromDevice(String channel, Frequency centralFreq) {
    List<FlowRule> confirmedRules = new ArrayList<>();
    FlowRule cacheAddRule;
    FlowRule cacheDropRule;
    NetconfSession session = getNetconfSession();
    log.debug("fetchOpticalConnectionsFromDevice {} frequency {}", did(), centralFreq);
    // Build the corresponding flow rule as expected
    // Selector including port and ochSignal
    // Treatment including port
    PortNumber inputPortNumber = PortNumber.portNumber(channel);
    PortNumber outputPortNumber = PortNumber.portNumber(channel);
    log.debug("fetchOpticalConnectionsFromDevice {} port {}-{}", did(), inputPortNumber, outputPortNumber);
    TrafficSelector selectorDrop = DefaultTrafficSelector.builder().matchInPort(inputPortNumber).add(Criteria.matchLambda(toOchSignal(centralFreq, 50.0))).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).build();
    TrafficTreatment treatmentDrop = DefaultTrafficTreatment.builder().setOutput(outputPortNumber).build();
    TrafficSelector selectorAdd = DefaultTrafficSelector.builder().matchInPort(inputPortNumber).build();
    TrafficTreatment treatmentAdd = DefaultTrafficTreatment.builder().add(Instructions.modL0Lambda(toOchSignal(centralFreq, 50.0))).setOutput(outputPortNumber).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("fetchOpticalConnectionsFromDevice {} DROP LINE rule included in the cache {}", did(), cacheDropRule);
    } else {
        log.warn("fetchOpticalConnectionsFromDevice {} DROP LINE rule not included in cache", did());
    }
    // Include the ADD rule to the retrieved rules if found in cache
    if ((cacheAddRule != null)) {
        confirmedRules.add(cacheAddRule);
        log.debug("fetchOpticalConnectionsFromDevice {} ADD LINE rule included in the cache {}", did(), cacheAddRule.selector());
    } else {
        log.warn("fetchOpticalConnectionsFromDevice {} ADD LINE rule not included in cache", did());
    }
    // If neither Add or Drop rules are present in the cache, remove configuration from the device
    if ((cacheDropRule == null) && (cacheAddRule == null)) {
        log.warn("fetchOpticalConnectionsFromDevice {} 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 LINE 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) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 25 with NetconfException

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

the class NetconfGetConfigCommand method doExecute.

@Override
protected void doExecute() {
    deviceId = DeviceId.deviceId(uri);
    NetconfController controller = get(NetconfController.class);
    checkNotNull(controller, "Netconf controller is null");
    NetconfDevice device = controller.getDevicesMap().get(deviceId);
    if (device == null) {
        print("Netconf device object not found for %s", deviceId);
        return;
    }
    NetconfSession session = device.getSession();
    if (session == null) {
        print("Netconf session not found for %s", deviceId);
        return;
    }
    try {
        CharSequence res = session.asyncGetConfig(datastore(datastore.toLowerCase())).get(timeoutSec, TimeUnit.SECONDS);
        print("%s", res);
    } catch (NetconfException | InterruptedException | ExecutionException | TimeoutException e) {
        log.error("Configuration could not be retrieved", e);
        print("Error occurred retrieving configuration");
    }
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) NetconfDevice(org.onosproject.netconf.NetconfDevice) ExecutionException(java.util.concurrent.ExecutionException) NetconfController(org.onosproject.netconf.NetconfController) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

NetconfException (org.onosproject.netconf.NetconfException)120 NetconfController (org.onosproject.netconf.NetconfController)65 NetconfSession (org.onosproject.netconf.NetconfSession)65 DeviceId (org.onosproject.net.DeviceId)50 XPath (javax.xml.xpath.XPath)23 DriverHandler (org.onosproject.net.driver.DriverHandler)22 XPathExpressionException (javax.xml.xpath.XPathExpressionException)19 Node (org.w3c.dom.Node)19 ByteArrayInputStream (java.io.ByteArrayInputStream)18 ArrayList (java.util.ArrayList)18 NetconfDevice (org.onosproject.netconf.NetconfDevice)18 MastershipService (org.onosproject.mastership.MastershipService)17 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)15 ExecutionException (java.util.concurrent.ExecutionException)12 Device (org.onosproject.net.Device)12 DefaultDeviceDescription (org.onosproject.net.device.DefaultDeviceDescription)12 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)11 DeviceService (org.onosproject.net.device.DeviceService)11 ChassisId (org.onlab.packet.ChassisId)10 HashMap (java.util.HashMap)9