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