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