2 * Copyright © 2017 Orange, Inc. 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.opendaylight.mdsal.binding.api.DataBroker;
26 import org.opendaylight.mdsal.binding.api.WriteTransaction;
27 import org.opendaylight.mdsal.common.api.CommitInfo;
28 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
29 import org.opendaylight.transportpce.common.StringConstants;
30 import org.opendaylight.transportpce.common.Timeouts;
31 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
32 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
33 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.Network;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.NetworkBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.OpenroadmNodeVersion;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.cp.to.degree.CpToDegree;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.cp.to.degree.CpToDegreeBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.cp.to.degree.CpToDegreeKey;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.Mapping;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.MappingBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.MappingKey;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mc.capabilities.McCapabilities;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mc.capabilities.McCapabilitiesBuilder;
45 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mc.capabilities.McCapabilitiesKey;
46 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.Nodes;
47 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.NodesBuilder;
48 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.NodesKey;
49 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.nodes.NodeInfo;
50 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.nodes.NodeInfoBuilder;
51 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.switching.pool.lcp.SwitchingPoolLcp;
52 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.switching.pool.lcp.SwitchingPoolLcpBuilder;
53 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.switching.pool.lcp.SwitchingPoolLcpKey;
54 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.switching.pool.lcp.switching.pool.lcp.NonBlockingList;
55 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.switching.pool.lcp.switching.pool.lcp.NonBlockingListBuilder;
56 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.switching.pool.lcp.switching.pool.lcp.NonBlockingListKey;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.optical.channel.types.rev200529.FrequencyGHz;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.Direction;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.PortQual;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.XpdrNodeTypes;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.CircuitPack;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.pack.Ports;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.pack.PortsKey;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.packs.CircuitPacks;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.packs.CircuitPacksKey;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.degree.ConnectionPorts;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.Interface;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.InterfaceKey;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.OrgOpenroadmDevice;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.ConnectionMap;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.Degree;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.DegreeKey;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.Info;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.OduSwitchingPools;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.Protocols;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.SharedRiskGroup;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.SharedRiskGroupKey;
78 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.Xponder;
79 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.connection.map.Destination;
80 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.odu.switching.pools.non.blocking.list.PortList;
81 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.port.Interfaces;
82 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.xponder.XpdrPort;
83 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
84 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.InterfaceType;
85 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.OpenROADMOpticalMultiplex;
86 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.OpticalTransport;
87 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.OtnOdu;
88 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.Protocols1;
89 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.Lldp;
90 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.lldp.PortConfig;
91 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev181019.SupportedIfCapability;
92 import org.opendaylight.yang.gen.v1.http.org.openroadm.switching.pool.types.rev191129.SwitchingPoolTypes;
93 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
94 import org.opendaylight.yangtools.yang.common.Uint16;
95 import org.opendaylight.yangtools.yang.common.Uint32;
96 import org.slf4j.Logger;
97 import org.slf4j.LoggerFactory;
99 // FIXME: many common pieces of code between PortMapping Versions 121 and 221 and 710
100 // some mutualization would be helpful
101 public class PortMappingVersion221 {
103 private static final Logger LOG = LoggerFactory.getLogger(PortMappingVersion221.class);
104 private static final Map<Direction, String> SUFFIX;
106 private final DataBroker dataBroker;
107 private final DeviceTransactionManager deviceTransactionManager;
108 private final OpenRoadmInterfaces openRoadmInterfaces;
114 Direction.Bidirectional, "TXRX");
117 public PortMappingVersion221(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
118 OpenRoadmInterfaces openRoadmInterfaces) {
119 this.dataBroker = dataBroker;
120 this.deviceTransactionManager = deviceTransactionManager;
121 this.openRoadmInterfaces = openRoadmInterfaces;
124 public boolean createMappingData(String nodeId) {
125 LOG.info(PortMappingUtils.CREATE_MAPPING_DATA_LOGMSG, nodeId, "2.2.1");
126 List<Mapping> portMapList = new ArrayList<>();
127 Map<McCapabilitiesKey, McCapabilities> mcCapabilities = new HashMap<>();
128 InstanceIdentifier<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
129 Optional<Info> deviceInfoOptional = this.deviceTransactionManager.getDataFromDevice(
130 nodeId, LogicalDatastoreType.OPERATIONAL, infoIID,
131 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
132 if (deviceInfoOptional.isEmpty()) {
133 LOG.warn(PortMappingUtils.DEVICE_HAS_LOGMSG, nodeId, "no info", "subtree");
136 Info deviceInfo = deviceInfoOptional.get();
137 NodeInfo nodeInfo = createNodeInfo(deviceInfo);
138 if (nodeInfo == null) {
141 postPortMapping(nodeId, nodeInfo, null, null, null, null);
143 switch (deviceInfo.getNodeType()) {
146 // Get TTP port mapping
147 if (!createTtpPortMapping(nodeId, deviceInfo, portMapList)) {
148 // return false if mapping creation for TTP's failed
149 LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "create", "TTP's");
153 // Get PP port mapping
154 if (!createPpPortMapping(nodeId, deviceInfo, portMapList)) {
155 // return false if mapping creation for PP's failed
156 LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "create", "PP's");
159 // Get MC capabilities
160 if (!createMcCapabilitiesList(nodeId, deviceInfo, mcCapabilities)) {
161 // return false if MC capabilites failed
162 LOG.warn(PortMappingUtils.UNABLE_MC_CAPA_LOGMSG, nodeId);
167 if (!createXpdrPortMapping(nodeId, portMapList)) {
168 LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "create", "Xponder");
173 LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG,
174 nodeId, "create", deviceInfo.getNodeType() + " - unknown nodetype");
178 return postPortMapping(nodeId, nodeInfo, portMapList, null, null, mcCapabilities);
181 public boolean updateMapping(String nodeId, Mapping oldMapping) {
182 if (nodeId == null) {
183 LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, "node id null" , "update", "a null value");
186 if (oldMapping == null) {
187 LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "update", "a null value");
190 InstanceIdentifier<Ports> portId = InstanceIdentifier.create(OrgOpenroadmDevice.class)
191 .child(CircuitPacks.class, new CircuitPacksKey(oldMapping.getSupportingCircuitPackName()))
192 .child(Ports.class, new PortsKey(oldMapping.getSupportingPort()));
194 Ports port = deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL,
195 portId, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT).get();
196 Mapping newMapping = updateMappingObject(nodeId, port, oldMapping);
197 LOG.debug("{} : Updating old mapping Data {} for {} by new mapping data {}",
198 nodeId, oldMapping, oldMapping.getLogicalConnectionPoint(), newMapping);
199 final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
200 InstanceIdentifier<Mapping> mapIID = InstanceIdentifier.create(Network.class)
201 .child(Nodes.class, new NodesKey(nodeId))
202 .child(Mapping.class, new MappingKey(oldMapping.getLogicalConnectionPoint()));
203 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, mapIID, newMapping);
204 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
207 } catch (InterruptedException | ExecutionException e) {
208 LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG,
209 nodeId, "update", oldMapping.getLogicalConnectionPoint(), e);
214 private boolean createXpdrPortMapping(String nodeId, List<Mapping> portMapList) {
215 // Creating for Xponder Line and Client Ports
216 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
217 Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
218 LogicalDatastoreType.OPERATIONAL, deviceIID,
219 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
220 if (!deviceObject.isPresent()) {
221 LOG.error(PortMappingUtils.CANNOT_GET_DEV_CONF_LOGMSG, nodeId);
224 OrgOpenroadmDevice device = deviceObject.get();
225 if (device.getCircuitPacks() == null) {
226 LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, "found");
230 Map<String, String> lcpMap = new HashMap<>();
231 Map<String, Mapping> mappingMap = new HashMap<>();
232 List<CircuitPacks> circuitPackList = new ArrayList<>(device.nonnullCircuitPacks().values());
233 circuitPackList.sort(Comparator.comparing(CircuitPack::getCircuitPackName));
234 if (device.getXponder() == null) {
235 LOG.warn("{} : configuration does not contain a list of Xponders", nodeId);
236 // Variables to keep track of number of line ports and client ports
239 // TODO the treatment here inside the 2 nested for-loop is very similar to the one
240 // when device.getXponder() != null. Some code mutualization must be considered.
241 for (CircuitPacks cp : circuitPackList) {
242 String circuitPackName = cp.getCircuitPackName();
243 if (cp.getPorts() == null) {
244 LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, "found", circuitPackName);
247 List<Ports> portList = new ArrayList<>(cp.nonnullPorts().values());
248 portList.sort(Comparator.comparing(Ports::getPortName));
249 for (Ports port : portList) {
250 int[] counters = fillXpdrLcpsMaps(line, client, nodeId,
251 1, null, circuitPackName, port,
252 circuitPackList, lcpMap, mappingMap);
254 client = counters[1];
258 LOG.info("{} : configuration contains a list of xponders", nodeId);
259 for (Xponder xponder : deviceObject.get().nonnullXponder().values()) {
260 // Variables to keep track of number of line ports and client ports
263 Integer xponderNb = xponder.getXpdrNumber().toJava();
264 XpdrNodeTypes xponderType = xponder.getXpdrType();
265 for (XpdrPort xpdrPort : xponder.nonnullXpdrPort().values().stream()
266 .sorted((xp1, xp2) -> xp1.getIndex().compareTo(xp2.getIndex())).collect(Collectors.toList())) {
267 String circuitPackName = xpdrPort.getCircuitPackName();
268 String portName = xpdrPort.getPortName();
269 // If there xponder-subtree has missing circuit-packs or ports,
270 // This gives a null-pointer expection,
271 if (device.nonnullCircuitPacks().values().stream()
272 .filter(cp -> cp.getCircuitPackName().equals(circuitPackName))
273 .findFirst().isEmpty()) {
274 LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
275 nodeId, circuitPackName);
278 if (device.nonnullCircuitPacks().values().stream()
279 .filter(cp -> cp.getCircuitPackName().equals(circuitPackName))
280 .findFirst().get().nonnullPorts().values().stream()
281 .filter(p -> p.getPortName().equals(portName))
282 .findFirst().isEmpty()) {
283 LOG.warn(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
284 nodeId, portName, circuitPackName, "in the device");
287 Ports port = device.nonnullCircuitPacks().values().stream()
288 .filter(cp -> cp.getCircuitPackName().equals(circuitPackName))
289 .findFirst().get().nonnullPorts().values().stream()
290 .filter(p -> p.getPortName().equals(portName))
292 int[] counters = fillXpdrLcpsMaps(line, client, nodeId,
293 xponderNb, xponderType, circuitPackName, port,
294 circuitPackList, lcpMap, mappingMap);
296 client = counters[1];
301 if (device.getConnectionMap() == null) {
302 LOG.warn("{} : No connection-map inside device configuration", nodeId);
304 Collection<ConnectionMap> connectionMap = deviceObject.get().nonnullConnectionMap().values();
305 for (ConnectionMap cm : connectionMap) {
306 String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
307 String slcp = lcpMap.containsKey(skey) ? lcpMap.get(skey) : null;
308 Destination destination0 = cm.nonnullDestination().values().iterator().next();
309 String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName();
311 LOG.error("{} : Error in connection-map analysis for source {} and destination (CP+port) {}",
315 String dlcp = lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null;
316 Mapping mapping = mappingMap.get(slcp);
317 mappingMap.remove(slcp);
318 portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping, dlcp, null));
322 if (device.getOduSwitchingPools() != null) {
323 Collection<OduSwitchingPools> oduSwithcingPools = device.nonnullOduSwitchingPools().values();
324 List<SwitchingPoolLcp> switchingPoolList = new ArrayList<>();
325 for (OduSwitchingPools odp : oduSwithcingPools) {
326 Map<NonBlockingListKey,NonBlockingList> nbMap = new HashMap<>();
327 for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org
328 .openroadm.device.odu.switching.pools.NonBlockingList nbl : odp.nonnullNonBlockingList().values()) {
329 if (nbl.getPortList() == null) {
332 List<String> lcpList = new ArrayList<>();
333 for (PortList item : nbl.nonnullPortList().values()) {
334 String key = item.getCircuitPackName() + "+" + item.getPortName();
335 if (!lcpMap.containsKey(key)) {
336 LOG.error(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG,
337 nodeId, item.getPortName(), item.getCircuitPackName(), "to a logical connection point");
340 lcpList.add(lcpMap.get(key));
342 NonBlockingList nonBlockingList = new NonBlockingListBuilder()
343 .setNblNumber(nbl.getNblNumber())
344 .setInterconnectBandwidth(nbl.getInterconnectBandwidth())
345 .setInterconnectBandwidthUnit(nbl.getInterconnectBandwidthUnit())
348 nbMap.put(nonBlockingList.key(), nonBlockingList);
350 SwitchingPoolLcp splBldr = new SwitchingPoolLcpBuilder()
351 .setSwitchingPoolNumber(odp.getSwitchingPoolNumber())
352 .setSwitchingPoolType(SwitchingPoolTypes.forValue(odp.getSwitchingPoolType().getIntValue()))
353 .setNonBlockingList(nbMap)
355 switchingPoolList.add(splBldr);
357 postPortMapping(nodeId, null, null, null, switchingPoolList, null);
360 if (!mappingMap.isEmpty()) {
361 mappingMap.forEach((k,v) -> portMapList.add(v));
366 private boolean checkPartnerPortNotNull(Ports port) {
367 return (port.getPartnerPort() != null
368 && port.getPartnerPort().getCircuitPackName() != null
369 && port.getPartnerPort().getPortName() != null);
372 private boolean checkPartnerPortNoDir(String circuitPackName, Ports port1, Ports port2) {
373 return (checkPartnerPortNotNull(port2)
374 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
375 && port2.getPartnerPort().getPortName().equals(port1.getPortName()));
378 private boolean checkPartnerPort(String circuitPackName, Ports port1, Ports port2) {
379 return (checkPartnerPortNoDir(circuitPackName, port1, port2)
380 && ((Direction.Rx.getIntValue() == port1.getPortDirection().getIntValue()
381 && Direction.Tx.getIntValue() == port2.getPortDirection().getIntValue())
383 (Direction.Tx.getIntValue() == port1.getPortDirection().getIntValue()
384 && Direction.Rx.getIntValue() == port2.getPortDirection().getIntValue())));
388 private HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg
389 .CircuitPacks>> getSrgCps(String deviceId, Info ordmInfo) {
390 HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg
391 .CircuitPacks>> cpPerSrg = new HashMap<>();
392 // Get value for max Srg from info subtree, required for iteration
393 // if not present assume to be 20 (temporary)
394 Integer maxSrg = ordmInfo.getMaxSrgs() == null ? 20 : ordmInfo.getMaxSrgs().toJava();
395 for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) {
396 List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks> srgCps
398 LOG.debug("{} : Getting Circuitpacks for Srg Number {}", deviceId, srgCounter);
399 InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
400 .child(SharedRiskGroup.class, new SharedRiskGroupKey(Uint16.valueOf(srgCounter)));
401 Optional<SharedRiskGroup> ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
402 LogicalDatastoreType.OPERATIONAL, srgIID,
403 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
404 if (ordmSrgObject.isPresent()) {
405 srgCps.addAll(ordmSrgObject.get().nonnullCircuitPacks().values());
406 cpPerSrg.put(ordmSrgObject.get().getSrgNumber().toJava(), srgCps);
409 LOG.info(PortMappingUtils.DEVICE_HAS_LOGMSG, deviceId, cpPerSrg.size(), "SRG");
413 private boolean createPpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
414 // Creating mapping data for SRG's PP
415 HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks>> srgCps
416 = getSrgCps(nodeId, deviceInfo);
417 for (Entry<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks>>
418 srgCpEntry : srgCps.entrySet()) {
419 List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks> cpList =
420 srgCps.get(srgCpEntry.getKey());
421 List<String> keys = new ArrayList<>();
422 for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks cp : cpList) {
423 String circuitPackName = cp.getCircuitPackName();
424 InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
425 .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName));
426 Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
427 LogicalDatastoreType.OPERATIONAL, cpIID,
428 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
430 if (circuitPackObject.isEmpty()) {
431 LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
432 nodeId, circuitPackName);
435 if (circuitPackObject.get().getPorts() == null) {
436 LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, "found", circuitPackName);
440 List<Ports> portList = new ArrayList<>(circuitPackObject.get().nonnullPorts().values());
441 Collections.sort(portList, new SortPort221ByName());
443 for (Ports port : portList) {
444 String currentKey = circuitPackName + "-" + port.getPortName();
445 if (port.getPortQual() == null) {
449 if (PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) {
450 LOG.debug("{} : port {} on {} is not roadm-external" + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
451 nodeId, port.getPortName(), circuitPackName);
455 if (keys.contains(currentKey)) {
456 LOG.debug("{} : port {} on {} has already been handled" + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
457 nodeId, port.getPortName(), circuitPackName);
461 switch (port.getPortDirection()) {
464 String lcp = createLogicalConnectionPort(port, srgCpEntry.getKey(), portIndex);
465 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
466 nodeId, port.getPortName(), circuitPackName, lcp);
467 portMapList.add(createMappingObject(nodeId, port, circuitPackName, lcp));
469 keys.add(currentKey);
474 if (!checkPartnerPortNotNull(port)) {
475 LOG.info(PortMappingUtils.NO_VALID_PARTNERPORT_UNIDIR_LOGMSG
476 + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
477 nodeId, port.getPortName(), circuitPackName);
481 String lcp1 = createLogicalConnectionPort(port, srgCpEntry.getKey(), portIndex);
482 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
483 nodeId, port.getPortName(), circuitPackName, lcp1);
484 InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
485 .child(CircuitPacks.class,
486 new CircuitPacksKey(port.getPartnerPort().getCircuitPackName()))
487 .child(Ports.class, new PortsKey(port.getPartnerPort().getPortName()));
488 Optional<Ports> port2Object = this.deviceTransactionManager
489 .getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, port2ID,
490 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
491 if (port2Object.isEmpty()
492 || port2Object.get().getPortQual().getIntValue()
493 != PortQual.RoadmExternal.getIntValue()) {
494 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG
495 + PortMappingUtils.PARTNERPORT_GET_ERROR_LOGMSG,
496 nodeId, port.getPartnerPort().getPortName(),
497 port.getPartnerPort().getCircuitPackName(),
498 port.getPortName(), circuitPackName);
502 Ports port2 = port2Object.get();
503 if (!checkPartnerPort(circuitPackName, port, port2)) {
504 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG
505 + PortMappingUtils.PARTNERPORT_CONF_ERROR_LOGMSG,
506 nodeId, port2.getPortName(), port.getPartnerPort().getCircuitPackName(),
507 port.getPortName(), circuitPackName);
511 String lcp2 = createLogicalConnectionPort(port2, srgCpEntry.getKey(),portIndex);
512 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
513 nodeId, port2.getPortName(), circuitPackName, lcp2);
514 portMapList.add(createMappingObject(nodeId, port, circuitPackName, lcp1));
516 createMappingObject(nodeId ,port2, port.getPartnerPort().getCircuitPackName(), lcp2));
518 keys.add(currentKey);
519 keys.add(port.getPartnerPort().getCircuitPackName() + "-" + port2.getPortName());
523 LOG.error(PortMappingUtils.UNSUPPORTED_DIR_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
524 nodeId, port.getPortName(), circuitPackName, port.getPortDirection());
533 private String createLogicalConnectionPort(Ports port, int index, int portIndex) {
534 if (SUFFIX.containsKey(port.getPortDirection())) {
535 return String.join("-", "SRG" + index, "PP" + portIndex, SUFFIX.get(port.getPortDirection()));
537 LOG.error(PortMappingUtils.UNSUPPORTED_DIR_LOGMSG,
538 "createLogicalConnectionPort", port, "SRG" + index + "-PP" + portIndex, port.getPortDirection());
542 private Map<Integer, Degree> getDegreesMap(String deviceId, Info ordmInfo) {
543 Map<Integer, Degree> degrees = new HashMap<>();
545 // Get value for max degree from info subtree, required for iteration
546 // if not present assume to be 20 (temporary)
547 Integer maxDegree = ordmInfo.getMaxDegrees() == null ? 20 : ordmInfo.getMaxDegrees().toJava();
549 for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
550 LOG.debug("{} : Getting Connection ports for Degree Number {}", deviceId, degreeCounter);
551 InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
552 .child(Degree.class, new DegreeKey(Uint16.valueOf(degreeCounter)));
553 Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
554 LogicalDatastoreType.OPERATIONAL, deviceIID,
555 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
556 if (ordmDegreeObject.isPresent()) {
557 degrees.put(degreeCounter, ordmDegreeObject.get());
560 LOG.info(PortMappingUtils.DEVICE_HAS_LOGMSG,
561 deviceId, degrees.size(), degrees.size() <= 1 ? "degree" : "degrees");
565 private Map<Integer, List<ConnectionPorts>> getPerDegreePorts(String deviceId, Info ordmInfo) {
566 Map<Integer, List<ConnectionPorts>> conPortMap = new HashMap<>();
567 getDegreesMap(deviceId, ordmInfo).forEach(
568 (index, degree) -> conPortMap.put(index, new ArrayList<>(degree.nonnullConnectionPorts().values())));
572 private List<SharedRiskGroup> getSrgs(String deviceId, Info ordmInfo) {
573 List<SharedRiskGroup> srgs = new ArrayList<>();
575 // Get value for max Srg from info subtree, required for iteration
576 // if not present assume to be 20 (temporary)
577 Integer maxSrg = ordmInfo.getMaxSrgs() == null ? 20 : ordmInfo.getMaxSrgs().toJava();
578 for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) {
579 InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
580 .child(SharedRiskGroup.class, new SharedRiskGroupKey(Uint16.valueOf(srgCounter)));
581 Optional<SharedRiskGroup> ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
582 LogicalDatastoreType.OPERATIONAL, srgIID,
583 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
584 if (ordmSrgObject.isPresent()) {
585 srgs.add(ordmSrgObject.get());
592 private Map<String, String> getEthInterfaceList(String nodeId) {
593 LOG.info(PortMappingUtils.GETTING_ETH_LIST_LOGMSG, nodeId);
594 InstanceIdentifier<Protocols> protocoliid = InstanceIdentifier.create(OrgOpenroadmDevice.class)
595 .child(Protocols.class);
596 Optional<Protocols> protocolObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
597 LogicalDatastoreType.OPERATIONAL, protocoliid, Timeouts.DEVICE_READ_TIMEOUT,
598 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
599 if (!protocolObject.isPresent() || protocolObject.get().augmentation(Protocols1.class).getLldp() == null) {
600 LOG.warn(PortMappingUtils.PROCESSING_DONE_LOGMSG, nodeId, PortMappingUtils.CANNOT_GET_LLDP_CONF_LOGMSG);
601 return new HashMap<>();
603 Map<String, String> cpToInterfaceMap = new HashMap<>();
604 Lldp lldp = protocolObject.get().augmentation(Protocols1.class).getLldp();
605 for (PortConfig portConfig : lldp.nonnullPortConfig().values()) {
606 if (!portConfig.getAdminStatus().equals(PortConfig.AdminStatus.Txandrx)) {
609 InstanceIdentifier<Interface> interfaceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
610 .child(Interface.class, new InterfaceKey(portConfig.getIfName()));
611 Optional<Interface> interfaceObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
612 LogicalDatastoreType.OPERATIONAL, interfaceIID, Timeouts.DEVICE_READ_TIMEOUT,
613 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
614 if (!interfaceObject.isPresent() || (interfaceObject.get().getSupportingCircuitPackName() == null)) {
617 String supportingCircuitPackName = interfaceObject.get().getSupportingCircuitPackName();
618 cpToInterfaceMap.put(supportingCircuitPackName, portConfig.getIfName());
619 InstanceIdentifier<CircuitPacks> circuitPacksIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
620 .child(CircuitPacks.class, new CircuitPacksKey(supportingCircuitPackName));
621 Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(
622 nodeId, LogicalDatastoreType.OPERATIONAL, circuitPacksIID, Timeouts.DEVICE_READ_TIMEOUT,
623 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
624 if (!circuitPackObject.isPresent() || (circuitPackObject.get().getParentCircuitPack() == null)) {
627 cpToInterfaceMap.put(circuitPackObject.get().getParentCircuitPack().getCircuitPackName(),
628 portConfig.getIfName());
630 LOG.info(PortMappingUtils.PROCESSING_DONE_LOGMSG, nodeId, " - success");
631 return cpToInterfaceMap;
634 private List<CpToDegree> getCpToDegreeList(Map<Integer, Degree> degrees, Map<String, String> interfaceList) {
635 List<CpToDegree> cpToDegreeList = new ArrayList<>();
636 for (Degree degree : degrees.values()) {
637 LOG.debug("Inside CP to degree list");
638 cpToDegreeList.addAll(degree.nonnullCircuitPacks().values().stream()
639 .map(cp -> createCpToDegreeObject(cp.getCircuitPackName(),
640 degree.getDegreeNumber().toString(), interfaceList))
641 .collect(Collectors.toList()));
643 return cpToDegreeList;
646 private Map<McCapabilitiesKey, McCapabilities> getMcCapabilities(Map<Integer, Degree> degrees,
647 List<SharedRiskGroup> srgs, String nodeId) {
648 LOG.info(PortMappingUtils.GETTING_MC_CAPA_LOGMSG , nodeId, "degrees");
649 Map<McCapabilitiesKey, McCapabilities> mcCapabilities = degrees.values().stream()
650 .map(degree -> createMcCapDegreeObject(degree, nodeId))
651 .collect(Collectors.toMap(McCapabilities::key, mcc -> mcc));
652 // Add the SRG mc-capabilities
653 LOG.info(PortMappingUtils.GETTING_MC_CAPA_LOGMSG , nodeId, "SRGs");
654 mcCapabilities.putAll(srgs.stream().map(srg -> createMcCapSrgObject(srg, nodeId))
655 .collect(Collectors.toMap(McCapabilities::key, mcCapabilities2 -> mcCapabilities2)));
656 return mcCapabilities;
659 private boolean postPortMapping(String nodeId, NodeInfo nodeInfo, List<Mapping> portMapList,
660 List<CpToDegree> cp2DegreeList, List<SwitchingPoolLcp> splList,
661 Map<McCapabilitiesKey, McCapabilities> mcCapabilities) {
662 NodesBuilder nodesBldr = new NodesBuilder().withKey(new NodesKey(nodeId)).setNodeId(nodeId);
663 if (nodeInfo != null) {
664 nodesBldr.setNodeInfo(nodeInfo);
666 if (portMapList != null) {
667 Map<MappingKey, Mapping> mappingMap = new HashMap<>();
668 // No element in the list below should be null at this stage
669 for (Mapping mapping: portMapList) {
670 mappingMap.put(mapping.key(), mapping);
672 nodesBldr.setMapping(mappingMap);
674 if (cp2DegreeList != null) {
675 Map<CpToDegreeKey, CpToDegree> cpToDegreeMap = new HashMap<>();
676 // No element in the list below should be null at this stage
677 for (CpToDegree cp2Degree: cp2DegreeList) {
678 cpToDegreeMap.put(cp2Degree.key(), cp2Degree);
680 nodesBldr.setCpToDegree(cpToDegreeMap);
683 if (splList != null) {
684 Map<SwitchingPoolLcpKey,SwitchingPoolLcp> splMap = new HashMap<>();
685 // No element in the list below should be null at this stage
686 for (SwitchingPoolLcp spl: splList) {
687 splMap.put(spl.key(), spl);
689 nodesBldr.setSwitchingPoolLcp(splMap);
691 if (mcCapabilities != null) {
692 nodesBldr.setMcCapabilities(mcCapabilities);
694 Map<NodesKey,Nodes> nodesList = new HashMap<>();
695 Nodes nodes = nodesBldr.build();
696 nodesList.put(nodes.key(),nodes);
698 Network network = new NetworkBuilder().setNodes(nodesList).build();
700 final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
701 InstanceIdentifier<Network> nodesIID = InstanceIdentifier.builder(Network.class).build();
702 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodesIID, network);
703 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
707 } catch (InterruptedException | ExecutionException e) {
708 LOG.warn("{} : Failed to post {}", nodeId, network, e);
713 private CpToDegree createCpToDegreeObject(String circuitPackName, String degreeNumber,
714 Map<String, String> interfaceList) {
715 return new CpToDegreeBuilder()
716 .withKey(new CpToDegreeKey(circuitPackName))
717 .setCircuitPackName(circuitPackName)
718 .setDegreeNumber(Uint32.valueOf(degreeNumber))
719 .setInterfaceName(interfaceList.get(circuitPackName)).build();
722 private McCapabilities createMcCapDegreeObject(Degree degree, String nodeId) {
723 String mcNodeName = PortMappingUtils.degreeTtpNodeName(degree.getDegreeNumber().toString(), null);
724 McCapabilitiesBuilder mcCapabilitiesBuilder = new McCapabilitiesBuilder()
725 .withKey(new McCapabilitiesKey(mcNodeName))
726 .setMcNodeName(mcNodeName);
727 if (degree.getMcCapabilities() == null) {
728 LOG.warn(PortMappingUtils.NO_MC_LOGMSG, nodeId, "degree", degree.getDegreeNumber());
729 mcCapabilitiesBuilder
730 .setCenterFreqGranularity(FrequencyGHz.getDefaultInstance("50"))
731 .setSlotWidthGranularity(FrequencyGHz.getDefaultInstance("50"));
733 mcCapabilitiesBuilder
734 .setCenterFreqGranularity(FrequencyGHz.getDefaultInstance(degree.getMcCapabilities()
735 .getCenterFreqGranularity().getValue().toString()))
736 .setSlotWidthGranularity(FrequencyGHz.getDefaultInstance(degree.getMcCapabilities()
737 .getSlotWidthGranularity().getValue().toString()));
739 return mcCapabilitiesBuilder.build();
742 private McCapabilities createMcCapSrgObject(SharedRiskGroup srg, String nodeId) {
743 String mcNodeName = "SRG" + srg.getSrgNumber().toString() + "-PP";
744 McCapabilitiesBuilder mcCapabilitiesBuilder = new McCapabilitiesBuilder()
745 .withKey(new McCapabilitiesKey(mcNodeName))
746 .setMcNodeName(mcNodeName);
747 if (srg.getMcCapabilities() == null) {
748 LOG.warn(PortMappingUtils.NO_MC_LOGMSG, nodeId, "SRG", srg.getSrgNumber());
749 mcCapabilitiesBuilder
750 .setCenterFreqGranularity(FrequencyGHz.getDefaultInstance("50"))
751 .setSlotWidthGranularity(FrequencyGHz.getDefaultInstance("50"));
753 mcCapabilitiesBuilder
754 .setCenterFreqGranularity(FrequencyGHz.getDefaultInstance(srg.getMcCapabilities()
755 .getCenterFreqGranularity().getValue().toString()))
756 .setSlotWidthGranularity(FrequencyGHz.getDefaultInstance(srg.getMcCapabilities()
757 .getSlotWidthGranularity().getValue().toString()));
759 return mcCapabilitiesBuilder.build();
762 private Mapping createMappingObject(String nodeId, Ports port, String circuitPackName,
763 String logicalConnectionPoint) {
764 MappingBuilder mpBldr = new MappingBuilder()
765 .withKey(new MappingKey(logicalConnectionPoint))
766 .setLogicalConnectionPoint(logicalConnectionPoint)
767 .setSupportingCircuitPackName(circuitPackName)
768 .setSupportingPort(port.getPortName())
769 .setPortDirection(port.getPortDirection().getName());
770 if (port.getAdministrativeState() != null) {
771 mpBldr.setPortAdminState(port.getAdministrativeState().name());
773 if (port.getOperationalState() != null) {
774 mpBldr.setPortOperState(port.getOperationalState().name());
777 if ((port.getInterfaces() == null)
778 || (!logicalConnectionPoint.contains(StringConstants.TTP_TOKEN)
779 && !logicalConnectionPoint.contains(StringConstants.NETWORK_TOKEN))) {
780 return mpBldr.build();
782 mpBldr = updateMappingInterfaces(nodeId, mpBldr, port);
783 return mpBldr.build();
786 private Mapping updateMappingObject(String nodeId, Ports port, Mapping oldmapping) {
787 MappingBuilder mpBldr = new MappingBuilder(oldmapping);
788 updateMappingStates(mpBldr, port, oldmapping);
789 if ((port.getInterfaces() == null)
790 || (!oldmapping.getLogicalConnectionPoint().contains(StringConstants.TTP_TOKEN)
791 && !oldmapping.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN))) {
792 return mpBldr.build();
794 // Get interfaces provisioned on the port
795 mpBldr = updateMappingInterfaces(nodeId, mpBldr, port);
796 return mpBldr.build();
799 private MappingBuilder updateMappingStates(MappingBuilder mpBldr, Ports port, Mapping oldmapping) {
800 if (port.getAdministrativeState() != null
801 && !port.getAdministrativeState().getName().equals(oldmapping.getPortAdminState())) {
802 mpBldr.setPortAdminState(port.getAdministrativeState().name());
804 if (port.getOperationalState() != null
805 && !port.getOperationalState().getName().equals(oldmapping.getPortOperState())) {
806 mpBldr.setPortOperState(port.getOperationalState().name());
811 private MappingBuilder updateMappingInterfaces(String nodeId, MappingBuilder mpBldr, Ports port) {
812 for (Interfaces interfaces : port.getInterfaces()) {
814 Optional<Interface> openRoadmInterface = this.openRoadmInterfaces.getInterface(nodeId,
815 interfaces.getInterfaceName());
816 if (!openRoadmInterface.isPresent()) {
817 LOG.warn("{} : Interface {} was null!", nodeId, interfaces.getInterfaceName());
820 LOG.debug("{} : interface get from device is {} and of type {}",
821 nodeId, openRoadmInterface.get().getName(), openRoadmInterface.get().getType());
822 Class<? extends InterfaceType> interfaceType
823 = (Class<? extends InterfaceType>) openRoadmInterface.get().getType();
824 // Check if interface type is OMS or OTS
825 if (interfaceType.equals(OpenROADMOpticalMultiplex.class)) {
826 mpBldr.setSupportingOms(interfaces.getInterfaceName());
828 if (interfaceType.equals(OpticalTransport.class)) {
829 mpBldr.setSupportingOts(interfaces.getInterfaceName());
831 if (interfaceType.equals(OtnOdu.class)) {
832 mpBldr.setSupportingOdu4(interfaces.getInterfaceName());
834 } catch (OpenRoadmInterfaceException ex) {
835 LOG.warn("{} : Error while getting interface {} - ", nodeId, interfaces.getInterfaceName(), ex);
841 private Mapping createXpdrMappingObject(String nodeId, Ports port, String circuitPackName,
842 String logicalConnectionPoint, String partnerLcp, Mapping mapping, String connectionMapLcp,
843 XpdrNodeTypes xpdrNodeType) {
845 if (mapping != null && connectionMapLcp != null) {
846 // update existing mapping
847 return new MappingBuilder(mapping).setConnectionMapLcp(connectionMapLcp).build();
850 // create a new mapping
851 String nodeIdLcp = nodeId + "-" + logicalConnectionPoint;
852 MappingBuilder mpBldr = new MappingBuilder()
853 .withKey(new MappingKey(logicalConnectionPoint))
854 .setLogicalConnectionPoint(logicalConnectionPoint)
855 .setSupportingCircuitPackName(circuitPackName)
856 .setSupportingPort(port.getPortName())
857 .setPortDirection(port.getPortDirection().getName())
858 .setLcpHashVal(PortMappingUtils.fnv1size64(nodeIdLcp));
859 if (port.getPortQual() != null) {
860 mpBldr.setPortQual(port.getPortQual().getName());
862 if (xpdrNodeType != null) {
863 mpBldr.setXponderType(
864 org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.XpdrNodeTypes.forValue(
865 xpdrNodeType.getIntValue()));
867 if (partnerLcp != null) {
868 mpBldr.setPartnerLcp(partnerLcp);
870 if (port.getSupportedInterfaceCapability() != null) {
871 List<Class<? extends org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327
872 .SupportedIfCapability>> supportedIntf = new ArrayList<>();
873 for (Class<? extends SupportedIfCapability> sup: port.getSupportedInterfaceCapability()) {
874 supportedIntf.add(MappingUtilsImpl.convertSupIfCapa(sup.getSimpleName()));
876 mpBldr.setSupportedInterfaceCapability(supportedIntf);
878 if (port.getAdministrativeState() != null) {
879 mpBldr.setPortAdminState(port.getAdministrativeState().name());
881 if (port.getOperationalState() != null) {
882 mpBldr.setPortOperState(port.getOperationalState().name());
884 return mpBldr.build();
887 private Ports getPort2(Ports port, String nodeId, String circuitPackName, StringBuilder circuitPackName2,
888 //circuitPackName2 will be updated by reference contrary to circuitPackName
889 List<CircuitPacks> circuitPackList, Map<String, String> lcpMap) {
890 if (!checkPartnerPortNotNull(port)) {
891 LOG.warn("{} : port {} on {} - Error in the configuration ", nodeId, port.getPortName(), circuitPackName);
894 if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) {
897 Optional<CircuitPacks> cpOpt = circuitPackList.stream()
899 cP -> cP.getCircuitPackName().equals(port.getPartnerPort().getCircuitPackName()))
901 if (!cpOpt.isPresent()) {
902 LOG.error("{} : Error fetching circuit-pack {}", nodeId, port.getPartnerPort().getCircuitPackName());
905 Optional<Ports> poOpt = cpOpt.get().nonnullPorts().values().stream()
906 .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName()))
908 if (!poOpt.isPresent()) {
909 LOG.error("{} : Error fetching port {} on {}",
910 nodeId, port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName());
913 Ports port2 = poOpt.get();
914 circuitPackName2.append(cpOpt.get().getCircuitPackName());
915 if (!checkPartnerPort(circuitPackName, port, port2)) {
916 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
917 nodeId, port2.getPortName(), circuitPackName2, port.getPortName(), circuitPackName);
924 private void putXpdrLcpsInMaps(int line, String nodeId,
925 Integer xponderNb, XpdrNodeTypes xponderType,
926 String circuitPackName, String circuitPackName2, Ports port, Ports port2,
927 Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
929 PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, line, StringConstants.NETWORK_TOKEN);
930 if (lcpMap.containsKey(lcp1)) {
931 LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "add", lcp1 + " - already exist");
935 PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, line + 1, StringConstants.NETWORK_TOKEN);
936 if (lcpMap.containsKey(lcp2)) {
937 LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "add", lcp2 + " - already exist");
940 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp1);
941 lcpMap.put(circuitPackName2 + '+' + port2.getPortName(), lcp2);
943 createXpdrMappingObject(nodeId, port, circuitPackName, lcp1, lcp2, null, null, xponderType));
945 createXpdrMappingObject(nodeId, port2, circuitPackName2, lcp2, lcp1, null, null, xponderType));
949 private int[] fillXpdrLcpsMaps(int line, int client, String nodeId,
950 Integer xponderNb, XpdrNodeTypes xponderType,
951 String circuitPackName, Ports port,
952 List<CircuitPacks> circuitPackList, Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
953 if (port.getPortQual() == null) {
954 LOG.warn("{} : port {} on {} - PortQual was not found", nodeId, port.getPortName(), circuitPackName);
955 return new int[] {line, client};
958 switch (port.getPortQual()) {
963 PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, client, StringConstants.CLIENT_TOKEN);
964 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp0);
966 createXpdrMappingObject(nodeId, port, circuitPackName, lcp0, null, null, null, null));
972 line = fillXpdrNetworkLcpsMaps(line, nodeId,
973 xponderNb, xponderType,
974 circuitPackName, port,
975 circuitPackList, lcpMap, mappingMap);
979 LOG.error("{} : port {} on {} - unsupported PortQual {}",
980 nodeId, port.getPortName(), circuitPackName, port.getPortQual());
982 return new int[] {line, client};
985 private int fillXpdrNetworkLcpsMaps(int line, String nodeId,
986 Integer xponderNb, XpdrNodeTypes xponderType,
987 String circuitPackName, Ports port,
988 List<CircuitPacks> circuitPackList, Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
990 switch (port.getPortDirection()) {
994 PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, line, StringConstants.NETWORK_TOKEN);
995 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp);
997 createXpdrMappingObject(nodeId, port, circuitPackName, lcp, null, null, null, xponderType));
1003 StringBuilder circuitPackName2 = new StringBuilder();
1004 Ports port2 = getPort2(port, nodeId, circuitPackName, circuitPackName2,
1005 circuitPackList, lcpMap);
1007 if (port2 == null) {
1008 //key already present or an error occured and was logged
1012 putXpdrLcpsInMaps(line, nodeId, xponderNb, xponderType,
1013 circuitPackName, circuitPackName2.toString(), port, port2,
1014 lcpMap, mappingMap);
1019 LOG.error(PortMappingUtils.UNSUPPORTED_DIR_LOGMSG,
1020 nodeId, port.getPortName(), circuitPackName, port.getPortDirection());
1026 private boolean createMcCapabilitiesList(String nodeId, Info deviceInfo,
1027 Map<McCapabilitiesKey, McCapabilities> mcCapabilitiesMap) {
1028 Map<Integer, Degree> degrees = getDegreesMap(nodeId, deviceInfo);
1029 List<SharedRiskGroup> srgs = getSrgs(nodeId, deviceInfo);
1030 mcCapabilitiesMap.putAll(getMcCapabilities(degrees, srgs, nodeId));
1034 private boolean createTtpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
1035 // Creating mapping data for degree TTP's
1036 Map<Integer, Degree> degrees = getDegreesMap(nodeId, deviceInfo);
1037 Map<String, String> interfaceList = getEthInterfaceList(nodeId);
1038 List<CpToDegree> cpToDegreeList = getCpToDegreeList(degrees, interfaceList);
1039 LOG.info("{} : Map looks like this {}", nodeId, interfaceList);
1040 postPortMapping(nodeId, null, null, cpToDegreeList, null, null);
1042 Map<Integer, List<ConnectionPorts>> connectionPortMap = getPerDegreePorts(nodeId, deviceInfo);
1043 for (Entry<Integer, List<ConnectionPorts>> cpMapEntry : connectionPortMap.entrySet()) {
1044 switch (connectionPortMap.get(cpMapEntry.getKey()).size()) {
1046 // port is bidirectional
1047 String cpName = connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName();
1048 InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
1049 .child(CircuitPacks.class, new CircuitPacksKey(cpName))
1051 new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName()));
1052 LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG,
1053 nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cpName);
1054 Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
1055 LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
1056 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1057 if (!portObject.isPresent()) {
1058 LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG,
1059 nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cpName);
1062 Ports port = portObject.get();
1063 if (port.getPortQual() == null) {
1066 if (PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) {
1067 LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTQUAL_ERROR_LOGMSG,
1068 nodeId, port.getPortName(), cpName);
1071 if (Direction.Bidirectional.getIntValue() != port.getPortDirection().getIntValue()) {
1072 LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTDIR_ERROR_LOGMSG,
1073 nodeId, port.getPortName(), cpName);
1077 String logicalConnectionPoint =
1078 PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(), "TXRX");
1079 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
1080 nodeId, port.getPortName(), cpName, logicalConnectionPoint);
1081 portMapList.add(createMappingObject(nodeId, port, cpName, logicalConnectionPoint));
1084 // ports are unidirectionals
1085 String cp1Name = connectionPortMap.get(cpMapEntry.getKey()).get(0).getCircuitPackName();
1086 String cp2Name = connectionPortMap.get(cpMapEntry.getKey()).get(1).getCircuitPackName();
1087 InstanceIdentifier<Ports> port1ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
1088 .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
1090 new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName()));
1091 LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG,
1092 nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cp1Name);
1093 Optional<Ports> port1Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
1094 LogicalDatastoreType.OPERATIONAL, port1ID, Timeouts.DEVICE_READ_TIMEOUT,
1095 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1096 InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
1097 .child(CircuitPacks.class, new CircuitPacksKey(cp2Name))
1099 new PortsKey(connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName()));
1100 LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG,
1101 nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName(), cp2Name);
1102 Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
1103 LogicalDatastoreType.OPERATIONAL, port2ID, Timeouts.DEVICE_READ_TIMEOUT,
1104 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1105 if (!port1Object.isPresent() || !port2Object.isPresent()) {
1106 LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG,
1107 nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(0).getPortName(), cp1Name);
1110 if (!port2Object.isPresent()) {
1111 LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG,
1112 nodeId, connectionPortMap.get(cpMapEntry.getKey()).get(1).getPortName(), cp2Name);
1116 Ports port1 = port1Object.get();
1117 Ports port2 = port2Object.get();
1118 if (port1.getPortQual() == null || port2.getPortQual() == null) {
1121 if (PortQual.RoadmExternal.getIntValue() != port1.getPortQual().getIntValue()) {
1122 LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTQUAL_ERROR_LOGMSG,
1123 nodeId, port1.getPortName(), cp1Name);
1126 if (PortQual.RoadmExternal.getIntValue() != port2.getPortQual().getIntValue()) {
1127 LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTQUAL_ERROR_LOGMSG,
1128 nodeId, port2.getPortName(), cp2Name);
1132 if (!checkPartnerPort(cp1Name, port1, port2)) {
1133 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
1134 nodeId, port2.getPortName(), cp2Name, port1.getPortName(), cp1Name);
1137 // Directions checks are the same for cp1 and cp2, no need to check them twice.
1138 if (!checkPartnerPortNoDir(cp2Name, port2, port1)) {
1139 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
1140 nodeId, port1.getPortName(), cp1Name, port2.getPortName(), cp2Name);
1144 String logicalConnectionPoint1 = PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(),
1145 port1.getPortDirection().getName().toUpperCase(Locale.getDefault()));
1146 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
1147 nodeId, port1.getPortName(), cp1Name, logicalConnectionPoint1);
1148 portMapList.add(createMappingObject(nodeId, port1, cp1Name, logicalConnectionPoint1));
1149 String logicalConnectionPoint2 = PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(),
1150 port2.getPortDirection().getName().toUpperCase(Locale.getDefault()));
1151 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
1152 nodeId, port2.getPortName(), cp2Name, logicalConnectionPoint2);
1153 portMapList.add(createMappingObject(nodeId, port2, cp2Name, logicalConnectionPoint2));
1156 LOG.error("{} : Number of connection port for DEG{} is incorrect", nodeId, cpMapEntry.getKey());
1163 private NodeInfo createNodeInfo(Info deviceInfo) {
1165 if (deviceInfo.getNodeType() == null) {
1166 // TODO make mandatory in yang
1167 LOG.error("Node type field is missing");
1171 NodeInfoBuilder nodeInfoBldr = new NodeInfoBuilder()
1172 .setOpenroadmVersion(OpenroadmNodeVersion._221)
1173 .setNodeType(NodeTypes.forValue(deviceInfo.getNodeType().getIntValue()));
1174 if (deviceInfo.getClli() != null && !deviceInfo.getClli().isEmpty()) {
1175 nodeInfoBldr.setNodeClli(deviceInfo.getClli());
1177 nodeInfoBldr.setNodeClli("defaultCLLI");
1179 if (deviceInfo.getModel() != null) {
1180 nodeInfoBldr.setNodeModel(deviceInfo.getModel());
1182 if (deviceInfo.getVendor() != null) {
1183 nodeInfoBldr.setNodeVendor(deviceInfo.getVendor());
1185 if (deviceInfo.getIpAddress() != null) {
1186 nodeInfoBldr.setNodeIpAddress(deviceInfo.getIpAddress());
1189 return nodeInfoBldr.build();