Add OTN links support in TAPI topology
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / topology / ConvertORTopoObjectToTapiTopoObject.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.HashMap;
14 import java.util.List;
15 import java.util.Map;
16 import java.util.UUID;
17 import java.util.stream.Collectors;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.TerminationPoint1;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev181130.xpdr.odu.switching.pools.OduSwitchingPools;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev181130.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingList;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmTpType;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.xpdr.tp.supported.interfaces.SupportedInterfaceCapability;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.Link1;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev181130.Node1;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.TpId;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPoint;
28 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.AdministrativeState;
29 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.CapacityUnit;
30 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.ForwardingDirection;
31 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LAYERPROTOCOLQUALIFIER;
32 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LayerProtocolName;
33 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LifecycleState;
34 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.OperationalState;
35 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.PortDirection;
36 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.PortRole;
37 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.TerminationDirection;
38 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.TerminationState;
39 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
40 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.capacity.TotalSizeBuilder;
41 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.capacity.pac.AvailableCapacityBuilder;
42 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.capacity.pac.TotalPotentialCapacityBuilder;
43 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.Name;
44 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameBuilder;
45 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameKey;
46 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev181210.DIGITALSIGNALTYPE100GigE;
47 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev181210.DIGITALSIGNALTYPE10GigELAN;
48 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.odu.rev181210.ODUTYPEODU2E;
49 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.odu.rev181210.ODUTYPEODU4;
50 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev181210.PHOTONICLAYERQUALIFIEROMS;
51 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev181210.PHOTONICLAYERQUALIFIEROTSi;
52 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.ForwardingRule;
53 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.RuleType;
54 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.link.NodeEdgePoint;
55 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.link.NodeEdgePointBuilder;
56 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.link.NodeEdgePointKey;
57 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.NodeRuleGroup;
58 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.NodeRuleGroupBuilder;
59 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.NodeRuleGroupKey;
60 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePoint;
61 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePointBuilder;
62 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePointKey;
63 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.edge.point.MappedServiceInterfacePoint;
64 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.edge.point.MappedServiceInterfacePointBuilder;
65 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.edge.point.MappedServiceInterfacePointKey;
66 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.Rule;
67 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.RuleBuilder;
68 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.RuleKey;
69 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link;
70 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.LinkBuilder;
71 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.LinkKey;
72 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.NodeBuilder;
73 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.NodeKey;
74 import org.opendaylight.yangtools.yang.common.Uint64;
75 import org.slf4j.Logger;
76 import org.slf4j.LoggerFactory;
77
78
79 public class ConvertORTopoObjectToTapiTopoObject {
80
81     private static final String DSR = "DSR";
82     private static final String OTSI = "OTSi";
83     private static final String E_OTSI = "eOTSi";
84     private static final String I_OTSI = "iOTSi";
85     private static final Logger LOG = LoggerFactory.getLogger(ConvertORTopoObjectToTapiTopoObject.class);
86     private String ietfNodeId;
87     private List<TerminationPoint> oorClientPortList;
88     private List<TerminationPoint> oorNetworkPortList;
89     private OduSwitchingPools oorOduSwitchingPool;
90     private Uuid tapiTopoUuid;
91     private Map<NodeKey, org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node>
92         tapiNodes;
93     private Map<LinkKey, Link> tapiLinks;
94     private Map<String, Uuid> uuidMap;
95
96
97     public ConvertORTopoObjectToTapiTopoObject(Uuid tapiTopoUuid) {
98         this.tapiTopoUuid = tapiTopoUuid;
99         this.tapiNodes = new HashMap<>();
100         this.tapiLinks = new HashMap<>();
101         this.uuidMap = new HashMap<>();
102     }
103
104     public void convertNode(Node ietfNode) {
105         this.ietfNodeId = ietfNode.getNodeId().getValue();
106         this.oorClientPortList = ietfNode.augmentation(
107                 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
108             .getTerminationPoint().values().stream()
109             .filter(tp -> tp.augmentation(TerminationPoint1.class).getTpType().getIntValue()
110             == OpenroadmTpType.XPONDERCLIENT.getIntValue())
111             .sorted((tp1, tp2) -> tp1.getTpId().getValue().compareTo(tp2.getTpId().getValue()))
112             .collect(Collectors.toList());
113         this.oorNetworkPortList = ietfNode.augmentation(
114                 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
115             .getTerminationPoint().values().stream()
116             .filter(tp -> tp.augmentation(TerminationPoint1.class).getTpType().getIntValue()
117             == OpenroadmTpType.XPONDERNETWORK.getIntValue())
118             .sorted((tp1, tp2) -> tp1.getTpId().getValue().compareTo(tp2.getTpId().getValue()))
119             .collect(Collectors.toList());
120         this.oorOduSwitchingPool = ietfNode.augmentation(Node1.class).getSwitchingPools().getOduSwitchingPools()
121             .values().stream().findFirst().get();
122
123         // node creation [DSR/ODU]
124         LOG.info("creation of a DSR/ODU node");
125         Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", this.ietfNodeId, DSR))
126             .getBytes(Charset.forName("UTF-8"))).toString());
127         this.uuidMap.put(String.join("+", this.ietfNodeId, DSR), nodeUuid);
128         Name nameDsr = new NameBuilder().setValueName("dsr/odu node name").setValue(this.ietfNodeId).build();
129         List<LayerProtocolName> dsrLayerProtocols = Arrays.asList(LayerProtocolName.DSR, LayerProtocolName.ODU);
130         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology
131             .Node dsrNode = createTapiNode(Map.of(nameDsr.key(), nameDsr), dsrLayerProtocols);
132         tapiNodes.put(dsrNode.key(), dsrNode);
133
134         // node creation [otsi]
135         LOG.info("creation of an OTSi node");
136         nodeUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", this.ietfNodeId, OTSI))
137             .getBytes(Charset.forName("UTF-8"))).toString());
138         this.uuidMap.put(String.join("+", this.ietfNodeId, OTSI), nodeUuid);
139         Name nameOtsi =  new NameBuilder().setValueName("otsi node name").setValue(this.ietfNodeId).build();
140         List<LayerProtocolName> otsiLayerProtocols = Arrays.asList(LayerProtocolName.PHOTONICMEDIA);
141         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology
142             .Node otsiNode = createTapiNode(Map.of(nameOtsi.key(), nameOtsi), otsiLayerProtocols);
143         tapiNodes.put(otsiNode.key(), otsiNode);
144
145         // transitional link cration between network nep of DSR/ODU node and iNep of otsi node
146         LOG.info("creation of transitional links between DSR/ODU and OTSi nodes");
147         createTapiTransitionalLinks();
148     }
149
150     public void convertLinks(List
151         <org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link>
152         otnLinkList) {
153         List<String> linksToNotConvert = new ArrayList<>();
154         LOG.info("creation of {} otn links", otnLinkList.size() / 2);
155         for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
156             .Link link : otnLinkList) {
157             if (!linksToNotConvert.contains(link.getLinkId().getValue())) {
158                 Link tapiLink = createTapiLink(link);
159                 linksToNotConvert.add(link
160                     .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1.class)
161                     .getOppositeLink().getValue());
162                 tapiLinks.put(tapiLink.key(), tapiLink);
163             }
164         }
165     }
166
167     private org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology
168         .Node createTapiNode(Map<NameKey, Name> nodeNames, List<LayerProtocolName> layerProtocols) {
169         Uuid nodeUuid = null;
170         Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepl = new HashMap<>();
171         Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupList = new HashMap<>();
172         Map<RuleKey, Rule> ruleList = new HashMap<>();
173         Rule rule = new RuleBuilder()
174             .setLocalId("forward")
175             .setForwardingRule(ForwardingRule.MAYFORWARDACROSSGROUP)
176             .setRuleType(RuleType.FORWARDING)
177             .build();
178         ruleList.put(rule.key(), rule);
179         if (layerProtocols.contains(LayerProtocolName.DSR)) {
180             nodeUuid = getNodeUuid4Dsr(onepl, nodeRuleGroupList, ruleList);
181         } else if (layerProtocols.contains(LayerProtocolName.PHOTONICMEDIA)) {
182             nodeUuid = getNodeUuid4Phonic(onepl, nodeRuleGroupList, ruleList);
183         } else {
184             LOG.error("Undefined LayerProtocolName for {} node {}", nodeNames.get(nodeNames.keySet().iterator().next())
185                 .getValueName(), nodeNames.get(nodeNames.keySet().iterator().next()).getValue());
186         }
187
188         // create tapi node
189
190         return new NodeBuilder()
191                 .setUuid(nodeUuid)
192                 .setName(nodeNames)
193                 .setLayerProtocolName(layerProtocols)
194                 .setAdministrativeState(AdministrativeState.UNLOCKED)
195                 .setOperationalState(OperationalState.ENABLED)
196                 .setLifecycleState(LifecycleState.INSTALLED)
197                 .setOwnedNodeEdgePoint(onepl)
198                 .setNodeRuleGroup(nodeRuleGroupList)
199                 .build();
200     }
201
202     private Uuid getNodeUuid4Phonic(Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepl,
203         Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupList, Map<RuleKey, Rule> ruleList) {
204         Uuid nodeUuid;
205         nodeUuid = this.uuidMap.get(String.join("+", this.ietfNodeId, OTSI));
206         // iNep creation on otsi node
207         for (int i = 0; i < oorNetworkPortList.size(); i++) {
208             Uuid nepUuid1 = new Uuid(UUID.nameUUIDFromBytes(
209                     (String.join("+", this.ietfNodeId, I_OTSI, oorNetworkPortList.get(i).getTpId().getValue()))
210                     .getBytes(Charset.forName("UTF-8")))
211                 .toString());
212             this.uuidMap.put(String.join("+", this.ietfNodeId, I_OTSI, oorNetworkPortList.get(i).getTpId().getValue()),
213                 nepUuid1);
214             Name onedName = new NameBuilder()
215                 .setValueName(new StringBuilder("iNodeEdgePoint_").append(i + 1).toString())
216                 .setValue(oorNetworkPortList.get(i).getTpId().getValue())
217                 .build();
218
219             OwnedNodeEdgePoint onep = createNep(oorNetworkPortList.get(i), Map.of(onedName.key(), onedName),
220                 LayerProtocolName.PHOTONICMEDIA, LayerProtocolName.PHOTONICMEDIA, true,
221                 String.join("+", this.ietfNodeId, I_OTSI));
222             onepl.put(onep.key(), onep);
223         }
224         // eNep creation on otsi node
225         for (int i = 0; i < oorNetworkPortList.size(); i++) {
226             Uuid nepUuid2 = new Uuid(UUID.nameUUIDFromBytes(
227                     (String.join("+", this.ietfNodeId, E_OTSI, oorNetworkPortList.get(i).getTpId().getValue()))
228                     .getBytes(Charset.forName("UTF-8")))
229                 .toString());
230             this.uuidMap.put(String.join("+", this.ietfNodeId, E_OTSI, oorNetworkPortList.get(i).getTpId().getValue()),
231                 nepUuid2);
232             Name onedName = new NameBuilder()
233                 .setValueName(new StringBuilder("eNodeEdgePoint_").append(i + 1).toString())
234                 .setValue(oorNetworkPortList.get(i).getTpId().getValue())
235                 .build();
236
237             OwnedNodeEdgePoint onep = createNep(oorNetworkPortList.get(i), Map.of(onedName.key(), onedName),
238                 LayerProtocolName.PHOTONICMEDIA, LayerProtocolName.PHOTONICMEDIA, true,
239                 String.join("+", this.ietfNodeId, E_OTSI));
240             onepl.put(onep.key(), onep);
241         }
242         // create NodeRuleGroup
243         int count = 1;
244         for (TerminationPoint tp : this.oorNetworkPortList) {
245             Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePointKey,
246                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePoint>
247                 nepList = new HashMap<>();
248             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group
249                 .NodeEdgePoint inep = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
250                 .node.rule.group.NodeEdgePointBuilder()
251                 .setTopologyUuid(tapiTopoUuid)
252                 .setNodeUuid(this.uuidMap.get(String.join("+", this.ietfNodeId, OTSI)))
253                 .setNodeEdgePointUuid(
254                     this.uuidMap.get(String.join("+", this.ietfNodeId, I_OTSI, tp.getTpId().getValue())))
255                 .build();
256             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group
257                 .NodeEdgePoint enep = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
258                 .node.rule.group.NodeEdgePointBuilder()
259                 .setTopologyUuid(tapiTopoUuid)
260                 .setNodeUuid(this.uuidMap.get(String.join("+", this.ietfNodeId, OTSI)))
261                 .setNodeEdgePointUuid(
262                     this.uuidMap.get(String.join("+", this.ietfNodeId, E_OTSI, tp.getTpId().getValue())))
263                 .build();
264             nepList.put(inep.key(), inep);
265             nepList.put(enep.key(), enep);
266             NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
267                 .setUuid(new Uuid(
268                         UUID.nameUUIDFromBytes(("otsi node rule group " + count).getBytes(Charset.forName("UTF-8")))
269                     .toString()))
270                 .setRule(ruleList)
271                 .setNodeEdgePoint(nepList)
272                 .build();
273             nodeRuleGroupList.put(nodeRuleGroup.key(), nodeRuleGroup);
274             count++;
275         }
276         return nodeUuid;
277     }
278
279     private Uuid getNodeUuid4Dsr(Map<OwnedNodeEdgePointKey, OwnedNodeEdgePoint> onepl,
280         Map<NodeRuleGroupKey, NodeRuleGroup> nodeRuleGroupList, Map<RuleKey, Rule> ruleList) {
281         Uuid nodeUuid;
282         nodeUuid = this.uuidMap.get(String.join("+", this.ietfNodeId, DSR));
283         // client nep creation on DSR/ODU node
284         for (int i = 0; i < oorClientPortList.size(); i++) {
285             Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes(
286                 (String.join("+", this.ietfNodeId, DSR, oorClientPortList.get(i).getTpId().getValue()))
287                 .getBytes(Charset.forName("UTF-8"))).toString());
288             this.uuidMap.put(String.join("+", this.ietfNodeId, DSR, oorClientPortList.get(i).getTpId().getValue()),
289                 nepUuid);
290             Name name = new NameBuilder()
291                 .setValueName(new StringBuilder("NodeEdgePoint_C").append(i + 1).toString())
292                 .setValue(oorClientPortList.get(i).getTpId().getValue())
293                 .build();
294
295             OwnedNodeEdgePoint onep = createNep(oorClientPortList.get(i), Map.of(name.key(), name),
296                 LayerProtocolName.ETH, LayerProtocolName.DSR, true, String.join("+", this.ietfNodeId, DSR));
297             onepl.put(onep.key(), onep);
298         }
299         // network nep creation on DSR/ODU node
300         for (int i = 0; i < oorNetworkPortList.size(); i++) {
301             Uuid nepUuid = new Uuid(UUID.nameUUIDFromBytes(
302                 (String.join("+", this.ietfNodeId, DSR, oorNetworkPortList.get(i).getTpId().getValue()))
303                 .getBytes(Charset.forName("UTF-8"))).toString());
304             this.uuidMap.put(String.join("+", this.ietfNodeId, DSR, oorNetworkPortList.get(i).getTpId().getValue()),
305                 nepUuid);
306             Name onedName = new NameBuilder()
307                 .setValueName(new StringBuilder("NodeEdgePoint_N").append(i + 1).toString())
308                 .setValue(oorNetworkPortList.get(i).getTpId().getValue())
309                 .build();
310
311             OwnedNodeEdgePoint onep = createNep(oorNetworkPortList.get(i), Map.of(onedName.key(), onedName),
312                 LayerProtocolName.ODU, LayerProtocolName.DSR, true, String.join("+", this.ietfNodeId, DSR));
313             onepl.put(onep.key(), onep);
314         }
315         // create NodeRuleGroup
316         int count = 1;
317         for (NonBlockingList nbl : this.oorOduSwitchingPool.getNonBlockingList().values()) {
318             Map<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePointKey,
319                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePoint>
320                 nepList = new HashMap<>();
321             for (TpId tp : nbl.getTpList()) {
322                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group
323                     .NodeEdgePoint nep = new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
324                     .node.rule.group.NodeEdgePointBuilder()
325                     .setTopologyUuid(tapiTopoUuid)
326                     .setNodeUuid(this.uuidMap.get(String.join("+", this.ietfNodeId, DSR)))
327                     .setNodeEdgePointUuid(this.uuidMap.get(String.join("+", this.ietfNodeId, DSR, tp.getValue())))
328                     .build();
329                 nepList.put(nep.key(), nep);
330             }
331             NodeRuleGroup nodeRuleGroup = new NodeRuleGroupBuilder()
332                 .setUuid(new Uuid(
333                         UUID.nameUUIDFromBytes(("dsr node rule group " + count).getBytes(Charset.forName("UTF-8")))
334                     .toString()))
335                 .setRule(ruleList)
336                 .setNodeEdgePoint(nepList)
337                 .build();
338             nodeRuleGroupList.put(nodeRuleGroup.key(), nodeRuleGroup);
339             count++;
340         }
341         return nodeUuid;
342     }
343
344     private OwnedNodeEdgePoint createNep(TerminationPoint oorTp, Map<NameKey, Name> nepNames,
345         LayerProtocolName nepProtocol, LayerProtocolName nodeProtocol, boolean withSip, String keyword) {
346         String key = String.join("+", keyword, oorTp.getTpId().getValue());
347         OwnedNodeEdgePointBuilder onepBldr = new OwnedNodeEdgePointBuilder()
348             .setUuid(this.uuidMap.get(key))
349             .setLayerProtocolName(nepProtocol)
350             .setName(nepNames);
351         if (withSip) {
352             onepBldr.setMappedServiceInterfacePoint(createSIP(1));
353         }
354         onepBldr.setSupportedCepLayerProtocolQualifier(createSupportedCepLayerProtocolQualifier(oorTp, nodeProtocol));
355         onepBldr.setLinkPortDirection(PortDirection.BIDIRECTIONAL).setLinkPortRole(PortRole.SYMMETRIC)
356                 .setAdministrativeState(AdministrativeState.UNLOCKED).setOperationalState(OperationalState.ENABLED)
357                 .setLifecycleState(LifecycleState.INSTALLED).setTerminationDirection(TerminationDirection.BIDIRECTIONAL)
358                 .setTerminationState(TerminationState.TERMINATEDBIDIRECTIONAL);
359         return onepBldr.build();
360     }
361
362     private Map<MappedServiceInterfacePointKey, MappedServiceInterfacePoint> createSIP(int nb) {
363         Map<MappedServiceInterfacePointKey, MappedServiceInterfacePoint> msipl = new HashMap<>();
364         for (int i = 0; i < nb; i++) {
365             MappedServiceInterfacePoint msip = new MappedServiceInterfacePointBuilder()
366                 .setServiceInterfacePointUuid(new Uuid(UUID.randomUUID().toString())).build();
367             msipl.put(msip.key(), msip);
368         }
369         return msipl;
370     }
371
372     private List<Class<? extends LAYERPROTOCOLQUALIFIER>> createSupportedCepLayerProtocolQualifier(TerminationPoint tp,
373         LayerProtocolName lpn) {
374         List<Class<? extends LAYERPROTOCOLQUALIFIER>> sclpqList = new ArrayList<>();
375         List<SupportedInterfaceCapability> sicList = new ArrayList<>(
376             tp.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm
377             .otn.network.topology.rev181130.TerminationPoint1.class).getTpSupportedInterfaces()
378             .getSupportedInterfaceCapability().values());
379         for (SupportedInterfaceCapability sic : sicList) {
380             switch (lpn.getName()) {
381                 case "DSR":
382                     if (sic.getIfCapType().getSimpleName().equals("If10GEODU2e")) {
383                         sclpqList.add(DIGITALSIGNALTYPE10GigELAN.class);
384                         sclpqList.add(ODUTYPEODU2E.class);
385                     } else if (sic.getIfCapType().getSimpleName().equals("IfOCHOTU4ODU4")) {
386                         sclpqList.add(ODUTYPEODU4.class);
387                     } else if (sic.getIfCapType().getSimpleName().equals("If100GEODU4")) {
388                         sclpqList.add(DIGITALSIGNALTYPE100GigE.class);
389                         sclpqList.add(ODUTYPEODU4.class);
390                     }
391                     break;
392                 case "PHOTONIC_MEDIA":
393                     if (sic.getIfCapType().getSimpleName().equals("IfOCHOTU4ODU4")) {
394                         sclpqList.add(PHOTONICLAYERQUALIFIEROTSi.class);
395                         sclpqList.add(PHOTONICLAYERQUALIFIEROMS.class);
396                     }
397                     break;
398                 default:
399                     LOG.error("Layer Protocol Name is unknown");
400                     break;
401             }
402         }
403         return sclpqList;
404     }
405
406     private void createTapiTransitionalLinks() {
407         for (TerminationPoint tp : this.oorNetworkPortList) {
408             Map<NodeEdgePointKey, NodeEdgePoint> nepList = new HashMap<>();
409             String sourceKey = String.join("+", this.ietfNodeId, DSR, tp.getTpId().getValue());
410             Uuid sourceUuidTp = this.uuidMap.get(sourceKey);
411             String destKey = String.join("+", this.ietfNodeId, I_OTSI, tp.getTpId().getValue());
412             Uuid destUuidTp = this.uuidMap.get(destKey);
413             NodeEdgePoint sourceNep = new NodeEdgePointBuilder()
414                 .setTopologyUuid(this.tapiTopoUuid)
415                 .setNodeUuid(this.uuidMap.get(String.join("+", this.ietfNodeId, DSR)))
416                 .setNodeEdgePointUuid(sourceUuidTp)
417                 .build();
418             nepList.put(sourceNep.key(), sourceNep);
419             NodeEdgePoint destNep = new NodeEdgePointBuilder()
420                 .setTopologyUuid(this.tapiTopoUuid)
421                 .setNodeUuid(this.uuidMap.get(String.join("+", this.ietfNodeId, OTSI)))
422                 .setNodeEdgePointUuid(destUuidTp)
423                 .build();
424             nepList.put(destNep.key(), destNep);
425             Name linkName = new NameBuilder().setValueName("transitional link name")
426                 .setValue(String.join("--", this.ietfNodeId, sourceKey, destKey))
427                 .build();
428             Link transiLink = new LinkBuilder()
429                 .setUuid(new Uuid(
430                         UUID.nameUUIDFromBytes((String.join("--", this.ietfNodeId, sourceKey, destKey))
431                             .getBytes(Charset.forName("UTF-8")))
432                     .toString()))
433                 .setName(Map.of(linkName.key(), linkName))
434                 .setTransitionedLayerProtocolName(Arrays.asList(LayerProtocolName.ODU.getName(),
435                     LayerProtocolName.PHOTONICMEDIA.getName()))
436                 .setNodeEdgePoint(nepList)
437                 .setDirection(ForwardingDirection.BIDIRECTIONAL)
438                 .setAvailableCapacity(new AvailableCapacityBuilder().setTotalSize(
439                     new TotalSizeBuilder().setUnit(CapacityUnit.GBPS).setValue(Uint64.valueOf(100)).build()).build())
440                 .build();
441             this.tapiLinks.put(transiLink.key(), transiLink);
442         }
443     }
444
445     private Link createTapiLink(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226
446         .networks.network.Link link) {
447         String prefix = link.getLinkId().getValue().split("-")[0];
448         String sourceNode = link.getSource().getSourceNode().getValue();
449         String sourceTp = link.getSource().getSourceTp().toString();
450         String destNode = link.getDestination().getDestNode().getValue();
451         String destTp = link.getDestination().getDestTp().toString();
452         Map<NodeEdgePointKey, NodeEdgePoint> nepList = new HashMap<>();
453         Uuid sourceUuidTp;
454         Uuid sourceUuidNode;
455         Uuid destUuidTp;
456         Uuid destUuidNode;
457         Name linkName;
458         switch (prefix) {
459             case "OTU4":
460                 sourceUuidTp = this.uuidMap.get(String.join("+", sourceNode, I_OTSI, sourceTp));
461                 sourceUuidNode = this.uuidMap.get(String.join("+", sourceNode, OTSI));
462                 NodeEdgePoint sourceNep = new NodeEdgePointBuilder()
463                     .setTopologyUuid(this.tapiTopoUuid)
464                     .setNodeUuid(sourceUuidNode)
465                     .setNodeEdgePointUuid(sourceUuidTp)
466                     .build();
467                 nepList.put(sourceNep.key(), sourceNep);
468                 destUuidTp = this.uuidMap.get(String.join("+", destNode, I_OTSI, destTp));
469                 destUuidNode = this.uuidMap.get(String.join("+", destNode, OTSI));
470                 NodeEdgePoint destNep = new NodeEdgePointBuilder()
471                     .setTopologyUuid(this.tapiTopoUuid)
472                     .setNodeUuid(destUuidNode)
473                     .setNodeEdgePointUuid(destUuidTp)
474                     .build();
475                 nepList.put(destNep.key(), destNep);
476                 linkName = new NameBuilder().setValueName("otn link name")
477                     .setValue(link.getLinkId().getValue())
478                     .build();
479                 return new LinkBuilder()
480                     .setUuid(new Uuid(
481                         UUID.nameUUIDFromBytes((link.getLinkId().getValue())
482                             .getBytes(Charset.forName("UTF-8")))
483                     .toString()))
484                 .setName(Map.of(linkName.key(), linkName))
485                 .setLayerProtocolName(Arrays.asList(LayerProtocolName.PHOTONICMEDIA))
486                 .setAdministrativeState(AdministrativeState.UNLOCKED)
487                 .setOperationalState(OperationalState.ENABLED)
488                 .setDirection(ForwardingDirection.BIDIRECTIONAL)
489                 .setNodeEdgePoint(nepList)
490                 .setTotalPotentialCapacity(new TotalPotentialCapacityBuilder().setTotalSize(
491                     new TotalSizeBuilder().setUnit(CapacityUnit.GBPS)
492                         .setValue(Uint64.valueOf(100)).build()).build())
493                 .setAvailableCapacity(new AvailableCapacityBuilder().setTotalSize(
494                     new TotalSizeBuilder().setUnit(CapacityUnit.MBPS)
495                         .setValue(Uint64.valueOf(link.augmentation(Link1.class).getAvailableBandwidth())).build())
496                     .build())
497                 .build();
498             case "ODU4":
499                 sourceUuidTp = this.uuidMap.get(String.join("+", sourceNode, DSR, sourceTp));
500                 sourceUuidNode = this.uuidMap.get(String.join("+", sourceNode, DSR));
501                 NodeEdgePoint sourceNep2 = new NodeEdgePointBuilder()
502                     .setTopologyUuid(this.tapiTopoUuid)
503                     .setNodeUuid(sourceUuidNode)
504                     .setNodeEdgePointUuid(sourceUuidTp)
505                     .build();
506                 nepList.put(sourceNep2.key(), sourceNep2);
507                 destUuidTp = this.uuidMap.get(String.join("+", destNode, DSR, destTp));
508                 destUuidNode = this.uuidMap.get(String.join("+", destNode, DSR));
509                 NodeEdgePoint destNep2 = new NodeEdgePointBuilder()
510                     .setTopologyUuid(this.tapiTopoUuid)
511                     .setNodeUuid(destUuidNode)
512                     .setNodeEdgePointUuid(destUuidTp)
513                     .build();
514                 nepList.put(destNep2.key(), destNep2);
515                 linkName = new NameBuilder().setValueName("otn link name")
516                     .setValue(link.getLinkId().getValue())
517                     .build();
518                 return new LinkBuilder()
519                     .setUuid(new Uuid(
520                         UUID.nameUUIDFromBytes((link.getLinkId().getValue())
521                             .getBytes(Charset.forName("UTF-8")))
522                     .toString()))
523                 .setName(Map.of(linkName.key(), linkName))
524                 .setLayerProtocolName(Arrays.asList(LayerProtocolName.ODU))
525                 .setAdministrativeState(AdministrativeState.UNLOCKED)
526                 .setOperationalState(OperationalState.ENABLED)
527                 .setDirection(ForwardingDirection.BIDIRECTIONAL)
528                 .setNodeEdgePoint(nepList)
529                 .setTotalPotentialCapacity(new TotalPotentialCapacityBuilder().setTotalSize(
530                     new TotalSizeBuilder().setUnit(CapacityUnit.GBPS)
531                         .setValue(Uint64.valueOf(100)).build()).build())
532                 .setAvailableCapacity(new AvailableCapacityBuilder().setTotalSize(
533                     new TotalSizeBuilder().setUnit(CapacityUnit.MBPS)
534                         .setValue(Uint64.valueOf(link.augmentation(Link1.class).getAvailableBandwidth())).build())
535                     .build())
536                 .build();
537             default:
538                 LOG.error("OTN link of type {} not managed yet", prefix);
539                 return null;
540         }
541     }
542
543     public Map<NodeKey, org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node>
544         getTapiNodes() {
545         return tapiNodes;
546     }
547
548     public Map<LinkKey, Link> getTapiLinks() {
549         return tapiLinks;
550     }
551
552     public Map<String, Uuid> getUuidMap() {
553         return uuidMap;
554     }
555
556 }