Merge "PortMapping for device 1.2.1 and 2.2"
authorGuillaume Lambert <guillaume.lambert@orange.com>
Thu, 21 Mar 2019 16:27:23 +0000 (16:27 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 21 Mar 2019 16:27:23 +0000 (16:27 +0000)
common/src/main/java/org/opendaylight/transportpce/common/mapping/MappingUtilsImpl.java
common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMapping.java
common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingImpl.java
common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java
common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion22.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/NetConfTopologyListener.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/service/NetworkModelService.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/service/NetworkModelServiceImpl.java

index b87971a1faddde0ce28928f1b957c01275feebdd..ca3e029782732e291c70cf7cbc59df9b13669cec 100644 (file)
@@ -49,11 +49,10 @@ public class MappingUtilsImpl implements MappingUtils {
                     case _121:
                         return StringConstants.OPENROADM_DEVICE_VERSION_1_2_1;
                     default:
-                        return StringConstants.OPENROADM_DEVICE_VERSION_1_2_1;
+                        LOG.warn("unknown openROADM device version");
                 }
             } else {
                 LOG.warn("Could not find mapping for nodeId {}", nodeId);
-                return StringConstants.OPENROADM_DEVICE_VERSION_1_2_1;
             }
         } catch (InterruptedException | ExecutionException ex) {
             LOG.error("Unable to read mapping for nodeId {}",nodeId, ex);
index a636105c4bda082b50ee2d617ee88dae1c682c5b..987c545aeb359c430d392421d325fe811ebcde8f 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.transportpce.common.mapping;
 
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev170228.network.Nodes;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev170228.network.nodes.Mapping;
 
 public interface PortMapping {
@@ -41,7 +42,7 @@ public interface PortMapping {
      *
      * @return true/false based on status of operation
      */
-    boolean createMappingData(String nodeId);
+    boolean createMappingData(String nodeId, String nodeVersion);
 
     /**
      * This method removes mapping data from the datastore after disconnecting
@@ -78,4 +79,17 @@ public interface PortMapping {
     Mapping getMapping(String nodeId, String logicalConnPoint);
 
     boolean updateMapping(String nodeId, Mapping mapping);
+
+    /**
+     * This method returns all Mapping informations already stored in the MD-SAL
+     * data store for a given openroadm device. Beyound the list of mappings, it
+     * gives access to general node information as its version or its node type,
+     * etc.
+     *
+     * @param nodeId
+     *            Unique Identifier for the node of interest.
+     *
+     * @return node data if success otherwise null.
+     */
+    Nodes getNode(String nodeId);
 }
index 2dac08d0543b6bd55510eb848c384bda408584b5..7374530d421f3602a23ee659ef14e27d6e8d6444 100644 (file)
@@ -48,16 +48,13 @@ public class PortMappingImpl implements PortMapping {
     }
 
     @Override
-    public boolean createMappingData(String nodeId) {
-
-        String openROADMversion = mappingUtils.getOpenRoadmVersion(nodeId);
-        if (openROADMversion.equals(OPENROADM_DEVICE_VERSION_1_2_1)) {
+    public boolean createMappingData(String nodeId, String nodeVersion) {
+        if (nodeVersion.equals(OPENROADM_DEVICE_VERSION_1_2_1)) {
             return portMappingVersion121.createMappingData(nodeId);
         }
-        else if (openROADMversion.equals(OPENROADM_DEVICE_VERSION_2_2)) {
+        else if (nodeVersion.equals(OPENROADM_DEVICE_VERSION_2_2)) {
             return portMappingVersion22.createMappingData(nodeId);
         }
-
         else {
             return false;
         }
@@ -127,5 +124,25 @@ public class PortMappingImpl implements PortMapping {
         }
     }
 
+    @Override
+    public Nodes getNode(String nodeId) {
+        InstanceIdentifier<Nodes> nodePortMappingIID = InstanceIdentifier.builder(Network.class).child(Nodes.class,
+            new NodesKey(nodeId)).build();
+        try (ReadOnlyTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
+            Optional<Nodes> nodePortMapObject = readTx.read(LogicalDatastoreType.CONFIGURATION, nodePortMappingIID)
+                .get().toJavaUtil();
+            if (nodePortMapObject.isPresent()) {
+                Nodes node = nodePortMapObject.get();
+                LOG.info("Found node {} in portmapping.", nodeId);
+                return node;
+            } else {
+                LOG.warn("Could not find node {} in portmapping.", nodeId);
+            }
+        } catch (InterruptedException | ExecutionException ex) {
+            LOG.error("Unable to get node {} in portmapping", nodeId);
+        }
+        return null;
+    }
+
 
 }
index 9a0c9b49c763bb9511392abaf5854e7f23d41aa3..742e2953a305aa0bdc2c9927d9750ef02aa7431b 100644 (file)
@@ -84,7 +84,7 @@ public class PortMappingVersion121 {
 
     public boolean createMappingData(String nodeId) {
 
-        LOG.info("Create Mapping Data for node {}", nodeId);
+        LOG.info("Create Mapping Data for node 1.2.1 {}", nodeId);
         List<Mapping> portMapList = new ArrayList<>();
         InstanceIdentifier<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
         Optional<Info> deviceInfoOptional = this.deviceTransactionManager.getDataFromDevice(nodeId,
index aa61ace7359ef3771351cce59ebfb6b56b8977d4..b1e66a3cf43e96797edff340b8f7bb13a729f5c2 100644 (file)
@@ -86,7 +86,7 @@ public class PortMappingVersion22 {
 
     public boolean createMappingData(String nodeId) {
 
-        LOG.info("Create Mapping Data for node {}", nodeId);
+        LOG.info("Create Mapping Data for node 2.2 {}", nodeId);
         List<Mapping> portMapList = new ArrayList<>();
         InstanceIdentifier<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
         Optional<Info> deviceInfoOptional = this.deviceTransactionManager
@@ -199,16 +199,16 @@ public class PortMappingVersion22 {
                 continue;
             }
             for (Ports port : cp.getPorts()) {
-                if (Port.PortQual.XpdrNetwork.equals(port.getPortQual())) {
+                if (Port.PortQual.XpdrNetwork.getName().equals(port.getPortQual().getName())) {
                     portMapList.add(createMappingObject(nodeId, port, circuitPackName,
                             "XPDR1-" + StringConstants.NETWORK_TOKEN + line));
                     line++;
-                } else if (Port.PortQual.XpdrClient.equals(port.getPortQual())) {
+                } else if (Port.PortQual.XpdrClient.getName().equals(port.getPortQual().getName())) {
                     portMapList.add(createMappingObject(nodeId, port, circuitPackName,
                             "XPDR1-" + StringConstants.CLIENT_TOKEN + client));
                     client++;
                 } else {
-                    LOG.warn("Not supported type of port! Port type: {}", port.getPortQual());
+                    LOG.warn("Not supported type of port! Port type: {}", port.getPortQual().getName());
                 }
             }
         }
@@ -236,7 +236,7 @@ public class PortMappingVersion22 {
             InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
                     .child(SharedRiskGroup.class, new SharedRiskGroupKey(srgCounter));
             Optional<SharedRiskGroup> ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
-                LogicalDatastoreType.CONFIGURATION, srgIID,
+                LogicalDatastoreType.OPERATIONAL, srgIID,
                 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
             if (ordmSrgObject.isPresent()) {
                 srgCps.addAll(ordmSrgObject.get().getCircuitPacks());
@@ -352,7 +352,7 @@ public class PortMappingVersion22 {
             InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
                     .child(Degree.class, new DegreeKey(degreeCounter));
             Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
-                LogicalDatastoreType.CONFIGURATION, deviceIID,
+                LogicalDatastoreType.OPERATIONAL, deviceIID,
                 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
             if (ordmDegreeObject.isPresent()) {
                 degrees.add(ordmDegreeObject.get());
@@ -425,7 +425,7 @@ public class PortMappingVersion22 {
         NodesBuilder nodesBldr = new NodesBuilder();
         nodesBldr.withKey(new NodesKey(deviceInfo.getNodeId().getValue())).setNodeId(deviceInfo.getNodeId().getValue());
         nodesBldr.setNodeType(NodeTypes.forValue(nodeType));
-        nodesBldr.setOpenroadmVersion(Nodes.OpenroadmVersion._121);
+        nodesBldr.setOpenroadmVersion(Nodes.OpenroadmVersion._22);
         if (portMapList != null) {
             nodesBldr.setMapping(portMapList);
         }
index 9772212e00775c6b836753ce8d8f4039b7e1deeb..a09a3be7e0178a594a5fa51cefaf487874be6de6 100644 (file)
@@ -8,10 +8,15 @@
 package org.opendaylight.transportpce.networkmodel;
 
 import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
 import javax.annotation.Nonnull;
+
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
@@ -39,6 +44,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.r
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.Streams;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -154,14 +160,17 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
                         NetconfNodeConnectionStatus.ConnectionStatus connectionStatus =
                                 netconfNode.getConnectionStatus();
                         try {
-                            long count = netconfNode.getAvailableCapabilities().getAvailableCapability().stream()
-                                .filter(cp -> cp.getCapability().contains(StringConstants.OPENROADM_DEVICE_MODEL_NAME))
-                                .count();
-                            if (count > 0) {
+                            List<AvailableCapability> deviceCapabilities = netconfNode.getAvailableCapabilities()
+                                .getAvailableCapability().stream().filter(cp -> cp.getCapability()
+                                .contains(StringConstants.OPENROADM_DEVICE_MODEL_NAME)).collect(Collectors.toList());
+                            if (!deviceCapabilities.isEmpty()) {
+                                Collections.sort(deviceCapabilities, (cp0, cp1) -> cp1.getCapability()
+                                    .compareTo(cp0.getCapability()));
                                 LOG.info("OpenROADM node detected: {} {}", nodeId, connectionStatus.name());
                                 switch (connectionStatus) {
                                     case Connected:
-                                        this.networkModelService.createOpenROADMnode(nodeId);
+                                        this.networkModelService.createOpenROADMnode(nodeId, deviceCapabilities.get(0)
+                                            .getCapability());
                                         onDeviceConnected(nodeId);
                                         break;
                                     case Connecting:
@@ -174,6 +183,7 @@ public class NetConfTopologyListener implements DataTreeChangeListener<Node> {
                                         break;
                                 }
                             }
+                            LOG.error("Not an openROADM node");
                         } catch (NullPointerException e) {
                             LOG.error("Cannot get available Capabilities");
                         }
index f5f2f2ca26cdf6780be1d6524451ca09adddf1d9..f3242a1e4cd0d7e662cdacfc3b4d53f47510b306 100644 (file)
@@ -19,8 +19,10 @@ public interface NetworkModelService {
      *
      * @param nodeId
      *   unique node ID of new OpenROADM node
+     * @param nodeVersion
+     *   OpenROADM node version
      */
-    void createOpenROADMnode(String nodeId);
+    void createOpenROADMnode(String nodeId, String nodeVersion);
 
     /**
      * Delete OpenROADM node mapping and topologies.
index 81079870e9022d32b1f09b69195f0d44c0880612..c38356c80b0fc2a4876a4908b85ecc7258aff5c8 100644 (file)
@@ -64,70 +64,74 @@ public class NetworkModelServiceImpl implements NetworkModelService {
     }
 
     @Override
-    public void createOpenROADMnode(String nodeId) {
+    public void createOpenROADMnode(String nodeId, String nodeVersion) {
         try {
             LOG.info("createOpenROADMNode: {} ", nodeId);
 
-            this.portMapping.createMappingData(nodeId);
-            this.linkDiscovery.readLLDP(new NodeId(nodeId));
+            boolean isPortMapping = this.portMapping.createMappingData(nodeId, nodeVersion);
+            if (isPortMapping && "1.2.1".equals(this.portMapping.getNode(nodeId).getOpenroadmVersion().getName())) {
+                this.linkDiscovery.readLLDP(new NodeId(nodeId));
 
-            Node clliNode = ClliNetwork.createNode(this.deviceTransactionManager, nodeId);
-            if (clliNode == null) {
-                LOG.error("Unable to create clli node! Node id: {}", nodeId);
-                return;
-            }
+                Node clliNode = ClliNetwork.createNode(this.deviceTransactionManager, nodeId);
+                if (clliNode == null) {
+                    LOG.error("Unable to create clli node! Node id: {}", nodeId);
+                    return;
+                }
 
-            Node openRoadmNode = OpenRoadmNetwork.createNode(nodeId, this.deviceTransactionManager);
-            if (openRoadmNode == null) {
-                LOG.error("Unable to create OpenRoadm node! Node id: {}", nodeId);
-                return;
-            }
+                Node openRoadmNode = OpenRoadmNetwork.createNode(nodeId, this.deviceTransactionManager);
+                if (openRoadmNode == null) {
+                    LOG.error("Unable to create OpenRoadm node! Node id: {}", nodeId);
+                    return;
+                }
 
-            TopologyShard topologyShard = this.openRoadmTopology.createTopologyShard(nodeId);
-            if (topologyShard == null) {
-                LOG.error("Unable to create topology shard for node {}!", nodeId);
-                return;
-            }
-            this.topologyShardMountedDevice.put(nodeId, topologyShard);
+                TopologyShard topologyShard = this.openRoadmTopology.createTopologyShard(nodeId);
+                if (topologyShard == null) {
+                    LOG.error("Unable to create topology shard for node {}!", nodeId);
+                    return;
+                }
+                this.topologyShardMountedDevice.put(nodeId, topologyShard);
 
-            WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
-            LOG.info("creating node in {}", NetworkUtils.CLLI_NETWORK_ID);
-            InstanceIdentifier<Node> iiClliNode = InstanceIdentifier
-                    .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.CLLI_NETWORK_ID)))
-                    .child(Node.class, clliNode.key())
-                    .build();
-            writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, iiClliNode, clliNode,
-                    CREATE_MISSING_PARENTS);
-            LOG.info("creating node in {}", NetworkUtils.UNDERLAY_NETWORK_ID);
-            InstanceIdentifier<Node> iiOpenRoadmNode = InstanceIdentifier
-                    .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID)))
-                    .child(Node.class, openRoadmNode.key())
-                    .build();
-            writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmNode, openRoadmNode,
-                    CREATE_MISSING_PARENTS);
-            for (Node openRoadmTopologyNode: topologyShard.getNodes()) {
-                LOG.info("creating node {} in {}", openRoadmTopologyNode.getNodeId().getValue(),
-                        NetworkUtils.OVERLAY_NETWORK_ID);
-                InstanceIdentifier<Node> iiOpenRoadmTopologyNode = InstanceIdentifier
-                        .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
-                        .child(Node.class, openRoadmTopologyNode.key())
+                WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
+                LOG.info("creating node in {}", NetworkUtils.CLLI_NETWORK_ID);
+                InstanceIdentifier<Node> iiClliNode = InstanceIdentifier
+                        .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.CLLI_NETWORK_ID)))
+                        .child(Node.class, clliNode.key())
                         .build();
-                writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyNode,
-                        openRoadmTopologyNode, CREATE_MISSING_PARENTS);
-            }
-            for (Link openRoadmTopologyLink: topologyShard.getLinks()) {
-                LOG.info("creating link {} in {}", openRoadmTopologyLink.getLinkId().getValue(),
-                        NetworkUtils.OVERLAY_NETWORK_ID);
-                InstanceIdentifier<Link> iiOpenRoadmTopologyLink = InstanceIdentifier
-                        .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
-                        .augmentation(Network1.class)
-                        .child(Link.class, openRoadmTopologyLink.key())
+                writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, iiClliNode, clliNode,
+                        CREATE_MISSING_PARENTS);
+                LOG.info("creating node in {}", NetworkUtils.UNDERLAY_NETWORK_ID);
+                InstanceIdentifier<Node> iiOpenRoadmNode = InstanceIdentifier
+                        .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID)))
+                        .child(Node.class, openRoadmNode.key())
                         .build();
-                writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyLink,
-                        openRoadmTopologyLink, CREATE_MISSING_PARENTS);
+                writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmNode, openRoadmNode,
+                        CREATE_MISSING_PARENTS);
+                for (Node openRoadmTopologyNode: topologyShard.getNodes()) {
+                    LOG.info("creating node {} in {}", openRoadmTopologyNode.getNodeId().getValue(),
+                            NetworkUtils.OVERLAY_NETWORK_ID);
+                    InstanceIdentifier<Node> iiOpenRoadmTopologyNode = InstanceIdentifier
+                            .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
+                            .child(Node.class, openRoadmTopologyNode.key())
+                            .build();
+                    writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyNode,
+                            openRoadmTopologyNode, CREATE_MISSING_PARENTS);
+                }
+                for (Link openRoadmTopologyLink: topologyShard.getLinks()) {
+                    LOG.info("creating link {} in {}", openRoadmTopologyLink.getLinkId().getValue(),
+                            NetworkUtils.OVERLAY_NETWORK_ID);
+                    InstanceIdentifier<Link> iiOpenRoadmTopologyLink = InstanceIdentifier
+                            .builder(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
+                            .augmentation(Network1.class)
+                            .child(Link.class, openRoadmTopologyLink.key())
+                            .build();
+                    writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyLink,
+                            openRoadmTopologyLink, CREATE_MISSING_PARENTS);
+                }
+                writeTransaction.submit().get();
+                LOG.info("all nodes and links created");
+            } else {
+                LOG.warn("openroadm-topology is not managed yet with openROADM device 2.2");
             }
-            writeTransaction.submit().get();
-            LOG.info("all nodes and links created");
         } catch (InterruptedException | ExecutionException e) {
             LOG.error("ERROR: ", e);
         }