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