209fef96739068372b5f716096a1eac2c689d890
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / topology / ConvertORToTapiTopology.java
1 /*
2  * Copyright © 2023 Orange, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.transportpce.tapi.topology;
9
10 import java.math.RoundingMode;
11 import java.nio.charset.Charset;
12 import java.util.ArrayList;
13 import java.util.Arrays;
14 import java.util.Collection;
15 import java.util.Collections;
16 import java.util.Comparator;
17 import java.util.HashMap;
18 import java.util.HashSet;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Set;
22 import java.util.TreeMap;
23 import java.util.UUID;
24 import java.util.stream.Collectors;
25 import org.opendaylight.transportpce.common.fixedflex.GridConstant;
26 import org.opendaylight.transportpce.common.fixedflex.GridUtils;
27 import org.opendaylight.transportpce.tapi.TapiStringConstants;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.TerminationPoint1;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev230526.degree.used.wavelengths.UsedWavelengths;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev230526.degree.used.wavelengths.UsedWavelengthsKey;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.networks.network.node.termination.point.PpAttributes;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.networks.network.node.termination.point.TxTtpAttributes;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.networks.network.node.termination.point.XpdrNetworkAttributes;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev230526.xpdr.odu.switching.pools.OduSwitchingPools;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev230526.xpdr.odu.switching.pools.OduSwitchingPoolsBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev230526.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingList;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev230526.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingListBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev230526.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingListKey;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmNodeType;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmTpType;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.xpdr.tp.supported.interfaces.SupportedInterfaceCapability;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev230526.Node1;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.xponder.rev230526.xpdr.mode.attributes.supported.operational.modes.OperationalModeKey;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.TpId;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPoint;
49 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.AdministrativeState;
50 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.CAPACITYUNITGBPS;
51 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Direction;
52 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.LAYERPROTOCOLQUALIFIER;
53 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.LayerProtocolName;
54 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.LifecycleState;
55 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.OperationalState;
56 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.PortRole;
57 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Uuid;
58 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.capacity.pac.AvailableCapacityBuilder;
59 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.capacity.pac.TotalPotentialCapacityBuilder;
60 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.Name;
61 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.NameBuilder;
62 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.NameKey;
63 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.payload.structure.CapacityBuilder;
64 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.tapi.context.ServiceInterfacePoint;
65 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.tapi.context.ServiceInterfacePointBuilder;
66 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.tapi.context.ServiceInterfacePointKey;
67 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.digital.otn.rev221121.ODUTYPEODU0;
68 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.digital.otn.rev221121.ODUTYPEODU2;
69 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.digital.otn.rev221121.ODUTYPEODU2E;
70 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.digital.otn.rev221121.ODUTYPEODU4;
71 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.digital.otn.rev221121.ODUTYPEODUCN;
72 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.digital.otn.rev221121.OTUTYPEOTUCN;
73 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev221121.DIGITALSIGNALTYPE100GigE;
74 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev221121.DIGITALSIGNALTYPE10GigELAN;
75 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev221121.DIGITALSIGNALTYPEGigE;
76 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.PHOTONICLAYERQUALIFIEROTS;
77 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.PHOTONICLAYERQUALIFIEROTSi;
78 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.PHOTONICLAYERQUALIFIEROTSiMC;
79 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.context.topology.context.topology.node.owned.node.edge.point.PhotonicMediaNodeEdgePointSpecBuilder;
80 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.photonic.media.node.edge.point.spec.SpectrumCapabilityPacBuilder;
81 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.spectrum.capability.pac.AvailableSpectrum;
82 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.spectrum.capability.pac.AvailableSpectrumBuilder;
83 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.spectrum.capability.pac.AvailableSpectrumKey;
84 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.spectrum.capability.pac.OccupiedSpectrum;
85 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.spectrum.capability.pac.OccupiedSpectrumBuilder;
86 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.spectrum.capability.pac.OccupiedSpectrumKey;
87 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.spectrum.capability.pac.SupportableSpectrum;
88 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.spectrum.capability.pac.SupportableSpectrumBuilder;
89 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.spectrum.capability.pac.SupportableSpectrumKey;
90 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.FORWARDINGRULE;
91 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.FORWARDINGRULECANNOTFORWARDACROSSGROUP;
92 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.FORWARDINGRULEMAYFORWARDACROSSGROUP;
93 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.RuleType;
94 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.inter.rule.group.AssociatedNodeRuleGroup;
95 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.inter.rule.group.AssociatedNodeRuleGroupBuilder;
96 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.inter.rule.group.AssociatedNodeRuleGroupKey;
97 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.InterRuleGroup;
98 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.InterRuleGroupBuilder;
99 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.InterRuleGroupKey;
100 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.NodeRuleGroup;
101 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.NodeRuleGroupBuilder;
102 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.NodeRuleGroupKey;
103 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.OwnedNodeEdgePoint;
104 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.OwnedNodeEdgePointBuilder;
105 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.OwnedNodeEdgePointKey;
106 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.RiskParameterPacBuilder;
107 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.edge.point.AvailablePayloadStructure;
108 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.edge.point.AvailablePayloadStructureBuilder;
109 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.edge.point.MappedServiceInterfacePoint;
110 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.edge.point.MappedServiceInterfacePointBuilder;
111 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.edge.point.MappedServiceInterfacePointKey;
112 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.edge.point.SupportedCepLayerProtocolQualifierInstances;
113 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.edge.point.SupportedCepLayerProtocolQualifierInstancesBuilder;
114 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.edge.point.SupportedPayloadStructure;
115 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.edge.point.SupportedPayloadStructureBuilder;
116 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.Rule;
117 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.RuleBuilder;
118 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.RuleKey;
119 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.risk.parameter.pac.RiskCharacteristic;
120 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.risk.parameter.pac.RiskCharacteristicBuilder;
121 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Link;
122 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.LinkKey;
123 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.NodeBuilder;
124 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.NodeKey;
125 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.transfer.cost.pac.CostCharacteristic;
126 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.transfer.cost.pac.CostCharacteristicBuilder;
127 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.transfer.timing.pac.LatencyCharacteristic;
128 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.transfer.timing.pac.LatencyCharacteristicBuilder;
129 import org.opendaylight.yangtools.yang.common.Decimal64;
130 import org.opendaylight.yangtools.yang.common.Uint16;
131 import org.opendaylight.yangtools.yang.common.Uint64;
132 import org.slf4j.Logger;
133 import org.slf4j.LoggerFactory;
134
135
136 public class ConvertORToTapiTopology {
137
138     private static final Logger LOG = LoggerFactory.getLogger(ConvertORToTapiTopology.class);
139     private static final TreeMap<Integer, String> OPMODE_LOOPRATE_MAP;
140     private static final int OPMODE_LOOPRATE_MAX;
141     private static final Map<String, Map<String, Map<LAYERPROTOCOLQUALIFIER, Uint64>>> LPN_MAP;
142     private String ietfNodeId;
143     private OpenroadmNodeType ietfNodeType;
144     private AdminStates ietfNodeAdminState;
145     private State ietfNodeOperState;
146     private List<TerminationPoint> oorClientPortList;
147     private List<TerminationPoint> oorNetworkPortList;
148     private OduSwitchingPools oorOduSwitchingPool;
149     private Uuid tapiTopoUuid;
150     private Map<NodeKey, org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node>
151         tapiNodes;
152     private Map<LinkKey, Link> tapiLinks;
153     private Map<ServiceInterfacePointKey, ServiceInterfacePoint> tapiSips;
154     private Map<String, Uuid> uuidMap;
155
156     static {
157         OPMODE_LOOPRATE_MAP = new TreeMap<>(Comparator.reverseOrder());
158         OPMODE_LOOPRATE_MAP.putAll(Map.of(8, "800G", 6, "600G" , 4, "400G" , 3, "300G" , 2, "200G" , 1, "100G"));
159         OPMODE_LOOPRATE_MAX = Collections.max(OPMODE_LOOPRATE_MAP.keySet());
160         LPN_MAP = new HashMap<>(Map.of(
161             "ETH", new HashMap<>(Map.of(
162                 "If1GEODU0", Map.of(
163                     ODUTYPEODU0.VALUE, Uint64.valueOf(0), DIGITALSIGNALTYPEGigE.VALUE, Uint64.valueOf(0)),
164                 "If10GEODU2e", Map.of(
165                     ODUTYPEODU2E.VALUE, Uint64.valueOf(0), DIGITALSIGNALTYPE10GigELAN.VALUE, Uint64.valueOf(0)),
166                 "If10GEODU2", Map.of(
167                     ODUTYPEODU2.VALUE, Uint64.valueOf(0), DIGITALSIGNALTYPE10GigELAN.VALUE, Uint64.valueOf(0)),
168                 "If10GE", Map.of(DIGITALSIGNALTYPE10GigELAN.VALUE, Uint64.valueOf(0)),
169                 "If100GEODU4", Map.of(
170                     ODUTYPEODU4.VALUE, Uint64.valueOf(0), DIGITALSIGNALTYPE100GigE.VALUE, Uint64.valueOf(0)),
171                 "If100GE", Map.of(DIGITALSIGNALTYPE100GigE.VALUE, Uint64.valueOf(0)),
172                 "IfOCH", Map.of(ODUTYPEODU4.VALUE, Uint64.valueOf(0)))),
173             "ODU", new HashMap<>(Map.of(
174                 "If1GEODU0", Map.of(ODUTYPEODU0.VALUE, Uint64.valueOf(0)),
175                 "If10GEODU2e", Map.of(ODUTYPEODU2E.VALUE, Uint64.valueOf(0)),
176                 "If10GEODU2", Map.of(ODUTYPEODU2.VALUE, Uint64.valueOf(0)),
177                 "If100GEODU4", Map.of(ODUTYPEODU4.VALUE, Uint64.valueOf(0)))),
178             "PHOTONIC_MEDIA", new HashMap<>(Map.of(
179                 "IfOCHOTUCnODUCn",
180                     Map.of(ODUTYPEODUCN.VALUE, Uint64.valueOf(1), OTUTYPEOTUCN.VALUE, Uint64.valueOf(1)),
181                 "IfOCH",
182                     Map.of(ODUTYPEODUCN.VALUE, Uint64.valueOf(1), OTUTYPEOTUCN.VALUE, Uint64.valueOf(1),
183                         PHOTONICLAYERQUALIFIEROTSiMC.VALUE, Uint64.valueOf(1),
184                         PHOTONICLAYERQUALIFIEROTS.VALUE, Uint64.valueOf(1))))));
185         LPN_MAP.get("ETH").put("IfOCHOTU4ODU4", LPN_MAP.get("ETH").get("IfOCH"));
186         LPN_MAP.put("DSR", LPN_MAP.get("ETH"));
187         LPN_MAP.get("ODU").put("If10GE", LPN_MAP.get("ODU").get("If10GEODU2"));
188         LPN_MAP.get("ODU").put("If100GE", LPN_MAP.get("ODU").get("If100GEODU4"));
189         LPN_MAP.get("ODU").put("IfOCHOTU4ODU4", LPN_MAP.get("ODU").get("If100GEODU4"));
190         LPN_MAP.get("ODU").put("IfOCH", LPN_MAP.get("ODU").get("If100GEODU4"));
191         LPN_MAP.get("PHOTONIC_MEDIA").put("IfOtsiOtucnOducn", LPN_MAP.get("PHOTONIC_MEDIA").get("IfOCHOTUCnODUCn"));
192         LPN_MAP.get("PHOTONIC_MEDIA").put("IfOCHOTUCnODUCnRegen", LPN_MAP.get("PHOTONIC_MEDIA").get("IfOCHOTUCnODUCn"));
193         LPN_MAP
194             .get("PHOTONIC_MEDIA").put("IfOCHOTUCnODUCnUniregen", LPN_MAP.get("PHOTONIC_MEDIA").get("IfOCHOTUCnODUCn"));
195         LPN_MAP.get("PHOTONIC_MEDIA").put("IfOCHOTU4ODU4", LPN_MAP.get("PHOTONIC_MEDIA").get("IfOCH"));
196         LPN_MAP.get("PHOTONIC_MEDIA").put("IfOCHOTU4ODU4Regen", LPN_MAP.get("PHOTONIC_MEDIA").get("IfOCH"));
197         LPN_MAP.get("PHOTONIC_MEDIA").put("IfOCHOTU4ODU4Uniregen", LPN_MAP.get("PHOTONIC_MEDIA").get("IfOCH"));
198     }
199
200
201     public ConvertORToTapiTopology(Uuid tapiTopoUuid) {
202         this.tapiTopoUuid = tapiTopoUuid;
203         this.tapiNodes = new HashMap<>();
204         this.tapiLinks = new HashMap<>();
205         this.uuidMap = new HashMap<>();
206         this.tapiSips = new HashMap<>();
207     }
208
209     public void convertNode(Node ietfNode, List<String> networkPorts) {
210         this.ietfNodeId = ietfNode.getNodeId().getValue();
211         var ietfAug =
212             ietfNode.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.Node1.class);
213         if (ietfAug == null) {
214             return;
215         }
216         this.ietfNodeType = ietfAug.getNodeType();
217         this.ietfNodeAdminState = ietfAug.getAdministrativeState();
218         this.ietfNodeOperState = ietfAug.getOperationalState();
219         var ietfAugTopo =
220             ietfNode.augmentation(
221                 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class);
222         this.oorNetworkPortList = ietfAugTopo.getTerminationPoint().values().stream()
223             .filter(tp -> tp.augmentation(TerminationPoint1.class).getTpType().getIntValue()
224                     == OpenroadmTpType.XPONDERNETWORK.getIntValue()
225                 && networkPorts.contains(tp.getTpId().getValue()))
226             .sorted((tp1, tp2) -> tp1.getTpId().getValue().compareTo(tp2.getTpId().getValue()))
227             .collect(Collectors.toList());
228         if (this.ietfNodeType.equals(OpenroadmNodeType.TPDR)) {
229             this.oorOduSwitchingPool = createOduSwitchingPoolForTp100G();
230             List<TpId> tpList = this.oorOduSwitchingPool.getNonBlockingList().values().stream()
231                 .flatMap(nbl -> nbl.getTpList().stream())
232                 .collect(Collectors.toList());
233             this.oorClientPortList = ietfAugTopo.getTerminationPoint().values().stream()
234                 .filter(tp -> tp.augmentation(TerminationPoint1.class).getTpType().getIntValue()
235                         == OpenroadmTpType.XPONDERCLIENT.getIntValue()
236                     && tpList.contains(tp.getTpId()))
237                 .sorted((tp1, tp2) -> tp1.getTpId().getValue().compareTo(tp2.getTpId().getValue()))
238                 .collect(Collectors.toList());
239             this.oorClientPortList.forEach(tp -> LOG.info("tp = {}", tp.getTpId()));
240         } else {
241             this.oorOduSwitchingPool = ietfNode.augmentation(Node1.class).getSwitchingPools().getOduSwitchingPools()
242                 .values().stream().findFirst().orElseThrow();
243             this.oorClientPortList = ietfAugTopo.getTerminationPoint().values().stream()
244                 .filter(tp -> tp.augmentation(TerminationPoint1.class).getTpType().getIntValue()
245                     == OpenroadmTpType.XPONDERCLIENT.getIntValue())
246                 .sorted((tp1, tp2) -> tp1.getTpId().getValue().compareTo(tp2.getTpId().getValue()))
247                 .collect(Collectors.toList());
248         }
249
250         // node creation [DSR/ODU] ([DSR/ODU] and OTSI merged in R 2.4.X)
251         LOG.info("creation of a DSR/ODU node for {}", this.ietfNodeId);
252         String nodeIdXpdr = String.join("+", this.ietfNodeId, TapiStringConstants.XPDR);
253         this.uuidMap.put(nodeIdXpdr,
254                 //nodeUuid
255                 new Uuid(UUID.nameUUIDFromBytes(nodeIdXpdr.getBytes(Charset.forName("UTF-8"))).toString()));
256         Name nameDsr = new NameBuilder().setValueName("dsr/odu node name").setValue(nodeIdXpdr).build();
257         Name namePhot = new NameBuilder().setValueName("otsi node name").setValue(nodeIdXpdr).build();
258         Name nameNodeType = new NameBuilder().setValueName("Node Type").setValue(this.ietfNodeType.getName()).build();
259         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node dsrNode =
260             createTapiNode(
261                 Map.of(nameDsr.key(), nameDsr, namePhot.key(), namePhot, nameNodeType.key(), nameNodeType),
262                 //dsrLayerProtocols
263                 Set.of(LayerProtocolName.DSR, LayerProtocolName.ODU,
264                        LayerProtocolName.DIGITALOTN, LayerProtocolName.PHOTONICMEDIA));
265         LOG.debug("XPDR Node {} should have {} NEPs and SIPs",
266             this.ietfNodeId, this.oorClientPortList.size() + this.oorNetworkPortList.size());
267         LOG.info("XPDR Node {} has {} NEPs and {} SIPs",
268             this.ietfNodeId,
269             dsrNode.getOwnedNodeEdgePoint().values().size(),
270             dsrNode.getOwnedNodeEdgePoint().values().stream()
271                 .filter(nep -> nep.getMappedServiceInterfacePoint() != null).count());
272         tapiNodes.put(dsrNode.key(), dsrNode);
273     }
274
275     public Map<NodeRuleGroupKey, NodeRuleGroup> createNodeRuleGroupForRdmNode(String topoType, Uuid nodeUuid,
276             String subNodeName, List<OwnedNodeEdgePointKey> onepl, FORWARDINGRULE forwardingRule, int index) {
277         Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.NodeEdgePointKey,
278             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.NodeEdgePoint>
279                 nepMap = new HashMap<>();
280         for (OwnedNodeEdgePointKey onepKey : onepl) {
281             var nep = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121
282                     .node.rule.group.NodeEdgePointBuilder()
283                 .setTopologyUuid(tapiTopoUuid)
284                 .setNodeUuid(nodeUuid)
285                 .setNodeEdgePointUuid(onepKey.getUuid())
286                 .build();
287             nepMap.put(nep.key(), nep);
288         }
289         String nrgNameValue = String.join("-", subNodeName, "node-rule-group-" + index);
290         Rule rule = new RuleBuilder()
291             .setLocalId("forward")
292             .setForwardingRule(forwardingRule)
293             .setRuleType(new HashSet<RuleType>(Set.of(RuleType.FORWARDING)))
294             .build();
295         Name nrgName = new NameBuilder().setValueName("nrg name").setValue(nrgNameValue).build();
296         NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
297             .setName(Map.of(nrgName.key(), nrgName))
298             .setUuid(new Uuid(UUID.nameUUIDFromBytes((nrgNameValue).getBytes(Charset.forName("UTF-8"))).toString()))
299             .setRule(new HashMap<RuleKey, Rule>(Map.of(rule.key(), rule)))
300             .setNodeEdgePoint(nepMap)
301             .build();
302         return new HashMap<>(Map.of(nodeRuleGroup.key(), nodeRuleGroup));
303     }
304
305     public Map<NodeRuleGroupKey, NodeRuleGroup> createAllNodeRuleGroupForRdmNode(
306             String topoType, Uuid nodeUuid, String orNodeId, Collection<OwnedNodeEdgePoint> onepl) {
307         List<OwnedNodeEdgePoint> otsNepList = topoType.equals("T0ML") ? onepl.stream().collect(Collectors.toList())
308                 : onepl.stream()
309                     .filter(onep -> onep.getName().keySet().contains(new NameKey("PHOTONIC_MEDIA_OTSNodeEdgePoint")))
310                     .collect(Collectors.toList());
311         LOG.info("Creating NRG for {} {}", topoType, otsNepList);
312         List<OwnedNodeEdgePointKey> degOnepKeyList = new ArrayList<>();
313         List<String> srgNames = new ArrayList<>();
314         Map<OwnedNodeEdgePointKey,String> srgMap = new HashMap<>();
315         for (OwnedNodeEdgePoint onep : otsNepList) {
316             String onepName = onep.getName()
317                 .get(new NameKey(topoType.equals("T0ML") ? "NodeEdgePoint name" : "PHOTONIC_MEDIA_OTSNodeEdgePoint"))
318                 .getValue();
319             String subNodeName = topoType.equals("T0ML") ? "ROADMINFRA-SRG-PP"
320                 : String.join("-", onepName.split("\\+")[0], onepName.split("\\+")[2]);
321             if (subNodeName.contains("DEG")) {
322                 subNodeName = subNodeName.split("\\-TTP")[0];
323                 degOnepKeyList.add(onep.key());
324             } else if (subNodeName.contains("SRG")) {
325                 subNodeName = subNodeName.split("\\-PP")[0];
326                 srgMap.put(onep.key(), subNodeName);
327                 if (!srgNames.contains(subNodeName)) {
328                     srgNames.add(subNodeName);
329                 }
330             }
331         }
332         int index = 0;
333         Map<NodeRuleGroupKey, NodeRuleGroup> globalNrgMap = new  HashMap<>();
334         if (topoType.equals("Full")) {
335             globalNrgMap.putAll(createNodeRuleGroupForRdmNode(
336                     topoType, nodeUuid, String.join("-", orNodeId, "DEG"),
337                     degOnepKeyList, FORWARDINGRULEMAYFORWARDACROSSGROUP.VALUE, index));
338             index++;
339         }
340         for (String srgName : srgNames) {
341             globalNrgMap.putAll(createNodeRuleGroupForRdmNode(
342                 topoType,
343                 nodeUuid,
344                 srgName,
345                 srgMap.entrySet().stream()
346                     .filter(item -> item.getValue().equals(srgName))
347                     .map(item -> item.getKey())
348                     .collect(Collectors.toList()),
349                 // For T0ML we consider any port of ROADM INFRA can connect to potentially any other port
350                 //topoType.equals("T0ML") ? FORWARDINGRULEMAYFORWARDACROSSGROUP.VALUE
351                 topoType.equals("T0ML") ? FORWARDINGRULEMAYFORWARDACROSSGROUP.VALUE
352                     : FORWARDINGRULECANNOTFORWARDACROSSGROUP.VALUE,
353                 // Whereas for Abstracted or Full Topology we consider any port of the same SRG can not forward to
354                 // another port of the same SRG. Connectivity between SRGS will be defined through inter-rule-group
355                 index));
356             index++;
357             LOG.debug("AllNodeRuleGroup : creating a NRG for {}", srgName);
358         }
359         return globalNrgMap;
360     }
361
362     public Map<InterRuleGroupKey, InterRuleGroup> createInterRuleGroupForRdmNode(
363             String topoType, Uuid nodeUuid,String orNodeId, List<NodeRuleGroupKey> nrgList) {
364         Map<AssociatedNodeRuleGroupKey, AssociatedNodeRuleGroup> associatedNrgMap = new HashMap<>();
365         for (NodeRuleGroupKey nrgKey : nrgList) {
366             AssociatedNodeRuleGroup associatedNrg = new AssociatedNodeRuleGroupBuilder()
367                 .setTopologyUuid(tapiTopoUuid)
368                 .setNodeUuid(nodeUuid)
369                 .setNodeRuleGroupUuid(nrgKey.getUuid())
370                 .build();
371             associatedNrgMap.put(associatedNrg.key(), associatedNrg);
372         }
373         var rule = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121
374                 .inter.rule.group.RuleBuilder()
375             .setLocalId("forward")
376             .setForwardingRule(FORWARDINGRULEMAYFORWARDACROSSGROUP.VALUE)
377             .setRuleType(new HashSet<RuleType>(Set.of(RuleType.FORWARDING)))
378             .build();
379         String irgNameValue = topoType.equals("Full") ? orNodeId + " inter rule group-" : "rdm infra inter rule group-";
380         Name irgName = new NameBuilder().setValueName("irg name").setValue(irgNameValue).build();
381         InterRuleGroup interRuleGroup = new InterRuleGroupBuilder()
382             .setUuid(new Uuid(UUID.nameUUIDFromBytes((irgNameValue).getBytes(Charset.forName("UTF-8"))).toString()))
383             .setName(Map.of(irgName.key(), irgName))
384             .setRule(new HashMap<>(Map.of(rule.key(), rule)))
385             .setAssociatedNodeRuleGroup(associatedNrgMap)
386             .build();
387         return new HashMap<>(Map.of(new InterRuleGroupKey(interRuleGroup.getUuid()), interRuleGroup));
388     }
389
390     public Map<MappedServiceInterfacePointKey, MappedServiceInterfacePoint> createMSIP(
391             int nb, LayerProtocolName layerProtocol, String tpId, String nodeid,
392             Collection<SupportedInterfaceCapability> supportedInterfaceCapability,
393             OperationalState operState, AdministrativeState adminState) {
394         // add them to SIP context
395         Map<MappedServiceInterfacePointKey, MappedServiceInterfacePoint> msipl = new HashMap<>();
396         for (int i = 0; i < nb; i++) {
397             String sipName = nb == 1 ? String.join("+", "SIP", nodeid, tpId)
398                     : String.join("+", "SIP", nodeid, tpId, "Nber", String.valueOf(i));
399             LOG.info("SIP = {}", sipName);
400             Uuid sipUuid = new Uuid(UUID.nameUUIDFromBytes(sipName.getBytes(Charset.forName("UTF-8"))).toString());
401             MappedServiceInterfacePoint msip =
402                 new MappedServiceInterfacePointBuilder().setServiceInterfacePointUuid(sipUuid).build();
403             ServiceInterfacePoint sip =
404                 createSIP(sipUuid, layerProtocol, tpId, nodeid, supportedInterfaceCapability, operState, adminState);
405             this.tapiSips.put(sip.key(), sip);
406             msipl.put(msip.key(), msip);
407             LOG.debug("SIP created {}", sip.getUuid());
408             LOG.debug("This SIP corresponds to SIP+nodeId {} + TpId {}", nodeid, tpId);
409         }
410         return msipl;
411     }
412
413     public List<AvailablePayloadStructure> createAvailablePayloadStructureForPhtncMedia(
414             Boolean otsiProvisioned,
415             Collection<SupportedInterfaceCapability> sicList,
416             List<OperationalModeKey> supportedOpModes) {
417         if (supportedOpModes == null || supportedOpModes.isEmpty()) {
418             return null;
419         }
420         Integer nepRate = 0;
421         Integer loopRate = 0;
422         for (OperationalModeKey operationalMode : supportedOpModes) {
423             for (Map.Entry<Integer, String> entry: OPMODE_LOOPRATE_MAP.entrySet()) {
424                 if (operationalMode.toString().contains(entry.getValue())) {
425                     loopRate = entry.getKey();
426                     break;
427                 }
428             }
429             if (loopRate > nepRate) {
430                 nepRate = loopRate;
431                 if (nepRate >= OPMODE_LOOPRATE_MAX) {
432                     break;
433                 }
434             }
435         }
436         List<AvailablePayloadStructure> aps = new ArrayList<>();
437         Integer cepInstanceNber = otsiProvisioned ? 0 : 1;
438         for (SupportedInterfaceCapability sic : sicList) {
439             switch (sic.getIfCapType().toString().split("\\{")[0]) {
440                 case "IfOCHOTU4ODU4":
441                 case "IfOCHOTU4ODU4Regen":
442                 case "IfOCHOTU4ODU4Uniregen":
443                     aps.add(new AvailablePayloadStructureBuilder()
444                         .setMultiplexingSequence(Set.of(PHOTONICLAYERQUALIFIEROTSi.VALUE, ODUTYPEODU4.VALUE))
445                         .setNumberOfCepInstances(Uint64.valueOf(cepInstanceNber))
446                         .setCapacity(
447                             new CapacityBuilder()
448                                 .setUnit(CAPACITYUNITGBPS.VALUE)
449                                 .setValue(Decimal64.valueOf(100.0 * cepInstanceNber, RoundingMode.DOWN))
450                                 .build())
451                         .build());
452                     break;
453                 case "IfOCHOTUCnODUCn":
454                 case "IfOtsiOtucnOducn":
455                 case "IfOCHOTUCnODUCnRegen":
456                 case "IfOCHOTUCnODUCnUniregen":
457                     aps.add(new AvailablePayloadStructureBuilder()
458                         .setMultiplexingSequence(Set.of(PHOTONICLAYERQUALIFIEROTSi.VALUE, OTUTYPEOTUCN.VALUE,
459                             ODUTYPEODUCN.VALUE, ODUTYPEODU4.VALUE))
460                         .setNumberOfCepInstances(Uint64.valueOf(nepRate * cepInstanceNber))
461                         .setCapacity(
462                             new CapacityBuilder()
463                                 .setUnit(CAPACITYUNITGBPS.VALUE)
464                                 .setValue(Decimal64.valueOf(nepRate * 100.0 * cepInstanceNber, RoundingMode.DOWN))
465                                 .build())
466                         .build());
467                     break;
468                 default:
469                     break;
470             }
471         }
472         return aps.stream().distinct().toList();
473     }
474
475     public List<SupportedPayloadStructure> createSupportedPayloadStructureForPhtncMedia(
476             Collection<SupportedInterfaceCapability> sicList, List<OperationalModeKey> supportedOpModes) {
477         if (supportedOpModes == null || supportedOpModes.isEmpty()) {
478             return null;
479         }
480         Integer nepRate = 0;
481         Integer loopRate = 0;
482         for (OperationalModeKey operationalMode : supportedOpModes) {
483             for (Map.Entry<Integer, String> entry: OPMODE_LOOPRATE_MAP.entrySet()) {
484                 if (operationalMode.toString().contains(entry.getValue())) {
485                     loopRate = entry.getKey();
486                     break;
487                 }
488             }
489             if (loopRate > nepRate) {
490                 nepRate = loopRate;
491                 if (nepRate >= OPMODE_LOOPRATE_MAX) {
492                     break;
493                 }
494             }
495         }
496         List<SupportedPayloadStructure> sps = new ArrayList<>();
497         for (SupportedInterfaceCapability sic : sicList) {
498             String ifCapType = sic.getIfCapType().toString().split("\\{")[0];
499             switch (ifCapType) {
500                 case "IfOCHOTU4ODU4":
501                 case "IfOCHOTU4ODU4Regen":
502                 case "IfOCHOTU4ODU4Uniregen":
503                     sps.add(new SupportedPayloadStructureBuilder()
504                         .setMultiplexingSequence(Set.of(PHOTONICLAYERQUALIFIEROTSi.VALUE, ODUTYPEODU4.VALUE))
505                         .setNumberOfCepInstances(Uint64.valueOf(1))
506                         .setCapacity(
507                             new CapacityBuilder()
508                                 .setUnit(CAPACITYUNITGBPS.VALUE)
509                                 .setValue(Decimal64.valueOf(100.0, RoundingMode.DOWN))
510                                 .build())
511                         .build());
512                     break;
513                 case "IfOCHOTUCnODUCn":
514                 case "IfOtsiOtucnOducn":
515                 case "IfOCHOTUCnODUCnRegen":
516                 case "IfOCHOTUCnODUCnUniregen":
517                     sps.add(new SupportedPayloadStructureBuilder()
518                         .setMultiplexingSequence(Set.of(
519                             PHOTONICLAYERQUALIFIEROTSi.VALUE, OTUTYPEOTUCN.VALUE,
520                             ODUTYPEODUCN.VALUE, ODUTYPEODU4.VALUE))
521                         .setNumberOfCepInstances(Uint64.valueOf(nepRate))
522                         .setCapacity(
523                             new CapacityBuilder()
524                                 .setUnit(CAPACITYUNITGBPS.VALUE)
525                                 .setValue(Decimal64.valueOf(nepRate * 100.0, RoundingMode.DOWN))
526                                 .build())
527                         .build());
528                     break;
529                 default:
530                     break;
531             }
532         }
533         return sps.stream().distinct().toList();
534     }
535
536     public List<SupportedCepLayerProtocolQualifierInstances> createSupportedCepLayerProtocolQualifier(
537             Collection<SupportedInterfaceCapability> sicList, LayerProtocolName lpn) {
538         if (sicList == null) {
539             return new ArrayList<>(List.of(
540                 new SupportedCepLayerProtocolQualifierInstancesBuilder()
541                     .setLayerProtocolQualifier(PHOTONICLAYERQUALIFIEROTS.VALUE)
542                     .setNumberOfCepInstances(Uint64.valueOf(1))
543                     .build()));
544         }
545         LOG.debug("SIC list = {}", sicList);
546         List<SupportedCepLayerProtocolQualifierInstances> sclpqiList = new ArrayList<>();
547         String lpnName = lpn.getName();
548         for (SupportedInterfaceCapability sic : sicList) {
549             String ifCapType = sic.getIfCapType().toString().split("\\{")[0];
550             if (!LPN_MAP.containsKey(lpnName)) {
551                 LOG.error("Layer Protocol Name is unknown {}", lpnName);
552                 break;
553             }
554             var ifCapTypeMap = LPN_MAP.get(lpnName);
555             if (!ifCapTypeMap.containsKey(ifCapType)) {
556                 LOG.error("IfCapability type {} not managed", ifCapType);
557                 break;
558             }
559             for (LAYERPROTOCOLQUALIFIER qualifier: ifCapTypeMap.get(ifCapType).keySet()) {
560                 sclpqiList.add(new SupportedCepLayerProtocolQualifierInstancesBuilder()
561                     .setLayerProtocolQualifier(qualifier)
562                     .setNumberOfCepInstances(Uint64.valueOf(1))
563                     .build());
564             }
565         }
566         return sclpqiList.stream().distinct().toList();
567     }
568
569     public Map<Double, Double> getXpdrUsedWavelength(TerminationPoint tp) {
570         var tpAug = tp.augmentation(
571             org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.TerminationPoint1.class);
572         if (tpAug == null) {
573             return null;
574         }
575         XpdrNetworkAttributes xnatt = tpAug.getXpdrNetworkAttributes();
576         if (xnatt == null) {
577             return null;
578         }
579         var xnattWvlgth = xnatt.getWavelength();
580         if (xnattWvlgth == null) {
581             return null;
582         }
583         var freq = xnattWvlgth.getFrequency();
584         if (freq == null) {
585             return null;
586         }
587         var width = xnattWvlgth.getWidth();
588         if (width == null) {
589             return null;
590         }
591         Double freqValue = freq.getValue().doubleValue();
592         Double widthValue = width.getValue().doubleValue();
593         Double value = freqValue - widthValue * 0.001 / 2;
594         return new HashMap<>(Map.of(value, value));
595     }
596
597     public Map<Double, Double> getPPUsedWavelength(TerminationPoint tp) {
598         var tpAug = tp.augmentation(
599             org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.TerminationPoint1.class);
600         if (tpAug == null) {
601             return null;
602         }
603         PpAttributes ppAtt = tpAug.getPpAttributes();
604         if (ppAtt == null) {
605             return null;
606         }
607         var usedWvl = ppAtt.getUsedWavelength();
608         if (usedWvl == null || usedWvl.isEmpty()) {
609             return null;
610         }
611         var usedWvlfirstValue = usedWvl.entrySet().iterator().next().getValue();
612         Double centFreq = usedWvlfirstValue.getFrequency().getValue().doubleValue();
613         Double width = usedWvlfirstValue.getWidth().getValue().doubleValue();
614         return  new HashMap<>(Map.of(centFreq - width * 0.001 / 2, centFreq + width * 0.001 / 2));
615     }
616
617     public Map<Double, Double> getTTPUsedFreqMap(TerminationPoint tp) {
618         byte[] byteArray = new byte[GridConstant.NB_OCTECTS];
619         Arrays.fill(byteArray, (byte) GridConstant.AVAILABLE_SLOT_VALUE);
620         var termPoint1 = tp.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526
621             .TerminationPoint1.class);
622         if (termPoint1 == null) {
623             return null;
624         }
625         TxTtpAttributes txttpAtt = termPoint1.getTxTtpAttributes();
626         if (txttpAtt  == null) {
627             return null;
628         }
629         var txttpAttUsedWvl = txttpAtt.getUsedWavelengths();
630         if (txttpAttUsedWvl == null || txttpAttUsedWvl.isEmpty()) {
631             var txttpAttAvlFreqMaps = txttpAtt.getAvailFreqMaps();
632             if (txttpAttAvlFreqMaps == null || !txttpAttAvlFreqMaps.keySet().toString().contains(GridConstant.C_BAND)) {
633                 return null;
634             }
635             byte[] freqBitSet = new byte[GridConstant.NB_OCTECTS];
636             LOG.debug("Creation of Bitset {}", freqBitSet);
637             freqBitSet = txttpAttAvlFreqMaps.entrySet().stream()
638                 .filter(afm -> afm.getKey().toString().equals(GridConstant.C_BAND))
639                 .findFirst().orElseThrow().getValue().getFreqMap();
640             for (int i = 0; i < GridConstant.EFFECTIVE_BITS; i++) {
641                 if (freqBitSet[i] == 0) {
642                     freqBitSet[i] = 1;
643                 } else {
644                     freqBitSet[i] = 0;
645                 }
646             }
647             return getFreqMapFromBitSet(freqBitSet);
648         }
649         Map<Double,Double> freqMap = new HashMap<>();
650         for (Map.Entry<UsedWavelengthsKey, UsedWavelengths> usedLambdas : txttpAttUsedWvl.entrySet()) {
651             Double centFreq = usedLambdas.getValue().getFrequency().getValue().doubleValue();
652             Double width = usedLambdas.getValue().getWidth().getValue().doubleValue();
653             freqMap.put(centFreq - width * 0.001 / 2, centFreq + width * 0.001 / 2);
654         }
655         return freqMap;
656     }
657
658     public Map<Double, Double> getTTPAvailableFreqMap(TerminationPoint tp) {
659         var termPoint1 = tp.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526
660             .TerminationPoint1.class);
661         if (termPoint1 == null) {
662             return null;
663         }
664         TxTtpAttributes txttpAtt = termPoint1.getTxTtpAttributes();
665         if (txttpAtt == null) {
666             return null;
667         }
668         var avlFreqMaps = txttpAtt.getAvailFreqMaps();
669         if (avlFreqMaps == null || !avlFreqMaps.keySet().toString().contains(GridConstant.C_BAND)) {
670             return null;
671         }
672         byte[] byteArray = new byte[GridConstant.NB_OCTECTS];
673         LOG.debug("Creation of Bitset {}", byteArray);
674         return getFreqMapFromBitSet(
675             avlFreqMaps.entrySet().stream()
676                 .filter(afm -> afm.getKey().toString().equals(GridConstant.C_BAND))
677                 .findFirst().orElseThrow().getValue().getFreqMap());
678     }
679
680     public Map<Double, Double> getTTP11AvailableFreqMap(
681             org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.TerminationPoint1 tp) {
682         if (tp == null) {
683             return null;
684         }
685         TxTtpAttributes txttpAtt = tp.getTxTtpAttributes();
686         if (txttpAtt == null) {
687             return null;
688         }
689         var avlFreqMaps = txttpAtt.getAvailFreqMaps();
690         if (avlFreqMaps == null || !avlFreqMaps.keySet().toString().contains(GridConstant.C_BAND)) {
691             return null;
692         }
693         byte[] byteArray = new byte[GridConstant.NB_OCTECTS];
694         LOG.debug("Creation of Bitset {}", byteArray);
695         return getFreqMapFromBitSet(
696             avlFreqMaps.entrySet().stream()
697                 .filter(afm -> afm.getKey().toString().equals(GridConstant.C_BAND))
698                 .findFirst().orElseThrow().getValue().getFreqMap());
699     }
700
701     public Map<Double, Double> getPP11UsedWavelength(
702             org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.TerminationPoint1 tp) {
703         if (tp == null) {
704             return null;
705         }
706         PpAttributes ppAtt = tp.getPpAttributes();
707         if (ppAtt == null) {
708             return null;
709         }
710         var usedWvl = ppAtt.getUsedWavelength();
711         if (usedWvl == null || usedWvl.isEmpty()) {
712             return null;
713         }
714         var usedWvlFirstValue = usedWvl.entrySet().iterator().next().getValue();
715         Double centFreq = usedWvlFirstValue.getFrequency().getValue().doubleValue();
716         Double width = usedWvlFirstValue.getWidth().getValue().doubleValue();
717         return new HashMap<>(Map.of(centFreq - width * 0.001 / 2, centFreq + width * 0.001 / 2));
718     }
719
720     public Map<Double, Double> getTTP11UsedFreqMap(
721             org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.TerminationPoint1 tp) {
722         byte[] byteArray = new byte[GridConstant.NB_OCTECTS];
723         Arrays.fill(byteArray, (byte) GridConstant.AVAILABLE_SLOT_VALUE);
724         if (tp == null) {
725             return null;
726         }
727         TxTtpAttributes txttpAtt = tp.getTxTtpAttributes();
728         if (txttpAtt == null) {
729             return null;
730         }
731         var txttpAttUsedWvl = txttpAtt.getUsedWavelengths();
732         if (txttpAttUsedWvl == null || txttpAttUsedWvl.isEmpty()) {
733             var txttpAttAvlFreqMaps = txttpAtt.getAvailFreqMaps();
734             if (txttpAttAvlFreqMaps == null || !txttpAttAvlFreqMaps.keySet().toString().contains(GridConstant.C_BAND)) {
735                 return null;
736             }
737             byte[] freqBitSet = new byte[GridConstant.NB_OCTECTS];
738             LOG.debug("Creation of Bitset {}", freqBitSet);
739             freqBitSet = txttpAttAvlFreqMaps.entrySet().stream()
740                 .filter(afm -> afm.getKey().toString().equals(GridConstant.C_BAND))
741                 .findFirst().orElseThrow().getValue().getFreqMap();
742             for (int i = 0; i < GridConstant.EFFECTIVE_BITS; i++) {
743                 if (freqBitSet[i] == 0) {
744                     freqBitSet[i] = 1;
745                 } else {
746                     freqBitSet[i] = 0;
747                 }
748             }
749             return getFreqMapFromBitSet(freqBitSet);
750         }
751         Map<Double,Double> freqMap = new HashMap<>();
752         for (Map.Entry<UsedWavelengthsKey, UsedWavelengths> usedLambdas : txttpAttUsedWvl.entrySet()) {
753             var usedLambdasValue = usedLambdas.getValue();
754             Double centFreq = usedLambdasValue.getFrequency().getValue().doubleValue();
755             Double width = usedLambdasValue.getWidth().getValue().doubleValue();
756             freqMap.put(centFreq - width * 0.001 / 2, centFreq + width * 0.001 / 2);
757         }
758         return freqMap;
759     }
760
761     public Map<Double, Double> getFreqMapFromBitSet(byte[] byteArray) {
762         // Provides a Map <LowerFreq, HigherFreq> describing start and stop frequencies of all slots that are available
763         // in the ByteArray describing the spectrum : bit sets initially sets to 1/true
764         // In case the byte array has been inverted before calling this method, it provides respectively a map
765         // describing all occupied slots!
766         Map<Double,Double> freqMap = new HashMap<>();
767         Double startFreq = GridConstant.START_EDGE_FREQUENCY;
768         Double stopFreq = 0.0;
769         boolean occupied = false;
770         if (byteArray[0] == 0) {
771             occupied = true;
772         }
773         for (int index = 0 ; index < GridConstant.EFFECTIVE_BITS ; index++) {
774             if (occupied) {
775                 if (byteArray[index] == 1) {
776                     startFreq = GridUtils.getStartFrequencyFromIndex(index).doubleValue();
777                     stopFreq = GridUtils.getStartFrequencyFromIndex(index).doubleValue();
778                     occupied = false;
779                 }
780             } else {
781                 if (byteArray[index] == 0) {
782                     stopFreq = GridUtils.getStartFrequencyFromIndex(index).doubleValue();
783                     occupied = true;
784                 }
785             }
786             if (occupied) {
787                 if (stopFreq.doubleValue() > startFreq.doubleValue()) {
788                     freqMap.put(startFreq, stopFreq);
789                     startFreq = stopFreq;
790                 }
791             } else {
792                 if (index == GridConstant.EFFECTIVE_BITS - 1 && startFreq.doubleValue() == stopFreq.doubleValue()) {
793                     stopFreq = GridUtils.getStopFrequencyFromIndex(index).doubleValue();
794                     freqMap.put(startFreq, stopFreq);
795                 }
796             }
797         }
798         return freqMap;
799     }
800
801     public OwnedNodeEdgePointBuilder addPayloadStructureAndPhotSpecToOnep(String nodeId,
802             Map<Double, Double> freqMap, List<OperationalModeKey> operModeList,
803             Collection<SupportedInterfaceCapability> sicColl, OwnedNodeEdgePointBuilder onepBldr, String keyword) {
804         if (!String.join("+", nodeId, TapiStringConstants.OTSI_MC).equals(keyword)
805                 && !String.join("+", nodeId, TapiStringConstants.PHTNC_MEDIA_OTS).equals(keyword)) {
806             return onepBldr;
807         }
808         LOG.debug("Entering LOOP Step1");
809         double naz = 0.01;
810         Double lowSupFreq = GridConstant.START_EDGE_FREQUENCY * 1E09 ;
811         Double upSupFreq = lowSupFreq + GridConstant.GRANULARITY * GridConstant.EFFECTIVE_BITS * 1E06 + naz;
812         lowSupFreq += naz;
813         // Creating OTS & OTSI_MC NEP specific attributes
814         onepBldr.setSupportedPayloadStructure(
815             createSupportedPayloadStructureForPhtncMedia(sicColl,operModeList));
816         SpectrumCapabilityPacBuilder spectrumPac = new SpectrumCapabilityPacBuilder();
817         OccupiedSpectrumBuilder ospecBd = new OccupiedSpectrumBuilder();
818         if (freqMap == null || freqMap.isEmpty()) {
819 //                TODO: verify if we need to fill OcupiedSpectrum as follows when no lambda provisioned
820 //                ospecBd
821 //                    .setUpperFrequency(Uint64.valueOf(0))
822 //                    .setLowerFrequency(Uint64.valueOf(0));
823             onepBldr.setAvailablePayloadStructure(
824                 createAvailablePayloadStructureForPhtncMedia(false, sicColl,operModeList));
825             AvailableSpectrum  aspec = new AvailableSpectrumBuilder()
826                 .setLowerFrequency(Uint64.valueOf(Math.round(lowSupFreq)))
827                 .setUpperFrequency(Uint64.valueOf(Math.round(upSupFreq)))
828                 .build();
829             spectrumPac.setAvailableSpectrum(
830                 new HashMap<AvailableSpectrumKey, AvailableSpectrum>(Map.of(
831                     new AvailableSpectrumKey(aspec.getLowerFrequency(), aspec.getUpperFrequency()), aspec)));
832         } else {
833             LOG.debug("Entering LOOP Step2");
834             onepBldr.setAvailablePayloadStructure(
835                 createAvailablePayloadStructureForPhtncMedia(true, sicColl,operModeList));
836             for (Map.Entry<Double, Double> frequency : freqMap.entrySet()) {
837                 ospecBd
838                     .setLowerFrequency(Uint64.valueOf(Math.round(frequency.getKey().doubleValue() * 1E09)))
839                     .setUpperFrequency(Uint64.valueOf(Math.round(frequency.getValue().doubleValue() * 1E09)));
840             }
841             OccupiedSpectrum ospec = ospecBd.build();
842             spectrumPac.setOccupiedSpectrum(
843                 new HashMap<OccupiedSpectrumKey, OccupiedSpectrum>(Map.of(
844                     new OccupiedSpectrumKey(ospec.getLowerFrequency(), ospec.getUpperFrequency()), ospec)));
845         }
846         LOG.debug("Entering LOOP Step3");
847         SupportableSpectrum  sspec = new SupportableSpectrumBuilder()
848             .setLowerFrequency(Uint64.valueOf(Math.round(lowSupFreq)))
849             .setUpperFrequency(Uint64.valueOf(Math.round(upSupFreq)))
850             .build();
851         spectrumPac.setSupportableSpectrum(
852             new HashMap<SupportableSpectrumKey, SupportableSpectrum>(Map.of(
853                 new SupportableSpectrumKey(sspec.getLowerFrequency(), sspec.getUpperFrequency()), sspec)));
854         LOG.debug("Entering LOOP Step4");
855         var onep1 = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121
856                 .OwnedNodeEdgePoint1Builder()
857             .setPhotonicMediaNodeEdgePointSpec(
858                 new PhotonicMediaNodeEdgePointSpecBuilder().setSpectrumCapabilityPac(spectrumPac.build()).build())
859             .build();
860         LOG.debug("creating Photonic NEP SPEC for node {} and nep {}", nodeId, onep1);
861         onepBldr.addAugmentation(onep1);
862         LOG.debug("Entering LOOP Step5");
863         return onepBldr;
864     }
865
866
867     public OwnedNodeEdgePointBuilder addPhotSpecToRoadmOnep(String nodeId,
868             Map<Double, Double> usedFreqMap, Map<Double, Double> availableFreqMap,
869             OwnedNodeEdgePointBuilder onepBldr, String keyword) {
870         if (!String.join("+", nodeId, TapiStringConstants.PHTNC_MEDIA_OTS).equals(keyword)
871                 && !String.join("+", nodeId, TapiStringConstants.PHTNC_MEDIA_OMS).equals(keyword)) {
872             return onepBldr;
873         }
874         // Creating OTS/OMS NEP specific attributes
875         double naz = 0.01;
876         Double lowSupFreq = GridConstant.START_EDGE_FREQUENCY * 1E09 ;
877         Double upSupFreq = lowSupFreq + GridConstant.GRANULARITY * GridConstant.EFFECTIVE_BITS * 1E06 + naz;
878         lowSupFreq += naz;
879         SpectrumCapabilityPacBuilder spectrumPac = new SpectrumCapabilityPacBuilder();
880         Map<Double, Double> freqMap = null;
881         if (usedFreqMap == null || usedFreqMap.isEmpty()) {
882             freqMap = Map.of(lowSupFreq, upSupFreq);
883         } else {
884             Map<OccupiedSpectrumKey, OccupiedSpectrum> ospecMap = new HashMap<>();
885             OccupiedSpectrumBuilder ospecBd = new OccupiedSpectrumBuilder();
886             for (Map.Entry<Double, Double> frequency : usedFreqMap.entrySet()) {
887                 ospecBd
888                     .setLowerFrequency(Uint64.valueOf(Math.round(frequency.getKey().doubleValue() * 1E09)))
889                     .setUpperFrequency(Uint64.valueOf(Math.round(frequency.getValue().doubleValue() * 1E09)));
890                 OccupiedSpectrum ospec = ospecBd.build();
891                 ospecMap.put(new OccupiedSpectrumKey(ospec.getLowerFrequency(), ospec.getUpperFrequency()), ospec);
892             }
893             spectrumPac.setOccupiedSpectrum(ospecMap);
894         }
895         if (availableFreqMap != null && !availableFreqMap.isEmpty()) {
896             freqMap = availableFreqMap;
897         }
898         if (freqMap != null) {
899             Map<AvailableSpectrumKey, AvailableSpectrum> aspecMap = new HashMap<>();
900             AvailableSpectrumBuilder aspecBd = new AvailableSpectrumBuilder();
901             for (Map.Entry<Double, Double> frequency : availableFreqMap.entrySet()) {
902                 aspecBd
903                     .setLowerFrequency(Uint64.valueOf(Math.round(frequency.getKey().doubleValue() * 1E09)))
904                     .setUpperFrequency(Uint64.valueOf(Math.round(frequency.getValue().doubleValue() * 1E09)));
905                 AvailableSpectrum aspec = aspecBd.build();
906                 aspecMap.put(new AvailableSpectrumKey(aspec.getLowerFrequency(), aspec.getUpperFrequency()), aspec);
907             }
908             spectrumPac.setAvailableSpectrum(aspecMap);
909         }
910         SupportableSpectrum  sspec = new SupportableSpectrumBuilder()
911             .setLowerFrequency(Uint64.valueOf(Math.round(lowSupFreq)))
912             .setUpperFrequency(Uint64.valueOf(Math.round(upSupFreq)))
913             .build();
914         spectrumPac.setSupportableSpectrum(
915             new HashMap<SupportableSpectrumKey, SupportableSpectrum>(Map.of(
916                 new SupportableSpectrumKey(sspec.getLowerFrequency(), sspec.getUpperFrequency()), sspec)));
917         var onep1 = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121
918                 .OwnedNodeEdgePoint1Builder()
919             .setPhotonicMediaNodeEdgePointSpec(
920                 new PhotonicMediaNodeEdgePointSpecBuilder().setSpectrumCapabilityPac(spectrumPac.build()).build())
921             .build();
922         onepBldr.addAugmentation(onep1);
923         LOG.debug("Add Photonic Node Edge point Spec to {} including available Spectrum {} = ",
924             onepBldr.getName(),
925             onep1.getPhotonicMediaNodeEdgePointSpec().getSpectrumCapabilityPac().getAvailableSpectrum());
926         return onepBldr;
927     }
928
929     private OduSwitchingPools createOduSwitchingPoolForTp100G() {
930         Map<NonBlockingListKey, NonBlockingList> nblMap = new HashMap<>();
931         int count = 1;
932         for (TerminationPoint tp : this.oorNetworkPortList) {
933             NonBlockingList nbl = new NonBlockingListBuilder()
934                 .setNblNumber(Uint16.valueOf(count))
935                 .setTpList(new HashSet<>(Set.of(
936                     tp.getTpId(),
937                     tp.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526
938                             .TerminationPoint1.class)
939                         .getAssociatedConnectionMapTp().iterator().next())))
940                 .build();
941             nblMap.put(nbl.key(), nbl);
942             count++;
943         }
944         return new OduSwitchingPoolsBuilder()
945             .setNonBlockingList(nblMap)
946             .setSwitchingPoolNumber(Uint16.valueOf(1))
947             .build();
948     }
949
950     private org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node createTapiNode(
951             Map<NameKey, Name> nodeNames, Set<LayerProtocolName> layerProtocols) {
952         Uuid nodeUuid = null;
953         Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepl = new HashMap<>();
954         Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupList = new HashMap<>();
955         if (layerProtocols.contains(LayerProtocolName.DSR)
956                 || layerProtocols.contains(LayerProtocolName.PHOTONICMEDIA)) {
957             Rule rule = new RuleBuilder()
958                 .setLocalId("forward")
959                 .setForwardingRule(FORWARDINGRULEMAYFORWARDACROSSGROUP.VALUE)
960                 .setRuleType(new HashSet<>(Set.of(RuleType.FORWARDING)))
961                 .build();
962             nodeUuid = getNodeUuid4Dsr(onepl, nodeRuleGroupList, new HashMap<>(Map.of(rule.key(), rule)));
963         } else {
964             var nodeName = nodeNames.get(nodeNames.keySet().iterator().next());
965             LOG.error("Undefined LayerProtocolName for {} node {}", nodeName.getValueName(), nodeName.getValue());
966         }
967      // Empty random creation of mandatory fields for avoiding errors....
968         CostCharacteristic costCharacteristic = new CostCharacteristicBuilder()
969             .setCostAlgorithm("Restricted Shortest Path - RSP")
970             .setCostName("HOP_COUNT")
971             .setCostValue(TapiStringConstants.COST_HOP_VALUE)
972             .build();
973         LatencyCharacteristic latencyCharacteristic = new LatencyCharacteristicBuilder()
974             .setFixedLatencyCharacteristic(TapiStringConstants.FIXED_LATENCY_VALUE)
975             .setQueuingLatencyCharacteristic(TapiStringConstants.QUEING_LATENCY_VALUE)
976             .setJitterCharacteristic(TapiStringConstants.JITTER_VALUE)
977             .setWanderCharacteristic(TapiStringConstants.WANDER_VALUE)
978             .setTrafficPropertyName("FIXED_LATENCY")
979             .build();
980         RiskCharacteristic riskCharacteristic = new RiskCharacteristicBuilder()
981             .setRiskCharacteristicName("risk characteristic")
982             .setRiskIdentifierList(Set.of("risk identifier1", "risk identifier2"))
983             .build();
984         return new NodeBuilder()
985             .setUuid(nodeUuid)
986             .setName(nodeNames)
987             .setLayerProtocolName(layerProtocols)
988             .setAdministrativeState(transformAsToTapiAdminState(this.ietfNodeAdminState.getName()))
989             .setOperationalState(transformOsToTapiOperationalState(this.ietfNodeOperState.getName()))
990             .setLifecycleState(LifecycleState.INSTALLED)
991             .setOwnedNodeEdgePoint(onepl)
992             .setNodeRuleGroup(nodeRuleGroupList)
993             .setCostCharacteristic(Map.of(costCharacteristic.key(), costCharacteristic))
994             .setLatencyCharacteristic(Map.of(latencyCharacteristic.key(), latencyCharacteristic))
995             .setRiskParameterPac(
996                 new RiskParameterPacBuilder()
997                     .setRiskCharacteristic(Map.of(riskCharacteristic.key(), riskCharacteristic))
998                     .build())
999             .setErrorCharacteristic("error")
1000             .setLossCharacteristic("loss")
1001             .setRepeatDeliveryCharacteristic("repeat delivery")
1002             .setDeliveryOrderCharacteristic("delivery order")
1003             .setUnavailableTimeCharacteristic("unavailable time")
1004             .setServerIntegrityProcessCharacteristic("server integrity process")
1005             .build();
1006     }
1007
1008     private Uuid getNodeUuid4Dsr(
1009             Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepl,
1010             Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupList,
1011             Map<RuleKey, Rule> ruleList) {
1012         // client NEP DSR creation on DSR/ODU node
1013         for (int i = 0; i < oorClientPortList.size(); i++) {
1014             String nodeIdDsr = String.join("+",
1015                 this.ietfNodeId, TapiStringConstants.DSR, oorClientPortList.get(i).getTpId().getValue());
1016             Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes(nodeIdDsr.getBytes(Charset.forName("UTF-8"))).toString());
1017             LOG.info("NEP = {} has Uuid {} ", nodeIdDsr, nepUuid);
1018             this.uuidMap.put(nodeIdDsr, nepUuid);
1019             Name name = new NameBuilder()
1020                 .setValue(nodeIdDsr)
1021                 .setValueName(OpenroadmNodeType.TPDR.equals(this.ietfNodeType) ? "100G-tpdr" : "NodeEdgePoint_C")
1022                 .build();
1023             OwnedNodeEdgePoint onep = createNep(
1024                 oorClientPortList.get(i),
1025                 Map.of(name.key(), name),
1026                 LayerProtocolName.DSR, LayerProtocolName.DSR, true,
1027                 String.join("+", this.ietfNodeId, TapiStringConstants.DSR));
1028             onepl.put(onep.key(), onep);
1029         }
1030         // CLIENT NEP E_ODU creation on DSR/ODU node
1031         for (int i = 0; i < oorClientPortList.size(); i++) {
1032             String nodeIdEodu = String.join("+",
1033                 this.ietfNodeId, TapiStringConstants.E_ODU, oorClientPortList.get(i).getTpId().getValue());
1034             Uuid nepUuid1 = new Uuid(UUID.nameUUIDFromBytes(nodeIdEodu.getBytes(Charset.forName("UTF-8"))).toString());
1035             LOG.info("NEP = {} has Uuid {} ", nodeIdEodu, nepUuid1);
1036             this.uuidMap.put(nodeIdEodu, nepUuid1);
1037             Name onedName = new NameBuilder()
1038                 .setValueName("eNodeEdgePoint_N")
1039                 .setValue(nodeIdEodu)
1040                 .build();
1041             OwnedNodeEdgePoint onep = createNep(
1042                 oorClientPortList.get(i),
1043                 Map.of(onedName.key(), onedName),
1044                 LayerProtocolName.ODU, LayerProtocolName.DSR, false,
1045                 String.join("+", this.ietfNodeId, TapiStringConstants.E_ODU));
1046             onepl.put(onep.key(), onep);
1047         }
1048         // NETWORK NEPs I_ODU creation on DSR/ODU node
1049         for (int i = 0; i < oorNetworkPortList.size(); i++) {
1050             String nodeIdIodu = String.join("+",
1051                 this.ietfNodeId, TapiStringConstants.I_ODU, oorNetworkPortList.get(i).getTpId().getValue());
1052             Uuid nepUuid1 = new Uuid(UUID.nameUUIDFromBytes(nodeIdIodu.getBytes(Charset.forName("UTF-8"))).toString());
1053             LOG.info("NEP = {} has Uuid {} ", nodeIdIodu, nepUuid1);
1054             this.uuidMap.put(nodeIdIodu, nepUuid1);
1055             Name onedName = new NameBuilder()
1056                 .setValueName("iNodeEdgePoint_N")
1057                 .setValue(nodeIdIodu)
1058                 .build();
1059             OwnedNodeEdgePoint onep = createNep(
1060                 oorNetworkPortList.get(i),
1061                 Map.of(onedName.key(), onedName),
1062                 LayerProtocolName.ODU, LayerProtocolName.DSR, true,
1063                 String.join("+", this.ietfNodeId, TapiStringConstants.I_ODU));
1064             onepl.put(onep.key(), onep);
1065         }
1066         // NETWORK NEP OTS network on DSR/ODU node
1067         for (int i = 0; i < oorNetworkPortList.size(); i++) {
1068             String nodeIdPmOts = String.join("+",
1069                 this.ietfNodeId, TapiStringConstants.PHTNC_MEDIA_OTS, oorNetworkPortList.get(i).getTpId().getValue());
1070             Uuid nepUuid2 = new Uuid(UUID.nameUUIDFromBytes(nodeIdPmOts.getBytes(Charset.forName("UTF-8"))).toString());
1071             LOG.info("NEP = {} has Uuid {} ", nodeIdPmOts, nepUuid2);
1072             this.uuidMap.put(nodeIdPmOts, nepUuid2);
1073             Name onedName = new NameBuilder()
1074                 .setValueName("eNodeEdgePoint")
1075                 .setValue(nodeIdPmOts)
1076                 .build();
1077             OwnedNodeEdgePoint onep = createNep(
1078                 oorNetworkPortList.get(i),
1079                 Map.of(onedName.key(), onedName),
1080                 LayerProtocolName.PHOTONICMEDIA, LayerProtocolName.PHOTONICMEDIA, true,
1081                 String.join("+", this.ietfNodeId, TapiStringConstants.PHTNC_MEDIA_OTS));
1082             onepl.put(onep.key(), onep);
1083         }
1084         for (int i = 0; i < oorNetworkPortList.size(); i++) {
1085             String nodeIdOtMc = String.join("+",
1086                 this.ietfNodeId, TapiStringConstants.OTSI_MC, oorNetworkPortList.get(i).getTpId().getValue());
1087             Uuid nepUuid3 = new Uuid(UUID.nameUUIDFromBytes(nodeIdOtMc.getBytes(Charset.forName("UTF-8"))).toString());
1088             LOG.info("NEP = {} has Uuid {} ", nodeIdOtMc, nepUuid3);
1089             this.uuidMap.put(nodeIdOtMc, nepUuid3);
1090             Name onedName = new NameBuilder()
1091                 .setValueName("PhotMedNodeEdgePoint")
1092                 .setValue(nodeIdOtMc)
1093                 .build();
1094             OwnedNodeEdgePoint onep = createNep(
1095                 oorNetworkPortList.get(i),
1096                 Map.of(onedName.key(), onedName),
1097                 LayerProtocolName.PHOTONICMEDIA, LayerProtocolName.PHOTONICMEDIA, true,
1098                 String.join("+", this.ietfNodeId, TapiStringConstants.OTSI_MC));
1099             onepl.put(onep.key(), onep);
1100         }
1101         // create NodeRuleGroup
1102         int count = 1;
1103         LOG.debug("ODU switching pool = {}", this.oorOduSwitchingPool.nonnullNonBlockingList().values());
1104         String ietfXpdr = String.join("+", this.ietfNodeId, TapiStringConstants.XPDR);
1105         for (NonBlockingList nbl : this.oorOduSwitchingPool.nonnullNonBlockingList().values()) {
1106             Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.NodeEdgePointKey,
1107                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.NodeEdgePoint>
1108                     nepList = new HashMap<>();
1109             Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.NodeEdgePointKey,
1110                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.NodeEdgePoint>
1111                     oduNepList = new HashMap<>();
1112             LOG.debug("UUidMap={}", this.uuidMap.keySet());
1113             LOG.debug("TP list = {}", nbl.getTpList());
1114             for (TpId tp : nbl.getTpList()) {
1115                 String tpValue = tp.getValue();
1116                 LOG.debug("TP={}", tpValue);
1117                 String ietfEoduTp = String.join("+", this.ietfNodeId, TapiStringConstants.E_ODU, tpValue);
1118                 LOG.debug("UuidKey={}", ietfEoduTp);
1119                 String ietfIoduTp = String.join("+", this.ietfNodeId, TapiStringConstants.I_ODU, tpValue);
1120                 if (this.uuidMap.containsKey(String.join("+", this.ietfNodeId, TapiStringConstants.DSR, tpValue))
1121                         || this.uuidMap.containsKey(ietfIoduTp)) {
1122                     var nep = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121
1123                                 .node.rule.group.NodeEdgePointBuilder()
1124                             .setTopologyUuid(tapiTopoUuid)
1125                             .setNodeUuid(this.uuidMap.get(ietfXpdr))
1126                             .setNodeEdgePointUuid(this.uuidMap.get(
1127                                 String.join("+",
1128                                     this.ietfNodeId,
1129                                     tpValue.contains("CLIENT") ? TapiStringConstants.DSR : TapiStringConstants.I_ODU,
1130                                     tpValue)))
1131                             .build();
1132                     nepList.put(nep.key(), nep);
1133                 }
1134                 if (this.uuidMap.containsKey(ietfEoduTp)) {
1135                     var nep1 = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121
1136                                 .node.rule.group.NodeEdgePointBuilder()
1137                             .setTopologyUuid(tapiTopoUuid)
1138                             .setNodeUuid(this.uuidMap.get(ietfXpdr))
1139                             .setNodeEdgePointUuid(this.uuidMap.get(ietfEoduTp))
1140                             .build();
1141                     oduNepList.put(nep1.key(), nep1);
1142                 }
1143                 if (this.uuidMap.containsKey(ietfIoduTp)) {
1144                 // TODO already checked with DSR above -> potential factorization ?
1145                     var nep2 = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121
1146                                 .node.rule.group.NodeEdgePointBuilder()
1147                             .setTopologyUuid(tapiTopoUuid)
1148                             .setNodeUuid(this.uuidMap.get(ietfXpdr))
1149                             .setNodeEdgePointUuid(this.uuidMap.get(ietfIoduTp))
1150                             .build();
1151                     oduNepList.put(nep2.key(), nep2);
1152                 }
1153             }
1154             LOG.debug("NEPLIST (DSR/I_ODU) of [dsr node rule group] is {}", nepList);
1155             LOG.debug("NEPLIST (E_ODU/I_ODU) of [odu node rule group] is {}", nepList);
1156             // Empty random creation of mandatory fields for avoiding errors....
1157             CostCharacteristic costCharacteristic = new CostCharacteristicBuilder()
1158                 .setCostAlgorithm("Restricted Shortest Path - RSP")
1159                 .setCostName("HOP_COUNT")
1160                 .setCostValue(TapiStringConstants.COST_HOP_VALUE)
1161                 .build();
1162             LatencyCharacteristic latencyCharacteristic = new LatencyCharacteristicBuilder()
1163                 .setFixedLatencyCharacteristic(TapiStringConstants.FIXED_LATENCY_VALUE)
1164                 .setQueuingLatencyCharacteristic(TapiStringConstants.QUEING_LATENCY_VALUE)
1165                 .setJitterCharacteristic(TapiStringConstants.JITTER_VALUE)
1166                 .setWanderCharacteristic(TapiStringConstants.WANDER_VALUE)
1167                 .setTrafficPropertyName("FIXED_LATENCY")
1168                 .build();
1169             RiskCharacteristic riskCharacteristic = new RiskCharacteristicBuilder()
1170                 .setRiskCharacteristicName("risk characteristic")
1171                 .setRiskIdentifierList(Set.of("risk identifier1", "risk identifier2"))
1172                 .build();
1173             Name nrgName = new NameBuilder()
1174                 .setValueName("nrg name")
1175                 .setValue("odu node rule group " + count)
1176                 .build();
1177             NodeRuleGroup nodeRuleGroup1 = new NodeRuleGroupBuilder()
1178                 .setName(Map.of(nrgName.key(), nrgName))
1179                 .setUuid(new Uuid(UUID.nameUUIDFromBytes(("dsr node rule group " + count)
1180                     .getBytes(Charset.forName("UTF-8"))).toString()))
1181                 .setRule(ruleList)
1182                 .setNodeEdgePoint(nepList)
1183                 .setRiskCharacteristic(Map.of(riskCharacteristic.key(), riskCharacteristic))
1184                 .setCostCharacteristic(Map.of(costCharacteristic.key(), costCharacteristic))
1185                 .setLatencyCharacteristic(Map.of(latencyCharacteristic.key(), latencyCharacteristic))
1186                 .build();
1187             nodeRuleGroupList.put(nodeRuleGroup1.key(), nodeRuleGroup1);
1188             NodeRuleGroup nodeRuleGroup2 = new NodeRuleGroupBuilder()
1189                 .setUuid(new Uuid(UUID.nameUUIDFromBytes(("odu node rule group " + count)
1190                     .getBytes(Charset.forName("UTF-8"))).toString()))
1191                 .setRule(ruleList)
1192                 .setNodeEdgePoint(oduNepList)
1193                 .setRiskCharacteristic(Map.of(riskCharacteristic.key(), riskCharacteristic))
1194                 .setCostCharacteristic(Map.of(costCharacteristic.key(), costCharacteristic))
1195                 .setLatencyCharacteristic(Map.of(latencyCharacteristic.key(), latencyCharacteristic))
1196                 .build();
1197             nodeRuleGroupList.put(nodeRuleGroup2.key(), nodeRuleGroup2);
1198             count++;
1199         }
1200         return this.uuidMap.get(ietfXpdr);
1201     }
1202
1203     private OwnedNodeEdgePoint createNep(TerminationPoint oorTp, Map<NameKey, Name> nepNames,
1204             LayerProtocolName nepProtocol, LayerProtocolName nodeProtocol, boolean withSip, String keyword) {
1205         var tp1 = oorTp.augmentation(
1206             org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev230526.TerminationPoint1.class);
1207         var oorTpId = oorTp.getTpId();
1208         var oorTpIdValue = oorTpId.getValue();
1209         if (tp1.getTpSupportedInterfaces() == null) {
1210             LOG.warn("Tp supported interface doesnt exist on TP {}", oorTpIdValue);
1211             return null;
1212         }
1213         TerminationPoint1 oorTpAug = oorTp.augmentation(TerminationPoint1.class);
1214         var oorTpAugAdmState = oorTpAug.getAdministrativeState();
1215         AdministrativeState adminState =
1216             oorTpAugAdmState == null ? null : transformAsToTapiAdminState(oorTpAugAdmState.getName());
1217         var oorTpAugOprState = oorTpAug.getOperationalState();
1218         OperationalState operState =
1219             oorTpAugOprState == null ? null : transformOsToTapiOperationalState(oorTpAugOprState.getName());
1220         Collection<SupportedInterfaceCapability> sicColl =
1221             tp1.getTpSupportedInterfaces().getSupportedInterfaceCapability().values();
1222         OwnedNodeEdgePointBuilder onepBldr = new OwnedNodeEdgePointBuilder()
1223             .setUuid(this.uuidMap.get(String.join("+", keyword, oorTpIdValue)))
1224             .setLayerProtocolName(nepProtocol)
1225             .setName(nepNames)
1226             .setSupportedCepLayerProtocolQualifierInstances(
1227                 createSupportedCepLayerProtocolQualifier(sicColl, nepProtocol))
1228             .setDirection(Direction.BIDIRECTIONAL)
1229             .setLinkPortRole(PortRole.SYMMETRIC)
1230             .setAdministrativeState(adminState)
1231             .setOperationalState(operState)
1232             .setLifecycleState(LifecycleState.INSTALLED);
1233         if (withSip) {
1234             onepBldr.setMappedServiceInterfacePoint(
1235                 createMSIP(1, nepProtocol, oorTpIdValue, keyword, sicColl, operState, adminState));
1236         }
1237         if (oorTpAug.getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
1238             List<OperationalModeKey> opModeList = new ArrayList<>();
1239             var tp11 = oorTp.augmentation(
1240                 org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev230526.TerminationPoint1.class);
1241             if (tp11 == null || tp11.getXpdrNetworkAttributes() == null) {
1242                 for (SupportedInterfaceCapability sic : sicColl) {
1243                     String ifCapType = sic.getIfCapType().toString().split("\\{")[0];
1244                     switch (ifCapType) {
1245                         case "IfOCHOTUCnODUCn":
1246                         case "IfOCHOTUCnODUCnUniregen":
1247                         case "IfOCHOTUCnODUCnRegen":
1248                             opModeList.add(new OperationalModeKey("400G"));
1249                             LOG.warn(TopologyUtils.NOOPMODEDECLARED + "400G rate available", oorTpId);
1250                             break;
1251                         default:
1252                             break;
1253                     }
1254                 }
1255                 opModeList.add(new OperationalModeKey("100G"));
1256                 LOG.warn(TopologyUtils.NOOPMODEDECLARED + "100G rate available", oorTpId);
1257             } else {
1258                 opModeList = tp11.getXpdrNetworkAttributes().getSupportedOperationalModes().getOperationalMode()
1259                     .keySet().stream().toList();
1260             }
1261             onepBldr = addPayloadStructureAndPhotSpecToOnep(
1262                 this.ietfNodeId, getXpdrUsedWavelength(oorTp), opModeList, sicColl, onepBldr, keyword);
1263         }
1264         OwnedNodeEdgePoint onep = onepBldr.build();
1265         LOG.debug("ConvertORToTapiTopology 1360, onep = {}", onep);
1266         return onep;
1267     }
1268
1269     private ServiceInterfacePoint createSIP(Uuid sipUuid, LayerProtocolName layerProtocol, String tpId,
1270         String nodeid, Collection<SupportedInterfaceCapability> supportedInterfaceCapability,
1271         OperationalState operState, AdministrativeState adminState) {
1272     // TODO: what value should be set in total capacity and available capacity??
1273         LOG.debug("SIP name = {}", String.join("+", nodeid, tpId));
1274         Name sipName = new NameBuilder()
1275             .setValueName("SIP name")
1276             .setValue(String.join("+", nodeid, tpId))
1277             .build();
1278         return new ServiceInterfacePointBuilder()
1279             .setUuid(sipUuid)
1280             .setName(Map.of(sipName.key(), sipName))
1281             .setLayerProtocolName(layerProtocol)
1282             .setAdministrativeState(adminState)
1283             .setOperationalState(operState)
1284             .setLifecycleState(LifecycleState.INSTALLED)
1285             .setAvailableCapacity(new AvailableCapacityBuilder().build())
1286             .setTotalPotentialCapacity(new TotalPotentialCapacityBuilder().build())
1287             .setSupportedCepLayerProtocolQualifierInstances(createSipSupportedLayerProtocolQualifier(
1288                 supportedInterfaceCapability, layerProtocol))
1289             .build();
1290     }
1291
1292     private List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1293                 .service._interface.point.SupportedCepLayerProtocolQualifierInstances>
1294              createSipSupportedLayerProtocolQualifier(
1295                 Collection<SupportedInterfaceCapability> supportedInterfaceCapability, LayerProtocolName lpn) {
1296         if (supportedInterfaceCapability == null) {
1297             return new ArrayList<>(List.of(new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1298                     .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1299                 .setLayerProtocolQualifier(PHOTONICLAYERQUALIFIEROTS.VALUE)
1300                 .setNumberOfCepInstances(Uint64.valueOf(1))
1301                 .build()));
1302         }
1303         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1304             .service._interface.point.SupportedCepLayerProtocolQualifierInstances> sclpqiList = new ArrayList<>();
1305         String lpnName = lpn.getName();
1306         for (SupportedInterfaceCapability sic : supportedInterfaceCapability) {
1307             String ifCapType = sic.getIfCapType().toString().split("\\{")[0];
1308             if (!LPN_MAP.containsKey(lpnName)) {
1309                 LOG.error("Layer Protocol Name is unknown {}", lpnName);
1310                 break;
1311             }
1312             var ifCapTypeMap = LPN_MAP.get(lpnName);
1313             if (!ifCapTypeMap.containsKey(ifCapType)) {
1314                 LOG.error("IfCapability type {} not managed", ifCapType);
1315                 break;
1316             }
1317             for (Map.Entry<LAYERPROTOCOLQUALIFIER, Uint64> entry: ifCapTypeMap.get(ifCapType).entrySet()) {
1318                 sclpqiList.add(
1319                     new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121
1320                             .service._interface.point.SupportedCepLayerProtocolQualifierInstancesBuilder()
1321                         .setLayerProtocolQualifier(entry.getKey())
1322                         .setNumberOfCepInstances(entry.getValue())
1323                         .build());
1324             }
1325         }
1326         return sclpqiList.stream().distinct().toList();
1327     }
1328
1329     public Map<NodeKey, org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node>
1330             getTapiNodes() {
1331         return tapiNodes;
1332     }
1333
1334     public Map<LinkKey, Link> getTapiLinks() {
1335         return tapiLinks;
1336     }
1337
1338     public AdministrativeState transformAsToTapiAdminState(String adminState) {
1339         return adminState == null ? null
1340             : adminState.equals(AdminStates.InService.getName())
1341                     || adminState.equals(AdministrativeState.UNLOCKED.getName())
1342                 ? AdministrativeState.UNLOCKED : AdministrativeState.LOCKED;
1343     }
1344
1345     public OperationalState transformOsToTapiOperationalState(String operState) {
1346         return operState == null ? null
1347             : operState.equals("inService") || operState.equals(OperationalState.ENABLED.getName())
1348                 ? OperationalState.ENABLED : OperationalState.DISABLED;
1349     }
1350
1351     public Map<ServiceInterfacePointKey, ServiceInterfacePoint> getTapiSips() {
1352         return tapiSips;
1353     }
1354
1355     public void setTapiSips(Map<ServiceInterfacePointKey, ServiceInterfacePoint> tapiSip) {
1356         this.tapiSips.putAll(tapiSip);
1357     }
1358
1359 }