Add openconfig node in openroadm network layers 39/114939/5
authorGilles Thouenon <gilles.thouenon@orange.com>
Sat, 18 Jan 2025 10:08:07 +0000 (11:08 +0100)
committerGilles Thouenon <gilles.thouenon@orange.com>
Tue, 21 Jan 2025 11:25:33 +0000 (12:25 +0100)
- refactor NetworkModelServiceImpl to add and remove an openconfig node
  in openroadm network layers (clli, network, topology, otn)
- refactor switch case structure in TopologyUtils to update the
  operational and admin states with openconfig values
- add a new functional test suite to check this new feature

JIRA: TRNSPRTPCE-845
Change-Id: Ia06c02732a9de1bc243540f9a29cdc2755eddb76
Signed-off-by: Gilles Thouenon <gilles.thouenon@orange.com>
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/service/NetworkModelServiceImpl.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/util/TopologyUtils.java
tests/transportpce_tests/oc/test02_topology.py [new file with mode: 0644]

index 51389de0d691aa4809643daf2c45439484f8126d..07139b47ebf2073a7dbe75f144a6e3550ab7afe4 100644 (file)
@@ -20,7 +20,6 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.stream.Collectors;
-import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
@@ -46,9 +45,9 @@ import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkmo
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkutils.rev240923.OtnLinkType;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.or.network.augmentation.rev240923.DataModelEnum;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.or.network.augmentation.rev240923.LinkClassEnum;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev240315.OpenconfigNodeVersion;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev240315.OpenroadmNodeVersion;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev240315.mapping.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev240315.network.Nodes;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev240315.network.nodes.NodeInfo;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
@@ -152,58 +151,18 @@ public class NetworkModelServiceImpl implements NetworkModelService {
                 LOG.warn("Could not generate port mapping for {} skipping network model creation", nodeId);
                 return;
             }
-            NodeInfo nodeInfo = portMapping.getNode(nodeId).getNodeInfo();
+            Nodes mappingNode = portMapping.getNode(nodeId);
+            NodeInfo nodeInfo = mappingNode.getNodeInfo();
             // node creation in clli-network
-            Node clliNode = ClliNetwork.createNode(nodeId, nodeInfo);
-            DataObjectIdentifier<Node> iiClliNode = DataObjectIdentifier.builder(Networks.class)
-                .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.CLLI_NETWORK_ID)))
-                .child(Node.class, clliNode.key())
-                .build();
-            LOG.info("creating node in {}", NetworkUtils.CLLI_NETWORK_ID);
-            networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiClliNode, clliNode);
-
+            addNodeInClliNetwork(nodeId, nodeInfo);
             // node creation in openroadm-network
-            Node openroadmNetworkNode = OpenRoadmNetwork.createNode(nodeId, nodeInfo);
-            DataObjectIdentifier<Node> iiopenroadmNetworkNode = DataObjectIdentifier.builder(Networks.class)
-                .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID)))
-                .child(Node.class, openroadmNetworkNode.key())
-                .build();
-            LOG.info("creating node in {}", NetworkUtils.UNDERLAY_NETWORK_ID);
-            networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiopenroadmNetworkNode,
-                openroadmNetworkNode);
-
+            addNodeInOpenroadmNetwork(nodeId, nodeInfo);
             // nodes/links creation in openroadm-topology
-            TopologyShard topologyShard = OpenRoadmTopology.createTopologyShard(portMapping.getNode(nodeId),
-                                                                                firstMount);
-            if (topologyShard != null) {
-                this.topologyShardMountedDevice.put(nodeId, topologyShard);
-                for (Node openRoadmTopologyNode : topologyShard.getNodes()) {
-                    LOG.info("creating node {} in {}", openRoadmTopologyNode.getNodeId().getValue(),
-                        NetworkUtils.OVERLAY_NETWORK_ID);
-                    DataObjectIdentifier<Node> iiOpenRoadmTopologyNode = DataObjectIdentifier.builder(Networks.class)
-                        .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
-                        .child(Node.class, openRoadmTopologyNode.key())
-                        .build();
-                    networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyNode,
-                        openRoadmTopologyNode);
-                }
-                for (Link openRoadmTopologyLink : topologyShard.getLinks()) {
-                    LOG.info("creating link {} in {}", openRoadmTopologyLink.getLinkId().getValue(),
-                        NetworkUtils.OVERLAY_NETWORK_ID);
-                    DataObjectIdentifier<Link> iiOpenRoadmTopologyLink = DataObjectIdentifier.builder(Networks.class)
-                        .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
-                        .augmentation(Network1.class)
-                        .child(Link.class, openRoadmTopologyLink.key())
-                        .build();
-                    networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyLink,
-                        openRoadmTopologyLink);
-                }
-            } else {
-                LOG.error("Unable to create openroadm-topology shard for node {}!", nodeId);
-            }
+            addNodeInOpenroadmTopology(mappingNode, firstMount);
             // nodes/links creation in otn-topology
-            if (nodeInfo.getNodeType().getIntValue() == 2 && (nodeInfo.getOpenroadmVersion().getIntValue() != 1)) {
-                createOpenRoadmOtnNode(nodeId);
+            if (NodeTypes.Xpdr.equals(nodeInfo.getNodeType())
+                    && !OpenroadmNodeVersion._121.equals(nodeInfo.getOpenroadmVersion())) {
+                addNodeInOtnTopology(nodeId);
             }
             networkTransactionService.commit().get();
             // neighbour links through LLDP
@@ -222,6 +181,24 @@ public class NetworkModelServiceImpl implements NetworkModelService {
         if (!ocPortMapping.createMappingData(nodeId, openConfigVersion, ipAddress)) {
             LOG.error("could not generate portmapping {}", nodeId);
         }
+        Nodes mappingNode = portMapping.getNode(nodeId);
+        NodeInfo nodeInfo = portMapping.getNode(nodeId).getNodeInfo();
+        // node creation in clli-network
+        addNodeInClliNetwork(nodeId, nodeInfo);
+        // node creation in openroadm-network
+        addNodeInOpenroadmNetwork(nodeId, nodeInfo);
+        // nodes/links creation in openroadm-topology
+        addNodeInOpenroadmTopology(mappingNode, true);
+        // nodes/links creation in otn-topology
+        if (NodeTypes.Xpdr.equals(nodeInfo.getNodeType())) {
+            addNodeInOtnTopology(nodeId);
+        }
+
+        try {
+            networkTransactionService.commit().get();
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.error("Error adding openconfig node in openroadm network layers");
+        }
     }
 
     @Override
@@ -235,105 +212,65 @@ public class NetworkModelServiceImpl implements NetworkModelService {
          */
     }
 
-    /*
-     @see org.opendaylight.transportpce.networkmodel.service.NetworkModelService# deleteOpenROADMnode(java.lang.String)
+    /**
+     * This Method is used to delete OpenROADM node from openroadm network layers and portmapping datastores.
+     * @param nodeId
+     *     unique node ID of OpenConfig node.
+     *
+     * @return result of node deletion from network and portmapping datastore
      */
-
     @Override
     public boolean deleteOpenRoadmnode(String nodeId) {
+        if (!this.portMapping.isNodeExist(nodeId)) {
+            return false;
+        }
+        OpenroadmNodeVersion deviceVersion = this.portMapping.getNode(nodeId).getNodeInfo().getOpenroadmVersion();
+        LOG.info("deleteOpenROADMnode: {} version {}", nodeId, deviceVersion.getName());
+        removeNodeFromOpenroadmNetwork(nodeId);
+        removeNodeFromOpenroadmTopology(nodeId);
+        NodeTypes nodeType = this.portMapping.getNode(nodeId).getNodeInfo().getNodeType();
+        if (NodeTypes.Xpdr.equals(nodeType) && !OpenroadmNodeVersion._121.equals(deviceVersion)) {
+            removeNodeFromOtnTopology(nodeId);
+        }
         try {
-            if (!this.portMapping.isNodeExist(nodeId)) {
-                return false;
-            }
-            NodeKey nodeIdKey = new NodeKey(new NodeId(nodeId));
-
-            LOG.info("deleting node in {}", NetworkUtils.UNDERLAY_NETWORK_ID);
-            DataObjectIdentifier<Node> iiopenroadmNetworkNode = DataObjectIdentifier.builder(Networks.class)
-                .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID)))
-                .child(Node.class, nodeIdKey)
-                .build();
-            this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiopenroadmNetworkNode);
-
-            TopologyShard topologyShard = this.topologyShardMountedDevice.get(nodeId);
-            if (topologyShard != null) {
-                for (Node openRoadmTopologyNode : topologyShard.getNodes()) {
-                    LOG.info("deleting node {} in {}", openRoadmTopologyNode.getNodeId().getValue(),
-                        NetworkUtils.OVERLAY_NETWORK_ID);
-                    DataObjectIdentifier<Node> iiOpenRoadmTopologyNode = DataObjectIdentifier.builder(Networks.class)
-                        .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
-                        .child(Node.class, openRoadmTopologyNode.key())
-                        .build();
-                    this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyNode);
-                }
-                for (Link openRoadmTopologyLink : topologyShard.getLinks()) {
-                    LOG.info("deleting link {} in {}", openRoadmTopologyLink.getLinkId().getValue(),
-                        NetworkUtils.OVERLAY_NETWORK_ID);
-                    DataObjectIdentifier<Link> iiOpenRoadmTopologyLink = DataObjectIdentifier.builder(Networks.class)
-                        .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
-                        .augmentation(Network1.class)
-                        .child(Link.class, openRoadmTopologyLink.key())
-                        .build();
-                    this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyLink);
-                }
-            } else {
-                LOG.warn("TopologyShard for node '{}' is not present", nodeId);
-            }
-            @Nullable
-            OpenroadmNodeVersion deviceVersion = this.portMapping.getNode(nodeId).getNodeInfo().getOpenroadmVersion();
-            @Nullable
-            NodeTypes nodeType = this.portMapping.getNode(nodeId).getNodeInfo().getNodeType();
-            if (nodeType.getIntValue() == 2 && deviceVersion.getIntValue() != 1) {
-                TopologyShard otnTopologyShard = this.otnTopologyShardMountedDevice.get(nodeId);
-                if (otnTopologyShard != null) {
-                    LOG.info("suppression de otnTopologyShard = {}", otnTopologyShard.toString());
-                    for (Node otnTopologyNode : otnTopologyShard.getNodes()) {
-                        LOG.info("deleting node {} in {}", otnTopologyNode.getNodeId().getValue(),
-                            NetworkUtils.OTN_NETWORK_ID);
-                        DataObjectIdentifier<Node> iiotnTopologyNode = DataObjectIdentifier.builder(Networks.class)
-                            .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
-                            .child(Node.class, otnTopologyNode.key())
-                            .build();
-                        this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiotnTopologyNode);
-                    }
-                    for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
-                        LOG.info("deleting link {} in {}", otnTopologyLink.getLinkId().getValue(),
-                            NetworkUtils.OTN_NETWORK_ID);
-                        DataObjectIdentifier<Link> iiotnTopologyLink = DataObjectIdentifier.builder(Networks.class)
-                            .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
-                            .augmentation(Network1.class)
-                            .child(Link.class, otnTopologyLink.key())
-                            .build();
-                        this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiotnTopologyLink);
-                    }
-                }
-            }
-
-            LOG.info("deleteOpenROADMnode: {} version {}", nodeId, deviceVersion.getName());
-            this.portMapping.deletePortMappingNode(nodeId);
-
             this.networkTransactionService.commit().get(1, TimeUnit.SECONDS);
-            LOG.info("all nodes and links deleted ! ");
+            LOG.info("all nodes and links deleted in topologies! ");
         } catch (InterruptedException | ExecutionException | TimeoutException e) {
             LOG.error("Error when trying to delete node : {}", nodeId, e);
             return false;
         }
+        this.portMapping.deletePortMappingNode(nodeId);
         return true;
     }
 
     /**
-     * This Method is used to delete openconfig node in portmapping.
+     * This Method is used to delete openconfig node from openroadm network layers and portmapping datastores.
      * @param nodeId
      *     unique node ID of OpenConfig node.
      *
-     * @return result of node deletion from portmapping
+     * @return result of node deletion from network and portmapping datastore
      */
     @Override
     public boolean deleteOpenConfignode(String nodeId) {
         if (!this.portMapping.isNodeExist(nodeId)) {
             return false;
         }
-        OpenconfigNodeVersion deviceVersion = this.portMapping.getNode(nodeId).getNodeInfo().getOpenconfigVersion();
-        LOG.info("deleteOpenConfignode: {} version {}", nodeId, deviceVersion.getName());
+        NodeInfo nodeInfo = this.portMapping.getNode(nodeId).getNodeInfo();
+        LOG.info("deleteOpenConfignode: {} version {}", nodeId, nodeInfo.getOpenconfigVersion().getName());
+
+        removeNodeFromOpenroadmNetwork(nodeId);
+        removeNodeFromOpenroadmTopology(nodeId);
+        if (NodeTypes.Xpdr.equals(nodeInfo.getNodeType())) {
+            removeNodeFromOtnTopology(nodeId);
+        }
+        try {
+            this.networkTransactionService.commit().get(1, TimeUnit.SECONDS);
+            LOG.info("all nodes and links deleted in topologies! ");
+
+        } catch (InterruptedException | ExecutionException | TimeoutException e) {
+            LOG.error("Error when trying to delete node : {}", nodeId, e);
+            return false;
+        }
         this.portMapping.deletePortMappingNode(nodeId);
         return true;
     }
@@ -873,6 +810,149 @@ public class NetworkModelServiceImpl implements NetworkModelService {
         }
     }
 
+    private void addNodeInClliNetwork(String nodeId, NodeInfo nodeInfo) {
+        Node clliNode = ClliNetwork.createNode(nodeId, nodeInfo);
+        DataObjectIdentifier<Node> iiClliNode = DataObjectIdentifier.builder(Networks.class)
+            .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.CLLI_NETWORK_ID)))
+            .child(Node.class, clliNode.key())
+            .build();
+        LOG.info("creating node in {}", NetworkUtils.CLLI_NETWORK_ID);
+        networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiClliNode, clliNode);
+
+    }
+
+    private void addNodeInOpenroadmNetwork(String nodeId, NodeInfo nodeInfo) {
+        Node openroadmNetworkNode = OpenRoadmNetwork.createNode(nodeId, nodeInfo);
+        DataObjectIdentifier<Node> iiopenroadmNetworkNode = DataObjectIdentifier.builder(Networks.class)
+            .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID)))
+            .child(Node.class, openroadmNetworkNode.key())
+            .build();
+        LOG.info("creating node in {}", NetworkUtils.UNDERLAY_NETWORK_ID);
+        networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiopenroadmNetworkNode,
+            openroadmNetworkNode);
+    }
+
+    private void addNodeInOpenroadmTopology(Nodes mappingNode, boolean firstMount) {
+        // nodes/links creation in openroadm-topology
+        TopologyShard topologyShard = OpenRoadmTopology.createTopologyShard(mappingNode, firstMount);
+        if (topologyShard != null) {
+            this.topologyShardMountedDevice.put(mappingNode.getNodeId(), topologyShard);
+            for (Node openRoadmTopologyNode : topologyShard.getNodes()) {
+                LOG.info("creating node {} in {}", openRoadmTopologyNode.getNodeId().getValue(),
+                    NetworkUtils.OVERLAY_NETWORK_ID);
+                DataObjectIdentifier<Node> iiOpenRoadmTopologyNode = DataObjectIdentifier.builder(Networks.class)
+                    .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
+                    .child(Node.class, openRoadmTopologyNode.key())
+                    .build();
+                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyNode,
+                    openRoadmTopologyNode);
+            }
+            for (Link openRoadmTopologyLink : topologyShard.getLinks()) {
+                LOG.info("creating link {} in {}", openRoadmTopologyLink.getLinkId().getValue(),
+                    NetworkUtils.OVERLAY_NETWORK_ID);
+                DataObjectIdentifier<Link> iiOpenRoadmTopologyLink = DataObjectIdentifier.builder(Networks.class)
+                    .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
+                    .augmentation(Network1.class)
+                    .child(Link.class, openRoadmTopologyLink.key())
+                    .build();
+                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyLink,
+                    openRoadmTopologyLink);
+            }
+        } else {
+            LOG.error("Unable to create openroadm-topology shard for node {}!", mappingNode.getNodeId());
+        }
+    }
+
+    private void addNodeInOtnTopology(String nodeId) {
+        TopologyShard otnTopologyShard = OpenRoadmOtnTopology.createTopologyShard(portMapping.getNode(nodeId));
+        if (otnTopologyShard != null) {
+            this.otnTopologyShardMountedDevice.put(nodeId, otnTopologyShard);
+            for (Node otnTopologyNode : otnTopologyShard.getNodes()) {
+                LOG.info("creating otn node {} in {}", otnTopologyNode.getNodeId().getValue(),
+                    NetworkUtils.OTN_NETWORK_ID);
+                DataObjectIdentifier<Node> iiOtnTopologyNode = DataObjectIdentifier.builder(Networks.class)
+                    .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+                    .child(Node.class, otnTopologyNode.key())
+                    .build();
+                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyNode, otnTopologyNode);
+            }
+            for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
+                LOG.info("creating otn link {} in {}", otnTopologyLink.getLinkId().getValue(),
+                    NetworkUtils.OVERLAY_NETWORK_ID);
+                DataObjectIdentifier<Link> iiOtnTopologyLink = DataObjectIdentifier.builder(Networks.class)
+                    .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+                    .augmentation(Network1.class)
+                    .child(Link.class, otnTopologyLink.key())
+                    .build();
+                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
+            }
+        } else {
+            LOG.error("Unable to create OTN topology shard for node {}!", nodeId);
+        }
+    }
+
+    private void removeNodeFromOpenroadmNetwork(String nodeId) {
+        LOG.info("deleting node {} in {}", nodeId, NetworkUtils.UNDERLAY_NETWORK_ID);
+        DataObjectIdentifier<Node> iiopenroadmNetworkNode = DataObjectIdentifier.builder(Networks.class)
+            .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID)))
+            .child(Node.class, new NodeKey(new NodeId(nodeId)))
+            .build();
+        this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiopenroadmNetworkNode);
+    }
+
+    private void removeNodeFromOpenroadmTopology(String nodeId) {
+        TopologyShard topologyShard = this.topologyShardMountedDevice.get(nodeId);
+        if (topologyShard != null) {
+            for (Node openRoadmTopologyNode : topologyShard.getNodes()) {
+                LOG.info("deleting node {} in {}", openRoadmTopologyNode.getNodeId().getValue(),
+                    NetworkUtils.OVERLAY_NETWORK_ID);
+                DataObjectIdentifier<Node> iiOpenRoadmTopologyNode = DataObjectIdentifier.builder(Networks.class)
+                    .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
+                    .child(Node.class, openRoadmTopologyNode.key())
+                    .build();
+                this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyNode);
+            }
+            for (Link openRoadmTopologyLink : topologyShard.getLinks()) {
+                LOG.info("deleting link {} in {}", openRoadmTopologyLink.getLinkId().getValue(),
+                    NetworkUtils.OVERLAY_NETWORK_ID);
+                DataObjectIdentifier<Link> iiOpenRoadmTopologyLink = DataObjectIdentifier.builder(Networks.class)
+                    .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID)))
+                    .augmentation(Network1.class)
+                    .child(Link.class, openRoadmTopologyLink.key())
+                    .build();
+                this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiOpenRoadmTopologyLink);
+            }
+        } else {
+            LOG.warn("TopologyShard for node '{}' is not present", nodeId);
+        }
+    }
+
+    private void removeNodeFromOtnTopology(String nodeId) {
+        TopologyShard otnTopologyShard = this.otnTopologyShardMountedDevice.get(nodeId);
+        if (otnTopologyShard != null) {
+            LOG.info("suppression de otnTopologyShard = {}", otnTopologyShard.toString());
+            for (Node otnTopologyNode : otnTopologyShard.getNodes()) {
+                LOG.info("deleting node {} in {}", otnTopologyNode.getNodeId().getValue(),
+                    NetworkUtils.OTN_NETWORK_ID);
+                DataObjectIdentifier<Node> iiotnTopologyNode = DataObjectIdentifier.builder(Networks.class)
+                    .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+                    .child(Node.class, otnTopologyNode.key())
+                    .build();
+                this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiotnTopologyNode);
+            }
+            for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
+                LOG.info("deleting link {} in {}", otnTopologyLink.getLinkId().getValue(),
+                    NetworkUtils.OTN_NETWORK_ID);
+                DataObjectIdentifier<Link> iiotnTopologyLink = DataObjectIdentifier.builder(Networks.class)
+                    .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
+                    .augmentation(Network1.class)
+                    .child(Link.class, otnTopologyLink.key())
+                    .build();
+                this.networkTransactionService.delete(LogicalDatastoreType.CONFIGURATION, iiotnTopologyLink);
+            }
+        }
+    }
+
     private List<Link> getOtnLinks(List<LinkId> linkIds) {
         List<Link> links = new ArrayList<>();
         for (LinkId linkId : linkIds) {
@@ -1055,34 +1135,6 @@ public class NetworkModelServiceImpl implements NetworkModelService {
         return links;
     }
 
-    private void createOpenRoadmOtnNode(String nodeId) {
-        TopologyShard otnTopologyShard = OpenRoadmOtnTopology.createTopologyShard(portMapping.getNode(nodeId));
-        if (otnTopologyShard != null) {
-            this.otnTopologyShardMountedDevice.put(nodeId, otnTopologyShard);
-            for (Node otnTopologyNode : otnTopologyShard.getNodes()) {
-                LOG.info("creating otn node {} in {}", otnTopologyNode.getNodeId().getValue(),
-                    NetworkUtils.OTN_NETWORK_ID);
-                DataObjectIdentifier<Node> iiOtnTopologyNode = DataObjectIdentifier.builder(Networks.class)
-                    .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
-                    .child(Node.class, otnTopologyNode.key())
-                    .build();
-                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyNode, otnTopologyNode);
-            }
-            for (Link otnTopologyLink : otnTopologyShard.getLinks()) {
-                LOG.info("creating otn link {} in {}", otnTopologyLink.getLinkId().getValue(),
-                    NetworkUtils.OVERLAY_NETWORK_ID);
-                DataObjectIdentifier<Link> iiOtnTopologyLink = DataObjectIdentifier.builder(Networks.class)
-                    .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.OTN_NETWORK_ID)))
-                    .augmentation(Network1.class)
-                    .child(Link.class, otnTopologyLink.key())
-                    .build();
-                networkTransactionService.merge(LogicalDatastoreType.CONFIGURATION, iiOtnTopologyLink, otnTopologyLink);
-            }
-        } else {
-            LOG.error("Unable to create OTN topology shard for node {}!", nodeId);
-        }
-    }
-
     private NodeBuilder createTapiNodeBuilder(String supportingLayer, String nodeId) {
         SupportingNodeBuilder supNBd = new SupportingNodeBuilder()
             .setNetworkRef(new NetworkId(supportingLayer))
index a249603879c673ff50604e7bde64e8d52930fbae..719d4653ce51de2aa87626297d5b18208d98c0f6 100644 (file)
@@ -168,16 +168,12 @@ public final class TopologyUtils {
         if (adminState == null) {
             return null;
         }
-        switch (adminState) {
-            case "InService":
-                return AdminStates.InService;
-            case "OutOfService":
-                return AdminStates.OutOfService;
-            case "Maintenance":
-                return AdminStates.Maintenance;
-            default:
-                return null;
-        }
+        return switch (adminState) {
+            case "InService", "ENABLED" -> AdminStates.InService;
+            case "OutOfService", "DISABLED" -> AdminStates.OutOfService;
+            case "Maintenance" -> AdminStates.Maintenance;
+            default -> null;
+        };
     }
 
     /**
@@ -189,16 +185,12 @@ public final class TopologyUtils {
         if (operState == null) {
             return null;
         }
-        switch (operState) {
-            case "InService":
-                return State.InService;
-            case "OutOfService":
-                return State.OutOfService;
-            case "Degraded":
-                return State.Degraded;
-            default:
-                return null;
-        }
+        return switch (operState) {
+            case "InService", "ACTIVE" -> State.InService;
+            case "OutOfService", "INACTIVE" -> State.OutOfService;
+            case "Degraded" -> State.Degraded;
+            default -> null;
+        };
     }
 
     /**
diff --git a/tests/transportpce_tests/oc/test02_topology.py b/tests/transportpce_tests/oc/test02_topology.py
new file mode 100644 (file)
index 0000000..3394239
--- /dev/null
@@ -0,0 +1,205 @@
+#!/usr/bin/env python
+
+##############################################################################
+# Copyright (c) 2019 Orange, Inc. and others.  All rights reserved.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import unittest
+import time
+import requests
+# pylint: disable=wrong-import-order
+import sys
+sys.path.append('transportpce_tests/common/')
+# pylint: disable=wrong-import-position
+# pylint: disable=import-error
+import test_utils  # nopep8
+import test_utils_oc  # nopep8
+
+
+class TransportPCEtesting(unittest.TestCase):
+
+    processes = None
+    NODE_VERSION = 'oc'
+
+    @classmethod
+    def setUpClass(cls):
+        cls.processes = test_utils.start_tpce()
+        cls.processes = test_utils.start_sims([('oc-mpdr', cls.NODE_VERSION)])
+
+    @classmethod
+    def tearDownClass(cls):
+        # pylint: disable=not-an-iterable
+        for process in cls.processes:
+            test_utils.shutdown_process(process)
+        print("all processes killed")
+
+    def setUp(self):
+        time.sleep(2)
+
+    def test_01_meta_data_insertion(self):
+        response = test_utils_oc.metadata_input()
+        self.assertEqual(response.status_code, requests.codes.created,
+                         test_utils.CODE_SHOULD_BE_201)
+
+    def test_02_catlog_input_insertion(self):
+        response = test_utils_oc.catlog_input()
+        self.assertEqual(response.status_code, requests.codes.ok,
+                         test_utils.CODE_SHOULD_BE_200)
+
+    def test_03_connect_mpdr(self):
+        response = test_utils.mount_device("XPDR-OC",
+                                           ('oc-mpdr', self.NODE_VERSION))
+        self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201)
+        time.sleep(3)
+
+        response = test_utils.check_device_connection("XPDR-OC")
+        self.assertEqual(response['status_code'], requests.codes.ok)
+        self.assertEqual(response['connection-status'], 'connected')
+
+    def test_04_getClliNetwork(self):
+        response = test_utils.get_ietf_network_request('clli-network', 'config')
+        self.assertEqual(response['status_code'], requests.codes.ok)
+        self.assertEqual(response['network'][0]['node'][0]['node-id'], '1')
+        self.assertEqual(response['network'][0]['node'][0]['org-openroadm-clli-network:clli'], '1')
+
+    def test_05_getOpenRoadmNetwork(self):
+        response = test_utils.get_ietf_network_request('openroadm-network', 'config')
+        self.assertEqual(response['status_code'], requests.codes.ok)
+        self.assertEqual(response['network'][0]['node'][0]['node-id'], 'XPDR-OC')
+        self.assertEqual(response['network'][0]['node'][0]['supporting-node'][0]['network-ref'], 'clli-network')
+        self.assertEqual(response['network'][0]['node'][0]['supporting-node'][0]['node-ref'], '1')
+        self.assertEqual(response['network'][0]['node'][0]['org-openroadm-common-network:node-type'], 'XPONDER')
+        self.assertEqual(response['network'][0]['node'][0]['org-openroadm-network:model'], 'Chassis component')
+        self.assertEqual(response['network'][0]['node'][0]['org-openroadm-network:vendor'], 'vendor1')
+        self.assertEqual(response['network'][0]['node'][0]['org-openroadm-network:ip'], '127.0.0.1')
+
+    def test_06_getLinks_OpenroadmTopology(self):
+        response = test_utils.get_ietf_network_request('openroadm-topology', 'config')
+        self.assertEqual(response['status_code'], requests.codes.ok)
+        self.assertNotIn('ietf-network-topology:link', response['network'][0])
+
+    def test_07_getNodes_OpenRoadmTopology(self):
+        # pylint: disable=redundant-unittest-assert
+        response = test_utils.get_ietf_network_request('openroadm-topology', 'config')
+        self.assertEqual(response['status_code'], requests.codes.ok)
+        self.assertIn('node', response['network'][0])
+        self.assertEqual(len(response['network'][0]['node']), 1)
+        listNode = ['XPDR-OC-XPDR1']
+        for node in response['network'][0]['node']:
+            self.assertIn({'network-ref': 'openroadm-network', 'node-ref': 'XPDR-OC'}, node['supporting-node'])
+            self.assertIn({'network-ref': 'clli-network', 'node-ref': '1'}, node['supporting-node'])
+            nodeType = node['org-openroadm-common-network:node-type']
+            nodeId = node['node-id']
+            if nodeId not in listNode:
+                self.assertFalse(True)
+                continue
+            self.assertEqual(nodeType, 'XPONDER')
+            client = 0
+            network = 0
+            for tp in node['ietf-network-topology:termination-point']:
+                tpType = tp['org-openroadm-common-network:tp-type']
+                if tpType == 'XPONDER-CLIENT':
+                    client += 1
+                elif tpType == 'XPONDER-NETWORK':
+                    network += 1
+            self.assertTrue(client == 0)
+            self.assertTrue(network == 1)
+            listNode.remove(nodeId)
+        self.assertEqual(len(listNode), 0)
+
+    def test_08_getLinks_OtnTopology(self):
+        response = test_utils.get_ietf_network_request('otn-topology', 'config')
+        self.assertEqual(response['status_code'], requests.codes.ok)
+        self.assertNotIn('ietf-network-topology:link', response['network'][0])
+
+    def test_07_getNodes_OtnTopology(self):
+        # pylint: disable=redundant-unittest-assert
+        response = test_utils.get_ietf_network_request('otn-topology', 'config')
+        self.assertEqual(response['status_code'], requests.codes.ok)
+        self.assertEqual(len(response['network'][0]['node']), 1)
+        listNode = ['XPDR-OC-XPDR1']
+        CHECK_LIST = {
+            'XPDR-OC-XPDR1': {
+                'node-type': 'MUXPDR',
+                'xpdr-number': 1,
+                'network_nb': 1,
+                'nbl_nb': 4,
+                'tp-checklist': ['XPDR1-NETWORK1', 'XPDR1-CLIENT1'],
+                'tp-unchecklist': ['XPDR1-CLIENT2']
+            }
+        }
+        for node in response['network'][0]['node']:
+            nodeId = node['node-id']
+            self.assertEqual(node['org-openroadm-common-network:node-type'], CHECK_LIST[nodeId]['node-type'])
+            self.assertIn({'network-ref': 'openroadm-network', 'node-ref': 'XPDR-OC'},
+                          node['supporting-node'])
+            self.assertIn({'network-ref': 'openroadm-topology', 'node-ref': nodeId},
+                          node['supporting-node'])
+            self.assertIn({'network-ref': 'clli-network', 'node-ref': '1'},
+                          node['supporting-node'])
+            self.assertEqual(node['org-openroadm-otn-network-topology:xpdr-attributes']['xpdr-number'],
+                             CHECK_LIST[nodeId]['xpdr-number'])
+            client = 0
+            network = 0
+            for tp in node['ietf-network-topology:termination-point']:
+                tpType = tp['org-openroadm-common-network:tp-type']
+                tpId = tp['tp-id']
+                if tpType == 'XPONDER-CLIENT':
+                    client += 1
+                elif tpType == 'XPONDER-NETWORK':
+                    network += 1
+                    self.assertEqual((tp['org-openroadm-otn-network-topology:tp-supported-interfaces']
+                                      ['supported-interface-capability'][0]['if-cap-type']),
+                                     'org-openroadm-port-types:if-OTUCn-ODUCn')
+                    self.assertEqual((tp['supporting-termination-point'][0]['network-ref']), 'openroadm-topology')
+                    self.assertEqual((tp['supporting-termination-point'][0]['node-ref']), nodeId)
+                    self.assertEqual((tp['supporting-termination-point'][0]['tp-ref']), tpId)
+            self.assertTrue(client == 4)
+            self.assertTrue(network == CHECK_LIST[nodeId]['network_nb'])
+            self.assertEqual(
+                len(node['org-openroadm-otn-network-topology:switching-pools']
+                    ['odu-switching-pools'][0]['non-blocking-list']),
+                CHECK_LIST[nodeId]['nbl_nb'])
+            # pylint: disable=line-too-long
+            for nbl in node['org-openroadm-otn-network-topology:switching-pools']['odu-switching-pools'][0]['non-blocking-list']:
+                if nbl['nbl-number'] == 1:
+                    self.assertEqual(nbl['available-interconnect-bandwidth'], 10)
+                    self.assertEqual(nbl['interconnect-bandwidth-unit'], 1000000000)
+                    for tp in CHECK_LIST[nodeId]['tp-checklist']:
+                        self.assertIn(tp, nbl['tp-list'])
+                    for tp in CHECK_LIST[nodeId]['tp-unchecklist']:
+                        self.assertNotIn(tp, nbl['tp-list'])
+            listNode.remove(nodeId)
+        self.assertEqual(len(listNode), 0)
+
+    def test_08_disconnect_mpdr(self):
+        response = test_utils.unmount_device("XPDR-OC")
+        self.assertIn(response.status_code, (requests.codes.ok, requests.codes.no_content))
+
+    def test_09_getClliNetwork(self):
+        response = test_utils.get_ietf_network_request('clli-network', 'config')
+        self.assertEqual(response['status_code'], requests.codes.ok)
+        self.assertEqual(len(response['network'][0]['node']), 1)
+        self.assertEqual(response['network'][0]['node'][0]['org-openroadm-clli-network:clli'], '1')
+
+    def test_10_getOpenRoadmNetwork(self):
+        response = test_utils.get_ietf_network_request('openroadm-network', 'config')
+        self.assertEqual(response['status_code'], requests.codes.ok)
+        self.assertNotIn('node', response['network'][0])
+
+    def test_11_getNodes_OpenRoadmTopology(self):
+        response = test_utils.get_ietf_network_request('openroadm-topology', 'config')
+        self.assertNotIn('node', response['network'][0])
+
+    def test_12_getNodes_OtnTopology(self):
+        response = test_utils.get_ietf_network_request('otn-topology', 'config')
+        self.assertNotIn('node', response['network'][0])
+
+
+if __name__ == "__main__":
+    unittest.main(verbosity=2)