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