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