Migrate networkmodel module to JUnit5
[transportpce.git] / networkmodel / src / test / java / org / opendaylight / transportpce / networkmodel / util / OpenRoadmOtnTopologyTest.java
1 /*
2  * Copyright © 2020 Orange Labs, 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.networkmodel.util;
9
10 import static org.hamcrest.CoreMatchers.containsString;
11 import static org.hamcrest.CoreMatchers.either;
12 import static org.hamcrest.CoreMatchers.hasItem;
13 import static org.hamcrest.CoreMatchers.hasItems;
14 import static org.hamcrest.CoreMatchers.not;
15 import static org.hamcrest.MatcherAssert.assertThat;
16 import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
17 import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
18 import static org.junit.jupiter.api.Assertions.assertEquals;
19 import static org.junit.jupiter.api.Assertions.assertNotNull;
20 import static org.junit.jupiter.api.Assertions.assertNull;
21 import static org.junit.jupiter.api.Assertions.assertTrue;
22 import static org.junit.jupiter.api.Assertions.fail;
23
24 import com.google.gson.stream.JsonReader;
25 import java.io.FileReader;
26 import java.io.IOException;
27 import java.io.Reader;
28 import java.nio.charset.StandardCharsets;
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.stream.Collectors;
34 import org.junit.jupiter.api.Test;
35 import org.opendaylight.transportpce.networkmodel.dto.TopologyShard;
36 import org.opendaylight.transportpce.networkmodel.util.test.JsonUtil;
37 import org.opendaylight.transportpce.networkmodel.util.test.NetworkmodelTestUtil;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkutils.rev220630.OtnLinkType;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.Network;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.Mapping;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.MappingBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.MappingKey;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.Nodes;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.NodesBuilder;
45 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.network.nodes.NodeInfoBuilder;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Node1;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.TerminationPoint1;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.NodeTypes;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev201211.xpdr.odu.switching.pools.OduSwitchingPools;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev201211.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingList;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmLinkType;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmNodeType;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmTpType;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.xpdr.tp.supported.interfaces.SupportedInterfaceCapability;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.ODU2;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.ODU2e;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev210924.ODU4;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210.Link1;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210.networks.network.node.SwitchingPools;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.If100GE;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.If100GEODU4;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.If10GE;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.If10GEODU2;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.If10GEODU2e;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.IfOCH;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev201211.IfOCHOTU4ODU4;
67 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
68 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.node.SupportingNode;
69 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.TpId;
70 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
71 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.LinkBuilder;
72 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPoint;
73 import org.opendaylight.yangtools.yang.common.QName;
74 import org.opendaylight.yangtools.yang.common.Uint16;
75 import org.opendaylight.yangtools.yang.common.Uint32;
76 import org.slf4j.Logger;
77 import org.slf4j.LoggerFactory;
78
79 public class OpenRoadmOtnTopologyTest {
80
81     private static final Logger LOG = LoggerFactory.getLogger(OpenRoadmOtnTopologyTest.class);
82     private Nodes portMappingTpdr;
83     private Nodes portMappingSpdr;
84     private Nodes portMappingBad;
85
86     public OpenRoadmOtnTopologyTest() {
87         try (Reader reader = new FileReader("src/test/resources/portMapping.json", StandardCharsets.UTF_8);
88                 JsonReader portMappingReader = new JsonReader(reader)) {
89             Network portMapping = (Network) JsonUtil.getInstance().getDataObjectFromJson(portMappingReader,
90                     QName.create("http://org/opendaylight/transportpce/portmapping", "2022-03-16", "network"));
91             for (Nodes nodes : portMapping.nonnullNodes().values()) {
92                 if (nodes.getNodeId().equals("XPDR-A1")) {
93                     this.portMappingTpdr = nodes;
94                 } else {
95                     this.portMappingSpdr = nodes;
96                 }
97             }
98             Map<MappingKey,Mapping> mappingList = new HashMap<>();
99             Mapping mapping = new MappingBuilder().setLogicalConnectionPoint("XPDR0-NETWORK0").build();
100             mappingList.put(mapping.key(),mapping);
101             this.portMappingBad = new NodesBuilder()
102                 .setNodeId(this.portMappingTpdr.getNodeId())
103                 .setNodeInfo(new NodeInfoBuilder(this.portMappingTpdr.getNodeInfo()).setNodeType(NodeTypes.Ila).build())
104                 .setMapping(mappingList)
105                 .build();
106             LOG.info("tpdr portMapping = {}", this.portMappingTpdr.toString());
107             LOG.info("spdr portMapping = {}", this.portMappingSpdr.toString());
108             LOG.info("ila portMapping = {}", this.portMappingBad.toString());
109         } catch (IOException e) {
110             LOG.error("Cannot init OpenRoadmOtnTopologyTest ", e);
111             fail("Cannot init OpenRoadmOtnTopologyTest ");
112         }
113     }
114
115     @Test
116     void createTopologyShardForTpdrTest() {
117         TopologyShard topologyShard = OpenRoadmOtnTopology.createTopologyShard(this.portMappingTpdr);
118         assertNotNull(topologyShard, "TopologyShard should never be null");
119         assertEquals(1, topologyShard.getNodes().size(), "Should contain a single node");
120         assertEquals(0, topologyShard.getLinks().size(), "Should contain no link");
121         Node node = topologyShard.getNodes().get(0);
122         assertEquals("XPDR-A1-XPDR1", node.getNodeId().getValue());
123         // tests supporting nodes
124         List<SupportingNode> supportingNodes = node.nonnullSupportingNode().values().stream()
125             .sorted((sn1, sn2) -> sn1.getNetworkRef().getValue().compareTo(sn2.getNetworkRef().getValue()))
126             .collect(Collectors.toList());
127         assertEquals(3, supportingNodes.size(),"Should contain 3 supporting nodes");
128         assertEquals(supportingNodes.get(0).getNetworkRef().getValue(), "clli-network");
129         assertEquals(supportingNodes.get(0).getNodeRef().getValue(), "NodeA");
130         assertEquals(supportingNodes.get(1).getNetworkRef().getValue(), "openroadm-network");
131         assertEquals(supportingNodes.get(1).getNodeRef().getValue(), "XPDR-A1");
132         assertEquals(supportingNodes.get(2).getNetworkRef().getValue(), "openroadm-topology");
133         assertEquals(supportingNodes.get(2).getNodeRef().getValue(), "XPDR-A1-XPDR1");
134         assertEquals(OpenroadmNodeType.TPDR, node.augmentation(Node1.class).getNodeType());
135         assertEquals(
136             Uint16.valueOf(1),
137             node.augmentation(
138                         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210.Node1.class)
139                     .getXpdrAttributes().getXpdrNumber());
140         //tests list of TPs
141         List<TerminationPoint> tps = node.augmentation(
142                 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
143             .nonnullTerminationPoint().values().stream()
144                 .sorted((tp1, tp2) -> tp1.getTpId().getValue().compareTo(tp2.getTpId().getValue()))
145                 .collect(Collectors.toList());
146         assertEquals(4, tps.size(), "node should contain 4 TPs");
147         //tests client tp
148         assertEquals("XPDR1-CLIENT1", tps.get(0).getTpId().getValue());
149         assertEquals(
150             "XPDR1-NETWORK1",
151             tps.get(0).augmentation(
152                         TerminationPoint1.class).getAssociatedConnectionMapTp().iterator().next().getValue());
153         assertEquals(
154             1,
155             tps.get(0).augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
156                         .TerminationPoint1.class)
157                     .getTpSupportedInterfaces().getSupportedInterfaceCapability().size(),
158             "only If100GE interface capabitily expected");
159         assertEquals(
160             If100GE.VALUE,
161             tps.get(0).augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
162                         .TerminationPoint1.class)
163                     .getTpSupportedInterfaces().nonnullSupportedInterfaceCapability().values().stream().findFirst()
164                         .get().getIfCapType());
165         assertEquals(OpenroadmTpType.XPONDERCLIENT,tps.get(0).augmentation(TerminationPoint1.class).getTpType(),
166             "first TP must be of type client");
167         //tests network tp
168         assertEquals("XPDR1-NETWORK1", tps.get(2).getTpId().getValue());
169         assertEquals("XPDR1-CLIENT1", tps.get(2).augmentation(TerminationPoint1.class)
170                     .getAssociatedConnectionMapTp().iterator().next().getValue());
171         assertEquals(
172             1,
173             tps.get(2).augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
174                         .TerminationPoint1.class)
175                     .getTpSupportedInterfaces().getSupportedInterfaceCapability().size());
176         assertEquals(
177             IfOCH.VALUE,
178             tps.get(2).augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
179                         .TerminationPoint1.class)
180                     .getTpSupportedInterfaces().getSupportedInterfaceCapability().values().stream().findFirst().get()
181                         .getIfCapType());
182         assertNull(
183             tps.get(2).augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
184                     .TerminationPoint1.class)
185                 .getXpdrTpPortConnectionAttributes().getRate(),
186             "the rate should be null");
187         assertEquals(OpenroadmTpType.XPONDERNETWORK,tps.get(2).augmentation(TerminationPoint1.class).getTpType(),
188             "third TP must be of type network");
189     }
190
191     @Test
192     void createTopologyShardForSpdrTest() {
193         TopologyShard topologyShard = OpenRoadmOtnTopology.createTopologyShard(this.portMappingSpdr);
194         assertNotNull(topologyShard, "TopologyShard should never be null");
195         assertEquals(2, topologyShard.getNodes().size(), "Should contain two nodes");
196         assertEquals(0, topologyShard.getLinks().size(), "Should contain no link");
197         List<Node> nodes = topologyShard.getNodes().stream()
198             .sorted((n1, n2) -> n1.getNodeId().getValue().compareTo(n2.getNodeId().getValue()))
199             .collect(Collectors.toList());
200         for (Node node : nodes) {
201             checkSpdrNode(node);
202         }
203     }
204
205     @Test
206     void createOtnLinksForOTU4NormalTest() {
207         String nodeA = "SPDRA";
208         String tpA = "XPDR1-NETWORK1";
209         String nodeZ = "SPDRZ";
210         String tpZ = "XPDR1-NETWORK1";
211         List<Link> links = OpenRoadmOtnTopology.createOtnLinks(nodeA, tpA, nodeZ, tpZ, OtnLinkType.OTU4).getLinks();
212         assertEquals(2, links.size(), "2 OTU4 links should have been created");
213         List<Link> sortedLinks = links.stream()
214             .sorted((l1, l2) -> l1.getLinkId().getValue().compareTo(l2.getLinkId().getValue()))
215             .collect(Collectors.toList());
216         assertEquals(
217             "OTU4-SPDRA-XPDR1-XPDR1-NETWORK1toSPDRZ-XPDR1-XPDR1-NETWORK1",
218             sortedLinks.get(0).getLinkId().getValue(),
219             "name of OTU4 linkid AZ");
220         assertEquals(
221             "OTU4-SPDRZ-XPDR1-XPDR1-NETWORK1toSPDRA-XPDR1-XPDR1-NETWORK1",
222             sortedLinks.get(1).getLinkId().getValue(),
223             "name of OTU4 linkid ZA");
224         assertEquals("SPDRA-XPDR1", sortedLinks.get(0).getSource().getSourceNode().getValue());
225         assertEquals("SPDRZ-XPDR1", sortedLinks.get(0).getDestination().getDestNode().getValue());
226         assertEquals("SPDRZ-XPDR1", sortedLinks.get(1).getSource().getSourceNode().getValue());
227         assertEquals("SPDRA-XPDR1", sortedLinks.get(1).getDestination().getDestNode().getValue());
228         assertEquals(
229             Uint32.valueOf(100000),
230             sortedLinks.get(0).augmentation(Link1.class).getAvailableBandwidth(),
231             "available BW at OTU4 creation should be 100G (100000)");
232         assertEquals(
233             Uint32.valueOf(0),
234             sortedLinks.get(0).augmentation(Link1.class).getUsedBandwidth(),
235             "used BW at OTU4 creation should be 0");
236         assertEquals(
237             OpenroadmLinkType.OTNLINK,
238             sortedLinks.get(0).augmentation(
239                     org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Link1.class)
240                 .getLinkType());
241         assertEquals(
242             "OTU4-SPDRZ-XPDR1-XPDR1-NETWORK1toSPDRA-XPDR1-XPDR1-NETWORK1",
243             sortedLinks.get(0).augmentation(
244                     org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Link1.class)
245                 .getOppositeLink().getValue(),
246             "opposite link must be present");
247         assertEquals(
248             OtnLinkType.OTU4,
249             sortedLinks.get(0).augmentation(
250                     org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkutils.rev220630.Link1.class)
251                 .getOtnLinkType(),
252             "otn link type should be OTU4");
253     }
254
255     @Test
256     void createOtnLinksForNotManagedOtnlinktypeTest() {
257         String nodeA = "SPDRA";
258         String tpA = "XPDR1-NETWORK1";
259         String nodeZ = "SPDRZ";
260         String tpZ = "XPDR1-NETWORK1";
261         TopologyShard topoShard = OpenRoadmOtnTopology.createOtnLinks(nodeA, tpA, nodeZ, tpZ, OtnLinkType.ODU0);
262         assertNotNull(topoShard, "TopologyShard should never be null");
263         assertNull(topoShard.getNodes(), "TopologyShard should not contain any node");
264         assertNull(topoShard.getLinks(), "TopologyShard should not contain any link");
265     }
266
267     @Test
268     void createOtnLinksForODU4NormalTest() {
269         TopologyShard topoShard = OpenRoadmOtnTopology
270             .createOtnLinks(
271                 NetworkmodelTestUtil.createSuppOTNLinks(OtnLinkType.OTU4, Uint32.valueOf(100000)),
272                 NetworkmodelTestUtil.createTpList(false), OtnLinkType.ODTU4);
273         assertNotNull(topoShard, "TopologyShard should never be null");
274         assertNull(topoShard.getNodes(), "list of nodes should be null");
275         List<Link> sortedLinks = topoShard.getLinks().stream()
276             .sorted((l1, l2) -> l1.getLinkId().getValue().compareTo(l2.getLinkId().getValue()))
277             .collect(Collectors.toList());
278         assertEquals(4, sortedLinks.size(), "list of links should contain 4 links");
279         assertTrue(sortedLinks.get(2).getLinkId().getValue().startsWith("OTU4-"), "link 3 should be of type OTU4");
280         assertEquals(
281             Uint32.valueOf(0),
282             sortedLinks.get(2).augmentation(Link1.class).getAvailableBandwidth(),
283             "after odu4 creation, available BW of supported OTU4 should be 0");
284         assertEquals(
285             Uint32.valueOf(100000),
286             sortedLinks.get(2).augmentation(Link1.class).getUsedBandwidth(),
287             "after odu4 creation, used BW of supported OTU4 should be 100 000");
288         assertEquals(
289             "ODTU4-SPDRA-XPDR1-XPDR1-NETWORK1toSPDRZ-XPDR1-XPDR1-NETWORK1",
290             sortedLinks.get(0).getLinkId().getValue());
291         assertEquals(
292             "ODTU4-SPDRZ-XPDR1-XPDR1-NETWORK1toSPDRA-XPDR1-XPDR1-NETWORK1",
293             sortedLinks.get(1).getLinkId().getValue());
294         assertEquals("SPDRA-XPDR1", sortedLinks.get(0).getSource().getSourceNode().getValue());
295         assertEquals("SPDRZ-XPDR1", sortedLinks.get(0).getDestination().getDestNode().getValue());
296         assertEquals("SPDRZ-XPDR1", sortedLinks.get(1).getSource().getSourceNode().getValue());
297         assertEquals("SPDRA-XPDR1", sortedLinks.get(1).getDestination().getDestNode().getValue());
298         assertEquals(
299             Uint32.valueOf(100000),
300             sortedLinks.get(0).augmentation(Link1.class).getAvailableBandwidth(),
301             "after odu4 creation, its available BW should be 100 000");
302         assertEquals(
303             Uint32.valueOf(0),
304             sortedLinks.get(0).augmentation(Link1.class).getUsedBandwidth(),
305             "after odu4 creation, its used BW should be 0");
306         assertEquals(
307             OpenroadmLinkType.OTNLINK,
308             sortedLinks.get(0).augmentation(
309                     org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Link1.class)
310                 .getLinkType());
311         assertEquals(
312             "ODTU4-SPDRZ-XPDR1-XPDR1-NETWORK1toSPDRA-XPDR1-XPDR1-NETWORK1",
313             sortedLinks.get(0).augmentation(
314                     org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev211210.Link1.class)
315                 .getOppositeLink().getValue(),
316             "opposite link must be present");
317         assertEquals(
318             OtnLinkType.ODTU4,
319             sortedLinks.get(0).augmentation(
320                     org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkutils.rev220630.Link1.class)
321                 .getOtnLinkType(),
322             "otn link type should be ODTU4");
323
324         assertEquals(2, topoShard.getTps().size(), "list of TPs should contain 2 updated TPs");
325         assertNotNull(
326             topoShard.getTps().get(0).augmentation(
327                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
328                         .TerminationPoint1.class)
329                 .getXpdrTpPortConnectionAttributes().getTsPool(),
330             "after ODU4 creation, its termination point should contain a TsPool list");
331         assertEquals(
332             80,
333             topoShard.getTps().get(0).augmentation(
334                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
335                         .TerminationPoint1.class)
336                 .getXpdrTpPortConnectionAttributes().getTsPool().size(),
337             "Ts pool list should be full, with 80 trib slots");
338         assertNotNull(
339             topoShard.getTps().get(0).augmentation(
340                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
341                         .TerminationPoint1.class)
342                 .getXpdrTpPortConnectionAttributes().getOdtuTpnPool().values().stream().findFirst().get().getTpnPool(),
343             "after ODU4 creation, its termination point should contain a TpnPool list");
344         assertEquals(
345             80,
346             topoShard.getTps().get(0).augmentation(
347                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
348                         .TerminationPoint1.class)
349                 .getXpdrTpPortConnectionAttributes().getOdtuTpnPool().values().stream().findFirst().get().getTpnPool()
350                 .size(),
351             "Tpn pool list should be full, with 80 trib ports");
352     }
353
354     @Test
355     void createOtnLinksForODU4WhenOTU4HaveBadBWParamsTest() {
356         List<Link> otu4Links = NetworkmodelTestUtil.createSuppOTNLinks(OtnLinkType.OTU4, Uint32.valueOf(100000));
357         List<Link> otu4LinksWithBadBWParam = new ArrayList<>();
358         for (Link link : otu4Links) {
359             otu4LinksWithBadBWParam.add(new LinkBuilder(link).removeAugmentation(Link1.class).build());
360         }
361         TopologyShard topoShard = OpenRoadmOtnTopology.createOtnLinks(
362                 otu4LinksWithBadBWParam,
363                 NetworkmodelTestUtil.createTpList(false),
364                 OtnLinkType.OTU4);
365         assertNotNull(topoShard, "TopologyShard should never be null");
366         assertNull(topoShard.getNodes(), "list of nodes should be null");
367         assertNull(topoShard.getLinks(), "list of links should be null");
368         assertNull(topoShard.getTps(), "list of tps should be null");
369
370         otu4LinksWithBadBWParam.clear();
371         topoShard = OpenRoadmOtnTopology.createOtnLinks(
372                 NetworkmodelTestUtil.createSuppOTNLinks(OtnLinkType.OTU4, Uint32.valueOf(99000)),
373                 NetworkmodelTestUtil.createTpList(false),
374                 OtnLinkType.OTU4);
375         assertNull(topoShard.getNodes(), "list of nodes should be null");
376         assertNull(topoShard.getLinks(), "list of links should be null");
377         assertNull(topoShard.getTps(), "list of tps should be null");
378     }
379
380     @Test
381     void deleteOtnLinksForODU4NormalTest() {
382         TopologyShard topoShard = OpenRoadmOtnTopology.deleteOtnLinks(
383                     NetworkmodelTestUtil.createSuppOTNLinks(OtnLinkType.OTU4, Uint32.valueOf(0)),
384                     NetworkmodelTestUtil.createTpList(true),
385                     OtnLinkType.OTU4);
386         assertNotNull(topoShard, "TopologyShard should never be null");
387         assertEquals(2, topoShard.getLinks().size(), "list of links should contain 2 links");
388         assertEquals(
389             Uint32.valueOf(100000),
390             topoShard.getLinks().get(0).augmentation(Link1.class).getAvailableBandwidth(),
391             "after ODU4 deletion, available BW of supported OTU4 should be 100 000");
392         assertEquals(
393             Uint32.valueOf(0),
394             topoShard.getLinks().get(0).augmentation(Link1.class).getUsedBandwidth(),
395             "after ODU4 deletion, used BW of supported OTU4 should be 0");
396
397         assertEquals(2, topoShard.getTps().size(), "list of TPs should contain 2 updated TPs");
398         assertNull(
399             topoShard.getTps().get(0).augmentation(
400                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
401                         .TerminationPoint1.class)
402                 .getXpdrTpPortConnectionAttributes().getTsPool(),
403             "after ODU4 deletion, its termination points should not contain any TsPool list");
404         assertNull(
405             topoShard.getTps().get(0).augmentation(
406                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
407                         .TerminationPoint1.class)
408                 .getXpdrTpPortConnectionAttributes().getOdtuTpnPool(),
409             "after ODU4 deletion, its termination points should not contain any TpnPool list");
410     }
411
412     @Test
413     void deleteOtnLinksForODU4WhenOTU4HaveBadBWParamsTest() {
414         List<Link> otu4Links = NetworkmodelTestUtil.createSuppOTNLinks(OtnLinkType.OTU4, Uint32.valueOf(0));
415         List<Link> otu4LinksWithBadBWParam = new ArrayList<>();
416         for (Link link : otu4Links) {
417             otu4LinksWithBadBWParam.add(new LinkBuilder(link).removeAugmentation(Link1.class).build());
418         }
419         TopologyShard topoShard = OpenRoadmOtnTopology.deleteOtnLinks(
420                 otu4LinksWithBadBWParam,
421                 NetworkmodelTestUtil.createTpList(true),
422                 OtnLinkType.OTU4);
423         assertNotNull(topoShard, "TopologyShard should never be null");
424         assertNull(topoShard.getNodes(), "list of nodes should be null");
425         assertNull(topoShard.getLinks(), "list of links should be null");
426         assertNull(topoShard.getTps(), "list of tps should be null");
427     }
428
429     @Test
430     void updateOtnLinksFor10GTest() {
431         // tests update for 10G creation
432         TopologyShard topoShard = OpenRoadmOtnTopology.updateOtnLinks(
433                     NetworkmodelTestUtil.createSuppOTNLinks(OtnLinkType.ODTU4, Uint32.valueOf(100000)),
434                     NetworkmodelTestUtil.createTpList(true),
435                     Uint32.valueOf(10), (short)1, (short)1, (short)8, false);
436         assertNotNull(topoShard, "TopologyShard should never be null");
437         assertNull(topoShard.getNodes(), "list of nodes should be null");
438         List<Link> sortedLinks = topoShard.getLinks().stream()
439             .sorted((l1, l2) -> l1.getLinkId().getValue().compareTo(l2.getLinkId().getValue()))
440             .collect(Collectors.toList());
441         assertEquals(2, sortedLinks.size(), "list of links should contain 2 links");
442         assertTrue(sortedLinks.get(0).getLinkId().getValue().startsWith("ODTU4-"));
443         assertEquals(
444             Uint32.valueOf(90000),
445             sortedLinks.get(0).augmentation(Link1.class).getAvailableBandwidth(),
446             "after 10G creation, available BW of supported ODU4 should be 90000");
447         assertEquals(
448             Uint32.valueOf(10000),
449             sortedLinks.get(0).augmentation(Link1.class).getUsedBandwidth(),
450             "after 10G creation, used BW of supported ODU4 should be 10000");
451
452         assertEquals(
453             72,
454             topoShard.getTps().get(0).augmentation(
455                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
456                         .TerminationPoint1.class)
457                 .getXpdrTpPortConnectionAttributes().getTsPool().size(),
458             "after 10G creation, 8 (over 80) trib slot should be occupied");
459         assertThat(
460             "trib slot 1-8 should no longer be present in Trib slot list",
461             topoShard.getTps().get(0).augmentation(
462                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
463                         .TerminationPoint1.class)
464                 .getXpdrTpPortConnectionAttributes().getTsPool(),
465             not(hasItems(Uint16.valueOf(1), Uint16.valueOf(8))));
466         assertThat(
467             "trib slot 9 should always be present in trib slot list",
468             topoShard.getTps().get(0).augmentation(
469                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
470                         .TerminationPoint1.class)
471                 .getXpdrTpPortConnectionAttributes().getTsPool(),
472             hasItem(Uint16.valueOf(9)));
473         assertEquals(
474             79,
475             topoShard.getTps().get(0).augmentation(
476                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
477                         .TerminationPoint1.class)
478                 .getXpdrTpPortConnectionAttributes().getOdtuTpnPool().values().stream().findFirst().get().getTpnPool()
479                 .size(),
480             "after 10G creation, 1 (over 80) trib port should be occupied");
481         assertThat(
482             "trib port 1 should no longer be present",
483             topoShard.getTps().get(0).augmentation(
484                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
485                         .TerminationPoint1.class)
486                 .getXpdrTpPortConnectionAttributes().getOdtuTpnPool().values().stream().findFirst().get().getTpnPool(),
487             not(hasItem(Uint16.valueOf(1))));
488
489         // tests update for 10G deletion
490         sortedLinks.clear();
491         topoShard = OpenRoadmOtnTopology.updateOtnLinks(topoShard.getLinks(), topoShard.getTps(), Uint32.valueOf(10),
492                 (short)1, (short)1, (short)8, true);
493         sortedLinks = topoShard.getLinks().stream()
494             .sorted((l1, l2) -> l1.getLinkId().getValue().compareTo(l2.getLinkId().getValue()))
495             .collect(Collectors.toList());
496         assertEquals(2, sortedLinks.size(), "list of links should contain 2 links");
497         assertTrue(sortedLinks.get(0).getLinkId().getValue().startsWith("ODTU4-"));
498         assertEquals(
499             Uint32.valueOf(100000),
500             sortedLinks.get(0).augmentation(Link1.class).getAvailableBandwidth(),
501             "after 10G deletion, available BW of supported ODU4 should be 100 000");
502         assertEquals(
503             Uint32.valueOf(0),
504             sortedLinks.get(0).augmentation(Link1.class).getUsedBandwidth(),
505             "after 10G deletion, used BW of supported ODU4 should be 0");
506
507         assertEquals(
508             80,
509             topoShard.getTps().get(0).augmentation(
510                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
511                         .TerminationPoint1.class)
512                 .getXpdrTpPortConnectionAttributes().getTsPool().size(),
513             "after 10G deletion, trib slot list should be full");
514         assertThat(
515             "after 10G deletion, trib slot list should contain items 1-8",
516             topoShard.getTps().get(0).augmentation(
517                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
518                         .TerminationPoint1.class)
519                 .getXpdrTpPortConnectionAttributes().getTsPool(),
520             hasItems(Uint16.valueOf(1), Uint16.valueOf(8), Uint16.valueOf(9)));
521         assertEquals(
522                 80,
523                 topoShard.getTps().get(0).augmentation(
524                         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
525                             .TerminationPoint1.class)
526                     .getXpdrTpPortConnectionAttributes().getOdtuTpnPool().values().stream().findFirst().get()
527                     .getTpnPool().size(),
528                 "after 10G deletion, trib port list should be full");
529         assertThat(
530             "after 10G deletion, trib port list should contain items 1",
531             topoShard.getTps().get(0).augmentation(
532                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
533                         .TerminationPoint1.class)
534                 .getXpdrTpPortConnectionAttributes().getOdtuTpnPool().values().stream().findFirst().get().getTpnPool(),
535             hasItem(Uint16.valueOf(1)));
536     }
537
538     @Test
539     void updateOtnLinksFor1GCreationTest() {
540         // tests update for 1G creation
541         TopologyShard topoShard = OpenRoadmOtnTopology.updateOtnLinks(
542                     NetworkmodelTestUtil.createSuppOTNLinks(OtnLinkType.ODTU4, Uint32.valueOf(100000)),
543                     NetworkmodelTestUtil.createTpList(true),
544                     Uint32.valueOf(1), (short)1, (short)1, (short)1, false);
545         assertNotNull(topoShard, "TopologyShard should never be null");
546         assertNull(topoShard.getNodes(), "list of nodes should be null");
547         List<Link> sortedLinks = topoShard.getLinks().stream()
548             .sorted((l1, l2) -> l1.getLinkId().getValue().compareTo(l2.getLinkId().getValue()))
549             .collect(Collectors.toList());
550         assertEquals(2, sortedLinks.size(), "list of links should contain 2 links");
551         assertTrue(sortedLinks.get(0).getLinkId().getValue().startsWith("ODTU4-"));
552         assertEquals(
553             Uint32.valueOf(99000),
554             sortedLinks.get(0).augmentation(Link1.class).getAvailableBandwidth(),
555             "after 1G creation, available BW of supported ODU4 should be 99000");
556         assertEquals(
557             Uint32.valueOf(1000),
558             sortedLinks.get(0).augmentation(Link1.class).getUsedBandwidth(),
559             "after 1G creation, used BW of supported ODU4 should be 1000");
560
561         assertEquals(
562             79,
563             topoShard.getTps().get(0).augmentation(
564                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
565                         .TerminationPoint1.class)
566                 .getXpdrTpPortConnectionAttributes().getTsPool().size(),
567             "after 1G creation, 1 (over 80) trib slot should be occupied");
568         assertThat(
569             "trib slot 1 should no longer be present in Trib slot list",
570             topoShard.getTps().get(0).augmentation(
571                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
572                         .TerminationPoint1.class)
573                 .getXpdrTpPortConnectionAttributes().getTsPool(),
574             not(hasItem(Uint16.valueOf(1))));
575         assertThat(
576             "trib slot 2 should always be present in Trib slot list",
577             topoShard.getTps().get(0).augmentation(
578                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
579                         .TerminationPoint1.class)
580                 .getXpdrTpPortConnectionAttributes().getTsPool(),
581             hasItem(Uint16.valueOf(2)));
582         assertEquals(
583             79,
584             topoShard.getTps().get(0).augmentation(
585                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
586                         .TerminationPoint1.class)
587                 .getXpdrTpPortConnectionAttributes().getOdtuTpnPool().values().stream().findFirst().get().getTpnPool()
588                 .size(),
589             "after 1G creation, 1 (over 80) trib port should be occupied");
590         assertThat(
591             "trib port 1 should no longer be present in Trib port list",
592             topoShard.getTps().get(0).augmentation(
593                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
594                         .TerminationPoint1.class)
595                 .getXpdrTpPortConnectionAttributes().getOdtuTpnPool().values().stream().findFirst().get().getTpnPool(),
596             not(hasItem(Uint16.valueOf(1))));
597
598         // tests update for 1G deletion
599         sortedLinks.clear();
600         topoShard = OpenRoadmOtnTopology.updateOtnLinks(
601                     topoShard.getLinks(),
602                     topoShard.getTps(),
603                     Uint32.valueOf(1), (short)1, (short)1, (short)1, true);
604         sortedLinks = topoShard.getLinks().stream()
605             .sorted((l1, l2) -> l1.getLinkId().getValue().compareTo(l2.getLinkId().getValue()))
606             .collect(Collectors.toList());
607         assertEquals(2, sortedLinks.size(), "list of links should contain 2 links");
608         assertTrue(sortedLinks.get(0).getLinkId().getValue().startsWith("ODTU4-"));
609         assertEquals(
610             Uint32.valueOf(100000),
611             sortedLinks.get(0).augmentation(Link1.class).getAvailableBandwidth(),
612             "after 1G deletion, available BW of supported ODU4 should be 100 000");
613         assertEquals(
614             Uint32.valueOf(0),
615             sortedLinks.get(0).augmentation(Link1.class).getUsedBandwidth(),
616             "after 1G deletion, used BW of supported ODU4 should be 0");
617
618         assertEquals(
619             80,
620             topoShard.getTps().get(0).augmentation(
621                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
622                         .TerminationPoint1.class)
623                 .getXpdrTpPortConnectionAttributes().getTsPool().size(),
624             "after 1G deletion, trib slot list should be full");
625         assertThat(
626             "after 1G deletion, trib slot list should contain items 1 and 2",
627             topoShard.getTps().get(0).augmentation(
628                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
629                         .TerminationPoint1.class)
630                 .getXpdrTpPortConnectionAttributes().getTsPool(),
631             hasItems(Uint16.valueOf(1), Uint16.valueOf(2)));
632         assertEquals(
633             80,
634             topoShard.getTps().get(0).augmentation(
635                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
636                         .TerminationPoint1.class)
637                 .getXpdrTpPortConnectionAttributes().getOdtuTpnPool().values().stream().findFirst().get().getTpnPool()
638                 .size(),
639             "after 1G deletion, trib port list should be full");
640         assertThat(
641             "after 1G deletion, trib port list should contain items 1",
642             topoShard.getTps().get(0).augmentation(
643                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
644                         .TerminationPoint1.class)
645                 .getXpdrTpPortConnectionAttributes().getOdtuTpnPool().values().stream().findFirst().get().getTpnPool(),
646             hasItem(Uint16.valueOf(1)));
647     }
648
649     @Test
650     void updateOtnLinksForODU4WhenBWParamsNotPresentTest() {
651         List<Link> odu4Links = NetworkmodelTestUtil.createSuppOTNLinks(OtnLinkType.ODTU4, Uint32.valueOf(100000));
652         List<Link> odu4LinksWithBadBWParam = new ArrayList<>();
653         for (Link link : odu4Links) {
654             odu4LinksWithBadBWParam.add(new LinkBuilder(link).removeAugmentation(Link1.class).build());
655         }
656         TopologyShard topoShard =
657             OpenRoadmOtnTopology.updateOtnLinks(
658                     odu4LinksWithBadBWParam,
659                     NetworkmodelTestUtil.createTpList(true),
660                     Uint32.valueOf(1), (short)1, (short)1, (short)10, false);
661         assertNotNull(topoShard, "TopologyShard should never be null");
662         assertNull(topoShard.getNodes(), "list of nodes should be null");
663         assertNull(topoShard.getLinks(), "list of links should be null");
664         assertNull(topoShard.getTps(), "list of tps should be null");
665     }
666
667     @Test
668     void updateOtnLinksForODU4WhenAvailBWNotSufficientTest() {
669         List<Link> odu4LinksWithBadBWParam = NetworkmodelTestUtil.createSuppOTNLinks(
670                 OtnLinkType.ODTU4,
671                 Uint32.valueOf(8000));
672         TopologyShard topoShard = OpenRoadmOtnTopology.updateOtnLinks(
673                     odu4LinksWithBadBWParam,
674                     NetworkmodelTestUtil.createTpList(true),
675                     Uint32.valueOf(10), (short)1, (short)1, (short)10, false);
676         assertNotNull(topoShard, "TopologyShard should never be null");
677         assertNull(topoShard.getNodes(), "list of nodes should be null");
678         assertNull(topoShard.getLinks(), "list of links should be null");
679         assertNull(topoShard.getTps(), "list of tps should be null");
680     }
681
682     private void checkSpdrNode(Node node) {
683         Uint16 xpdrNb = node.augmentation(
684                 org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210.Node1.class)
685             .getXpdrAttributes().getXpdrNumber();
686         assertEquals("SPDR-SA1-XPDR" + xpdrNb, node.getNodeId().getValue());
687         if (xpdrNb.equals(Uint16.valueOf(1))) {
688             assertEquals(OpenroadmNodeType.MUXPDR, node.augmentation(Node1.class).getNodeType());
689         } else if (xpdrNb.equals(Uint16.valueOf(2))) {
690             assertEquals(OpenroadmNodeType.SWITCH, node.augmentation(Node1.class).getNodeType());
691         }
692         // tests supporting nodes
693         List<SupportingNode> supportingNodes = node.nonnullSupportingNode().values().stream()
694             .sorted((sn1, sn2) -> sn1.getNetworkRef().getValue().compareTo(sn2.getNetworkRef().getValue()))
695             .collect(Collectors.toList());
696         assertEquals(3, supportingNodes.size(), "Should contain 3 supporting nodes");
697         assertEquals("clli-network", supportingNodes.get(0).getNetworkRef().getValue());
698         assertEquals("NodeSA", supportingNodes.get(0).getNodeRef().getValue());
699         assertEquals("openroadm-network", supportingNodes.get(1).getNetworkRef().getValue());
700         assertEquals("SPDR-SA1", supportingNodes.get(1).getNodeRef().getValue());
701         assertEquals("openroadm-topology", supportingNodes.get(2).getNetworkRef().getValue());
702         assertEquals("SPDR-SA1-XPDR" + xpdrNb, supportingNodes.get(2).getNodeRef().getValue());
703         checkSpdrSwitchingPools(
704             xpdrNb,
705             node.augmentation(
706                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210.Node1.class)
707                 .getSwitchingPools());
708         List<TerminationPoint> tpList = node.augmentation(
709                 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
710             .nonnullTerminationPoint().values().stream()
711             .sorted((tp1, tp2) -> tp1.getTpId().getValue().compareTo(tp2.getTpId().getValue()))
712             .collect(Collectors.toList());
713         checkSpdrTpList(xpdrNb, tpList);
714     }
715
716     private void checkSpdrSwitchingPools(Uint16 xpdrNb, SwitchingPools sp) {
717         List<OduSwitchingPools> oduSwitchingPools = new ArrayList<>(sp.nonnullOduSwitchingPools().values());
718         assertEquals(
719             1,
720             oduSwitchingPools.size(),
721             "switching-pools augmentation should contain a single odu-switching-pools");
722         assertEquals(
723             Uint16.valueOf(1),
724             oduSwitchingPools.get(0).getSwitchingPoolNumber(),
725             "switching-pool-number should be 1");
726         assertEquals(
727             "non-blocking",
728             oduSwitchingPools.get(0).getSwitchingPoolType().getName(),
729             "switching-pool-type should be non-blocking");
730
731         List<NonBlockingList> nonBlockingList =
732                 new ArrayList<>(oduSwitchingPools.get(0).nonnullNonBlockingList().values());
733         if (xpdrNb.equals(Uint16.valueOf(1))) {
734             assertEquals(4, nonBlockingList.size(), "Mux should contain 4 non blocking list");
735             assertEquals(Uint16.valueOf(1), nonBlockingList.get(0).getNblNumber());
736             List<NonBlockingList> nblList = oduSwitchingPools.get(0).nonnullNonBlockingList().values().stream()
737                 .sorted((nbl1, nbl2) -> nbl1.getNblNumber().compareTo(nbl2.getNblNumber()))
738                 .collect(Collectors.toList());
739             for (NonBlockingList nbl : nblList) {
740                 assertEquals(
741                     Uint32.valueOf(10),
742                     nbl.getAvailableInterconnectBandwidth(),
743                     "for a 10G mux, interconnect BW should be 10G");
744                 assertEquals(Uint32.valueOf(1000000000), nbl.getInterconnectBandwidthUnit());
745                 assertThat(
746                     "for a 10G mux, non blocking list should contain 2 entries (client + network ports)",
747                     nbl.getTpList(),
748                     hasSize(2));
749                 String nb = nbl.getNblNumber().toString();
750                 assertThat(
751                     nbl.getTpList(),
752                     containsInAnyOrder(new TpId("XPDR1-NETWORK1"), new TpId("XPDR1-CLIENT" + nb)));
753             }
754         } else if (xpdrNb.equals(Uint16.valueOf(2))) {
755             assertEquals(1, nonBlockingList.size(), "Switch should contain a single non blocking list");
756             assertEquals(Uint16.valueOf(1), nonBlockingList.get(0).getNblNumber());
757             assertThat(
758                 "for a 100G Switch, non blocking list should contain 8 entries (4 clients + 4 network ports)",
759                 nonBlockingList.get(0).getTpList(),
760                 hasSize(8));
761             assertThat(
762                 nonBlockingList.get(0).getTpList(),
763                 containsInAnyOrder(
764                     new TpId("XPDR2-CLIENT1"), new TpId("XPDR2-NETWORK1"), new TpId("XPDR2-CLIENT2"),
765                     new TpId("XPDR2-NETWORK2"), new TpId("XPDR2-CLIENT3"), new TpId("XPDR2-NETWORK3"),
766                     new TpId("XPDR2-CLIENT4"), new TpId("XPDR2-NETWORK4")));
767         }
768     }
769
770     private void checkSpdrTpList(Uint16 xpdrNb, List<TerminationPoint> tpList) {
771         LOG.info("tpList = {}", tpList);
772         assertEquals(
773             IfOCHOTU4ODU4.VALUE,
774             tpList.get(4).augmentation(
775                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
776                         .TerminationPoint1.class)
777                 .getTpSupportedInterfaces().getSupportedInterfaceCapability().values().stream().findFirst().get()
778                 .getIfCapType(),
779             "only IfOCHOTU4ODU4 interface capabitily expected");
780         assertEquals(
781             ODU4.VALUE,
782             tpList.get(4).augmentation(
783                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
784                         .TerminationPoint1.class)
785                 .getXpdrTpPortConnectionAttributes().getRate(),
786             "the rate should be ODU4");
787         assertEquals(
788             "openroadm-topology",
789             tpList.get(4).getSupportingTerminationPoint().values().stream().findFirst().get().getNetworkRef()
790                 .getValue());
791         assertEquals(
792             "SPDR-SA1-XPDR" + xpdrNb,
793             tpList.get(4).getSupportingTerminationPoint().values().stream().findFirst().get().getNodeRef().getValue());
794         assertEquals(
795             "XPDR" + xpdrNb + "-NETWORK1",
796             tpList.get(4).getSupportingTerminationPoint().values().stream().findFirst().get().getTpRef().getValue());
797         if (xpdrNb.equals(Uint16.valueOf(1))) {
798             assertEquals(5, tpList.size(), "should contain 5 TPs");
799             assertEquals("XPDR1-CLIENT1", tpList.get(0).getTpId().getValue());
800             assertEquals("XPDR1-CLIENT2", tpList.get(1).getTpId().getValue());
801             assertEquals("XPDR1-NETWORK1", tpList.get(4).getTpId().getValue());
802             assertEquals(
803                 2,
804                 tpList.get(1).augmentation(
805                         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
806                             .TerminationPoint1.class)
807                     .getTpSupportedInterfaces().getSupportedInterfaceCapability().values().size(),
808                 "supported interface capability of tp-id XPDR1-CLIENT2 should contain 2 if-cap-type");
809             assertEquals(
810                 3,
811                 tpList.get(2).augmentation(
812                         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
813                             .TerminationPoint1.class)
814                     .getTpSupportedInterfaces().getSupportedInterfaceCapability().values().size(),
815                 "supported interface capability of tp-id XPDR1-CLIENT3 should contain 3 if-cap-type");
816             List<SupportedInterfaceCapability> sicListClient1 = tpList.get(0).augmentation(
817                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
818                         .TerminationPoint1.class)
819                 .getTpSupportedInterfaces().getSupportedInterfaceCapability().values().stream()
820                 .collect(Collectors.toList());
821             for (SupportedInterfaceCapability supportedInterfaceCapability : sicListClient1) {
822                 assertThat("tp should have 2 if-cap-type: if-10GE-ODU2e, if-10GE-ODU2",
823                     String.valueOf(supportedInterfaceCapability.getIfCapType()),
824                     either(containsString(String.valueOf(If10GEODU2e.VALUE)))
825                         .or(containsString(String.valueOf(If10GEODU2.VALUE))));
826             }
827             List<SupportedInterfaceCapability> sicListClient3 = tpList.get(3).augmentation(
828                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
829                         .TerminationPoint1.class)
830                 .getTpSupportedInterfaces().getSupportedInterfaceCapability().values().stream()
831                 .collect(Collectors.toList());
832             for (SupportedInterfaceCapability supportedInterfaceCapability : sicListClient3) {
833                 assertThat("tp should have 3 if-cap-type: if-10GE-ODU2e, if-10GE-ODU2, if-10GE",
834                     String.valueOf(supportedInterfaceCapability.getIfCapType()),
835                     either(containsString(String.valueOf(If10GEODU2e.VALUE)))
836                         .or(containsString(String.valueOf(If10GEODU2.VALUE)))
837                         .or(containsString(String.valueOf(If10GE.VALUE))));
838             }
839             assertThat("the rate should be ODU2 or ODU2e",
840                 String.valueOf(tpList.get(2).augmentation(
841                         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
842                             .TerminationPoint1.class)
843                     .getXpdrTpPortConnectionAttributes().getRate()),
844                 either(containsString(String.valueOf(ODU2e.VALUE)))
845                     .or(containsString(String.valueOf(ODU2.VALUE))));
846             assertEquals(
847                 OpenroadmTpType.XPONDERCLIENT,
848                 tpList.get(2).augmentation(TerminationPoint1.class).getTpType(),
849                 "TP should be of type client");
850             assertEquals(
851                 OpenroadmTpType.XPONDERNETWORK,
852                 tpList.get(4).augmentation(TerminationPoint1.class).getTpType(),
853                 "TP should be of type network");
854         } else if (xpdrNb.equals(Uint16.valueOf(2))) {
855             assertEquals(8, tpList.size(), "should contain 8 TPs");
856             assertEquals("XPDR2-CLIENT1", tpList.get(0).getTpId().getValue());
857             assertEquals("XPDR2-CLIENT2", tpList.get(1).getTpId().getValue());
858             assertEquals("XPDR2-NETWORK1", tpList.get(4).getTpId().getValue());
859             assertEquals("XPDR2-NETWORK2", tpList.get(5).getTpId().getValue());
860             assertEquals(
861                 IfOCHOTU4ODU4.VALUE,
862                 tpList.get(5).augmentation(
863                         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
864                             .TerminationPoint1.class)
865                     .getTpSupportedInterfaces().getSupportedInterfaceCapability().values().stream().findFirst().get()
866                     .getIfCapType(),
867                 "only IfOCHOTU4ODU4 interface capabitily expected");
868             assertEquals(
869                 2,
870                 tpList.get(2).augmentation(
871                         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
872                             .TerminationPoint1.class)
873                     .getTpSupportedInterfaces().getSupportedInterfaceCapability().values().size(),
874                 "supported interface capability of tp should contain 2 IfCapType");
875             List<SupportedInterfaceCapability> sicListClient3 = tpList.get(2).augmentation(
876                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev211210
877                         .TerminationPoint1.class)
878                 .getTpSupportedInterfaces().getSupportedInterfaceCapability().values().stream()
879                 .collect(Collectors.toList());
880             for (SupportedInterfaceCapability supportedInterfaceCapability : sicListClient3) {
881                 assertThat(
882                     "tp should have 2 if-cap-type: if-100GE-ODU4, if-100GE",
883                     String.valueOf(supportedInterfaceCapability.getIfCapType()),
884                     either(containsString(String.valueOf(If100GEODU4.VALUE)))
885                         .or(containsString(String.valueOf(If100GE.VALUE))));
886             }
887             assertEquals(
888                 OpenroadmTpType.XPONDERCLIENT,
889                 tpList.get(2).augmentation(TerminationPoint1.class).getTpType(),
890                 "TP should be of type client");
891             assertEquals(
892                 OpenroadmTpType.XPONDERNETWORK,
893                 tpList.get(6).augmentation(TerminationPoint1.class).getTpType(),
894                 "TP should be of type network");
895         }
896     }
897 }