Search in sources :

Example 56 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 57 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 58 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)

Example 59 with PortDescription

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

the class GeneralDeviceProvider method createOrUpdateDevice.

private void createOrUpdateDevice(DeviceId deviceId, boolean available) {
    assertConfig(deviceId);
    if (available) {
        // Push port descriptions. If marking online, make sure to update
        // ports before other subsystems pick up the device  event.
        final List<PortDescription> ports = getPortDetails(deviceId);
        providerService.updatePorts(deviceId, ports);
    }
    DeviceDescription deviceDescription = getDeviceDescription(deviceId, available);
    DeviceDescription storeDescription = providerService.getDeviceDescription(deviceId);
    if (deviceService.getDevice(deviceId) != null && deviceService.isAvailable(deviceId) == available && storeDescription != null) {
        // FIXME SDFAB-650 rethink the APIs and abstractions around the DeviceStore.
        // Device registration is a two-step process for the GDP. Initially, the device is
        // registered with default avail. to false. Later, the checkup task will update the
        // description with the default avail to true in order to mark it available. Today,
        // there is only one API to mark online a device from the device provider which is
        // deviceConnected which assumes an update on the device description. The device provider
        // is the only one able to update the device description and we have to make sure that
        // the default avail. is flipped to true as it is used to mark as online the device when
        // it is created or updated. Otherwise, if an ONOS instance fails and restarts, when re-joining
        // the cluster, it will get the device marked as offline and will not be able to update
        // its status until it become the master. This process concurs with the markOnline done
        // by the background thread in the DeviceManager and its the reason why we cannot just check
        // the device availability but we need to compare also the desc. Checking here the equality,
        // as in general we may want to upgrade the device description at run time.
        DeviceDescription testDeviceDescription = DefaultDeviceDescription.copyReplacingAnnotation(deviceDescription, storeDescription.annotations());
        if (testDeviceDescription.equals(storeDescription)) {
            return;
        }
    }
    providerService.deviceConnected(deviceId, deviceDescription);
}
Also used : DeviceDescription(org.onosproject.net.device.DeviceDescription) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) PortDescription(org.onosproject.net.device.PortDescription)

Example 60 with PortDescription

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

the class GnmiDeviceStateSubscriber method handleOperStatusUpdate.

private void handleOperStatusUpdate(DeviceId deviceId, Update update, long timestamp) {
    Path path = update.getPath();
    // first element should be "interface"
    String interfaceName = path.getElem(1).getKeyOrDefault("name", null);
    if (interfaceName == null) {
        log.error("No interface present in gNMI update, abort");
        log.debug("gNMI update:\n{}", update);
        return;
    }
    List<Port> portsFromDevice = deviceService.getPorts(deviceId);
    portsFromDevice.forEach(port -> {
        if (!port.number().name().equals(interfaceName)) {
            return;
        }
        DefaultAnnotations portAnnotations = DefaultAnnotations.builder().putAll(port.annotations()).set(LAST_CHANGE, String.valueOf(timestamp)).build();
        // Port/Interface name is identical in OpenConfig model, but not in ONOS
        // This might cause some problem if we use one name to different port
        PortDescription portDescription = DefaultPortDescription.builder().portSpeed(port.portSpeed()).withPortNumber(port.number()).isEnabled(update.getVal().getStringVal().equals("UP")).type(port.type()).annotations(portAnnotations).build();
        providerService.portStatusChanged(deviceId, portDescription);
    });
}
Also used : Path(gnmi.Gnmi.Path) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Port(org.onosproject.net.Port) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription)

Aggregations

PortDescription (org.onosproject.net.device.PortDescription)81 DefaultPortDescription (org.onosproject.net.device.DefaultPortDescription)41 Test (org.junit.Test)25 DefaultAnnotations (org.onosproject.net.DefaultAnnotations)25 PortNumber (org.onosproject.net.PortNumber)24 DeviceId (org.onosproject.net.DeviceId)23 ArrayList (java.util.ArrayList)22 Port (org.onosproject.net.Port)22 DeviceEvent (org.onosproject.net.device.DeviceEvent)14 ProviderId (org.onosproject.net.provider.ProviderId)13 Device (org.onosproject.net.Device)12 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)11 DefaultPort (org.onosproject.net.DefaultPort)9 DeviceService (org.onosproject.net.device.DeviceService)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 OchPortHelper.ochPortDescription (org.onosproject.net.optical.device.OchPortHelper.ochPortDescription)6