Search in sources :

Example 6 with Builder

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

the class CassiniTerminalDeviceDiscoveryOld 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");
    log.info("Parsing Component {} type {} rate {}", logicalChannelIndex, description, rateClass);
    Map<String, String> annotations = new HashMap<>();
    annotations.put(OdtnDeviceDescriptionDiscovery.OC_LOGICAL_CHANNEL, logicalChannelIndex);
    annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, description);
    // Store all properties as port properties
    // e.g. xe1/1
    Pattern clientPattern = Pattern.compile("xe(\\d*)/1");
    // e.g. oe1
    Pattern linePattern = Pattern.compile("oe(\\d*)/(\\d*)");
    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();
    if (portSpeedMatch.find()) {
        Long speed = Long.parseLong(portSpeedMatch.group(1));
        builder.portSpeed(speed * 1000);
    }
    if (clientMatch.find()) {
        Long num = Long.parseLong(clientMatch.group(1));
        Long portNum = 100 + num;
        String connectionId = "connection:" + num.toString();
        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()) {
        Long num = (Long.parseLong(lineMatch.group(1)) - 1) * 2 + Long.parseLong(lineMatch.group(2));
        Long portNum = 200 + num;
        String connectionId = "connection:" + num.toString();
        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, // TODO Client signal to be discovered
        OduSignalType.ODU4, true, signalId, DefaultAnnotations.builder().putAll(annotations).build());
    } else {
        log.warn("Unexpected component description: {}", 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 7 with Builder

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

the class AdvaTerminalDeviceDiscovery 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");
    log.info("Parsing Component {} type {} speed {}", logicalChannelIndex, description, rateClass);
    Map<String, String> annotations = new HashMap<>();
    annotations.put(OdtnDeviceDescriptionDiscovery.OC_LOGICAL_CHANNEL, logicalChannelIndex);
    // Store all properties as port properties
    // e.g. xe1/1
    Pattern clientPattern = Pattern.compile("(\\d*)/(\\d*)/c(\\d)");
    Pattern linePattern = Pattern.compile("(\\d*)/(\\d*)/n(\\d)");
    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();
    if (portSpeedMatch.find()) {
        Long speed = Long.parseLong(portSpeedMatch.group(1));
        builder.portSpeed(speed * 1000);
    }
    if (clientMatch.find()) {
        Long num = Long.parseLong(clientMatch.group(1));
        Long portNum = 100 + num;
        String connectionId = "connection:" + num.toString();
        annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, description);
        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()) {
        Long num = (Long.parseLong(lineMatch.group(1)) - 1) * 2 + Long.parseLong(lineMatch.group(2));
        Long portNum = 200 + num;
        String connectionId = "connection:" + num.toString();
        description = description.substring(0, description.length() - 6);
        annotations.putIfAbsent(PORT_TYPE, OdtnPortType.LINE.value());
        annotations.putIfAbsent(ONOS_PORT_INDEX, portNum.toString());
        annotations.putIfAbsent(CONNECTION_ID, connectionId);
        annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, "optch " + description);
        OchSignal signalId = OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1);
        return OchPortHelper.ochPortDescription(PortNumber.portNumber(portNum), true, // TODO Client signal to be discovered
        OduSignalType.ODU4, true, signalId, DefaultAnnotations.builder().putAll(annotations).build());
    } else {
        log.warn("Unexpected component description: {}", 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 8 with Builder

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

the class ZteDeviceDiscoveryImpl method toPortDescriptionInternal.

private PortDescription toPortDescriptionInternal(HierarchicalConfiguration component) {
    Map<String, String> annotations = new HashMap<>();
    String name = component.getString("name");
    String type = component.getString("state/type");
    annotations.put(OdtnDeviceDescriptionDiscovery.OC_NAME, name);
    annotations.put(OdtnDeviceDescriptionDiscovery.OC_TYPE, type);
    annotations.putIfAbsent(AnnotationKeys.PORT_NAME, name);
    // PORT-1-4-C1
    String[] textStr = name.split("-");
    // use different value of portNumber on the same equipment
    String portComponentIndex = textStr[textStr.length - 1];
    int slotIndex = Integer.parseInt(textStr[2]);
    int slotPortIndex = Integer.parseInt(portComponentIndex.substring(1));
    int portNumber = slotIndex * 10 + slotPortIndex;
    annotations.putIfAbsent(ONOS_PORT_INDEX, portComponentIndex);
    annotations.putIfAbsent(CONNECTION_ID, "connection:" + Integer.parseInt(portComponentIndex.substring(1)));
    if (portComponentIndex.charAt(0) == 'L') {
        // line
        annotations.putIfAbsent(PORT_TYPE, OdtnPortType.LINE.value());
        OchSignal signalId = OchSignal.newDwdmSlot(ChannelSpacing.CHL_50GHZ, 1);
        return OchPortHelper.ochPortDescription(PortNumber.portNumber(portNumber + 100L), true, OduSignalType.ODUC2, true, signalId, DefaultAnnotations.builder().putAll(annotations).build());
    } else if (portComponentIndex.charAt(0) == 'C') {
        // client
        annotations.putIfAbsent(PORT_TYPE, OdtnPortType.CLIENT.value());
        Builder builder = DefaultPortDescription.builder();
        builder.withPortNumber(PortNumber.portNumber(portNumber)).isEnabled(true).portSpeed(100000L).type(Type.PACKET).annotations(DefaultAnnotations.builder().putAll(annotations).build());
        return builder.build();
    }
    return null;
}
Also used : HashMap(java.util.HashMap) Builder(org.onosproject.net.device.DefaultPortDescription.Builder) OchSignal(org.onosproject.net.OchSignal)

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