Search in sources :

Example 51 with PortDescription

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

the class GossipDeviceStore method updatePortsInternal.

private List<DeviceEvent> updatePortsInternal(ProviderId providerId, DeviceId deviceId, Timestamped<List<PortDescription>> portDescriptions) {
    Device device = devices.get(deviceId);
    if (device == null) {
        log.debug("Device is no longer valid: {}", deviceId);
        return Collections.emptyList();
    }
    Map<ProviderId, DeviceDescriptions> descsMap = deviceDescs.get(deviceId);
    checkArgument(descsMap != null, DEVICE_NOT_FOUND, deviceId);
    List<DeviceEvent> events = new ArrayList<>();
    synchronized (descsMap) {
        if (isDeviceRemoved(deviceId, portDescriptions.timestamp())) {
            log.debug("Ignoring outdated events: {}", portDescriptions);
            return Collections.emptyList();
        }
        DeviceDescriptions descs = descsMap.get(providerId);
        // every provider must provide DeviceDescription.
        checkArgument(descs != null, "Device description for Device ID %s from Provider %s was not found", deviceId, providerId);
        Map<PortNumber, Port> ports = getPortMap(deviceId);
        final Timestamp newTimestamp = portDescriptions.timestamp();
        // Add new ports
        Set<PortNumber> processed = new HashSet<>();
        for (PortDescription portDescription : portDescriptions.value()) {
            final PortNumber number = portDescription.portNumber();
            processed.add(number);
            final Port oldPort = ports.get(number);
            final Port newPort;
            boolean isRemoved = portDescription.isRemoved();
            final Timestamped<PortDescription> existingPortDesc = descs.getPortDesc(number);
            if (existingPortDesc == null || newTimestamp.compareTo(existingPortDesc.timestamp()) >= 0) {
                // on new port or valid update
                // update description
                descs.putPortDesc(new Timestamped<>(portDescription, portDescriptions.timestamp()));
                newPort = composePort(device, number, descsMap);
            } else {
                // outdated event, ignored.
                continue;
            }
            if (isRemoved && oldPort != null) {
                events.add(removePort(deviceId, oldPort.number(), providerId, descsMap));
            } else if (!isRemoved) {
                events.add(oldPort == null ? createPort(device, newPort, ports) : updatePort(device, oldPort, newPort, ports));
            }
        }
        events.addAll(pruneOldPorts(device, ports, processed));
    }
    return FluentIterable.from(events).filter(notNull()).toList();
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) DeviceEvent(org.onosproject.net.device.DeviceEvent) DefaultDevice(org.onosproject.net.DefaultDevice) Device(org.onosproject.net.Device) Port(org.onosproject.net.Port) DefaultPort(org.onosproject.net.DefaultPort) ArrayList(java.util.ArrayList) PortDescription(org.onosproject.net.device.PortDescription) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp) PortNumber(org.onosproject.net.PortNumber) HashSet(java.util.HashSet)

Example 52 with PortDescription

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

the class InfineraOpenConfigDeviceDiscoveryTest method testToPortDescription.

@Test
public void testToPortDescription() throws ConfigurationException, IOException {
    // CHECKSTYLE:OFF
    String input = "<data>\n" + "  <interfaces xmlns=\"http://openconfig.net/yang/interfaces\">\n" + "    <interface>\n" + "      <name>CARRIERCTP.1-L1-1</name>\n" + "      <config>\n" + "        <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + "        <name>CARRIERCTP.1-L1-1</name>\n" + "        <description/>\n" + "        <enabled>true</enabled>\n" + "      </config>\n" + "    </interface>\n" + "    <interface>\n" + "      <name>CARRIERCTP.1-L1-2</name>\n" + "      <config>\n" + "        <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + "        <name>CARRIERCTP.1-L1-2</name>\n" + "        <description/>\n" + "        <enabled>true</enabled>\n" + "      </config>\n" + "    </interface>\n" + "    <interface>\n" + "      <name>CARRIERCTP.1-L1-3</name>\n" + "      <config>\n" + "        <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + "        <name>CARRIERCTP.1-L1-3</name>\n" + "        <description/>\n" + "        <enabled>true</enabled>\n" + "      </config>\n" + "    </interface>\n" + "    <interface>\n" + "      <name>CARRIERCTP.1-L1-4</name>\n" + "      <config>\n" + "        <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + "        <name>CARRIERCTP.1-L1-4</name>\n" + "        <description/>\n" + "        <enabled>true</enabled>\n" + "      </config>\n" + "    </interface>\n" + "    <interface>\n" + "      <name>CARRIERCTP.1-L1-5</name>\n" + "      <config>\n" + "        <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + "        <name>CARRIERCTP.1-L1-5</name>\n" + "        <description/>\n" + "        <enabled>true</enabled>\n" + "      </config>\n" + "    </interface>\n" + "    <interface>\n" + "      <name>CARRIERCTP.1-L1-6</name>\n" + "      <config>\n" + "        <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + "        <name>CARRIERCTP.1-L1-6</name>\n" + "        <description/>\n" + "        <enabled>true</enabled>\n" + "      </config>\n" + "    </interface>\n" + "    <interface>\n" + "      <name>GIGECLIENTCTP.1-A-2-T1</name>\n" + "      <config>\n" + "        <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + "        <name>GIGECLIENTCTP.1-A-2-T1</name>\n" + "        <description/>\n" + "        <enabled>true</enabled>\n" + "      </config>\n" + "    </interface>\n" + "    <interface>\n" + "      <name>GIGECLIENTCTP.1-A-2-T2</name>\n" + "      <config>\n" + "        <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + "        <name>GIGECLIENTCTP.1-A-2-T2</name>\n" + "        <description/>\n" + "        <enabled>true</enabled>\n" + "      </config>\n" + "    </interface>\n" + "    <interface>\n" + "      <name>GIGECLIENTCTP.1-L1-1-1</name>\n" + "      <config>\n" + "        <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + "        <name>GIGECLIENTCTP.1-L1-1-1</name>\n" + "        <description/>\n" + "        <enabled>true</enabled>\n" + "      </config>\n" + "    </interface>\n" + "    <interface>\n" + "      <name>GIGECLIENTCTP.1-L2-1-1</name>\n" + "      <config>\n" + "        <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + "        <name>GIGECLIENTCTP.1-L2-1-1</name>\n" + "        <description/>\n" + "        <enabled>true</enabled>\n" + "      </config>\n" + "    </interface>\n" + "    <interface>\n" + "      <name>NCTGIGE.1-NCT-1</name>\n" + "      <config>\n" + "        <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" + "        <name>NCTGIGE.1-NCT-1</name>\n" + "        <description/>\n" + "        <enabled>true</enabled>\n" + "      </config>\n" + "    </interface>\n" + "    <interface>\n" + "      <name>NCTGIGE.1-NCT-2</name>\n" + "      <config>\n" + "        <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:ethernetCsmacd</type>\n" + "        <name>NCTGIGE.1-NCT-2</name>\n" + "        <description/>\n" + "        <enabled>true</enabled>\n" + "      </config>\n" + "    </interface>\n" + "    <interface>\n" + "      <name>OCHCTP.1-L1-1</name>\n" + "      <config>\n" + "        <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + "        <name>OCHCTP.1-L1-1</name>\n" + "        <description/>\n" + "        <enabled>true</enabled>\n" + "      </config>\n" + "    </interface>\n" + "    <interface>\n" + "      <name>SCHCTP.1-L1-1</name>\n" + "      <config>\n" + "        <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + "        <name>SCHCTP.1-L1-1</name>\n" + "        <description/>\n" + "        <enabled>true</enabled>\n" + "      </config>\n" + "    </interface>\n" + "    <interface>\n" + "      <name>TRIBPTP.1-A-2-T1</name>\n" + "      <config>\n" + "        <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + "        <name>TRIBPTP.1-A-2-T1</name>\n" + "        <description/>\n" + "        <enabled>true</enabled>\n" + "      </config>\n" + "    </interface>\n" + "    <interface>\n" + "      <name>TRIBPTP.1-A-2-T2</name>\n" + "      <config>\n" + "        <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + "        <name>TRIBPTP.1-A-2-T2</name>\n" + "        <description/>\n" + "        <enabled>true</enabled>\n" + "      </config>\n" + "    </interface>\n" + "    <interface>\n" + "      <name>XTSCGPTP.1-L1</name>\n" + "      <config>\n" + "        <type xmlns:ianaift=\"urn:ietf:params:xml:ns:yang:iana-if-type\">ianaift:opticalTransport</type>\n" + "        <name>XTSCGPTP.1-L1</name>\n" + "        <description/>\n" + "        <enabled>true</enabled>\n" + "      </config>\n" + "    </interface>\n" + "  </interfaces>\n" + "</data>\n";
    // CHECKSTYLE:ON
    InfineraOpenConfigDeviceDiscovery sut = new InfineraOpenConfigDeviceDiscovery();
    XMLConfiguration cfg = new XMLConfiguration();
    cfg.load(CharSource.wrap(input).openStream());
    List<PortDescription> ports = sut.discoverPorts(cfg);
    assertThat(ports, hasSize(4));
    PortDescription portDescription;
    portDescription = ports.get(0);
    assertThat(portDescription.portNumber().toLong(), is(1L));
    assertThat(portDescription.portNumber().name(), is("GIGECLIENTCTP.1-A-2-T1"));
    assertThat(portDescription.annotations().value(OC_NAME), is("GIGECLIENTCTP.1-A-2-T1"));
    assertThat(portDescription.annotations().value(OC_TYPE), is("GIGECLIENTCTP.1-A-2-T1"));
    assertThat(portDescription.annotations().value(ODTN_PORT_TYPE), is(OdtnDeviceDescriptionDiscovery.OdtnPortType.CLIENT.value()));
    portDescription = ports.get(3);
    assertThat(portDescription.portNumber().toLong(), is(102L));
    assertThat(portDescription.portNumber().name(), is("GIGECLIENTCTP.1-L2-1-1"));
    assertThat(portDescription.annotations().value(OC_NAME), is("GIGECLIENTCTP.1-L2-1-1"));
    assertThat(portDescription.annotations().value(OC_TYPE), is("GIGECLIENTCTP.1-L2-1-1"));
    assertThat(portDescription.annotations().value(ODTN_PORT_TYPE), is(OdtnDeviceDescriptionDiscovery.OdtnPortType.LINE.value()));
}
Also used : XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) PortDescription(org.onosproject.net.device.PortDescription) Test(org.junit.Test)

Example 53 with PortDescription

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

the class OpenConfigDeviceDiscoveryTest method testToPortDescription.

@Test
public void testToPortDescription() throws ConfigurationException, IOException {
    // CHECKSTYLE:OFF
    String input = "<data>\n" + "<components  xmlns=\"http://openconfig.net/yang/platform\">\n" + "\n" + "  <component>\n" + "    <name>TPC_1_1_4_N2_200G</name>\n" + "    <config>\n" + "      <name>TPC_1_1_4_N2_200G</name>\n" + "    </config>\n" + "    <state>\n" + "      <name>TPC_1_1_4_N2_200G</name>\n" + "      <type  xmlns:oc-platform-types=\"http://openconfig.net/yang/platform-types\">oc-platform-types:LINECARD</type>\n" + "    </state>\n" + "  </component>\n" + "\n" + "  <component>\n" + "    <name>CLIPORT_1_1_4_1</name>\n" + "    <config>\n" + "      <name>CLIPORT_1_1_4_1</name>\n" + "    </config>\n" + "    <state>\n" + "      <name>CLIPORT_1_1_4_1</name>\n" + "      <type  xmlns:oc-platform-types=\"http://openconfig.net/yang/platform-types\">oc-platform-types:PORT</type>\n" + "    </state>\n" + "  </component>\n" + "\n" + "  <component>\n" + "    <name>LINEPORT_1_1_4</name>\n" + "    <config>\n" + "      <name>LINEPORT_1_1_4</name>\n" + "    </config>\n" + "    <state>\n" + "      <name>LINEPORT_1_1_4</name>\n" + "      <type  xmlns:oc-platform-types=\"http://openconfig.net/yang/platform-types\">oc-platform-types:PORT</type>\n" + "    </state>\n" + "  </component>\n" + "\n" + "  <component>\n" + "    <name>TRANSCEIVER_1_1_4_1</name>\n" + "    <config>\n" + "      <name>TRANSCEIVER_1_1_4_1</name>    \n" + "    </config>\n" + "    <state>\n" + "      <name>TRANSCEIVER_1_1_4_1</name>\n" + "      <type  xmlns:oc-platform-types=\"http://openconfig.net/yang/platform-types\">oc-platform-types:TRANSCEIVER</type>\n" + "    </state>\n" + "        <properties>\n" + "          <property>\n" + "            <name>onos-index</name>\n" + "            <config>\n" + "              <name>onos-index</name>\n" + "              <value>42</value>\n" + "            </config>\n" + "          </property>\n" + "        </properties>\n" + "    <transceiver  xmlns=\"http://openconfig.net/yang/platform/transceiver\">\n" + "      <config>\n" + "        <enabled>true</enabled>\n" + "        <form-factor-preconf  xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:QSFP28</form-factor-preconf>\n" + "        <ethernet-pmd-preconf  xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:ETH_100GBASE_LR4</ethernet-pmd-preconf>\n" + "      </config>\n" + "      <state>\n" + "        <enabled>true</enabled>\n" + "        <form-factor-preconf  xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:QSFP28</form-factor-preconf>\n" + "        <ethernet-pmd-preconf  xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:ETH_100GBASE_LR4</ethernet-pmd-preconf>\n" + "      </state>\n" + "    </transceiver>\n" + "  </component>\n" + "\n" + "  <component>\n" + "    <name>OPTCHANNEL_1_1_4</name>\n" + "    <config>\n" + "      <name>OPTCHANNEL_1_1_4</name>\n" + "    </config>\n" + "    <state>\n" + "      <name>OPTCHANNEL_1_1_4</name>\n" + "      <type  xmlns:oc-opt-types=\"http://openconfig.net/yang/transport-types\">oc-opt-types:OPTICAL_CHANNEL</type>\n" + "    </state>\n" + "    <optical-channel  xmlns=\"http://openconfig.net/yang/terminal-device\">\n" + "      <config>\n" + "        <frequency>191500000</frequency>\n" + "        <target-output-power>0.0</target-output-power>\n" + "      </config>\n" + "      <state>\n" + "        <frequency>191500000</frequency>\n" + "        <target-output-power>0.0</target-output-power>\n" + "      </state>\n" + "    </optical-channel>\n" + "  </component>\n" + "\n" + "</components>\n" + "</data>";
    // CHECKSTYLE:ON
    OpenConfigDeviceDiscovery sut = new OpenConfigDeviceDiscovery();
    XMLConfiguration cfg = new XMLConfiguration();
    cfg.load(CharSource.wrap(input).openStream());
    List<PortDescription> ports = sut.discoverPorts(cfg);
    assertThat(ports, hasSize(4));
    PortDescription portDescription = ports.get(2);
    assertThat(portDescription.portNumber().toLong(), is(42L));
    assertThat(portDescription.portNumber().name(), is("TRANSCEIVER_1_1_4_1"));
    assertThat(portDescription.annotations().value(OC_NAME), is("TRANSCEIVER_1_1_4_1"));
    assertThat(portDescription.annotations().value(OC_TYPE), is("oc-platform-types:TRANSCEIVER"));
}
Also used : XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) PortDescription(org.onosproject.net.device.PortDescription) Test(org.junit.Test)

Example 54 with PortDescription

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

the class OpenRoadmDeviceDescription method discoverDegreePorts.

/**
 * Parses degree (ROADM) port information.
 *
 * @param session the NETConf session to the OpenROADM device.
 * @param list  List of port descriptions to append to.
 * @param externalLinks Hierarchical configuration containing all the external
 *        links.
 * Port-id is obtained from degree-number and from the index contained
 * in the <connection-ports> leaf.
 * For OpenROADM Device model 2.2 both <degree-number> and <index> inside
 * <connection-ports> are key for the related lists, so composing them
 * assures identificator uniqueness.
 * Degree IDs are chosen as 10 * degree-number + index to avoid overlapping
 * with SRGs IDs.
 * The above formula allows making a two-digit number starting from two
 * one-digit numbers (actually, only port index needs to be single digit and
 * this assumption is assured by what stated in the model:
 *     OpenROADM Device model 2.2 (line 675):
 *        (connection-ports) description "Port associated with degree: One if bi-directional; two if uni-directional"
 * If my numbers are A and B, to have a number in the form AB (i.e. 11, 12, 21,
 * 31, 42, ...) I have to multiply A by 10.
 *
 * Note that both bidirectional and unidirectional ports IDs are taken from
 * the datastore.
 * Ex. DEG1 bidirectional port
 *          ONOS port ID: 11
 *     DEG3 unidirectional port
 *          ONOS port IDs: 31 and 32
 */
private List<PortDescription> discoverDegreePorts(NetconfSession session, List<PortDescription> list, List<HierarchicalConfiguration> externalLinks) {
    int degreeNumber = 0;
    String nodeId = getDevice().annotations().value(AnnotationKeys.OPENROADM_NODEID);
    List<HierarchicalConfiguration> degrees = getDegrees(session);
    for (HierarchicalConfiguration degree : degrees) {
        degreeNumber = degree.getInt("degree-number", 0);
        // From OpenROADM Device model 2.2: degree-number must be > 0
        if (degreeNumber == 0) {
            log.warn("[OPENROADM] Device {} <degree-number> MUST be > 0", did());
            continue;
        }
        List<HierarchicalConfiguration> connectionPorts = degree.configurationsAt("connection-ports");
        for (HierarchicalConfiguration cport : connectionPorts) {
            int portIndex = cport.getInt("index", 0);
            long portNum = degreeNumber * 10 + portIndex;
            PortNumber pNum = PortNumber.portNumber(portNum);
            String cpName = cport.getString("circuit-pack-name", "");
            String portName = cport.getString("port-name", "");
            PortNumber reversepNum = findDegreeReversePort(degreeNumber, portIndex, connectionPorts);
            HierarchicalConfiguration eLink = parseExternalLink(externalLinks, nodeId, cpName, portName);
            HierarchicalConfiguration circuitPack = getCircuitPackByName(session, cpName);
            List<HierarchicalConfiguration> cpPorts = circuitPack.configurationsAt("ports[port-name='" + portName + "']");
            if (cpPorts.size() > 1) {
                log.warn("[OPENROADM] {}: more than one port with the same name. Using first one", did());
            }
            HierarchicalConfiguration port = cpPorts.get(0);
            PortDescription pd = buildDegreePortDesc(nodeId, cpName, pNum, reversepNum, port, eLink);
            if (pd != null) {
                list.add(pd);
            }
        }
    }
    return list;
}
Also used : PortDescription(org.onosproject.net.device.PortDescription) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) PortNumber(org.onosproject.net.PortNumber)

Example 55 with PortDescription

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

the class OpenRoadmDeviceDescription method discoverSrgPorts.

/**
 * Parses SRG (ROADM) port information.
 *
 * @param session the NETConf session to the OpenROADM device.
 * @param list  List of port descriptions to append to.
 * @param externalLinks Hierarchical configuration containing all the external
 *        links.
 *
 * Port-id is obtained from srg-number and the number of the client
 * port contained in the <logical-connection-point> leaf.
 * OpenROADM Device Whitepaper for release 2.2, sect. 7.2.2.2.1:
 *     "For the ROADM SRG add/drop port, the logical connection point should
 *      be set to the format “SRG<n>-PP<m>”, where <n> is the SRG number
 *      and <m> is the add/drop port pair identifier. For example SRG1
 *      add/drop port #7 would have the logical connection point set to
 *      SRG1-PP7".
 * The method extract <m> following the sustring PP and use it in conjuncion
 * with the degree-number taken from the <degree> branch (If the datastore is
 * consistent this should be the same number in SRG<n>).
 * To avoid overlapping with IDs assigned to degrees, the srg-number is multiplied
 * by 1000. The to cover the uni-directional case (that needs two IDs, one per
 * direction) the port index is multiplied by 10.
 * Using 1000 as multiplier avoids overlapping with degree port IDs as long as
 * the number of degree in the ROADM is less than 100. Current optical
 * technologies don't allow ROADMs having such a high number of degrees.
 *
 * For unidirectional links the logical connection point is assumed to
 * have the form DEGn-PPi[-TX/-RX] and to the RX link is assigned an ID
 * following (+1) the TX one.
 * Ex. SRG1 second port bidirectional link (SRG1-PP2)
 *                      ONOS port ID: 1020
 *     SRG2 third port, unidirectional link (SRG2-PP3-TX, SRG2-PP3-RX)
 *                      ONOS port IDs: 2030 and 2031
 */
private List<PortDescription> discoverSrgPorts(NetconfSession session, List<PortDescription> list, List<HierarchicalConfiguration> externalLinks) {
    int srgNumber = 0;
    String nodeId = getDevice().annotations().value(AnnotationKeys.OPENROADM_NODEID);
    List<HierarchicalConfiguration> srgs = getSrgs(session);
    for (HierarchicalConfiguration s : srgs) {
        srgNumber = s.getInt("srg-number", 0);
        // From OpenROADM Device model 2.2: srg-number must be > 0
        if (srgNumber == 0) {
            log.warn("[OPENROADM] Device {} <srg-number> MUST be > 0", did());
            continue;
        }
        List<HierarchicalConfiguration> srgCircuitPacks = s.configurationsAt("circuit-packs");
        for (HierarchicalConfiguration scp : srgCircuitPacks) {
            String srgCpName = scp.getString("circuit-pack-name");
            HierarchicalConfiguration cpConf = getCircuitPackByName(session, srgCpName);
            List<HierarchicalConfiguration> ports = cpConf.configurationsAt("ports[port-qual='roadm-external']");
            for (HierarchicalConfiguration p : ports) {
                String portName = p.getString("port-name");
                String lcp = p.getString("logical-connection-point", "unknown");
                int ppIndex = lcp.indexOf("PP");
                if (ppIndex == -1) {
                    log.warn("[OPENROADM] {}: cannot find port index for circuit-pack {}", did(), srgCpName);
                } else {
                    long portNum, revPortNum;
                    String[] split = lcp.split("-");
                    // 1000 is chosen as base value to avoid overlapping
                    // with IDs for degree ports that have 10 as base value
                    long basePort = srgNumber * 1000 + Long.parseLong(split[1].replace("PP", "")) * 10;
                    if (split.length > 2) {
                        // Unidirectional port
                        portNum = basePort + (split[2].equals("RX") ? 1 : 0);
                        revPortNum = basePort + (split[2].equals("RX") ? 0 : 1);
                    } else {
                        // Bidirectional port
                        portNum = basePort;
                        revPortNum = 0;
                    }
                    PortNumber pNum = PortNumber.portNumber(portNum);
                    PortNumber reversepNum = PortNumber.portNumber(revPortNum);
                    HierarchicalConfiguration eLink = parseExternalLink(externalLinks, nodeId, srgCpName, portName);
                    PortDescription pd = buildSrgPortDesc(nodeId, srgCpName, pNum, reversepNum, p, eLink);
                    if (pd != null) {
                        list.add(pd);
                    }
                }
            }
        }
    }
    return list;
}
Also used : PortDescription(org.onosproject.net.device.PortDescription) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) PortNumber(org.onosproject.net.PortNumber)

Aggregations

PortDescription (org.onosproject.net.device.PortDescription)82 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)42 Test (org.junit.Test)25 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)25 PortNumber (org.onosproject.net.PortNumber)25 DeviceId (org.onosproject.net.DeviceId)24 Port (org.onosproject.net.Port)23 ArrayList (java.util.ArrayList)22 DeviceEvent (org.onosproject.net.device.DeviceEvent)15 ProviderId (org.onosproject.net.provider.ProviderId)14 Device (org.onosproject.net.Device)13 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)11 DeviceService (org.onosproject.net.device.DeviceService)10 DefaultPort (org.onosproject.net.DefaultPort)9 NetconfSession (org.onosproject.netconf.NetconfSession)8 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 OduCltPortHelper.oduCltPortDescription (org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription)7 OmsPortHelper.omsPortDescription (org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription)7 ConnectPoint (org.onosproject.net.ConnectPoint)6