2 * Copyright © 2017 AT&T and others. All rights reserved.
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
9 package org.opendaylight.transportpce.common.mapping;
11 import com.google.common.util.concurrent.FluentFuture;
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.Collections;
15 import java.util.Comparator;
16 import java.util.HashMap;
17 import java.util.List;
18 import java.util.Locale;
20 import java.util.Map.Entry;
21 import java.util.Optional;
22 import java.util.concurrent.ExecutionException;
23 import java.util.stream.Collectors;
24 import org.eclipse.jdt.annotation.NonNull;
25 import org.eclipse.jdt.annotation.Nullable;
26 import org.opendaylight.mdsal.binding.api.DataBroker;
27 import org.opendaylight.mdsal.binding.api.WriteTransaction;
28 import org.opendaylight.mdsal.common.api.CommitInfo;
29 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
30 import org.opendaylight.transportpce.common.StringConstants;
31 import org.opendaylight.transportpce.common.Timeouts;
32 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
33 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
34 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.Network;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.NetworkBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.OpenroadmNodeVersion;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.cp.to.degree.CpToDegree;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.cp.to.degree.CpToDegreeBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.cp.to.degree.CpToDegreeKey;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.Mapping;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.MappingBuilder;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.MappingKey;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.Nodes;
45 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.NodesBuilder;
46 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.NodesKey;
47 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.nodes.NodeInfo;
48 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.nodes.NodeInfoBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.Direction;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.CircuitPack;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.Port;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.Ports;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.PortsKey;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacksKey;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.ConnectionPorts;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.InterfaceKey;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.ConnectionMap;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Degree;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.DegreeKey;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Info;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Protocols;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroup;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroupKey;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.connection.map.Destination;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.port.Interfaces;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.InterfaceType;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.OpenROADMOpticalMultiplex;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.OpticalTransport;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.Protocols1;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.Lldp;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.PortConfig;
76 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
77 import org.opendaylight.yangtools.yang.common.Uint16;
78 import org.opendaylight.yangtools.yang.common.Uint32;
79 import org.slf4j.Logger;
80 import org.slf4j.LoggerFactory;
82 // FIXME: many common pieces of code between PortMapping Versions 121 and 221 and 710
83 // some mutualization would be helpful
84 @SuppressWarnings("CPD-START")
85 public class PortMappingVersion121 {
87 private static final Logger LOG = LoggerFactory.getLogger(PortMappingVersion121.class);
88 private static final Map<Direction, String> SUFFIX;
90 private final DataBroker dataBroker;
91 private final DeviceTransactionManager deviceTransactionManager;
92 private final OpenRoadmInterfaces openRoadmInterfaces;
98 Direction.Bidirectional, "TXRX");
101 public PortMappingVersion121(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
102 OpenRoadmInterfaces openRoadmInterfaces) {
103 this.dataBroker = dataBroker;
104 this.deviceTransactionManager = deviceTransactionManager;
105 this.openRoadmInterfaces = openRoadmInterfaces;
108 public boolean createMappingData(String nodeId) {
109 LOG.info(PortMappingUtils.CREATE_MAPPING_DATA_LOGMSG, nodeId, "1.2.1");
110 List<Mapping> portMapList = new ArrayList<>();
111 InstanceIdentifier<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
112 Optional<Info> deviceInfoOptional = this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType
113 .OPERATIONAL, infoIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
114 if (deviceInfoOptional.isEmpty()) {
115 LOG.warn(PortMappingUtils.DEVICE_HAS_LOGMSG, nodeId, "no info", "subtree");
118 Info deviceInfo = deviceInfoOptional.get();
119 NodeInfo nodeInfo = createNodeInfo(deviceInfo);
120 if (nodeInfo == null) {
123 postPortMapping(nodeId, nodeInfo, null, null);
125 switch (deviceInfo.getNodeType()) {
128 // Get TTP port mapping
129 if (!createTtpPortMapping(nodeId, deviceInfo, portMapList)) {
130 // return false if mapping creation for TTP's failed
131 LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "create", "TTP's");
135 // Get PP port mapping
136 if (!createPpPortMapping(nodeId, deviceInfo, portMapList)) {
137 // return false if mapping creation for PP's failed
138 LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "create", "PP's");
143 if (!createXpdrPortMapping(nodeId, portMapList)) {
144 LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "create", "Xponder");
149 LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG,
150 nodeId, "create", deviceInfo.getNodeType() + " - unknown nodetype");
154 return postPortMapping(nodeId, nodeInfo, portMapList, null);
157 public boolean updateMapping(String nodeId, Mapping oldMapping) {
158 if (nodeId == null) {
159 LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, "node id null" , "update", "a null value");
162 if (oldMapping == null) {
163 LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "update", "a null value");
166 InstanceIdentifier<Ports> portId = InstanceIdentifier.create(OrgOpenroadmDevice.class)
167 .child(CircuitPacks.class, new CircuitPacksKey(oldMapping.getSupportingCircuitPackName()))
168 .child(Ports.class, new PortsKey(oldMapping.getSupportingPort()));
170 Ports port = deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL,
171 portId, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT).get();
172 Mapping newMapping = updateMappingObject(nodeId, port, oldMapping);
173 LOG.debug("{} : Updating old mapping Data {} for {} by new mapping data {}",
174 nodeId, oldMapping, oldMapping.getLogicalConnectionPoint(), newMapping);
175 final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
176 InstanceIdentifier<Mapping> mapIID = InstanceIdentifier.create(Network.class)
177 .child(Nodes.class, new NodesKey(nodeId))
178 .child(Mapping.class, new MappingKey(oldMapping.getLogicalConnectionPoint()));
179 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, mapIID, newMapping);
180 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
183 } catch (InterruptedException | ExecutionException e) {
184 LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG,
185 nodeId, "update", oldMapping.getLogicalConnectionPoint(), e);
190 private boolean createXpdrPortMapping(String nodeId, List<Mapping> portMapList) {
191 // Creating for Xponder Line and Client Ports
192 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
193 Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
194 LogicalDatastoreType.OPERATIONAL, deviceIID,
195 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
196 if (!deviceObject.isPresent()) {
197 LOG.error(PortMappingUtils.CANNOT_GET_DEV_CONF_LOGMSG, nodeId);
200 OrgOpenroadmDevice device = deviceObject.get();
201 if (device.getCircuitPacks() == null) {
202 LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, "found");
205 // Variable to keep track of number of line ports
207 // Variable to keep track of number of client ports
209 Map<String, String> lcpMap = new HashMap<>();
210 Map<String, Mapping> mappingMap = new HashMap<>();
211 List<CircuitPacks> circuitPackList = new ArrayList<>(device.nonnullCircuitPacks().values());
212 circuitPackList.sort(Comparator.comparing(CircuitPack::getCircuitPackName));
214 for (CircuitPacks cp : circuitPackList) {
215 String circuitPackName = cp.getCircuitPackName();
216 if (cp.getPorts() == null) {
217 LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, "found", circuitPackName);
221 // com.google.common.collect.ImmutableList implementation of List
222 List<Ports> portList = new ArrayList<>(cp.nonnullPorts().values());
223 portList.sort(Comparator.comparing(Ports::getPortName));
224 for (Ports port : portList) {
225 int[] counters = fillXpdrLcpsMaps(line, client, nodeId,
226 1, circuitPackName, port,
227 circuitPackList, lcpMap, mappingMap);
229 client = counters[1];
233 Collection<ConnectionMap> connectionMap = deviceObject.get().nonnullConnectionMap().values();
234 for (ConnectionMap cm : connectionMap) {
235 String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
236 String slcp = lcpMap.containsKey(skey) ? lcpMap.get(skey) : null;
237 Destination destination0 = cm.nonnullDestination().values().iterator().next();
238 String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName();
240 LOG.error("{} : Error in connection-map analysis for source {} and destination (CP+port) {}",
244 String dlcp = lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null;
245 Mapping mapping = mappingMap.get(slcp);
246 mappingMap.remove(slcp);
247 portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping, dlcp));
250 if (!mappingMap.isEmpty()) {
251 for (Mapping m : mappingMap.values()) {
258 private boolean checkPartnerPortNotNull(Ports port) {
259 return (port.getPartnerPort() != null
260 && port.getPartnerPort().getCircuitPackName() != null
261 && port.getPartnerPort().getPortName() != null);
264 private boolean checkPartnerPortNoDir(String circuitPackName, Ports port1, Ports port2) {
265 return (checkPartnerPortNotNull(port2)
266 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
267 && port2.getPartnerPort().getPortName().equals(port1.getPortName()));
270 private boolean checkPartnerPort(String circuitPackName, Ports port1, Ports port2) {
271 return (checkPartnerPortNoDir(circuitPackName, port1, port2)
272 && ((Direction.Rx.getIntValue() == port1.getPortDirection().getIntValue()
273 && Direction.Tx.getIntValue() == port2.getPortDirection().getIntValue())
275 (Direction.Tx.getIntValue() == port1.getPortDirection().getIntValue()
276 && Direction.Rx.getIntValue() == port2.getPortDirection().getIntValue())));
279 private HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg
280 .CircuitPacks>> getSrgCps(String deviceId, Info ordmInfo) {
281 HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg
282 .CircuitPacks>> cpPerSrg = new HashMap<>();
283 // Get value for max Srg from info subtree, required for iteration
284 // if not present assume to be 20 (temporary)
285 Integer maxSrg = ordmInfo.getMaxSrgs() == null ? 20 : ordmInfo.getMaxSrgs().toJava();
286 for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) {
287 List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> srgCps
289 LOG.debug("{} : Getting Circuitpacks for Srg Number {}", deviceId, srgCounter);
290 InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
291 .child(SharedRiskGroup.class, new SharedRiskGroupKey(Uint16.valueOf(srgCounter)));
292 Optional<SharedRiskGroup> ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
293 LogicalDatastoreType.OPERATIONAL, srgIID,
294 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
295 if (ordmSrgObject.isPresent()) {
296 srgCps.addAll(ordmSrgObject.get().nonnullCircuitPacks().values());
297 cpPerSrg.put(ordmSrgObject.get().getSrgNumber().toJava(), srgCps);
300 LOG.info(PortMappingUtils.DEVICE_HAS_LOGMSG, deviceId, cpPerSrg.size(), "SRG");
304 private boolean createPpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
305 // Creating mapping data for SRG's PP
306 HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks>> srgCps
307 = getSrgCps(nodeId, deviceInfo);
309 for (Entry<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks>>
310 srgCpEntry : srgCps.entrySet()) {
311 List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> cpList =
312 srgCps.get(srgCpEntry.getKey());
313 List<String> keys = new ArrayList<>();
314 for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks cp : cpList) {
315 String circuitPackName = cp.getCircuitPackName();
316 InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
317 .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName));
318 Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
319 LogicalDatastoreType.OPERATIONAL, cpIID,
320 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
322 if (circuitPackObject.isEmpty()) {
323 LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
324 nodeId, circuitPackName);
327 if (circuitPackObject.get().getPorts() == null) {
328 LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, "found", circuitPackName);
332 // com.google.common.collect.ImmutableList implementation of List
334 List<Ports> portList = new ArrayList<>(circuitPackObject.get().nonnullPorts().values());
335 Collections.sort(portList, new SortPort121ByName());
337 for (Ports port : portList) {
338 String currentKey = circuitPackName + "-" + port.getPortName();
339 if (port.getPortQual() == null) {
343 if (Port.PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) {
344 LOG.debug("{} : port {} on {} is not roadm-external" + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
345 nodeId, port.getPortName(), circuitPackName);
349 if (keys.contains(currentKey)) {
350 LOG.debug("{} : port {} on {} has already been handled" + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
351 nodeId, port.getPortName(), circuitPackName);
355 switch (port.getPortDirection()) {
358 String lcp = createLogicalConnectionPort(port, srgCpEntry.getKey(), portIndex);
359 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
360 nodeId, port.getPortName(), circuitPackName, lcp);
361 portMapList.add(createMappingObject(nodeId, port, circuitPackName, lcp));
363 keys.add(currentKey);
368 if (!checkPartnerPortNotNull(port)) {
369 LOG.info(PortMappingUtils.NO_VALID_PARTNERPORT_UNIDIR_LOGMSG
370 + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
371 nodeId, port.getPortName(), circuitPackName);
375 String lcp1 = createLogicalConnectionPort(port, srgCpEntry.getKey(), portIndex);
376 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
377 nodeId, port.getPortName(), circuitPackName, lcp1);
378 InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
379 .child(CircuitPacks.class,
380 new CircuitPacksKey(port.getPartnerPort().getCircuitPackName()))
381 .child(Ports.class, new PortsKey(port.getPartnerPort().getPortName()));
382 Optional<Ports> port2Object = this.deviceTransactionManager
383 .getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, port2ID,
384 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
385 if (port2Object.isEmpty()
386 || port2Object.get().getPortQual().getIntValue()
387 != Port.PortQual.RoadmExternal.getIntValue()) {
388 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG
389 + PortMappingUtils.PARTNERPORT_GET_ERROR_LOGMSG,
390 nodeId, port.getPartnerPort().getPortName(),
391 port.getPartnerPort().getCircuitPackName(),
392 port.getPortName(), circuitPackName);
397 Ports port2 = port2Object.get();
398 if (!checkPartnerPort(circuitPackName, port, port2)) {
399 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG
400 + PortMappingUtils.PARTNERPORT_CONF_ERROR_LOGMSG,
401 nodeId, port2.getPortName(), port.getPartnerPort().getCircuitPackName(),
402 port.getPortName(), circuitPackName);
406 String lcp2 = createLogicalConnectionPort(port2, srgCpEntry.getKey(),portIndex);
407 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
408 nodeId, port2.getPortName(), circuitPackName, lcp2);
409 portMapList.add(createMappingObject(nodeId, port, circuitPackName, lcp1));
411 createMappingObject(nodeId ,port2, port.getPartnerPort().getCircuitPackName(), lcp2));
413 keys.add(currentKey);
414 keys.add(port.getPartnerPort().getCircuitPackName() + "-" + port2.getPortName());
418 LOG.error(PortMappingUtils.UNSUPPORTED_DIR_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
419 nodeId, port.getPortName(), circuitPackName, port.getPortDirection());
428 private String createLogicalConnectionPort(Ports port, int index, int portIndex) {
429 if (SUFFIX.containsKey(port.getPortDirection())) {
430 return String.join("-", "SRG" + index, "PP" + portIndex, SUFFIX.get(port.getPortDirection()));
432 LOG.error(PortMappingUtils.UNSUPPORTED_DIR_LOGMSG,
433 "createLogicalConnectionPort", port, "SRG" + index + "-PP" + portIndex, port.getPortDirection());
437 private Map<Integer, Degree> getDegreesMap(String deviceId, Info ordmInfo) {
438 Map<Integer, Degree> degrees = new HashMap<>();
440 // Get value for max degree from info subtree, required for iteration
441 // if not present assume to be 20 (temporary)
442 Integer maxDegree = ordmInfo.getMaxDegrees() == null ? 20 : ordmInfo.getMaxDegrees().toJava();
444 for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
445 LOG.debug("{} : Getting Connection ports for Degree Number {}", deviceId, degreeCounter);
446 InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
447 .child(Degree.class, new DegreeKey(Uint16.valueOf(degreeCounter)));
448 Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
449 LogicalDatastoreType.OPERATIONAL, deviceIID,
450 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
451 if (ordmDegreeObject.isPresent()) {
452 degrees.put(degreeCounter, ordmDegreeObject.get());
455 LOG.info(PortMappingUtils.DEVICE_HAS_LOGMSG,
456 deviceId, degrees.size(), degrees.size() <= 1 ? "degree" : "degrees");
460 private Map<Integer, List<ConnectionPorts>> getPerDegreePorts(String deviceId, Info ordmInfo) {
461 Map<Integer, List<ConnectionPorts>> conPortMap = new HashMap<>();
462 getDegreesMap(deviceId, ordmInfo).forEach(
463 (index, degree) -> conPortMap.put(index, new ArrayList<>(degree.nonnullConnectionPorts().values())));
467 private Map<String, String> getEthInterfaceList(String nodeId) {
468 LOG.info(PortMappingUtils.GETTING_ETH_LIST_LOGMSG, nodeId);
469 InstanceIdentifier<Protocols> protocoliid = InstanceIdentifier.create(OrgOpenroadmDevice.class)
470 .child(Protocols.class);
471 Optional<Protocols> protocolObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
472 LogicalDatastoreType.OPERATIONAL, protocoliid, Timeouts.DEVICE_READ_TIMEOUT,
473 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
474 if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class).getLldp() == null) {
475 LOG.warn(PortMappingUtils.PROCESSING_DONE_LOGMSG, nodeId, PortMappingUtils.CANNOT_GET_LLDP_CONF_LOGMSG);
476 return new HashMap<>();
478 Map<String, String> cpToInterfaceMap = new HashMap<>();
479 Lldp lldp = protocolObject.get().augmentation(Protocols1.class).getLldp();
480 for (PortConfig portConfig : lldp.nonnullPortConfig().values()) {
481 if (!portConfig.getAdminStatus().equals(PortConfig.AdminStatus.Txandrx)) {
484 InstanceIdentifier<Interface> interfaceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
485 .child(Interface.class, new InterfaceKey(portConfig.getIfName()));
486 Optional<Interface> interfaceObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
487 LogicalDatastoreType.OPERATIONAL, interfaceIID, Timeouts.DEVICE_READ_TIMEOUT,
488 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
489 if (!interfaceObject.isPresent() || (interfaceObject.get().getSupportingCircuitPackName() == null)) {
492 String supportingCircuitPackName = interfaceObject.get().getSupportingCircuitPackName();
493 cpToInterfaceMap.put(supportingCircuitPackName, portConfig.getIfName());
494 InstanceIdentifier<CircuitPacks> circuitPacksIID = InstanceIdentifier
495 .create(OrgOpenroadmDevice.class)
496 .child(CircuitPacks.class, new CircuitPacksKey(supportingCircuitPackName));
497 Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(
498 nodeId, LogicalDatastoreType.OPERATIONAL, circuitPacksIID, Timeouts.DEVICE_READ_TIMEOUT,
499 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
500 if (!circuitPackObject.isPresent() || (circuitPackObject.get().getParentCircuitPack() == null)) {
503 cpToInterfaceMap.put(circuitPackObject.get().getParentCircuitPack().getCircuitPackName(),
504 portConfig.getIfName());
506 LOG.info(PortMappingUtils.PROCESSING_DONE_LOGMSG, nodeId, " - success");
507 return cpToInterfaceMap;
510 private List<CpToDegree> getCpToDegreeList(Map<Integer, Degree> degrees, Map<String, String> interfaceList) {
511 List<CpToDegree> cpToDegreeList = new ArrayList<>();
512 for (Degree degree : degrees.values()) {
513 LOG.debug("Inside CP to degree list");
514 cpToDegreeList.addAll(degree.nonnullCircuitPacks().values().stream()
515 .map(cp -> createCpToDegreeObject(cp.getCircuitPackName(),
516 degree.getDegreeNumber().toString(), interfaceList))
517 .collect(Collectors.toList()));
519 return cpToDegreeList;
522 private boolean postPortMapping(String nodeId, NodeInfo nodeInfo, List<Mapping> portMapList,
523 List<CpToDegree> cp2DegreeList) {
524 NodesBuilder nodesBldr = new NodesBuilder().withKey(new NodesKey(nodeId)).setNodeId(nodeId);
525 if (nodeInfo != null) {
526 nodesBldr.setNodeInfo(nodeInfo);
528 if (portMapList != null) {
529 Map<MappingKey, Mapping> mappingMap = new HashMap<>();
530 // No element in the list below should be null at this stage
531 for (Mapping mapping: portMapList) {
532 mappingMap.put(mapping.key(), mapping);
534 nodesBldr.setMapping(mappingMap);
536 if (cp2DegreeList != null) {
537 Map<CpToDegreeKey, CpToDegree> cpToDegreeMap = new HashMap<>();
538 // No element in the list below should be null at this stage
539 for (CpToDegree cp2Degree: cp2DegreeList) {
540 cpToDegreeMap.put(cp2Degree.key(), cp2Degree);
542 nodesBldr.setCpToDegree(cpToDegreeMap);
545 Map<NodesKey,Nodes> nodesList = new HashMap<>();
546 Nodes nodes = nodesBldr.build();
547 nodesList.put(nodes.key(),nodes);
549 Network network = new NetworkBuilder().setNodes(nodesList).build();
551 final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
552 InstanceIdentifier<Network> nodesIID = InstanceIdentifier.builder(Network.class).build();
553 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodesIID, network);
554 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
558 } catch (InterruptedException | ExecutionException e) {
559 LOG.warn("Failed to post {}", network, e);
564 private CpToDegree createCpToDegreeObject(String circuitPackName, String degreeNumber,
565 Map<String, String> interfaceList) {
566 return new CpToDegreeBuilder()
567 .withKey(new CpToDegreeKey(circuitPackName))
568 .setCircuitPackName(circuitPackName)
569 .setDegreeNumber(Uint32.valueOf(degreeNumber))
570 .setInterfaceName(interfaceList.get(circuitPackName)).build();
573 private Mapping createMappingObject(String nodeId, Ports port, String circuitPackName,
574 String logicalConnectionPoint) {
575 MappingBuilder mpBldr = new MappingBuilder()
576 .withKey(new MappingKey(logicalConnectionPoint))
577 .setLogicalConnectionPoint(logicalConnectionPoint)
578 .setSupportingCircuitPackName(circuitPackName)
579 .setSupportingPort(port.getPortName())
580 .setPortDirection(port.getPortDirection().getName());
581 if (port.getAdministrativeState() != null) {
582 mpBldr.setPortAdminState(port.getAdministrativeState().name());
584 if (port.getOperationalState() != null) {
585 mpBldr.setPortOperState(port.getOperationalState().name());
587 if (!logicalConnectionPoint.contains(StringConstants.TTP_TOKEN) || (port.getInterfaces() == null)) {
588 return mpBldr.build();
590 mpBldr = updateMappingInterfaces(nodeId, mpBldr, port);
591 return mpBldr.build();
594 private Mapping updateMappingObject(String nodeId, Ports port, Mapping oldmapping) {
595 MappingBuilder mpBldr = new MappingBuilder(oldmapping);
596 updateMappingStates(mpBldr, port, oldmapping);
597 if ((port.getInterfaces() == null)
598 || (!oldmapping.getLogicalConnectionPoint().contains(StringConstants.TTP_TOKEN)
599 && !oldmapping.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN))) {
600 return mpBldr.build();
602 // Get interfaces provisioned on the port
603 mpBldr = updateMappingInterfaces(nodeId, mpBldr, port);
604 return mpBldr.build();
607 private MappingBuilder updateMappingStates(MappingBuilder mpBldr, Ports port, Mapping oldmapping) {
608 if (port.getAdministrativeState() != null
609 && !port.getAdministrativeState().getName().equals(oldmapping.getPortAdminState())) {
610 mpBldr.setPortAdminState(port.getAdministrativeState().name());
612 if (port.getOperationalState() != null
613 && !port.getOperationalState().getName().equals(oldmapping.getPortOperState())) {
614 mpBldr.setPortOperState(port.getOperationalState().name());
619 private MappingBuilder updateMappingInterfaces(String nodeId, MappingBuilder mpBldr, Ports port) {
620 for (Interfaces interfaces : port.getInterfaces()) {
622 Optional<Interface> openRoadmInterface = this.openRoadmInterfaces.getInterface(nodeId,
623 interfaces.getInterfaceName());
624 if (!openRoadmInterface.isPresent()) {
625 LOG.warn("{} : Interface {} was null!", nodeId, interfaces.getInterfaceName());
628 LOG.debug("{} : interface get from device is {} and of type {}",
629 nodeId, openRoadmInterface.get().getName(), openRoadmInterface.get().getType());
630 Class<? extends InterfaceType> interfaceType
631 = (Class<? extends InterfaceType>) openRoadmInterface.get().getType();
632 // Check if interface type is OMS or OTS
633 if (interfaceType.equals(OpenROADMOpticalMultiplex.class)) {
634 mpBldr.setSupportingOms(interfaces.getInterfaceName());
636 if (interfaceType.equals(OpticalTransport.class)) {
637 mpBldr.setSupportingOts(interfaces.getInterfaceName());
639 } catch (OpenRoadmInterfaceException ex) {
640 LOG.warn("{} : Error while getting interface {} - ", nodeId, interfaces.getInterfaceName(), ex);
646 private Mapping createXpdrMappingObject(String nodeId, Ports port, String circuitPackName,
647 String logicalConnectionPoint, String partnerLcp, Mapping mapping, String assoLcp) {
649 if (mapping != null && assoLcp != null) {
650 // update existing mapping
651 return new MappingBuilder(mapping).setConnectionMapLcp(assoLcp).build();
654 // create a new mapping
655 String nodeIdLcp = nodeId + "-" + logicalConnectionPoint;
656 MappingBuilder mpBldr = new MappingBuilder()
657 .withKey(new MappingKey(logicalConnectionPoint))
658 .setLogicalConnectionPoint(logicalConnectionPoint)
659 .setSupportingCircuitPackName(circuitPackName)
660 .setSupportingPort(port.getPortName())
661 .setPortDirection(port.getPortDirection().getName())
662 .setLcpHashVal(PortMappingUtils.fnv1size64(nodeIdLcp));
663 if (port.getPortQual() != null) {
664 mpBldr.setPortQual(port.getPortQual().getName());
666 if (partnerLcp != null) {
667 mpBldr.setPartnerLcp(partnerLcp);
669 if (port.getAdministrativeState() != null) {
670 mpBldr.setPortAdminState(port.getAdministrativeState().name());
672 if (port.getOperationalState() != null) {
673 mpBldr.setPortOperState(port.getOperationalState().name());
675 return mpBldr.build();
678 private Ports getPort2(Ports port, String nodeId, String circuitPackName, StringBuilder circuitPackName2,
679 //circuitPackName2 will be updated by reference contrary to circuitPackName
680 List<CircuitPacks> circuitPackList, Map<String, String> lcpMap) {
681 if (!checkPartnerPortNotNull(port)) {
682 LOG.warn("{} : port {} on {} - Error in the configuration ", nodeId, port.getPortName(), circuitPackName);
685 if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) {
688 Optional<CircuitPacks> cpOpt = circuitPackList.stream()
689 .filter(cP -> cP.getCircuitPackName().equals(port.getPartnerPort().getCircuitPackName()))
691 if (!cpOpt.isPresent()) {
692 LOG.error("{} : Error fetching circuit-pack {}", nodeId, port.getPartnerPort().getCircuitPackName());
695 Optional<Ports> poOpt = cpOpt.get().nonnullPorts().values().stream()
696 .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName()))
698 if (!poOpt.isPresent()) {
699 LOG.error("{} : Error fetching port {} on {}",
700 nodeId, port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName());
703 Ports port2 = poOpt.get();
704 circuitPackName2.append(cpOpt.get().getCircuitPackName());
705 if (!checkPartnerPort(circuitPackName, port, port2)) {
706 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
707 nodeId, port2.getPortName(), circuitPackName2, port.getPortName(), circuitPackName);
713 private void putXpdrLcpsInMaps(int line, String nodeId,
715 String circuitPackName, String circuitPackName2, Ports port, Ports port2,
716 Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
718 PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, line, StringConstants.NETWORK_TOKEN);
719 if (lcpMap.containsKey(lcp1)) {
720 LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "add", lcp1 + " - already exist");
724 PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, line + 1, StringConstants.NETWORK_TOKEN);
725 if (lcpMap.containsKey(lcp2)) {
726 LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "add", lcp2 + " - already exist");
729 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp1);
730 lcpMap.put(circuitPackName2 + '+' + port2.getPortName(), lcp2);
732 createXpdrMappingObject(nodeId, port, circuitPackName, lcp1, lcp2, null, null));
734 createXpdrMappingObject(nodeId, port2, circuitPackName2, lcp2, lcp1, null, null));
738 private int[] fillXpdrLcpsMaps(int line, int client, String nodeId,
740 String circuitPackName, Ports port,
741 List<CircuitPacks> circuitPackList, Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
743 if (port.getPortQual() == null) {
744 LOG.warn("{} : port {} on {} - PortQual was not found", nodeId, port.getPortName(), circuitPackName);
745 return new int[] {line, client};
748 switch (port.getPortQual()) {
752 PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, client, StringConstants.CLIENT_TOKEN);
753 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp0);
755 createXpdrMappingObject(nodeId, port, circuitPackName, lcp0, null, null, null));
760 line = fillXpdrNetworkLcpsMaps(line, nodeId,
762 circuitPackName, port,
763 circuitPackList, lcpMap, mappingMap);
767 LOG.error("{} : port {} on {} - unsupported PortQual {}",
768 nodeId, port.getPortName(), circuitPackName, port.getPortQual());
770 return new int[] {line, client};
773 private int fillXpdrNetworkLcpsMaps(int line, String nodeId,
775 String circuitPackName, Ports port,
776 List<CircuitPacks> circuitPackList, Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
778 switch (port.getPortDirection()) {
782 PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, line, StringConstants.NETWORK_TOKEN);
783 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp);
785 createXpdrMappingObject(nodeId, port, circuitPackName, lcp, null, null, null));
791 StringBuilder circuitPackName2 = new StringBuilder();
792 Ports port2 = getPort2(port, nodeId, circuitPackName, circuitPackName2,
793 circuitPackList, lcpMap);
796 //key already present or an error occured and was logged
800 putXpdrLcpsInMaps(line, nodeId, xponderNb,
801 circuitPackName, circuitPackName2.toString(), port, port2,
808 LOG.error(PortMappingUtils.UNSUPPORTED_DIR_LOGMSG,
809 nodeId, port.getPortName(), circuitPackName, port.getPortDirection());
815 private boolean createTtpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
816 // Creating mapping data for degree TTP's
817 Map<Integer, Degree> degrees = getDegreesMap(nodeId, deviceInfo);
818 Map<String, String> interfaceList = getEthInterfaceList(nodeId);
819 List<CpToDegree> cpToDegreeList = getCpToDegreeList(degrees, interfaceList);
820 LOG.info("{} : Map looks like this {}", nodeId, interfaceList);
821 postPortMapping(nodeId, null, null, cpToDegreeList);
823 Map<Integer, List<ConnectionPorts>> connectionPortMap = getPerDegreePorts(nodeId, deviceInfo);
824 for (Entry<Integer, List<ConnectionPorts>> cpMapEntry : connectionPortMap.entrySet()) {
825 switch (connectionPortMap.get(cpMapEntry.getKey()).size()) {
827 // port is bidirectional
828 String cpName = connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName();
829 InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
830 .child(CircuitPacks.class, new CircuitPacksKey(cpName))
832 new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName()));
833 LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG,
834 nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cpName);
835 Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
836 LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
837 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
838 if (!portObject.isPresent()) {
839 LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG,
840 nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cpName);
843 Ports port = portObject.get();
844 if (port.getPortQual() == null) {
847 if (Port.PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) {
848 LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTQUAL_ERROR_LOGMSG,
849 nodeId, port.getPortName(), cpName);
852 if (Direction.Bidirectional.getIntValue() != port.getPortDirection().getIntValue()) {
853 LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTDIR_ERROR_LOGMSG,
854 nodeId, port.getPortName(), cpName);
858 String logicalConnectionPoint =
859 PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(), "TXRX");
860 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
861 nodeId, port.getPortName(), cpName, logicalConnectionPoint);
862 portMapList.add(createMappingObject(nodeId, port, cpName, logicalConnectionPoint));
865 // ports are unidirectionals
866 String cp1Name = connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName();
867 String cp2Name = connectionPortMap.get(cpMapEntry.getKey()).get(1).getCircuitPackName();
868 InstanceIdentifier<Ports> port1ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
869 .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
871 new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName()));
872 LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG,
873 nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cp1Name);
874 Optional<Ports> port1Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
875 LogicalDatastoreType.OPERATIONAL, port1ID, Timeouts.DEVICE_READ_TIMEOUT,
876 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
877 InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
878 .child(CircuitPacks.class, new CircuitPacksKey(cp2Name))
880 new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName()));
881 LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG,
882 nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName(), cp2Name);
883 Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
884 LogicalDatastoreType.OPERATIONAL, port2ID, Timeouts.DEVICE_READ_TIMEOUT,
885 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
886 if (!port1Object.isPresent() || !port2Object.isPresent()) {
887 LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG,
888 nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cp1Name);
891 if (!port2Object.isPresent()) {
892 LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG,
893 nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName(), cp2Name);
897 Ports port1 = port1Object.get();
898 Ports port2 = port2Object.get();
899 if (port1.getPortQual() == null || port2.getPortQual() == null) {
902 if (Port.PortQual.RoadmExternal.getIntValue() != port1.getPortQual().getIntValue()) {
903 LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTQUAL_ERROR_LOGMSG,
904 nodeId, port1.getPortName(), cp1Name);
907 if (Port.PortQual.RoadmExternal.getIntValue() != port2.getPortQual().getIntValue()) {
908 LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTQUAL_ERROR_LOGMSG,
909 nodeId, port2.getPortName(), cp2Name);
913 if (!checkPartnerPort(cp1Name, port1, port2)) {
914 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
915 nodeId, port2.getPortName(), cp2Name, port1.getPortName(), cp1Name);
918 // Directions checks are the same for cp1 and cp2, no need to check them twice.
919 if (!checkPartnerPortNoDir(cp2Name, port2, port1)) {
920 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
921 nodeId, port1.getPortName(), cp1Name, port2.getPortName(), cp2Name);
925 String logicalConnectionPoint1 = PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(),
926 port1.getPortDirection().getName().toUpperCase(Locale.getDefault()));
927 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
928 nodeId, port1.getPortName(), cp1Name, logicalConnectionPoint1);
929 portMapList.add(createMappingObject(nodeId, port1, cp1Name, logicalConnectionPoint1));
930 String logicalConnectionPoint2 = PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(),
931 port2.getPortDirection().getName().toUpperCase(Locale.getDefault()));
932 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
933 nodeId, port2.getPortName(), cp2Name, logicalConnectionPoint2);
934 portMapList.add(createMappingObject(nodeId, port2, cp2Name, logicalConnectionPoint2));
937 LOG.error("{} : Number of connection port for DEG{} is incorrect", nodeId, cpMapEntry.getKey());
944 private NodeInfo createNodeInfo(Info deviceInfo) {
946 if (deviceInfo.getNodeType() == null) {
947 // TODO make mandatory in yang
948 LOG.error("Node type field is missing");
952 NodeInfoBuilder nodeInfoBldr = new NodeInfoBuilder()
953 .setOpenroadmVersion(OpenroadmNodeVersion._121);
954 // TODO check if we can use here .setNodeType(NodeTypes.forValue(..) such as with 221
955 switch (deviceInfo.getNodeType().getIntValue()) {
958 nodeInfoBldr.setNodeType(NodeTypes.forValue(deviceInfo.getNodeType().getIntValue()));
961 LOG.error("Error with node-type of {}", deviceInfo.getNodeId());
962 // TODO: is this protection useful ? it is not present in Portmapping 221
964 if (deviceInfo.getClli() != null && !deviceInfo.getClli().isEmpty()) {
965 nodeInfoBldr.setNodeClli(deviceInfo.getClli());
967 nodeInfoBldr.setNodeClli("defaultCLLI");
969 if (deviceInfo.getModel() != null) {
970 nodeInfoBldr.setNodeModel(deviceInfo.getModel());
972 if (deviceInfo.getVendor() != null) {
973 nodeInfoBldr.setNodeVendor(deviceInfo.getVendor());
975 if (deviceInfo.getIpAddress() != null) {
976 nodeInfoBldr.setNodeIpAddress(deviceInfo.getIpAddress());
979 return nodeInfoBldr.build();