Search in sources :

Example 1 with Builder

use of org.onosproject.net.device.DefaultPortDescription.Builder in project onos by opennetworkinglab.

the class TerminalDeviceDiscovery method parsePortComponent.

/**
 * Parses a component XML doc into a PortDescription.
 *
 * @param component subtree to parse. It must be a component ot type PORT.
 * @param components the full components tree, to cross-ref in
 *  case we need to check transceivers or optical channels.
 *
 * @return PortDescription or null if component does not have onos-index
 */
private PortDescription parsePortComponent(HierarchicalConfiguration component, HierarchicalConfiguration components) {
    Map<String, String> annotations = new HashMap<>();
    String name = component.getString("name");
    String type = component.getString("state/type");
    log.info("Parsing Component {} type {}", name, type);
    annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, name);
    annotations.put(OdtnDeviceDescriptionDiscovery.OC_TYPE, type);
    // Store all properties as port properties
    component.configurationsAt("properties/property").forEach(property -> {
        String pn = property.getString("name");
        String pv = property.getString("state/value");
        annotations.put(pn, pv);
    });
    // Assing an ONOS port number
    PortNumber portNum;
    if (annotations.containsKey(ONOS_PORT_INDEX)) {
        portNum = PortNumber.portNumber(Long.parseLong(annotations.get(ONOS_PORT_INDEX)));
    } else {
        log.warn("PORT {} does not include onos-index, hashing...", name);
        portNum = PortNumber.portNumber(name.hashCode());
    }
    log.debug("PORT {} number {}", name, portNum);
    // The heuristic to know if it is client or line side
    if (!annotations.containsKey(PORT_TYPE)) {
        if (hasTransceiverSubComponent(component, components)) {
            annotations.put(PORT_TYPE, OdtnPortType.CLIENT.value());
        } else if (hasOpticalChannelSubComponent(component, components)) {
            annotations.put(PORT_TYPE, OdtnPortType.LINE.value());
        }
    }
    // to be an issue with resource mapping
    if (annotations.get(PORT_TYPE).equals(OdtnPortType.CLIENT.value())) {
        log.debug("Adding CLIENT port");
        Builder builder = DefaultPortDescription.builder();
        builder.type(Type.PACKET);
        builder.withPortNumber(portNum);
        builder.annotations(DefaultAnnotations.builder().putAll(annotations).build());
        return builder.build();
    }
    if (annotations.get(PORT_TYPE).equals(OdtnPortType.LINE.value())) {
        log.debug("Adding LINE port");
        // TODO: To be configured
        OchSignal signalId = OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1);
        return OchPortHelper.ochPortDescription(portNum, true, // TODO Client signal to be discovered
        OduSignalType.ODU4, true, signalId, DefaultAnnotations.builder().putAll(annotations).build());
    }
    log.error("Unknown port type");
    return null;
}
Also used : HashMap(java.util.HashMap) Builder(org.onosproject.net.device.DefaultPortDescription.Builder) OchSignal(org.onosproject.net.OchSignal) PortNumber(org.onosproject.net.PortNumber)

Example 2 with Builder

use of org.onosproject.net.device.DefaultPortDescription.Builder in project onos by opennetworkinglab.

the class GrooveOpenConfigDeviceDiscovery method parseLogicalChannel.

/**
 * Parses a component XML doc into a PortDescription.
 *
 * @param channel subtree to parse. It must be a component ot type PORT.
 *  case we need to check transceivers or optical channels.
 *
 * @return PortDescription or null if component does not have onos-index
 */
private PortDescription parseLogicalChannel(HierarchicalConfiguration channel) {
    HierarchicalConfiguration config = channel.configurationAt("config");
    String logicalChannelIndex = config.getString("index");
    String description = config.getString("description");
    String rateClass = config.getString("rate-class");
    Map<String, String> annotations = new HashMap<>();
    annotations.put(OdtnDeviceDescriptionDiscovery.OC_LOGICAL_CHANNEL, logicalChannelIndex);
    HierarchicalConfiguration assignment = channel.configurationAt("logical-channel-assignments/assignment[index=1]/config");
    annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, assignment.getString("optical-channel"));
    // Store all properties as port properties
    // e.g. 100GE-1-14-C3
    Pattern clientPattern = Pattern.compile(".*-[1]-[1-9][0-4]?-C[3-9]$");
    // e.g. OTUC2-1-1-L2
    Pattern linePattern = Pattern.compile(".*-[1]-[1-9][0-4]?-L[1-2]$");
    Matcher clientMatch = clientPattern.matcher(description);
    Matcher lineMatch = linePattern.matcher(description);
    Pattern portSpeedPattern = Pattern.compile("TRIB_RATE_([0-9.]*)G");
    Matcher portSpeedMatch = portSpeedPattern.matcher(rateClass);
    Builder builder = DefaultPortDescription.builder();
    Long speed = 0L;
    if (portSpeedMatch.find()) {
        speed = Long.parseLong(portSpeedMatch.group(1));
        builder.portSpeed(speed * 1000);
    }
    if (clientMatch.find()) {
        log.info("Parsing CLIENT port {} type {} rate {}", logicalChannelIndex, description, rateClass);
        final String[] split = clientMatch.group(0).split("-");
        Long portNum = (10000 * Long.parseLong(split[1])) + (100 * Long.parseLong(split[2])) + Long.parseLong(split[3].replace("C", ""));
        String connectionId = "connection:" + portNum;
        annotations.putIfAbsent(PORT_TYPE, OdtnPortType.CLIENT.value());
        annotations.putIfAbsent(ONOS_PORT_INDEX, portNum.toString());
        annotations.putIfAbsent(CONNECTION_ID, connectionId);
        builder.withPortNumber(PortNumber.portNumber(portNum));
        builder.type(Type.PACKET);
        builder.annotations(DefaultAnnotations.builder().putAll(annotations).build());
        return builder.build();
    } else if (lineMatch.find()) {
        log.info("Parsing LINE port {} type {} rate {}", logicalChannelIndex, description, rateClass);
        final String[] split = lineMatch.group(0).split("-");
        Long portNum = (10000 * Long.parseLong(split[1])) + (100 * Long.parseLong(split[2])) + Long.parseLong(split[3].replace("L", ""));
        String connectionId = "connection:" + portNum;
        annotations.putIfAbsent(PORT_TYPE, OdtnPortType.LINE.value());
        annotations.putIfAbsent(ONOS_PORT_INDEX, portNum.toString());
        annotations.putIfAbsent(CONNECTION_ID, connectionId);
        OchSignal signalId = OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1);
        return OchPortHelper.ochPortDescription(PortNumber.portNumber(portNum), true, speed == 200 ? OduSignalType.ODUC2 : OduSignalType.ODU4, true, signalId, DefaultAnnotations.builder().putAll(annotations).build());
    } else {
        log.debug("Discarding component: {}", description);
        return null;
    }
}
Also used : Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) Builder(org.onosproject.net.device.DefaultPortDescription.Builder) OchSignal(org.onosproject.net.OchSignal) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 3 with Builder

use of org.onosproject.net.device.DefaultPortDescription.Builder in project onos by opennetworkinglab.

the class InfineraOpenConfigDeviceDiscovery method toPortDescriptionInternal.

/**
 * Converts Component subtree to PortDescription.
 *
 * @param component subtree to parse
 * @return PortDescription or null if component is not an ONOS Port
 */
private PortDescription toPortDescriptionInternal(HierarchicalConfiguration component) {
    // to access other part of <data> tree:
    // log.warn("parent data Node: {}",
    // ((SubnodeConfiguration) component).getParent().getRootNode().getName());
    String name = component.getString("name");
    checkNotNull(name);
    if (!name.contains("GIGECLIENTCTP")) {
        return null;
    }
    Builder builder = DefaultPortDescription.builder();
    Map<String, String> props = new HashMap<>();
    props.put(OdtnDeviceDescriptionDiscovery.OC_NAME, name);
    props.put(OdtnDeviceDescriptionDiscovery.OC_TYPE, name);
    Pattern clientPattern = Pattern.compile("GIGECLIENTCTP.1-A-2-T(\\d+)");
    Pattern linePattern = Pattern.compile("GIGECLIENTCTP.1-L(\\d+)-1-1");
    Matcher clientMatch = clientPattern.matcher(name);
    Matcher lineMatch = linePattern.matcher(name);
    if (clientMatch.find()) {
        String num = clientMatch.group(1);
        Integer connection = (Integer.parseInt(num) + 1) / 2;
        props.putIfAbsent(PORT_TYPE, OdtnPortType.CLIENT.value());
        props.putIfAbsent(CONNECTION_ID, "connection:" + connection.toString());
        builder.withPortNumber(PortNumber.portNumber(Long.parseLong(num), name));
        builder.type(Type.PACKET);
    } else if (lineMatch.find()) {
        String num = lineMatch.group(1);
        props.putIfAbsent(PORT_TYPE, OdtnPortType.LINE.value());
        props.putIfAbsent(CONNECTION_ID, "connection:" + num);
        builder.withPortNumber(PortNumber.portNumber(100 + Long.parseLong(num), name));
        builder.type(Type.OCH);
    } else {
        return null;
    }
    builder.annotations(DefaultAnnotations.builder().putAll(props).build());
    return builder.build();
}
Also used : Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) Builder(org.onosproject.net.device.DefaultPortDescription.Builder)

Example 4 with Builder

use of org.onosproject.net.device.DefaultPortDescription.Builder in project onos by opennetworkinglab.

the class NokiaOpenConfigDeviceDiscovery method toPortDescriptionInternal.

/**
 * Converts Component subtree to PortDescription.
 *
 * @param component subtree to parse
 * @return PortDescription or null if component is not an ONOS Port
 */
private PortDescription toPortDescriptionInternal(HierarchicalConfiguration component) {
    Map<String, String> annotations = new HashMap<>();
    String name = component.getString("name");
    String type = component.getString("state/type");
    checkNotNull(name, "name not found");
    checkNotNull(type, "state/type not found");
    annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, name);
    annotations.put(OdtnDeviceDescriptionDiscovery.OC_TYPE, type);
    component.configurationsAt("properties/property").forEach(property -> {
        String pn = property.getString("name");
        String pv = property.getString("state/value");
        annotations.put(pn, pv);
    });
    if (type.equals("oc-platform-types:PORT")) {
        String subComponentName = component.getString("subcomponents/subcomponent/name");
        String[] textStr = subComponentName.split("-");
        String portComponentType = textStr[0];
        String portComponentIndex = textStr[textStr.length - 1];
        String portNumber = component.getString("name");
        if (portComponentType.equals(OPTICAL_CHANNEL)) {
            annotations.putIfAbsent(PORT_TYPE, OdtnPortType.LINE.value());
            annotations.putIfAbsent(ONOS_PORT_INDEX, portComponentIndex.toString());
            annotations.putIfAbsent(CONNECTION_ID, "connection" + portComponentIndex.toString());
            annotations.putIfAbsent(AnnotationKeys.PORT_NAME, portNumber);
            OchSignal signalId = OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1);
            return OchPortHelper.ochPortDescription(PortNumber.portNumber(Long.parseLong(portComponentIndex)), true, // TODO Client signal to be discovered
            OduSignalType.ODU4, true, signalId, DefaultAnnotations.builder().putAll(annotations).build());
        } else if (portComponentType.equals(TRANSCEIVER)) {
            Builder builder = DefaultPortDescription.builder();
            annotations.putIfAbsent(PORT_TYPE, OdtnPortType.CLIENT.value());
            annotations.putIfAbsent(ONOS_PORT_INDEX, portComponentIndex.toString());
            annotations.putIfAbsent(CONNECTION_ID, "connection" + portComponentIndex.toString());
            annotations.putIfAbsent(AnnotationKeys.PORT_NAME, portNumber);
            builder.withPortNumber(PortNumber.portNumber(Long.parseLong(portComponentIndex), subComponentName));
            builder.type(Type.PACKET);
            builder.annotations(DefaultAnnotations.builder().putAll(annotations).build());
            return builder.build();
        } else {
            log.debug("Unknown port component type {}", type);
            return null;
        }
    } else {
        log.debug("Another component type {}", type);
        return null;
    }
}
Also used : HashMap(java.util.HashMap) Builder(org.onosproject.net.device.DefaultPortDescription.Builder) OchSignal(org.onosproject.net.OchSignal)

Example 5 with Builder

use of org.onosproject.net.device.DefaultPortDescription.Builder in project onos by opennetworkinglab.

the class OpenConfigDeviceDiscovery method toPortDescriptionInternal.

/**
 * Converts Component subtree to PortDescription.
 *
 * @param component subtree to parse
 * @return PortDescription or null if component is not an ONOS Port
 */
private PortDescription toPortDescriptionInternal(HierarchicalConfiguration component) {
    // to access other part of <data> tree:
    // log.warn("parent data Node: {}",
    // ((SubnodeConfiguration) component).getParent().getRootNode().getName());
    Map<String, String> props = new HashMap<>();
    String name = component.getString("name");
    String type = component.getString("state/type");
    checkNotNull(name, "name not found");
    checkNotNull(type, "state/type not found");
    props.put(OdtnDeviceDescriptionDiscovery.OC_NAME, name);
    props.put(OdtnDeviceDescriptionDiscovery.OC_TYPE, type);
    component.configurationsAt("properties/property").forEach(prop -> {
        String pName = prop.getString("name");
        String pValue = prop.getString("config/value");
        props.put(pName, pValue);
    });
    PortNumber number = null;
    if (!props.containsKey(ONOS_PORT_INDEX)) {
        log.info("DEBUG: Component {} does not include onos-index, skipping", name);
        // ODTN: port must have onos-index property
        number = PortNumber.portNumber(COUNTER.getAndIncrement(), name);
    } else {
        number = PortNumber.portNumber(Long.parseLong(props.get(ONOS_PORT_INDEX)), name);
    }
    Builder builder = DefaultPortDescription.builder();
    builder.withPortNumber(number);
    switch(type) {
        case "oc-platform-types:PORT":
        case "PORT":
        case "oc-opt-types:OPTICAL_CHANNEL":
        case "OPTICAL CHANNEL":
            // TODO assign appropriate port type & annotations at some point
            // for now we just need a Port with annotations
            builder.type(Type.OCH);
            props.putIfAbsent(PORT_TYPE, OdtnPortType.LINE.value());
            // Just a heuristics to deal with simple transponder
            // if the device declare odtn-connection-id, just use them
            // if not assign same value to relevant ports types
            props.putIfAbsent(CONNECTION_ID, "the-only-one");
            break;
        case "oc-platform-types:TRANSCEIVER":
        case "TRANSCEIVER":
            // TODO assign appropriate port type & annotations at some point
            // for now we just need a Port with annotations
            builder.type(Type.PACKET);
            props.putIfAbsent(PORT_TYPE, OdtnPortType.CLIENT.value());
            // Just a heuristics to deal with simple transponder
            // if the device declare odtn-connection-id, just use them
            // if not assign same value to relevant ports types
            props.putIfAbsent(CONNECTION_ID, "the-only-one");
            break;
        default:
            log.info("DEBUG: Unknown component type {}", type);
            return null;
    }
    builder.annotations(DefaultAnnotations.builder().putAll(props).build());
    return builder.build();
}
Also used : HashMap(java.util.HashMap) Builder(org.onosproject.net.device.DefaultPortDescription.Builder) PortNumber(org.onosproject.net.PortNumber)

Aggregations

HashMap (java.util.HashMap)8 Builder (org.onosproject.net.device.DefaultPortDescription.Builder)8 OchSignal (org.onosproject.net.OchSignal)6 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)3 PortNumber (org.onosproject.net.PortNumber)2