update portmapping YANG to store SAPI/DAPI hashmap
[transportpce.git] / common / src / main / java / org / opendaylight / transportpce / common / mapping / PortMappingVersion121.java
1 /*
2  * Copyright © 2017 AT&T and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.transportpce.common.mapping;
10
11 import com.google.common.util.concurrent.FluentFuture;
12 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
13 import java.util.ArrayList;
14 import java.util.Collections;
15 import java.util.Comparator;
16 import java.util.HashMap;
17 import java.util.List;
18 import java.util.Map;
19 import java.util.Map.Entry;
20 import java.util.Optional;
21 import java.util.concurrent.ExecutionException;
22 import java.util.stream.Collectors;
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.eclipse.jdt.annotation.Nullable;
25 import org.opendaylight.mdsal.binding.api.DataBroker;
26 import org.opendaylight.mdsal.binding.api.WriteTransaction;
27 import org.opendaylight.mdsal.common.api.CommitInfo;
28 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
29 import org.opendaylight.transportpce.common.StringConstants;
30 import org.opendaylight.transportpce.common.Timeouts;
31 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
32 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
33 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200429.Network;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200429.NetworkBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200429.network.Nodes;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200429.network.NodesBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200429.network.NodesKey;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200429.network.nodes.CpToDegree;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200429.network.nodes.CpToDegreeBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200429.network.nodes.CpToDegreeKey;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200429.network.nodes.Mapping;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200429.network.nodes.MappingBuilder;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200429.network.nodes.MappingKey;
45 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200429.network.nodes.NodeInfo;
46 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200429.network.nodes.NodeInfo.OpenroadmVersion;
47 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev200429.network.nodes.NodeInfoBuilder;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.Direction;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.NodeTypes;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.CircuitPack;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.Port;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.Ports;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.PortsKey;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacksKey;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.ConnectionPorts;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.InterfaceKey;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.ConnectionMap;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Degree;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.DegreeKey;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Info;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Protocols;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroup;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroupKey;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.port.Interfaces;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.InterfaceType;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.OpenROADMOpticalMultiplex;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.OpticalTransport;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.Protocols1;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.Lldp;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.PortConfig;
74 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
75 import org.slf4j.Logger;
76 import org.slf4j.LoggerFactory;
77
78 public class PortMappingVersion121 {
79
80     private static final Logger LOG = LoggerFactory.getLogger(PortMappingVersion121.class);
81
82     private final DataBroker dataBroker;
83     private final DeviceTransactionManager deviceTransactionManager;
84     private final OpenRoadmInterfaces openRoadmInterfaces;
85
86     public PortMappingVersion121(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
87         OpenRoadmInterfaces openRoadmInterfaces) {
88         this.dataBroker = dataBroker;
89         this.deviceTransactionManager = deviceTransactionManager;
90         this.openRoadmInterfaces = openRoadmInterfaces;
91     }
92
93     public boolean createMappingData(String nodeId) {
94         LOG.info("Create Mapping Data for node 1.2.1 {}", nodeId);
95         List<Mapping> portMapList = new ArrayList<>();
96         InstanceIdentifier<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
97         Optional<Info> deviceInfoOptional = this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType
98             .OPERATIONAL, infoIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
99         Info deviceInfo;
100         NodeInfo nodeInfo;
101         if (deviceInfoOptional.isPresent()) {
102             deviceInfo = deviceInfoOptional.get();
103             nodeInfo = createNodeInfo(deviceInfo);
104             if (nodeInfo == null) {
105                 return false;
106             } else {
107                 postPortMapping(nodeId, nodeInfo, null, null);
108             }
109         } else {
110             LOG.warn("Device info subtree is absent for {}", nodeId);
111             return false;
112         }
113
114         switch (deviceInfo.getNodeType()) {
115
116             case Rdm:
117                 // Get TTP port mapping
118                 if (!createTtpPortMapping(nodeId, deviceInfo, portMapList)) {
119                     // return false if mapping creation for TTP's failed
120                     LOG.warn("Unable to create mapping for TTP's on node {}", nodeId);
121                     return false;
122                 }
123
124                 // Get PP port mapping
125                 if (!createPpPortMapping(nodeId, deviceInfo, portMapList)) {
126                     // return false if mapping creation for PP's failed
127                     LOG.warn("Unable to create mapping for PP's on node {}", nodeId);
128                     return false;
129                 }
130                 break;
131             case Xpdr:
132                 if (!createXpdrPortMapping(nodeId, portMapList)) {
133                     LOG.warn("Unable to create mapping for Xponder on node {}", nodeId);
134                     return false;
135                 }
136                 break;
137             default:
138                 LOG.error("Unable to create mapping for node {} : unknown nodetype ", nodeId);
139                 break;
140
141         }
142         return postPortMapping(nodeId, nodeInfo, portMapList, null);
143     }
144
145     public boolean updateMapping(String nodeId, Mapping oldMapping) {
146         InstanceIdentifier<Ports> portIId = InstanceIdentifier.create(OrgOpenroadmDevice.class)
147             .child(CircuitPacks.class, new CircuitPacksKey(oldMapping.getSupportingCircuitPackName()))
148             .child(Ports.class, new PortsKey(oldMapping.getSupportingPort()));
149         if ((oldMapping != null) && (nodeId != null)) {
150             try {
151                 Optional<Ports> portObject = deviceTransactionManager.getDataFromDevice(nodeId,
152                     LogicalDatastoreType.OPERATIONAL, portIId, Timeouts.DEVICE_READ_TIMEOUT,
153                     Timeouts.DEVICE_READ_TIMEOUT_UNIT);
154                 if (portObject.isPresent()) {
155                     Ports port = portObject.get();
156                     Mapping newMapping = createMappingObject(nodeId, port, oldMapping.getSupportingCircuitPackName(),
157                         oldMapping.getLogicalConnectionPoint());
158                     LOG.info("Updating old mapping Data {} for {} of {} by new mapping data {}", oldMapping,
159                         oldMapping.getLogicalConnectionPoint(), nodeId, newMapping);
160                     final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
161                     InstanceIdentifier<Mapping> mapIID = InstanceIdentifier.create(Network.class)
162                         .child(Nodes.class, new NodesKey(nodeId))
163                         .child(Mapping.class, new MappingKey(oldMapping.getLogicalConnectionPoint()));
164                     writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, mapIID, newMapping);
165                     FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
166                     commit.get();
167                     return true;
168                 }
169                 return false;
170             } catch (InterruptedException | ExecutionException e) {
171                 LOG.error("Error updating Mapping {} for node {}", oldMapping.getLogicalConnectionPoint(), nodeId, e);
172                 return false;
173             }
174         } else {
175             LOG.error("Impossible to update mapping");
176             return false;
177         }
178     }
179
180     private boolean createXpdrPortMapping(String nodeId, List<Mapping> portMapList) {
181         // Creating for Xponder Line and Client Ports
182         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
183         Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
184             LogicalDatastoreType.OPERATIONAL, deviceIID,
185             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
186
187         // Variable to keep track of number of line ports
188         int line = 1;
189         // Variable to keep track of number of client ports
190         int client = 1;
191         if (!deviceObject.isPresent() || deviceObject.get().getCircuitPacks() == null) {
192             LOG.warn("Circuit Packs are not present for {}", nodeId);
193             return false;
194             // TODO return false or continue?
195         }
196         Map<String, String> lcpMap = new HashMap<>();
197         Map<String, Mapping> mappingMap = new HashMap<>();
198
199         // com.google.common.collect.ImmutableList implementation of List
200         List<CircuitPacks> circuitPackList = new ArrayList<>(deviceObject.get().getCircuitPacks());
201         circuitPackList.sort(Comparator.comparing(CircuitPack::getCircuitPackName));
202
203         for (CircuitPacks cp : circuitPackList) {
204             String circuitPackName = cp.getCircuitPackName();
205             if (cp.getPorts() == null) {
206                 LOG.warn("Ports were not found for circuit pack: {}", circuitPackName);
207                 continue;
208             }
209
210             // com.google.common.collect.ImmutableList implementation of List
211             List<Ports> portList = new ArrayList<>(cp.getPorts());
212             portList.sort(Comparator.comparing(Ports::getPortName));
213             for (Ports port : portList) {
214                 if (port.getPortQual() == null) {
215                     LOG.warn("PortQual was not found for port {} on circuit pack: {}", port.getPortName(),
216                         circuitPackName);
217                     continue;
218                 }
219                 if (Port.PortQual.XpdrNetwork.getIntValue() == port.getPortQual().getIntValue()
220                     && port.getPortDirection().getIntValue() == Direction.Bidirectional.getIntValue()) {
221                     String lcp = "XPDR1-" + StringConstants.NETWORK_TOKEN + line;
222                     lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp);
223                     mappingMap.put(lcp, createXpdrMappingObject(nodeId, port, circuitPackName, lcp, null, null, null));
224                     line++;
225                 } else if (Port.PortQual.XpdrNetwork.getIntValue() == port.getPortQual().getIntValue()
226                     && port.getPortDirection().getIntValue() != Direction.Bidirectional.getIntValue()
227                     && port.getPartnerPort() != null
228                     && port.getPartnerPort().getCircuitPackName() != null
229                     && port.getPartnerPort().getPortName() != null) {
230                     if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) {
231                         continue;
232                     }
233                     String lcp1 = "XPDR1-" + StringConstants.NETWORK_TOKEN + line;
234                     Optional<CircuitPacks> cpOpt = circuitPackList.stream().filter(cP -> cP.getCircuitPackName()
235                         .equals(port.getPartnerPort().getCircuitPackName())).findFirst();
236                     if (cpOpt.isPresent()) {
237                         Optional<Ports> poOpt = cpOpt.get().getPorts().stream().filter(p -> p.getPortName().equals(port
238                             .getPartnerPort().getPortName().toString())).findFirst();
239                         if (poOpt.isPresent()) {
240                             Ports port2 = poOpt.get();
241                             if ((Direction.Rx.getIntValue() == port.getPortDirection().getIntValue()
242                                 && Direction.Tx.getIntValue() == port2.getPortDirection().getIntValue()
243                                 && port2.getPartnerPort() != null && port2.getPartnerPort().getCircuitPackName() != null
244                                 && port2.getPartnerPort().getPortName() != null
245                                 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
246                                 && port2.getPartnerPort().getPortName().equals(port.getPortName()))
247                                 ||
248                                 (Direction.Tx.getIntValue() == port.getPortDirection().getIntValue()
249                                 && Direction.Rx.getIntValue() == port2.getPortDirection().getIntValue()
250                                 && port2.getPartnerPort() != null && port2.getPartnerPort().getCircuitPackName() != null
251                                 && port2.getPartnerPort().getPortName() != null
252                                 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
253                                 && port2.getPartnerPort().getPortName().equals(port.getPortName()))) {
254                                 String lcp2 = new StringBuilder("XPDR1-").append(StringConstants.NETWORK_TOKEN)
255                                     .append(line + 1).toString();
256                                 if (!lcpMap.containsKey(lcp1) && !lcpMap.containsKey(lcp2)) {
257                                     lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp1);
258                                     lcpMap.put(cpOpt.get().getCircuitPackName() + '+' + port2.getPortName(), lcp2);
259                                     mappingMap.put(lcp1, createXpdrMappingObject(nodeId, port, circuitPackName, lcp1,
260                                         lcp2, null, null));
261                                     mappingMap.put(lcp2, createXpdrMappingObject(nodeId, port2,
262                                         cpOpt.get().getCircuitPackName(), lcp2, lcp1, null, null));
263                                 } else {
264                                     LOG.warn("mapping already exists for {} or {}", lcp1, lcp2);
265                                 }
266                                 line += 2;
267                             } else {
268                                 LOG.error("port {} on {} is not a correct partner port of {} on  {}",
269                                     port2.getPortName(), cpOpt.get().getCircuitPackName(), port.getPortName(),
270                                     circuitPackName);
271                             }
272                         } else {
273                             LOG.error("Error fetching port {} on {} for {}", port.getPartnerPort().getPortName(),
274                                 port.getPartnerPort().getCircuitPackName(), nodeId);
275                         }
276                     } else {
277                         LOG.error("Error fetching circuit-pack {} for {}", port.getPartnerPort().getCircuitPackName(),
278                             nodeId);
279                     }
280                 } else if (Port.PortQual.XpdrClient.getIntValue() == port.getPortQual().getIntValue()) {
281                     String lcp = "XPDR1-" + StringConstants.CLIENT_TOKEN + client;
282                     lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp);
283                     mappingMap.put(lcp, createXpdrMappingObject(nodeId, port, circuitPackName, lcp, null, null, null));
284                     client++;
285                 } else {
286                     LOG.warn("Error in the configuration of port {} of {} for {}", port.getPortName(), circuitPackName,
287                         nodeId);
288                 }
289             }
290         }
291         List<ConnectionMap> connectionMap = deviceObject.get().getConnectionMap();
292         String slcp = null;
293         String dlcp = null;
294         for (ConnectionMap cm : connectionMap) {
295             String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
296             if (lcpMap.containsKey(skey)) {
297                 slcp = lcpMap.get(skey);
298             }
299             String dkey = cm.getDestination().get(0).getCircuitPackName() + "+"
300                 + cm.getDestination().get(0).getPortName();
301             if (lcpMap.containsKey(dkey)) {
302                 dlcp = lcpMap.get(dkey);
303             }
304             if (slcp != null) {
305                 Mapping mapping = mappingMap.get(slcp);
306                 mappingMap.remove(slcp);
307                 portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping, dlcp));
308             } else {
309                 LOG.error("Error in connection-map analysis");
310             }
311         }
312         if (!mappingMap.isEmpty()) {
313             for (Mapping m : mappingMap.values()) {
314                 portMapList.add(m);
315             }
316         }
317         return true;
318     }
319
320     private HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg
321         .CircuitPacks>> getSrgCps(String deviceId, Info ordmInfo) {
322         HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg
323             .CircuitPacks>> cpPerSrg = new HashMap<>();
324         Integer maxSrg;
325         // Get value for max Srg from info subtree, required for iteration
326         // if not present assume to be 20 (temporary)
327         if (ordmInfo.getMaxSrgs() != null) {
328             maxSrg = ordmInfo.getMaxSrgs().toJava();
329         } else {
330             maxSrg = 20;
331         }
332         for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) {
333             List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> srgCps
334                 = new ArrayList<>();
335             LOG.info("Getting Circuitpacks for Srg Number {}", srgCounter);
336             InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
337                 .child(SharedRiskGroup.class, new SharedRiskGroupKey(srgCounter));
338             Optional<SharedRiskGroup> ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
339                 LogicalDatastoreType.OPERATIONAL, srgIID,
340                 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
341             if (ordmSrgObject.isPresent()) {
342                 srgCps.addAll(ordmSrgObject.get().getCircuitPacks());
343                 cpPerSrg.put(ordmSrgObject.get().getSrgNumber().toJava(), srgCps);
344             }
345         }
346         LOG.info("Device {} has {} Srg", deviceId, cpPerSrg.size());
347         return cpPerSrg;
348     }
349
350     //last LOG info message in this method is too long
351     @SuppressWarnings("checkstyle:linelength")
352     private boolean createPpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
353         // Creating mapping data for SRG's PP
354         HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks>> srgCps
355             = getSrgCps(nodeId, deviceInfo);
356
357         for (Entry<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks>> srgCpEntry : srgCps.entrySet()) {
358             List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> cpList =
359                 srgCps.get(srgCpEntry.getKey());
360             List<String> keys = new ArrayList<>();
361             for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks cp : cpList) {
362                 String circuitPackName = cp.getCircuitPackName();
363                 InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
364                     .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName));
365                 Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
366                     LogicalDatastoreType.OPERATIONAL, cpIID,
367                     Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
368
369                 if (!circuitPackObject.isPresent() || (circuitPackObject.get().getPorts() == null)) {
370                     LOG.warn("{} : Circuit pack {} not found or without ports.", nodeId, circuitPackName);
371                     continue;
372                 }
373                 // com.google.common.collect.ImmutableList implementation of List
374                 @Nullable
375                 List<Ports> portList = new ArrayList<>(circuitPackObject.get().getPorts());
376                 Collections.sort(portList, new SortPort121ByName());
377                 int portIndex = 1;
378                 for (Ports port : portList) {
379                     String currentKey = circuitPackName + "-" + port.getPortName();
380                     if (port.getPortQual() == null) {
381                         continue;
382                     } else if (Port.PortQual.RoadmExternal.getIntValue() == port.getPortQual().getIntValue()
383                         && Direction.Bidirectional.getIntValue() == port.getPortDirection().getIntValue()
384                         && !keys.contains(currentKey)) {
385                         String logicalConnectionPoint = createLogicalConnectionPort(port, srgCpEntry.getKey(), portIndex);
386                         LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId, circuitPackName,
387                             port.getPortName(), logicalConnectionPoint);
388                         portMapList.add(createMappingObject(nodeId, port, circuitPackName, logicalConnectionPoint));
389                         portIndex++;
390                         keys.add(currentKey);
391                     } else if (Port.PortQual.RoadmExternal.getIntValue() == port.getPortQual().getIntValue()
392                         && (Direction.Rx.getIntValue() == port.getPortDirection().getIntValue()
393                         || Direction.Tx.getIntValue() == port.getPortDirection().getIntValue())
394                         && !keys.contains(currentKey)
395                         && port.getPartnerPort() != null) {
396                         String logicalConnectionPoint1 = createLogicalConnectionPort(port, srgCpEntry.getKey(),
397                             portIndex);
398                         LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId, circuitPackName,
399                             port.getPortName(), logicalConnectionPoint1);
400                         InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
401                             .child(CircuitPacks.class, new CircuitPacksKey(port.getPartnerPort().getCircuitPackName()))
402                             .child(Ports.class, new PortsKey(port.getPartnerPort().getPortName().toString()));
403                         Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
404                             LogicalDatastoreType.OPERATIONAL, port2ID,
405                             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
406                         if (port2Object.isPresent()
407                             && port2Object.get().getPortQual().getIntValue()
408                                 == Port.PortQual.RoadmExternal.getIntValue()) {
409                             Ports port2 = port2Object.get();
410                             if ((port.getPortDirection().getIntValue() == Direction.Rx.getIntValue()
411                                 && port2.getPortDirection().getIntValue() == Direction.Tx.getIntValue()
412                                 && port2.getPartnerPort() != null
413                                 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
414                                 && port2.getPartnerPort().getPortName().toString().equals(port.getPortName()))
415                                 ||
416                                 (port.getPortDirection().getIntValue() == Direction.Tx.getIntValue()
417                                 && port2.getPortDirection().getIntValue() == Direction.Rx.getIntValue()
418                                 && port2.getPartnerPort() != null
419                                 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
420                                 && port2.getPartnerPort().getPortName().toString().equals(port.getPortName()))) {
421                                 String logicalConnectionPoint2 = createLogicalConnectionPort(port2, srgCpEntry.getKey(),
422                                     portIndex);
423                                 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId, circuitPackName,
424                                     port2.getPortName(), logicalConnectionPoint2);
425                                 portMapList.add(createMappingObject(nodeId, port, circuitPackName,
426                                     logicalConnectionPoint1));
427                                 portMapList.add(createMappingObject(nodeId, port2, port.getPartnerPort()
428                                     .getCircuitPackName(), logicalConnectionPoint2));
429                                 portIndex++;
430                                 keys.add(currentKey);
431                                 keys.add(port.getPartnerPort().getCircuitPackName() + "-" + port2.getPortName());
432                             } else {
433                                 LOG.error("Error with partner port configuration for port {} of  {} - {}",
434                                     port.getPortName(), circuitPackName, nodeId);
435                                 portIndex++;
436                             }
437                         } else {
438                             LOG.error("error getting partner port {} of  {} - {}",
439                                 port.getPartnerPort().getPortName().toString(),
440                                 port.getPartnerPort().getCircuitPackName(), nodeId);
441                             continue;
442                         }
443                     } else {
444                         LOG.info("{} : port {} on {} is not roadm-external or has already been handled. No logicalConnectionPoint assignment for this port.",
445                             nodeId, port.getPortName(), circuitPackName);
446                     }
447                 }
448             }
449         }
450         return true;
451     }
452
453     private String createLogicalConnectionPort(Ports port, int index, int portIndex) {
454         String lcp = null;
455         switch (port.getPortDirection()) {
456             case Tx:
457                 lcp = "SRG" + index + "-PP" + portIndex + "-TX";
458                 break;
459             case Rx:
460                 lcp = "SRG" + index + "-PP" + portIndex + "-RX";
461                 break;
462             case Bidirectional:
463                 lcp = "SRG" + index + "-PP" + portIndex + "-TXRX";
464                 break;
465             default:
466                 LOG.error("Unsupported port direction for port {} : {}", port, port.getPortDirection());
467         }
468         return lcp;
469     }
470
471     private List<Degree> getDegrees(String deviceId, Info ordmInfo) {
472         List<Degree> degrees = new ArrayList<>();
473         Integer maxDegree;
474
475         // Get value for max degree from info subtree, required for iteration
476         // if not present assume to be 20 (temporary)
477         if (ordmInfo.getMaxDegrees() != null) {
478             maxDegree = ordmInfo.getMaxDegrees().toJava();
479         } else {
480             maxDegree = 20;
481         }
482
483         for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
484             LOG.info("Getting Connection ports for Degree Number {}", degreeCounter);
485             InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
486                 .child(Degree.class, new DegreeKey(degreeCounter));
487             Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
488                 LogicalDatastoreType.OPERATIONAL, deviceIID,
489                 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
490             if (ordmDegreeObject.isPresent()) {
491                 degrees.add(ordmDegreeObject.get());
492             }
493         }
494         LOG.info("Device {} has {} degree", deviceId, degrees.size());
495         return degrees;
496     }
497
498     private Map<Integer, List<ConnectionPorts>> getPerDegreePorts(String deviceId, Info ordmInfo) {
499         Map<Integer, List<ConnectionPorts>> conPortMap = new HashMap<>();
500         Integer maxDegree;
501
502         if (ordmInfo.getMaxDegrees() != null) {
503             maxDegree = ordmInfo.getMaxDegrees().toJava();
504         } else {
505             maxDegree = 20;
506         }
507         for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
508             LOG.info("Getting Connection ports for Degree Number {}", degreeCounter);
509             InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
510                 .child(Degree.class, new DegreeKey(degreeCounter));
511             Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
512                 LogicalDatastoreType.OPERATIONAL, deviceIID,
513                 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
514             if (ordmDegreeObject.isPresent()) {
515                 conPortMap.put(degreeCounter, ordmDegreeObject.get().getConnectionPorts());
516             }
517         }
518         LOG.info("Device {} has {} degree", deviceId, conPortMap.size());
519         return conPortMap;
520     }
521
522     private Map<String, String> getEthInterfaceList(String nodeId) {
523         LOG.info("It is calling get ethernet interface");
524         Map<String, String> cpToInterfaceMap = new HashMap<>();
525         InstanceIdentifier<Protocols> protocoliid = InstanceIdentifier.create(OrgOpenroadmDevice.class)
526             .child(Protocols.class);
527         Optional<Protocols> protocolObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
528             LogicalDatastoreType.OPERATIONAL, protocoliid, Timeouts.DEVICE_READ_TIMEOUT,
529             Timeouts.DEVICE_READ_TIMEOUT_UNIT);
530         if (protocolObject.isPresent() && protocolObject.get().augmentation(Protocols1.class).getLldp() != null) {
531             Lldp lldp = protocolObject.get().augmentation(Protocols1.class).getLldp();
532             for (PortConfig portConfig : lldp.getPortConfig()) {
533                 if (portConfig.getAdminStatus().equals(PortConfig.AdminStatus.Txandrx)) {
534                     InstanceIdentifier<Interface> interfaceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
535                         .child(Interface.class, new InterfaceKey(portConfig.getIfName()));
536                     Optional<Interface> interfaceObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
537                         LogicalDatastoreType.OPERATIONAL, interfaceIID, Timeouts.DEVICE_READ_TIMEOUT,
538                         Timeouts.DEVICE_READ_TIMEOUT_UNIT);
539                     if (interfaceObject.isPresent() && (interfaceObject.get().getSupportingCircuitPackName() != null)) {
540                         String supportingCircuitPackName = interfaceObject.get().getSupportingCircuitPackName();
541                         cpToInterfaceMap.put(supportingCircuitPackName, portConfig.getIfName());
542                         InstanceIdentifier<CircuitPacks> circuitPacksIID = InstanceIdentifier
543                             .create(OrgOpenroadmDevice.class)
544                             .child(CircuitPacks.class, new CircuitPacksKey(supportingCircuitPackName));
545                         Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(
546                             nodeId, LogicalDatastoreType.OPERATIONAL, circuitPacksIID, Timeouts.DEVICE_READ_TIMEOUT,
547                             Timeouts.DEVICE_READ_TIMEOUT_UNIT);
548                         if (circuitPackObject.isPresent() && (circuitPackObject.get().getParentCircuitPack() != null)) {
549                             cpToInterfaceMap.put(circuitPackObject.get().getParentCircuitPack().getCircuitPackName(),
550                                 portConfig.getIfName());
551                         }
552                     }
553                 }
554             }
555         } else {
556             LOG.warn("Couldnt find port config under LLDP for Node : {}", nodeId);
557         }
558         LOG.info("Processiong is done.. now returning..");
559         return cpToInterfaceMap;
560     }
561
562     private List<CpToDegree> getCpToDegreeList(List<Degree> degrees, String nodeId,
563         Map<String, String> interfaceList) {
564         List<CpToDegree> cpToDegreeList = new ArrayList<>();
565         for (Degree degree : degrees) {
566             if (degree.getCircuitPacks() != null) {
567                 LOG.info("Inside CP to degree list");
568                 cpToDegreeList.addAll(degree.getCircuitPacks().stream()
569                     .map(cp -> createCpToDegreeObject(cp.getCircuitPackName(),
570                         degree.getDegreeNumber().toString(), nodeId, interfaceList))
571                     .collect(Collectors.toList()));
572             }
573         }
574         return cpToDegreeList;
575     }
576
577     private boolean postPortMapping(String nodeId, NodeInfo nodeInfo, List<Mapping> portMapList,
578         List<CpToDegree> cp2DegreeList) {
579         NodesBuilder nodesBldr = new NodesBuilder();
580         nodesBldr.withKey(new NodesKey(nodeId)).setNodeId(nodeId);
581         if (nodeInfo != null) {
582             nodesBldr.setNodeInfo(nodeInfo);
583         }
584         if (portMapList != null) {
585             nodesBldr.setMapping(portMapList);
586         }
587         if (cp2DegreeList != null) {
588             nodesBldr.setCpToDegree(cp2DegreeList);
589         }
590
591         List<Nodes> nodesList = new ArrayList<>();
592         nodesList.add(nodesBldr.build());
593
594         NetworkBuilder nwBldr = new NetworkBuilder();
595         nwBldr.setNodes(nodesList);
596
597         final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
598         InstanceIdentifier<Network> nodesIID = InstanceIdentifier.builder(Network.class).build();
599         Network network = nwBldr.build();
600         writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodesIID, network);
601         FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
602         try {
603             commit.get();
604             return true;
605
606         } catch (InterruptedException | ExecutionException e) {
607             LOG.warn("Failed to post {}", network, e);
608             return false;
609         }
610     }
611
612     private CpToDegree createCpToDegreeObject(String circuitPackName, String degreeNumber, String nodeId,
613         Map<String, String> interfaceList) {
614         String interfaceName = null;
615         if (interfaceList.get(circuitPackName) != null) {
616             interfaceName = interfaceList.get(circuitPackName);
617         }
618         return new CpToDegreeBuilder().withKey(new CpToDegreeKey(circuitPackName)).setCircuitPackName(circuitPackName)
619             .setDegreeNumber(Long.valueOf(degreeNumber)).setInterfaceName(interfaceName).build();
620     }
621
622     private Mapping createMappingObject(String nodeId, Ports port, String circuitPackName,
623         String logicalConnectionPoint) {
624         MappingBuilder mpBldr = new MappingBuilder();
625         mpBldr.withKey(new MappingKey(logicalConnectionPoint)).setLogicalConnectionPoint(logicalConnectionPoint)
626             .setSupportingCircuitPackName(circuitPackName).setSupportingPort(port.getPortName())
627             .setPortDirection(port.getPortDirection().getName());
628
629         // Get OMS and OTS interface provisioned on the TTP's
630         if (logicalConnectionPoint.contains(StringConstants.TTP_TOKEN) && (port.getInterfaces() != null)) {
631             for (Interfaces interfaces : port.getInterfaces()) {
632                 try {
633                     Optional<Interface> openRoadmInterface = this.openRoadmInterfaces.getInterface(nodeId,
634                         interfaces.getInterfaceName());
635                     if (openRoadmInterface.isPresent()) {
636                         Class<? extends InterfaceType> interfaceType
637                             = (Class<? extends InterfaceType>) openRoadmInterface.get().getType();
638                         // Check if interface type is OMS or OTS
639                         if (interfaceType.equals(OpenROADMOpticalMultiplex.class)) {
640                             mpBldr.setSupportingOms(interfaces.getInterfaceName());
641                         }
642                         if (interfaceType.equals(OpticalTransport.class)) {
643                             mpBldr.setSupportingOts(interfaces.getInterfaceName());
644                         }
645                     } else {
646                         LOG.warn("Interface {} from node {} was null!", interfaces.getInterfaceName(), nodeId);
647                     }
648                 } catch (OpenRoadmInterfaceException ex) {
649                     LOG.warn("Error while getting interface {} from node {}!", interfaces.getInterfaceName(), nodeId,
650                         ex);
651                 }
652             }
653         }
654         return mpBldr.build();
655     }
656
657     private Mapping createXpdrMappingObject(String nodeId, Ports port, String circuitPackName,
658         String logicalConnectionPoint, String partnerLcp, Mapping mapping, String assoLcp) {
659         MappingBuilder mpBldr;
660         if (mapping != null && assoLcp != null) {
661             // update existing mapping
662             mpBldr = new MappingBuilder(mapping);
663             mpBldr.setConnectionMapLcp(assoLcp);
664         } else {
665             // create a new mapping
666             mpBldr = new MappingBuilder();
667             mpBldr.withKey(new MappingKey(logicalConnectionPoint))
668                 .setLogicalConnectionPoint(logicalConnectionPoint)
669                 .setSupportingCircuitPackName(circuitPackName)
670                 .setSupportingPort(port.getPortName())
671                 .setPortDirection(port.getPortDirection().getName());
672             if (port.getPortQual() != null) {
673                 mpBldr.setPortQual(port.getPortQual().getName());
674             }
675             if (partnerLcp != null) {
676                 mpBldr.setPartnerLcp(partnerLcp);
677             }
678         }
679         return mpBldr.build();
680     }
681
682     // some LOG messages are too long
683     @SuppressWarnings("checkstyle:linelength")
684     @SuppressFBWarnings("DM_CONVERT_CASE")
685     private boolean createTtpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
686         // Creating mapping data for degree TTP's
687         List<Degree> degrees = getDegrees(nodeId, deviceInfo);
688         Map<String, String> interfaceList = getEthInterfaceList(nodeId);
689         List<CpToDegree> cpToDegreeList = getCpToDegreeList(degrees, nodeId, interfaceList);
690         LOG.info("Map looks like this {}", interfaceList);
691         postPortMapping(nodeId, null, null, cpToDegreeList);
692
693         Map<Integer, List<ConnectionPorts>> connectionPortMap = getPerDegreePorts(nodeId, deviceInfo);
694         for (Entry<Integer, List<ConnectionPorts>> cpMapEntry : connectionPortMap.entrySet()) {
695             switch (connectionPortMap.get(cpMapEntry.getKey()).size()) {
696                 case 1:
697                     // port is bidirectional
698                     InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
699                         .child(CircuitPacks.class, new CircuitPacksKey(connectionPortMap.get(cpMapEntry.getKey()).get(0)
700                             .getCircuitPackName()))
701                         .child(Ports.class, new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(0)
702                             .getPortName().toString()));
703                     LOG.info("Fetching connection-port {} at circuit pack {}", connectionPortMap
704                         .get(cpMapEntry.getKey()).get(0).getPortName().toString(), connectionPortMap
705                         .get(cpMapEntry.getKey()).get(0).getCircuitPackName());
706                     Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
707                         LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
708                         Timeouts.DEVICE_READ_TIMEOUT_UNIT);
709                     if (portObject.isPresent()) {
710                         Ports port = portObject.get();
711                         if (port.getPortQual() == null) {
712                             continue;
713                         } else if (Port.PortQual.RoadmExternal.getIntValue() == port.getPortQual().getIntValue()
714                             && Direction.Bidirectional.getIntValue() == port.getPortDirection().getIntValue()) {
715                             String logicalConnectionPoint = new StringBuilder("DEG").append(cpMapEntry.getKey())
716                                 .append("-TTP-TXRX").toString();
717                             LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId,
718                                 connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName(),
719                                 port.getPortName(), logicalConnectionPoint);
720                             portMapList.add(createMappingObject(nodeId, port,
721                                 connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName(),
722                                 logicalConnectionPoint));
723                         } else {
724                             LOG.error(
725                                 "Impossible to create logical connection point for port {} of {} on node {} - Error in configuration with port-qual or port-direction",
726                                 port.getPortName(), connectionPortMap
727                                 .get(cpMapEntry.getKey()).get(0).getCircuitPackName(), nodeId);
728                         }
729                     } else {
730                         LOG.error("No port {} on circuit pack {} for node {}",
731                             connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName().toString(),
732                             connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName(), nodeId);
733                         return false;
734                     }
735                     break;
736                 case 2:
737                     // ports are unidirectionals
738                     String cp1Name = connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName();
739                     String cp2Name = connectionPortMap.get(cpMapEntry.getKey()).get(1).getCircuitPackName();
740                     InstanceIdentifier<Ports> port1ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
741                         .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
742                         .child(Ports.class, new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName()
743                             .toString()));
744                     LOG.info("Fetching connection-port {} at circuit pack {}", connectionPortMap
745                         .get(cpMapEntry.getKey()).get(0).getPortName().toString(), cp1Name);
746                     Optional<Ports> port1Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
747                         LogicalDatastoreType.OPERATIONAL, port1ID, Timeouts.DEVICE_READ_TIMEOUT,
748                         Timeouts.DEVICE_READ_TIMEOUT_UNIT);
749                     InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
750                         .child(CircuitPacks.class, new CircuitPacksKey(cp2Name))
751                         .child(Ports.class, new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName()
752                             .toString()));
753                     LOG.info("Fetching connection-port {} at circuit pack {}",
754                         connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName().toString(), cp2Name);
755                     Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
756                         LogicalDatastoreType.OPERATIONAL, port2ID, Timeouts.DEVICE_READ_TIMEOUT,
757                         Timeouts.DEVICE_READ_TIMEOUT_UNIT);
758                     if (port1Object.isPresent() && port2Object.isPresent()) {
759                         Ports port1 = port1Object.get();
760                         Ports port2 = port2Object.get();
761                         if (port1.getPortQual() == null || port2.getPortQual() == null) {
762                             continue;
763                         } else if ((Port.PortQual.RoadmExternal.getIntValue() == port1.getPortQual().getIntValue()
764                                 && Port.PortQual.RoadmExternal.getIntValue() == port2.getPortQual().getIntValue()
765                                 && Direction.Rx.getIntValue() == port1.getPortDirection().getIntValue()
766                                 && Direction.Tx.getIntValue() == port2.getPortDirection().getIntValue()
767                                 && port1.getPartnerPort() != null && port2.getPartnerPort() != null
768                                 && port1.getPartnerPort().getCircuitPackName().equals(cp2Name)
769                                 && port1.getPartnerPort().getPortName().equals(port2.getPortName())
770                                 && port2.getPartnerPort().getCircuitPackName().equals(cp1Name)
771                                 && port2.getPartnerPort().getPortName().equals(port1.getPortName()))
772                                 ||
773                                 (Port.PortQual.RoadmExternal.getIntValue() == port1.getPortQual().getIntValue()
774                                 && Port.PortQual.RoadmExternal.getIntValue() == port2.getPortQual().getIntValue()
775                                 && Direction.Rx.getIntValue() == port2.getPortDirection().getIntValue()
776                                 && Direction.Tx.getIntValue() == port1.getPortDirection().getIntValue()
777                                 && port1.getPartnerPort() != null && port2.getPartnerPort() != null
778                                 && port1.getPartnerPort().getCircuitPackName().equals(cp2Name)
779                                 && port1.getPartnerPort().getPortName().equals(port2.getPortName())
780                                 && port2.getPartnerPort().getCircuitPackName().equals(cp1Name)
781                                 && port2.getPartnerPort().getPortName().equals(port1.getPortName()))) {
782                             String logicalConnectionPoint1 = new StringBuilder("DEG").append(cpMapEntry.getKey())
783                                 .append("-TTP-").append(port1.getPortDirection().getName().toUpperCase()).toString();
784                             LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId,
785                                 connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName(),
786                                 port1.getPortName(), logicalConnectionPoint1);
787                             portMapList.add(createMappingObject(nodeId, port1, connectionPortMap
788                                 .get(cpMapEntry.getKey()).get(0).getCircuitPackName(), logicalConnectionPoint1));
789                             String logicalConnectionPoint2 = new StringBuilder("DEG").append(cpMapEntry.getKey())
790                                 .append("-TTP-").append(port2.getPortDirection().getName().toUpperCase()).toString();
791                             LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId,
792                                 connectionPortMap.get(cpMapEntry.getKey()).get(1).getCircuitPackName(),
793                                 port2.getPortName(), logicalConnectionPoint2);
794                             portMapList.add(createMappingObject(nodeId, port2, connectionPortMap
795                                 .get(cpMapEntry.getKey()).get(1).getCircuitPackName(), logicalConnectionPoint2));
796                         } else {
797                             LOG.error(
798                                 "Impossible to create logical connection point for port {} or port {} on node {} - Error in configuration with port-qual, port-direction or partner-port configuration",
799                                 port1.getPortName(), port2.getPortName(), nodeId);
800                         }
801                     } else {
802                         LOG.error("No port {} on circuit pack {} for node {}",
803                             connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName().toString(),
804                             connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName(), nodeId);
805                         return false;
806                     }
807
808                     break;
809                 default:
810                     LOG.error("Number of connection port for DEG{} on {} is incorrect", cpMapEntry.getKey(), nodeId);
811                     continue;
812             }
813         }
814         return true;
815     }
816
817     private NodeInfo createNodeInfo(Info deviceInfo) {
818         NodeInfoBuilder nodeInfoBldr = new NodeInfoBuilder();
819         if (deviceInfo.getNodeType() != null) {
820             nodeInfoBldr.setOpenroadmVersion(OpenroadmVersion._121);
821             if (deviceInfo.getNodeType().getIntValue() == 1) {
822                 nodeInfoBldr.setNodeType(NodeTypes.Rdm);
823             } else if (deviceInfo.getNodeType().getIntValue() == 2) {
824                 nodeInfoBldr.setNodeType(NodeTypes.Xpdr);
825             } else {
826                 LOG.error("Error with node-type of {}", deviceInfo.getNodeId());
827             }
828             if (deviceInfo.getClli() != null && !deviceInfo.getClli().isEmpty()) {
829                 nodeInfoBldr.setNodeClli(deviceInfo.getClli());
830             } else {
831                 nodeInfoBldr.setNodeClli("defaultCLLI");
832             }
833             if (deviceInfo.getModel() != null) {
834                 nodeInfoBldr.setNodeModel(deviceInfo.getModel());
835             }
836             if (deviceInfo.getVendor() != null) {
837                 nodeInfoBldr.setNodeVendor(deviceInfo.getVendor());
838             }
839             if (deviceInfo.getIpAddress() != null) {
840                 nodeInfoBldr.setNodeIpAddress(deviceInfo.getIpAddress());
841             }
842         } else {
843          // TODO make mandatory in yang
844             LOG.error("Node type field is missing");
845             return null;
846         }
847         return nodeInfoBldr.build();
848     }
849
850 }