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