Bug corrections in topo and portmapping modules 55/73555/6
authorGilles Thouenon <gilles.thouenon@orange.com>
Wed, 6 Jun 2018 14:21:42 +0000 (16:21 +0200)
committerguillaume.lambert <guillaume.lambert@orange.com>
Wed, 18 Jul 2018 14:50:49 +0000 (16:50 +0200)
- insert if not found, the SRG number into the logical connection
point name during the portmapping creation.
- add the CP as one of the  termination points of the SRG
- put the right node type value of the XPONDER
- take into account the ROADMs found by the lldp even if the previous
declared ones are missing

Change-Id: I9da179dada5a23c764da3fdb3f74ccd493e9dc4e
Signed-off-by: Gilles Thouenon <gilles.thouenon@orange.com>
Co-authored-by: Christophe Betoule <christophe.betoule@orange.com>
Co-authored-by: Martial COULIBALY <martial.coulibaly@gfi.fr>
common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingImpl.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/R2RLinkDiscovery.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/util/OpenRoadmNetwork.java
networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/util/OpenRoadmTopology.java

index 7ac0f2c3d0163fd96ebd8a1681512b718082c0fd..3dc9f3f6be339f7ba87045191f2476e46c586c8f 100644 (file)
@@ -12,8 +12,12 @@ import com.google.common.util.concurrent.CheckedFuture;
 
 import java.util.ArrayList;
 import java.util.Comparator;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Optional;
+import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
@@ -72,7 +76,7 @@ public class PortMappingImpl implements PortMapping {
     private final OpenRoadmInterfaces openRoadmInterfaces;
 
     public PortMappingImpl(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
-            OpenRoadmInterfaces openRoadmInterfaces) {
+        OpenRoadmInterfaces openRoadmInterfaces) {
         this.dataBroker = dataBroker;
         this.deviceTransactionManager = deviceTransactionManager;
         this.openRoadmInterfaces = openRoadmInterfaces;
@@ -84,9 +88,9 @@ public class PortMappingImpl implements PortMapping {
         LOG.info("Create Mapping Data for node {}", nodeId);
         List<Mapping> portMapList = new ArrayList<>();
         InstanceIdentifier<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
-        Optional<Info> deviceInfoOptional =
-                this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, infoIID,
-                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        Optional<Info> deviceInfoOptional = this.deviceTransactionManager.getDataFromDevice(nodeId,
+            LogicalDatastoreType.OPERATIONAL, infoIID,
+            Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
 
         Info deviceInfo;
         if (deviceInfoOptional.isPresent()) {
@@ -96,7 +100,7 @@ public class PortMappingImpl implements PortMapping {
             return false;
         }
         if (deviceInfo.getNodeType() == null) {
-            LOG.warn("Node type field is missing"); // TODO make mandatory in yang
+            LOG.error("Node type field is missing"); // TODO make mandatory in yang
             return false;
         }
         switch (deviceInfo.getNodeType()) {
@@ -131,12 +135,16 @@ public class PortMappingImpl implements PortMapping {
     }
 
     /**
-     * This private method gets the list of external ports on a degree. For each port in the degree, it
-     * does a get on port subtree with circuit-pack-name/port-name as key in order to get the logical
-     * connection point name corresponding to it.
+     * This private method gets the list of external ports on a degree. For each
+     * port in the degree, it does a get on port subtree with
+     * circuit-pack-name/port-name as key in order to get the logical connection
+     * point name corresponding to it.
      *
-     * @param deviceInfo Info subtree read from the device
-     * @param portMapList Reference to the list containing the mapping to be pushed to MD-SAL
+     * @param deviceInfo
+     *            Info subtree read from the device
+     * @param portMapList
+     *            Reference to the list containing the mapping to be pushed to
+     *            MD-SAL
      *
      * @return true/false based on status of operation
      */
@@ -154,24 +162,24 @@ public class PortMappingImpl implements PortMapping {
             String circuitPackName = cp.getCircuitPackName();
             String portName = cp.getPortName().toString();
             InstanceIdentifier<Ports> portIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                    .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName))
-                    .child(Ports.class, new PortsKey(portName));
+                .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName))
+                .child(Ports.class, new PortsKey(portName));
 
             LOG.info("Fetching logical Connection Point value for port {} at circuit pack {}", portName,
-                    circuitPackName);
-            Optional<Ports> portObject =
-                    this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, portIID,
-                            Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+                circuitPackName);
+            Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
+                LogicalDatastoreType.OPERATIONAL, portIID,
+                Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
             if (portObject.isPresent()) {
                 Ports port = portObject.get();
                 if (port.getLogicalConnectionPoint() != null) {
                     LOG.info("Logical Connection Point for {} {} is {}", circuitPackName, portName,
-                            port.getLogicalConnectionPoint());
+                        port.getLogicalConnectionPoint());
                     portMapList.add(createMappingObject(nodeId, port, circuitPackName,
-                            port.getLogicalConnectionPoint()));
+                        port.getLogicalConnectionPoint()));
                 } else {
                     LOG.warn("Logical Connection Point value is missing for {} {}", circuitPackName,
-                            port.getPortName());
+                        port.getPortName());
                 }
             } else {
                 LOG.warn("Port {} is not present in node {} in circuit pack {}!", portName, nodeId, circuitPackName);
@@ -196,10 +204,10 @@ public class PortMappingImpl implements PortMapping {
         for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
             LOG.info("Getting Connection ports for Degree Number {}", degreeCounter);
             InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                    .child(Degree.class, new DegreeKey(degreeCounter));
-            Optional<Degree> ordmDegreeObject =
-                    this.deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.CONFIGURATION,
-                            deviceIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+                .child(Degree.class, new DegreeKey(degreeCounter));
+            Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
+                LogicalDatastoreType.CONFIGURATION,
+                deviceIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
             if (ordmDegreeObject.isPresent()) {
                 degrees.add(ordmDegreeObject.get());
             } else {
@@ -211,48 +219,62 @@ public class PortMappingImpl implements PortMapping {
     }
 
     /**
-     * This private method gets the list of circuit packs on an Srg. For each circuit pack on an Srg, it
-     * does a get on circuit-pack subtree with circuit-pack-name as key in order to get the list of
-     * ports. It then iterates over the list of ports to get ports with port-qual as roadm-external. It
-     * appends a TX,RX,TXRX to the logical connection point name based on the direction of the port.
+     * This private method gets the list of circuit packs on an Srg. For each
+     * circuit pack on an Srg, it does a get on circuit-pack subtree with
+     * circuit-pack-name as key in order to get the list of ports. It then
+     * iterates over the list of ports to get ports with port-qual as
+     * roadm-external. It appends a TX,RX,TXRX to the logical connection point
+     * name based on the direction of the port.
      *
-     * @param nodeId Id of device
-     * @param deviceInfo Info subtree read from the device
-     * @param portMapList Reference to the list containing the mapping to be pushed to MD-SAL
+     * @param nodeId
+     *            Id of device
+     * @param deviceInfo
+     *            Info subtree read from the device
+     * @param portMapList
+     *            Reference to the list containing the mapping to be pushed to
+     *            MD-SAL
      *
      * @return true/false based on status of operation
      */
 
     private boolean createPpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
-        // Creating mapping data for degree PP's
-        List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> srgCps =
-                getSrgCps(nodeId, deviceInfo);
-
-        for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks cps : srgCps) {
-            String circuitPackName = cps.getCircuitPackName();
-            InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+        // Creating mapping data for SRG's PP
+        HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg
+            .CircuitPacks>> srgCps = getSrgCps(nodeId, deviceInfo);
+        Set<Map.Entry<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206
+            .srg.CircuitPacks>>> circuitPacks = srgCps.entrySet();
+        for (Entry<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg
+                .CircuitPacks>> entry : circuitPacks) {
+            Integer srgIndex = entry.getKey();
+            for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks cp : entry
+                .getValue()) {
+                String circuitPackName = cp.getCircuitPackName();
+                InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
                     .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName));
-            Optional<CircuitPacks> circuitPackObject =
-                    this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, cpIID,
-                            Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+                Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
+                    LogicalDatastoreType.OPERATIONAL, cpIID,
+                    Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
 
-            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?
-            }
-            CircuitPacks cp = circuitPackObject.get();
-            for (Ports port : cp.getPorts()) {
-                if (port.getLogicalConnectionPoint() != null) {
-                    String logicalConnectionPoint = getLogicalConnectionPort(port);
-                    LOG.info("Logical Connection Point for {} {} is {}", circuitPackName, port.getPortName(),
+                if (!circuitPackObject.isPresent() || (circuitPackObject.get().getPorts() == null)) {
+                    LOG.warn("{} : Circuit pack {} not found or without ports.", nodeId, circuitPackName);
+                    continue; // TODO continue or return false?
+                }
+                CircuitPacks circuitPack = circuitPackObject.get();
+                for (Ports port : circuitPack.getPorts()) {
+                    if (port.getLogicalConnectionPoint() != null) {
+                        String logicalConnectionPoint = getLogicalConnectionPort(port, srgIndex);
+                        LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId, circuitPackName, port
+                            .getPortName(),
                             logicalConnectionPoint);
-                    portMapList.add(createMappingObject(nodeId, port, circuitPackName, logicalConnectionPoint));
-                } else if (Port.PortQual.RoadmInternal.equals(port.getPortQual())) {
-                    LOG.info("Port is internal, skipping Logical Connection Point missing for {} {}", circuitPackName,
+                        portMapList.add(createMappingObject(nodeId, port, circuitPackName, logicalConnectionPoint));
+                    } else if (Port.PortQual.RoadmInternal.equals(port.getPortQual())) {
+                        LOG.info("Port is internal, skipping Logical Connection Point missing for {} {}",
+                            circuitPackName,
                             port.getPortName());
-                } else if (port.getLogicalConnectionPoint() == null) {
-                    LOG.info("Value missing, Skipping Logical Connection Point missing for {} {}", circuitPackName,
+                    } else if (port.getLogicalConnectionPoint() == null) {
+                        LOG.info("Value missing, Skipping Logical Connection Point missing for {} {}", circuitPackName,
                             port.getPortName());
+                    }
                 }
             }
         }
@@ -265,15 +287,17 @@ public class PortMappingImpl implements PortMapping {
      * objects that are part of srgs. It is required to do a selective get on
      * all the circuit packs that contain add/drop ports of interest.
      *
-     * @param deviceId Device id
-     * @param ordmInfo Info subtree from the device
-     * @return List of circuit packs object belonging to- shared risk group subtree
+     * @param deviceId
+     *            Device id
+     * @param ordmInfo
+     *            Info subtree from the device
+     * @return List of circuit packs object belonging to- shared risk group
+     *         subtree
      */
-    private List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> getSrgCps(
-            String deviceId, Info ordmInfo) {
-
-        List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> srgCps =
-                new ArrayList<>();
+    private HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg
+        .CircuitPacks>> getSrgCps(String deviceId, Info ordmInfo) {
+        HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg
+            .CircuitPacks>> cpPerSrg = new HashMap<>();
         Integer maxSrg;
         // Get value for max Srg from info subtree, required for iteration
         // if not present assume to be 20 (temporary)
@@ -282,30 +306,29 @@ public class PortMappingImpl implements PortMapping {
         } else {
             maxSrg = 20;
         }
-
-        int srgCounter = 1;
-        Integer nbSrg = 0;
-        while (srgCounter <= maxSrg) {
+        for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) {
+            List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> srgCps =
+                new ArrayList<>();
             LOG.info("Getting Circuitpacks for Srg Number {}", srgCounter);
             InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
-                    .child(SharedRiskGroup.class, new SharedRiskGroupKey(srgCounter));
-            Optional<SharedRiskGroup> ordmSrgObject =
-                    this.deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.CONFIGURATION,
-                            srgIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+                .child(SharedRiskGroup.class, new SharedRiskGroupKey(srgCounter));
+            Optional<SharedRiskGroup> ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
+                LogicalDatastoreType.CONFIGURATION,
+                srgIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
             if (ordmSrgObject.isPresent()) {
                 srgCps.addAll(ordmSrgObject.get().getCircuitPacks());
-                nbSrg++;
+                cpPerSrg.put(ordmSrgObject.get().getSrgNumber(), srgCps);
             }
-            srgCounter++;
         }
-        LOG.info("Device has {} Srg", nbSrg);
-        return srgCps;
+        LOG.info("Device {} has {} Srg", deviceId, cpPerSrg.size());
+        return cpPerSrg;
     }
 
     /**
-     * This private method gets the list of circuit packs on a xponder. For each circuit pack on a
-     * Xponder, it does a get on circuit-pack subtree with circuit-pack-name as key in order to get the
-     * list of ports. It then iterates over the list of ports to get ports with port-qual as
+     * This private method gets the list of circuit packs on a xponder. For each
+     * circuit pack on a Xponder, it does a get on circuit-pack subtree with
+     * circuit-pack-name as key in order to get the list of ports. It then
+     * iterates over the list of ports to get ports with port-qual as
      * xpdr-network/xpdr-client. The line and client ports are saved as:
      *
      * <p>
@@ -314,17 +337,20 @@ public class PortMappingImpl implements PortMapping {
      * <p>
      * 2. CLNTn
      *
-     * @param nodeId Id of device
-     * @param portMapList Reference to the list containing the mapping to be pushed to MD-SAL
+     * @param nodeId
+     *            Id of device
+     * @param portMapList
+     *            Reference to the list containing the mapping to be pushed to
+     *            MD-SAL
      *
      * @return true/false based on status of operation
      */
     private boolean createXpdrPortMapping(String nodeId, List<Mapping> portMapList) {
         // Creating for Xponder Line and Client Ports
         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
-        Optional<OrgOpenroadmDevice> deviceObject =
-                this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, deviceIID,
-                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        Optional<OrgOpenroadmDevice> deviceObject = 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;
@@ -347,11 +373,11 @@ public class PortMappingImpl implements PortMapping {
             for (Ports port : cp.getPorts()) {
                 if (Port.PortQual.XpdrNetwork.equals(port.getPortQual())) {
                     portMapList.add(createMappingObject(nodeId, port, circuitPackName,
-                            OpenRoadmInterfacesImpl.NETWORK_TOKEN + line));
+                        OpenRoadmInterfacesImpl.NETWORK_TOKEN + line));
                     line++;
                 } else if (Port.PortQual.XpdrClient.equals(port.getPortQual())) {
                     portMapList.add(createMappingObject(nodeId, port, circuitPackName,
-                            OpenRoadmInterfacesImpl.CLIENT_TOKEN + client));
+                        OpenRoadmInterfacesImpl.CLIENT_TOKEN + client));
                     client++;
                 } else {
                     LOG.warn("Not supported type of port! Port type: {}", port.getPortQual());
@@ -362,28 +388,32 @@ public class PortMappingImpl implements PortMapping {
     }
 
     /**
-     * This private method builds the mapping object to be pushed in MD-SAL in order to save port
-     * mapping. In case of TTP ports, it also saves the OTS,OMS interfaces provisioned on the port.
+     * This private method builds the mapping object to be pushed in MD-SAL in
+     * order to save port mapping. In case of TTP ports, it also saves the
+     * OTS,OMS interfaces provisioned on the port.
      *
-     * @param port Reference to device's port subtree object.
-     * @param circuitPackName Name of cp where port exists.
-     * @param logicalConnectionPoint logical name of the port.
+     * @param port
+     *            Reference to device's port subtree object.
+     * @param circuitPackName
+     *            Name of cp where port exists.
+     * @param logicalConnectionPoint
+     *            logical name of the port.
      *
      * @return true/false based on status of operation
      */
 
     private Mapping createMappingObject(String nodeId, Ports port, String circuitPackName,
-            String logicalConnectionPoint) {
+        String logicalConnectionPoint) {
         MappingBuilder mpBldr = new MappingBuilder();
         mpBldr.setKey(new MappingKey(logicalConnectionPoint)).setLogicalConnectionPoint(logicalConnectionPoint)
-                .setSupportingCircuitPackName(circuitPackName).setSupportingPort(port.getPortName());
+            .setSupportingCircuitPackName(circuitPackName).setSupportingPort(port.getPortName());
 
         // Get OMS and OTS interface provisioned on the TTP's
         if (logicalConnectionPoint.contains(OpenRoadmInterfacesImpl.TTP_TOKEN) && (port.getInterfaces() != null)) {
             for (Interfaces interfaces : port.getInterfaces()) {
                 try {
-                    Optional<Interface> openRoadmInterface =
-                            this.openRoadmInterfaces.getInterface(nodeId, interfaces.getInterfaceName());
+                    Optional<Interface> openRoadmInterface = this.openRoadmInterfaces.getInterface(nodeId,
+                        interfaces.getInterfaceName());
                     if (openRoadmInterface.isPresent()) {
                         Class<? extends InterfaceType> interfaceType = openRoadmInterface.get().getType();
                         // Check if interface type is OMS or OTS
@@ -398,7 +428,7 @@ public class PortMappingImpl implements PortMapping {
                     }
                 } catch (OpenRoadmInterfaceException ex) {
                     LOG.warn("Error while getting interface {} from node {}!", interfaces.getInterfaceName(), nodeId,
-                            ex);
+                        ex);
                 }
             }
         }
@@ -407,12 +437,12 @@ public class PortMappingImpl implements PortMapping {
 
     private static CpToDegree createCpToDegreeObject(String circuitPackName, String degreeNumber) {
         return new CpToDegreeBuilder().setKey(new CpToDegreeKey(circuitPackName)).setCircuitPackName(circuitPackName)
-                .setDegreeNumber(new Long(degreeNumber)).build();
+            .setDegreeNumber(new Long(degreeNumber)).build();
     }
 
     private static List<ConnectionPorts> getDegreePorts(List<Degree> degrees) {
         return degrees.stream().filter(degree -> degree.getConnectionPorts() != null)
-                .flatMap(degree -> degree.getConnectionPorts().stream()).collect(Collectors.toList());
+            .flatMap(degree -> degree.getConnectionPorts().stream()).collect(Collectors.toList());
     }
 
     private List<CpToDegree> getCpToDegreeList(List<Degree> degrees) {
@@ -420,27 +450,31 @@ public class PortMappingImpl implements PortMapping {
         for (Degree degree : degrees) {
             if (degree.getCircuitPacks() != null) {
                 cpToDegreeList.addAll(degree.getCircuitPacks().stream()
-                        .map(cp -> createCpToDegreeObject(cp.getCircuitPackName(), degree.getDegreeNumber().toString()))
-                        .collect(Collectors.toList()));
+                    .map(cp -> createCpToDegreeObject(cp.getCircuitPackName(), degree.getDegreeNumber().toString()))
+                    .collect(Collectors.toList()));
             }
         }
         return cpToDegreeList;
     }
 
     /**
-     * This method for ports the portMapping corresponding to the portmapping.yang file to the MD-SAL
-     * datastore.
+     * This method for ports the portMapping corresponding to the
+     * portmapping.yang file to the MD-SAL datastore.
      *
      * <p>
-     * 1. Supporting circuit pack 2. Supporting port 3. Supporting OMS interface (if port on ROADM)
+     * 1. Supporting circuit pack 2. Supporting port 3. Supporting OMS interface
+     * (if port on ROADM)
      *
-     * @param deviceInfo Info subtree from the device.
-     * @param portMapList Reference to the list containing the mapping to be pushed to MD-SAL.
+     * @param deviceInfo
+     *            Info subtree from the device.
+     * @param portMapList
+     *            Reference to the list containing the mapping to be pushed to
+     *            MD-SAL.
      *
      * @return Result true/false based on status of operation.
      */
     private boolean postPortMapping(Info deviceInfo, List<Mapping> portMapList, Integer nodeType,
-            List<CpToDegree> cp2DegreeList) {
+        List<CpToDegree> cp2DegreeList) {
         NodesBuilder nodesBldr = new NodesBuilder();
         nodesBldr.setKey(new NodesKey(deviceInfo.getNodeId())).setNodeId(deviceInfo.getNodeId());
         nodesBldr.setNodeType(NodeTypes.forValue(nodeType));
@@ -482,52 +516,69 @@ 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 = this.dataBroker.newReadOnlyTransaction()) {
-            Optional<Mapping> mapObject =
-                    readTx.read(LogicalDatastoreType.CONFIGURATION, portMappingIID).get().toJavaUtil();
+            Optional<Mapping> mapObject = readTx.read(LogicalDatastoreType.CONFIGURATION, portMappingIID).get()
+                .toJavaUtil();
             if (mapObject.isPresent()) {
                 Mapping mapping = mapObject.get();
                 LOG.info("Found mapping for the logical port {}. Mapping: {}", logicalConnPoint, mapping.toString());
                 return mapping;
             } else {
                 LOG.warn("Could not find mapping for logical connection point {} for nodeId {}", logicalConnPoint,
-                        nodeId);
+                    nodeId);
             }
         } catch (InterruptedException | ExecutionException ex) {
             LOG.error("Unable to read mapping for logical connection point : {} for nodeId {}", logicalConnPoint,
-                    nodeId, ex);
+                nodeId, ex);
         }
         return null;
     }
 
-    private static String getLogicalConnectionPort(Ports port) {
+    private static String getLogicalConnectionPort(Ports port, int srgCounter) {
+        String logicalConnectionPoint = null;
         if (port.getLogicalConnectionPoint() != null) {
             switch (port.getPortDirection()) {
                 case Tx:
                     // Port direction is transmit
-                    return port.getLogicalConnectionPoint() + "-TX";
+                    if (!port.getLogicalConnectionPoint().contains("SRG")) {
+                        logicalConnectionPoint = "SRG" + srgCounter + "-" + port.getLogicalConnectionPoint() + "-TX";
+                    } else {
+                        logicalConnectionPoint = port.getLogicalConnectionPoint() + "-TX";
+                    }
+                    break;
                 case Rx:
                     // Port direction is receive
-                    return port.getLogicalConnectionPoint() + "-RX";
+                    if (!port.getLogicalConnectionPoint().contains("SRG")) {
+                        logicalConnectionPoint = "SRG" + srgCounter + "-" + port.getLogicalConnectionPoint() + "-RX";
+                    } else {
+                        logicalConnectionPoint = port.getLogicalConnectionPoint() + "-RX";
+                    }
+                    break;
                 case Bidirectional:
-                    // port is bi-directional
-                    if (port.getLogicalConnectionPoint().endsWith("-TXRX")) {
-                        return port.getLogicalConnectionPoint();
+                    // port is bidirectional
+                    if (!port.getLogicalConnectionPoint().contains("SRG")) {
+                        logicalConnectionPoint = "SRG" + srgCounter + "-" + port.getLogicalConnectionPoint();
+                    } else {
+                        logicalConnectionPoint = port.getLogicalConnectionPoint();
+                    }
+                    if (!port.getLogicalConnectionPoint().endsWith("-TXRX")) {
+                        logicalConnectionPoint = logicalConnectionPoint.concat("-TXRX");
                     }
-                    return port.getLogicalConnectionPoint() + "-TXRX";
+                    break;
                 default:
                     // Unsupported Port direction
-                    LOG.error("Unsupported port direction for port {} - {}", port, port.getPortDirection());
-                    return ""; // TODO return false or continue?
+                    LOG.error("Unsupported port direction for port {}  {}", port, port.getPortDirection());
+                    return null; // TODO return false or continue?
             }
+            return logicalConnectionPoint;
         }
         LOG.warn("Unsupported port direction for port {} - {} - LogicalConnectionPoint is null",
             port, port.getPortDirection());
-        return ""; // TODO return false or continue?
+        return null; // TODO return false or continue?
     }
 
     @Override
     public void deleteMappingData(String nodeId) {
-        LOG.info("Deleting Mapping Data corresponding at node '{}'",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));
@@ -536,7 +587,7 @@ public class PortMappingImpl implements PortMapping {
             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);
+            LOG.error("Error for removing port mapping infos for node '{}'", nodeId);
         }
 
     }
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 {
index 2292cf19235fcb71a08597254e31e31f6c84ce98..14ff27bd6f808efc2a7bf0a7abf2b05c1b7ae781 100644 (file)
@@ -47,7 +47,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdenti
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 public class OpenRoadmNetwork {
 
     private static final Logger LOG = LoggerFactory.getLogger(OpenRoadmNetwork.class);
@@ -57,7 +56,8 @@ public class OpenRoadmNetwork {
     }
 
     /**
-     * This public method creates the OpenRoadmNetwork Layer and posts it to the controller.
+     * This public method creates the OpenRoadmNetwork Layer and posts it to the
+     * controller.
      */
     public static void createOpenRoadmNetworkLayer(DataBroker controllerdb) {
         try {
@@ -80,9 +80,9 @@ public class OpenRoadmNetwork {
     public static Node createNode(String nodeId, DeviceTransactionManager deviceTransactionManager) {
         // Fetches the info from the deviceInfo
         InstanceIdentifier<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
-        Optional<Info> deviceInfoOpt =
-                deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, infoIID,
-                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        Optional<Info> deviceInfoOpt = deviceTransactionManager.getDataFromDevice(nodeId,
+                LogicalDatastoreType.OPERATIONAL, infoIID, Timeouts.DEVICE_READ_TIMEOUT,
+                Timeouts.DEVICE_READ_TIMEOUT_UNIT);
         Info deviceInfo;
         if (deviceInfoOpt.isPresent()) {
             deviceInfo = deviceInfoOpt.get();
@@ -100,12 +100,18 @@ public class OpenRoadmNetwork {
         Node1Builder node1bldr = new Node1Builder();
 
         /*
-         * If the type of the Node is ROADM, Node type is set to ROADM Else, XPONDER
+         * Recognize the node type: 1:ROADM, 2:XPONDER
          */
-        if (nodeType.getIntValue() == 1) {
-            node1bldr.setNodeType(OpenroadmNodeType.ROADM);
-        } else if (nodeType.getIntValue() == 3) {
-            node1bldr.setNodeType(OpenroadmNodeType.XPONDER);
+        switch (nodeType.getIntValue()) {
+            case 1:
+                node1bldr.setNodeType(OpenroadmNodeType.ROADM);
+                break;
+            case 2:
+                node1bldr.setNodeType(OpenroadmNodeType.XPONDER);
+                break;
+            default:
+                LOG.error("No correponsding type for the value: {}", nodeType.getIntValue());
+                break;
         }
 
         String vendor = deviceInfo.getVendor();
@@ -116,7 +122,8 @@ public class OpenRoadmNetwork {
         node1bldr.setModel(model);
         node1bldr.setVendor(vendor);
 
-        // Sets the value of Network-ref and Node-ref as a part of the supporting node attribute
+        // Sets the value of Network-ref and Node-ref as a part of the supporting node
+        // attribute
         String clli = deviceInfo.getClli();
         SupportingNodeBuilder supportbldr = new SupportingNodeBuilder();
         supportbldr.setKey(new SupportingNodeKey(new NetworkId(NetworkUtils.CLLI_NETWORK_ID), new NodeId(clli)));
@@ -137,7 +144,7 @@ public class OpenRoadmNetwork {
         NetworkId nwId = new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID);
         openrdmnwBuilder.setNetworkId(nwId);
         openrdmnwBuilder.setKey(new NetworkKey(nwId));
-        //sets network type to OpenRoadmNetwork
+        // sets network type to OpenRoadmNetwork
         NetworkTypes1Builder openRoadmNetworkTypesBldr = new NetworkTypes1Builder();
         openRoadmNetworkTypesBldr.setOpenroadmNetwork(new OpenroadmNetworkBuilder().build());
         NetworkTypesBuilder openrdmnwTypeBuilder = new NetworkTypesBuilder();
index 3a23f7cf1c22aa1296a433c06f79db2b6cff2a23..0abc53d5cd40a16d431e09f20fd49c157d89d431 100644 (file)
@@ -100,7 +100,8 @@ public class OpenRoadmTopology {
     }
 
     /**
-     * This public method creates the OpenROADM Topology Layer and posts it to the controller.
+     * This public method creates the OpenROADM Topology Layer and posts it to
+     * the controller.
      */
     public void createTopoLayer(DataBroker controllerdb) {
         try {
@@ -145,9 +146,9 @@ public class OpenRoadmTopology {
         int portDirectionEnum = DEFAULT_PORT_DIRECTION;
 
         InstanceIdentifier<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
-        java.util.Optional<Info> deviceInfoOpt =
-                this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, infoIID,
-                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        java.util.Optional<Info> deviceInfoOpt = this.deviceTransactionManager.getDataFromDevice(nodeId,
+                LogicalDatastoreType.OPERATIONAL, infoIID, Timeouts.DEVICE_READ_TIMEOUT,
+                Timeouts.DEVICE_READ_TIMEOUT_UNIT);
         Info deviceInfo;
         if (deviceInfoOpt.isPresent()) {
             deviceInfo = deviceInfoOpt.get();
@@ -161,8 +162,10 @@ public class OpenRoadmTopology {
         if (NodeTypes.Rdm.equals(deviceInfo.getNodeType())) {
 
             /*
-             * Adding Degree Node Get Degree Number -> x then get connection ports then find the port directions
-             * to decide whether TX/RX/TXRX Get value for max degree from info subtree, required for iteration
+             * Adding Degree Node Get Degree Number -> x
+             * then get connection ports
+             * then find the port directions to decide whether TX/RX/TXRX
+             * Get value for max degree from info subtree, required for iteration
              * if not present assume to be 20 (temporary)
              */
 
@@ -185,7 +188,7 @@ public class OpenRoadmTopology {
                     nodes.add(tempNode.build());
                     degreeCounter++;
                 } else {
-                // null returned if Degree number= degreeCounter not present in the device
+                    // null returned if Degree number= degreeCounter not present in the device
                     break;
                 }
             }
@@ -215,7 +218,6 @@ public class OpenRoadmTopology {
             }
             numOfSrgs = srgCounter - 1;
 
-
             LOG.info("adding links numOfDegrees={} numOfSrgs={}", numOfDegrees, numOfSrgs);
             List<Link> links = new ArrayList<>();
             links.addAll(createExpressLinks(nodeId, numOfDegrees, portDirectionEnum));
@@ -245,9 +247,10 @@ public class OpenRoadmTopology {
     }
 
     /**
-     * This private method gets the list of circuit packs on a xponder. For each circuit pack on a
-     * Xponder, it does a get on circuit-pack subtree with circuit-pack-name as key in order to get the
-     * list of ports. It then iterates over the list of ports to get ports with port-qual as
+     * This private method gets the list of circuit packs on a xponder.
+     * For each circuit pack on a Xponder, it does a get on circuit-pack subtree with
+     * circuit-pack-name as key in order to get the list of ports.
+     * It then iterates over the list of ports to get ports with port-qual as
      * xpdr-network/xpdr-client. The line and client ports are saved as:
      *
      * <p>
@@ -259,9 +262,9 @@ public class OpenRoadmTopology {
     private int getNoOfClientPorts(String deviceId) {
         // Creating for Xponder Line and Client Ports
         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
-        Optional<OrgOpenroadmDevice> deviceObject =
-                this.deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.OPERATIONAL, deviceIID,
-                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        Optional<OrgOpenroadmDevice> deviceObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
+                LogicalDatastoreType.OPERATIONAL, deviceIID, Timeouts.DEVICE_READ_TIMEOUT,
+                Timeouts.DEVICE_READ_TIMEOUT_UNIT);
 
         // Variable to keep track of number of client ports
         int client = 1;
@@ -321,18 +324,17 @@ public class OpenRoadmTopology {
             tpList.add(tempTpBldr.build());
             lineCounter--;
         }
-        LOG.info("printing tpList {}",tpList);
+        LOG.info("printing tpList {}", tpList);
         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.Node1Builder tpNode1 =
             new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.Node1Builder();
         tpNode1.setTerminationPoint(tpList);
         nodebldr.addAugmentation(
                 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.Node1.class,
                 tpNode1.build());
-        LOG.info("The nodebldr {}",nodebldr);
+        LOG.info("The nodebldr {}", nodebldr);
         return nodebldr;
     }
 
-
     private NodeData createDegreeNode(String nodeId, int degreeCounter) {
         // Create augmentation node to inorder to add degree
         Node1Builder node1bldr = new Node1Builder();
@@ -359,7 +361,7 @@ public class OpenRoadmTopology {
         nodebldr.addAugmentation(Node1.class, node1bldr.build());
         // Get Port direction
         int portDirectionEnum = getPortDirection(nodeId, degreeConPorts.get(0).getCircuitPackName(),
-                                             degreeConPorts.get(0).getPortName().toString());
+                degreeConPorts.get(0).getPortName().toString());
 
         /*
          * if bi-directional then create 2 tp's :
@@ -368,10 +370,7 @@ public class OpenRoadmTopology {
          *
          * if uni-directional :
          *
-         *     --> TTP-TX
-         *     --> TTP-RX
-         *     --> CTP-TX
-         *     --> CTP-RX
+         * --> TTP-TX --> TTP-RX --> CTP-TX --> CTP-RX
          */
         TerminationPoint1Builder tp1Bldr = new TerminationPoint1Builder();
         TerminationPointBuilder tempTpBldr;
@@ -391,21 +390,21 @@ public class OpenRoadmTopology {
             tempTpBldr = createTpBldr("DEG" + degreeCounter + "-TTP-RX");
             tp1Bldr.setTpType(OpenroadmTpType.DEGREERXTTP);
 
-            tempTpBldr.addAugmentation(TerminationPoint1.class,tp1Bldr.build());
+            tempTpBldr.addAugmentation(TerminationPoint1.class, tp1Bldr.build());
             tpList.add(tempTpBldr.build());
 
             // Create CTP-TX termination
             tp1Bldr = new TerminationPoint1Builder();
             tempTpBldr = createTpBldr("DEG" + degreeCounter + "-CTP-TX");
             tp1Bldr.setTpType(OpenroadmTpType.DEGREETXCTP);
-            tempTpBldr.addAugmentation(TerminationPoint1.class,tp1Bldr.build());
+            tempTpBldr.addAugmentation(TerminationPoint1.class, tp1Bldr.build());
             tpList.add(tempTpBldr.build());
 
             // Create CTP-RX termination
             tp1Bldr = new TerminationPoint1Builder();
             tempTpBldr = createTpBldr("DEG" + degreeCounter + "-CTP-RX");
             tp1Bldr.setTpType(OpenroadmTpType.DEGREERXCTP);
-            tempTpBldr.addAugmentation(TerminationPoint1.class,tp1Bldr.build());
+            tempTpBldr.addAugmentation(TerminationPoint1.class, tp1Bldr.build());
             tpList.add(tempTpBldr.build());
 
         } else if (portDirectionEnum == 3) {
@@ -414,14 +413,14 @@ public class OpenRoadmTopology {
             tp1Bldr = new TerminationPoint1Builder();
             tempTpBldr = createTpBldr("DEG" + degreeCounter + "-TTP-TXRX");
             tp1Bldr.setTpType(OpenroadmTpType.DEGREETXRXTTP);
-            tempTpBldr.addAugmentation(TerminationPoint1.class,tp1Bldr.build());
+            tempTpBldr.addAugmentation(TerminationPoint1.class, tp1Bldr.build());
             tpList.add(tempTpBldr.build());
 
             // Create CTP-TXRX termination
             tp1Bldr = new TerminationPoint1Builder();
             tempTpBldr = createTpBldr("DEG" + degreeCounter + "-CTP-TXRX");
             tp1Bldr.setTpType(OpenroadmTpType.DEGREETXRXCTP);
-            tempTpBldr.addAugmentation(TerminationPoint1.class,tp1Bldr.build());
+            tempTpBldr.addAugmentation(TerminationPoint1.class, tp1Bldr.build());
             tpList.add(tempTpBldr.build());
 
         }
@@ -437,7 +436,6 @@ public class OpenRoadmTopology {
         return new NodeData(nodebldr, portDirectionEnum);
     }
 
-
     private NodeBuilder createSrgNode(String nodeId, int srgCounter, int portDirectionEnum) {
         // Create augmentation node to inorder to add degree
         Node1Builder node1bldr = new Node1Builder();
@@ -461,7 +459,6 @@ public class OpenRoadmTopology {
             return null;
         }
 
-
         String nodeIdtopo = new StringBuilder().append(nodeId).append("-SRG").append(srgCounter).toString();
         nodebldr.setNodeId(new NodeId(nodeIdtopo));
         List<TerminationPoint> tpList = new ArrayList<>();
@@ -475,14 +472,14 @@ public class OpenRoadmTopology {
                     break;
                 }
                 // ports are uni Directional on a degree, therefore 4 termination points
-                // Create TTP-TX termination
+                // Create PP-TX termination
                 tempTpBldr = createTpBldr("SRG" + srgCounter + "-PP" + i + "-TX");
                 tp1Bldr = new TerminationPoint1Builder();
                 tp1Bldr.setTpType(OpenroadmTpType.SRGTXPP);
                 tempTpBldr.addAugmentation(TerminationPoint1.class, tp1Bldr.build());
                 tpList.add(tempTpBldr.build());
 
-                // Create TTP-RX termination
+                // Create PP-RX termination
                 tempTpBldr = createTpBldr("SRG" + srgCounter + "-PP" + i + "-RX");
                 tp1Bldr = new TerminationPoint1Builder();
                 tp1Bldr.setTpType(OpenroadmTpType.SRGRXPP);
@@ -491,7 +488,7 @@ public class OpenRoadmTopology {
 
             } else if (portDirectionEnum == 3) {
                 // Ports are bi directional therefore 2 termination points
-                // Create TTP-TXRX termination
+                // Create PP-TXRX termination
                 tempTpBldr = createTpBldr("SRG" + srgCounter + "-PP" + i + "-TXRX");
                 tp1Bldr = new TerminationPoint1Builder();
                 tp1Bldr.setTpType(OpenroadmTpType.SRGTXRXPP);
@@ -500,6 +497,37 @@ public class OpenRoadmTopology {
             }
         }
 
+        switch (portDirectionEnum) {
+            case 1: // ports are uni Directional on a degree
+                // Create CP-TX termination
+                tempTpBldr = createTpBldr("SRG" + srgCounter + "-CP" + "-TX");
+                tp1Bldr = new TerminationPoint1Builder();
+                tp1Bldr.setTpType(OpenroadmTpType.SRGTXCP);
+                tempTpBldr.addAugmentation(TerminationPoint1.class, tp1Bldr.build());
+                tpList.add(tempTpBldr.build());
+                break;
+            case 2:
+                // Create CP-RX termination
+                tempTpBldr = createTpBldr("SRG" + srgCounter + "-CP" + "-RX");
+                tp1Bldr = new TerminationPoint1Builder();
+                tp1Bldr.setTpType(OpenroadmTpType.SRGRXCP);
+                tempTpBldr.addAugmentation(TerminationPoint1.class, tp1Bldr.build());
+                tpList.add(tempTpBldr.build());
+                break;
+            case 3:
+                // Ports are bi directional therefore 2 termination points
+                // Create CP-TXRX termination
+                tempTpBldr = createTpBldr("SRG" + srgCounter + "-CP" + "-TXRX");
+                tp1Bldr = new TerminationPoint1Builder();
+                tp1Bldr.setTpType(OpenroadmTpType.SRGTXRXCP);
+                tempTpBldr.addAugmentation(TerminationPoint1.class, tp1Bldr.build());
+                tpList.add(tempTpBldr.build());
+                break;
+            default:
+                LOG.error("No correponsding direction to the value: {}", portDirectionEnum);
+                break;
+        }
+
         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.Node1Builder tpNode1 =
             new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.Node1Builder();
 
@@ -513,18 +541,18 @@ public class OpenRoadmTopology {
     }
 
     /*
-     * This method will return the TTP ports in the device for a given degree number to be used by the
-     * node to create TTP and CTP termination point on the device
+     * This method will return the TTP ports in the device for a given degree number to
+     * be used by the node to create TTP and CTP termination point on the device.
      */
     private List<ConnectionPorts> getDegreePorts(String deviceId, Integer degreeCounter) {
         List<ConnectionPorts> degreeConPorts = new ArrayList<>();
         LOG.info("Getting Connection ports for Degree Number {}", degreeCounter);
-        InstanceIdentifier<Degree> deviceIID =
-                InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Degree.class, new DegreeKey(degreeCounter));
+        InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Degree.class,
+                new DegreeKey(degreeCounter));
 
-        Optional<Degree> ordmDegreeObject =
-                this.deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.CONFIGURATION, deviceIID,
-                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
+                LogicalDatastoreType.CONFIGURATION, deviceIID, Timeouts.DEVICE_READ_TIMEOUT,
+                Timeouts.DEVICE_READ_TIMEOUT_UNIT);
 
         if (ordmDegreeObject.isPresent()) {
             degreeConPorts.addAll(new ArrayList<>(ordmDegreeObject.get().getConnectionPorts()));
@@ -540,9 +568,9 @@ public class OpenRoadmTopology {
         LOG.info("Getting max pp ports for Srg Number {}", srgCounter);
         InstanceIdentifier<SharedRiskGroup> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
                 .child(SharedRiskGroup.class, new SharedRiskGroupKey(srgCounter));
-        Optional<SharedRiskGroup> ordmSrgObject =
-                this.deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.OPERATIONAL, deviceIID,
-                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        Optional<SharedRiskGroup> ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
+                LogicalDatastoreType.OPERATIONAL, deviceIID, Timeouts.DEVICE_READ_TIMEOUT,
+                Timeouts.DEVICE_READ_TIMEOUT_UNIT);
         if (ordmSrgObject.isPresent()) {
             if (ordmSrgObject.get().getMaxAddDropPorts() != null) {
                 maxPpPorts = ordmSrgObject.get().getMaxAddDropPorts();
@@ -581,9 +609,9 @@ public class OpenRoadmTopology {
                 .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName))
                 .child(Ports.class, new PortsKey(portName));
         LOG.info("Fetching Port Direction for port {} at circuit pack {}", portName, circuitPackName);
-        Optional<Ports> portObject =
-                this.deviceTransactionManager.getDataFromDevice(deviceId, LogicalDatastoreType.OPERATIONAL, portIID,
-                        Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+        Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
+                LogicalDatastoreType.OPERATIONAL, portIID, Timeouts.DEVICE_READ_TIMEOUT,
+                Timeouts.DEVICE_READ_TIMEOUT_UNIT);
         if (portObject.isPresent()) {
             Ports port = portObject.get();
             if (port.getPortDirection() != null) {
@@ -606,7 +634,7 @@ public class OpenRoadmTopology {
         return tpBldr;
     }
 
-    // This method returns the linkBuilder object for given source and destination
+    // This method returns the linkBuilder object for given source and destination.
     public LinkBuilder createLink(String srcNode, String dstNode, String srcTp, String destTp) {
         LOG.info("creating link for {}-{}", srcNode, dstNode);
         // Create Destination for link
@@ -624,7 +652,7 @@ public class OpenRoadmTopology {
         lnkBldr.setLinkId(LinkIdUtil.buildLinkId(srcNode, srcTp, dstNode, destTp));
         lnkBldr.setKey(new LinkKey(lnkBldr.getLinkId()));
         org.opendaylight.yang.gen.v1.http.org.openroadm.opposite.links.rev170929.Link1Builder lnk1Bldr =
-                new org.opendaylight.yang.gen.v1.http.org.openroadm.opposite.links.rev170929.Link1Builder();
+            new org.opendaylight.yang.gen.v1.http.org.openroadm.opposite.links.rev170929.Link1Builder();
         LinkId oppositeLinkId = LinkIdUtil.getOppositeLinkId(srcNode, srcTp, dstNode, destTp);
         lnk1Bldr.setOppositeLink(oppositeLinkId);
         lnkBldr.addAugmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.opposite.links.rev170929.Link1.class,
@@ -692,7 +720,6 @@ public class OpenRoadmTopology {
                     Link1Builder lnk1Bldr = new Link1Builder();
                     lnk1Bldr.setLinkType(OpenroadmLinkType.EXPRESSLINK);
 
-
                     LinkBuilder expLinkBldr = createLink(srcNode, destNode, srcTp, destTp);
                     expLinkBldr.addAugmentation(Link1.class, lnk1Bldr.build());
                     links.add(expLinkBldr.build());
@@ -707,8 +734,7 @@ public class OpenRoadmTopology {
         return links;
     }
 
-    private List<Link> createAddDropLinks(String nodeId, int numOfDegrees, int numOfSrgs,
-            int portDirectionEnum) {
+    private List<Link> createAddDropLinks(String nodeId, int numOfDegrees, int numOfSrgs, int portDirectionEnum) {
         LOG.info("creating add-drop links {} {} {} {}", nodeId, numOfDegrees, numOfSrgs, portDirectionEnum);
         List<Link> links = new ArrayList<>();
 
@@ -779,7 +805,7 @@ public class OpenRoadmTopology {
         return links;
     }
 
-    // This method returns the linkBuilder object for given source and destination
+    // This method returns the linkBuilder object for given source and destination.
     public boolean deleteLink(String srcNode, String dstNode, String srcTp, String destTp) {
         LOG.info("deleting link for {}-{}", srcNode, dstNode);
         try {