fix some AsyncWriteTransaction.submit warnings
[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.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.opendaylight.controller.md.sal.binding.api.DataBroker;
23 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
24 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
25 import org.opendaylight.mdsal.common.api.CommitInfo;
26 import org.opendaylight.transportpce.common.StringConstants;
27 import org.opendaylight.transportpce.common.Timeouts;
28 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
29 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
30 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.Network;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.NetworkBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.Nodes;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.NodesBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.NodesKey;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.CpToDegree;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.CpToDegreeBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.CpToDegreeKey;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.Mapping;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.MappingBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.MappingKey;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.NodeInfo;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.NodeInfo.OpenroadmVersion;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.NodeInfoBuilder;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.Direction;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.Port;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.CircuitPack;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.pack.Ports;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.pack.PortsKey;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.packs.CircuitPacks;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.packs.CircuitPacksKey;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.degree.ConnectionPorts;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.Interface;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.InterfaceKey;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.OrgOpenroadmDevice;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.ConnectionMap;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.Degree;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.DegreeKey;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.Info;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.Protocols;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.SharedRiskGroup;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.SharedRiskGroupKey;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.port.Interfaces;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.InterfaceType;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.OpenROADMOpticalMultiplex;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.OpticalTransport;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.Protocols1;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.Lldp;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.lldp.PortConfig;
70 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
71 import org.slf4j.Logger;
72 import org.slf4j.LoggerFactory;
73
74 public class PortMappingVersion221 {
75     private static final Logger LOG = LoggerFactory.getLogger(PortMappingImpl.class);
76
77     private final DataBroker dataBroker;
78     private final DeviceTransactionManager deviceTransactionManager;
79     private final OpenRoadmInterfaces openRoadmInterfaces;
80
81     public PortMappingVersion221(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
82         OpenRoadmInterfaces openRoadmInterfaces) {
83         this.dataBroker = dataBroker;
84         this.deviceTransactionManager = deviceTransactionManager;
85         this.openRoadmInterfaces = openRoadmInterfaces;
86     }
87
88     public boolean createMappingData(String nodeId) {
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                     FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
161                     commit.get();
162                     return true;
163                 }
164                 return false;
165             } catch (InterruptedException | ExecutionException e) {
166                 LOG.error("Error updating Mapping {} for node {}", oldMapping.getLogicalConnectionPoint(), nodeId, e);
167                 return false;
168             }
169         } else {
170             LOG.error("Impossible to update mapping");
171             return false;
172         }
173     }
174
175     private boolean createXpdrPortMapping(String nodeId, List<Mapping> portMapList) {
176         // Creating for Xponder Line and Client Ports
177         InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
178         Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
179             LogicalDatastoreType.OPERATIONAL, deviceIID,
180             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
181
182         // Variable to keep track of number of line ports
183         int line = 1;
184         // Variable to keep track of number of client ports
185         int client = 1;
186         if (!deviceObject.isPresent() || deviceObject.get().getCircuitPacks() == null) {
187             LOG.warn("Circuit Packs are not present for {}", nodeId);
188             return false;
189             // 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     //last LOG info message in this method is too long
343     @SuppressWarnings("checkstyle:linelength")
344     private boolean createPpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
345         // Creating mapping data for SRG's PP
346         HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks>> srgCps
347             = getSrgCps(nodeId, deviceInfo);
348
349         for (Integer k : srgCps.keySet()) {
350             List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks> cpList =
351                 srgCps.get(k);
352             List<String> keys = new ArrayList<>();
353             for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks cp : cpList) {
354                 String circuitPackName = cp.getCircuitPackName();
355                 InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
356                     .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName));
357                 Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
358                     LogicalDatastoreType.OPERATIONAL, cpIID,
359                     Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
360
361                 if (!circuitPackObject.isPresent() || (circuitPackObject.get().getPorts() == null)) {
362                     LOG.warn("{} : Circuit pack {} not found or without ports.", nodeId, circuitPackName);
363                     continue;
364                 }
365                 List<Ports> portList = circuitPackObject.get().getPorts();
366                 Collections.sort(portList, new SortPort221ByName());
367                 int portIndex = 1;
368                 for (Ports port : portList) {
369                     String currentKey = circuitPackName + "-" + port.getPortName();
370                     if (port.getPortQual() == null) {
371                         continue;
372                     } else if (Port.PortQual.RoadmExternal.getIntValue() == port.getPortQual().getIntValue()
373                         && Direction.Bidirectional.getIntValue() == port.getPortDirection().getIntValue()
374                         && !keys.contains(currentKey)) {
375                         String logicalConnectionPoint = createLogicalConnectionPort(port, k, portIndex);
376                         LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId, circuitPackName,
377                             port.getPortName(), logicalConnectionPoint);
378                         portMapList.add(createMappingObject(nodeId, port, circuitPackName, logicalConnectionPoint));
379                         portIndex++;
380                         keys.add(currentKey);
381                     } else if (Port.PortQual.RoadmExternal.getIntValue() == port.getPortQual().getIntValue()
382                         && (Direction.Rx.getIntValue() == port.getPortDirection().getIntValue()
383                         || Direction.Tx.getIntValue() == port.getPortDirection().getIntValue())
384                         && !keys.contains(currentKey)
385                         && port.getPartnerPort() != null) {
386                         String logicalConnectionPoint1 = createLogicalConnectionPort(port, k, portIndex);
387                         LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId, circuitPackName,
388                             port.getPortName(), logicalConnectionPoint1);
389                         InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
390                             .child(CircuitPacks.class, new CircuitPacksKey(port.getPartnerPort().getCircuitPackName()))
391                             .child(Ports.class, new PortsKey(port.getPartnerPort().getPortName().toString()));
392                         Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
393                             LogicalDatastoreType.OPERATIONAL, port2ID,
394                             Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
395                         if (port2Object.isPresent()
396                             && port2Object.get().getPortQual().getIntValue()
397                                 == Port.PortQual.RoadmExternal.getIntValue()) {
398                             Ports port2 = port2Object.get();
399                             if ((port.getPortDirection().getIntValue() == Direction.Rx.getIntValue()
400                                 && port2.getPortDirection().getIntValue() == Direction.Tx.getIntValue()
401                                 && port2.getPartnerPort() != null
402                                 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
403                                 && port2.getPartnerPort().getPortName().toString().equals(port.getPortName()))
404                                 ||
405                                 (port.getPortDirection().getIntValue() == Direction.Tx.getIntValue()
406                                 && port2.getPortDirection().getIntValue() == Direction.Rx.getIntValue()
407                                 && port2.getPartnerPort() != null
408                                 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
409                                 && port2.getPartnerPort().getPortName().toString().equals(port.getPortName()))) {
410                                 String logicalConnectionPoint2 = createLogicalConnectionPort(port2, k, portIndex);
411                                 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId, circuitPackName,
412                                     port2.getPortName(), logicalConnectionPoint2);
413                                 portMapList.add(createMappingObject(nodeId, port, circuitPackName,
414                                     logicalConnectionPoint1));
415                                 portMapList.add(createMappingObject(nodeId,port2,
416                                     port.getPartnerPort().getCircuitPackName(), logicalConnectionPoint2));
417                                 portIndex++;
418                                 keys.add(currentKey);
419                                 keys.add(port.getPartnerPort().getCircuitPackName() + "-" + port2.getPortName());
420                             } else {
421                                 LOG.error("Error with partner port configuration for port {} of  {} - {}",
422                                     port.getPortName(), circuitPackName, nodeId);
423                                 portIndex++;
424                             }
425                         } else {
426                             LOG.error("error getting partner port {} of  {} - {}", port.getPartnerPort().getPortName()
427                                 .toString(), port.getPartnerPort().getCircuitPackName(), nodeId);
428                             continue;
429                         }
430                     } else {
431                         LOG.info("{} : port {} on {} is not roadm-external or has already been handled. No logicalConnectionPoint assignment for this port.",
432                             nodeId, port.getPortName(), circuitPackName);
433                     }
434                 }
435             }
436         }
437         return true;
438     }
439
440     private String createLogicalConnectionPort(Ports port, int index, int portIndex) {
441         String lcp = null;
442         switch (port.getPortDirection()) {
443             case Tx:
444                 lcp = "SRG" + index + "-PP" + portIndex + "-TX";
445                 break;
446             case Rx:
447                 lcp = "SRG" + index + "-PP" + portIndex + "-RX";
448                 break;
449             case Bidirectional:
450                 lcp = "SRG" + index + "-PP" + portIndex + "-TXRX";
451                 break;
452             default:
453                 LOG.error("Unsupported port direction for port {} : {}", port, port.getPortDirection());
454         }
455         return lcp;
456     }
457
458     private List<Degree> getDegrees(String deviceId, Info ordmInfo) {
459         List<Degree> degrees = new ArrayList<>();
460         Integer maxDegree;
461
462         // Get value for max degree from info subtree, required for iteration
463         // if not present assume to be 20 (temporary)
464         if (ordmInfo.getMaxDegrees() != null) {
465             maxDegree = ordmInfo.getMaxDegrees();
466         } else {
467             maxDegree = 20;
468         }
469
470         for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
471             LOG.info("Getting Connection ports for Degree Number {}", degreeCounter);
472             InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
473                 .child(Degree.class, new DegreeKey(degreeCounter));
474             Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
475                 LogicalDatastoreType.OPERATIONAL, deviceIID,
476                 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
477             if (ordmDegreeObject.isPresent()) {
478                 degrees.add(ordmDegreeObject.get());
479             }
480         }
481         LOG.info("Device {} has {} degree", degrees.size());
482         return degrees;
483     }
484
485     private Map<Integer, List<ConnectionPorts>> getPerDegreePorts(String deviceId, Info ordmInfo) {
486         Map<Integer, List<ConnectionPorts>> conPortMap = new HashMap<>();
487         Integer maxDegree;
488
489         if (ordmInfo.getMaxDegrees() != null) {
490             maxDegree = ordmInfo.getMaxDegrees();
491         } else {
492             maxDegree = 20;
493         }
494         for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
495             LOG.info("Getting Connection ports for Degree Number {}", degreeCounter);
496             InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
497                 .child(Degree.class, new DegreeKey(degreeCounter));
498             Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
499                 LogicalDatastoreType.OPERATIONAL, deviceIID,
500                 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
501             if (ordmDegreeObject.isPresent()) {
502                 conPortMap.put(degreeCounter, ordmDegreeObject.get().getConnectionPorts());
503             }
504         }
505         LOG.info("Device {} has {} degree", deviceId, conPortMap.size());
506         return conPortMap;
507     }
508
509     private Map<String, String> getEthInterfaceList(String nodeId) {
510         LOG.info("It is calling get ethernet interface");
511         Map<String, String> cpToInterfaceMap = new HashMap<>();
512         InstanceIdentifier<Protocols> protocoliid = InstanceIdentifier.create(OrgOpenroadmDevice.class)
513             .child(Protocols.class);
514         Optional<Protocols> protocolObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
515             LogicalDatastoreType.OPERATIONAL, protocoliid, Timeouts.DEVICE_READ_TIMEOUT,
516             Timeouts.DEVICE_READ_TIMEOUT_UNIT);
517         if (protocolObject.isPresent() && protocolObject.get().augmentation(Protocols1.class).getLldp() != null) {
518             Lldp lldp = protocolObject.get().augmentation(Protocols1.class).getLldp();
519             for (PortConfig portConfig : lldp.getPortConfig()) {
520                 if (portConfig.getAdminStatus().equals(PortConfig.AdminStatus.Txandrx)) {
521                     InstanceIdentifier<Interface> interfaceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
522                         .child(Interface.class, new InterfaceKey(portConfig.getIfName()));
523                     Optional<Interface> interfaceObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
524                         LogicalDatastoreType.OPERATIONAL, interfaceIID, Timeouts.DEVICE_READ_TIMEOUT,
525                         Timeouts.DEVICE_READ_TIMEOUT_UNIT);
526                     if (interfaceObject.isPresent() && (interfaceObject.get().getSupportingCircuitPackName() != null)) {
527                         String supportingCircuitPackName = interfaceObject.get().getSupportingCircuitPackName();
528                         cpToInterfaceMap.put(supportingCircuitPackName, portConfig.getIfName());
529                         InstanceIdentifier<CircuitPacks> circuitPacksIID = InstanceIdentifier
530                             .create(OrgOpenroadmDevice.class)
531                             .child(CircuitPacks.class, new CircuitPacksKey(supportingCircuitPackName));
532                         Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(
533                             nodeId, LogicalDatastoreType.OPERATIONAL, circuitPacksIID, Timeouts.DEVICE_READ_TIMEOUT,
534                             Timeouts.DEVICE_READ_TIMEOUT_UNIT);
535                         if (circuitPackObject.isPresent() && (circuitPackObject.get().getParentCircuitPack() != null)) {
536                             cpToInterfaceMap.put(circuitPackObject.get().getParentCircuitPack().getCircuitPackName(),
537                                 portConfig.getIfName());
538                         }
539                     }
540                 }
541             }
542         } else {
543             LOG.warn("Couldnt find port config under LLDP for Node : {}", nodeId);
544         }
545         LOG.info("Processiong is done.. now returning..");
546         return cpToInterfaceMap;
547     }
548
549     private List<CpToDegree> getCpToDegreeList(List<Degree> degrees, String nodeId,
550         Map<String, String> interfaceList) {
551         List<CpToDegree> cpToDegreeList = new ArrayList<>();
552         for (Degree degree : degrees) {
553             if (degree.getCircuitPacks() != null) {
554                 LOG.info("Inside CP to degree list");
555                 cpToDegreeList.addAll(degree.getCircuitPacks().stream()
556                     .map(cp -> createCpToDegreeObject(cp.getCircuitPackName(),
557                         degree.getDegreeNumber().toString(), nodeId, interfaceList))
558                     .collect(Collectors.toList()));
559             }
560         }
561         return cpToDegreeList;
562     }
563
564     private boolean postPortMapping(String nodeId, NodeInfo nodeInfo, List<Mapping> portMapList,
565         List<CpToDegree> cp2DegreeList) {
566         NodesBuilder nodesBldr = new NodesBuilder();
567         nodesBldr.withKey(new NodesKey(nodeId)).setNodeId(nodeId);
568         if (nodeInfo != null) {
569             nodesBldr.setNodeInfo(nodeInfo);
570         }
571         if (portMapList != null) {
572             nodesBldr.setMapping(portMapList);
573         }
574         if (cp2DegreeList != null) {
575             nodesBldr.setCpToDegree(cp2DegreeList);
576         }
577
578         List<Nodes> nodesList = new ArrayList<>();
579         nodesList.add(nodesBldr.build());
580
581         NetworkBuilder nwBldr = new NetworkBuilder();
582         nwBldr.setNodes(nodesList);
583
584         final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
585         InstanceIdentifier<Network> nodesIID = InstanceIdentifier.builder(Network.class).build();
586         Network network = nwBldr.build();
587         writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodesIID, network);
588         FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
589         try {
590             commit.get();
591             return true;
592
593         } catch (InterruptedException | ExecutionException e) {
594             LOG.warn("Failed to post {}", network, e);
595             return false;
596         }
597     }
598
599     private CpToDegree createCpToDegreeObject(String circuitPackName, String degreeNumber, String nodeId,
600         Map<String, String> interfaceList) {
601         String interfaceName = null;
602         if (interfaceList.get(circuitPackName) != null) {
603             interfaceName = interfaceList.get(circuitPackName);
604         }
605         return new CpToDegreeBuilder().withKey(new CpToDegreeKey(circuitPackName)).setCircuitPackName(circuitPackName)
606             .setDegreeNumber(new Long(degreeNumber)).setInterfaceName(interfaceName).build();
607     }
608
609     private Mapping createMappingObject(String nodeId, Ports port, String circuitPackName,
610         String logicalConnectionPoint) {
611         MappingBuilder mpBldr = new MappingBuilder();
612         mpBldr.withKey(new MappingKey(logicalConnectionPoint)).setLogicalConnectionPoint(logicalConnectionPoint)
613             .setSupportingCircuitPackName(circuitPackName).setSupportingPort(port.getPortName())
614             .setPortDirection(port.getPortDirection().getName());
615
616         // Get OMS and OTS interface provisioned on the TTP's
617         if (logicalConnectionPoint.contains(StringConstants.TTP_TOKEN) && (port.getInterfaces() != null)) {
618             for (Interfaces interfaces : port.getInterfaces()) {
619                 try {
620                     Optional<Interface> openRoadmInterface = this.openRoadmInterfaces.getInterface(nodeId,
621                         interfaces.getInterfaceName());
622                     if (openRoadmInterface.isPresent()) {
623                         Class<? extends InterfaceType> interfaceType
624                             = (Class<? extends InterfaceType>) openRoadmInterface.get().getType();
625                         // Check if interface type is OMS or OTS
626                         if (interfaceType.equals(OpenROADMOpticalMultiplex.class)) {
627                             mpBldr.setSupportingOms(interfaces.getInterfaceName());
628                         }
629                         if (interfaceType.equals(OpticalTransport.class)) {
630                             mpBldr.setSupportingOts(interfaces.getInterfaceName());
631                         }
632                     } else {
633                         LOG.warn("Interface {} from node {} was null!", interfaces.getInterfaceName(), nodeId);
634                     }
635                 } catch (OpenRoadmInterfaceException ex) {
636                     LOG.warn("Error while getting interface {} from node {}!", interfaces.getInterfaceName(), nodeId,
637                         ex);
638                 }
639             }
640         }
641         return mpBldr.build();
642     }
643
644     private Mapping createXpdrMappingObject(String nodeId, Ports port, String circuitPackName,
645         String logicalConnectionPoint, String partnerLcp, Mapping mapping, String assoLcp) {
646         MappingBuilder mpBldr;
647         if (mapping != null && assoLcp != null) {
648             // update existing mapping
649             mpBldr = new MappingBuilder(mapping);
650             mpBldr.setAssociatedLcp(assoLcp);
651         } else {
652             // create a new mapping
653             mpBldr = new MappingBuilder();
654             mpBldr.withKey(new MappingKey(logicalConnectionPoint))
655                 .setLogicalConnectionPoint(logicalConnectionPoint)
656                 .setSupportingCircuitPackName(circuitPackName)
657                 .setSupportingPort(port.getPortName())
658                 .setPortDirection(port.getPortDirection().getName());
659             if (port.getPortQual() != null) {
660                 mpBldr.setPortQual(port.getPortQual().getName());
661             }
662             if (partnerLcp != null) {
663                 mpBldr.setPartnerLcp(partnerLcp);
664             }
665         }
666         return mpBldr.build();
667     }
668
669     //some LOG messages are too long
670     @SuppressWarnings("checkstyle:linelength")
671     private boolean createTtpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
672         // Creating mapping data for degree TTP's
673         List<Degree> degrees = getDegrees(nodeId, deviceInfo);
674         Map<String, String> interfaceList = getEthInterfaceList(nodeId);
675         List<CpToDegree> cpToDegreeList = getCpToDegreeList(degrees, nodeId, interfaceList);
676         LOG.info("Map looks like this {}", interfaceList);
677         postPortMapping(nodeId, null, null, cpToDegreeList);
678
679         Map<Integer, List<ConnectionPorts>> connectionPortMap = getPerDegreePorts(nodeId, deviceInfo);
680         for (Integer k : connectionPortMap.keySet()) {
681             switch (connectionPortMap.get(k).size()) {
682                 case 1:
683                     // port is bidirectional
684                     InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
685                         .child(CircuitPacks.class, new CircuitPacksKey(connectionPortMap.get(k).get(0)
686                             .getCircuitPackName()))
687                         .child(Ports.class, new PortsKey(connectionPortMap.get(k).get(0)
688                             .getPortName().toString()));
689                     LOG.info("Fetching connection-port {} at circuit pack {}", connectionPortMap.get(k).get(0)
690                         .getPortName().toString(), connectionPortMap.get(k).get(0).getCircuitPackName());
691                     Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
692                         LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
693                         Timeouts.DEVICE_READ_TIMEOUT_UNIT);
694                     if (portObject.isPresent()) {
695                         Ports port = portObject.get();
696                         if (port.getPortQual() == null) {
697                             continue;
698                         } else if (Port.PortQual.RoadmExternal.getIntValue() == port.getPortQual().getIntValue()
699                             && Direction.Bidirectional.getIntValue() == port.getPortDirection().getIntValue()) {
700                             String logicalConnectionPoint = new StringBuilder("DEG").append(k).append("-TTP-TXRX")
701                                 .toString();
702                             LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId,
703                                 connectionPortMap.get(k).get(0).getCircuitPackName(), port.getPortName(),
704                                 logicalConnectionPoint);
705                             portMapList.add(createMappingObject(nodeId, port,
706                                 connectionPortMap.get(k).get(0).getCircuitPackName(), logicalConnectionPoint));
707                         } else {
708                             LOG.error(
709                                 "Impossible to create logical connection point for port {} of {} on node {} - Error in configuration with port-qual or port-direction",
710                                 port.getPortName(), connectionPortMap.get(k).get(0).getCircuitPackName(), nodeId);
711                         }
712                     } else {
713                         LOG.error("No port {} on circuit pack {} for node {}",
714                             connectionPortMap.get(k).get(0).getPortName().toString(),
715                             connectionPortMap.get(k).get(0).getCircuitPackName(), nodeId);
716                         return false;
717                     }
718                     break;
719                 case 2:
720                     // ports are unidirectionals
721                     String cp1Name = connectionPortMap.get(k).get(0).getCircuitPackName();
722                     String cp2Name = connectionPortMap.get(k).get(1).getCircuitPackName();
723                     InstanceIdentifier<Ports> port1ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
724                         .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
725                         .child(Ports.class, new PortsKey(connectionPortMap.get(k).get(0).getPortName().toString()));
726                     LOG.info("Fetching connection-port {} at circuit pack {}", connectionPortMap.get(k).get(0)
727                         .getPortName().toString(), cp1Name);
728                     Optional<Ports> port1Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
729                         LogicalDatastoreType.OPERATIONAL, port1ID, Timeouts.DEVICE_READ_TIMEOUT,
730                         Timeouts.DEVICE_READ_TIMEOUT_UNIT);
731                     InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
732                         .child(CircuitPacks.class, new CircuitPacksKey(cp2Name))
733                         .child(Ports.class, new PortsKey(connectionPortMap.get(k).get(1).getPortName().toString()));
734                     LOG.info("Fetching connection-port {} at circuit pack {}",
735                         connectionPortMap.get(k).get(1).getPortName().toString(), cp2Name);
736                     Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
737                         LogicalDatastoreType.OPERATIONAL, port2ID, Timeouts.DEVICE_READ_TIMEOUT,
738                         Timeouts.DEVICE_READ_TIMEOUT_UNIT);
739                     if (port1Object.isPresent() && port2Object.isPresent()) {
740                         Ports port1 = port1Object.get();
741                         Ports port2 = port2Object.get();
742                         if (port1.getPortQual() == null || port2.getPortQual() == null) {
743                             continue;
744                         } else if ((Port.PortQual.RoadmExternal.getIntValue() == port1.getPortQual().getIntValue()
745                                 && Port.PortQual.RoadmExternal.getIntValue() == port2.getPortQual().getIntValue()
746                                 && Direction.Rx.getIntValue() == port1.getPortDirection().getIntValue()
747                                 && Direction.Tx.getIntValue() == port2.getPortDirection().getIntValue()
748                                 && port1.getPartnerPort() != null && port2.getPartnerPort() != null
749                                 && port1.getPartnerPort().getCircuitPackName().equals(cp2Name)
750                                 && port1.getPartnerPort().getPortName().equals(port2.getPortName().toString())
751                                 && port2.getPartnerPort().getCircuitPackName().equals(cp1Name)
752                                 && port2.getPartnerPort().getPortName().equals(port1.getPortName()))
753                                 ||
754                                 (Port.PortQual.RoadmExternal.getIntValue() == port1.getPortQual().getIntValue()
755                                 && Port.PortQual.RoadmExternal.getIntValue() == port2.getPortQual().getIntValue()
756                                 && Direction.Rx.getIntValue() == port2.getPortDirection().getIntValue()
757                                 && Direction.Tx.getIntValue() == port1.getPortDirection().getIntValue()
758                                 && port1.getPartnerPort() != null && port2.getPartnerPort() != null
759                                 && port1.getPartnerPort().getCircuitPackName().equals(cp2Name)
760                                 && port1.getPartnerPort().getPortName().equals(port2.getPortName().toString())
761                                 && port2.getPartnerPort().getCircuitPackName().equals(cp1Name)
762                                 && port2.getPartnerPort().getPortName().equals(port1.getPortName().toString()))) {
763                             String logicalConnectionPoint1 = new StringBuilder("DEG").append(k).append("-TTP-")
764                                 .append(port1.getPortDirection().getName().toUpperCase()).toString();
765                             LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId,
766                                 connectionPortMap.get(k).get(0).getCircuitPackName(), port1.getPortName(),
767                                 logicalConnectionPoint1);
768                             portMapList.add(createMappingObject(nodeId, port1, connectionPortMap.get(k).get(0)
769                                 .getCircuitPackName(), logicalConnectionPoint1));
770                             String logicalConnectionPoint2 = new StringBuilder("DEG").append(k).append("-TTP-")
771                                 .append(port2.getPortDirection().getName().toUpperCase()).toString();
772                             LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId,
773                                 connectionPortMap.get(k).get(1).getCircuitPackName(), port2.getPortName(),
774                                 logicalConnectionPoint2);
775                             portMapList.add(createMappingObject(nodeId, port2, connectionPortMap.get(k).get(1)
776                                 .getCircuitPackName(), logicalConnectionPoint2));
777                         } else {
778                             LOG.error(
779                                 "impossible to create logical connection point for port {} or port {} on node {} - Error in configuration with port-qual, port-direction or partner-port configuration",
780                                 port1.getPortName(), port2.getPortName(), nodeId);
781                         }
782                     } else {
783                         LOG.error("No port {} on circuit pack {} for node {}",
784                             connectionPortMap.get(k).get(0).getPortName().toString(),
785                             connectionPortMap.get(k).get(0).getCircuitPackName(), nodeId);
786                         return false;
787                     }
788
789                     break;
790                 default:
791                     LOG.error("Number of connection port for DEG{} on {} is incorrect", k, nodeId);
792                     continue;
793             }
794         }
795         return true;
796     }
797
798     private NodeInfo createNodeInfo(Info deviceInfo) {
799         NodeInfoBuilder nodeInfoBldr = new NodeInfoBuilder();
800         if (deviceInfo.getNodeType() != null) {
801             nodeInfoBldr = new NodeInfoBuilder()
802                 .setOpenroadmVersion(OpenroadmVersion._221)
803                 .setNodeType(deviceInfo.getNodeType());
804             if (deviceInfo.getClli() != null && !deviceInfo.getClli().isEmpty()) {
805                 nodeInfoBldr.setNodeClli(deviceInfo.getClli());
806             } else {
807                 nodeInfoBldr.setNodeClli("defaultCLLI");
808             }
809             if (deviceInfo.getModel() != null) {
810                 nodeInfoBldr.setNodeModel(deviceInfo.getModel());
811             }
812             if (deviceInfo.getVendor() != null) {
813                 nodeInfoBldr.setNodeVendor(deviceInfo.getVendor());
814             }
815             if (deviceInfo.getIpAddress() != null) {
816                 nodeInfoBldr.setNodeIpAddress(deviceInfo.getIpAddress());
817             }
818         } else {
819          // TODO make mandatory in yang
820             LOG.error("Node type field is missing");
821             return null;
822         }
823         return nodeInfoBldr.build();
824     }
825
826 }