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