2 * Copyright © 2019 Orange, Inc. and others. All rights reserved.
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
8 package org.opendaylight.transportpce.tapi.topology;
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.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
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.Charset;
20 import java.util.ArrayList;
21 import java.util.List;
22 import java.util.UUID;
23 import java.util.concurrent.CountDownLatch;
24 import java.util.concurrent.ExecutionException;
25 import java.util.concurrent.Executors;
26 import java.util.stream.Collectors;
27 import org.eclipse.jdt.annotation.Nullable;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.opendaylight.transportpce.common.InstanceIdentifiers;
31 import org.opendaylight.transportpce.common.NetworkUtils;
32 import org.opendaylight.transportpce.tapi.utils.TopologyDataUtils;
33 import org.opendaylight.transportpce.test.AbstractTest;
34 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.AdministrativeState;
35 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.CapacityUnit;
36 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.ForwardingDirection;
37 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LayerProtocolName;
38 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.OperationalState;
39 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
40 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.Name;
41 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameKey;
42 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsInput;
43 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsOutput;
44 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.topology.details.output.Topology;
45 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link;
46 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node;
47 import org.opendaylight.yangtools.yang.common.RpcResult;
48 import org.opendaylight.yangtools.yang.common.Uint64;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
52 public class TapiTopologyImplTest extends AbstractTest {
53 private static final Logger LOG = LoggerFactory.getLogger(TapiTopologyImplTest.class);
55 private static ListeningExecutorService executorService;
56 private static CountDownLatch endSignal;
57 private static final int NUM_THREADS = 3;
60 public static void setUp() throws InterruptedException, ExecutionException {
61 executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
62 endSignal = new CountDownLatch(1);
63 TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
64 TopologyDataUtils.OPENROADM_TOPOLOGY_FILE, InstanceIdentifiers.OVERLAY_NETWORK_II);
65 TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
66 TopologyDataUtils.OTN_TOPOLOGY_FILE, InstanceIdentifiers.OTN_NETWORK_II);
67 TopologyDataUtils.writePortmappingFromFileToDatastore(getDataStoreContextUtil());
68 LOG.info("setup done");
72 public void getTopologyDetailsForOpenroadmTopologyWhenSuccessful() throws ExecutionException, InterruptedException {
73 GetTopologyDetailsInput input = TopologyDataUtils.buildGetTopologyDetailsInput(NetworkUtils.OVERLAY_NETWORK_ID);
74 TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(getDataBroker());
75 ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
76 result.addListener(new Runnable() {
79 endSignal.countDown();
83 RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
85 Topology topology = rpcResult.getResult().getTopology();
86 assertNotNull("Topology should not be null", topology);
87 assertEquals("Nodes list size should be 1", 1, topology.getNode().size());
88 List<Node> topologyNodeList = new ArrayList<>(topology.nonnullNode().values());
89 List<Node> nodeList = new ArrayList<>(topologyNodeList);
90 List<Name> nameList = new ArrayList<>(nodeList.get(0).nonnullName().values());
91 assertEquals("Node name should be TAPI Ethernet Node",
92 "TAPI Ethernet Node", nameList.get(0).getValue());
93 Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes("Ethernet Topology".getBytes()).toString());
94 Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes("TAPI Ethernet Node".getBytes()).toString());
95 assertEquals("incorrect topology uuid", topoUuid, topology.getUuid());
96 assertEquals("incorrect node uuid", nodeUuid, topologyNodeList.get(0).getUuid());
97 assertEquals("TAPI Ethernet Node should have 2 neps",
98 2, topologyNodeList.get(0).getOwnedNodeEdgePoint().size());
102 public void getTopologyDetailsForOtnTopologyWithOtnLinksWhenSuccessful()
103 throws ExecutionException, InterruptedException {
104 GetTopologyDetailsInput input = TopologyDataUtils.buildGetTopologyDetailsInput(NetworkUtils.OTN_NETWORK_ID);
105 TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(getDataBroker());
106 ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
107 result.addListener(new Runnable() {
110 endSignal.countDown();
114 RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
116 Topology topology = rpcResult.getResult().getTopology();
117 assertNotNull("Topology should not be null", topology);
118 assertEquals("Node list size should be 13", 13, topology.getNode().size());
119 long nb1 = topology.getNode().values().stream()
120 .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
121 .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("XPDR-A1-XPDR1"))
122 .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
123 .filter(nep -> nep.getName().containsKey(new NameKey("100G-tpdr"))))
125 assertEquals("XPDR-A1-XPDR1 should only have one client nep", 1, nb1);
126 long nb2 = topology.getNode().values().stream()
127 .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
128 .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR1"))
129 .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
130 .filter(nep -> nep.getName().containsKey(new NameKey("NodeEdgePoint_C"))))
132 assertEquals("SPDR-SA1-XPDR1 (mux) should have 4 client neps", 4, nb2);
133 long nb3 = topology.getNode().values().stream()
134 .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
135 .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR1"))
136 .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
137 .filter(nep -> nep.getName().containsKey(new NameKey("NodeEdgePoint_N"))))
139 assertEquals("SPDR-SA1-XPDR1 (mux) should have a single network nep", 1, nb3);
140 long nb4 = topology.getNode().values().stream()
141 .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
142 .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR2"))
143 .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
144 .filter(nep -> nep.getName().containsKey(new NameKey("NodeEdgePoint_C"))))
146 assertEquals("SPDR-SA1-XPDR2 (switch) should have 4 client neps", 4, nb4);
147 long nb5 = topology.getNode().values().stream()
148 .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
149 .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR2"))
150 .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
151 .filter(nep -> nep.getName().containsKey(new NameKey("NodeEdgePoint_N"))))
153 assertEquals("SPDR-SA1-XPDR2 (switch) should have 2 network neps", 2, nb5);
154 assertEquals("Link list size should be 18", 18, topology.getLink().size());
155 Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes("T0 - Multi-layer topology".getBytes()).toString());
156 assertEquals("incorrect topology uuid", topoUuid, topology.getUuid());
157 assertEquals("topology name should be T0 - Multi-layer topology",
158 "T0 - Multi-layer topology",
159 topology.nonnullName().values().stream().findFirst().get().getValue());
161 long nbDsrOduNodes = topology.nonnullNode().values().stream()
162 .filter(n -> n.getName().containsKey(new NameKey("dsr/odu node name"))).count();
163 long nbPhotonicNodes = topology.nonnullNode().values().stream()
164 .filter(n -> n.getName().containsKey(new NameKey("otsi node name"))).count();
165 assertEquals("Node list should contain 6 DSR-ODU nodes", 6, nbDsrOduNodes);
166 assertEquals("Node list should contain 7 Photonics nodes", 7, nbPhotonicNodes);
167 long nbTransititionalLinks = topology.getLink().values().stream()
168 .filter(l -> l.getName().containsKey(new NameKey("transitional link name"))).count();
169 long nbOmsLinks = topology.getLink().values().stream()
170 .filter(l -> l.getName().containsKey(new NameKey("OMS link name"))).count();
171 long nbOtnLinks = topology.getLink().values().stream()
172 .filter(l -> l.getName().containsKey(new NameKey("otn link name"))).count();
173 assertEquals("Link list should contain 8 transitional links", 8, nbTransititionalLinks);
174 assertEquals("Link list should contain 8 transitional links", 8, nbOmsLinks);
175 assertEquals("Link list should contain 2 OTN links", 2, nbOtnLinks);
177 Uuid node1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
179 Uuid node2Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
181 Uuid node3Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
183 Uuid node4Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
185 Uuid tp1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+DSR+XPDR1-NETWORK1"
186 .getBytes(Charset.forName("UTF-8"))).toString());
187 Uuid tp2Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+DSR+XPDR1-NETWORK1"
188 .getBytes(Charset.forName("UTF-8"))).toString());
189 Uuid tp3Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+iOTSi+XPDR1-NETWORK1"
190 .getBytes(Charset.forName("UTF-8"))).toString());
191 Uuid tp4Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+iOTSi+XPDR1-NETWORK1"
192 .getBytes(Charset.forName("UTF-8"))).toString());
194 new Uuid(UUID.nameUUIDFromBytes("ODU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1"
195 .getBytes(Charset.forName("UTF-8"))).toString());
197 new Uuid(UUID.nameUUIDFromBytes("OTU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1"
198 .getBytes(Charset.forName("UTF-8"))).toString());
200 List<Link> links = topology.nonnullLink().values().stream()
201 .filter(l -> l.getName().containsKey(new NameKey("otn link name")))
202 .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
203 .collect(Collectors.toList());
204 checkOtnLink(links.get(0), topoUuid, node1Uuid, node2Uuid, tp1Uuid, tp2Uuid, link1Uuid,
205 "ODU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1");
206 checkOtnLink(links.get(1), topoUuid, node3Uuid, node4Uuid, tp3Uuid, tp4Uuid, link2Uuid,
207 "OTU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1");
210 private void checkOtnLink(Link link, Uuid topoUuid, Uuid node1Uuid, Uuid node2Uuid, Uuid tp1Uuid, Uuid tp2Uuid,
211 Uuid linkUuid, String linkName) {
212 assertEquals("bad name for the link", linkName, link.getName().get(new NameKey("otn link name")).getValue());
213 assertEquals("bad uuid for link", linkUuid, link.getUuid());
214 assertEquals("Available capacity unit should be MBPS",
215 CapacityUnit.MBPS, link.getAvailableCapacity().getTotalSize().getUnit());
216 String prefix = linkName.split("-")[0];
217 if ("OTU4".equals(prefix)) {
218 assertEquals("Available capacity -total size value should be 0",
219 Uint64.valueOf(0), link.getAvailableCapacity().getTotalSize().getValue());
220 } else if ("ODU4".equals(prefix)) {
221 assertEquals("Available capacity -total size value should be 100 000",
222 Uint64.valueOf(100000), link.getAvailableCapacity().getTotalSize().getValue());
224 assertEquals("Total capacity unit should be GBPS",
225 CapacityUnit.GBPS, link.getTotalPotentialCapacity().getTotalSize().getUnit());
226 assertEquals("Total capacity -total size value should be 100",
227 Uint64.valueOf(100), link.getTotalPotentialCapacity().getTotalSize().getValue());
228 if ("OTU4".equals(prefix)) {
229 assertEquals("otn link should be between 2 nodes of protocol layers PHOTONIC_MEDIA",
230 LayerProtocolName.PHOTONICMEDIA.getName(), link.getLayerProtocolName().get(0).getName());
231 } else if ("ODU4".equals(prefix)) {
232 assertEquals("otn link should be between 2 nodes of protocol layers ODU",
233 LayerProtocolName.ODU.getName(), link.getLayerProtocolName().get(0).getName());
235 assertEquals("transitional link should be BIDIRECTIONAL",
236 ForwardingDirection.BIDIRECTIONAL, link.getDirection());
237 List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
238 .link.NodeEdgePoint> nodeEdgePointList = new ArrayList<>(link.nonnullNodeEdgePoint().values());
239 assertEquals("topology uuid should be the same for the two termination point of the link",
240 topoUuid, nodeEdgePointList.get(0).getTopologyUuid());
241 assertEquals("topology uuid should be the same for the two termination point of the link",
242 topoUuid, nodeEdgePointList.get(1).getTopologyUuid());
243 assertThat("otn links should terminate on two distinct nodes",
244 nodeEdgePointList.get(0).getNodeUuid().getValue(),
245 either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
246 assertThat("otn links should terminate on two distinct nodes",
247 nodeEdgePointList.get(1).getNodeUuid().getValue(),
248 either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
249 assertThat("otn links should terminate on two distinct tps",
250 nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
251 either(containsString(tp1Uuid.getValue())).or(containsString(tp2Uuid.getValue())));
252 assertThat("otn links should terminate on two distinct tps",
253 nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
254 either(containsString(tp1Uuid.getValue())).or(containsString(tp2Uuid.getValue())));
255 assertEquals("operational state should be ENABLED",
256 OperationalState.ENABLED, link.getOperationalState());
257 assertEquals("administrative state should be UNLOCKED",
258 AdministrativeState.UNLOCKED, link.getAdministrativeState());