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.Collections;
14 import java.util.Comparator;
15 import java.util.HashMap;
16 import java.util.List;
17 import java.util.Locale;
19 import java.util.Map.Entry;
20 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;
105 private static final Set<Integer> TXRX_SET = Set.of(Direction.Tx.getIntValue(), Direction.Rx.getIntValue());
107 private final DataBroker dataBroker;
108 private final DeviceTransactionManager deviceTransactionManager;
109 private final OpenRoadmInterfaces openRoadmInterfaces;
115 Direction.Bidirectional, "TXRX");
118 public PortMappingVersion221(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
119 OpenRoadmInterfaces openRoadmInterfaces) {
120 this.dataBroker = dataBroker;
121 this.deviceTransactionManager = deviceTransactionManager;
122 this.openRoadmInterfaces = openRoadmInterfaces;
125 public boolean createMappingData(String nodeId) {
126 LOG.info(PortMappingUtils.CREATE_MAPPING_DATA_LOGMSG, nodeId, "2.2.1");
127 List<Mapping> portMapList = new ArrayList<>();
128 Map<McCapabilitiesKey, McCapabilities> mcCapabilities = new HashMap<>();
129 InstanceIdentifier<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
130 Optional<Info> deviceInfoOptional = this.deviceTransactionManager.getDataFromDevice(
131 nodeId, LogicalDatastoreType.OPERATIONAL, infoIID,
132 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
133 if (deviceInfoOptional.isEmpty()) {
134 LOG.warn(PortMappingUtils.DEVICE_HAS_LOGMSG, nodeId, "no info", "subtree");
137 Info deviceInfo = deviceInfoOptional.get();
138 NodeInfo nodeInfo = createNodeInfo(deviceInfo);
139 if (nodeInfo == null) {
142 postPortMapping(nodeId, nodeInfo, null, null, null, null);
144 switch (deviceInfo.getNodeType()) {
147 // Get TTP port mapping
148 if (!createTtpPortMapping(nodeId, deviceInfo, portMapList)) {
149 // return false if mapping creation for TTP's failed
150 LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.CREATE, "TTP's");
154 // Get PP port mapping
155 if (!createPpPortMapping(nodeId, deviceInfo, portMapList)) {
156 // return false if mapping creation for PP's failed
157 LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.CREATE, "PP's");
160 // Get MC capabilities
161 if (!createMcCapabilitiesList(nodeId, deviceInfo, mcCapabilities)) {
162 // return false if MC capabilites failed
163 LOG.warn(PortMappingUtils.UNABLE_MC_CAPA_LOGMSG, nodeId);
168 if (!createXpdrPortMapping(nodeId, portMapList)) {
169 LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.CREATE, "Xponder");
174 LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG,
175 nodeId, PortMappingUtils.CREATE, deviceInfo.getNodeType() + " - unknown nodetype");
179 return postPortMapping(nodeId, nodeInfo, portMapList, null, null, mcCapabilities);
182 public boolean updateMapping(String nodeId, Mapping oldMapping) {
183 if (nodeId == null) {
184 LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, "node id null" , PortMappingUtils.UPDATE, "a null value");
187 if (oldMapping == null) {
188 LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, PortMappingUtils.UPDATE, "a null value");
191 InstanceIdentifier<Ports> portId = InstanceIdentifier.create(OrgOpenroadmDevice.class)
192 .child(CircuitPacks.class, new CircuitPacksKey(oldMapping.getSupportingCircuitPackName()))
193 .child(Ports.class, new PortsKey(oldMapping.getSupportingPort()));
195 Ports port = deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL,
196 portId, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT).get();
197 Mapping newMapping = updateMappingObject(nodeId, port, oldMapping);
198 LOG.debug(PortMappingUtils.UPDATE_MAPPING_LOGMSG,
199 nodeId, oldMapping, oldMapping.getLogicalConnectionPoint(), newMapping);
200 final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
201 InstanceIdentifier<Mapping> mapIID = InstanceIdentifier.create(Network.class)
202 .child(Nodes.class, new NodesKey(nodeId))
203 .child(Mapping.class, new MappingKey(oldMapping.getLogicalConnectionPoint()));
204 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, mapIID, newMapping);
205 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
208 } catch (InterruptedException | ExecutionException e) {
209 LOG.error(PortMappingUtils.UNABLE_MAPPING_LOGMSG,
210 nodeId, PortMappingUtils.UPDATE, oldMapping.getLogicalConnectionPoint(), e);
215 private boolean createXpdrPortMapping(String nodeId, List<Mapping> portMapList) {
216 // Creating for Xponder Line and Client Ports
217 OrgOpenroadmDevice device = getXpdrDevice(nodeId);
218 if (device == null) {
221 Map<String, String> lcpMap = new HashMap<>();
222 Map<String, Mapping> mappingMap = new HashMap<>();
223 getXpdrMaps(device, nodeId, lcpMap, mappingMap);
224 if (device.getConnectionMap() == null) {
225 LOG.warn(PortMappingUtils.NO_CONMAP_LOGMSG, nodeId);
227 for (ConnectionMap cm : device.nonnullConnectionMap().values()) {
228 String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
229 Destination destination0 = cm.nonnullDestination().values().iterator().next();
230 String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName();
231 if (!lcpMap.containsKey(skey)) {
232 LOG.error(PortMappingUtils.CONMAP_ISSUE_LOGMSG, nodeId, skey, dkey);
235 String slcp = lcpMap.get(skey);
236 Mapping mapping = mappingMap.get(slcp);
237 mappingMap.remove(slcp);
238 portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping,
240 lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null,
244 if (device.getOduSwitchingPools() != null) {
245 postPortMapping(nodeId, null, null, null, getSwitchingPoolList(device, lcpMap, nodeId), null);
247 mappingMap.forEach((k,v) -> portMapList.add(v));
251 private OrgOpenroadmDevice getXpdrDevice(String nodeId) {
252 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
253 Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
254 LogicalDatastoreType.OPERATIONAL, deviceIID,
255 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
256 if (deviceObject.isEmpty()) {
257 LOG.error(PortMappingUtils.CANNOT_GET_DEV_CONF_LOGMSG, nodeId);
260 OrgOpenroadmDevice device = deviceObject.get();
261 if (device.getCircuitPacks() == null) {
262 LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, PortMappingUtils.FOUND);
268 private void getXpdrMaps(OrgOpenroadmDevice device, String nodeId,
269 Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
270 List<CircuitPacks> circuitPackList = new ArrayList<>(device.nonnullCircuitPacks().values());
271 circuitPackList.sort(Comparator.comparing(CircuitPack::getCircuitPackName));
272 if (device.getXponder() == null) {
273 LOG.warn(PortMappingUtils.XPDR_LIST_IN_CONF_LOGMSG, nodeId, "not found");
274 // Variables to keep track of number of line ports and client ports
277 // TODO the treatment here inside the 2 nested for-loop is very similar to the one
278 // when device.getXponder() != null. Some code mutualization must be considered.
279 for (CircuitPacks cp : circuitPackList) {
280 String circuitPackName = cp.getCircuitPackName();
281 if (cp.getPorts() == null) {
282 LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, PortMappingUtils.FOUND, circuitPackName);
285 List<Ports> portList = new ArrayList<>(cp.nonnullPorts().values());
286 portList.sort(Comparator.comparing(Ports::getPortName));
287 for (Ports port : portList) {
288 int[] counters = fillXpdrLcpsMaps(line, client, nodeId,
289 1, XpdrNodeTypes.Tpdr, circuitPackName, port,
290 circuitPackList, lcpMap, mappingMap);
292 client = counters[1];
296 LOG.info(PortMappingUtils.XPDR_LIST_IN_CONF_LOGMSG, nodeId, PortMappingUtils.FOUND);
297 for (Xponder xponder : device.nonnullXponder().values()) {
298 // Variables to keep track of number of line ports and client ports
301 Integer xponderNb = xponder.getXpdrNumber().toJava();
302 XpdrNodeTypes xponderType = xponder.getXpdrType();
303 for (XpdrPort xpdrPort : xponder.nonnullXpdrPort().values().stream()
304 .sorted((xp1, xp2) -> xp1.getIndex().compareTo(xp2.getIndex())).collect(Collectors.toList())) {
305 Ports port = getXpdrPorts(device, xpdrPort, nodeId);
309 int[] counters = fillXpdrLcpsMaps(line, client, nodeId,
310 xponderNb, xponderType, xpdrPort.getCircuitPackName(), port,
311 circuitPackList, lcpMap, mappingMap);
313 client = counters[1];
319 private Ports getXpdrPorts(OrgOpenroadmDevice device, XpdrPort xpdrPort, String nodeId) {
320 String circuitPackName = xpdrPort.getCircuitPackName();
321 String portName = xpdrPort.getPortName();
322 // If there xponder-subtree has missing circuit-packs or ports,
323 // This gives a null-pointer expection,
324 Optional<CircuitPacks> cpList = device.nonnullCircuitPacks().values().stream()
325 .filter(cp -> cp.getCircuitPackName().equals(circuitPackName)).findFirst();
326 if (cpList.isEmpty()) {
327 LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
328 nodeId, circuitPackName);
331 Optional<Ports> portsList = cpList.get().nonnullPorts().values().stream()
332 .filter(p -> p.getPortName().equals(portName)).findFirst();
333 if (portsList.isEmpty()) {
334 LOG.warn(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
335 nodeId, portName, circuitPackName, "in the device");
338 return portsList.get();
341 private List<SwitchingPoolLcp> getSwitchingPoolList(OrgOpenroadmDevice device,
342 Map<String, String> lcpMap, String nodeId) {
343 List<SwitchingPoolLcp> switchingPoolList = new ArrayList<>();
344 for (OduSwitchingPools odp : device.nonnullOduSwitchingPools().values()) {
345 Map<NonBlockingListKey,NonBlockingList> nbMap = new HashMap<>();
346 for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org
347 .openroadm.device.odu.switching.pools.NonBlockingList nbl : odp.nonnullNonBlockingList().values()) {
348 if (nbl.getPortList() == null) {
351 List<String> lcpList = new ArrayList<>();
352 for (PortList item : nbl.nonnullPortList().values()) {
353 String key = item.getCircuitPackName() + "+" + item.getPortName();
354 if (!lcpMap.containsKey(key)) {
355 LOG.error(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG,
356 nodeId, item.getPortName(), item.getCircuitPackName(), "to a logical connection point");
359 lcpList.add(lcpMap.get(key));
361 NonBlockingList nonBlockingList = new NonBlockingListBuilder()
362 .setNblNumber(nbl.getNblNumber())
363 .setInterconnectBandwidth(nbl.getInterconnectBandwidth())
364 .setInterconnectBandwidthUnit(nbl.getInterconnectBandwidthUnit())
367 nbMap.put(nonBlockingList.key(), nonBlockingList);
369 switchingPoolList.add(
370 new SwitchingPoolLcpBuilder()
371 .setSwitchingPoolNumber(odp.getSwitchingPoolNumber())
372 .setSwitchingPoolType(SwitchingPoolTypes.forValue(odp.getSwitchingPoolType().getIntValue()))
373 .setNonBlockingList(nbMap)
376 return switchingPoolList;
379 private boolean checkPartnerPortNotNull(Ports port) {
380 return (port.getPartnerPort() != null
381 && port.getPartnerPort().getCircuitPackName() != null
382 && port.getPartnerPort().getPortName() != null);
385 private boolean checkPartnerPortNoDir(String circuitPackName, Ports port1, Ports port2) {
386 return (checkPartnerPortNotNull(port2)
387 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
388 && port2.getPartnerPort().getPortName().equals(port1.getPortName()));
391 private boolean checkPartnerPort(String circuitPackName, Ports port1, Ports port2) {
392 return checkPartnerPortNoDir(circuitPackName, port1, port2)
393 && Set.of(port1.getPortDirection().getIntValue(), port2.getPortDirection().getIntValue())
398 private HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg
399 .CircuitPacks>> getSrgCps(String deviceId, Info ordmInfo) {
400 HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg
401 .CircuitPacks>> cpPerSrg = new HashMap<>();
402 // Get value for max Srg from info subtree, required for iteration
403 // if not present assume to be 20 (temporary)
404 Integer maxSrg = ordmInfo.getMaxSrgs() == null ? 20 : ordmInfo.getMaxSrgs().toJava();
405 for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) {
406 List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks> srgCps
408 LOG.debug(PortMappingUtils.GETTING_CP_LOGMSG, deviceId, srgCounter);
409 InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
410 .child(SharedRiskGroup.class, new SharedRiskGroupKey(Uint16.valueOf(srgCounter)));
411 Optional<SharedRiskGroup> ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
412 LogicalDatastoreType.OPERATIONAL, srgIID,
413 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
414 if (ordmSrgObject.isPresent()) {
415 srgCps.addAll(ordmSrgObject.get().nonnullCircuitPacks().values());
416 cpPerSrg.put(ordmSrgObject.get().getSrgNumber().toJava(), srgCps);
419 LOG.info(PortMappingUtils.DEVICE_HAS_LOGMSG, deviceId, cpPerSrg.size(), "SRG");
423 private boolean createPpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
424 // Creating mapping data for SRG's PP
425 for (Entry<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks>>
426 srgCpEntry : getSrgCps(nodeId, deviceInfo).entrySet()) {
427 List<String> keys = new ArrayList<>();
428 for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks
429 cp : srgCpEntry.getValue()) {
430 String circuitPackName = cp.getCircuitPackName();
431 List<Ports> portList = getPortList(circuitPackName, nodeId);
432 Collections.sort(portList, new SortPort221ByName());
434 for (Ports port : portList) {
435 if (!checkPortQual(port, circuitPackName, nodeId)) {
438 String currentKey = circuitPackName + "-" + port.getPortName();
439 if (keys.contains(currentKey)) {
440 LOG.debug(PortMappingUtils.PORT_ALREADY_HANDLED_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
441 nodeId, port.getPortName(), circuitPackName);
444 switch (port.getPortDirection()) {
446 String lcp = createLogicalConnectionPort(port, srgCpEntry.getKey(), portIndex);
447 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
448 nodeId, port.getPortName(), circuitPackName, lcp);
449 portMapList.add(createMappingObject(nodeId, port, circuitPackName, lcp));
451 keys.add(currentKey);
455 Ports port2 = getPartnerPort(port, circuitPackName, nodeId);
459 String lcp1 = createLogicalConnectionPort(port, srgCpEntry.getKey(), portIndex);
460 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
461 nodeId, port.getPortName(), circuitPackName, lcp1);
462 String lcp2 = createLogicalConnectionPort(port2, srgCpEntry.getKey(),portIndex);
463 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
464 nodeId, port2.getPortName(), circuitPackName, lcp2);
465 portMapList.add(createMappingObject(nodeId, port, circuitPackName, lcp1));
467 createMappingObject(nodeId ,port2, port.getPartnerPort().getCircuitPackName(), lcp2));
469 keys.add(currentKey);
470 keys.add(port.getPartnerPort().getCircuitPackName() + "-" + port2.getPortName());
473 LOG.error(PortMappingUtils.UNSUPPORTED_DIR_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
474 nodeId, port.getPortName(), circuitPackName, port.getPortDirection());
482 private Ports getPartnerPort(Ports port, String circuitPackName, String nodeId) {
483 if (!checkPartnerPortNotNull(port)) {
484 LOG.info(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
485 nodeId, port.getPortName(), circuitPackName);
488 InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
489 .child(CircuitPacks.class, new CircuitPacksKey(port.getPartnerPort().getCircuitPackName()))
490 .child(Ports.class, new PortsKey(port.getPartnerPort().getPortName()));
491 Optional<Ports> port2Object = this.deviceTransactionManager
492 .getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, port2ID,
493 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
494 if (port2Object.isEmpty()
495 || port2Object.get().getPortQual().getIntValue() != PortQual.RoadmExternal.getIntValue()) {
496 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG + PortMappingUtils.PARTNERPORT_GET_ERROR_LOGMSG,
497 nodeId, port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName(),
498 port.getPortName(), circuitPackName);
501 Ports port2 = port2Object.get();
502 if (!checkPartnerPort(circuitPackName, port, port2)) {
503 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG + PortMappingUtils.PARTNERPORT_CONF_ERROR_LOGMSG,
504 nodeId, port2.getPortName(), port.getPartnerPort().getCircuitPackName(),
505 port.getPortName(), circuitPackName);
506 //TODO check if we really needed to increment portIndex in this condition
507 // if yes this block should not be in getPartnerPort and must move back to createPpPortMapping
513 private List<Ports> getPortList(String circuitPackName, String nodeId) {
514 InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
515 .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName));
516 Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
517 LogicalDatastoreType.OPERATIONAL, cpIID,
518 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
519 if (circuitPackObject.isEmpty()) {
520 LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
521 nodeId, circuitPackName);
522 return new ArrayList<>();
524 if (circuitPackObject.get().getPorts() == null) {
525 LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, PortMappingUtils.FOUND, circuitPackName);
526 return new ArrayList<>();
528 return new ArrayList<>(circuitPackObject.get().nonnullPorts().values());
531 private String createLogicalConnectionPort(Ports port, int index, int portIndex) {
532 if (SUFFIX.containsKey(port.getPortDirection())) {
533 return String.join("-", "SRG" + index, "PP" + portIndex, SUFFIX.get(port.getPortDirection()));
535 LOG.error(PortMappingUtils.UNSUPPORTED_DIR_LOGMSG,
536 "createLogicalConnectionPort", port, "SRG" + index + "-PP" + portIndex, port.getPortDirection());
540 private Map<Integer, Degree> getDegreesMap(String deviceId, Info ordmInfo) {
541 Map<Integer, Degree> degrees = new HashMap<>();
543 // Get value for max degree from info subtree, required for iteration
544 // if not present assume to be 20 (temporary)
545 Integer maxDegree = ordmInfo.getMaxDegrees() == null ? 20 : ordmInfo.getMaxDegrees().toJava();
547 for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
548 LOG.debug(PortMappingUtils.GETTING_CONPORT_LOGMSG, deviceId, degreeCounter);
549 InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
550 .child(Degree.class, new DegreeKey(Uint16.valueOf(degreeCounter)));
551 Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
552 LogicalDatastoreType.OPERATIONAL, deviceIID,
553 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
554 if (ordmDegreeObject.isPresent()) {
555 degrees.put(degreeCounter, ordmDegreeObject.get());
558 LOG.info(PortMappingUtils.DEVICE_HAS_LOGMSG,
559 deviceId, degrees.size(), degrees.size() <= 1 ? "degree" : "degrees");
563 private Map<Integer, List<ConnectionPorts>> getPerDegreePorts(String deviceId, Info ordmInfo) {
564 Map<Integer, List<ConnectionPorts>> conPortMap = new HashMap<>();
565 getDegreesMap(deviceId, ordmInfo).forEach(
566 (index, degree) -> conPortMap.put(index, new ArrayList<>(degree.nonnullConnectionPorts().values())));
570 private List<SharedRiskGroup> getSrgs(String deviceId, Info ordmInfo) {
571 List<SharedRiskGroup> srgs = new ArrayList<>();
573 // Get value for max Srg from info subtree, required for iteration
574 // if not present assume to be 20 (temporary)
575 Integer maxSrg = ordmInfo.getMaxSrgs() == null ? 20 : ordmInfo.getMaxSrgs().toJava();
576 for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) {
577 InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
578 .child(SharedRiskGroup.class, new SharedRiskGroupKey(Uint16.valueOf(srgCounter)));
579 Optional<SharedRiskGroup> ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
580 LogicalDatastoreType.OPERATIONAL, srgIID,
581 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
582 if (ordmSrgObject.isPresent()) {
583 srgs.add(ordmSrgObject.get());
590 private Map<String, String> getEthInterfaceList(String nodeId) {
591 LOG.info(PortMappingUtils.GETTING_ETH_LIST_LOGMSG, nodeId);
592 InstanceIdentifier<Protocols> protocoliid = InstanceIdentifier.create(OrgOpenroadmDevice.class)
593 .child(Protocols.class);
594 Optional<Protocols> protocolObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
595 LogicalDatastoreType.OPERATIONAL, protocoliid, Timeouts.DEVICE_READ_TIMEOUT,
596 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
597 if (protocolObject.isEmpty() || protocolObject.get().augmentation(Protocols1.class).getLldp() == null) {
598 LOG.warn(PortMappingUtils.PROCESSING_DONE_LOGMSG, nodeId, PortMappingUtils.CANNOT_GET_LLDP_CONF_LOGMSG);
599 return new HashMap<>();
601 Map<String, String> cpToInterfaceMap = new HashMap<>();
602 Lldp lldp = protocolObject.get().augmentation(Protocols1.class).getLldp();
603 for (PortConfig portConfig : lldp.nonnullPortConfig().values()) {
604 if (!portConfig.getAdminStatus().equals(PortConfig.AdminStatus.Txandrx)) {
607 InstanceIdentifier<Interface> interfaceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
608 .child(Interface.class, new InterfaceKey(portConfig.getIfName()));
609 Optional<Interface> interfaceObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
610 LogicalDatastoreType.OPERATIONAL, interfaceIID, Timeouts.DEVICE_READ_TIMEOUT,
611 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
612 if (interfaceObject.isEmpty() || interfaceObject.get().getSupportingCircuitPackName() == null) {
615 String supportingCircuitPackName = interfaceObject.get().getSupportingCircuitPackName();
616 cpToInterfaceMap.put(supportingCircuitPackName, portConfig.getIfName());
617 InstanceIdentifier<CircuitPacks> circuitPacksIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
618 .child(CircuitPacks.class, new CircuitPacksKey(supportingCircuitPackName));
619 Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(
620 nodeId, LogicalDatastoreType.OPERATIONAL, circuitPacksIID, Timeouts.DEVICE_READ_TIMEOUT,
621 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
622 if (circuitPackObject.isEmpty() || circuitPackObject.get().getParentCircuitPack() == null) {
625 cpToInterfaceMap.put(circuitPackObject.get().getParentCircuitPack().getCircuitPackName(),
626 portConfig.getIfName());
628 LOG.info(PortMappingUtils.PROCESSING_DONE_LOGMSG, nodeId, " - success");
629 return cpToInterfaceMap;
632 private List<CpToDegree> getCpToDegreeList(Map<Integer, Degree> degrees, Map<String, String> interfaceList) {
633 List<CpToDegree> cpToDegreeList = new ArrayList<>();
634 for (Degree degree : degrees.values()) {
635 cpToDegreeList.addAll(degree.nonnullCircuitPacks().values().stream()
636 .map(cp -> createCpToDegreeObject(cp.getCircuitPackName(),
637 degree.getDegreeNumber().toString(), interfaceList))
638 .collect(Collectors.toList()));
640 return cpToDegreeList;
643 private Map<McCapabilitiesKey, McCapabilities> getMcCapabilities(Map<Integer, Degree> degrees,
644 List<SharedRiskGroup> srgs, String nodeId) {
645 LOG.info(PortMappingUtils.GETTING_MC_CAPA_LOGMSG , nodeId, "degrees");
646 Map<McCapabilitiesKey, McCapabilities> mcCapabilities = degrees.values().stream()
647 .map(degree -> createMcCapDegreeObject(degree, nodeId))
648 .collect(Collectors.toMap(McCapabilities::key, mcc -> mcc));
649 // Add the SRG mc-capabilities
650 LOG.info(PortMappingUtils.GETTING_MC_CAPA_LOGMSG , nodeId, "SRGs");
651 mcCapabilities.putAll(srgs.stream().map(srg -> createMcCapSrgObject(srg, nodeId))
652 .collect(Collectors.toMap(McCapabilities::key, mcCapabilities2 -> mcCapabilities2)));
653 return mcCapabilities;
656 private boolean postPortMapping(String nodeId, NodeInfo nodeInfo, List<Mapping> portMapList,
657 List<CpToDegree> cp2DegreeList, List<SwitchingPoolLcp> splList,
658 Map<McCapabilitiesKey, McCapabilities> mcCapabilities) {
659 NodesBuilder nodesBldr = new NodesBuilder().withKey(new NodesKey(nodeId)).setNodeId(nodeId);
660 if (nodeInfo != null) {
661 nodesBldr.setNodeInfo(nodeInfo);
663 if (portMapList != null) {
664 Map<MappingKey, Mapping> mappingMap = new HashMap<>();
665 // No element in the list below should be null at this stage
666 for (Mapping mapping: portMapList) {
667 mappingMap.put(mapping.key(), mapping);
669 nodesBldr.setMapping(mappingMap);
671 if (cp2DegreeList != null) {
672 Map<CpToDegreeKey, CpToDegree> cpToDegreeMap = new HashMap<>();
673 // No element in the list below should be null at this stage
674 for (CpToDegree cp2Degree: cp2DegreeList) {
675 cpToDegreeMap.put(cp2Degree.key(), cp2Degree);
677 nodesBldr.setCpToDegree(cpToDegreeMap);
680 if (splList != null) {
681 Map<SwitchingPoolLcpKey,SwitchingPoolLcp> splMap = new HashMap<>();
682 // No element in the list below should be null at this stage
683 for (SwitchingPoolLcp spl: splList) {
684 splMap.put(spl.key(), spl);
686 nodesBldr.setSwitchingPoolLcp(splMap);
688 if (mcCapabilities != null) {
689 nodesBldr.setMcCapabilities(mcCapabilities);
691 Map<NodesKey,Nodes> nodesList = new HashMap<>();
692 Nodes nodes = nodesBldr.build();
693 nodesList.put(nodes.key(),nodes);
695 Network network = new NetworkBuilder().setNodes(nodesList).build();
697 final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
698 InstanceIdentifier<Network> nodesIID = InstanceIdentifier.builder(Network.class).build();
699 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodesIID, network);
700 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
704 } catch (InterruptedException | ExecutionException e) {
705 LOG.warn(PortMappingUtils.PORTMAPPING_POST_FAIL_LOGMSG, nodeId, network, e);
710 private CpToDegree createCpToDegreeObject(String circuitPackName, String degreeNumber,
711 Map<String, String> interfaceList) {
712 return new CpToDegreeBuilder()
713 .withKey(new CpToDegreeKey(circuitPackName))
714 .setCircuitPackName(circuitPackName)
715 .setDegreeNumber(Uint32.valueOf(degreeNumber))
716 .setInterfaceName(interfaceList.get(circuitPackName)).build();
719 private McCapabilities createMcCapDegreeObject(Degree degree, String nodeId) {
720 String mcNodeName = PortMappingUtils.degreeTtpNodeName(degree.getDegreeNumber().toString(), null);
721 McCapabilitiesBuilder mcCapabilitiesBuilder = new McCapabilitiesBuilder()
722 .withKey(new McCapabilitiesKey(mcNodeName))
723 .setMcNodeName(mcNodeName);
724 if (degree.getMcCapabilities() == null) {
725 LOG.warn(PortMappingUtils.NO_MC_LOGMSG, nodeId, "degree", degree.getDegreeNumber());
726 mcCapabilitiesBuilder
727 .setCenterFreqGranularity(FrequencyGHz.getDefaultInstance("50"))
728 .setSlotWidthGranularity(FrequencyGHz.getDefaultInstance("50"));
730 mcCapabilitiesBuilder
731 .setCenterFreqGranularity(FrequencyGHz.getDefaultInstance(degree.getMcCapabilities()
732 .getCenterFreqGranularity().getValue().toString()))
733 .setSlotWidthGranularity(FrequencyGHz.getDefaultInstance(degree.getMcCapabilities()
734 .getSlotWidthGranularity().getValue().toString()));
736 return mcCapabilitiesBuilder.build();
739 private McCapabilities createMcCapSrgObject(SharedRiskGroup srg, String nodeId) {
740 String mcNodeName = "SRG" + srg.getSrgNumber().toString() + "-PP";
741 McCapabilitiesBuilder mcCapabilitiesBuilder = new McCapabilitiesBuilder()
742 .withKey(new McCapabilitiesKey(mcNodeName))
743 .setMcNodeName(mcNodeName);
744 if (srg.getMcCapabilities() == null) {
745 LOG.warn(PortMappingUtils.NO_MC_LOGMSG, nodeId, "SRG", srg.getSrgNumber());
746 mcCapabilitiesBuilder
747 .setCenterFreqGranularity(FrequencyGHz.getDefaultInstance("50"))
748 .setSlotWidthGranularity(FrequencyGHz.getDefaultInstance("50"));
750 mcCapabilitiesBuilder
751 .setCenterFreqGranularity(FrequencyGHz.getDefaultInstance(srg.getMcCapabilities()
752 .getCenterFreqGranularity().getValue().toString()))
753 .setSlotWidthGranularity(FrequencyGHz.getDefaultInstance(srg.getMcCapabilities()
754 .getSlotWidthGranularity().getValue().toString()));
756 return mcCapabilitiesBuilder.build();
759 private Mapping createMappingObject(String nodeId, Ports port, String circuitPackName,
760 String logicalConnectionPoint) {
761 MappingBuilder mpBldr = new MappingBuilder()
762 .withKey(new MappingKey(logicalConnectionPoint))
763 .setLogicalConnectionPoint(logicalConnectionPoint)
764 .setSupportingCircuitPackName(circuitPackName)
765 .setSupportingPort(port.getPortName())
766 .setPortDirection(port.getPortDirection().getName());
767 if (port.getAdministrativeState() != null) {
768 mpBldr.setPortAdminState(port.getAdministrativeState().name());
770 if (port.getOperationalState() != null) {
771 mpBldr.setPortOperState(port.getOperationalState().name());
774 if ((port.getInterfaces() == null)
775 || (!logicalConnectionPoint.contains(StringConstants.TTP_TOKEN)
776 && !logicalConnectionPoint.contains(StringConstants.NETWORK_TOKEN))) {
777 return mpBldr.build();
779 mpBldr = updateMappingInterfaces(nodeId, mpBldr, port);
780 return mpBldr.build();
783 private Mapping updateMappingObject(String nodeId, Ports port, Mapping oldmapping) {
784 MappingBuilder mpBldr = new MappingBuilder(oldmapping);
785 updateMappingStates(mpBldr, port, oldmapping);
786 if ((port.getInterfaces() == null)
787 || (!oldmapping.getLogicalConnectionPoint().contains(StringConstants.TTP_TOKEN)
788 && !oldmapping.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN))) {
789 return mpBldr.build();
791 // Get interfaces provisioned on the port
792 mpBldr = updateMappingInterfaces(nodeId, mpBldr, port);
793 return mpBldr.build();
796 private MappingBuilder updateMappingStates(MappingBuilder mpBldr, Ports port, Mapping oldmapping) {
797 if (port.getAdministrativeState() != null
798 && !port.getAdministrativeState().getName().equals(oldmapping.getPortAdminState())) {
799 mpBldr.setPortAdminState(port.getAdministrativeState().name());
801 if (port.getOperationalState() != null
802 && !port.getOperationalState().getName().equals(oldmapping.getPortOperState())) {
803 mpBldr.setPortOperState(port.getOperationalState().name());
808 private MappingBuilder updateMappingInterfaces(String nodeId, MappingBuilder mpBldr, Ports port) {
809 for (Interfaces interfaces : port.getInterfaces()) {
811 Optional<Interface> openRoadmInterface = this.openRoadmInterfaces.getInterface(nodeId,
812 interfaces.getInterfaceName());
813 if (openRoadmInterface.isEmpty()) {
814 LOG.warn(PortMappingUtils.INTF_ISSUE_LOGMSG,
815 nodeId, interfaces.getInterfaceName() + "- empty interface");
818 LOG.debug(PortMappingUtils.GOT_INTF_LOGMSG,
819 nodeId, openRoadmInterface.get().getName(), openRoadmInterface.get().getType());
820 Class<? extends InterfaceType> interfaceType
821 = (Class<? extends InterfaceType>) openRoadmInterface.get().getType();
822 // Check if interface type is OMS or OTS
823 if (interfaceType.equals(OpenROADMOpticalMultiplex.class)) {
824 mpBldr.setSupportingOms(interfaces.getInterfaceName());
826 if (interfaceType.equals(OpticalTransport.class)) {
827 mpBldr.setSupportingOts(interfaces.getInterfaceName());
829 if (interfaceType.equals(OtnOdu.class)) {
830 mpBldr.setSupportingOdu4(interfaces.getInterfaceName());
832 } catch (OpenRoadmInterfaceException ex) {
833 LOG.warn(PortMappingUtils.INTF_ISSUE_LOGMSG, nodeId, interfaces.getInterfaceName(), ex);
839 private Mapping createXpdrMappingObject(String nodeId, Ports port, String circuitPackName,
840 String logicalConnectionPoint, String partnerLcp, Mapping mapping, String connectionMapLcp,
841 XpdrNodeTypes xpdrNodeType) {
842 if (mapping != null && connectionMapLcp != null) {
843 // update existing mapping
844 return new MappingBuilder(mapping).setConnectionMapLcp(connectionMapLcp).build();
846 return createNewXpdrMapping(nodeId, port, circuitPackName, logicalConnectionPoint, partnerLcp, xpdrNodeType);
849 private Mapping createNewXpdrMapping(String nodeId, Ports port, String circuitPackName,
850 String logicalConnectionPoint, String partnerLcp, XpdrNodeTypes xpdrNodeType) {
851 MappingBuilder mpBldr = new MappingBuilder()
852 .withKey(new MappingKey(logicalConnectionPoint))
853 .setLogicalConnectionPoint(logicalConnectionPoint)
854 .setSupportingCircuitPackName(circuitPackName)
855 .setSupportingPort(port.getPortName())
856 .setPortDirection(port.getPortDirection().getName())
857 .setLcpHashVal(PortMappingUtils.fnv1size64(nodeId + "-" + logicalConnectionPoint));
858 if (port.getPortQual() != null) {
859 mpBldr.setPortQual(port.getPortQual().getName());
861 if (xpdrNodeType != null) {
862 mpBldr.setXponderType(
863 org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.XpdrNodeTypes.forValue(
864 xpdrNodeType.getIntValue()));
866 if (partnerLcp != null) {
867 mpBldr.setPartnerLcp(partnerLcp);
869 if (port.getSupportedInterfaceCapability() != null) {
870 List<Class<? extends org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327
871 .SupportedIfCapability>> supportedIntf = new ArrayList<>();
872 for (Class<? extends SupportedIfCapability> sup: port.getSupportedInterfaceCapability()) {
873 supportedIntf.add(MappingUtilsImpl.convertSupIfCapa(sup.getSimpleName()));
875 mpBldr.setSupportedInterfaceCapability(supportedIntf);
877 if (port.getAdministrativeState() != null) {
878 mpBldr.setPortAdminState(port.getAdministrativeState().name());
880 if (port.getOperationalState() != null) {
881 mpBldr.setPortOperState(port.getOperationalState().name());
883 return mpBldr.build();
886 private Ports getPort2(Ports port, String nodeId, String circuitPackName, StringBuilder circuitPackName2,
887 //circuitPackName2 will be updated by reference contrary to circuitPackName
888 List<CircuitPacks> circuitPackList, Map<String, String> lcpMap) {
889 if (!checkPartnerPortNotNull(port)) {
890 LOG.warn(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG, nodeId, port.getPortName(), circuitPackName);
893 if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) {
896 Optional<CircuitPacks> cpOpt = circuitPackList.stream()
898 cP -> cP.getCircuitPackName().equals(port.getPartnerPort().getCircuitPackName()))
900 if (cpOpt.isEmpty()) {
901 LOG.error(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, port.getPartnerPort().getCircuitPackName());
904 Optional<Ports> poOpt = cpOpt.get().nonnullPorts().values().stream()
905 .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName()))
907 if (poOpt.isEmpty()) {
908 LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG,
909 nodeId, port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName());
912 Ports port2 = poOpt.get();
913 circuitPackName2.append(cpOpt.get().getCircuitPackName());
914 if (!checkPartnerPort(circuitPackName, port, port2)) {
915 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
916 nodeId, port2.getPortName(), circuitPackName2, port.getPortName(), circuitPackName);
923 private void putXpdrLcpsInMaps(int line, String nodeId,
924 Integer xponderNb, XpdrNodeTypes xponderType,
925 String circuitPackName, String circuitPackName2, Ports port, Ports port2,
926 Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
928 PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, line, StringConstants.NETWORK_TOKEN);
929 if (lcpMap.containsKey(lcp1)) {
930 LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "add", lcp1 + " - already exist");
934 PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, line + 1, StringConstants.NETWORK_TOKEN);
935 if (lcpMap.containsKey(lcp2)) {
936 LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "add", lcp2 + " - already exist");
939 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp1);
940 lcpMap.put(circuitPackName2 + '+' + port2.getPortName(), lcp2);
942 createXpdrMappingObject(nodeId, port, circuitPackName, lcp1, lcp2, null, null, xponderType));
944 createXpdrMappingObject(nodeId, port2, circuitPackName2, lcp2, lcp1, null, null, xponderType));
948 private int[] fillXpdrLcpsMaps(int line, int client, String nodeId,
949 Integer xponderNb, XpdrNodeTypes xponderType,
950 String circuitPackName, Ports port,
951 List<CircuitPacks> circuitPackList, Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
952 if (port.getPortQual() == null) {
953 LOG.warn(PortMappingUtils.PORTQUAL_LOGMSG, nodeId, port.getPortName(), circuitPackName, "not found");
954 return new int[] {line, client};
957 switch (port.getPortQual()) {
962 PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, client, StringConstants.CLIENT_TOKEN);
963 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp0);
965 createXpdrMappingObject(nodeId, port, circuitPackName, lcp0, null, null, null, xponderType));
971 line = fillXpdrNetworkLcpsMaps(line, nodeId,
972 xponderNb, xponderType,
973 circuitPackName, port,
974 circuitPackList, lcpMap, mappingMap);
978 LOG.error(PortMappingUtils.PORTQUAL_LOGMSG,
979 nodeId, port.getPortName(), circuitPackName, port.getPortQual() + " not supported");
981 return new int[] {line, client};
984 private int fillXpdrNetworkLcpsMaps(int line, String nodeId,
985 Integer xponderNb, XpdrNodeTypes xponderType,
986 String circuitPackName, Ports port,
987 List<CircuitPacks> circuitPackList, Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
989 switch (port.getPortDirection()) {
993 PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, line, StringConstants.NETWORK_TOKEN);
994 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp);
996 createXpdrMappingObject(nodeId, port, circuitPackName, lcp, null, null, null, xponderType));
1002 StringBuilder circuitPackName2 = new StringBuilder();
1003 Ports port2 = getPort2(port, nodeId, circuitPackName, circuitPackName2,
1004 circuitPackList, lcpMap);
1006 if (port2 == null) {
1007 //key already present or an error occured and was logged
1011 putXpdrLcpsInMaps(line, nodeId, xponderNb, xponderType,
1012 circuitPackName, circuitPackName2.toString(), port, port2,
1013 lcpMap, mappingMap);
1018 LOG.error(PortMappingUtils.UNSUPPORTED_DIR_LOGMSG,
1019 nodeId, port.getPortName(), circuitPackName, port.getPortDirection());
1025 private boolean createMcCapabilitiesList(String nodeId, Info deviceInfo,
1026 Map<McCapabilitiesKey, McCapabilities> mcCapabilitiesMap) {
1027 Map<Integer, Degree> degrees = getDegreesMap(nodeId, deviceInfo);
1028 List<SharedRiskGroup> srgs = getSrgs(nodeId, deviceInfo);
1029 mcCapabilitiesMap.putAll(getMcCapabilities(degrees, srgs, nodeId));
1033 private boolean createTtpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
1034 // Creating mapping data for degree TTP's
1035 Map<Integer, Degree> degrees = getDegreesMap(nodeId, deviceInfo);
1036 Map<String, String> interfaceList = getEthInterfaceList(nodeId);
1037 List<CpToDegree> cpToDegreeList = getCpToDegreeList(degrees, interfaceList);
1038 LOG.info(PortMappingUtils.MAP_LOOKS_LOGMSG, nodeId, interfaceList);
1039 postPortMapping(nodeId, null, null, cpToDegreeList, null, null);
1041 for (Entry<Integer, List<ConnectionPorts>> cpMapEntry : getPerDegreePorts(nodeId, deviceInfo).entrySet()) {
1042 List<ConnectionPorts> cpMapValue = cpMapEntry.getValue();
1043 ConnectionPorts cp1 = cpMapValue.get(0);
1044 String cp1Name = cp1.getCircuitPackName();
1045 switch (cpMapValue.size()) {
1047 // port is bidirectional
1048 Ports port = getTtpPort(cp1, cp1Name, nodeId);
1052 if (!checkTtpPort(port, cp1Name, nodeId, true)) {
1055 String logicalConnectionPoint =
1056 PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(), "TXRX");
1057 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
1058 nodeId, port.getPortName(), cp1Name, logicalConnectionPoint);
1059 portMapList.add(createMappingObject(nodeId, port, cp1Name, logicalConnectionPoint));
1062 // ports are unidirectionals
1063 Ports port1 = getTtpPort(cp1, cp1Name, nodeId);
1064 if (port1 == null) {
1067 ConnectionPorts cp2 = cpMapValue.get(1);
1068 String cp2Name = cp2.getCircuitPackName();
1069 Ports port2 = getTtpPort(cp2, cp2Name, nodeId);
1070 if (port2 == null) {
1073 if (!checkTtpPortsUnidir(port1, port2, cp1Name, cp2Name, nodeId)) {
1076 String logicalConnectionPoint1 = PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(),
1077 port1.getPortDirection().getName().toUpperCase(Locale.getDefault()));
1078 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
1079 nodeId, port1.getPortName(), cp1Name, logicalConnectionPoint1);
1080 portMapList.add(createMappingObject(nodeId, port1, cp1Name, logicalConnectionPoint1));
1081 String logicalConnectionPoint2 = PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(),
1082 port2.getPortDirection().getName().toUpperCase(Locale.getDefault()));
1083 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
1084 nodeId, port2.getPortName(), cp2Name, logicalConnectionPoint2);
1085 portMapList.add(createMappingObject(nodeId, port2, cp2Name, logicalConnectionPoint2));
1088 LOG.error(PortMappingUtils.NOT_CORRECT_CONPORT_LOGMSG, nodeId, cpMapEntry.getKey());
1090 //TODO should it be continue or return false ?
1096 private Ports getTtpPort(ConnectionPorts cp, String cpName, String nodeId) {
1097 InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
1098 .child(CircuitPacks.class, new CircuitPacksKey(cpName))
1099 .child(Ports.class, new PortsKey(cp.getPortName()));
1100 LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp.getPortName(), cpName);
1101 Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
1102 LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
1103 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1104 if (portObject.isEmpty()) {
1105 LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp.getPortName(), cpName);
1108 return portObject.get();
1111 private boolean checkPortQual(Ports port, String cpName, String nodeId) {
1112 if (port.getPortQual() == null) {
1115 if (PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) {
1116 //used to be LOG.error when called from createTtpPortMapping
1117 LOG.debug(PortMappingUtils.PORT_NOT_RDMEXT_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
1118 nodeId, port.getPortName(), cpName);
1124 private boolean checkTtpPort(Ports port, String cpName, String nodeId, boolean bidirectional) {
1125 if (!checkPortQual(port, cpName, nodeId)) {
1128 if (Direction.Bidirectional.getIntValue() == port.getPortDirection().getIntValue() ^ bidirectional) {
1129 // (a ^ b) makes more sense than (!a && b) here since it can also work for unidirectional links
1130 LOG.error(PortMappingUtils.PORTDIR_ERROR_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
1131 nodeId, port.getPortName(), cpName);
1137 private boolean checkTtpPortsUnidir(Ports port1, Ports port2, String cp1Name, String cp2Name, String nodeId) {
1138 if (!checkTtpPort(port1, cp1Name, nodeId, false)) {
1141 if (!checkTtpPort(port2, cp2Name, nodeId, false)) {
1144 if (!checkPartnerPort(cp1Name, port1, port2)) {
1145 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
1146 nodeId, port2.getPortName(), cp2Name, port1.getPortName(), cp1Name);
1149 // Directions checks are the same for cp1 and cp2, no need to check them twice.
1150 if (!checkPartnerPortNoDir(cp2Name, port2, port1)) {
1151 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
1152 nodeId, port1.getPortName(), cp1Name, port2.getPortName(), cp2Name);
1158 private NodeInfo createNodeInfo(Info deviceInfo) {
1159 if (deviceInfo.getNodeType() == null) {
1160 // TODO make mandatory in yang
1161 LOG.error(PortMappingUtils.NODE_TYPE_LOGMSG, deviceInfo.getNodeId(), "field missing");
1164 NodeInfoBuilder nodeInfoBldr = new NodeInfoBuilder()
1165 .setOpenroadmVersion(OpenroadmNodeVersion._221)
1167 deviceInfo.getClli() == null || deviceInfo.getClli().isEmpty()
1169 : deviceInfo.getClli())
1170 .setNodeType(NodeTypes.forValue(deviceInfo.getNodeType().getIntValue()));
1171 if (deviceInfo.getModel() != null) {
1172 nodeInfoBldr.setNodeModel(deviceInfo.getModel());
1174 if (deviceInfo.getVendor() != null) {
1175 nodeInfoBldr.setNodeVendor(deviceInfo.getVendor());
1177 if (deviceInfo.getIpAddress() != null) {
1178 nodeInfoBldr.setNodeIpAddress(deviceInfo.getIpAddress());
1180 return nodeInfoBldr.build();