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.HashMap;
22 import java.util.List;
23 import java.util.UUID;
24 import java.util.concurrent.CountDownLatch;
25 import java.util.concurrent.ExecutionException;
26 import java.util.concurrent.Executors;
27 import java.util.stream.Collectors;
28 import org.eclipse.jdt.annotation.Nullable;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.opendaylight.transportpce.common.InstanceIdentifiers;
32 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
33 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
34 import org.opendaylight.transportpce.common.network.RequestProcessor;
35 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
36 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl;
37 import org.opendaylight.transportpce.tapi.connectivity.ConnectivityUtils;
38 import org.opendaylight.transportpce.tapi.utils.TapiContext;
39 import org.opendaylight.transportpce.tapi.utils.TapiInitialORMapping;
40 import org.opendaylight.transportpce.tapi.utils.TapiTopologyDataUtils;
41 import org.opendaylight.transportpce.test.AbstractTest;
42 import org.opendaylight.transportpce.test.utils.TopologyDataUtils;
43 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.AdministrativeState;
44 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.CapacityUnit;
45 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.ForwardingDirection;
46 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LayerProtocolName;
47 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.OperationalState;
48 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
49 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.Name;
50 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameKey;
51 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.ForwardingRule;
52 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsInput;
53 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsOutput;
54 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.RuleType;
55 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.topology.details.output.Topology;
56 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.NodeRuleGroup;
57 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePoint;
58 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.Rule;
59 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link;
60 import org.opendaylight.yangtools.yang.common.RpcResult;
61 import org.opendaylight.yangtools.yang.common.Uint64;
62 import org.slf4j.Logger;
63 import org.slf4j.LoggerFactory;
65 public class TapiTopologyImplTest extends AbstractTest {
66 private static final Logger LOG = LoggerFactory.getLogger(TapiTopologyImplTest.class);
68 private static ListeningExecutorService executorService;
69 private static CountDownLatch endSignal;
70 private static final int NUM_THREADS = 3;
71 public static NetworkTransactionService networkTransactionService;
72 public static TapiContext tapiContext;
73 public static TopologyUtils topologyUtils;
74 public static ConnectivityUtils connectivityUtils;
75 public static ServiceDataStoreOperations serviceDataStoreOperations;
76 public static TapiInitialORMapping tapiInitialORMapping;
79 public static void setUp() throws InterruptedException, ExecutionException {
80 executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
81 endSignal = new CountDownLatch(1);
82 TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
83 TapiTopologyDataUtils.OPENROADM_TOPOLOGY_FILE, InstanceIdentifiers.OVERLAY_NETWORK_II);
84 TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
85 TapiTopologyDataUtils.OPENROADM_NETWORK_FILE, InstanceIdentifiers.UNDERLAY_NETWORK_II);
86 TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
87 TapiTopologyDataUtils.OTN_TOPOLOGY_FILE, InstanceIdentifiers.OTN_NETWORK_II);
88 TopologyDataUtils.writePortmappingFromFileToDatastore(getDataStoreContextUtil(),
89 TapiTopologyDataUtils.PORTMAPPING_FILE);
90 networkTransactionService = new NetworkTransactionImpl(
91 new RequestProcessor(getDataStoreContextUtil().getDataBroker()));
92 serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(getDataStoreContextUtil().getDataBroker());
93 tapiContext = new TapiContext(networkTransactionService);
94 topologyUtils = new TopologyUtils(networkTransactionService, getDataStoreContextUtil().getDataBroker());
95 connectivityUtils = new ConnectivityUtils(serviceDataStoreOperations, new HashMap<>(), tapiContext);
96 tapiInitialORMapping = new TapiInitialORMapping(topologyUtils, connectivityUtils,
97 tapiContext, serviceDataStoreOperations);
98 tapiInitialORMapping.performTopoInitialMapping();
99 LOG.info("setup done");
103 public void getTopologyDetailsForTransponder100GTopologyWhenSuccessful()
104 throws ExecutionException, InterruptedException {
105 GetTopologyDetailsInput input = TapiTopologyDataUtils.buildGetTopologyDetailsInput(TopologyUtils.TPDR_100G);
106 TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(getDataBroker(), tapiContext, topologyUtils);
107 ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
108 result.addListener(new Runnable() {
111 endSignal.countDown();
115 RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
117 Topology topology = rpcResult.getResult().getTopology();
118 assertNotNull("Topology should not be null", topology);
119 Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes(TopologyUtils.TPDR_100G.getBytes(Charset.forName("UTF-8")))
121 assertEquals("incorrect topology uuid", topoUuid, topology.getUuid());
122 assertEquals("Node list size should be 1", 1, topology.getNode().size());
123 Name nodeName = topology.getNode().values().stream().findFirst().get().getName()
124 .get(new NameKey("Tpdr100g node name"));
125 assertEquals("Node name should be 'Tpdr100g over WDM node'", "Tpdr100g over WDM node", nodeName.getValue());
126 Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes(nodeName.getValue().getBytes(Charset.forName("UTF-8")))
128 assertEquals("incorrect node uuid", nodeUuid, topology.getNode().values().stream().findFirst().get().getUuid());
129 long nb = topology.getNode().values().stream().findFirst().get().getOwnedNodeEdgePoint().size();
130 assertEquals("'Transponder 100GE' node should have 2 neps", 2, nb);
131 List<NodeRuleGroup> nrgList = topology.getNode().values().stream().findFirst().get().nonnullNodeRuleGroup()
132 .values().stream().sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
133 .collect(Collectors.toList());
134 assertEquals("'Transponder 100GE' node should contain a single node rule groups", 1, nrgList.size());
135 List<NodeEdgePoint> nodeEdgePointList = new ArrayList<>(nrgList.get(0).getNodeEdgePoint().values());
136 assertEquals("'Transponder 100GE' node -rule-group should contain 2 NEPs", nb, nodeEdgePointList.size());
137 List<Rule> ruleList = new ArrayList<>(nrgList.get(0).nonnullRule().values());
138 assertEquals("node-rule-group should contain a single rule", 1, ruleList.size());
139 assertEquals("local-id of the rule should be 'forward'",
140 "forward", ruleList.get(0).getLocalId());
141 assertEquals("the forwarding rule should be 'MAYFORWARDACROSSGROUP'",
142 ForwardingRule.MAYFORWARDACROSSGROUP, ruleList.get(0).getForwardingRule());
143 assertEquals("the rule type should be 'FORWARDING'",
144 RuleType.FORWARDING, ruleList.get(0).getRuleType());
148 public void getTopologyDetailsForOtnTopologyWithOtnLinksWhenSuccessful()
149 throws ExecutionException, InterruptedException {
150 GetTopologyDetailsInput input = TapiTopologyDataUtils.buildGetTopologyDetailsInput(TopologyUtils.T0_MULTILAYER);
151 TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(getDataBroker(), tapiContext, topologyUtils);
152 ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
153 result.addListener(new Runnable() {
156 endSignal.countDown();
160 RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
162 Topology topology = rpcResult.getResult().getTopology();
163 assertNotNull("Topology should not be null", topology);
164 assertEquals("Node list size should be 13", 13, topology.getNode().size());
165 long nb1 = topology.getNode().values().stream()
166 .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
167 .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("XPDR-A1-XPDR1"))
168 .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
169 .filter(nep -> nep.getName().containsKey(new NameKey("100G-tpdr"))))
171 assertEquals("XPDR-A1-XPDR1 should only have one client nep", 1, nb1);
172 long nb2 = topology.getNode().values().stream()
173 .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
174 .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR1"))
175 .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
176 .filter(nep -> nep.getName().containsKey(new NameKey("NodeEdgePoint_C"))))
178 assertEquals("SPDR-SA1-XPDR1 (mux) should have 4 client neps", 4, nb2);
179 long nb3 = topology.getNode().values().stream()
180 .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
181 .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR1"))
182 .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
183 .filter(nep -> nep.getName().containsKey(new NameKey("NodeEdgePoint_N"))))
185 assertEquals("SPDR-SA1-XPDR1 (mux) should have a single network nep", 1, nb3);
186 long nb4 = topology.getNode().values().stream()
187 .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
188 .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR2"))
189 .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
190 .filter(nep -> nep.getName().containsKey(new NameKey("NodeEdgePoint_C"))))
192 assertEquals("SPDR-SA1-XPDR2 (switch) should have 4 client neps", 4, nb4);
193 long nb5 = topology.getNode().values().stream()
194 .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
195 .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR2"))
196 .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
197 .filter(nep -> nep.getName().containsKey(new NameKey("NodeEdgePoint_N"))))
199 assertEquals("SPDR-SA1-XPDR2 (switch) should have 2 network neps", 2, nb5);
200 assertEquals("Link list size should be 18", 18, topology.getLink().size());
201 Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes("T0 - Multi-layer topology".getBytes()).toString());
202 assertEquals("incorrect topology uuid", topoUuid, topology.getUuid());
203 assertEquals("topology name should be T0 - Multi-layer topology",
204 "T0 - Multi-layer topology",
205 topology.nonnullName().values().stream().findFirst().get().getValue());
207 long nbDsrOduNodes = topology.nonnullNode().values().stream()
208 .filter(n -> n.getName().containsKey(new NameKey("dsr/odu node name"))).count();
209 long nbPhotonicNodes = topology.nonnullNode().values().stream()
210 .filter(n -> n.getName().containsKey(new NameKey("otsi node name"))).count();
211 assertEquals("Node list should contain 6 DSR-ODU nodes", 6, nbDsrOduNodes);
212 assertEquals("Node list should contain 7 Photonics nodes", 7, nbPhotonicNodes);
213 long nbTransititionalLinks = topology.getLink().values().stream()
214 .filter(l -> l.getName().containsKey(new NameKey("transitional link name"))).count();
215 long nbOmsLinks = topology.getLink().values().stream()
216 .filter(l -> l.getName().containsKey(new NameKey("OMS link name"))).count();
217 long nbOtnLinks = topology.getLink().values().stream()
218 .filter(l -> l.getName().containsKey(new NameKey("otn link name"))).count();
219 assertEquals("Link list should contain 8 transitional links", 8, nbTransititionalLinks);
220 assertEquals("Link list should contain 8 transitional links", 8, nbOmsLinks);
221 assertEquals("Link list should contain 2 OTN links", 2, nbOtnLinks);
223 Uuid node1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
225 Uuid node2Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
227 Uuid node3Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
229 Uuid node4Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
231 Uuid tp1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+DSR+XPDR1-NETWORK1"
232 .getBytes(Charset.forName("UTF-8"))).toString());
233 Uuid tp2Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+DSR+XPDR1-NETWORK1"
234 .getBytes(Charset.forName("UTF-8"))).toString());
235 Uuid tp3Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+iOTSi+XPDR1-NETWORK1"
236 .getBytes(Charset.forName("UTF-8"))).toString());
237 Uuid tp4Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+iOTSi+XPDR1-NETWORK1"
238 .getBytes(Charset.forName("UTF-8"))).toString());
240 new Uuid(UUID.nameUUIDFromBytes("ODTU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1"
241 .getBytes(Charset.forName("UTF-8"))).toString());
243 new Uuid(UUID.nameUUIDFromBytes("OTU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1"
244 .getBytes(Charset.forName("UTF-8"))).toString());
246 List<Link> links = topology.nonnullLink().values().stream()
247 .filter(l -> l.getName().containsKey(new NameKey("otn link name")))
248 .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
249 .collect(Collectors.toList());
250 checkOtnLink(links.get(0), topoUuid, node1Uuid, node2Uuid, tp1Uuid, tp2Uuid, link1Uuid,
251 "ODTU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1");
252 checkOtnLink(links.get(1), topoUuid, node3Uuid, node4Uuid, tp3Uuid, tp4Uuid, link2Uuid,
253 "OTU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1");
256 private void checkOtnLink(Link link, Uuid topoUuid, Uuid node1Uuid, Uuid node2Uuid, Uuid tp1Uuid, Uuid tp2Uuid,
257 Uuid linkUuid, String linkName) {
258 assertEquals("bad name for the link", linkName, link.getName().get(new NameKey("otn link name")).getValue());
259 assertEquals("bad uuid for link", linkUuid, link.getUuid());
260 assertEquals("Available capacity unit should be MBPS",
261 CapacityUnit.MBPS, link.getAvailableCapacity().getTotalSize().getUnit());
262 String prefix = linkName.split("-")[0];
263 if ("OTU4".equals(prefix)) {
264 assertEquals("Available capacity -total size value should be 0",
265 Uint64.valueOf(0), link.getAvailableCapacity().getTotalSize().getValue());
266 } else if ("ODTU4".equals(prefix)) {
267 assertEquals("Available capacity -total size value should be 100 000",
268 Uint64.valueOf(100000), link.getAvailableCapacity().getTotalSize().getValue());
270 assertEquals("Total capacity unit should be GBPS",
271 CapacityUnit.GBPS, link.getTotalPotentialCapacity().getTotalSize().getUnit());
272 assertEquals("Total capacity -total size value should be 100",
273 Uint64.valueOf(100), link.getTotalPotentialCapacity().getTotalSize().getValue());
274 if ("OTU4".equals(prefix)) {
275 assertEquals("otn link should be between 2 nodes of protocol layers PHOTONIC_MEDIA",
276 LayerProtocolName.PHOTONICMEDIA.getName(), link.getLayerProtocolName().get(0).getName());
277 } else if ("ODTU4".equals(prefix)) {
278 assertEquals("otn link should be between 2 nodes of protocol layers ODU",
279 LayerProtocolName.ODU.getName(), link.getLayerProtocolName().get(0).getName());
281 assertEquals("transitional link should be BIDIRECTIONAL",
282 ForwardingDirection.BIDIRECTIONAL, link.getDirection());
283 List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
284 .link.NodeEdgePoint> nodeEdgePointList = new ArrayList<>(link.nonnullNodeEdgePoint().values());
285 assertEquals("topology uuid should be the same for the two termination point of the link",
286 topoUuid, nodeEdgePointList.get(0).getTopologyUuid());
287 assertEquals("topology uuid should be the same for the two termination point of the link",
288 topoUuid, nodeEdgePointList.get(1).getTopologyUuid());
289 assertThat("otn links should terminate on two distinct nodes",
290 nodeEdgePointList.get(0).getNodeUuid().getValue(),
291 either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
292 assertThat("otn links should terminate on two distinct nodes",
293 nodeEdgePointList.get(1).getNodeUuid().getValue(),
294 either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
295 assertThat("otn links should terminate on two distinct tps",
296 nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
297 either(containsString(tp1Uuid.getValue())).or(containsString(tp2Uuid.getValue())));
298 assertThat("otn links should terminate on two distinct tps",
299 nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
300 either(containsString(tp1Uuid.getValue())).or(containsString(tp2Uuid.getValue())));
301 assertEquals("operational state should be ENABLED",
302 OperationalState.ENABLED, link.getOperationalState());
303 assertEquals("administrative state should be UNLOCKED",
304 AdministrativeState.UNLOCKED, link.getAdministrativeState());