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