Search in sources :

Example 26 with NetconfException

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

the class CzechLightDiscovery method discoverDeviceDetails.

@Override
public DeviceDescription discoverDeviceDetails() {
    NetconfSession session = getNetconfSession();
    if (session == null) {
        log.error("Cannot request NETCONF session for {}", data().deviceId());
        return null;
    }
    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
    final var noDevice = new DefaultDeviceDescription(handler().data().deviceId().uri(), Device.Type.OTHER, null, null, null, null, null, annotations.build());
    try {
        Boolean isLineDegree = false, isAddDrop = false, isCoherentAddDrop = false, isInlineAmp = false;
        var data = doGetXPath(getNetconfSession(), YANGLIB_XML_PREFIX, YANGLIB_XMLNS, YANGLIB_XPATH_FILTER);
        if (!data.containsKey(YANGLIB_KEY_REVISION)) {
            log.error("Not talking to a supported CzechLight device, is that a teapot?");
            return noDevice;
        }
        final var revision = data.getString(YANGLIB_KEY_REVISION);
        if (data.getString(YANGLIB_KEY_MODULE_NAME).equals(MOD_ROADM_DEVICE)) {
            if (!revision.equals(MOD_ROADM_DEVICE_DATE)) {
                log.error("Revision mismatch for YANG module {}: got {}", MOD_ROADM_DEVICE, revision);
                return noDevice;
            }
            final var features = data.getStringArray(YANGLIB_PATH_QUERY_FEATURES);
            isLineDegree = Arrays.stream(features).anyMatch(s -> s.equals(MOD_ROADM_FEATURE_LINE_DEGREE));
            isAddDrop = Arrays.stream(features).anyMatch(s -> s.equals(MOD_ROADM_FEATURE_FLEX_ADD_DROP));
            if (!isLineDegree && !isAddDrop) {
                log.error("Device type not recognized, but {} YANG model is present. Reported YANG features: {}", MOD_ROADM_DEVICE, String.join(", ", features));
                return noDevice;
            }
        } else if (data.getString(YANGLIB_KEY_MODULE_NAME).equals(MOD_COHERENT_A_D)) {
            if (!revision.equals(MOD_COHERENT_A_D_DATE)) {
                log.error("Revision mismatch for YANG module {}: got {}", MOD_COHERENT_A_D, revision);
                return noDevice;
            }
            isCoherentAddDrop = true;
        } else if (data.getString(YANGLIB_KEY_MODULE_NAME).equals(MOD_INLINE_AMP)) {
            if (!revision.equals(MOD_INLINE_AMP_DATE)) {
                log.error("Revision mismatch for YANG module {}: got {}", MOD_INLINE_AMP, revision);
                return noDevice;
            }
            isInlineAmp = true;
        }
        if (isLineDegree) {
            log.info("Talking to a Line/Degree ROADM node");
            annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.LINE_DEGREE.toString());
        } else if (isAddDrop) {
            log.info("Talking to an Add/Drop ROADM node");
            annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.ADD_DROP_FLEX.toString());
        } else if (isCoherentAddDrop) {
            log.info("Talking to a Coherent Add/Drop ROADM node");
            annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.COHERENT_ADD_DROP.toString());
        } else if (isInlineAmp) {
            log.info("Talking to an inline ampifier, not a ROADM, but we will fake it as a ROADM for now");
            annotations.set(DEVICE_TYPE_ANNOTATION, DeviceType.INLINE_AMP.toString());
        } else {
            log.error("Device type not recognized");
            return noDevice;
        }
    } catch (NetconfException e) {
        log.error("Cannot request ietf-yang-library data", e);
        return noDevice;
    }
    // FIXME: initialize these
    String vendor = "CzechLight";
    String hwVersion = "n/a";
    String swVersion = "n/a";
    String serialNumber = "n/a";
    ChassisId chassisId = null;
    return new DefaultDeviceDescription(handler().data().deviceId().uri(), Device.Type.ROADM, vendor, hwVersion, swVersion, serialNumber, chassisId, annotations.build());
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) OmsPortHelper.omsPortDescription(org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription) Arrays(java.util.Arrays) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) AnnotationKeys(org.onosproject.net.AnnotationKeys) NetconfSession(org.onosproject.netconf.NetconfSession) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) Frequency(org.onlab.util.Frequency) Lists(com.google.common.collect.Lists) NetconfController(org.onosproject.netconf.NetconfController) PortDescription(org.onosproject.net.device.PortDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DeviceDescription(org.onosproject.net.device.DeviceDescription) Logger(org.slf4j.Logger) Device(org.onosproject.net.Device) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) 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) DatastoreId(org.onosproject.netconf.DatastoreId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) List(java.util.List) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ChannelSpacing(org.onosproject.net.ChannelSpacing) DeviceId(org.onosproject.net.DeviceId) ChassisId(org.onlab.packet.ChassisId) ChassisId(org.onlab.packet.ChassisId) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) NetconfException(org.onosproject.netconf.NetconfException) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription)

Example 27 with NetconfException

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

the class CzechLightFlowRuleProgrammable method getFlowEntries.

@Override
public Collection<FlowEntry> getFlowEntries() {
    if (deviceType() == CzechLightDiscovery.DeviceType.INLINE_AMP || deviceType() == CzechLightDiscovery.DeviceType.COHERENT_ADD_DROP) {
        final var data = getConnectionCache().get(data().deviceId());
        if (data == null) {
            return new ArrayList<>();
        }
        return data.stream().map(rule -> new DefaultFlowEntry(rule)).collect(Collectors.toList());
    }
    HierarchicalConfiguration xml;
    try {
        xml = doGetSubtree(CzechLightDiscovery.CHANNEL_DEFS_FILTER + CzechLightDiscovery.MC_ROUTING_FILTER);
    } catch (NetconfException e) {
        log.error("Cannot read data from NETCONF: {}", e);
        return new ArrayList<>();
    }
    final var allChannels = MediaChannelDefinition.parseChannelDefinitions(xml);
    Collection<FlowEntry> list = new ArrayList<>();
    final var allMCs = xml.configurationsAt("data.media-channels");
    allMCs.stream().map(cfg -> confToMCRouting(ELEMENT_ADD, allChannels, cfg)).filter(Objects::nonNull).forEach(flow -> {
        log.debug("{}: found ADD: {}", data().deviceId(), flow.toString());
        list.add(new DefaultFlowEntry(asFlowRule(Direction.ADD, flow), FlowEntry.FlowEntryState.ADDED));
    });
    allMCs.stream().map(cfg -> confToMCRouting(ELEMENT_DROP, allChannels, cfg)).filter(Objects::nonNull).forEach(flow -> {
        log.debug("{}: found DROP: {}", data().deviceId(), flow.toString());
        list.add(new DefaultFlowEntry(asFlowRule(Direction.DROP, flow), FlowEntry.FlowEntryState.ADDED));
    });
    return list;
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) GridType(org.onosproject.net.GridType) FlowRuleProgrammable(org.onosproject.net.flow.FlowRuleProgrammable) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) 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) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) NetconfSession(org.onosproject.netconf.NetconfSession) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) OchSignalCriterion(org.onosproject.net.flow.criteria.OchSignalCriterion) ArrayList(java.util.ArrayList) FlowRuleService(org.onosproject.net.flow.FlowRuleService) TrafficSelector(org.onosproject.net.flow.TrafficSelector) NetconfController(org.onosproject.netconf.NetconfController) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) Map(java.util.Map) 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) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) Lambda(org.onosproject.net.Lambda) Collectors(java.util.stream.Collectors) DeviceConnectionCache(org.onosproject.drivers.odtn.impl.DeviceConnectionCache) OchSignal(org.onosproject.net.OchSignal) Objects(java.util.Objects) DatastoreId(org.onosproject.netconf.DatastoreId) TreeMap(java.util.TreeMap) FlowRule(org.onosproject.net.flow.FlowRule) ChannelSpacing(org.onosproject.net.ChannelSpacing) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry) NetconfException(org.onosproject.netconf.NetconfException) ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) FlowEntry(org.onosproject.net.flow.FlowEntry) DefaultFlowEntry(org.onosproject.net.flow.DefaultFlowEntry)

Example 28 with NetconfException

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

the class CzechLightFlowRuleProgrammable method removeFlowRules.

@Override
public Collection<FlowRule> removeFlowRules(Collection<FlowRule> rules) {
    if (deviceType() == CzechLightDiscovery.DeviceType.INLINE_AMP || deviceType() == CzechLightDiscovery.DeviceType.COHERENT_ADD_DROP) {
        rules.forEach(rule -> {
            log.debug("{}: asked to remove {} (whole C-band is always forwarded by the HW)", data().deviceId(), rule);
            getConnectionCache().remove(data().deviceId(), rule);
        });
        return rules;
    }
    HierarchicalConfiguration xml;
    try {
        xml = doGetSubtree(CzechLightDiscovery.CHANNEL_DEFS_FILTER + CzechLightDiscovery.MC_ROUTING_FILTER);
    } catch (NetconfException e) {
        log.error("Cannot read data from NETCONF: {}", e);
        return new ArrayList<>();
    }
    final var allChannels = MediaChannelDefinition.parseChannelDefinitions(xml);
    var hopefullyRemoved = new ArrayList<FlowRule>();
    // temporary store because both ADD and DROP must go into the same <media-channel> list item
    var changes = new TreeMap<String, String>();
    rules.forEach(rule -> {
        final String element = inputPortFromFlow(rule).toLong() == CzechLightDiscovery.PORT_COMMON ? ELEMENT_DROP : ELEMENT_ADD;
        final var och = ochSignalFromFlow(rule);
        final var channel = allChannels.entrySet().stream().filter(entry -> MediaChannelDefinition.mcMatches(entry, och)).findAny().orElse(null);
        if (channel == null) {
            log.error("Cannot find what channel to remove for the following flow rule at {}:", data().deviceId());
            rule.selector().criteria().forEach(criteria -> log.error("  criteria {}", criteria.toString()));
            rule.treatment().allInstructions().forEach(instruction -> log.error("  instruction {}", instruction.toString()));
        } else {
            log.info("{}: Removing {} MC {}", data().deviceId(), element, channel.getKey());
            changes.put(channel.getKey(), changes.getOrDefault(channel.getKey(), "") + "<" + element + " nc:operation=\"remove\"/>");
            hopefullyRemoved.add(rule);
        }
    });
    if (!hopefullyRemoved.isEmpty()) {
        var sb = new StringBuilder();
        changes.forEach((channel, data) -> {
            sb.append(CzechLightDiscovery.XML_MC_OPEN);
            sb.append("<channel>");
            sb.append(channel);
            sb.append("</channel>");
            sb.append(data);
            sb.append(CzechLightDiscovery.XML_MC_CLOSE);
        });
        doEditConfig(NETCONF_OP_NONE, sb.toString());
    }
    return hopefullyRemoved;
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) ArrayList(java.util.ArrayList) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) TreeMap(java.util.TreeMap)

Example 29 with NetconfException

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

the class CzechLightPowerConfig method setTargetPower.

// Used by the ROADM app to set the "attenuation" parameter
@Override
public void setTargetPower(PortNumber port, T component, double power) {
    switch(deviceType()) {
        case LINE_DEGREE:
        case ADD_DROP_FLEX:
            if (!(component instanceof OchSignal)) {
                log.error("Cannot set target power on anything but a Media Channel");
                return;
            }
            HierarchicalConfiguration xml;
            try {
                xml = doGetSubtree(CzechLightDiscovery.CHANNEL_DEFS_FILTER + CzechLightDiscovery.MC_ROUTING_FILTER);
            } catch (NetconfException e) {
                log.error("Cannot read data from NETCONF: {}", e);
                return;
            }
            final var allChannels = MediaChannelDefinition.parseChannelDefinitions(xml);
            final var och = ((OchSignal) component);
            final var channel = allChannels.entrySet().stream().filter(entry -> MediaChannelDefinition.mcMatches(entry, och)).findAny().orElse(null);
            if (channel == null) {
                log.error("Cannot map OCh definition {} to a channel from the channel plan", och);
                return;
            }
            final String element = port.toLong() == CzechLightDiscovery.PORT_COMMON ? "add" : "drop";
            log.debug("{}: setting power for MC {} to {}", data().deviceId(), channel.getKey().toUpperCase(), power);
            var sb = new StringBuilder();
            sb.append(CzechLightDiscovery.XML_MC_OPEN);
            sb.append("<channel>");
            sb.append(channel.getKey());
            sb.append("</channel>");
            sb.append("<");
            sb.append(element);
            sb.append("><power>");
            sb.append(power);
            sb.append("</power></");
            sb.append(element);
            sb.append(">");
            sb.append(CzechLightDiscovery.XML_MC_CLOSE);
            doEditConfig("merge", sb.toString());
            return;
        default:
            log.error("Target power is only supported on WSS-based devices");
            return;
    }
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) OchSignal(org.onosproject.net.OchSignal) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 30 with NetconfException

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

the class Ciena5170DeviceDescription method getLinks.

@Override
public Set<LinkDescription> getLinks() {
    log.debug("LINKS CHECKING ...");
    Set<LinkDescription> links = new HashSet<LinkDescription>();
    DeviceId deviceId = handler().data().deviceId();
    NetconfController controller = checkNotNull(handler().get(NetconfController.class));
    if (controller == null || controller.getDevicesMap() == null || controller.getDevicesMap().get(deviceId) == null) {
        log.warn("NETCONF session to device {} not yet established, cannot load links, will be retried", deviceId);
        return links;
    }
    NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
    try {
        DeviceService deviceService = this.handler().get(DeviceService.class);
        Iterable<Device> devices = deviceService.getAvailableDevices();
        Map<String, Device> lookup = new HashMap<String, Device>();
        for (Device d : devices) {
            lookup.put(d.chassisId().toString().toUpperCase(), d);
        }
        Node logicalPorts = TEMPLATE_MANAGER.doRequest(session, "link-info");
        XPath xp = XPathFactory.newInstance().newXPath();
        NodeList ifaces = (NodeList) xp.evaluate("interfaces/interface", logicalPorts, XPathConstants.NODESET);
        int count = ifaces.getLength();
        Node iface;
        Node destChassis;
        for (int i = 0; i < count; i += 1) {
            iface = ifaces.item(i);
            if (xp.evaluate("config/type/text()", iface).equals("ettp")) {
                destChassis = (Node) xp.evaluate("state/lldp-remote-port-operational/chassis-id", iface, XPathConstants.NODE);
                if (destChassis != null) {
                    Device dest = lookup.get(destChassis.getTextContent().toUpperCase());
                    if (dest != null) {
                        links.add(new DefaultLinkDescription(new ConnectPoint(dest.id(), PortNumber.portNumber(xp.evaluate("state/lldp-remote-port-operational/port-id/text()", iface))), new ConnectPoint(deviceId, PortNumber.portNumber(xp.evaluate("name/text()", iface))), Link.Type.DIRECT, true));
                    } else {
                        log.warn("DEST chassisID not found: chassis {} port {}", destChassis.getTextContent().toUpperCase(), xp.evaluate("name/text()", iface));
                    }
                } else {
                    log.debug("NO LINK for {}", xp.evaluate("name/text()", iface));
                }
            }
        }
    } catch (NetconfException | XPathExpressionException e) {
        log.error("Unable to retrieve links for device {}, {}", deviceId, e);
    }
    return links;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XPath(javax.xml.xpath.XPath) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) HashMap(java.util.HashMap) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) DeviceService(org.onosproject.net.device.DeviceService) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfController(org.onosproject.netconf.NetconfController) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfException(org.onosproject.netconf.NetconfException) HashSet(java.util.HashSet) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription)

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