Update portmapping YANG model
[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.rev210315.Network;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.mapping.Mapping;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.mapping.MappingBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.mapping.MappingKey;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.network.Nodes;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.network.NodesBuilder;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.network.nodes.NodeInfoBuilder;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.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.rev200327.xpdr.odu.switching.pools.OduSwitchingPools;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.types.rev200327.xpdr.odu.switching.pools.odu.switching.pools.NonBlockingList;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmLinkType;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmTpType;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.xpdr.tp.supported.interfaces.SupportedInterfaceCapability;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODU2;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODU2e;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.ODU4;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.Link1;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.networks.network.node.SwitchingPools;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If100GE;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If100GEODU4;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If10GE;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If10GEODU2;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.If10GEODU2e;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.IfOCH;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.types.rev200327.IfOCHOTU4ODU4;
65 import org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.OtnLinkType;
66 import org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.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", "2021-03-15", "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.rev200529.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.rev200529
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.rev200529
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.rev200529
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.rev200529
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.rev200529
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.rev200529
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.rev200529.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.rev200529.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.rev200529.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.rev201019.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, 100000),
299                 NetworkmodelTestUtil.createTpList(false));
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             "ODU4-SPDRA-XPDR1-XPDR1-NETWORK1toSPDRZ-XPDR1-XPDR1-NETWORK1",
318             sortedLinks.get(0).getLinkId().getValue());
319         assertEquals(
320             "ODU4-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.rev200529.Link1.class)
339                 .getLinkType());
340         assertEquals(
341             "opposite link must be present",
342             "ODU4-SPDRZ-XPDR1-XPDR1-NETWORK1toSPDRA-XPDR1-XPDR1-NETWORK1",
343             sortedLinks.get(0)
344                 .augmentation(
345                     org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.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.rev201019.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.rev200529
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.rev200529
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.rev200529
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.rev200529
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, 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         assertNotNull("TopologyShard should never be null", topoShard);
409         assertNull("list of nodes should be null", topoShard.getNodes());
410         assertNull("list of links should be null", topoShard.getLinks());
411         assertNull("list of tps should be null", topoShard.getTps());
412
413         otu4LinksWithBadBWParam.clear();
414         topoShard =
415             OpenRoadmOtnTopology.createOtnLinks(
416                     NetworkmodelTestUtil.createSuppOTNLinks(OtnLinkType.OTU4, 99000),
417                     NetworkmodelTestUtil.createTpList(false));
418         assertNull("list of nodes should be null", topoShard.getNodes());
419         assertNull("list of links should be null", topoShard.getLinks());
420         assertNull("list of tps should be null", topoShard.getTps());
421     }
422
423     @Test
424     public void deleteOtnLinksForODU4NormalTest() {
425         TopologyShard topoShard =
426             OpenRoadmOtnTopology.deleteOtnLinks(
427                     NetworkmodelTestUtil.createSuppOTNLinks(OtnLinkType.OTU4, 0),
428                     NetworkmodelTestUtil.createTpList(true));
429         assertNotNull("TopologyShard should never be null", topoShard);
430         assertEquals("list of links should contain 2 links", 2, topoShard.getLinks().size());
431         assertEquals(
432             "after ODU4 deletion, available BW of supported OTU4 should be 100 000",
433             Uint32.valueOf(100000),
434             topoShard.getLinks().get(0).augmentation(Link1.class).getAvailableBandwidth());
435         assertEquals(
436             "after ODU4 deletion, used BW of supported OTU4 should be 0",
437             Uint32.valueOf(0),
438             topoShard.getLinks().get(0).augmentation(Link1.class).getUsedBandwidth());
439
440         assertEquals("list of TPs should contain 2 updated TPs", 2, topoShard.getTps().size());
441         assertNull(
442             "after ODU4 deletion, its termination points should not contain any TsPool list",
443             topoShard.getTps().get(0)
444                 .augmentation(
445                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
446                         .TerminationPoint1.class)
447                 .getXpdrTpPortConnectionAttributes()
448                 .getTsPool());
449         assertNull(
450             "after ODU4 deletion, its termination points should not contain any TpnPool list",
451             topoShard.getTps().get(0)
452                 .augmentation(
453                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
454                         .TerminationPoint1.class)
455                 .getXpdrTpPortConnectionAttributes()
456                 .getOdtuTpnPool());
457     }
458
459     @Test
460     public void deleteOtnLinksForODU4WhenOTU4HaveBadBWParamsTest() {
461         List<Link> otu4Links = NetworkmodelTestUtil.createSuppOTNLinks(OtnLinkType.OTU4, 0);
462         List<Link> otu4LinksWithBadBWParam = new ArrayList<>();
463         for (Link link : otu4Links) {
464             otu4LinksWithBadBWParam.add(new LinkBuilder(link).removeAugmentation(Link1.class).build());
465         }
466         TopologyShard topoShard =
467             OpenRoadmOtnTopology.deleteOtnLinks(otu4LinksWithBadBWParam, NetworkmodelTestUtil.createTpList(true));
468         assertNotNull("TopologyShard should never be null", topoShard);
469         assertNull("list of nodes should be null", topoShard.getNodes());
470         assertNull("list of links should be null", topoShard.getLinks());
471         assertNull("list of tps should be null", topoShard.getTps());
472     }
473
474     @Test
475     public void updateOtnLinksFor10GTest() {
476         // tests update for 10G creation
477         TopologyShard topoShard =
478             OpenRoadmOtnTopology.updateOtnLinks(
479                     NetworkmodelTestUtil.createSuppOTNLinks(OtnLinkType.ODTU4, 100000),
480                     NetworkmodelTestUtil.createTpList(true),
481                     "10G", (short)1, (short)1, false);
482         assertNotNull("TopologyShard should never be null", topoShard);
483         assertNull("list of nodes should be null", topoShard.getNodes());
484         List<Link> sortedLinks = topoShard.getLinks().stream()
485             .sorted((l1, l2) -> l1.getLinkId().getValue().compareTo(l2.getLinkId().getValue()))
486             .collect(Collectors.toList());
487         assertEquals("list of links should contain 2 links", 2, sortedLinks.size());
488         assertTrue(sortedLinks.get(0).getLinkId().getValue().startsWith("ODU4-"));
489         assertEquals(
490             "after 10G creation, available BW of supported ODU4 should be 90000",
491             Uint32.valueOf(90000),
492             sortedLinks.get(0).augmentation(Link1.class).getAvailableBandwidth());
493         assertEquals(
494             "after 10G creation, used BW of supported ODU4 should be 10000",
495             Uint32.valueOf(10000),
496             sortedLinks.get(0).augmentation(Link1.class).getUsedBandwidth());
497
498         assertEquals(
499             "after 10G creation, 8 (over 80) trib slot should be occupied",
500             72,
501             topoShard.getTps().get(0)
502                 .augmentation(
503                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
504                         .TerminationPoint1.class)
505                 .getXpdrTpPortConnectionAttributes()
506                 .getTsPool()
507                 .size());
508         assertThat(
509             "trib slot 1-8 should no longer be present in Trib slot list",
510             topoShard.getTps().get(0)
511                 .augmentation(
512                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
513                         .TerminationPoint1.class)
514                 .getXpdrTpPortConnectionAttributes()
515                 .getTsPool(),
516             not(hasItems(Uint16.valueOf(1), Uint16.valueOf(8))));
517         assertThat(
518             "trib slot 9 should always be present in trib slot list",
519             topoShard.getTps().get(0)
520                 .augmentation(
521                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
522                         .TerminationPoint1.class)
523                 .getXpdrTpPortConnectionAttributes()
524                 .getTsPool(),
525             hasItem(Uint16.valueOf(9)));
526         assertEquals(
527             "after 10G creation, 1 (over 80) trib port should be occupied",
528             79,
529             topoShard.getTps().get(0)
530                 .augmentation(
531                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
532                         .TerminationPoint1.class)
533                 .getXpdrTpPortConnectionAttributes()
534                 .getOdtuTpnPool().values().stream().findFirst()
535                 .get()
536                 .getTpnPool()
537                 .size());
538         assertThat(
539             "trib port 1 should no longer be present",
540             topoShard.getTps().get(0)
541                 .augmentation(
542                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
543                         .TerminationPoint1.class)
544                 .getXpdrTpPortConnectionAttributes()
545                 .getOdtuTpnPool().values().stream().findFirst()
546                 .get()
547                 .getTpnPool(),
548             not(hasItem(Uint16.valueOf(1))));
549
550         // tests update for 10G deletion
551         sortedLinks.clear();
552         topoShard = OpenRoadmOtnTopology.updateOtnLinks(topoShard.getLinks(), topoShard.getTps(), "10G", (short)1,
553             (short)1, true);
554         sortedLinks = topoShard.getLinks().stream()
555             .sorted((l1, l2) -> l1.getLinkId().getValue().compareTo(l2.getLinkId().getValue()))
556             .collect(Collectors.toList());
557         assertEquals("list of links should contain 2 links", 2, sortedLinks.size());
558         assertTrue(sortedLinks.get(0).getLinkId().getValue().startsWith("ODU4-"));
559         assertEquals(
560             "after 10G deletion, available BW of supported ODU4 should be 100 000",
561             Uint32.valueOf(100000),
562             sortedLinks.get(0).augmentation(Link1.class).getAvailableBandwidth());
563         assertEquals(
564             "after 10G deletion, used BW of supported ODU4 should be 0",
565             Uint32.valueOf(0),
566             sortedLinks.get(0).augmentation(Link1.class).getUsedBandwidth());
567
568         assertEquals(
569             "after 10G deletion, trib slot list should be full",
570             80,
571             topoShard.getTps().get(0)
572                 .augmentation(
573                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
574                         .TerminationPoint1.class)
575                 .getXpdrTpPortConnectionAttributes()
576                 .getTsPool()
577                 .size());
578         assertThat(
579             "after 10G deletion, trib slot list should contain items 1-8",
580             topoShard.getTps().get(0)
581                 .augmentation(
582                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
583                         .TerminationPoint1.class)
584                 .getXpdrTpPortConnectionAttributes()
585                 .getTsPool(),
586             hasItems(Uint16.valueOf(1), Uint16.valueOf(8), Uint16.valueOf(9)));
587         assertEquals(
588             "after 10G deletion, trib port list should be full",
589                 80,
590                 topoShard.getTps().get(0)
591                     .augmentation(
592                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
593                         .TerminationPoint1.class)
594                     .getXpdrTpPortConnectionAttributes()
595                     .getOdtuTpnPool().values().stream().findFirst()
596                     .get()
597                     .getTpnPool()
598                     .size());
599         assertThat(
600             "after 10G deletion, trib port list should contain items 1",
601             topoShard.getTps().get(0)
602                 .augmentation(
603                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
604                         .TerminationPoint1.class)
605                 .getXpdrTpPortConnectionAttributes()
606                 .getOdtuTpnPool().values().stream().findFirst()
607                 .get()
608                 .getTpnPool(),
609             hasItem(Uint16.valueOf(1)));
610     }
611
612     @Test
613     public void updateOtnLinksFor1GCreationTest() {
614         // tests update for 1G creation
615         TopologyShard topoShard =
616             OpenRoadmOtnTopology.updateOtnLinks(
617                     NetworkmodelTestUtil.createSuppOTNLinks(OtnLinkType.ODTU4, 100000),
618                     NetworkmodelTestUtil.createTpList(true),
619                     "1G", (short)1, (short)1, false);
620         assertNotNull("TopologyShard should never be null", topoShard);
621         assertNull("list of nodes should be null", topoShard.getNodes());
622         List<Link> sortedLinks = topoShard.getLinks().stream()
623             .sorted((l1, l2) -> l1.getLinkId().getValue().compareTo(l2.getLinkId().getValue()))
624             .collect(Collectors.toList());
625         assertEquals("list of links should contain 2 links", 2, sortedLinks.size());
626         assertTrue(sortedLinks.get(0).getLinkId().getValue().startsWith("ODU4-"));
627         assertEquals(
628             "after 1G creation, available BW of supported ODU4 should be 99000",
629             Uint32.valueOf(99000),
630             sortedLinks.get(0).augmentation(Link1.class).getAvailableBandwidth());
631         assertEquals(
632             "after 1G creation, used BW of supported ODU4 should be 1000",
633             Uint32.valueOf(1000),
634             sortedLinks.get(0).augmentation(Link1.class).getUsedBandwidth());
635
636         assertEquals(
637             "after 1G creation, 1 (over 80) trib slot should be occupied",
638             79,
639             topoShard.getTps().get(0)
640                 .augmentation(
641                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
642                         .TerminationPoint1.class)
643                 .getXpdrTpPortConnectionAttributes()
644                 .getTsPool()
645                 .size());
646         assertThat(
647             "trib slot 1 should no longer be present in Trib slot list",
648             topoShard.getTps().get(0)
649                 .augmentation(
650                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
651                         .TerminationPoint1.class)
652                 .getXpdrTpPortConnectionAttributes()
653                 .getTsPool(),
654             not(hasItem(Uint16.valueOf(1))));
655         assertThat(
656             "trib slot 2 should always be present in Trib slot list",
657             topoShard.getTps().get(0)
658                 .augmentation(
659                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
660                         .TerminationPoint1.class)
661                 .getXpdrTpPortConnectionAttributes().getTsPool(),
662             hasItem(Uint16.valueOf(2)));
663         assertEquals(
664             "after 1G creation, 1 (over 80) trib port should be occupied",
665             79,
666             topoShard.getTps().get(0)
667                 .augmentation(
668                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
669                         .TerminationPoint1.class)
670                 .getXpdrTpPortConnectionAttributes()
671                 .getOdtuTpnPool().values().stream().findFirst()
672                 .get()
673                 .getTpnPool()
674                 .size());
675         assertThat(
676             "trib port 1 should no longer be present in Trib port list",
677             topoShard.getTps().get(0)
678                 .augmentation(
679                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
680                         .TerminationPoint1.class)
681                 .getXpdrTpPortConnectionAttributes()
682                 .getOdtuTpnPool().values().stream().findFirst()
683                 .get()
684                 .getTpnPool(),
685             not(hasItem(Uint16.valueOf(1))));
686
687         // tests update for 1G deletion
688         sortedLinks.clear();
689         topoShard =
690             OpenRoadmOtnTopology.updateOtnLinks(
691                     topoShard.getLinks(),
692                     topoShard.getTps(),
693                     "1G", (short)1, (short)1, true);
694         sortedLinks = topoShard.getLinks().stream()
695             .sorted((l1, l2) -> l1.getLinkId().getValue().compareTo(l2.getLinkId().getValue()))
696             .collect(Collectors.toList());
697         assertEquals("list of links should contain 2 links", 2, sortedLinks.size());
698         assertTrue(sortedLinks.get(0).getLinkId().getValue().startsWith("ODU4-"));
699         assertEquals(
700             "after 1G deletion, available BW of supported ODU4 should be 100 000",
701             Uint32.valueOf(100000),
702             sortedLinks.get(0).augmentation(Link1.class).getAvailableBandwidth());
703         assertEquals(
704             "after 1G deletion, used BW of supported ODU4 should be 0",
705             Uint32.valueOf(0),
706             sortedLinks.get(0).augmentation(Link1.class).getUsedBandwidth());
707
708         assertEquals(
709             "after 1G deletion, trib slot list should be full",
710             80,
711             topoShard.getTps().get(0)
712                 .augmentation(
713                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
714                         .TerminationPoint1.class)
715                 .getXpdrTpPortConnectionAttributes()
716                 .getTsPool()
717                 .size());
718         assertThat(
719             "after 1G deletion, trib slot list should contain items 1 and 2",
720             topoShard.getTps().get(0)
721                 .augmentation(
722                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
723                     .TerminationPoint1.class)
724                 .getXpdrTpPortConnectionAttributes()
725                 .getTsPool(),
726             hasItems(Uint16.valueOf(1), Uint16.valueOf(2)));
727         assertEquals(
728             "after 1G deletion, trib port list should be full",
729             80,
730             topoShard.getTps().get(0)
731                 .augmentation(
732                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
733                         .TerminationPoint1.class)
734                 .getXpdrTpPortConnectionAttributes()
735                 .getOdtuTpnPool().values().stream().findFirst()
736                 .get()
737                 .getTpnPool()
738                 .size());
739         assertThat(
740             "after 1G deletion, trib port list should contain items 1",
741             topoShard.getTps().get(0)
742                 .augmentation(
743                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
744                         .TerminationPoint1.class)
745                 .getXpdrTpPortConnectionAttributes()
746                 .getOdtuTpnPool().values().stream().findFirst()
747                 .get()
748                 .getTpnPool(),
749             hasItem(Uint16.valueOf(1)));
750     }
751
752     @Test
753     public void updateOtnLinksForODU4WhenBWParamsNotPresentTest() {
754         List<Link> odu4Links = NetworkmodelTestUtil.createSuppOTNLinks(OtnLinkType.ODTU4, 100000);
755         List<Link> odu4LinksWithBadBWParam = new ArrayList<>();
756         for (Link link : odu4Links) {
757             odu4LinksWithBadBWParam.add(new LinkBuilder(link).removeAugmentation(Link1.class).build());
758         }
759         TopologyShard topoShard =
760             OpenRoadmOtnTopology.updateOtnLinks(
761                     odu4LinksWithBadBWParam,
762                     NetworkmodelTestUtil.createTpList(true),
763                     "1G", (short)1, (short)1, false);
764         assertNotNull("TopologyShard should never be null", topoShard);
765         assertNull("list of nodes should be null", topoShard.getNodes());
766         assertNull("list of links should be null", topoShard.getLinks());
767         assertNull("list of tps should be null", topoShard.getTps());
768     }
769
770     @Test
771     public void updateOtnLinksForODU4WhenAvailBWNotSufficientTest() {
772         List<Link> odu4LinksWithBadBWParam = NetworkmodelTestUtil.createSuppOTNLinks(OtnLinkType.ODTU4, 8000);
773         TopologyShard topoShard =
774             OpenRoadmOtnTopology.updateOtnLinks(
775                     odu4LinksWithBadBWParam,
776                     NetworkmodelTestUtil.createTpList(true),
777                     "10G", (short)1, (short)1, false);
778         assertNotNull("TopologyShard should never be null", topoShard);
779         assertNull("list of nodes should be null", topoShard.getNodes());
780         assertNull("list of links should be null", topoShard.getLinks());
781         assertNull("list of tps should be null", topoShard.getTps());
782     }
783
784     private void checkSpdrNode(Node node) {
785         Uint16 xpdrNb = node
786             .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.Node1.class)
787             .getXpdrAttributes().getXpdrNumber();
788         assertEquals("SPDR-SA1-XPDR" + xpdrNb, node.getNodeId().getValue());
789         if (xpdrNb.equals(Uint16.valueOf(1))) {
790             assertEquals(OpenroadmNodeType.MUXPDR, node.augmentation(Node1.class).getNodeType());
791         } else if (xpdrNb.equals(Uint16.valueOf(2))) {
792             assertEquals(OpenroadmNodeType.SWITCH, node.augmentation(Node1.class).getNodeType());
793         }
794         // tests supporting nodes
795         List<SupportingNode> supportingNodes = node.nonnullSupportingNode().values().stream()
796             .sorted((sn1, sn2) -> sn1.getNetworkRef().getValue().compareTo(sn2.getNetworkRef().getValue()))
797             .collect(Collectors.toList());
798         assertEquals("Should contain 3 supporting nodes", 3, supportingNodes.size());
799         assertEquals("clli-network", supportingNodes.get(0).getNetworkRef().getValue());
800         assertEquals("NodeSA", supportingNodes.get(0).getNodeRef().getValue());
801         assertEquals("openroadm-network", supportingNodes.get(1).getNetworkRef().getValue());
802         assertEquals("SPDR-SA1", supportingNodes.get(1).getNodeRef().getValue());
803         assertEquals("openroadm-topology", supportingNodes.get(2).getNetworkRef().getValue());
804         assertEquals("SPDR-SA1-XPDR" + xpdrNb, supportingNodes.get(2).getNodeRef().getValue());
805         checkSpdrSwitchingPools(
806             xpdrNb,
807             node.augmentation(
808                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529.Node1.class)
809                 .getSwitchingPools());
810         List<TerminationPoint> tpList = node.augmentation(
811                 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1.class)
812             .nonnullTerminationPoint().values().stream()
813             .sorted((tp1, tp2) -> tp1.getTpId().getValue().compareTo(tp2.getTpId().getValue()))
814             .collect(Collectors.toList());
815         checkSpdrTpList(xpdrNb, tpList);
816     }
817
818     private void checkSpdrSwitchingPools(Uint16 xpdrNb, SwitchingPools sp) {
819         List<OduSwitchingPools> oduSwitchingPools = new ArrayList<>(sp.nonnullOduSwitchingPools().values());
820         assertEquals(
821             "switching-pools augmentation should contain a single odu-switching-pools",
822             1,
823             oduSwitchingPools.size());
824         assertEquals(
825             "switching-pool-number should be 1",
826             Uint16.valueOf(1),
827             oduSwitchingPools.get(0).getSwitchingPoolNumber());
828         assertEquals(
829             "switching-pool-type should be non-blocking",
830             "non-blocking",
831             oduSwitchingPools.get(0).getSwitchingPoolType().getName());
832
833         List<NonBlockingList> nonBlockingList =
834                 new ArrayList<>(oduSwitchingPools.get(0).nonnullNonBlockingList().values());
835         if (xpdrNb.equals(Uint16.valueOf(1))) {
836             assertEquals(
837                 "Mux should contain 4 non blocking list",
838                 4,
839                 nonBlockingList.size());
840             assertEquals(
841                 Uint16.valueOf(1),
842                 nonBlockingList.get(0).getNblNumber());
843             List<NonBlockingList> nblList = oduSwitchingPools.get(0).nonnullNonBlockingList().values().stream()
844                 .sorted((nbl1, nbl2) -> nbl1.getNblNumber().compareTo(nbl2.getNblNumber()))
845                 .collect(Collectors.toList());
846             for (NonBlockingList nbl : nblList) {
847                 assertEquals(
848                     "for a 10G mux, interconnect BW should be 10G",
849                     Uint32.valueOf(10),
850                     nbl.getAvailableInterconnectBandwidth());
851                 assertEquals(Uint32.valueOf(1000000000), nbl.getInterconnectBandwidthUnit());
852                 assertThat(
853                     "for a 10G mux, non blocking list should contain 2 entries (client + network ports)",
854                     nbl.getTpList(),
855                     hasSize(2));
856                 String nb = nbl.getNblNumber().toString();
857                 assertThat(
858                     nbl.getTpList(),
859                     containsInAnyOrder(new TpId("XPDR1-NETWORK1"),
860                         new TpId("XPDR1-CLIENT" + nb)));
861             }
862         } else if (xpdrNb.equals(Uint16.valueOf(2))) {
863             assertEquals(
864                 "Switch should contain a single non blocking list",
865                 1,
866                 nonBlockingList.size());
867             assertEquals(
868                 Uint16.valueOf(1),
869                 nonBlockingList.get(0).getNblNumber());
870             assertThat(
871                 "for a 100G Switch, non blocking list should contain 8 entries (4 clients + 4 network ports)",
872                 nonBlockingList.get(0).getTpList(),
873                 hasSize(8));
874             assertThat(
875                 nonBlockingList.get(0).getTpList(),
876                 containsInAnyOrder(
877                     new TpId("XPDR2-CLIENT1"), new TpId("XPDR2-NETWORK1"), new TpId("XPDR2-CLIENT2"),
878                     new TpId("XPDR2-NETWORK2"), new TpId("XPDR2-CLIENT3"), new TpId("XPDR2-NETWORK3"),
879                     new TpId("XPDR2-CLIENT4"), new TpId("XPDR2-NETWORK4")));
880         }
881     }
882
883     private void checkSpdrTpList(Uint16 xpdrNb, List<TerminationPoint> tpList) {
884         LOG.info("tpList = {}", tpList);
885         assertEquals(
886             "only IfOCHOTU4ODU4 interface capabitily expected",
887             IfOCHOTU4ODU4.class,
888             tpList.get(4)
889                 .augmentation(
890                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
891                         .TerminationPoint1.class)
892                 .getTpSupportedInterfaces()
893                 .getSupportedInterfaceCapability().values().stream().findFirst()
894                 .get()
895                 .getIfCapType());
896         assertEquals(
897             "the rate should be ODU4",
898             ODU4.class,
899             tpList.get(4)
900                 .augmentation(
901                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
902                         .TerminationPoint1.class)
903                 .getXpdrTpPortConnectionAttributes()
904                 .getRate());
905         assertEquals(
906             "openroadm-topology",
907             tpList.get(4).getSupportingTerminationPoint().values().stream().findFirst()
908             .get().getNetworkRef().getValue());
909         assertEquals(
910             "SPDR-SA1-XPDR" + xpdrNb,
911             tpList.get(4).getSupportingTerminationPoint().values().stream().findFirst()
912             .get().getNodeRef().getValue());
913         assertEquals(
914             "XPDR" + xpdrNb + "-NETWORK1",
915             tpList.get(4).getSupportingTerminationPoint().values().stream().findFirst()
916             .get().getTpRef().toString());
917         if (xpdrNb.equals(Uint16.valueOf(1))) {
918             assertEquals("should contain 5 TPs", 5, tpList.size());
919             assertEquals("XPDR1-CLIENT1", tpList.get(0).getTpId().getValue());
920             assertEquals("XPDR1-CLIENT2", tpList.get(1).getTpId().getValue());
921             assertEquals("XPDR1-NETWORK1", tpList.get(4).getTpId().getValue());
922             assertEquals(
923                 "supported interface capability of tp-id XPDR1-CLIENT2 should contain 2 if-cap-type",
924                 2,
925                 tpList.get(1)
926                     .augmentation(
927                         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
928                             .TerminationPoint1.class)
929                     .getTpSupportedInterfaces()
930                     .getSupportedInterfaceCapability().values().size());
931             assertEquals(
932                 "supported interface capability of tp-id XPDR1-CLIENT3 should contain 3 if-cap-type",
933                 3,
934                 tpList.get(2)
935                     .augmentation(
936                         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
937                             .TerminationPoint1.class)
938                     .getTpSupportedInterfaces()
939                     .getSupportedInterfaceCapability().values().size());
940             List<SupportedInterfaceCapability> sicListClient1 = tpList.get(0)
941                 .augmentation(
942                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
943                     .TerminationPoint1.class)
944                 .getTpSupportedInterfaces()
945                 .getSupportedInterfaceCapability().values().stream().collect(Collectors.toList());
946             for (SupportedInterfaceCapability supportedInterfaceCapability : sicListClient1) {
947                 assertThat("tp should have 2 if-cap-type: if-10GE-ODU2e, if-10GE-ODU2",
948                     String.valueOf(supportedInterfaceCapability.getIfCapType()),
949                     either(containsString(String.valueOf(If10GEODU2e.class)))
950                     .or(containsString(String.valueOf(If10GEODU2.class))));
951             }
952             List<SupportedInterfaceCapability> sicListClient3 = tpList.get(3)
953                 .augmentation(
954                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
955                     .TerminationPoint1.class)
956                 .getTpSupportedInterfaces()
957                 .getSupportedInterfaceCapability().values().stream().collect(Collectors.toList());
958             for (SupportedInterfaceCapability supportedInterfaceCapability : sicListClient3) {
959                 assertThat("tp should have 3 if-cap-type: if-10GE-ODU2e, if-10GE-ODU2, if-10GE",
960                     String.valueOf(supportedInterfaceCapability.getIfCapType()),
961                     either(containsString(String.valueOf(If10GEODU2e.class)))
962                     .or(containsString(String.valueOf(If10GEODU2.class)))
963                     .or(containsString(String.valueOf(If10GE.class))));
964             }
965             assertThat("the rate should be ODU2 or ODU2e or 10GE",
966                 String.valueOf(tpList.get(2)
967                     .augmentation(
968                         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
969                             .TerminationPoint1.class)
970                     .getXpdrTpPortConnectionAttributes()
971                     .getRate()),
972                 either(containsString(String.valueOf(ODU2e.class)))
973                 .or(containsString(String.valueOf(ODU2.class))));
974             assertEquals(
975                 "TP should be of type client",
976                 OpenroadmTpType.XPONDERCLIENT,
977                 tpList.get(2)
978                     .augmentation(
979                         org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529
980                             .TerminationPoint1.class)
981                     .getTpType());
982             assertEquals(
983                 "TP should be of type network",
984                 OpenroadmTpType.XPONDERNETWORK,
985                 tpList.get(4)
986                     .augmentation(
987                         org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529
988                             .TerminationPoint1.class)
989                     .getTpType());
990         } else if (xpdrNb.equals(Uint16.valueOf(2))) {
991             assertEquals("should contain 8 TPs", 8, tpList.size());
992             assertEquals("XPDR2-CLIENT1", tpList.get(0).getTpId().getValue());
993             assertEquals("XPDR2-CLIENT2", tpList.get(1).getTpId().getValue());
994             assertEquals("XPDR2-NETWORK1", tpList.get(4).getTpId().getValue());
995             assertEquals("XPDR2-NETWORK2", tpList.get(5).getTpId().getValue());
996             assertEquals(
997                 "only IfOCHOTU4ODU4 interface capabitily expected",
998                 IfOCHOTU4ODU4.class,
999                 tpList.get(5)
1000                     .augmentation(
1001                         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
1002                                 .TerminationPoint1.class)
1003                     .getTpSupportedInterfaces()
1004                     .getSupportedInterfaceCapability().values().stream().findFirst()
1005                     .get()
1006                     .getIfCapType());
1007             assertEquals(
1008                 "supported interface capability of tp should contain 2 IfCapType",
1009                 2,
1010                 tpList.get(2)
1011                     .augmentation(
1012                         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
1013                             .TerminationPoint1.class)
1014                     .getTpSupportedInterfaces()
1015                     .getSupportedInterfaceCapability().values().size());
1016             List<SupportedInterfaceCapability> sicListClient3 = tpList.get(2)
1017                 .augmentation(
1018                     org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529
1019                     .TerminationPoint1.class)
1020                 .getTpSupportedInterfaces()
1021                 .getSupportedInterfaceCapability().values().stream().collect(Collectors.toList());
1022             for (SupportedInterfaceCapability supportedInterfaceCapability : sicListClient3) {
1023                 assertThat("tp should have 2 if-cap-type: if-100GE-ODU4, if-100GE",
1024                     String.valueOf(supportedInterfaceCapability.getIfCapType()),
1025                     either(containsString(String.valueOf(If100GEODU4.class)))
1026                     .or(containsString(String.valueOf(If100GE.class))));
1027             }
1028             assertEquals(
1029                 "TP should be of type client", OpenroadmTpType.XPONDERCLIENT,
1030                 tpList.get(2)
1031                     .augmentation(
1032                         org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529
1033                             .TerminationPoint1.class)
1034                     .getTpType());
1035             assertEquals(
1036                 "TP should be of type network", OpenroadmTpType.XPONDERNETWORK,
1037                 tpList.get(6)
1038                     .augmentation(
1039                         org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529
1040                             .TerminationPoint1.class)
1041                     .getTpType());
1042         }
1043     }
1044 }