Bugs correction in Portmapping 91/74091/1
authorGilles Thouenon <gilles.thouenon@orange.com>
Mon, 16 Jul 2018 21:09:59 +0000 (23:09 +0200)
committerguillaume.lambert <guillaume.lambert@orange.com>
Mon, 16 Jul 2018 21:18:51 +0000 (23:18 +0200)
- Modify iteration for getting circuitpacks with srg number.
- Modify OpenRoadmInterfaces constants.
- Modify Portmapping class to add deleteMapping data function. This
function was already in Renderer maven project on master branch, but
was deleted in common maven project on change ATT-Sandbox 'Renderer and
OLM update' https://git.opendaylight.org/gerrit/#/c/66651/.

Co-authored-by: Christophe Betoule <christophe.betoule@orange.com>
Co-Authored-By: Dhruv Bhardwaj <db929a@att.com>
Co-Authored-By: Shweta Vachhani <sv111y@att.com>
Change-Id: If5833b306d00a6c140da665d2e8c69a2a7c69ac4
Signed-off-by: Martial COULIBALY <martial.coulibaly@gfi.fr>
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/openroadminterfaces/OpenRoadmInterfacesImpl.java

index 5ddbe0109378d5d5954c5b56cb6e2d9bc44fcc14..ccbd13547253c9036e1c99fdd8fde85fbd653eb8 100644 (file)
@@ -40,6 +40,12 @@ public interface PortMapping {
      */
     boolean createMappingData(String nodeId);
 
+    /**
+     * This method removes mapping data from the datastore after disconnecting
+     * ODL from a Netconf device.
+     */
+    void deleteMappingData(String nodeId);
+
     /**
      * This method for a given node's termination point returns the Mapping object based on
      * portmapping.yang model stored in the MD-SAL data store which is created when the node is
index e8e9e10fa28e6332f7d3ba08ea4a659937ce1ae7..7ac0f2c3d0163fd96ebd8a1681512b718082c0fd 100644 (file)
@@ -15,6 +15,8 @@ import java.util.Comparator;
 import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import java.util.stream.Collectors;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -83,7 +85,7 @@ public class PortMappingImpl implements PortMapping {
         List<Mapping> portMapList = new ArrayList<>();
         InstanceIdentifier<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
         Optional<Info> deviceInfoOptional =
-                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, infoIID,
+                this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, infoIID,
                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
 
         Info deviceInfo;
@@ -158,7 +160,7 @@ public class PortMappingImpl implements PortMapping {
             LOG.info("Fetching logical Connection Point value for port {} at circuit pack {}", portName,
                     circuitPackName);
             Optional<Ports> portObject =
-                    deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, portIID,
+                    this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, portIID,
                             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
             if (portObject.isPresent()) {
                 Ports port = portObject.get();
@@ -196,8 +198,8 @@ public class PortMappingImpl implements PortMapping {
             InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
                     .child(Degree.class, new DegreeKey(degreeCounter));
             Optional<Degree> ordmDegreeObject =
-                    deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.CONFIGURATION, deviceIID,
-                            Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+                    this.deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.CONFIGURATION,
+                            deviceIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
             if (ordmDegreeObject.isPresent()) {
                 degrees.add(ordmDegreeObject.get());
             } else {
@@ -231,10 +233,10 @@ public class PortMappingImpl implements PortMapping {
             InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
                     .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName));
             Optional<CircuitPacks> circuitPackObject =
-                    deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, cpIID,
+                    this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, cpIID,
                             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
 
-            if (!circuitPackObject.isPresent() || circuitPackObject.get().getPorts() == null) {
+            if (!circuitPackObject.isPresent() || (circuitPackObject.get().getPorts() == null)) {
                 LOG.warn("Circuit pack was not found or ports are mission for name: {}", circuitPackName);
                 continue; // TODO continue or return false?
             }
@@ -281,21 +283,22 @@ public class PortMappingImpl implements PortMapping {
             maxSrg = 20;
         }
 
-        for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) {
+        int srgCounter = 1;
+        Integer nbSrg = 0;
+        while (srgCounter <= maxSrg) {
             LOG.info("Getting Circuitpacks for Srg Number {}", srgCounter);
             InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
                     .child(SharedRiskGroup.class, new SharedRiskGroupKey(srgCounter));
             Optional<SharedRiskGroup> ordmSrgObject =
-                    deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.CONFIGURATION, srgIID,
-                            Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
-
+                    this.deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.CONFIGURATION,
+                            srgIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
             if (ordmSrgObject.isPresent()) {
                 srgCps.addAll(ordmSrgObject.get().getCircuitPacks());
-            } else {
-                LOG.info("Device has {} Srg", srgCounter - 1);
-                break;
+                nbSrg++;
             }
+            srgCounter++;
         }
+        LOG.info("Device has {} Srg", nbSrg);
         return srgCps;
     }
 
@@ -320,14 +323,14 @@ public class PortMappingImpl implements PortMapping {
         // Creating for Xponder Line and Client Ports
         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
         Optional<OrgOpenroadmDevice> deviceObject =
-                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
+                this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
                         Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
 
         // Variable to keep track of number of line ports
         int line = 1;
         // Variable to keep track of number of client ports
         int client = 1;
-        if (!deviceObject.isPresent() || deviceObject.get().getCircuitPacks() == null) {
+        if (!deviceObject.isPresent() || (deviceObject.get().getCircuitPacks() == null)) {
             LOG.warn("Circuit Packs are not present for {}", nodeId);
             return false; // TODO return false or continue?
         }
@@ -376,11 +379,11 @@ public class PortMappingImpl implements PortMapping {
                 .setSupportingCircuitPackName(circuitPackName).setSupportingPort(port.getPortName());
 
         // Get OMS and OTS interface provisioned on the TTP's
-        if (logicalConnectionPoint.contains(OpenRoadmInterfacesImpl.TTP_TOKEN) && port.getInterfaces() != null) {
+        if (logicalConnectionPoint.contains(OpenRoadmInterfacesImpl.TTP_TOKEN) && (port.getInterfaces() != null)) {
             for (Interfaces interfaces : port.getInterfaces()) {
                 try {
                     Optional<Interface> openRoadmInterface =
-                            openRoadmInterfaces.getInterface(nodeId, interfaces.getInterfaceName());
+                            this.openRoadmInterfaces.getInterface(nodeId, interfaces.getInterfaceName());
                     if (openRoadmInterface.isPresent()) {
                         Class<? extends InterfaceType> interfaceType = openRoadmInterface.get().getType();
                         // Check if interface type is OMS or OTS
@@ -455,7 +458,7 @@ public class PortMappingImpl implements PortMapping {
         NetworkBuilder nwBldr = new NetworkBuilder();
         nwBldr.setNodes(nodesList);
 
-        final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
+        final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
         InstanceIdentifier<Network> nodesIID = InstanceIdentifier.builder(Network.class).build();
         Network network = nwBldr.build();
         writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodesIID, network);
@@ -478,7 +481,7 @@ public class PortMappingImpl implements PortMapping {
          */
         InstanceIdentifier<Mapping> portMappingIID = InstanceIdentifier.builder(Network.class).child(Nodes.class,
             new NodesKey(nodeId)).child(Mapping.class, new MappingKey(logicalConnPoint)).build();
-        try (ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction()) {
+        try (ReadOnlyTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
             Optional<Mapping> mapObject =
                     readTx.read(LogicalDatastoreType.CONFIGURATION, portMappingIID).get().toJavaUtil();
             if (mapObject.isPresent()) {
@@ -522,4 +525,20 @@ public class PortMappingImpl implements PortMapping {
         return ""; // TODO return false or continue?
     }
 
+    @Override
+    public void deleteMappingData(String nodeId) {
+        LOG.info("Deleting Mapping Data corresponding at node '{}'",nodeId);
+        WriteTransaction rw = this.dataBroker.newWriteOnlyTransaction();
+        InstanceIdentifier<Nodes> nodesIID = InstanceIdentifier.create(Network.class)
+            .child(Nodes.class, new NodesKey(nodeId));
+        rw.delete(LogicalDatastoreType.CONFIGURATION, nodesIID);
+        try {
+            rw.submit().get(1, TimeUnit.SECONDS);
+            LOG.info("Port mapping removal for node '{}'", nodeId);
+        } catch (InterruptedException | ExecutionException | TimeoutException e) {
+            LOG.error("Error for removing port mapping infos for node '{}'",nodeId);
+        }
+
+    }
+
 }
index e8bff8fb7b48f41b8181a680b67feb654687c47f..793bffc78eaad62b18c083936b177314460d977c 100644 (file)
@@ -40,9 +40,9 @@ public class OpenRoadmInterfacesImpl implements OpenRoadmInterfaces {
     private static final Logger LOG = LoggerFactory.getLogger(OpenRoadmInterfacesImpl.class);
 
     // TODO move somewhere to constants
-    public static final String NETWORK_TOKEN = "XPDR1-NETWORK";
+    public static final String NETWORK_TOKEN = "XPDR-LINE";
     public static final String TTP_TOKEN = "TTP";
-    public static final String CLIENT_TOKEN = "XPDR1-CLIENT";
+    public static final String CLIENT_TOKEN = "XPDR-CLNT";
     public static final String PP_TOKEN = "PP";
 
     private final DeviceTransactionManager deviceTransactionManager;
@@ -53,7 +53,7 @@ public class OpenRoadmInterfacesImpl implements OpenRoadmInterfaces {
 
     @Override
     public void postInterface(String nodeId, InterfaceBuilder ifBuilder) throws OpenRoadmInterfaceException {
-        Future<Optional<DeviceTransaction>> deviceTxFuture = deviceTransactionManager.getDeviceTransaction(nodeId);
+        Future<Optional<DeviceTransaction>> deviceTxFuture = this.deviceTransactionManager.getDeviceTransaction(nodeId);
         DeviceTransaction deviceTx;
         try {
             Optional<DeviceTransaction> deviceTxOpt = deviceTxFuture.get();
@@ -86,7 +86,7 @@ public class OpenRoadmInterfacesImpl implements OpenRoadmInterfaces {
     public Optional<Interface> getInterface(String nodeId, String interfaceName) throws OpenRoadmInterfaceException {
         InstanceIdentifier<Interface> interfacesIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
                 .child(Interface.class, new InterfaceKey(interfaceName));
-        return deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, interfacesIID,
+        return this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, interfacesIID,
                 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
     }
 
@@ -144,7 +144,7 @@ public class OpenRoadmInterfacesImpl implements OpenRoadmInterfaces {
 
             InstanceIdentifier<Interface> interfacesIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
                     .child(Interface.class, new InterfaceKey(interfaceName));
-            Future<Optional<DeviceTransaction>> deviceTxFuture = deviceTransactionManager.getDeviceTransaction(nodeId);
+            Future<Optional<DeviceTransaction>> deviceTxFuture = this.deviceTransactionManager.getDeviceTransaction(nodeId);
             DeviceTransaction deviceTx;
             try {
                 Optional<DeviceTransaction> deviceTxOpt = deviceTxFuture.get();