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