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