2 * Copyright © 2020 Orange, Inc. and others. All rights reserved.
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
9 package org.opendaylight.transportpce.pce.networkanalyzer;
11 import java.math.BigDecimal;
12 import java.util.HashMap;
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;
51 public class PceLinkTest extends AbstractTest {
53 private static final String LINK_ID_FORMAT = "%1$s-%2$sto%3$s-%4$s";
54 private PceLink pceLink = null;
62 public void testBuildPceLinkRoadmToRoadm() {
63 Link link = createRoadmToRoadm("srcNode",
65 "srcTp", "destTp").build();
67 NodeBuilder node1Builder = getNodeBuilder(geSupportingNodes());
68 Node node = node1Builder.build();
70 PceOpticalNode pceOpticalNode = new PceOpticalNode(node,
71 OpenroadmNodeType.SRG, new NodeId("optical"), ServiceFormat.OMS, "test");
72 pceLink = new PceLink(link, pceOpticalNode, pceOpticalNode);
76 public void testBuildPceLinkRoadmToRoadmWithoutLinkLatency() {
77 Link link = createRoadmToRoadmWithoutLinkLatency("srcNode",
79 "srcTp", "destTp").build();
81 NodeBuilder node1Builder = getNodeBuilder(geSupportingNodes());
82 Node node = node1Builder.build();
84 PceOpticalNode pceOpticalNode = new PceOpticalNode(node,
85 OpenroadmNodeType.SRG, new NodeId("optical"), ServiceFormat.OMS, "test");
86 pceLink = new PceLink(link, pceOpticalNode, pceOpticalNode);
90 public void testBuildPceLinkOTN() {
91 Link link = createOTNLink("srcNode",
93 "srcTp", "destTp").build();
95 NodeBuilder node1Builder = getNodeBuilder(geSupportingNodes());
96 Node node = node1Builder.build();
98 PceOpticalNode pceOpticalNode = new PceOpticalNode(node,
99 OpenroadmNodeType.SRG, new NodeId("optical"), ServiceFormat.OMS, "test");
100 pceLink = new PceLink(link, pceOpticalNode, pceOpticalNode);
105 public void testBuildPceLinkExponder() {
106 Link link = createXponderLink("srcNode",
108 "srcTp", "destTp").build();
110 NodeBuilder node1Builder = getNodeBuilder(geSupportingNodes());
111 Node node = node1Builder.build();
113 PceOpticalNode pceOpticalNode = new PceOpticalNode(node,
114 OpenroadmNodeType.SRG, new NodeId("optical"), ServiceFormat.OMS, "test");
115 pceLink = new PceLink(link, pceOpticalNode, pceOpticalNode);
119 public void testCalcSpanOSNR() {
120 Link link = createRoadmToRoadm("srcNode",
122 "srcTp", "destTp").build();
124 NodeBuilder node1Builder = getNodeBuilder(geSupportingNodes());
125 Node node = node1Builder.build();
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()));
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).;
165 PceOtnNode pceOtnNode = new PceOtnNode(node, OpenroadmNodeType.SRG, node.getNodeId(), "otn", "serviceType");
169 private static LinkBuilder createOTNLink(String srcNode, String destNode, String srcTp, String destTp) {
170 Link1Builder link1Builder = new Link1Builder()
171 .setLinkType(OpenroadmLinkType.OTNLINK);
174 return createLinkBuilder(srcNode, destNode, srcTp, destTp, link1Builder);
178 private static LinkBuilder createXponderLink(String srcNode, String destNode, String srcTp, String destTp) {
179 Link1Builder link1Builder = new Link1Builder()
180 .setLinkType(OpenroadmLinkType.XPONDERINPUT);
183 return createLinkBuilder(srcNode, destNode, srcTp, destTp, link1Builder);
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))
195 LinkId linkId = new LinkId(String.format(LINK_ID_FORMAT, srcNode, srcTp, destNode, destTp));
197 //For setting up attributes for openRoadm augment
198 LinkConcatenation linkConcatenation = new LinkConcatenationBuilder()
199 .setSRLGLength(Uint32.valueOf(20))
200 .setFiberType(LinkConcatenation.FiberType.Dsf)
202 OMSAttributesBuilder omsAttributesBuilder =
203 new OMSAttributesBuilder()
204 .setSpan(new SpanBuilder()
205 .setSpanlossCurrent(new RatioDB(new BigDecimal("55")))
206 .setLinkConcatenation(Map.of(linkConcatenation.key(),
211 LinkBuilder linkBuilder = new LinkBuilder()
212 .setSource(ietfSrcLinkBldr.build())
213 .setDestination(ietfDestLinkBldr.build())
215 .withKey(new LinkKey(linkId));
217 linkBuilder.addAugmentation(link1Builder.build());
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
225 linkBuilder.addAugmentation(linkBuilderNetworkLink.build());
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);
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);
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))
253 .put(supportingNode1.key(),supportingNode1);
255 SupportingNode supportingNode2 = new SupportingNodeBuilder()
256 .setNodeRef(new NodeId("node 2"))
257 .setNetworkRef(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))
260 .put(supportingNode2.key(),supportingNode2);
261 return supportingNodes1;
264 private NodeBuilder getNodeBuilder(Map<SupportingNodeKey,SupportingNode> supportingNodes1) {
268 TerminationPointBuilder xpdrTpBldr = new TerminationPointBuilder();
269 TerminationPoint1Builder tp1Bldr = new TerminationPoint1Builder();
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();
278 return new NodeBuilder()
279 .setNodeId(new NodeId("node 1"))
280 .withKey(new NodeKey(new NodeId("node 1")))
281 .addAugmentation(node1)
282 .setSupportingNode(supportingNodes1);