Manage OTN links at 400G
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / topology / ConvertORTopoToTapiTopo.java
1 /*
2  * Copyright © 2019 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.nio.charset.Charset;
11 import java.util.ArrayList;
12 import java.util.Arrays;
13 import java.util.Collection;
14 import java.util.Collections;
15 import java.util.HashMap;
16 import java.util.HashSet;
17 import java.util.Iterator;
18 import java.util.List;
19 import java.util.Map;
20 import java.util.Map.Entry;
21 import java.util.Set;
22 import java.util.UUID;
23 import java.util.stream.Collectors;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev200327.xpdr.odu.switching.pools.OduSwitchingPools;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev200327.xpdr.odu.switching.pools.OduSwitchingPoolsBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev200327.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingList;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev200327.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingListBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev200327.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingListKey;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmTpType;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.xpdr.tp.supported.interfaces.SupportedInterfaceCapability;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.Link1;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.Node1;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.TpId;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPoint;
40 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.AdministrativeState;
41 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.CapacityUnit;
42 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.ForwardingDirection;
43 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LAYERPROTOCOLQUALIFIER;
44 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LayerProtocolName;
45 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LifecycleState;
46 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.OperationalState;
47 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.PortDirection;
48 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.PortRole;
49 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.TerminationDirection;
50 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.TerminationState;
51 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
52 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.capacity.TotalSizeBuilder;
53 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.capacity.pac.AvailableCapacityBuilder;
54 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.capacity.pac.TotalPotentialCapacityBuilder;
55 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.Name;
56 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameBuilder;
57 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameKey;
58 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev181210.DIGITALSIGNALTYPE100GigE;
59 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev181210.DIGITALSIGNALTYPE10GigELAN;
60 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.odu.rev181210.ODUTYPEODU2;
61 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.odu.rev181210.ODUTYPEODU2E;
62 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.odu.rev181210.ODUTYPEODU4;
63 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev181210.PHOTONICLAYERQUALIFIEROMS;
64 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev181210.PHOTONICLAYERQUALIFIEROTSi;
65 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.ForwardingRule;
66 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.RuleType;
67 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.link.NodeEdgePoint;
68 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.link.NodeEdgePointBuilder;
69 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.link.NodeEdgePointKey;
70 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.NodeRuleGroup;
71 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.NodeRuleGroupBuilder;
72 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.NodeRuleGroupKey;
73 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePoint;
74 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePointBuilder;
75 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePointKey;
76 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.edge.point.MappedServiceInterfacePoint;
77 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.edge.point.MappedServiceInterfacePointBuilder;
78 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.edge.point.MappedServiceInterfacePointKey;
79 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.Rule;
80 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.RuleBuilder;
81 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.RuleKey;
82 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link;
83 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.LinkBuilder;
84 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.LinkKey;
85 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.NodeBuilder;
86 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.NodeKey;
87 import org.opendaylight.yangtools.yang.common.Uint16;
88 import org.opendaylight.yangtools.yang.common.Uint64;
89 import org.slf4j.Logger;
90 import org.slf4j.LoggerFactory;
91
92
93 public class ConvertORTopoToTapiTopo {
94
95     private static final String DSR = "DSR";
96     private static final String OTSI = "OTSi";
97     private static final String E_OTSI = "eOTSi";
98     private static final String I_OTSI = "iOTSi";
99     private static final String RDM_INFRA = "ROADM-infra";
100     private static final Logger LOG = LoggerFactory.getLogger(ConvertORTopoToTapiTopo.class);
101     private String ietfNodeId;
102     private OpenroadmNodeType ietfNodeType;
103     private AdminStates ietfNodeAdminState;
104     private State ietfNodeOperState;
105     private List<TerminationPoint> oorClientPortList;
106     private List<TerminationPoint> oorNetworkPortList;
107     private OduSwitchingPools oorOduSwitchingPool;
108     private Uuid tapiTopoUuid;
109     private Map<NodeKey, org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node>
110         tapiNodes;
111     private Map<LinkKey, Link> tapiLinks;
112     private Map<String, Uuid> uuidMap;
113
114
115     public ConvertORTopoToTapiTopo(Uuid tapiTopoUuid) {
116         this.tapiTopoUuid = tapiTopoUuid;
117         this.tapiNodes = new HashMap<>();
118         this.tapiLinks = new HashMap<>();
119         this.uuidMap = new HashMap<>();
120     }
121
122     public void convertNode(Node ietfNode, List<String> networkPorts) {
123         this.ietfNodeId = ietfNode.getNodeId().getValue();
124         if (ietfNode.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1.class)
125                 == null) {
126             return;
127         }
128         this.ietfNodeType = ietfNode.augmentation(
129             org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1.class).getNodeType();
130         this.ietfNodeAdminState = ietfNode.augmentation(
131             org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1.class)
132             .getAdministrativeState();
133         this.ietfNodeOperState = ietfNode.augmentation(
134             org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Node1.class)
135             .getOperationalState();
136         this.oorNetworkPortList = ietfNode.augmentation(
137             org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
138             .getTerminationPoint().values().stream()
139             .filter(tp -> tp.augmentation(TerminationPoint1.class).getTpType().getIntValue()
140                 == OpenroadmTpType.XPONDERNETWORK.getIntValue()
141                 && networkPorts.contains(tp.getTpId().getValue()))
142             .sorted((tp1, tp2) -> tp1.getTpId().getValue().compareTo(tp2.getTpId().getValue()))
143             .collect(Collectors.toList());
144         if (!OpenroadmNodeType.TPDR.equals(this.ietfNodeType)) {
145             this.oorOduSwitchingPool = ietfNode.augmentation(Node1.class).getSwitchingPools().getOduSwitchingPools()
146                 .values().stream().findFirst().get();
147             this.oorClientPortList = ietfNode.augmentation(
148                 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
149                 .getTerminationPoint().values().stream()
150                 .filter(tp -> tp.augmentation(TerminationPoint1.class).getTpType().getIntValue()
151                     == OpenroadmTpType.XPONDERCLIENT.getIntValue())
152                 .sorted((tp1, tp2) -> tp1.getTpId().getValue().compareTo(tp2.getTpId().getValue()))
153                 .collect(Collectors.toList());
154         } else {
155             this.oorOduSwitchingPool = createOduSwitchingPoolForTp100G();
156             List<TpId> tpList = this.oorOduSwitchingPool.getNonBlockingList().values().stream()
157                 .flatMap(nbl -> nbl.getTpList().stream())
158                 .collect(Collectors.toList());
159             this.oorClientPortList = ietfNode.augmentation(
160                 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
161                 .getTerminationPoint().values().stream()
162                 .filter(tp -> tp.augmentation(TerminationPoint1.class).getTpType().getIntValue()
163                     == OpenroadmTpType.XPONDERCLIENT.getIntValue() && tpList.contains(tp.getTpId()))
164                 .sorted((tp1, tp2) -> tp1.getTpId().getValue().compareTo(tp2.getTpId().getValue()))
165                 .collect(Collectors.toList());
166             this.oorClientPortList.forEach(tp -> LOG.info("tp = {}", tp.getTpId()));
167         }
168
169         // node creation [DSR/ODU]
170         LOG.info("creation of a DSR/ODU node for {}", this.ietfNodeId);
171         Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", this.ietfNodeId, DSR))
172             .getBytes(Charset.forName("UTF-8"))).toString());
173         this.uuidMap.put(String.join("+", this.ietfNodeId, DSR), nodeUuid);
174         Name nameDsr = new NameBuilder().setValueName("dsr/odu node name").setValue(this.ietfNodeId).build();
175         List<LayerProtocolName> dsrLayerProtocols = Arrays.asList(LayerProtocolName.DSR, LayerProtocolName.ODU);
176         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology
177             .Node dsrNode = createTapiNode(Map.of(nameDsr.key(), nameDsr), dsrLayerProtocols);
178         tapiNodes.put(dsrNode.key(), dsrNode);
179
180         // node creation [otsi]
181         LOG.info("creation of an OTSi node for {}", this.ietfNodeId);
182         nodeUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", this.ietfNodeId, OTSI))
183             .getBytes(Charset.forName("UTF-8"))).toString());
184         this.uuidMap.put(String.join("+", this.ietfNodeId, OTSI), nodeUuid);
185         Name nameOtsi =  new NameBuilder().setValueName("otsi node name").setValue(this.ietfNodeId).build();
186         List<LayerProtocolName> otsiLayerProtocols = Arrays.asList(LayerProtocolName.PHOTONICMEDIA);
187         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology
188             .Node otsiNode = createTapiNode(Map.of(nameOtsi.key(), nameOtsi), otsiLayerProtocols);
189         tapiNodes.put(otsiNode.key(), otsiNode);
190
191         // transitional link cration between network nep of DSR/ODU node and iNep of otsi node
192         LOG.info("creation of transitional links between DSR/ODU and OTSi nodes");
193         createTapiTransitionalLinks();
194     }
195
196     public void convertLinks(Map<
197             org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
198                 .LinkKey,
199             org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
200                 .Link> otnLinkMap) {
201         List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
202             .Link> otnLinkList = new ArrayList<>(otnLinkMap.values());
203         Collections.sort(otnLinkList, (l1, l2) -> l1.getLinkId().getValue()
204             .compareTo(l2.getLinkId().getValue()));
205         List<String> linksToNotConvert = new ArrayList<>();
206         LOG.info("creation of {} otn links", otnLinkMap.size() / 2);
207         for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
208                 .Link otnlink : otnLinkList) {
209             if (!linksToNotConvert.contains(otnlink.getLinkId().getValue())) {
210                 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks
211                     .network.Link oppositeLink = otnLinkMap.get(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns
212                         .yang.ietf.network.topology.rev180226.networks.network.LinkKey(otnlink.augmentation(
213                             org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1.class)
214                     .getOppositeLink()));
215                 Link tapiLink = createTapiLink(otnlink, oppositeLink);
216                 linksToNotConvert.add(oppositeLink.getLinkId().getValue());
217                 tapiLinks.put(tapiLink.key(), tapiLink);
218             }
219         }
220     }
221
222     public void convertRoadmInfrastructure() {
223         LOG.info("abstraction of the ROADM infrastructure towards a photonic node");
224         Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes(RDM_INFRA.getBytes(Charset.forName("UTF-8"))).toString());
225         Name nodeName =  new NameBuilder().setValueName("otsi node name").setValue(RDM_INFRA).build();
226         List<LayerProtocolName> nodeLayerProtocols = Arrays.asList(LayerProtocolName.PHOTONICMEDIA);
227
228         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node> tapiPhotonicNodes
229             = pruneTapiPhotonicNodes();
230         Map<String, String> photonicNepUuisMap = convertListNodeWithListNepToMapForUuidAndName(tapiPhotonicNodes);
231         // nep creation for rdm infra abstraction node
232         Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepMap = createNepForRdmNode(photonicNepUuisMap.size());
233         // node rule group creation
234         Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupList
235             = createNodeRuleGroupForRdmNode(nodeUuid, onepMap.values());
236         // build RDM infra node abstraction
237         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node rdmNode = new NodeBuilder()
238             .setUuid(nodeUuid)
239             .setName(Map.of(nodeName.key(), nodeName))
240             .setLayerProtocolName(nodeLayerProtocols)
241             .setAdministrativeState(AdministrativeState.UNLOCKED)
242             .setOperationalState(OperationalState.ENABLED)
243             .setLifecycleState(LifecycleState.INSTALLED)
244             .setOwnedNodeEdgePoint(onepMap)
245             .setNodeRuleGroup(nodeRuleGroupList)
246             .build();
247         tapiNodes.put(rdmNode.key(), rdmNode);
248
249         // OMS link creation between photonoci nodes and RDM infra abstraction node
250         Map<String, String> rdmInfraNepUuisMap = convertListNodeWithListNepToMapForUuidAndName(List.of(rdmNode));
251         if (photonicNepUuisMap.size() != rdmInfraNepUuisMap.size()) {
252             LOG.warn("Unable to build OMS links between photonics nodes and RDM infrasctructure abstraction");
253         } else {
254             createTapiOmsLinks(photonicNepUuisMap, rdmInfraNepUuisMap);
255         }
256     }
257
258     private OduSwitchingPools createOduSwitchingPoolForTp100G() {
259         Map<NonBlockingListKey, NonBlockingList> nblMap = new HashMap<>();
260         int count = 1;
261         for (TerminationPoint tp : this.oorNetworkPortList) {
262             TpId tpid1 = tp.getTpId();
263             TpId tpid2 = new TpId(tp.augmentation(
264                     org.opendaylight.yang.gen.v1.http.transportpce.topology.rev210511.TerminationPoint1.class)
265                 .getAssociatedConnectionMapPort());
266             List<TpId> tpList = new ArrayList<>();
267             tpList.add(tpid1);
268             tpList.add(tpid2);
269             NonBlockingList nbl = new NonBlockingListBuilder()
270                 .setNblNumber(Uint16.valueOf(count))
271                 .setTpList(tpList)
272                 .build();
273             nblMap.put(nbl.key(), nbl);
274             count++;
275         }
276         return new OduSwitchingPoolsBuilder()
277             .setNonBlockingList(nblMap)
278             .setSwitchingPoolNumber(Uint16.valueOf(1))
279             .build();
280     }
281
282     private List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node>
283             pruneTapiPhotonicNodes() {
284         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node>
285             prunedTapiPhotonicNodes = new ArrayList<>();
286         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node> tapiPhotonicNodes
287             = this.tapiNodes.values().stream()
288                 .filter(n -> LayerProtocolName.PHOTONICMEDIA.equals(n.getLayerProtocolName().get(0)))
289                 .collect(Collectors.toList());
290         for (org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node node
291                 : tapiPhotonicNodes) {
292             Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepM = new HashMap<>();
293             for (Map.Entry<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> entry : node.getOwnedNodeEdgePoint().entrySet()) {
294                 if (entry.getValue().getName().values().stream()
295                         .filter(name -> name.getValueName().startsWith("eNodeEdgePoint")).count() > 0) {
296                     onepM.put(entry.getKey(), entry.getValue());
297                 }
298             }
299             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node prunedNode
300                 = new NodeBuilder(node).setOwnedNodeEdgePoint(onepM).build();
301             prunedTapiPhotonicNodes.add(prunedNode);
302         }
303         return prunedTapiPhotonicNodes;
304     }
305
306     private Map<String, String> convertListNodeWithListNepToMapForUuidAndName(
307             List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node> nodes) {
308         Map<String, String> uuidNameMap = new HashMap<>();
309         for (org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node node : nodes) {
310             for (OwnedNodeEdgePoint nep : node.nonnullOwnedNodeEdgePoint().values()) {
311                 String nodeUuid = node.getUuid().getValue();
312                 String nepUuid = nep.getUuid().getValue();
313                 String nodeName = node.getName().get(new NameKey("otsi node name")).getValue();
314                 String nepName = nep.getName().get(new NameKey(nep.getName().keySet().stream().findFirst().get()))
315                     .getValue();
316                 uuidNameMap.put(String.join("--", nodeUuid, nepUuid), String.join("--", nodeName, nepName));
317             }
318         }
319         return uuidNameMap;
320     }
321
322     private org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node
323             createTapiNode(Map<NameKey, Name> nodeNames, List<LayerProtocolName> layerProtocols) {
324         Uuid nodeUuid = null;
325         Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepl = new HashMap<>();
326         Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupList = new HashMap<>();
327         Map<RuleKey, Rule> ruleList = new HashMap<>();
328         Rule rule = new RuleBuilder()
329             .setLocalId("forward")
330             .setForwardingRule(ForwardingRule.MAYFORWARDACROSSGROUP)
331             .setRuleType(RuleType.FORWARDING)
332             .build();
333         ruleList.put(rule.key(), rule);
334         if (layerProtocols.contains(LayerProtocolName.DSR)) {
335             nodeUuid = getNodeUuid4Dsr(onepl, nodeRuleGroupList, ruleList);
336         } else if (layerProtocols.contains(LayerProtocolName.PHOTONICMEDIA)) {
337             nodeUuid = getNodeUuid4Photonic(onepl, nodeRuleGroupList, ruleList);
338         } else {
339             LOG.error("Undefined LayerProtocolName for {} node {}", nodeNames.get(nodeNames.keySet().iterator().next())
340                 .getValueName(), nodeNames.get(nodeNames.keySet().iterator().next()).getValue());
341         }
342         return new NodeBuilder()
343             .setUuid(nodeUuid)
344             .setName(nodeNames)
345             .setLayerProtocolName(layerProtocols)
346             .setAdministrativeState(setTapiAdminState(this.ietfNodeAdminState))
347             .setOperationalState(setTapiOperationalState(this.ietfNodeOperState))
348             .setLifecycleState(LifecycleState.INSTALLED)
349             .setOwnedNodeEdgePoint(onepl)
350             .setNodeRuleGroup(nodeRuleGroupList)
351             .build();
352     }
353
354     private AdministrativeState setTapiAdminState(AdminStates adminState) {
355         if (adminState == null) {
356             return null;
357         }
358         return adminState.equals(AdminStates.InService) ? AdministrativeState.UNLOCKED : AdministrativeState.LOCKED;
359     }
360
361     private AdministrativeState setTapiAdminState(AdminStates adminState1, AdminStates adminState2) {
362         if (adminState1 == null || adminState2 == null) {
363             return null;
364         }
365         if (AdminStates.InService.equals(adminState1) && AdminStates.InService.equals(adminState2)) {
366             return AdministrativeState.UNLOCKED;
367         } else {
368             return AdministrativeState.LOCKED;
369         }
370     }
371
372     private OperationalState setTapiOperationalState(State operState) {
373         if (operState == null) {
374             return null;
375         }
376         return operState.getName().equals("inService") ? OperationalState.ENABLED : OperationalState.DISABLED;
377     }
378
379     private OperationalState setTapiOperationalState(State operState1, State operState2) {
380         if (operState1 == null || operState2 == null) {
381             return null;
382         }
383         if (State.InService.equals(operState1) && State.InService.equals(operState2)) {
384             return OperationalState.ENABLED;
385         } else {
386             return OperationalState.DISABLED;
387         }
388     }
389
390     private Uuid getNodeUuid4Photonic(Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepl,
391             Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupList, Map<RuleKey, Rule> ruleList) {
392         Uuid nodeUuid;
393         nodeUuid = this.uuidMap.get(String.join("+", this.ietfNodeId, OTSI));
394         // iNep creation on otsi node
395         for (int i = 0; i < oorNetworkPortList.size(); i++) {
396             Uuid nepUuid1 = new Uuid(UUID.nameUUIDFromBytes(
397                 (String.join("+", this.ietfNodeId, I_OTSI, oorNetworkPortList.get(i).getTpId().getValue()))
398                     .getBytes(Charset.forName("UTF-8")))
399                 .toString());
400             this.uuidMap.put(String.join("+", this.ietfNodeId, I_OTSI, oorNetworkPortList.get(i).getTpId().getValue()),
401                 nepUuid1);
402             Name onedName = new NameBuilder()
403                 .setValueName("iNodeEdgePoint")
404                 .setValue(oorNetworkPortList.get(i).getTpId().getValue())
405                 .build();
406
407             OwnedNodeEdgePoint onep = createNep(oorNetworkPortList.get(i), Map.of(onedName.key(), onedName),
408                 LayerProtocolName.PHOTONICMEDIA, LayerProtocolName.PHOTONICMEDIA, true,
409                 String.join("+", this.ietfNodeId, I_OTSI));
410             onepl.put(onep.key(), onep);
411         }
412         // eNep creation on otsi node
413         for (int i = 0; i < oorNetworkPortList.size(); i++) {
414             Uuid nepUuid2 = new Uuid(UUID.nameUUIDFromBytes(
415                 (String.join("+", this.ietfNodeId, E_OTSI, oorNetworkPortList.get(i).getTpId().getValue()))
416                     .getBytes(Charset.forName("UTF-8")))
417                 .toString());
418             this.uuidMap.put(String.join("+", this.ietfNodeId, E_OTSI, oorNetworkPortList.get(i).getTpId().getValue()),
419                 nepUuid2);
420             Name onedName = new NameBuilder()
421                 .setValueName("eNodeEdgePoint")
422                 .setValue(oorNetworkPortList.get(i).getTpId().getValue())
423                 .build();
424
425             OwnedNodeEdgePoint onep = createNep(oorNetworkPortList.get(i), Map.of(onedName.key(), onedName),
426                 LayerProtocolName.PHOTONICMEDIA, LayerProtocolName.PHOTONICMEDIA, true,
427                 String.join("+", this.ietfNodeId, E_OTSI));
428             onepl.put(onep.key(), onep);
429         }
430         // create NodeRuleGroup
431         int count = 1;
432         for (TerminationPoint tp : this.oorNetworkPortList) {
433             Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePointKey,
434                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePoint>
435                 nepList = new HashMap<>();
436             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group
437                 .NodeEdgePoint inep = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
438                 .node.rule.group.NodeEdgePointBuilder()
439                 .setTopologyUuid(tapiTopoUuid)
440                 .setNodeUuid(this.uuidMap.get(String.join("+", this.ietfNodeId, OTSI)))
441                 .setNodeEdgePointUuid(
442                     this.uuidMap.get(String.join("+", this.ietfNodeId, I_OTSI, tp.getTpId().getValue())))
443                 .build();
444             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group
445                 .NodeEdgePoint enep = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
446                 .node.rule.group.NodeEdgePointBuilder()
447                 .setTopologyUuid(tapiTopoUuid)
448                 .setNodeUuid(this.uuidMap.get(String.join("+", this.ietfNodeId, OTSI)))
449                 .setNodeEdgePointUuid(
450                     this.uuidMap.get(String.join("+", this.ietfNodeId, E_OTSI, tp.getTpId().getValue())))
451                 .build();
452             nepList.put(inep.key(), inep);
453             nepList.put(enep.key(), enep);
454             NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
455                 .setUuid(new Uuid(
456                     UUID.nameUUIDFromBytes(("otsi node rule group " + count).getBytes(Charset.forName("UTF-8")))
457                         .toString()))
458                 .setRule(ruleList)
459                 .setNodeEdgePoint(nepList)
460                 .build();
461             nodeRuleGroupList.put(nodeRuleGroup.key(), nodeRuleGroup);
462             count++;
463         }
464         return nodeUuid;
465     }
466
467     private Uuid getNodeUuid4Dsr(Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepl,
468             Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupList, Map<RuleKey, Rule> ruleList) {
469         Uuid nodeUuid;
470         nodeUuid = this.uuidMap.get(String.join("+", this.ietfNodeId, DSR));
471         // client nep creation on DSR/ODU node
472         for (int i = 0; i < oorClientPortList.size(); i++) {
473             Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes(
474                 (String.join("+", this.ietfNodeId, DSR, oorClientPortList.get(i).getTpId().getValue()))
475                     .getBytes(Charset.forName("UTF-8"))).toString());
476             this.uuidMap.put(String.join("+", this.ietfNodeId, DSR, oorClientPortList.get(i).getTpId().getValue()),
477                 nepUuid);
478             NameBuilder nameBldr = new NameBuilder().setValue(oorClientPortList.get(i).getTpId().getValue());
479             Name name;
480             if (OpenroadmNodeType.TPDR.equals(this.ietfNodeType)) {
481                 name = nameBldr.setValueName("100G-tpdr").build();
482             } else {
483                 name = nameBldr.setValueName("NodeEdgePoint_C").build();
484             }
485
486             OwnedNodeEdgePoint onep = createNep(oorClientPortList.get(i), Map.of(name.key(), name),
487                 LayerProtocolName.ETH, LayerProtocolName.DSR, true, String.join("+", this.ietfNodeId, DSR));
488             onepl.put(onep.key(), onep);
489         }
490         // network nep creation on DSR/ODU node
491         for (int i = 0; i < oorNetworkPortList.size(); i++) {
492             Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes(
493                 (String.join("+", this.ietfNodeId, DSR, oorNetworkPortList.get(i).getTpId().getValue()))
494                     .getBytes(Charset.forName("UTF-8"))).toString());
495             this.uuidMap.put(String.join("+", this.ietfNodeId, DSR, oorNetworkPortList.get(i).getTpId().getValue()),
496                 nepUuid);
497             Name onedName = new NameBuilder()
498                 .setValueName("NodeEdgePoint_N")
499                 .setValue(oorNetworkPortList.get(i).getTpId().getValue())
500                 .build();
501
502             OwnedNodeEdgePoint onep = createNep(oorNetworkPortList.get(i), Map.of(onedName.key(), onedName),
503                 LayerProtocolName.ODU, LayerProtocolName.DSR, true, String.join("+", this.ietfNodeId, DSR));
504             onepl.put(onep.key(), onep);
505         }
506         // create NodeRuleGroup
507         int count = 1;
508         for (NonBlockingList nbl : this.oorOduSwitchingPool.nonnullNonBlockingList().values()) {
509             Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePointKey,
510                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePoint>
511                 nepList = new HashMap<>();
512             for (TpId tp : nbl.getTpList()) {
513                 if (this.uuidMap.containsKey(String.join("+", this.ietfNodeId, DSR, tp.getValue()))) {
514                     org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePoint
515                         nep = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group
516                         .NodeEdgePointBuilder()
517                         .setTopologyUuid(tapiTopoUuid)
518                         .setNodeUuid(this.uuidMap.get(String.join("+", this.ietfNodeId, DSR)))
519                         .setNodeEdgePointUuid(this.uuidMap.get(String.join("+", this.ietfNodeId, DSR, tp.getValue())))
520                         .build();
521                     nepList.put(nep.key(), nep);
522                 }
523             }
524             NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
525                 .setUuid(new Uuid(
526                     UUID.nameUUIDFromBytes(("dsr node rule group " + count).getBytes(Charset.forName("UTF-8")))
527                         .toString()))
528                 .setRule(ruleList)
529                 .setNodeEdgePoint(nepList)
530                 .build();
531             nodeRuleGroupList.put(nodeRuleGroup.key(), nodeRuleGroup);
532             count++;
533         }
534         return nodeUuid;
535     }
536
537     private OwnedNodeEdgePoint createNep(TerminationPoint oorTp, Map<NameKey, Name> nepNames,
538             LayerProtocolName nepProtocol, LayerProtocolName nodeProtocol, boolean withSip, String keyword) {
539         String key = String.join("+", keyword, oorTp.getTpId().getValue());
540         OwnedNodeEdgePointBuilder onepBldr = new OwnedNodeEdgePointBuilder()
541             .setUuid(this.uuidMap.get(key))
542             .setLayerProtocolName(nepProtocol)
543             .setName(nepNames);
544         if (withSip) {
545             onepBldr.setMappedServiceInterfacePoint(createSIP(this.uuidMap.get(key), 1));
546         }
547         onepBldr.setSupportedCepLayerProtocolQualifier(createSupportedCepLayerProtocolQualifier(oorTp, nodeProtocol))
548             .setLinkPortDirection(PortDirection.BIDIRECTIONAL)
549             .setLinkPortRole(PortRole.SYMMETRIC)
550             .setAdministrativeState(setTapiAdminState(
551                 oorTp.augmentation(TerminationPoint1.class).getAdministrativeState()))
552             .setOperationalState(setTapiOperationalState(
553                 oorTp.augmentation(TerminationPoint1.class).getOperationalState()))
554             .setLifecycleState(LifecycleState.INSTALLED)
555             .setTerminationDirection(TerminationDirection.BIDIRECTIONAL)
556             .setTerminationState(TerminationState.TERMINATEDBIDIRECTIONAL);
557         return onepBldr.build();
558     }
559
560     private Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> createNepForRdmNode(int nbNep) {
561         Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepMap = new HashMap<>();
562         for (int i = 1; i <= nbNep; i++) {
563             Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", "roadm node", "nep", String.valueOf(i)))
564                 .getBytes(Charset.forName("UTF-8"))).toString());
565             Name nepName = new NameBuilder()
566                 .setValueName("NodeEdgePoint name")
567                 .setValue(new StringBuilder("NodeEdgePoint_").append(i).toString())
568                 .build();
569             OwnedNodeEdgePoint onep = new OwnedNodeEdgePointBuilder()
570                 .setUuid(nepUuid)
571                 .setLayerProtocolName(LayerProtocolName.PHOTONICMEDIA)
572                 .setName(Map.of(nepName.key(), nepName))
573                 .setSupportedCepLayerProtocolQualifier(List.of(PHOTONICLAYERQUALIFIEROMS.class))
574                 .setLinkPortDirection(PortDirection.BIDIRECTIONAL).setLinkPortRole(PortRole.SYMMETRIC)
575                 .setAdministrativeState(AdministrativeState.UNLOCKED).setOperationalState(OperationalState.ENABLED)
576                 .setLifecycleState(LifecycleState.INSTALLED).setTerminationDirection(TerminationDirection.BIDIRECTIONAL)
577                 .setTerminationState(TerminationState.TERMINATEDBIDIRECTIONAL)
578                 .build();
579             onepMap.put(onep.key(), onep);
580         }
581         return onepMap;
582     }
583
584     private Map<NodeRuleGroupKey, NodeRuleGroup> createNodeRuleGroupForRdmNode(Uuid nodeUuid,
585             Collection<OwnedNodeEdgePoint> onepl) {
586         Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePointKey,
587             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePoint>
588             nepMap = new HashMap<>();
589         for (OwnedNodeEdgePoint onep : onepl) {
590             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePoint
591                 nep = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group
592                     .NodeEdgePointBuilder()
593                 .setTopologyUuid(tapiTopoUuid)
594                 .setNodeUuid(nodeUuid)
595                 .setNodeEdgePointUuid(onep.key().getUuid())
596                 .build();
597             nepMap.put(nep.key(), nep);
598         }
599         Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupMap = new HashMap<>();
600         Map<RuleKey, Rule> ruleList = new HashMap<>();
601         Rule rule = new RuleBuilder()
602             .setLocalId("forward")
603             .setForwardingRule(ForwardingRule.MAYFORWARDACROSSGROUP)
604             .setRuleType(RuleType.FORWARDING)
605             .build();
606         ruleList.put(rule.key(), rule);
607         NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
608             .setUuid(new Uuid(UUID.nameUUIDFromBytes(("rdm infra node rule group").getBytes(Charset.forName("UTF-8")))
609                 .toString()))
610             .setRule(ruleList)
611             .setNodeEdgePoint(nepMap)
612             .build();
613         nodeRuleGroupMap.put(nodeRuleGroup.key(), nodeRuleGroup);
614         return nodeRuleGroupMap;
615     }
616
617     private Map<MappedServiceInterfacePointKey, MappedServiceInterfacePoint> createSIP(Uuid nepUuid, int nb) {
618         Map<MappedServiceInterfacePointKey, MappedServiceInterfacePoint> msipl = new HashMap<>();
619         for (int i = 0; i < nb; i++) {
620             MappedServiceInterfacePoint msip = new MappedServiceInterfacePointBuilder()
621                 .setServiceInterfacePointUuid(new Uuid(UUID.nameUUIDFromBytes(nepUuid.getValue()
622                     .getBytes(Charset.forName("UTF-8"))).toString()))
623                 .build();
624             msipl.put(msip.key(), msip);
625         }
626         return msipl;
627     }
628
629     private List<Class<? extends LAYERPROTOCOLQUALIFIER>> createSupportedCepLayerProtocolQualifier(TerminationPoint tp,
630             LayerProtocolName lpn) {
631         Set<Class<? extends LAYERPROTOCOLQUALIFIER>> sclpqSet = new HashSet<>();
632         List<SupportedInterfaceCapability> sicList = new ArrayList<>(
633             tp.augmentation(org.opendaylight.yang.gen.v1.http
634                 .org.openroadm.otn.network.topology.rev200529.TerminationPoint1.class).getTpSupportedInterfaces()
635                 .getSupportedInterfaceCapability().values());
636         for (SupportedInterfaceCapability sic : sicList) {
637             switch (lpn.getName()) {
638                 case "DSR":
639                     switch (sic.getIfCapType().getSimpleName()) {
640                         case "If10GEODU2e":
641                             sclpqSet.add(ODUTYPEODU2E.class);
642                             sclpqSet.add(DIGITALSIGNALTYPE10GigELAN.class);
643                             break;
644                         case "If10GEODU2":
645                             sclpqSet.add(ODUTYPEODU2.class);
646                             sclpqSet.add(DIGITALSIGNALTYPE10GigELAN.class);
647                             break;
648                         case "If10GE":
649                             sclpqSet.add(DIGITALSIGNALTYPE10GigELAN.class);
650                             break;
651                         case "If100GEODU4":
652                             sclpqSet.add(DIGITALSIGNALTYPE100GigE.class);
653                             sclpqSet.add(ODUTYPEODU4.class);
654                             break;
655                         case "If100GE":
656                             sclpqSet.add(DIGITALSIGNALTYPE100GigE.class);
657                             break;
658                         case "IfOCHOTU4ODU4":
659                         case "IfOCH":
660                             sclpqSet.add(ODUTYPEODU4.class);
661                             break;
662                         default:
663                             LOG.error("IfCapability type not managed");
664                             break;
665                     }
666                     break;
667                 case "PHOTONIC_MEDIA":
668                     if (sic.getIfCapType().getSimpleName().equals("IfOCHOTU4ODU4")
669                             || sic.getIfCapType().getSimpleName().equals("IfOCH")) {
670                         sclpqSet.add(PHOTONICLAYERQUALIFIEROTSi.class);
671                         sclpqSet.add(PHOTONICLAYERQUALIFIEROMS.class);
672                     }
673                     break;
674                 default:
675                     LOG.error("Layer Protocol Name is unknown");
676                     break;
677             }
678         }
679         return new ArrayList<>(sclpqSet);
680     }
681
682     private void createTapiTransitionalLinks() {
683         for (TerminationPoint tp : this.oorNetworkPortList) {
684             Map<NodeEdgePointKey, NodeEdgePoint> nepList = new HashMap<>();
685             String sourceKey = String.join("+", this.ietfNodeId, DSR, tp.getTpId().getValue());
686             Uuid sourceUuidTp = this.uuidMap.get(sourceKey);
687             String destKey = String.join("+", this.ietfNodeId, I_OTSI, tp.getTpId().getValue());
688             Uuid destUuidTp = this.uuidMap.get(destKey);
689             NodeEdgePoint sourceNep = new NodeEdgePointBuilder()
690                 .setTopologyUuid(this.tapiTopoUuid)
691                 .setNodeUuid(this.uuidMap.get(String.join("+", this.ietfNodeId, DSR)))
692                 .setNodeEdgePointUuid(sourceUuidTp)
693                 .build();
694             nepList.put(sourceNep.key(), sourceNep);
695             NodeEdgePoint destNep = new NodeEdgePointBuilder()
696                 .setTopologyUuid(this.tapiTopoUuid)
697                 .setNodeUuid(this.uuidMap.get(String.join("+", this.ietfNodeId, OTSI)))
698                 .setNodeEdgePointUuid(destUuidTp)
699                 .build();
700             nepList.put(destNep.key(), destNep);
701             Name linkName = new NameBuilder().setValueName("transitional link name")
702                 .setValue(String.join("--", this.ietfNodeId, sourceKey, destKey))
703                 .build();
704             Link transiLink = new LinkBuilder()
705                 .setUuid(new Uuid(
706                     UUID.nameUUIDFromBytes((String.join("--", this.ietfNodeId, sourceKey, destKey))
707                         .getBytes(Charset.forName("UTF-8")))
708                         .toString()))
709                 .setName(Map.of(linkName.key(), linkName))
710                 .setTransitionedLayerProtocolName(Arrays.asList(LayerProtocolName.ODU.getName(),
711                     LayerProtocolName.PHOTONICMEDIA.getName()))
712                 .setNodeEdgePoint(nepList)
713                 .setDirection(ForwardingDirection.BIDIRECTIONAL)
714                 .setAvailableCapacity(new AvailableCapacityBuilder().setTotalSize(
715                     new TotalSizeBuilder().setUnit(CapacityUnit.GBPS).setValue(Uint64.valueOf(100)).build()).build())
716                 .build();
717             this.tapiLinks.put(transiLink.key(), transiLink);
718         }
719     }
720
721     private Link createTapiLink(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
722                                     .ietf.network.topology.rev180226.networks.network.Link link,
723                                 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
724                                     .ietf.network.topology.rev180226.networks.network.Link oppositeLink) {
725         String prefix = link.getLinkId().getValue().split("-")[0];
726         String sourceNode = link.getSource().getSourceNode().getValue();
727         String sourceTp = link.getSource().getSourceTp().toString();
728         String destNode = link.getDestination().getDestNode().getValue();
729         String destTp = link.getDestination().getDestTp().toString();
730         Map<NodeEdgePointKey, NodeEdgePoint> nepList = new HashMap<>();
731         Uuid sourceUuidTp;
732         Uuid sourceUuidNode;
733         Uuid destUuidTp;
734         Uuid destUuidNode;
735         Name linkName;
736         AdminStates oppositeLinkAdminState = null;
737         State oppositeLinkOperState = null;
738         if (oppositeLink != null) {
739             oppositeLinkAdminState = oppositeLink.augmentation(
740                 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1.class)
741                 .getAdministrativeState();
742             oppositeLinkOperState = oppositeLink.augmentation(
743                 org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1.class)
744                 .getOperationalState();
745         }
746         switch (prefix) {
747             case "OTU4":
748                 sourceUuidTp = this.uuidMap.get(String.join("+", sourceNode, I_OTSI, sourceTp));
749                 sourceUuidNode = this.uuidMap.get(String.join("+", sourceNode, OTSI));
750                 NodeEdgePoint sourceNep = new NodeEdgePointBuilder()
751                     .setTopologyUuid(this.tapiTopoUuid)
752                     .setNodeUuid(sourceUuidNode)
753                     .setNodeEdgePointUuid(sourceUuidTp)
754                     .build();
755                 nepList.put(sourceNep.key(), sourceNep);
756                 destUuidTp = this.uuidMap.get(String.join("+", destNode, I_OTSI, destTp));
757                 destUuidNode = this.uuidMap.get(String.join("+", destNode, OTSI));
758                 NodeEdgePoint destNep = new NodeEdgePointBuilder()
759                     .setTopologyUuid(this.tapiTopoUuid)
760                     .setNodeUuid(destUuidNode)
761                     .setNodeEdgePointUuid(destUuidTp)
762                     .build();
763                 nepList.put(destNep.key(), destNep);
764                 linkName = new NameBuilder().setValueName("otn link name")
765                     .setValue(link.getLinkId().getValue())
766                     .build();
767                 return new LinkBuilder()
768                     .setUuid(new Uuid(
769                         UUID.nameUUIDFromBytes((link.getLinkId().getValue())
770                             .getBytes(Charset.forName("UTF-8")))
771                     .toString()))
772                 .setName(Map.of(linkName.key(), linkName))
773                 .setLayerProtocolName(Arrays.asList(LayerProtocolName.PHOTONICMEDIA))
774                 .setAdministrativeState(setTapiAdminState(link
775                     .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1.class)
776                     .getAdministrativeState(), oppositeLinkAdminState))
777                 .setOperationalState(setTapiOperationalState(link
778                     .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1.class)
779                     .getOperationalState(), oppositeLinkOperState))
780                 .setDirection(ForwardingDirection.BIDIRECTIONAL)
781                 .setNodeEdgePoint(nepList)
782                 .setTotalPotentialCapacity(new TotalPotentialCapacityBuilder().setTotalSize(
783                     new TotalSizeBuilder().setUnit(CapacityUnit.GBPS)
784                         .setValue(Uint64.valueOf(100)).build()).build())
785                 .setAvailableCapacity(new AvailableCapacityBuilder().setTotalSize(
786                     new TotalSizeBuilder().setUnit(CapacityUnit.MBPS)
787                         .setValue(Uint64.valueOf(link.augmentation(Link1.class).getAvailableBandwidth())).build())
788                     .build())
789                 .build();
790             case "ODTU4":
791                 sourceUuidTp = this.uuidMap.get(String.join("+", sourceNode, DSR, sourceTp));
792                 sourceUuidNode = this.uuidMap.get(String.join("+", sourceNode, DSR));
793                 NodeEdgePoint sourceNep2 = new NodeEdgePointBuilder()
794                     .setTopologyUuid(this.tapiTopoUuid)
795                     .setNodeUuid(sourceUuidNode)
796                     .setNodeEdgePointUuid(sourceUuidTp)
797                     .build();
798                 nepList.put(sourceNep2.key(), sourceNep2);
799                 destUuidTp = this.uuidMap.get(String.join("+", destNode, DSR, destTp));
800                 destUuidNode = this.uuidMap.get(String.join("+", destNode, DSR));
801                 NodeEdgePoint destNep2 = new NodeEdgePointBuilder()
802                     .setTopologyUuid(this.tapiTopoUuid)
803                     .setNodeUuid(destUuidNode)
804                     .setNodeEdgePointUuid(destUuidTp)
805                     .build();
806                 nepList.put(destNep2.key(), destNep2);
807                 linkName = new NameBuilder().setValueName("otn link name")
808                     .setValue(link.getLinkId().getValue())
809                     .build();
810                 return new LinkBuilder()
811                     .setUuid(new Uuid(UUID.nameUUIDFromBytes((link.getLinkId().getValue())
812                         .getBytes(Charset.forName("UTF-8")))
813                     .toString()))
814                 .setName(Map.of(linkName.key(), linkName))
815                 .setLayerProtocolName(Arrays.asList(LayerProtocolName.ODU))
816                 .setAdministrativeState(setTapiAdminState(link
817                     .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1.class)
818                     .getAdministrativeState(), oppositeLinkAdminState))
819                 .setOperationalState(setTapiOperationalState(link
820                     .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1.class)
821                     .getOperationalState(), oppositeLinkOperState))
822                 .setDirection(ForwardingDirection.BIDIRECTIONAL)
823                 .setNodeEdgePoint(nepList)
824                 .setTotalPotentialCapacity(new TotalPotentialCapacityBuilder().setTotalSize(
825                     new TotalSizeBuilder().setUnit(CapacityUnit.GBPS)
826                         .setValue(Uint64.valueOf(100)).build()).build())
827                 .setAvailableCapacity(new AvailableCapacityBuilder().setTotalSize(
828                     new TotalSizeBuilder().setUnit(CapacityUnit.MBPS)
829                         .setValue(Uint64.valueOf(link.augmentation(Link1.class).getAvailableBandwidth())).build())
830                     .build())
831                 .build();
832             default:
833                 LOG.error("OTN link of type {} not managed yet", prefix);
834                 return null;
835         }
836     }
837
838     private void createTapiOmsLinks(Map<String, String> photonicNepUuisMap, Map<String, String> rdmInfraNepUuisMap) {
839         Iterator<Entry<String, String>> it1 = photonicNepUuisMap.entrySet().iterator();
840         Iterator<Entry<String, String>> it2 = rdmInfraNepUuisMap.entrySet().iterator();
841         while (it1.hasNext()) {
842             Map<NodeEdgePointKey, NodeEdgePoint> nepMap = new HashMap<>();
843             Map.Entry<String, String> photonicEntry = it1.next();
844             Map.Entry<String, String> rdmEntry = it2.next();
845             Uuid sourceUuidTp = new Uuid(photonicEntry.getKey().split("--")[1]);
846             Uuid sourceUuidNode = new Uuid(photonicEntry.getKey().split("--")[0]);
847             Uuid destUuidTp = new Uuid(rdmEntry.getKey().split("--")[1]);
848             Uuid destUuidNode = new Uuid(rdmEntry.getKey().split("--")[0]);
849             NodeEdgePoint sourceNep = new NodeEdgePointBuilder()
850                 .setTopologyUuid(this.tapiTopoUuid)
851                 .setNodeUuid(sourceUuidNode)
852                 .setNodeEdgePointUuid(sourceUuidTp)
853                 .build();
854             nepMap.put(sourceNep.key(), sourceNep);
855             NodeEdgePoint destNep = new NodeEdgePointBuilder()
856                 .setTopologyUuid(this.tapiTopoUuid)
857                 .setNodeUuid(destUuidNode)
858                 .setNodeEdgePointUuid(destUuidTp)
859                 .build();
860             nepMap.put(destNep.key(), destNep);
861             Name linkName = new NameBuilder().setValueName("OMS link name")
862                 .setValue(String.join(" and ", photonicEntry.getValue(), rdmEntry.getValue()))
863                 .build();
864             Link omsLink = new LinkBuilder()
865                 .setUuid(new Uuid(
866                     UUID.nameUUIDFromBytes((String.join(" and ", photonicEntry.getValue(), rdmEntry.getValue()))
867                         .getBytes(Charset.forName("UTF-8")))
868                         .toString()))
869                 .setName(Map.of(linkName.key(), linkName))
870                 .setLayerProtocolName(List.of(LayerProtocolName.PHOTONICMEDIA))
871                 .setNodeEdgePoint(nepMap)
872                 .setDirection(ForwardingDirection.BIDIRECTIONAL)
873                 .build();
874             this.tapiLinks.put(omsLink.key(), omsLink);
875         }
876     }
877
878     public Map<NodeKey, org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node>
879             getTapiNodes() {
880         return tapiNodes;
881     }
882
883     public Map<LinkKey, Link> getTapiLinks() {
884         return tapiLinks;
885     }
886 }