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