update pce yang model
[transportpce.git] / pce / src / test / java / org / opendaylight / transportpce / pce / utils / NodeUtils.java
1 /*
2  * Copyright © 2020 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
9 package org.opendaylight.transportpce.pce.utils;
10
11 import java.util.ArrayList;
12 import java.util.HashMap;
13 import java.util.List;
14 import java.util.Map;
15 import org.opendaylight.transportpce.common.NetworkUtils;
16 import org.opendaylight.transportpce.common.fixedflex.GridUtils;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Link1Builder;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Node1;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.TerminationPoint1Builder;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.networks.network.link.OMSAttributesBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.networks.network.link.oms.attributes.SpanBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.networks.network.node.DegreeAttributes;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.networks.network.node.DegreeAttributesBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.networks.network.node.SrgAttributes;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.networks.network.node.SrgAttributesBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.networks.network.node.termination.point.CpAttributesBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.networks.network.node.termination.point.CtpAttributesBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.networks.network.node.termination.point.PpAttributesBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.networks.network.node.termination.point.RxTtpAttributesBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.networks.network.node.termination.point.TxTtpAttributesBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.networks.network.node.termination.point.XpdrClientAttributesBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.networks.network.node.termination.point.XpdrNetworkAttributesBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.networks.network.node.termination.point.XpdrPortAttributesBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmLinkType;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmTpType;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.xpdr.tp.supported.interfaces.SupportedInterfaceCapability;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.xpdr.tp.supported.interfaces.SupportedInterfaceCapabilityBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.xpdr.tp.supported.interfaces.SupportedInterfaceCapabilityKey;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210.networks.network.node.termination.point.TpSupportedInterfaces;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210.networks.network.node.termination.point.TpSupportedInterfacesBuilder;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210.networks.network.node.termination.point.XpdrTpPortConnectionAttributesBuilder;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.If100GEODU4;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.If10GEODU2e;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.If1GEODU0;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.IfOCHOTU4ODU4;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
50 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.NodeBuilder;
51 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.NodeKey;
52 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.node.SupportingNode;
53 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.node.SupportingNodeBuilder;
54 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.node.SupportingNodeKey;
55 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
56 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1Builder;
57 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.TpId;
58 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
59 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.LinkBuilder;
60 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.LinkKey;
61 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.link.DestinationBuilder;
62 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.link.SourceBuilder;
63 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPoint;
64 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPointBuilder;
65 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPointKey;
66 import org.opendaylight.yangtools.yang.binding.Augmentation;
67 import org.opendaylight.yangtools.yang.common.Uint32;
68
69 public final class NodeUtils {
70
71     private static final String LINK_ID_FORMAT = "%1$s-%2$sto%3$s-%4$s";
72
73     public static LinkBuilder createLinkBuilder(
74             String srcNode, String destNode, String srcTp, String destTp, Link1Builder link1Builder) {
75         SourceBuilder ietfSrcLinkBldr =
76                 new SourceBuilder().setSourceNode(new NodeId(srcNode)).setSourceTp(new TpId(srcTp));
77         //create destination link
78         DestinationBuilder ietfDestLinkBldr =
79                 new DestinationBuilder().setDestNode(new NodeId(destNode)).setDestTp(new TpId(destTp));
80         LinkId linkId = new LinkId(String.format(LINK_ID_FORMAT, srcNode, srcTp, destNode, destTp));
81
82         LinkId oppositeLinkId = new LinkId("OpenROADM-3-2-DEG1-to-OpenROADM-3-1-DEG1");
83         // Augementation
84         Augmentation<Link> aug11 = new org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210
85                 .Link1Builder()
86                 .setAmplified(true)
87                 .setOMSAttributes(new OMSAttributesBuilder()
88                         .setSpan(new SpanBuilder().build())
89                         .build())
90                 .build();
91         return new LinkBuilder()
92                 .setSource(ietfSrcLinkBldr.build())
93                 .setDestination(ietfDestLinkBldr.build())
94                 .setLinkId(linkId)
95                 .addAugmentation(aug11)
96                 .withKey(new LinkKey(linkId))
97                 .addAugmentation(link1Builder.setOppositeLink(oppositeLinkId).build());
98     }
99
100     public static LinkBuilder createRoadmToRoadm(String srcNode, String destNode, String srcTp, String destTp) {
101         Link1Builder link1Builder = new Link1Builder()
102                 .setLinkLatency(Uint32.valueOf(30))
103                 .setLinkType(OpenroadmLinkType.ROADMTOROADM)
104                 .setAdministrativeState(AdminStates.InService)
105                 .setOperationalState(State.InService);
106         return createLinkBuilder(srcNode, destNode, srcTp, destTp, link1Builder);
107
108     }
109
110     public static Map<SupportingNodeKey, SupportingNode> geSupportingNodes() {
111         Map<SupportingNodeKey, SupportingNode> supportingNodes1 = new HashMap<>();
112         SupportingNode supportingNode1 = new SupportingNodeBuilder()
113                 .setNodeRef(new NodeId("node 1"))
114                 .setNetworkRef(new NetworkId(NetworkUtils.CLLI_NETWORK_ID))
115                 .build();
116         supportingNodes1
117                 .put(supportingNode1.key(),supportingNode1);
118
119         SupportingNode supportingNode2 = new SupportingNodeBuilder()
120                 .setNodeRef(new NodeId("node 2"))
121                 .setNetworkRef(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))
122                 .build();
123         supportingNodes1
124                 .put(supportingNode2.key(),supportingNode2);
125         return supportingNodes1;
126     }
127
128     public static NodeBuilder getNodeBuilder(Map<SupportingNodeKey,SupportingNode> supportingNodes1) {
129
130
131         //update tp of nodes
132         TerminationPointBuilder xpdrTpBldr = new TerminationPointBuilder()
133                 .withKey(new TerminationPointKey(new TpId("xpdr")));
134         TerminationPoint1Builder tp1Bldr = new TerminationPoint1Builder();
135         org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.TerminationPoint1Builder tp11Bldr =
136             new org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.TerminationPoint1Builder()
137                 .setAdministrativeState(AdminStates.InService)
138                 .setOperationalState(State.InService);
139
140         tp1Bldr.setTpType(OpenroadmTpType.XPONDERNETWORK);
141         xpdrTpBldr.addAugmentation(tp1Bldr.build());
142         xpdrTpBldr.addAugmentation(tp11Bldr.build());
143         TerminationPoint xpdr = xpdrTpBldr.build();
144         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 node1 =
145             new Node1Builder().setTerminationPoint(Map.of(xpdr.key(),xpdr)).build();
146         Node1 node11 = new org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Node1Builder()
147             .setAdministrativeState(AdminStates.InService)
148             .setOperationalState(State.InService).build();
149         return new NodeBuilder()
150                 .setNodeId(new NodeId("node 1"))
151                 .withKey(new NodeKey(new NodeId("node 1")))
152                 .addAugmentation(node1)
153                 .addAugmentation(node11)
154                 .setSupportingNode(supportingNodes1);
155     }
156
157
158     // OTN network node
159     public static List<SupportingNode> getOTNSupportingNodes() {
160         List<SupportingNode> supportingNodes1 = new ArrayList<>();
161         supportingNodes1
162                 .add(new SupportingNodeBuilder()
163                         .setNodeRef(new NodeId("node 1"))
164                         .setNetworkRef(new NetworkId(NetworkUtils.CLLI_NETWORK_ID))
165                         .build());
166
167         supportingNodes1
168                 .add(new SupportingNodeBuilder()
169                         .setNodeRef(new NodeId("node 2"))
170                         .setNetworkRef(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))
171                         .build());
172         return supportingNodes1;
173     }
174
175     public static NodeBuilder getOTNNodeBuilder(Map<SupportingNodeKey,SupportingNode> supportingNodes1,
176                                                 OpenroadmTpType openroadmTpType) {
177
178         org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.TerminationPoint1Builder
179                 tp1Bldr = getTerminationPoint1Builder(openroadmTpType);
180         TerminationPointBuilder xpdrTpBldr = getTerminationPointBuilder(openroadmTpType);
181         xpdrTpBldr
182                 .addAugmentation(tp1Bldr.build());
183
184         xpdrTpBldr.addAugmentation(createAnother2TerminationPoint(openroadmTpType).build());
185         xpdrTpBldr.addAugmentation(createAnotherTerminationPoint(openroadmTpType).build());
186
187         org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.Node1 node1 = getNode1();
188         TerminationPoint xpdr = xpdrTpBldr.build();
189         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 node1Rev180226 =
190                 new Node1Builder()
191                         .setTerminationPoint(Map.of(xpdr.key(),xpdr))
192                         .build();
193
194
195         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 nodeIetf =
196                 new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226
197                         .Node1Builder()
198                         .setTerminationPoint(Map.of(xpdr.key(),xpdr))
199                         .build();
200
201         return new NodeBuilder()
202                 .setNodeId(new NodeId("node_test"))
203                 .withKey(new NodeKey(new NodeId("node 1")))
204                 .addAugmentation(node1Rev180226)
205                 .addAugmentation(node1)
206                 .addAugmentation(nodeIetf)
207                 .setSupportingNode(supportingNodes1);
208     }
209
210     public static NodeBuilder getOTNNodeBuilderEmpty(Map<SupportingNodeKey,SupportingNode> supportingNodes1,
211                                                      OpenroadmTpType openroadmTpType) {
212
213         org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.TerminationPoint1Builder tp1Bldr =
214                 getTerminationPoint1Builder(openroadmTpType);
215         TerminationPointBuilder xpdrTpBldr = getTerminationPointBuilder(openroadmTpType);
216         xpdrTpBldr.addAugmentation(tp1Bldr.build());
217         xpdrTpBldr.addAugmentation(createAnotherTerminationPoint(openroadmTpType).build());
218
219         org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.Node1 node1 = getNode1Empty();
220         TerminationPoint xpdr = xpdrTpBldr.build();
221         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 node1Rev180226 =
222                 new Node1Builder()
223                         .setTerminationPoint(Map.of(xpdr.key(),xpdr))
224                         .build();
225         return new NodeBuilder()
226                 .setNodeId(new NodeId("node_test"))
227                 .withKey(new NodeKey(new NodeId("node 1")))
228                 .addAugmentation(node1Rev180226)
229                 .addAugmentation(node1)
230                 .setSupportingNode(supportingNodes1);
231     }
232
233     private static org.opendaylight
234             .yang.gen.v1.http.org.openroadm.network.topology.rev211210.Node1 getNode1() {
235         return new org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.Node1Builder()
236                 .setSrgAttributes(getSrgAttributes())
237                 .setDegreeAttributes(getDegAttributes())
238                 .build();
239     }
240
241     private static org.opendaylight
242             .yang.gen.v1.http.org.openroadm.network.topology.rev211210.Node1 getNode1Empty() {
243         return new org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev211210.Node1Builder()
244                 .setSrgAttributes(getEmptySrgAttributes())
245                 .setDegreeAttributes(getEmptyDegAttributes())
246                 .build();
247     }
248
249     private static DegreeAttributes getDegAttributes() {
250         return (new DegreeAttributesBuilder())
251                 .setAvailFreqMaps(GridUtils.initFreqMaps4FixedGrid2Available())
252                 .build();
253     }
254
255     private static SrgAttributes getSrgAttributes() {
256         return new SrgAttributesBuilder().setAvailFreqMaps(GridUtils.initFreqMaps4FixedGrid2Available()).build();
257     }
258
259     private static DegreeAttributes getEmptyDegAttributes() {
260         return (new DegreeAttributesBuilder())
261                 .setAvailFreqMaps(Map.of())
262                 .build();
263     }
264
265     private static SrgAttributes getEmptySrgAttributes() {
266         return new SrgAttributesBuilder().setAvailFreqMaps(Map.of()).build();
267     }
268
269     private static TerminationPointBuilder getTerminationPointBuilder(OpenroadmTpType openroadmTpType) {
270         return new TerminationPointBuilder()
271                 .setTpId(new TpId("2"))
272                 .addAugmentation(createOTNTerminationPoint(openroadmTpType).build());
273     }
274
275     private static org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.TerminationPoint1Builder
276         getTerminationPoint1Builder(OpenroadmTpType openroadmTpType) {
277
278         return new org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.TerminationPoint1Builder()
279                 .setTpType(openroadmTpType);
280
281     }
282
283     private static org.opendaylight.yang.gen
284             .v1.http.org.openroadm.network.topology.rev211210.TerminationPoint1Builder createAnotherTerminationPoint(
285             OpenroadmTpType openroadmTpType
286     ) {
287         return new org.opendaylight
288                 .yang.gen.v1.http.org.openroadm.network.topology.rev211210.TerminationPoint1Builder()
289                 .setCtpAttributes((new CtpAttributesBuilder()).build())
290                 .setCpAttributes((new CpAttributesBuilder()).build())
291                 .setTxTtpAttributes((new TxTtpAttributesBuilder()).setUsedWavelengths(Map.of()).build())
292                 .setRxTtpAttributes((new RxTtpAttributesBuilder()).setUsedWavelengths(Map.of()).build())
293                 .setPpAttributes((new PpAttributesBuilder()).setUsedWavelength(Map.of()).build())
294                 .setXpdrClientAttributes((new XpdrClientAttributesBuilder()).build())
295                 .setXpdrPortAttributes((new XpdrPortAttributesBuilder()).build())
296                 .setXpdrNetworkAttributes(new XpdrNetworkAttributesBuilder()
297                         .setTailEquipmentId("destNode" + "--" + "destTp").build());
298     }
299
300     private static org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
301             .TerminationPoint1Builder createOTNTerminationPoint(OpenroadmTpType openroadmTpType) {
302
303         SupportedInterfaceCapability supIfCapa = new SupportedInterfaceCapabilityBuilder()
304                 .setIfCapType(IfOCHOTU4ODU4.class)
305                 .build();
306
307         SupportedInterfaceCapability supIfCapa1 = new SupportedInterfaceCapabilityBuilder()
308                 .setIfCapType(If100GEODU4.class)
309                 .build();
310         SupportedInterfaceCapability supIfCapa2 = new SupportedInterfaceCapabilityBuilder()
311                 .setIfCapType(If10GEODU2e.class)
312                 .build();
313         SupportedInterfaceCapability supIfCapa3 = new SupportedInterfaceCapabilityBuilder()
314                 .setIfCapType(If1GEODU0.class)
315                 .build();
316
317         Map<SupportedInterfaceCapabilityKey,SupportedInterfaceCapability> supIfCapaList = new HashMap<>();
318         supIfCapaList.put(supIfCapa.key(),supIfCapa);
319         supIfCapaList.put(supIfCapa1.key(),supIfCapa1);
320         supIfCapaList.put(supIfCapa2.key(),supIfCapa2);
321         supIfCapaList.put(supIfCapa3.key(),supIfCapa3);
322
323         TpSupportedInterfaces tpSupIf = new TpSupportedInterfacesBuilder()
324                 .setSupportedInterfaceCapability(supIfCapaList)
325                 .build();
326
327         XpdrTpPortConnectionAttributesBuilder xtpcaBldr = new XpdrTpPortConnectionAttributesBuilder();
328
329         return new org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
330                 .TerminationPoint1Builder()
331                 .setTpSupportedInterfaces(tpSupIf)
332                 .setXpdrTpPortConnectionAttributes(xtpcaBldr.build());
333     }
334
335     private static org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210
336             .TerminationPoint1Builder createAnother2TerminationPoint(OpenroadmTpType openroadmTpType) {
337         return new org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210
338                 .TerminationPoint1Builder()
339                 .setOperationalState(State.InService)
340                 .setAdministrativeState(AdminStates.InService)
341                 .setTpType(openroadmTpType);
342     }
343
344     private NodeUtils() {
345         throw new IllegalStateException("Utility class");
346     }
347 }