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