Upgrade to OpenROADM 7.1.0 network models
[transportpce.git] / pce / src / test / java / org / opendaylight / transportpce / pce / networkanalyzer / PceLinkTest.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.networkanalyzer;
10
11 import java.math.BigDecimal;
12 import java.util.HashMap;
13 import java.util.Map;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.transportpce.common.NetworkUtils;
18 import org.opendaylight.transportpce.test.AbstractTest;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.link.types.rev191129.RatioDB;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1Builder;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1Builder;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev200529.span.attributes.LinkConcatenation;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev200529.span.attributes.LinkConcatenationBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.networks.network.link.OMSAttributesBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.networks.network.link.oms.attributes.SpanBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmLinkType;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmTpType;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.NodeBuilder;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.NodeKey;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.node.SupportingNode;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.node.SupportingNodeBuilder;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.node.SupportingNodeKey;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1Builder;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.LinkBuilder;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.LinkKey;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.link.DestinationBuilder;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.link.SourceBuilder;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPoint;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPointBuilder;
48 import org.opendaylight.yangtools.yang.common.Uint32;
49
50
51 public class PceLinkTest extends AbstractTest {
52
53     private static final String LINK_ID_FORMAT = "%1$s-%2$sto%3$s-%4$s";
54     private PceLink pceLink = null;
55
56     @Before
57     public void setup() {
58
59     }
60
61     @Test
62     public void testBuildPceLinkRoadmToRoadm() {
63         Link link = createRoadmToRoadm("srcNode",
64                 "destNode",
65                 "srcTp", "destTp").build();
66
67         NodeBuilder node1Builder = getNodeBuilder(geSupportingNodes());
68         Node node = node1Builder.build();
69
70         PceOpticalNode pceOpticalNode = new PceOpticalNode(node,
71                 OpenroadmNodeType.SRG, new NodeId("optical"), ServiceFormat.OMS, "test");
72         pceLink = new PceLink(link, pceOpticalNode, pceOpticalNode);
73     }
74
75     @Test
76     public void testBuildPceLinkRoadmToRoadmWithoutLinkLatency() {
77         Link link = createRoadmToRoadmWithoutLinkLatency("srcNode",
78                 "destNode",
79                 "srcTp", "destTp").build();
80
81         NodeBuilder node1Builder = getNodeBuilder(geSupportingNodes());
82         Node node = node1Builder.build();
83
84         PceOpticalNode pceOpticalNode = new PceOpticalNode(node,
85                 OpenroadmNodeType.SRG, new NodeId("optical"), ServiceFormat.OMS, "test");
86         pceLink = new PceLink(link, pceOpticalNode, pceOpticalNode);
87     }
88
89     @Test
90     public void testBuildPceLinkOTN() {
91         Link link = createOTNLink("srcNode",
92                 "destNode",
93                 "srcTp", "destTp").build();
94
95         NodeBuilder node1Builder = getNodeBuilder(geSupportingNodes());
96         Node node = node1Builder.build();
97
98         PceOpticalNode pceOpticalNode = new PceOpticalNode(node,
99                 OpenroadmNodeType.SRG, new NodeId("optical"), ServiceFormat.OMS, "test");
100         pceLink = new PceLink(link, pceOpticalNode, pceOpticalNode);
101
102     }
103
104     @Test
105     public void testBuildPceLinkExponder() {
106         Link link = createXponderLink("srcNode",
107                 "destNode",
108                 "srcTp", "destTp").build();
109
110         NodeBuilder node1Builder = getNodeBuilder(geSupportingNodes());
111         Node node = node1Builder.build();
112
113         PceOpticalNode pceOpticalNode = new PceOpticalNode(node,
114                 OpenroadmNodeType.SRG, new NodeId("optical"), ServiceFormat.OMS, "test");
115         pceLink = new PceLink(link, pceOpticalNode, pceOpticalNode);
116     }
117
118     @Test
119     public void testCalcSpanOSNR() {
120         Link link = createRoadmToRoadm("srcNode",
121                 "destNode",
122                 "srcTp", "destTp").build();
123
124         NodeBuilder node1Builder = getNodeBuilder(geSupportingNodes());
125         Node node = node1Builder.build();
126
127         PceOpticalNode pceOpticalNode = new PceOpticalNode(node,
128                 OpenroadmNodeType.SRG, new NodeId("optical"), ServiceFormat.OMS, "test");
129         pceLink = new PceLink(link, pceOpticalNode, pceOpticalNode);
130         Assert.assertNotNull(MapUtils.getOmsAttributesSpan(link));
131         Assert.assertNotNull(pceLink.calcSpanOSNR());
132         Assert.assertEquals(0, pceLink.getsrlgList().size());
133         Assert.assertTrue(7.857119000000001 == pceLink.calcSpanOSNR());
134         Assert.assertNull(pceLink.getOppositeLink());
135         Assert.assertNull(pceLink.getOppositeLink());
136         Assert.assertNotNull(pceLink.getDestTP());
137         Assert.assertNotNull(pceLink.getlinkType());
138         Assert.assertNotNull(pceLink.getLinkId());
139         Assert.assertNotNull(pceLink.getSourceId());
140         Assert.assertNotNull(pceLink.getDestId());
141         pceLink.setClient("specific_client");
142         Assert.assertTrue(pceLink.getClient().equals("specific_client"));
143         Assert.assertNotNull(pceLink.getClient());
144         Assert.assertNotNull(pceLink.getLatency());
145         Assert.assertNotNull(pceLink.getAvailableBandwidth());
146         Assert.assertNotNull(pceLink.getUsedBandwidth());
147         Assert.assertNotNull(pceLink.getsourceNetworkSupNodeId());
148         Assert.assertNotNull(pceLink.getdestNetworkSupNodeId());
149         Assert.assertNotNull(pceLink.getosnr());
150         Assert.assertNotNull(pceLink.getSourceTP());
151         Assert.assertNotNull(pceLink.getsourceCLLI());
152         Assert.assertNotNull(pceLink.getdestCLLI());
153         Assert.assertTrue(pceLink.toString().equals("PceLink type=" + pceLink.getlinkType()
154                 + " ID=" + pceLink.getLinkId().getValue() + " latency=" + pceLink.getLatency().intValue()));
155
156     }
157
158     @Test(expected = NullPointerException.class)
159     public void testPceOTNNode() {
160         NodeBuilder node1Builder = getNodeBuilder(geSupportingNodes());
161         Node node = node1Builder.build();
162         Assert.assertNotNull(node.augmentation(Node1.class));
163         // OpenroadmNodeType nodeType = node.augmentation(Node1.class).;
164
165         PceOtnNode pceOtnNode = new PceOtnNode(node, OpenroadmNodeType.SRG, node.getNodeId(), "otn", "serviceType");
166
167     }
168
169     private static LinkBuilder createOTNLink(String srcNode, String destNode, String srcTp, String destTp) {
170         Link1Builder link1Builder = new Link1Builder()
171                 .setLinkType(OpenroadmLinkType.OTNLINK);
172
173         //create source link
174         return createLinkBuilder(srcNode, destNode, srcTp, destTp, link1Builder);
175
176     }
177
178     private static LinkBuilder createXponderLink(String srcNode, String destNode, String srcTp, String destTp) {
179         Link1Builder link1Builder = new Link1Builder()
180                 .setLinkType(OpenroadmLinkType.XPONDERINPUT);
181
182         //create source link
183         return createLinkBuilder(srcNode, destNode, srcTp, destTp, link1Builder);
184
185     }
186
187     private static LinkBuilder createLinkBuilder(
188             String srcNode, String destNode, String srcTp, String destTp, Link1Builder link1Builder) {
189         SourceBuilder ietfSrcLinkBldr =
190                 new SourceBuilder().setSourceNode(new NodeId(srcNode)).setSourceTp(srcTp);
191         //create destination link
192         DestinationBuilder ietfDestLinkBldr =
193                 new DestinationBuilder().setDestNode(new NodeId(destNode))
194                         .setDestTp(destTp);
195         LinkId linkId = new LinkId(String.format(LINK_ID_FORMAT, srcNode, srcTp, destNode, destTp));
196
197         //For setting up attributes for openRoadm augment
198         LinkConcatenation linkConcatenation = new LinkConcatenationBuilder()
199                 .setSRLGLength(Uint32.valueOf(20))
200                 .setFiberType(LinkConcatenation.FiberType.Dsf)
201                 .build();
202         OMSAttributesBuilder omsAttributesBuilder =
203                 new OMSAttributesBuilder()
204                         .setSpan(new SpanBuilder()
205                                 .setSpanlossCurrent(new RatioDB(new BigDecimal("55")))
206                                 .setLinkConcatenation(Map.of(linkConcatenation.key(),
207                                         linkConcatenation
208                                 )).build());
209
210
211         LinkBuilder linkBuilder = new LinkBuilder()
212                 .setSource(ietfSrcLinkBldr.build())
213                 .setDestination(ietfDestLinkBldr.build())
214                 .setLinkId(linkId)
215                 .withKey(new LinkKey(linkId));
216
217         linkBuilder.addAugmentation(link1Builder.build());
218
219         org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.Link1Builder linkBuilderNetworkLink
220                 = new org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.Link1Builder()
221                 .setOMSAttributes(omsAttributesBuilder
222                         .build());
223
224
225         linkBuilder.addAugmentation(linkBuilderNetworkLink.build());
226
227         return linkBuilder;
228     }
229
230     private static LinkBuilder createRoadmToRoadm(String srcNode, String destNode, String srcTp, String destTp) {
231         Link1Builder link1Builder = new Link1Builder()
232                 .setLinkLatency(Uint32.valueOf(100))
233                 .setLinkType(OpenroadmLinkType.ROADMTOROADM);
234         return createLinkBuilder(srcNode, destNode, srcTp, destTp, link1Builder);
235
236     }
237
238     private static LinkBuilder createRoadmToRoadmWithoutLinkLatency(
239             String srcNode, String destNode, String srcTp, String destTp) {
240         Link1Builder link1Builder = new Link1Builder()
241                 .setLinkType(OpenroadmLinkType.ROADMTOROADM);
242         return createLinkBuilder(srcNode, destNode, srcTp, destTp, link1Builder);
243
244     }
245
246     private Map<SupportingNodeKey,SupportingNode> geSupportingNodes() {
247         Map<SupportingNodeKey,SupportingNode> supportingNodes1 = new HashMap<>();
248         SupportingNode supportingNode1 = new SupportingNodeBuilder()
249                 .setNodeRef(new NodeId("node 1"))
250                 .setNetworkRef(new NetworkId(NetworkUtils.CLLI_NETWORK_ID))
251                 .build();
252         supportingNodes1
253                 .put(supportingNode1.key(),supportingNode1);
254
255         SupportingNode supportingNode2 = new SupportingNodeBuilder()
256                 .setNodeRef(new NodeId("node 2"))
257                 .setNetworkRef(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))
258                 .build();
259         supportingNodes1
260                 .put(supportingNode2.key(),supportingNode2);
261         return supportingNodes1;
262     }
263
264     private NodeBuilder getNodeBuilder(Map<SupportingNodeKey,SupportingNode> supportingNodes1) {
265
266
267         //update tp of nodes
268         TerminationPointBuilder xpdrTpBldr = new TerminationPointBuilder();
269         TerminationPoint1Builder tp1Bldr = new TerminationPoint1Builder();
270
271         tp1Bldr.setTpType(OpenroadmTpType.XPONDERNETWORK);
272         xpdrTpBldr.addAugmentation(tp1Bldr.build());
273         TerminationPoint xpdr = xpdrTpBldr.build();
274         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1 node1 =
275                 new Node1Builder().setTerminationPoint(Map.of(xpdr.key(),xpdr)).build();
276
277
278         return new NodeBuilder()
279                 .setNodeId(new NodeId("node 1"))
280                 .withKey(new NodeKey(new NodeId("node 1")))
281                 .addAugmentation(node1)
282                 .setSupportingNode(supportingNodes1);
283     }
284
285 }