Migrate tapi module to JUnit5
[transportpce.git] / tapi / src / test / java / org / opendaylight / transportpce / tapi / topology / TapiTopologyImplTest.java
1 /*
2  * Copyright © 2019 Orange, 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.tapi.topology;
9
10 import static org.hamcrest.CoreMatchers.containsString;
11 import static org.hamcrest.CoreMatchers.either;
12 import static org.hamcrest.MatcherAssert.assertThat;
13 import static org.junit.jupiter.api.Assertions.assertEquals;
14 import static org.junit.jupiter.api.Assertions.assertNotNull;
15
16 import com.google.common.util.concurrent.ListenableFuture;
17 import com.google.common.util.concurrent.ListeningExecutorService;
18 import com.google.common.util.concurrent.MoreExecutors;
19 import java.nio.charset.StandardCharsets;
20 import java.util.ArrayList;
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.UUID;
25 import java.util.concurrent.CountDownLatch;
26 import java.util.concurrent.ExecutionException;
27 import java.util.concurrent.Executors;
28 import java.util.stream.Collectors;
29 import org.eclipse.jdt.annotation.Nullable;
30 import org.junit.jupiter.api.BeforeAll;
31 import org.junit.jupiter.api.Test;
32 import org.opendaylight.transportpce.common.InstanceIdentifiers;
33 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
34 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
35 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
36 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl;
37 import org.opendaylight.transportpce.tapi.TapiStringConstants;
38 import org.opendaylight.transportpce.tapi.connectivity.ConnectivityUtils;
39 import org.opendaylight.transportpce.tapi.utils.TapiContext;
40 import org.opendaylight.transportpce.tapi.utils.TapiInitialORMapping;
41 import org.opendaylight.transportpce.tapi.utils.TapiLink;
42 import org.opendaylight.transportpce.tapi.utils.TapiTopologyDataUtils;
43 import org.opendaylight.transportpce.test.AbstractTest;
44 import org.opendaylight.transportpce.test.utils.TopologyDataUtils;
45 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.AdministrativeState;
46 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.CapacityUnit;
47 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.ForwardingDirection;
48 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.GetServiceInterfacePointDetailsInput;
49 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.GetServiceInterfacePointDetailsOutput;
50 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.GetServiceInterfacePointListInput;
51 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.GetServiceInterfacePointListOutput;
52 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LayerProtocolName;
53 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.OperationalState;
54 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
55 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.get.service._interface.point.list.output.Sip;
56 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.get.service._interface.point.list.output.SipKey;
57 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.Name;
58 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameKey;
59 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.ForwardingRule;
60 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetLinkDetailsInput;
61 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetLinkDetailsOutput;
62 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetNodeDetailsInput;
63 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetNodeDetailsOutput;
64 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetNodeEdgePointDetailsInput;
65 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetNodeEdgePointDetailsOutput;
66 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsInput;
67 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsOutput;
68 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Node;
69 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.RuleType;
70 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.topology.details.output.Topology;
71 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.NodeRuleGroup;
72 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePoint;
73 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePoint;
74 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.Rule;
75 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link;
76 import org.opendaylight.yangtools.yang.common.RpcResult;
77 import org.opendaylight.yangtools.yang.common.Uint64;
78 import org.slf4j.Logger;
79 import org.slf4j.LoggerFactory;
80
81 public class TapiTopologyImplTest extends AbstractTest {
82     private static final Logger LOG = LoggerFactory.getLogger(TapiTopologyImplTest.class);
83
84     private static ListeningExecutorService executorService;
85     private static CountDownLatch endSignal;
86     private static final int NUM_THREADS = 3;
87     private static NetworkTransactionService networkTransactionService;
88     private static TapiContext tapiContext;
89     private static TopologyUtils topologyUtils;
90     private static ConnectivityUtils connectivityUtils;
91     private static ServiceDataStoreOperations serviceDataStoreOperations;
92     private static TapiInitialORMapping tapiInitialORMapping;
93     private static TapiLink tapiLink;
94
95     @BeforeAll
96     static void setUp() throws InterruptedException, ExecutionException {
97         executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
98         endSignal = new CountDownLatch(1);
99         TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
100             TapiTopologyDataUtils.OPENROADM_TOPOLOGY_FILE, InstanceIdentifiers.OVERLAY_NETWORK_II);
101         TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
102             TapiTopologyDataUtils.OPENROADM_NETWORK_FILE, InstanceIdentifiers.UNDERLAY_NETWORK_II);
103         TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
104             TapiTopologyDataUtils.OTN_TOPOLOGY_FILE, InstanceIdentifiers.OTN_NETWORK_II);
105         TopologyDataUtils.writePortmappingFromFileToDatastore(getDataStoreContextUtil(),
106             TapiTopologyDataUtils.PORTMAPPING_FILE);
107         networkTransactionService = new NetworkTransactionImpl(getDataBroker());
108         tapiLink = new TapiLink(networkTransactionService);
109         serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(getDataStoreContextUtil().getDataBroker());
110         tapiContext = new TapiContext(networkTransactionService);
111         topologyUtils = new TopologyUtils(networkTransactionService, getDataStoreContextUtil().getDataBroker(),
112             tapiLink);
113         connectivityUtils = new ConnectivityUtils(serviceDataStoreOperations, new HashMap<>(), tapiContext,
114             networkTransactionService);
115         tapiInitialORMapping = new TapiInitialORMapping(topologyUtils, connectivityUtils,
116             tapiContext, serviceDataStoreOperations);
117         tapiInitialORMapping.performTopoInitialMapping();
118         LOG.info("setup done");
119     }
120
121     @Test
122     void getTopologyDetailsForTransponder100GTopologyWhenSuccessful()
123             throws ExecutionException, InterruptedException {
124         GetTopologyDetailsInput input = TapiTopologyDataUtils.buildGetTopologyDetailsInput(
125             TapiStringConstants.TPDR_100G);
126         TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(getDataBroker(), tapiContext, topologyUtils, tapiLink);
127         ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
128         result.addListener(new Runnable() {
129             @Override
130             public void run() {
131                 endSignal.countDown();
132             }
133         }, executorService);
134         endSignal.await();
135         RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
136         @Nullable
137         Topology topology = rpcResult.getResult().getTopology();
138         assertNotNull(topology, "Topology should not be null");
139         Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.TPDR_100G.getBytes(StandardCharsets.UTF_8))
140             .toString());
141         assertEquals(topoUuid, topology.getUuid(), "incorrect topology uuid");
142         assertEquals(1, topology.getNode().size(), "Node list size should be 1");
143         Name nodeName = topology.getNode().values().stream().findFirst().get().getName()
144             .get(new NameKey("Tpdr100g node name"));
145         assertEquals("Tpdr100g over WDM node", nodeName.getValue(), "Node name should be 'Tpdr100g over WDM node'");
146         Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes(nodeName.getValue().getBytes(StandardCharsets.UTF_8))
147             .toString());
148         assertEquals(nodeUuid, topology.getNode().values().stream().findFirst().get().getUuid(), "incorrect node uuid");
149         long nb = topology.getNode().values().stream().findFirst().get().getOwnedNodeEdgePoint().size();
150         assertEquals(2, nb, "'Transponder 100GE' node should have 2 neps");
151         List<NodeRuleGroup> nrgList = topology.getNode().values().stream().findFirst().get().nonnullNodeRuleGroup()
152             .values().stream().sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
153             .collect(Collectors.toList());
154         assertEquals(1, nrgList.size(), "'Transponder 100GE' node should contain a single node rule groups");
155         List<NodeEdgePoint> nodeEdgePointList = new ArrayList<>(nrgList.get(0).getNodeEdgePoint().values());
156         assertEquals(nb, nodeEdgePointList.size(), "'Transponder 100GE' node -rule-group should contain 2 NEPs");
157         List<Rule> ruleList = new ArrayList<>(nrgList.get(0).nonnullRule().values());
158         assertEquals(1, ruleList.size(), "node-rule-group should contain a single rule");
159         assertEquals("forward", ruleList.get(0).getLocalId(), "local-id of the rule should be 'forward'");
160         assertEquals(ForwardingRule.MAYFORWARDACROSSGROUP, ruleList.get(0).getForwardingRule(),
161             "the forwarding rule should be 'MAYFORWARDACROSSGROUP'");
162         assertEquals(RuleType.FORWARDING, ruleList.get(0).getRuleType(), "the rule type should be 'FORWARDING'");
163     }
164
165     @Test
166     void getTopologyDetailsForOtnTopologyWithOtnLinksWhenSuccessful()
167             throws ExecutionException, InterruptedException {
168         GetTopologyDetailsInput input = TapiTopologyDataUtils.buildGetTopologyDetailsInput(
169             TapiStringConstants.T0_MULTILAYER);
170         TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(getDataBroker(), tapiContext, topologyUtils, tapiLink);
171         ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
172         result.addListener(new Runnable() {
173             @Override
174             public void run() {
175                 endSignal.countDown();
176             }
177         }, executorService);
178         endSignal.await();
179         RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
180         @Nullable
181         Topology topology = rpcResult.getResult().getTopology();
182         assertNotNull(topology, "Topology should not be null");
183         assertEquals(13, topology.getNode().size(), "Node list size should be 13");
184         long nb1 = topology.getNode().values().stream()
185             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
186             .filter(node -> node.getName().get(new NameKey("dsr/odu node name")).getValue()
187                 .equals("XPDR-A1-XPDR1+DSR"))
188             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
189                 .filter(nep -> nep.getName().containsKey(new NameKey("100G-tpdr"))))
190             .count();
191         assertEquals(1, nb1, "XPDR-A1-XPDR1 should only have one client nep");
192         long nb2 = topology.getNode().values().stream()
193             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
194             .filter(node -> node.getName().get(new NameKey("dsr/odu node name")).getValue()
195                 .equals("SPDR-SA1-XPDR1+DSR"))
196             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
197                 .filter(nep -> nep.getName().containsKey(new NameKey("NodeEdgePoint_C"))))
198             .count();
199         assertEquals(4, nb2, "SPDR-SA1-XPDR1 (mux) should have 4 client neps");
200         long nb3 = topology.getNode().values().stream()
201             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
202             .filter(node -> node.getName().get(new NameKey("dsr/odu node name")).getValue()
203                 .equals("SPDR-SA1-XPDR1+DSR"))
204             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
205                 .filter(nep -> nep.getName().containsKey(new NameKey("iNodeEdgePoint_N"))))
206             .count();
207         assertEquals(1, nb3, "SPDR-SA1-XPDR1 (mux) should have a single network nep");
208         long nb4 = topology.getNode().values().stream()
209             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
210             .filter(node -> node.getName().get(new NameKey("dsr/odu node name")).getValue()
211                 .equals("SPDR-SA1-XPDR2+DSR"))
212             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
213                 .filter(nep -> nep.getName().containsKey(new NameKey("NodeEdgePoint_C"))))
214             .count();
215         assertEquals(4, nb4, "SPDR-SA1-XPDR2 (switch) should have 4 client neps");
216         long nb5 = topology.getNode().values().stream()
217             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
218             .filter(node -> node.getName().get(new NameKey("dsr/odu node name")).getValue()
219                 .equals("SPDR-SA1-XPDR2+DSR"))
220             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
221                 .filter(nep -> nep.getName().containsKey(new NameKey("iNodeEdgePoint_N"))))
222             .count();
223         assertEquals(2, nb5, "SPDR-SA1-XPDR2 (switch) should have 2 network neps");
224         assertEquals(18, topology.getLink().size(), "Link list size should be 18");
225         Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes("T0 - Multi-layer topology".getBytes()).toString());
226         assertEquals(topoUuid, topology.getUuid(), "incorrect topology uuid");
227         assertEquals(
228             "T0 - Multi-layer topology",
229             topology.nonnullName().values().stream().findFirst().get().getValue(),
230             "topology name should be T0 - Multi-layer topology");
231
232         long nbDsrOduNodes = topology.nonnullNode().values().stream()
233             .filter(n -> n.getName().containsKey(new NameKey("dsr/odu node name"))).count();
234         long nbPhotonicNodes = topology.nonnullNode().values().stream()
235             .filter(n -> n.getName().containsKey(new NameKey("otsi node name"))).count();
236         assertEquals(6, nbDsrOduNodes, "Node list should contain 6 DSR-ODU nodes");
237         assertEquals(7, nbPhotonicNodes, "Node list should contain 7 Photonics nodes");
238         long nbTransititionalLinks = topology.getLink().values().stream()
239             .filter(l -> l.getName().containsKey(new NameKey("transitional link name"))).count();
240         long nbOmsLinks = topology.getLink().values().stream()
241             .filter(l -> l.getName().containsKey(new NameKey("OMS link name"))).count();
242         long nbOtnLinks = topology.getLink().values().stream()
243             .filter(l -> l.getName().containsKey(new NameKey("otn link name"))).count();
244         assertEquals(8, nbTransititionalLinks, "Link list should contain 8 transitional links");
245         assertEquals(8, nbOmsLinks, "Link list should contain 8 transitional links");
246         assertEquals(2, nbOtnLinks, "Link list should contain 2 OTN links");
247
248         Uuid node1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+DSR".getBytes(StandardCharsets.UTF_8))
249             .toString());
250         Uuid node2Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+DSR".getBytes(StandardCharsets.UTF_8))
251             .toString());
252         Uuid node3Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+OTSi".getBytes(StandardCharsets.UTF_8))
253             .toString());
254         Uuid node4Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+OTSi".getBytes(StandardCharsets.UTF_8))
255             .toString());
256         Uuid tp1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+eODU+XPDR1-NETWORK1"
257             .getBytes(StandardCharsets.UTF_8)).toString());
258         Uuid tp2Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+eODU+XPDR1-NETWORK1"
259             .getBytes(StandardCharsets.UTF_8)).toString());
260         Uuid tp3Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+iOTSi+XPDR1-NETWORK1"
261             .getBytes(StandardCharsets.UTF_8)).toString());
262         Uuid tp4Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+iOTSi+XPDR1-NETWORK1"
263             .getBytes(StandardCharsets.UTF_8)).toString());
264         Uuid link1Uuid =
265             new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+iOTSi+XPDR1-NETWORK1toSPDR-SC1-XPDR1+iOTSi+XPDR1-NETWORK1"
266                 .getBytes(StandardCharsets.UTF_8)).toString());
267         Uuid link2Uuid =
268             new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+eODU+XPDR1-NETWORK1toSPDR-SC1-XPDR1+eODU+XPDR1-NETWORK1"
269                 .getBytes(StandardCharsets.UTF_8)).toString());
270
271         List<Link> links = topology.nonnullLink().values().stream()
272             .filter(l -> l.getName().containsKey(new NameKey("otn link name")))
273             .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
274             .collect(Collectors.toList());
275         checkOtnLink(links.get(0), topoUuid, node3Uuid, node4Uuid, tp3Uuid, tp4Uuid, link1Uuid,
276             "SPDR-SA1-XPDR1+iOTSi+XPDR1-NETWORK1toSPDR-SC1-XPDR1+iOTSi+XPDR1-NETWORK1");
277         checkOtnLink(links.get(1), topoUuid, node1Uuid, node2Uuid, tp1Uuid, tp2Uuid, link2Uuid,
278             "SPDR-SA1-XPDR1+eODU+XPDR1-NETWORK1toSPDR-SC1-XPDR1+eODU+XPDR1-NETWORK1");
279     }
280
281     @Test
282     void getTopologyDetailsForFullTapiTopologyWithLinksWhenSuccessful()
283             throws ExecutionException, InterruptedException {
284         GetTopologyDetailsInput input = TapiTopologyDataUtils.buildGetTopologyDetailsInput(
285             TapiStringConstants.T0_FULL_MULTILAYER);
286         TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(getDataBroker(), tapiContext, topologyUtils, tapiLink);
287         ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
288         result.addListener(new Runnable() {
289             @Override
290             public void run() {
291                 endSignal.countDown();
292             }
293         }, executorService);
294         endSignal.await();
295         RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
296         @Nullable
297         Topology topology = rpcResult.getResult().getTopology();
298         assertNotNull(topology, "Topology should not be null");
299         // 2 Nodes per Xpdr/Spdr node (DSR-ODU & PHOT) + 1 Node per Roadm
300         assertEquals(18, topology.getNode().size(), "Node list size should be 18");
301         long nb1 = topology.getNode().values().stream()
302             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
303             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("XPDR-A1-XPDR1+DSR"))
304             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
305                 .filter(nep -> nep.getName().containsKey(new NameKey("100G-tpdr"))))
306             .count();
307         // 2 client ports in configuration -> removed the checkTp so we have 2 NEPs
308         assertEquals(2, nb1, "XPDR-A1-XPDR1+DSR should only have two client neps");
309         long inb1 = topology.getNode().values().stream()
310             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
311             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("XPDR-A1-XPDR1+DSR"))
312             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
313                 .filter(nep -> nep.getName().containsKey(new NameKey("iNodeEdgePoint_N"))))
314             .count();
315         assertEquals(2, inb1, "XPDR-A1-XPDR1+DSR should only have two internal network neps");
316         long enb1 = topology.getNode().values().stream()
317             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
318             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("XPDR-A1-XPDR1+DSR"))
319             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
320                 .filter(nep -> nep.getName().containsKey(new NameKey("eNodeEdgePoint_N"))))
321             .count();
322         assertEquals(2, enb1, "XPDR-A1-XPDR1+DSR should only have two external network neps");
323         long nb2 = topology.getNode().values().stream()
324             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
325             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR1+DSR"))
326             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
327                 .filter(nep -> nep.getName().containsKey(new NameKey("NodeEdgePoint_C"))))
328             .count();
329         assertEquals(4, nb2, "SPDR-SA1-XPDR1+DSR (mux) should have 4 client neps");
330         long inb3 = topology.getNode().values().stream()
331             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
332             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR1+DSR"))
333             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
334                 .filter(nep -> nep.getName().containsKey(new NameKey("iNodeEdgePoint_N"))))
335             .count();
336         assertEquals(1, inb3, "SPDR-SA1-XPDR1+DSR (mux) should have a single internal network nep");
337         long enb3 = topology.getNode().values().stream()
338             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
339             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR1+DSR"))
340             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
341                 .filter(nep -> nep.getName().containsKey(new NameKey("eNodeEdgePoint_N"))))
342             .count();
343         assertEquals(4, enb3, "SPDR-SA1-XPDR1+DSR (mux) should have 4 external network nep");
344         long nb4 = topology.getNode().values().stream()
345             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
346             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR2+DSR"))
347             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
348                 .filter(nep -> nep.getName().containsKey(new NameKey("NodeEdgePoint_C"))))
349             .count();
350         assertEquals(4, nb4, "SPDR-SA1-XPDR2+DSR (switch) should have 4 client neps");
351         long inb5 = topology.getNode().values().stream()
352             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
353             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR2+DSR"))
354             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
355                 .filter(nep -> nep.getName().containsKey(new NameKey("iNodeEdgePoint_N"))))
356             .count();
357         assertEquals(4, inb5, "SPDR-SA1-XPDR2+DSR (switch) should have 4 internal network neps");
358         long enb5 = topology.getNode().values().stream()
359             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
360             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR2+DSR"))
361             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
362                 .filter(nep -> nep.getName().containsKey(new NameKey("eNodeEdgePoint_N"))))
363             .count();
364         assertEquals(4, enb5, "SPDR-SA1-XPDR2+DSR (switch) should have 4 external network neps");
365
366         // Now lets check for the Photonic media nodes (same nodes as for DSR + 1 Roadm node)
367         nb1 = topology.getNode().values().stream()
368             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.PHOTONICMEDIA))
369             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("XPDR-A1-XPDR1+OTSi"))
370             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
371                 .filter(nep -> nep.getName().containsKey(new NameKey("iNodeEdgePoint"))))
372             .count();
373         // 2 client ports in configuration -> removed the checkTp so we have 2 NEPs
374         assertEquals(2, nb1, "XPDR-A1-XPDR1+OTSi should only have two internal network neps");
375         inb1 = topology.getNode().values().stream()
376             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.PHOTONICMEDIA))
377             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("XPDR-A1-XPDR1+OTSi"))
378             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
379                 .filter(nep -> nep.getName().containsKey(new NameKey("eNodeEdgePoint"))))
380             .count();
381         assertEquals(2, inb1, "XPDR-A1-XPDR1+OTSi should only have two external network neps");
382         enb1 = topology.getNode().values().stream()
383             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.PHOTONICMEDIA))
384             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("XPDR-A1-XPDR1+OTSi"))
385             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
386                 .filter(nep -> nep.getName().containsKey(new NameKey("PhotMedNodeEdgePoint"))))
387             .count();
388         assertEquals(2, enb1, "XPDR-A1-XPDR1+OTSi should only have two photonic network neps");
389         nb2 = topology.getNode().values().stream()
390             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.PHOTONICMEDIA))
391             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR1+OTSi"))
392             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
393                 .filter(nep -> nep.getName().containsKey(new NameKey("iNodeEdgePoint"))))
394             .count();
395         assertEquals(1, nb2, "SPDR-SA1-XPDR1+OTSi (mux) should have a single internal network nep");
396         inb3 = topology.getNode().values().stream()
397             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.PHOTONICMEDIA))
398             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR1+OTSi"))
399             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
400                 .filter(nep -> nep.getName().containsKey(new NameKey("eNodeEdgePoint"))))
401             .count();
402         assertEquals(1, inb3, "SPDR-SA1-XPDR1+OTSi (mux) should have a single external network nep");
403         enb3 = topology.getNode().values().stream()
404             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.PHOTONICMEDIA))
405             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR1+OTSi"))
406             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
407                 .filter(nep -> nep.getName().containsKey(new NameKey("PhotMedNodeEdgePoint"))))
408             .count();
409         assertEquals(1, enb3, "SPDR-SA1-XPDR1+OTSi (mux) should have a single photonic network nep");
410         nb4 = topology.getNode().values().stream()
411             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.PHOTONICMEDIA))
412             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR2+OTSi"))
413             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
414                 .filter(nep -> nep.getName().containsKey(new NameKey("iNodeEdgePoint"))))
415             .count();
416         assertEquals(4, nb4, "SPDR-SA1-XPDR2+OTSi (switch) should have 4 internal network neps");
417         inb5 = topology.getNode().values().stream()
418             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.PHOTONICMEDIA))
419             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR2+OTSi"))
420             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
421                 .filter(nep -> nep.getName().containsKey(new NameKey("eNodeEdgePoint"))))
422             .count();
423         assertEquals(4, inb5, "SPDR-SA1-XPDR2+OTSi (switch) should have 4 external network neps");
424         enb5 = topology.getNode().values().stream()
425             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.PHOTONICMEDIA))
426             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR2+OTSi"))
427             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
428                 .filter(nep -> nep.getName().containsKey(new NameKey("PhotMedNodeEdgePoint"))))
429             .count();
430         assertEquals(4, enb5, "SPDR-SA1-XPDR2+OTSi (switch) should have 4 photonic network neps");
431         // We should have 3 neps per DEGREE-TTP port and 3 neps per SRG-PP port
432         long inb6 = topology.getNode().values().stream()
433             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.PHOTONICMEDIA))
434             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals(
435                 "ROADM-A1+PHOTONIC_MEDIA"))
436             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
437                 .filter(nep -> nep.getName().values().stream().findFirst().get().getValue().contains("DEG")))
438             .count();
439         assertEquals(6, inb6, "ROADM-A1+PHOTONIC_MEDIA (DEGREE) should have 6 network neps");
440         long enb6 = topology.getNode().values().stream()
441             .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.PHOTONICMEDIA))
442             .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals(
443                 "ROADM-A1+PHOTONIC_MEDIA"))
444             .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
445                 .filter(nep -> nep.getName().values().stream().findFirst().get().getValue().contains("SRG")))
446             .count();
447         assertEquals(24, enb6, "ROADM-A1+PHOTONIC_MEDIA (SRG) should have 24 network neps");
448
449         // Links in openroadm topology which include Roadm-to-Roadm and Xpdr-to-Roadm (ortopo / 2)
450         // + transitional links -> 1 per network port of Xpdr + OTN links / 2
451         assertEquals(25, topology.getLink().size(), "Link list size should be 25");
452         Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes("T0 - Full Multi-layer topology".getBytes()).toString());
453         assertEquals(topoUuid, topology.getUuid(), "incorrect topology uuid");
454         assertEquals(
455             "T0 - Full Multi-layer topology",
456             topology.nonnullName().values().stream().findFirst().get().getValue(),
457             "topology name should be T0 - Full Multi-layer topology");
458
459         long nbDsrOduNodes = topology.nonnullNode().values().stream()
460             .filter(n -> n.getName().containsKey(new NameKey("dsr/odu node name"))).count();
461         long nbPhotonicNodes = topology.nonnullNode().values().stream()
462             .filter(n -> n.getName().containsKey(new NameKey("otsi node name"))).count();
463         // In DSR/ODU we create one node per Xpdr (no filtering out)
464         assertEquals(8, nbDsrOduNodes, "Node list should contain 8 DSR-ODU nodes");
465         // We need to add the Roadms as Photonic nodes. Instead of 1 node as roadm infra we have 2 roadm nodes
466         assertEquals(8, nbPhotonicNodes, "Node list should contain 8 Photonics nodes");
467         long nbTransititionalLinks = topology.getLink().values().stream()
468             .filter(l -> l.getName().containsKey(new NameKey("transitional link name"))).count();
469         // Roadm-to-Roadm
470         long nbOmsLinks = topology.getLink().values().stream()
471             .filter(l -> l.getName().containsKey(new NameKey("OMS link name"))).count();
472         // Xpdr-to-Roadm
473         long nbOmsLinks1 = topology.getLink().values().stream()
474             .filter(l -> l.getName().containsKey(new NameKey("XPDR-RDM link name"))).count();
475         // 1 transitional link per NETWORK port
476         assertEquals(16, nbTransititionalLinks, "Link list should contain 16 transitional links");
477         // 1 OMS per ROADM-to-ROADM link + Existing XPDR-tp-ROADM link in openroadm topology
478         assertEquals(9, nbOmsLinks + nbOmsLinks1, "Link list should contain 9 OMS links");
479     }
480
481     @Test
482     void getNodeAndNepsDetailsWhenSuccessful()
483             throws ExecutionException, InterruptedException {
484         GetTopologyDetailsInput input = TapiTopologyDataUtils.buildGetTopologyDetailsInput(
485             TapiStringConstants.T0_FULL_MULTILAYER);
486         TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(getDataBroker(), tapiContext, topologyUtils, tapiLink);
487         ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
488         result.addListener(new Runnable() {
489             @Override
490             public void run() {
491                 endSignal.countDown();
492             }
493         }, executorService);
494         endSignal.await();
495         RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
496         @Nullable
497         Topology topology = rpcResult.getResult().getTopology();
498         for (Node node:topology.getNode().values()) {
499             String nodeName = node.getName().values().stream().findFirst().get().getValue();
500             GetNodeDetailsInput input1 = TapiTopologyDataUtils.buildGetNodeDetailsInput(
501                 TapiStringConstants.T0_FULL_MULTILAYER, nodeName);
502             ListenableFuture<RpcResult<GetNodeDetailsOutput>> result1 = tapiTopoImpl.getNodeDetails(input1);
503             result.addListener(new Runnable() {
504                 @Override
505                 public void run() {
506                     endSignal.countDown();
507                 }
508             }, executorService);
509             endSignal.await();
510             RpcResult<GetNodeDetailsOutput> rpcResult1 = result1.get();
511             @Nullable
512             Node node1 = rpcResult1.getResult().getNode();
513             assertNotNull(node1, "Node should not be null");
514             for (OwnedNodeEdgePoint onep:node1.getOwnedNodeEdgePoint().values()) {
515                 String onepName = onep.getName().values().stream().findFirst().get().getValue();
516                 GetNodeEdgePointDetailsInput input2 = TapiTopologyDataUtils.buildGetNodeEdgePointDetailsInput(
517                     TapiStringConstants.T0_FULL_MULTILAYER, nodeName, onepName);
518                 ListenableFuture<RpcResult<GetNodeEdgePointDetailsOutput>> result2
519                     = tapiTopoImpl.getNodeEdgePointDetails(input2);
520                 result.addListener(new Runnable() {
521                     @Override
522                     public void run() {
523                         endSignal.countDown();
524                     }
525                 }, executorService);
526                 endSignal.await();
527                 RpcResult<GetNodeEdgePointDetailsOutput> rpcResult2 = result2.get();
528                 org.opendaylight.yang.gen.v1
529                     .urn.onf.otcc.yang.tapi.topology.rev181210.get.node.edge.point.details.output.NodeEdgePoint
530                     onep1 = rpcResult2.getResult().getNodeEdgePoint();
531                 assertNotNull(onep1, "Node Edge Point should not be null");
532             }
533         }
534     }
535
536     @Test
537     void getLinkDetailsWhenSuccessful()
538             throws ExecutionException, InterruptedException {
539         GetTopologyDetailsInput input = TapiTopologyDataUtils.buildGetTopologyDetailsInput(
540             TapiStringConstants.T0_FULL_MULTILAYER);
541         TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(getDataBroker(), tapiContext, topologyUtils, tapiLink);
542         ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
543         result.addListener(new Runnable() {
544             @Override
545             public void run() {
546                 endSignal.countDown();
547             }
548         }, executorService);
549         endSignal.await();
550         RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
551         @Nullable
552         Topology topology = rpcResult.getResult().getTopology();
553         for (Link link:topology.getLink().values()) {
554             String linkName = link.getName().values().stream().findFirst().get().getValue();
555             GetLinkDetailsInput input1 = TapiTopologyDataUtils.buildGetLinkDetailsInput(
556                 TapiStringConstants.T0_FULL_MULTILAYER, linkName);
557             ListenableFuture<RpcResult<GetLinkDetailsOutput>> result1 = tapiTopoImpl.getLinkDetails(input1);
558             result.addListener(new Runnable() {
559                 @Override
560                 public void run() {
561                     endSignal.countDown();
562                 }
563             }, executorService);
564             endSignal.await();
565             RpcResult<GetLinkDetailsOutput> rpcResult1 = result1.get();
566             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.link.details.output.Link link1
567                 = rpcResult1.getResult().getLink();
568             assertNotNull(link1, "Link should not be null");
569         }
570     }
571
572     @Test
573     void getSipDetailsWhenSuccessful()
574             throws ExecutionException, InterruptedException {
575         GetServiceInterfacePointListInput input = TapiTopologyDataUtils.buildServiceInterfacePointListInput();
576         TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(getDataBroker(), tapiContext, topologyUtils, tapiLink);
577         ListenableFuture<RpcResult<GetServiceInterfacePointListOutput>> result = tapiTopoImpl
578             .getServiceInterfacePointList(input);
579         result.addListener(new Runnable() {
580             @Override
581             public void run() {
582                 endSignal.countDown();
583             }
584         }, executorService);
585         endSignal.await();
586         RpcResult<GetServiceInterfacePointListOutput> rpcResult = result.get();
587         Map<SipKey, Sip> sipMap = rpcResult.getResult().getSip();
588         for (Sip sip:sipMap.values()) {
589             Uuid sipUuid = sip.getUuid();
590             GetServiceInterfacePointDetailsInput input1 = TapiTopologyDataUtils
591                 .buildGetServiceInterfacePointDetailsInput(sipUuid);
592             ListenableFuture<RpcResult<GetServiceInterfacePointDetailsOutput>> result1
593                 = tapiTopoImpl.getServiceInterfacePointDetails(input1);
594             result.addListener(new Runnable() {
595                 @Override
596                 public void run() {
597                     endSignal.countDown();
598                 }
599             }, executorService);
600             endSignal.await();
601             RpcResult<GetServiceInterfacePointDetailsOutput> rpcResult1 = result1.get();
602             org.opendaylight.yang.gen.v1
603                 .urn.onf.otcc.yang.tapi.common.rev181210.get.service._interface.point.details.output.Sip sip1
604                 = rpcResult1.getResult().getSip();
605             assertNotNull(sip1, "Sip should not be null");
606         }
607     }
608
609     private void checkOtnLink(Link link, Uuid topoUuid, Uuid node1Uuid, Uuid node2Uuid, Uuid tp1Uuid, Uuid tp2Uuid,
610             Uuid linkUuid, String linkName) {
611         assertEquals(linkName, link.getName().get(new NameKey("otn link name")).getValue(), "bad name for the link");
612         assertEquals(linkUuid, link.getUuid(), "bad uuid for link");
613         assertEquals(CapacityUnit.GBPS, link.getAvailableCapacity().getTotalSize().getUnit(),
614             "Available capacity unit should be MBPS");
615         String prefix = linkName.split("-")[0];
616         if ("OTU4".equals(prefix)) {
617             assertEquals(Uint64.valueOf(0), link.getAvailableCapacity().getTotalSize().getValue(),
618                 "Available capacity -total size value should be 0");
619         } else if ("ODTU4".equals(prefix)) {
620             assertEquals(Uint64.valueOf(100000), link.getAvailableCapacity().getTotalSize().getValue(),
621                 "Available capacity -total size value should be 100 000");
622         }
623         assertEquals(CapacityUnit.GBPS, link.getTotalPotentialCapacity().getTotalSize().getUnit(),
624             "Total capacity unit should be GBPS");
625         assertEquals(Uint64.valueOf(100), link.getTotalPotentialCapacity().getTotalSize().getValue(),
626             "Total capacity -total size value should be 100");
627         if ("OTU4".equals(prefix)) {
628             assertEquals("otn link should be between 2 nodes of protocol layers PHOTONIC_MEDIA",
629                 LayerProtocolName.PHOTONICMEDIA.getName(),
630                 link.getLayerProtocolName().stream().findFirst().get().getName());
631         } else if ("ODTU4".equals(prefix)) {
632             assertEquals("otn link should be between 2 nodes of protocol layers ODU",
633                 LayerProtocolName.ODU.getName(),
634                 link.getLayerProtocolName().stream().findFirst().get().getName());
635         }
636         assertEquals(ForwardingDirection.BIDIRECTIONAL, link.getDirection(),
637             "transitional link should be BIDIRECTIONAL");
638         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
639             .link.NodeEdgePoint> nodeEdgePointList = new ArrayList<>(link.nonnullNodeEdgePoint().values());
640         assertEquals(topoUuid, nodeEdgePointList.get(0).getTopologyUuid(),
641             "topology uuid should be the same for the two termination point of the link");
642         assertEquals(topoUuid, nodeEdgePointList.get(1).getTopologyUuid(),
643             "topology uuid should be the same for the two termination point of the link");
644         assertThat("otn links should terminate on two distinct nodes",
645             nodeEdgePointList.get(0).getNodeUuid().getValue(),
646             either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
647         assertThat("otn links should terminate on two distinct nodes",
648             nodeEdgePointList.get(1).getNodeUuid().getValue(),
649             either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
650         assertThat("otn links should terminate on two distinct tps",
651             nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
652             either(containsString(tp1Uuid.getValue())).or(containsString(tp2Uuid.getValue())));
653         assertThat("otn links should terminate on two distinct tps",
654             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
655             either(containsString(tp1Uuid.getValue())).or(containsString(tp2Uuid.getValue())));
656         assertEquals(OperationalState.ENABLED, link.getOperationalState(), "operational state should be ENABLED");
657         assertEquals(AdministrativeState.UNLOCKED, link.getAdministrativeState(),
658             "administrative state should be UNLOCKED");
659     }
660 }