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 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
218 Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
219 LogicalDatastoreType.OPERATIONAL, deviceIID,
220 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
221 if (deviceObject.isEmpty()) {
222 LOG.error(PortMappingUtils.CANNOT_GET_DEV_CONF_LOGMSG, nodeId);
225 OrgOpenroadmDevice device = deviceObject.get();
226 if (device.getCircuitPacks() == null) {
227 LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, PortMappingUtils.FOUND);
231 Map<String, String> lcpMap = new HashMap<>();
232 Map<String, Mapping> mappingMap = new HashMap<>();
233 List<CircuitPacks> circuitPackList = new ArrayList<>(device.nonnullCircuitPacks().values());
234 circuitPackList.sort(Comparator.comparing(CircuitPack::getCircuitPackName));
235 if (device.getXponder() == null) {
236 LOG.warn(PortMappingUtils.XPDR_LIST_IN_CONF_LOGMSG, nodeId, "not found");
237 // Variables to keep track of number of line ports and client ports
240 // TODO the treatment here inside the 2 nested for-loop is very similar to the one
241 // when device.getXponder() != null. Some code mutualization must be considered.
242 for (CircuitPacks cp : circuitPackList) {
243 String circuitPackName = cp.getCircuitPackName();
244 if (cp.getPorts() == null) {
245 LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, PortMappingUtils.FOUND, circuitPackName);
248 List<Ports> portList = new ArrayList<>(cp.nonnullPorts().values());
249 portList.sort(Comparator.comparing(Ports::getPortName));
250 for (Ports port : portList) {
251 int[] counters = fillXpdrLcpsMaps(line, client, nodeId,
252 1, null, circuitPackName, port,
253 circuitPackList, lcpMap, mappingMap);
255 client = counters[1];
259 LOG.info(PortMappingUtils.XPDR_LIST_IN_CONF_LOGMSG, nodeId, PortMappingUtils.FOUND);
260 for (Xponder xponder : deviceObject.get().nonnullXponder().values()) {
261 // Variables to keep track of number of line ports and client ports
264 Integer xponderNb = xponder.getXpdrNumber().toJava();
265 XpdrNodeTypes xponderType = xponder.getXpdrType();
266 for (XpdrPort xpdrPort : xponder.nonnullXpdrPort().values().stream()
267 .sorted((xp1, xp2) -> xp1.getIndex().compareTo(xp2.getIndex())).collect(Collectors.toList())) {
268 String circuitPackName = xpdrPort.getCircuitPackName();
269 String portName = xpdrPort.getPortName();
270 // If there xponder-subtree has missing circuit-packs or ports,
271 // This gives a null-pointer expection,
272 Optional<CircuitPacks> cpList = device.nonnullCircuitPacks().values().stream()
273 .filter(cp -> cp.getCircuitPackName().equals(circuitPackName)).findFirst();
274 if (cpList.isEmpty()) {
275 LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
276 nodeId, circuitPackName);
279 Optional<Ports> portsList = cpList.get().nonnullPorts().values().stream()
280 .filter(p -> p.getPortName().equals(portName)).findFirst();
281 if (portsList.isEmpty()) {
282 LOG.warn(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
283 nodeId, portName, circuitPackName, "in the device");
286 int[] counters = fillXpdrLcpsMaps(line, client, nodeId,
287 xponderNb, xponderType, circuitPackName, portsList.get(),
288 circuitPackList, lcpMap, mappingMap);
290 client = counters[1];
295 if (device.getConnectionMap() == null) {
296 LOG.warn(PortMappingUtils.NO_CONMAP_LOGMSG, nodeId);
298 for (ConnectionMap cm : deviceObject.get().nonnullConnectionMap().values()) {
299 String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
300 Destination destination0 = cm.nonnullDestination().values().iterator().next();
301 String dkey = destination0.getCircuitPackName() + "+" + destination0.getPortName();
302 if (!lcpMap.containsKey(skey)) {
303 LOG.error(PortMappingUtils.CONMAP_ISSUE_LOGMSG, nodeId, skey, dkey);
306 String slcp = lcpMap.get(skey);
307 Mapping mapping = mappingMap.get(slcp);
308 mappingMap.remove(slcp);
309 portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping,
311 lcpMap.containsKey(dkey) ? lcpMap.get(dkey) : null,
316 if (device.getOduSwitchingPools() != null) {
317 List<SwitchingPoolLcp> switchingPoolList = new ArrayList<>();
318 for (OduSwitchingPools odp : device.nonnullOduSwitchingPools().values()) {
319 Map<NonBlockingListKey,NonBlockingList> nbMap = new HashMap<>();
320 for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org
321 .openroadm.device.odu.switching.pools.NonBlockingList nbl : odp.nonnullNonBlockingList().values()) {
322 if (nbl.getPortList() == null) {
325 List<String> lcpList = new ArrayList<>();
326 for (PortList item : nbl.nonnullPortList().values()) {
327 String key = item.getCircuitPackName() + "+" + item.getPortName();
328 if (!lcpMap.containsKey(key)) {
329 LOG.error(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG,
330 nodeId, item.getPortName(), item.getCircuitPackName(), "to a logical connection point");
333 lcpList.add(lcpMap.get(key));
335 NonBlockingList nonBlockingList = new NonBlockingListBuilder()
336 .setNblNumber(nbl.getNblNumber())
337 .setInterconnectBandwidth(nbl.getInterconnectBandwidth())
338 .setInterconnectBandwidthUnit(nbl.getInterconnectBandwidthUnit())
341 nbMap.put(nonBlockingList.key(), nonBlockingList);
343 SwitchingPoolLcp splBldr = new SwitchingPoolLcpBuilder()
344 .setSwitchingPoolNumber(odp.getSwitchingPoolNumber())
345 .setSwitchingPoolType(SwitchingPoolTypes.forValue(odp.getSwitchingPoolType().getIntValue()))
346 .setNonBlockingList(nbMap)
348 switchingPoolList.add(splBldr);
350 postPortMapping(nodeId, null, null, null, switchingPoolList, null);
353 mappingMap.forEach((k,v) -> portMapList.add(v));
357 private boolean checkPartnerPortNotNull(Ports port) {
358 return (port.getPartnerPort() != null
359 && port.getPartnerPort().getCircuitPackName() != null
360 && port.getPartnerPort().getPortName() != null);
363 private boolean checkPartnerPortNoDir(String circuitPackName, Ports port1, Ports port2) {
364 return (checkPartnerPortNotNull(port2)
365 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
366 && port2.getPartnerPort().getPortName().equals(port1.getPortName()));
369 private boolean checkPartnerPort(String circuitPackName, Ports port1, Ports port2) {
370 return checkPartnerPortNoDir(circuitPackName, port1, port2)
371 && Set.of(port1.getPortDirection().getIntValue(), port2.getPortDirection().getIntValue())
376 private HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg
377 .CircuitPacks>> getSrgCps(String deviceId, Info ordmInfo) {
378 HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg
379 .CircuitPacks>> cpPerSrg = new HashMap<>();
380 // Get value for max Srg from info subtree, required for iteration
381 // if not present assume to be 20 (temporary)
382 Integer maxSrg = ordmInfo.getMaxSrgs() == null ? 20 : ordmInfo.getMaxSrgs().toJava();
383 for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) {
384 List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks> srgCps
386 LOG.debug(PortMappingUtils.GETTING_CP_LOGMSG, deviceId, srgCounter);
387 InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
388 .child(SharedRiskGroup.class, new SharedRiskGroupKey(Uint16.valueOf(srgCounter)));
389 Optional<SharedRiskGroup> ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
390 LogicalDatastoreType.OPERATIONAL, srgIID,
391 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
392 if (ordmSrgObject.isPresent()) {
393 srgCps.addAll(ordmSrgObject.get().nonnullCircuitPacks().values());
394 cpPerSrg.put(ordmSrgObject.get().getSrgNumber().toJava(), srgCps);
397 LOG.info(PortMappingUtils.DEVICE_HAS_LOGMSG, deviceId, cpPerSrg.size(), "SRG");
401 private boolean createPpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
402 // Creating mapping data for SRG's PP
403 for (Entry<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks>>
404 srgCpEntry : getSrgCps(nodeId, deviceInfo).entrySet()) {
405 List<String> keys = new ArrayList<>();
406 for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks
407 cp : srgCpEntry.getValue()) {
408 String circuitPackName = cp.getCircuitPackName();
409 List<Ports> portList = getPortList(circuitPackName, nodeId);
410 Collections.sort(portList, new SortPort221ByName());
412 for (Ports port : portList) {
413 if (!checkPortQual(port, circuitPackName, nodeId)) {
416 String currentKey = circuitPackName + "-" + port.getPortName();
417 if (keys.contains(currentKey)) {
418 LOG.debug(PortMappingUtils.PORT_ALREADY_HANDLED_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
419 nodeId, port.getPortName(), circuitPackName);
422 switch (port.getPortDirection()) {
424 String lcp = createLogicalConnectionPort(port, srgCpEntry.getKey(), portIndex);
425 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
426 nodeId, port.getPortName(), circuitPackName, lcp);
427 portMapList.add(createMappingObject(nodeId, port, circuitPackName, lcp));
429 keys.add(currentKey);
433 Ports port2 = getPartnerPort(port, circuitPackName, nodeId);
437 String lcp1 = createLogicalConnectionPort(port, srgCpEntry.getKey(), portIndex);
438 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
439 nodeId, port.getPortName(), circuitPackName, lcp1);
440 String lcp2 = createLogicalConnectionPort(port2, srgCpEntry.getKey(),portIndex);
441 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
442 nodeId, port2.getPortName(), circuitPackName, lcp2);
443 portMapList.add(createMappingObject(nodeId, port, circuitPackName, lcp1));
445 createMappingObject(nodeId ,port2, port.getPartnerPort().getCircuitPackName(), lcp2));
447 keys.add(currentKey);
448 keys.add(port.getPartnerPort().getCircuitPackName() + "-" + port2.getPortName());
451 LOG.error(PortMappingUtils.UNSUPPORTED_DIR_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
452 nodeId, port.getPortName(), circuitPackName, port.getPortDirection());
460 private Ports getPartnerPort(Ports port, String circuitPackName, String nodeId) {
461 if (!checkPartnerPortNotNull(port)) {
462 LOG.info(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
463 nodeId, port.getPortName(), circuitPackName);
466 InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
467 .child(CircuitPacks.class, new CircuitPacksKey(port.getPartnerPort().getCircuitPackName()))
468 .child(Ports.class, new PortsKey(port.getPartnerPort().getPortName()));
469 Optional<Ports> port2Object = this.deviceTransactionManager
470 .getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, port2ID,
471 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
472 if (port2Object.isEmpty()
473 || port2Object.get().getPortQual().getIntValue() != PortQual.RoadmExternal.getIntValue()) {
474 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG + PortMappingUtils.PARTNERPORT_GET_ERROR_LOGMSG,
475 nodeId, port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName(),
476 port.getPortName(), circuitPackName);
479 Ports port2 = port2Object.get();
480 if (!checkPartnerPort(circuitPackName, port, port2)) {
481 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG + PortMappingUtils.PARTNERPORT_CONF_ERROR_LOGMSG,
482 nodeId, port2.getPortName(), port.getPartnerPort().getCircuitPackName(),
483 port.getPortName(), circuitPackName);
485 //TODO check if we really needed to increase portIndex
486 // if yes this block should not be in getPartnerPort
492 private List<Ports> getPortList(String circuitPackName, String nodeId) {
493 InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
494 .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName));
495 Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
496 LogicalDatastoreType.OPERATIONAL, cpIID,
497 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
498 if (circuitPackObject.isEmpty()) {
499 LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
500 nodeId, circuitPackName);
501 return new ArrayList<>();
503 if (circuitPackObject.get().getPorts() == null) {
504 LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, PortMappingUtils.FOUND, circuitPackName);
505 return new ArrayList<>();
507 return new ArrayList<>(circuitPackObject.get().nonnullPorts().values());
510 private String createLogicalConnectionPort(Ports port, int index, int portIndex) {
511 if (SUFFIX.containsKey(port.getPortDirection())) {
512 return String.join("-", "SRG" + index, "PP" + portIndex, SUFFIX.get(port.getPortDirection()));
514 LOG.error(PortMappingUtils.UNSUPPORTED_DIR_LOGMSG,
515 "createLogicalConnectionPort", port, "SRG" + index + "-PP" + portIndex, port.getPortDirection());
519 private Map<Integer, Degree> getDegreesMap(String deviceId, Info ordmInfo) {
520 Map<Integer, Degree> degrees = new HashMap<>();
522 // Get value for max degree from info subtree, required for iteration
523 // if not present assume to be 20 (temporary)
524 Integer maxDegree = ordmInfo.getMaxDegrees() == null ? 20 : ordmInfo.getMaxDegrees().toJava();
526 for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
527 LOG.debug(PortMappingUtils.GETTING_CONPORT_LOGMSG, deviceId, degreeCounter);
528 InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
529 .child(Degree.class, new DegreeKey(Uint16.valueOf(degreeCounter)));
530 Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
531 LogicalDatastoreType.OPERATIONAL, deviceIID,
532 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
533 if (ordmDegreeObject.isPresent()) {
534 degrees.put(degreeCounter, ordmDegreeObject.get());
537 LOG.info(PortMappingUtils.DEVICE_HAS_LOGMSG,
538 deviceId, degrees.size(), degrees.size() <= 1 ? "degree" : "degrees");
542 private Map<Integer, List<ConnectionPorts>> getPerDegreePorts(String deviceId, Info ordmInfo) {
543 Map<Integer, List<ConnectionPorts>> conPortMap = new HashMap<>();
544 getDegreesMap(deviceId, ordmInfo).forEach(
545 (index, degree) -> conPortMap.put(index, new ArrayList<>(degree.nonnullConnectionPorts().values())));
549 private List<SharedRiskGroup> getSrgs(String deviceId, Info ordmInfo) {
550 List<SharedRiskGroup> srgs = new ArrayList<>();
552 // Get value for max Srg from info subtree, required for iteration
553 // if not present assume to be 20 (temporary)
554 Integer maxSrg = ordmInfo.getMaxSrgs() == null ? 20 : ordmInfo.getMaxSrgs().toJava();
555 for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) {
556 InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
557 .child(SharedRiskGroup.class, new SharedRiskGroupKey(Uint16.valueOf(srgCounter)));
558 Optional<SharedRiskGroup> ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
559 LogicalDatastoreType.OPERATIONAL, srgIID,
560 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
561 if (ordmSrgObject.isPresent()) {
562 srgs.add(ordmSrgObject.get());
569 private Map<String, String> getEthInterfaceList(String nodeId) {
570 LOG.info(PortMappingUtils.GETTING_ETH_LIST_LOGMSG, nodeId);
571 InstanceIdentifier<Protocols> protocoliid = InstanceIdentifier.create(OrgOpenroadmDevice.class)
572 .child(Protocols.class);
573 Optional<Protocols> protocolObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
574 LogicalDatastoreType.OPERATIONAL, protocoliid, Timeouts.DEVICE_READ_TIMEOUT,
575 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
576 if (protocolObject.isEmpty() || protocolObject.get().augmentation(Protocols1.class).getLldp() == null) {
577 LOG.warn(PortMappingUtils.PROCESSING_DONE_LOGMSG, nodeId, PortMappingUtils.CANNOT_GET_LLDP_CONF_LOGMSG);
578 return new HashMap<>();
580 Map<String, String> cpToInterfaceMap = new HashMap<>();
581 Lldp lldp = protocolObject.get().augmentation(Protocols1.class).getLldp();
582 for (PortConfig portConfig : lldp.nonnullPortConfig().values()) {
583 if (!portConfig.getAdminStatus().equals(PortConfig.AdminStatus.Txandrx)) {
586 InstanceIdentifier<Interface> interfaceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
587 .child(Interface.class, new InterfaceKey(portConfig.getIfName()));
588 Optional<Interface> interfaceObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
589 LogicalDatastoreType.OPERATIONAL, interfaceIID, Timeouts.DEVICE_READ_TIMEOUT,
590 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
591 if (interfaceObject.isEmpty() || interfaceObject.get().getSupportingCircuitPackName() == null) {
594 String supportingCircuitPackName = interfaceObject.get().getSupportingCircuitPackName();
595 cpToInterfaceMap.put(supportingCircuitPackName, portConfig.getIfName());
596 InstanceIdentifier<CircuitPacks> circuitPacksIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
597 .child(CircuitPacks.class, new CircuitPacksKey(supportingCircuitPackName));
598 Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(
599 nodeId, LogicalDatastoreType.OPERATIONAL, circuitPacksIID, Timeouts.DEVICE_READ_TIMEOUT,
600 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
601 if (circuitPackObject.isEmpty() || circuitPackObject.get().getParentCircuitPack() == null) {
604 cpToInterfaceMap.put(circuitPackObject.get().getParentCircuitPack().getCircuitPackName(),
605 portConfig.getIfName());
607 LOG.info(PortMappingUtils.PROCESSING_DONE_LOGMSG, nodeId, " - success");
608 return cpToInterfaceMap;
611 private List<CpToDegree> getCpToDegreeList(Map<Integer, Degree> degrees, Map<String, String> interfaceList) {
612 List<CpToDegree> cpToDegreeList = new ArrayList<>();
613 for (Degree degree : degrees.values()) {
614 cpToDegreeList.addAll(degree.nonnullCircuitPacks().values().stream()
615 .map(cp -> createCpToDegreeObject(cp.getCircuitPackName(),
616 degree.getDegreeNumber().toString(), interfaceList))
617 .collect(Collectors.toList()));
619 return cpToDegreeList;
622 private Map<McCapabilitiesKey, McCapabilities> getMcCapabilities(Map<Integer, Degree> degrees,
623 List<SharedRiskGroup> srgs, String nodeId) {
624 LOG.info(PortMappingUtils.GETTING_MC_CAPA_LOGMSG , nodeId, "degrees");
625 Map<McCapabilitiesKey, McCapabilities> mcCapabilities = degrees.values().stream()
626 .map(degree -> createMcCapDegreeObject(degree, nodeId))
627 .collect(Collectors.toMap(McCapabilities::key, mcc -> mcc));
628 // Add the SRG mc-capabilities
629 LOG.info(PortMappingUtils.GETTING_MC_CAPA_LOGMSG , nodeId, "SRGs");
630 mcCapabilities.putAll(srgs.stream().map(srg -> createMcCapSrgObject(srg, nodeId))
631 .collect(Collectors.toMap(McCapabilities::key, mcCapabilities2 -> mcCapabilities2)));
632 return mcCapabilities;
635 private boolean postPortMapping(String nodeId, NodeInfo nodeInfo, List<Mapping> portMapList,
636 List<CpToDegree> cp2DegreeList, List<SwitchingPoolLcp> splList,
637 Map<McCapabilitiesKey, McCapabilities> mcCapabilities) {
638 NodesBuilder nodesBldr = new NodesBuilder().withKey(new NodesKey(nodeId)).setNodeId(nodeId);
639 if (nodeInfo != null) {
640 nodesBldr.setNodeInfo(nodeInfo);
642 if (portMapList != null) {
643 Map<MappingKey, Mapping> mappingMap = new HashMap<>();
644 // No element in the list below should be null at this stage
645 for (Mapping mapping: portMapList) {
646 mappingMap.put(mapping.key(), mapping);
648 nodesBldr.setMapping(mappingMap);
650 if (cp2DegreeList != null) {
651 Map<CpToDegreeKey, CpToDegree> cpToDegreeMap = new HashMap<>();
652 // No element in the list below should be null at this stage
653 for (CpToDegree cp2Degree: cp2DegreeList) {
654 cpToDegreeMap.put(cp2Degree.key(), cp2Degree);
656 nodesBldr.setCpToDegree(cpToDegreeMap);
659 if (splList != null) {
660 Map<SwitchingPoolLcpKey,SwitchingPoolLcp> splMap = new HashMap<>();
661 // No element in the list below should be null at this stage
662 for (SwitchingPoolLcp spl: splList) {
663 splMap.put(spl.key(), spl);
665 nodesBldr.setSwitchingPoolLcp(splMap);
667 if (mcCapabilities != null) {
668 nodesBldr.setMcCapabilities(mcCapabilities);
670 Map<NodesKey,Nodes> nodesList = new HashMap<>();
671 Nodes nodes = nodesBldr.build();
672 nodesList.put(nodes.key(),nodes);
674 Network network = new NetworkBuilder().setNodes(nodesList).build();
676 final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
677 InstanceIdentifier<Network> nodesIID = InstanceIdentifier.builder(Network.class).build();
678 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodesIID, network);
679 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
683 } catch (InterruptedException | ExecutionException e) {
684 LOG.warn(PortMappingUtils.PORTMAPPING_POST_FAIL_LOGMSG, nodeId, network, e);
689 private CpToDegree createCpToDegreeObject(String circuitPackName, String degreeNumber,
690 Map<String, String> interfaceList) {
691 return new CpToDegreeBuilder()
692 .withKey(new CpToDegreeKey(circuitPackName))
693 .setCircuitPackName(circuitPackName)
694 .setDegreeNumber(Uint32.valueOf(degreeNumber))
695 .setInterfaceName(interfaceList.get(circuitPackName)).build();
698 private McCapabilities createMcCapDegreeObject(Degree degree, String nodeId) {
699 String mcNodeName = PortMappingUtils.degreeTtpNodeName(degree.getDegreeNumber().toString(), null);
700 McCapabilitiesBuilder mcCapabilitiesBuilder = new McCapabilitiesBuilder()
701 .withKey(new McCapabilitiesKey(mcNodeName))
702 .setMcNodeName(mcNodeName);
703 if (degree.getMcCapabilities() == null) {
704 LOG.warn(PortMappingUtils.NO_MC_LOGMSG, nodeId, "degree", degree.getDegreeNumber());
705 mcCapabilitiesBuilder
706 .setCenterFreqGranularity(FrequencyGHz.getDefaultInstance("50"))
707 .setSlotWidthGranularity(FrequencyGHz.getDefaultInstance("50"));
709 mcCapabilitiesBuilder
710 .setCenterFreqGranularity(FrequencyGHz.getDefaultInstance(degree.getMcCapabilities()
711 .getCenterFreqGranularity().getValue().toString()))
712 .setSlotWidthGranularity(FrequencyGHz.getDefaultInstance(degree.getMcCapabilities()
713 .getSlotWidthGranularity().getValue().toString()));
715 return mcCapabilitiesBuilder.build();
718 private McCapabilities createMcCapSrgObject(SharedRiskGroup srg, String nodeId) {
719 String mcNodeName = "SRG" + srg.getSrgNumber().toString() + "-PP";
720 McCapabilitiesBuilder mcCapabilitiesBuilder = new McCapabilitiesBuilder()
721 .withKey(new McCapabilitiesKey(mcNodeName))
722 .setMcNodeName(mcNodeName);
723 if (srg.getMcCapabilities() == null) {
724 LOG.warn(PortMappingUtils.NO_MC_LOGMSG, nodeId, "SRG", srg.getSrgNumber());
725 mcCapabilitiesBuilder
726 .setCenterFreqGranularity(FrequencyGHz.getDefaultInstance("50"))
727 .setSlotWidthGranularity(FrequencyGHz.getDefaultInstance("50"));
729 mcCapabilitiesBuilder
730 .setCenterFreqGranularity(FrequencyGHz.getDefaultInstance(srg.getMcCapabilities()
731 .getCenterFreqGranularity().getValue().toString()))
732 .setSlotWidthGranularity(FrequencyGHz.getDefaultInstance(srg.getMcCapabilities()
733 .getSlotWidthGranularity().getValue().toString()));
735 return mcCapabilitiesBuilder.build();
738 private Mapping createMappingObject(String nodeId, Ports port, String circuitPackName,
739 String logicalConnectionPoint) {
740 MappingBuilder mpBldr = new MappingBuilder()
741 .withKey(new MappingKey(logicalConnectionPoint))
742 .setLogicalConnectionPoint(logicalConnectionPoint)
743 .setSupportingCircuitPackName(circuitPackName)
744 .setSupportingPort(port.getPortName())
745 .setPortDirection(port.getPortDirection().getName());
746 if (port.getAdministrativeState() != null) {
747 mpBldr.setPortAdminState(port.getAdministrativeState().name());
749 if (port.getOperationalState() != null) {
750 mpBldr.setPortOperState(port.getOperationalState().name());
753 if ((port.getInterfaces() == null)
754 || (!logicalConnectionPoint.contains(StringConstants.TTP_TOKEN)
755 && !logicalConnectionPoint.contains(StringConstants.NETWORK_TOKEN))) {
756 return mpBldr.build();
758 mpBldr = updateMappingInterfaces(nodeId, mpBldr, port);
759 return mpBldr.build();
762 private Mapping updateMappingObject(String nodeId, Ports port, Mapping oldmapping) {
763 MappingBuilder mpBldr = new MappingBuilder(oldmapping);
764 updateMappingStates(mpBldr, port, oldmapping);
765 if ((port.getInterfaces() == null)
766 || (!oldmapping.getLogicalConnectionPoint().contains(StringConstants.TTP_TOKEN)
767 && !oldmapping.getLogicalConnectionPoint().contains(StringConstants.NETWORK_TOKEN))) {
768 return mpBldr.build();
770 // Get interfaces provisioned on the port
771 mpBldr = updateMappingInterfaces(nodeId, mpBldr, port);
772 return mpBldr.build();
775 private MappingBuilder updateMappingStates(MappingBuilder mpBldr, Ports port, Mapping oldmapping) {
776 if (port.getAdministrativeState() != null
777 && !port.getAdministrativeState().getName().equals(oldmapping.getPortAdminState())) {
778 mpBldr.setPortAdminState(port.getAdministrativeState().name());
780 if (port.getOperationalState() != null
781 && !port.getOperationalState().getName().equals(oldmapping.getPortOperState())) {
782 mpBldr.setPortOperState(port.getOperationalState().name());
787 private MappingBuilder updateMappingInterfaces(String nodeId, MappingBuilder mpBldr, Ports port) {
788 for (Interfaces interfaces : port.getInterfaces()) {
790 Optional<Interface> openRoadmInterface = this.openRoadmInterfaces.getInterface(nodeId,
791 interfaces.getInterfaceName());
792 if (openRoadmInterface.isEmpty()) {
793 LOG.warn(PortMappingUtils.INTF_ISSUE_LOGMSG,
794 nodeId, interfaces.getInterfaceName() + "- empty interface");
797 LOG.debug(PortMappingUtils.GOT_INTF_LOGMSG,
798 nodeId, openRoadmInterface.get().getName(), openRoadmInterface.get().getType());
799 Class<? extends InterfaceType> interfaceType
800 = (Class<? extends InterfaceType>) openRoadmInterface.get().getType();
801 // Check if interface type is OMS or OTS
802 if (interfaceType.equals(OpenROADMOpticalMultiplex.class)) {
803 mpBldr.setSupportingOms(interfaces.getInterfaceName());
805 if (interfaceType.equals(OpticalTransport.class)) {
806 mpBldr.setSupportingOts(interfaces.getInterfaceName());
808 if (interfaceType.equals(OtnOdu.class)) {
809 mpBldr.setSupportingOdu4(interfaces.getInterfaceName());
811 } catch (OpenRoadmInterfaceException ex) {
812 LOG.warn(PortMappingUtils.INTF_ISSUE_LOGMSG, nodeId, interfaces.getInterfaceName(), ex);
818 private Mapping createXpdrMappingObject(String nodeId, Ports port, String circuitPackName,
819 String logicalConnectionPoint, String partnerLcp, Mapping mapping, String connectionMapLcp,
820 XpdrNodeTypes xpdrNodeType) {
821 if (mapping != null && connectionMapLcp != null) {
822 // update existing mapping
823 return new MappingBuilder(mapping).setConnectionMapLcp(connectionMapLcp).build();
825 return createNewXpdrMapping(nodeId, port, circuitPackName, logicalConnectionPoint, partnerLcp, xpdrNodeType);
828 private Mapping createNewXpdrMapping(String nodeId, Ports port, String circuitPackName,
829 String logicalConnectionPoint, String partnerLcp, XpdrNodeTypes xpdrNodeType) {
830 MappingBuilder mpBldr = new MappingBuilder()
831 .withKey(new MappingKey(logicalConnectionPoint))
832 .setLogicalConnectionPoint(logicalConnectionPoint)
833 .setSupportingCircuitPackName(circuitPackName)
834 .setSupportingPort(port.getPortName())
835 .setPortDirection(port.getPortDirection().getName())
836 .setLcpHashVal(PortMappingUtils.fnv1size64(nodeId + "-" + logicalConnectionPoint));
837 if (port.getPortQual() != null) {
838 mpBldr.setPortQual(port.getPortQual().getName());
840 if (xpdrNodeType != null) {
841 mpBldr.setXponderType(
842 org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.XpdrNodeTypes.forValue(
843 xpdrNodeType.getIntValue()));
845 if (partnerLcp != null) {
846 mpBldr.setPartnerLcp(partnerLcp);
848 if (port.getSupportedInterfaceCapability() != null) {
849 List<Class<? extends org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327
850 .SupportedIfCapability>> supportedIntf = new ArrayList<>();
851 for (Class<? extends SupportedIfCapability> sup: port.getSupportedInterfaceCapability()) {
852 supportedIntf.add(MappingUtilsImpl.convertSupIfCapa(sup.getSimpleName()));
854 mpBldr.setSupportedInterfaceCapability(supportedIntf);
856 if (port.getAdministrativeState() != null) {
857 mpBldr.setPortAdminState(port.getAdministrativeState().name());
859 if (port.getOperationalState() != null) {
860 mpBldr.setPortOperState(port.getOperationalState().name());
862 return mpBldr.build();
865 private Ports getPort2(Ports port, String nodeId, String circuitPackName, StringBuilder circuitPackName2,
866 //circuitPackName2 will be updated by reference contrary to circuitPackName
867 List<CircuitPacks> circuitPackList, Map<String, String> lcpMap) {
868 if (!checkPartnerPortNotNull(port)) {
869 LOG.warn(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG, nodeId, port.getPortName(), circuitPackName);
872 if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) {
875 Optional<CircuitPacks> cpOpt = circuitPackList.stream()
877 cP -> cP.getCircuitPackName().equals(port.getPartnerPort().getCircuitPackName()))
879 if (cpOpt.isEmpty()) {
880 LOG.error(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, port.getPartnerPort().getCircuitPackName());
883 Optional<Ports> poOpt = cpOpt.get().nonnullPorts().values().stream()
884 .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName()))
886 if (poOpt.isEmpty()) {
887 LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG,
888 nodeId, port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName());
891 Ports port2 = poOpt.get();
892 circuitPackName2.append(cpOpt.get().getCircuitPackName());
893 if (!checkPartnerPort(circuitPackName, port, port2)) {
894 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
895 nodeId, port2.getPortName(), circuitPackName2, port.getPortName(), circuitPackName);
902 private void putXpdrLcpsInMaps(int line, String nodeId,
903 Integer xponderNb, XpdrNodeTypes xponderType,
904 String circuitPackName, String circuitPackName2, Ports port, Ports port2,
905 Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
907 PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, line, StringConstants.NETWORK_TOKEN);
908 if (lcpMap.containsKey(lcp1)) {
909 LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "add", lcp1 + " - already exist");
913 PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, line + 1, StringConstants.NETWORK_TOKEN);
914 if (lcpMap.containsKey(lcp2)) {
915 LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "add", lcp2 + " - already exist");
918 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp1);
919 lcpMap.put(circuitPackName2 + '+' + port2.getPortName(), lcp2);
921 createXpdrMappingObject(nodeId, port, circuitPackName, lcp1, lcp2, null, null, xponderType));
923 createXpdrMappingObject(nodeId, port2, circuitPackName2, lcp2, lcp1, null, null, xponderType));
927 private int[] fillXpdrLcpsMaps(int line, int client, String nodeId,
928 Integer xponderNb, XpdrNodeTypes xponderType,
929 String circuitPackName, Ports port,
930 List<CircuitPacks> circuitPackList, Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
931 if (port.getPortQual() == null) {
932 LOG.warn(PortMappingUtils.PORTQUAL_LOGMSG, nodeId, port.getPortName(), circuitPackName, "not found");
933 return new int[] {line, client};
936 switch (port.getPortQual()) {
941 PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, client, StringConstants.CLIENT_TOKEN);
942 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp0);
944 createXpdrMappingObject(nodeId, port, circuitPackName, lcp0, null, null, null, null));
950 line = fillXpdrNetworkLcpsMaps(line, nodeId,
951 xponderNb, xponderType,
952 circuitPackName, port,
953 circuitPackList, lcpMap, mappingMap);
957 LOG.error(PortMappingUtils.PORTQUAL_LOGMSG,
958 nodeId, port.getPortName(), circuitPackName, port.getPortQual() + " not supported");
960 return new int[] {line, client};
963 private int fillXpdrNetworkLcpsMaps(int line, String nodeId,
964 Integer xponderNb, XpdrNodeTypes xponderType,
965 String circuitPackName, Ports port,
966 List<CircuitPacks> circuitPackList, Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
968 switch (port.getPortDirection()) {
972 PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, line, StringConstants.NETWORK_TOKEN);
973 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp);
975 createXpdrMappingObject(nodeId, port, circuitPackName, lcp, null, null, null, xponderType));
981 StringBuilder circuitPackName2 = new StringBuilder();
982 Ports port2 = getPort2(port, nodeId, circuitPackName, circuitPackName2,
983 circuitPackList, lcpMap);
986 //key already present or an error occured and was logged
990 putXpdrLcpsInMaps(line, nodeId, xponderNb, xponderType,
991 circuitPackName, circuitPackName2.toString(), port, port2,
997 LOG.error(PortMappingUtils.UNSUPPORTED_DIR_LOGMSG,
998 nodeId, port.getPortName(), circuitPackName, port.getPortDirection());
1004 private boolean createMcCapabilitiesList(String nodeId, Info deviceInfo,
1005 Map<McCapabilitiesKey, McCapabilities> mcCapabilitiesMap) {
1006 Map<Integer, Degree> degrees = getDegreesMap(nodeId, deviceInfo);
1007 List<SharedRiskGroup> srgs = getSrgs(nodeId, deviceInfo);
1008 mcCapabilitiesMap.putAll(getMcCapabilities(degrees, srgs, nodeId));
1012 private boolean createTtpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
1013 // Creating mapping data for degree TTP's
1014 Map<Integer, Degree> degrees = getDegreesMap(nodeId, deviceInfo);
1015 Map<String, String> interfaceList = getEthInterfaceList(nodeId);
1016 List<CpToDegree> cpToDegreeList = getCpToDegreeList(degrees, interfaceList);
1017 LOG.info(PortMappingUtils.MAP_LOOKS_LOGMSG, nodeId, interfaceList);
1018 postPortMapping(nodeId, null, null, cpToDegreeList, null, null);
1020 for (Entry<Integer, List<ConnectionPorts>> cpMapEntry : getPerDegreePorts(nodeId, deviceInfo).entrySet()) {
1021 List<ConnectionPorts> cpMapValue = cpMapEntry.getValue();
1022 ConnectionPorts cp1 = cpMapValue.get(0);
1023 String cp1Name = cp1.getCircuitPackName();
1024 switch (cpMapValue.size()) {
1026 // port is bidirectional
1027 Ports port = getTtpPort(cp1, cp1Name, nodeId);
1031 if (!checkTtpPort(port, cp1Name, nodeId, true)) {
1034 String logicalConnectionPoint =
1035 PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(), "TXRX");
1036 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
1037 nodeId, port.getPortName(), cp1Name, logicalConnectionPoint);
1038 portMapList.add(createMappingObject(nodeId, port, cp1Name, logicalConnectionPoint));
1041 // ports are unidirectionals
1042 Ports port1 = getTtpPort(cp1, cp1Name, nodeId);
1043 if (port1 == null) {
1046 ConnectionPorts cp2 = cpMapValue.get(1);
1047 String cp2Name = cp2.getCircuitPackName();
1048 Ports port2 = getTtpPort(cp2, cp2Name, nodeId);
1049 if (port2 == null) {
1052 if (!checkTtpPortsUnidir(port1, port2, cp1Name, cp2Name, nodeId)) {
1055 String logicalConnectionPoint1 = PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(),
1056 port1.getPortDirection().getName().toUpperCase(Locale.getDefault()));
1057 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
1058 nodeId, port1.getPortName(), cp1Name, logicalConnectionPoint1);
1059 portMapList.add(createMappingObject(nodeId, port1, cp1Name, logicalConnectionPoint1));
1060 String logicalConnectionPoint2 = PortMappingUtils.degreeTtpNodeName(cpMapEntry.getKey().toString(),
1061 port2.getPortDirection().getName().toUpperCase(Locale.getDefault()));
1062 LOG.info(PortMappingUtils.ASSOCIATED_LCP_LOGMSG,
1063 nodeId, port2.getPortName(), cp2Name, logicalConnectionPoint2);
1064 portMapList.add(createMappingObject(nodeId, port2, cp2Name, logicalConnectionPoint2));
1067 LOG.error(PortMappingUtils.NOT_CORRECT_CONPORT_LOGMSG, nodeId, cpMapEntry.getKey());
1069 //TODO should it be continue or return false ?
1075 private Ports getTtpPort(ConnectionPorts cp, String cpName, String nodeId) {
1076 InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
1077 .child(CircuitPacks.class, new CircuitPacksKey(cpName))
1078 .child(Ports.class, new PortsKey(cp.getPortName()));
1079 LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp.getPortName(), cpName);
1080 Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
1081 LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
1082 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
1083 if (portObject.isEmpty()) {
1084 LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp.getPortName(), cpName);
1087 return portObject.get();
1090 private boolean checkPortQual(Ports port, String cpName, String nodeId) {
1091 if (port.getPortQual() == null) {
1094 if (PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) {
1095 //used to be LOG.error when called from createTtpPortMapping
1096 LOG.debug(PortMappingUtils.PORT_NOT_RDMEXT_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
1097 nodeId, port.getPortName(), cpName);
1103 private boolean checkTtpPort(Ports port, String cpName, String nodeId, boolean bidirectional) {
1104 if (!checkPortQual(port, cpName, nodeId)) {
1107 if (Direction.Bidirectional.getIntValue() == port.getPortDirection().getIntValue() ^ bidirectional) {
1108 // (a ^ b) makes more sense than (!a && b) here since it can also work for unidirectional links
1109 LOG.error(PortMappingUtils.PORTDIR_ERROR_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
1110 nodeId, port.getPortName(), cpName);
1116 private boolean checkTtpPortsUnidir(Ports port1, Ports port2, String cp1Name, String cp2Name, String nodeId) {
1117 if (!checkTtpPort(port1, cp1Name, nodeId, false)) {
1120 if (!checkTtpPort(port2, cp2Name, nodeId, false)) {
1123 if (!checkPartnerPort(cp1Name, port1, port2)) {
1124 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
1125 nodeId, port2.getPortName(), cp2Name, port1.getPortName(), cp1Name);
1128 // Directions checks are the same for cp1 and cp2, no need to check them twice.
1129 if (!checkPartnerPortNoDir(cp2Name, port2, port1)) {
1130 LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
1131 nodeId, port1.getPortName(), cp1Name, port2.getPortName(), cp2Name);
1137 private NodeInfo createNodeInfo(Info deviceInfo) {
1138 if (deviceInfo.getNodeType() == null) {
1139 // TODO make mandatory in yang
1140 LOG.error(PortMappingUtils.NODE_TYPE_LOGMSG, deviceInfo.getNodeId(), "field missing");
1143 NodeInfoBuilder nodeInfoBldr = new NodeInfoBuilder()
1144 .setOpenroadmVersion(OpenroadmNodeVersion._221)
1146 deviceInfo.getClli() == null || deviceInfo.getClli().isEmpty()
1148 : deviceInfo.getClli())
1149 .setNodeType(NodeTypes.forValue(deviceInfo.getNodeType().getIntValue()));
1150 if (deviceInfo.getModel() != null) {
1151 nodeInfoBldr.setNodeModel(deviceInfo.getModel());
1153 if (deviceInfo.getVendor() != null) {
1154 nodeInfoBldr.setNodeVendor(deviceInfo.getVendor());
1156 if (deviceInfo.getIpAddress() != null) {
1157 nodeInfoBldr.setNodeIpAddress(deviceInfo.getIpAddress());
1159 return nodeInfoBldr.build();