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