Bug corrections in topo and portmapping modules
[transportpce.git] / networkmodel / src / main / java / org / opendaylight / transportpce / networkmodel / R2RLinkDiscovery.java
index 5bc386548628d06ec8e692e8b347ffb106ee351b..2dd9da35332b8c01cc4345feab1d8d5403d938e3 100644 (file)
@@ -50,9 +50,8 @@ public class R2RLinkDiscovery {
     private final OpenRoadmTopology openRoadmTopology;
     private final OpenRoadmInterfaces openRoadmInterfaces;
 
-    public R2RLinkDiscovery(final DataBroker dataBroker,
-            DeviceTransactionManager deviceTransactionManager, OpenRoadmTopology openRoadmTopology,
-            OpenRoadmInterfaces openRoadmInterfaces) {
+    public R2RLinkDiscovery(final DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
+            OpenRoadmTopology openRoadmTopology, OpenRoadmInterfaces openRoadmInterfaces) {
         this.dataBroker = dataBroker;
         this.deviceTransactionManager = deviceTransactionManager;
         this.openRoadmTopology = openRoadmTopology;
@@ -60,11 +59,11 @@ public class R2RLinkDiscovery {
     }
 
     public boolean readLLDP(NodeId nodeId) {
-        InstanceIdentifier<Protocols> protocolsIID =
-                InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class);
-        Optional<Protocols> protocolObject =
-                this.deviceTransactionManager.getDataFromDevice(nodeId.getValue(), LogicalDatastoreType.OPERATIONAL,
-                    protocolsIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        InstanceIdentifier<Protocols> protocolsIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+                .child(Protocols.class);
+        Optional<Protocols> protocolObject = this.deviceTransactionManager.getDataFromDevice(nodeId.getValue(),
+                LogicalDatastoreType.OPERATIONAL, protocolsIID, Timeouts.DEVICE_READ_TIMEOUT,
+                Timeouts.DEVICE_READ_TIMEOUT_UNIT);
         if (!protocolObject.isPresent() || (protocolObject.get().getAugmentation(Protocols1.class) == null)) {
             LOG.warn("LLDP subtree is missing : isolated openroadm device");
             return false;
@@ -73,18 +72,18 @@ public class R2RLinkDiscovery {
         LOG.info("LLDP subtree is present. Device has {} neighbours", nbrList.getIfName().size());
         for (IfName ifName : nbrList.getIfName()) {
             if (ifName.getRemoteSysName() == null) {
-                LOG.error("LLDP subtree is empty in the device for nodeId: {}",
-                        nodeId.getValue());
+                LOG.error("LLDP subtree is empty in the device for nodeId: {}", nodeId.getValue());
                 return false;
             }
             Optional<MountPoint> mps = this.deviceTransactionManager.getDeviceMountPoint(ifName.getRemoteSysName());
             if (!mps.isPresent()) {
                 LOG.warn("Neighbouring nodeId: {} is not mounted yet", ifName.getRemoteSysName());
-                return false;
+                // The controller raises a warning rather than an error because the first node to
+                // mount cannot see its neighbors yet. The link will be detected when processing
+                // the neighbor node.
             } else {
-                if (!createR2RLink(nodeId, ifName.getIfName(), ifName.getRemoteSysName(),
-                        ifName.getRemotePortId())) {
-                    LOG.warn("Link Creation failed between {} and {} nodes.", nodeId, ifName.getRemoteSysName());
+                if (!createR2RLink(nodeId, ifName.getIfName(), ifName.getRemoteSysName(), ifName.getRemotePortId())) {
+                    LOG.error("Link Creation failed between {} and {} nodes.", nodeId, ifName.getRemoteSysName());
                     return false;
                 }
             }
@@ -93,11 +92,11 @@ public class R2RLinkDiscovery {
     }
 
     public Direction getDegreeDirection(Integer degreeCounter, NodeId nodeId) {
-        InstanceIdentifier<Degree> deviceIID =
-                InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Degree.class, new DegreeKey(degreeCounter));
-        Optional<Degree> degreeObject =
-                this.deviceTransactionManager.getDataFromDevice(nodeId.getValue(), LogicalDatastoreType.OPERATIONAL,
-                    deviceIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Degree.class,
+                new DegreeKey(degreeCounter));
+        Optional<Degree> degreeObject = this.deviceTransactionManager.getDataFromDevice(nodeId.getValue(),
+                LogicalDatastoreType.OPERATIONAL, deviceIID, Timeouts.DEVICE_READ_TIMEOUT,
+                Timeouts.DEVICE_READ_TIMEOUT_UNIT);
         if (degreeObject.isPresent()) {
             Integer connectionPortCount = degreeObject.get().getConnectionPorts().size();
             if (connectionPortCount == 1) {
@@ -107,27 +106,28 @@ public class R2RLinkDiscovery {
             } else {
                 return Direction.NotApplicable;
             }
-        }  else {
-            LOG.error("Couldnt retrieve Degree object for nodeId: {} and DegreeNumbner: {}",
-                    nodeId.getValue(),degreeCounter);
+        } else {
+            LOG.error("Couldnt retrieve Degree object for nodeId: {} and DegreeNumbner: {}", nodeId.getValue(),
+                    degreeCounter);
             return Direction.NotApplicable;
         }
     }
 
     public boolean createR2RLink(NodeId nodeId, String interfaceName, String remoteSystemName,
-                                 String remoteInterfaceName) {
+            String remoteInterfaceName) {
         String srcTpTx = null;
         String srcTpRx = null;
         String destTpTx = null;
         String destTpRx = null;
-        //Find which degree is associated with ethernet interface
-        //portmapping.getDegFromCP(nodeId,interfaceName);
+        // Find which degree is associated with ethernet interface
+        // portmapping.getDegFromCP(nodeId,interfaceName);
         Integer srcDegId = getDegFromCP(nodeId, interfaceName);
         if (srcDegId == null) {
             LOG.error("Couldnt find degree connected to Ethernet interface for nodeId: {}", nodeId);
             return false;
         }
-        // Check whether degree is Unidirectional or Bidirectional by counting number of
+        // Check whether degree is Unidirectional or Bidirectional by counting
+        // number of
         // circuit-packs under degree subtree
         Direction sourceDirection = getDegreeDirection(srcDegId, nodeId);
         if (Direction.NotApplicable == sourceDirection) {
@@ -143,12 +143,13 @@ public class R2RLinkDiscovery {
         // Find degree for which Ethernet interface is created on other end
         NodeId destNodeId = new NodeId(remoteSystemName);
         Integer destDegId = getDegFromCP(destNodeId, remoteInterfaceName);
-        //portmapping.getDegFromCP(nodeId,interfaceName);
+        // portmapping.getDegFromCP(nodeId,interfaceName);
         if (destDegId == null) {
             LOG.error("Couldnt find degree connected to Ethernet interface for nodeId: {}", nodeId);
             return false;
         }
-        // Check whether degree is Unidirectional or Bidirectional by counting number of
+        // Check whether degree is Unidirectional or Bidirectional by counting
+        // number of
         // circuit-packs under degree subtree
         Direction destinationDirection = getDegreeDirection(destDegId, destNodeId);
         if (Direction.NotApplicable == destinationDirection) {
@@ -161,36 +162,32 @@ public class R2RLinkDiscovery {
             destTpTx = "DEG" + destDegId + "-TTP-TX";
             destTpRx = "DEG" + destDegId + "-TTP-RX";
         }
-        //A->Z
+        // A->Z
         LOG.debug(
             "Found a neighbor SrcNodeId: {} , SrcDegId: {} , SrcTPId: {}, DestNodeId:{} , DestDegId: {}, DestTPId: {}",
-            nodeId.getValue(), srcDegId, srcTpTx, destNodeId, destDegId, destTpRx);
+                nodeId.getValue(), srcDegId, srcTpTx, destNodeId, destDegId, destTpRx);
         InitRoadmNodesInputBuilder r2rlinkBuilderAToZ = new InitRoadmNodesInputBuilder();
-        r2rlinkBuilderAToZ.setRdmANode(nodeId.getValue())
-                .setDegANum(srcDegId.shortValue()).setTerminationPointA(srcTpTx)
-                .setRdmZNode(destNodeId.getValue())
-                .setDegZNum(destDegId.shortValue()).setTerminationPointZ(destTpRx);
-        if (!OrdLink.createRdm2RdmLinks(r2rlinkBuilderAToZ.build(),openRoadmTopology,
-                dataBroker)) {
-            LOG.error("OMS Link creation failed between node: {} and nodeId: {} in A->Z direction",
-                    nodeId.getValue(),destNodeId.getValue());
+        r2rlinkBuilderAToZ.setRdmANode(nodeId.getValue()).setDegANum(srcDegId.shortValue())
+                .setTerminationPointA(srcTpTx).setRdmZNode(destNodeId.getValue()).setDegZNum(destDegId.shortValue())
+                .setTerminationPointZ(destTpRx);
+        if (!OrdLink.createRdm2RdmLinks(r2rlinkBuilderAToZ.build(), openRoadmTopology, dataBroker)) {
+            LOG.error("OMS Link creation failed between node: {} and nodeId: {} in A->Z direction", nodeId.getValue(),
+                    destNodeId.getValue());
             return false;
         }
-        //Z->A
+        // Z->A
         LOG.debug(
                 "Found a neighbor SrcNodeId: {} , SrcDegId: {}"
                         + ", SrcTPId: {}, DestNodeId:{} , DestDegId: {}, DestTPId: {}",
                 destNodeId, destDegId, destTpTx, nodeId.getValue(), srcDegId, srcTpRx);
 
         InitRoadmNodesInputBuilder r2rlinkBuilderZToA = new InitRoadmNodesInputBuilder();
-        r2rlinkBuilderZToA.setRdmANode(destNodeId.getValue())
-                .setDegANum(destDegId.shortValue()).setTerminationPointA(destTpTx)
-                .setRdmZNode(nodeId.getValue())
-                .setDegZNum(srcDegId.shortValue()).setTerminationPointZ(srcTpRx);
-        if (!OrdLink.createRdm2RdmLinks(r2rlinkBuilderZToA.build(),openRoadmTopology,
-                dataBroker)) {
+        r2rlinkBuilderZToA.setRdmANode(destNodeId.getValue()).setDegANum(destDegId.shortValue())
+                .setTerminationPointA(destTpTx).setRdmZNode(nodeId.getValue()).setDegZNum(srcDegId.shortValue())
+                .setTerminationPointZ(srcTpRx);
+        if (!OrdLink.createRdm2RdmLinks(r2rlinkBuilderZToA.build(), openRoadmTopology, dataBroker)) {
             LOG.error("OMS Link creation failed between node: {} and nodeId: {} in Z->A direction",
-                    destNodeId.getValue(),nodeId.getValue());
+                    destNodeId.getValue(), nodeId.getValue());
             return false;
         }
         return true;
@@ -202,8 +199,8 @@ public class R2RLinkDiscovery {
         String srcTpRx = null;
         String destTpTx = null;
         String destTpRx = null;
-        //Find which degree is associated with ethernet interface
-        //portmapping.getDegFromCP(nodeId,interfaceName);
+        // Find which degree is associated with ethernet interface
+        // portmapping.getDegFromCP(nodeId,interfaceName);
         Integer srcDegId = getDegFromCP(nodeId, interfaceName);
         if (srcDegId == null) {
             LOG.error("Couldnt find degree connected to Ethernet interface for nodeId: {}", nodeId);
@@ -224,7 +221,7 @@ public class R2RLinkDiscovery {
         }
         // Find degree for which Ethernet interface is created on other end
         NodeId destNodeId = new NodeId(remoteSystemName);
-        //portmapping.getDegFromCP(nodeId,interfaceName);
+        // portmapping.getDegFromCP(nodeId,interfaceName);
         Integer destDegId = getDegFromCP(destNodeId, remoteInterfaceName);
         if (destDegId == null) {
             LOG.error("Couldnt find degree connected to Ethernet interface for nodeId: {}", nodeId);
@@ -244,18 +241,17 @@ public class R2RLinkDiscovery {
             destTpRx = "DEG" + destDegId + "-TTP-RX";
         }
         return this.openRoadmTopology.deleteLink(nodeId.getValue(), destNodeId.getValue(), srcTpTx, destTpRx)
-                    && this.openRoadmTopology.deleteLink(destNodeId.getValue(), nodeId.getValue(), destTpTx, srcTpRx);
+                && this.openRoadmTopology.deleteLink(destNodeId.getValue(), nodeId.getValue(), destTpTx, srcTpRx);
     }
 
     private CpToDegree getCPtoDegreeMapping(NodeId nodeId, String circuitPackName) {
-        InstanceIdentifier<CpToDegree> cptoDegMappingIID =
-                InstanceIdentifier.builder(Network.class).child(Nodes.class,
-                        new NodesKey(nodeId.getValue()))
-                        .child(CpToDegree.class, new CpToDegreeKey(circuitPackName)).build();
+        InstanceIdentifier<CpToDegree> cptoDegMappingIID = InstanceIdentifier.builder(Network.class)
+                .child(Nodes.class, new NodesKey(nodeId.getValue()))
+                .child(CpToDegree.class, new CpToDegreeKey(circuitPackName)).build();
         LOG.debug("Input parameters are {},{}", nodeId.getValue(), circuitPackName);
         try (ReadOnlyTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
-            Optional<CpToDegree> cptpDegObject =
-                    readTx.read(LogicalDatastoreType.CONFIGURATION, cptoDegMappingIID).get().toJavaUtil();
+            Optional<CpToDegree> cptpDegObject = readTx.read(LogicalDatastoreType.CONFIGURATION, cptoDegMappingIID)
+                    .get().toJavaUtil();
             if (cptpDegObject.isPresent()) {
                 CpToDegree cpToDeg = cptpDegObject.get();
                 LOG.debug("Found mapping for the Circuit Pack {}. Degree: {}", circuitPackName, cpToDeg);
@@ -273,9 +269,9 @@ public class R2RLinkDiscovery {
     private Integer getDegFromParentCP(NodeId nodeId, String interfaceName, String supportingCircuitPack) {
         InstanceIdentifier<CircuitPacks> circuitPackIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
                 .child(CircuitPacks.class, new CircuitPacksKey(supportingCircuitPack));
-        Optional<CircuitPacks> circuitPackObject =
-                this.deviceTransactionManager.getDataFromDevice(nodeId.getValue(), LogicalDatastoreType.OPERATIONAL,
-                        circuitPackIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(nodeId.getValue(),
+                LogicalDatastoreType.OPERATIONAL, circuitPackIID, Timeouts.DEVICE_READ_TIMEOUT,
+                Timeouts.DEVICE_READ_TIMEOUT_UNIT);
         if (!circuitPackObject.isPresent()
                 || (circuitPackObject.get().getParentCircuitPack().getCircuitPackName() == null)) {
             LOG.warn("Parent circuitpack not found for NodeId: {} and Interface: {}", nodeId, interfaceName);
@@ -302,11 +298,12 @@ public class R2RLinkDiscovery {
                 return null;
             }
             String supportingCircuitPack = interfaceOpt.get().getSupportingCircuitPackName();
-            LOG.debug("Supporting circuitpack name is :{}",
-                    interfaceOpt.get().getSupportingCircuitPackName());
+            LOG.debug("Supporting circuitpack name is :{}", interfaceOpt.get().getSupportingCircuitPackName());
             CpToDegree cpToDegree = getCPtoDegreeMapping(nodeId, supportingCircuitPack);
-            // Currently devices have different ways to represent connection to Ethernet port and degree port
-            // If Circuit pack is not present under degree tree then read parent CP of given CP(Circuit pack)
+            // Currently devices have different ways to represent connection to Ethernet port
+            // and degree port.
+            // If Circuit pack is not present under degree tree then read parent CP of given
+            // CP (Circuit pack).
             if (cpToDegree != null) {
                 return cpToDegree.getDegreeNumber().intValue();
             } else {