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.tapi.utils.TapiTopologyDataUtils;
32 import org.opendaylight.transportpce.test.AbstractTest;
33 import org.opendaylight.transportpce.test.utils.TopologyDataUtils;
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.ForwardingRule;
43 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsInput;
44 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsOutput;
45 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.RuleType;
46 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.topology.details.output.Topology;
47 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.NodeRuleGroup;
48 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePoint;
49 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.Rule;
50 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link;
51 import org.opendaylight.yangtools.yang.common.RpcResult;
52 import org.opendaylight.yangtools.yang.common.Uint64;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
56 public class TapiTopologyImplTest extends AbstractTest {
57 private static final Logger LOG = LoggerFactory.getLogger(TapiTopologyImplTest.class);
59 private static ListeningExecutorService executorService;
60 private static CountDownLatch endSignal;
61 private static final int NUM_THREADS = 3;
64 public static void setUp() throws InterruptedException, ExecutionException {
65 executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
66 endSignal = new CountDownLatch(1);
67 TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
68 TapiTopologyDataUtils.OPENROADM_TOPOLOGY_FILE, InstanceIdentifiers.OVERLAY_NETWORK_II);
69 TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
70 TapiTopologyDataUtils.OTN_TOPOLOGY_FILE, InstanceIdentifiers.OTN_NETWORK_II);
71 TopologyDataUtils.writePortmappingFromFileToDatastore(getDataStoreContextUtil(),
72 TapiTopologyDataUtils.PORTMAPPING_FILE);
73 LOG.info("setup done");
77 public void getTopologyDetailsForTransponder100GTopologyWhenSuccessful()
78 throws ExecutionException, InterruptedException {
79 GetTopologyDetailsInput input = TapiTopologyDataUtils.buildGetTopologyDetailsInput(TopologyUtils.TPDR_100G);
80 TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(getDataBroker());
81 ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
82 result.addListener(new Runnable() {
85 endSignal.countDown();
89 RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
91 Topology topology = rpcResult.getResult().getTopology();
92 assertNotNull("Topology should not be null", topology);
93 Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes(TopologyUtils.TPDR_100G.getBytes(Charset.forName("UTF-8")))
95 assertEquals("incorrect topology uuid", topoUuid, topology.getUuid());
96 assertEquals("Node list size should be 1", 1, topology.getNode().size());
97 Name nodeName = topology.getNode().values().stream().findFirst().get().getName()
98 .get(new NameKey("Tpdr100g node name"));
99 assertEquals("Node name should be 'Tpdr100g over WDM node'", "Tpdr100g over WDM node", nodeName.getValue());
100 Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes(nodeName.getValue().getBytes(Charset.forName("UTF-8")))
102 assertEquals("incorrect node uuid", nodeUuid, topology.getNode().values().stream().findFirst().get().getUuid());
103 long nb = topology.getNode().values().stream().findFirst().get().getOwnedNodeEdgePoint().size();
104 assertEquals("'Transponder 100GE' node should have 2 neps", 2, nb);
105 List<NodeRuleGroup> nrgList = topology.getNode().values().stream().findFirst().get().nonnullNodeRuleGroup()
106 .values().stream().sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
107 .collect(Collectors.toList());
108 assertEquals("'Transponder 100GE' node should contain a single node rule groups", 1, nrgList.size());
109 List<NodeEdgePoint> nodeEdgePointList = new ArrayList<>(nrgList.get(0).getNodeEdgePoint().values());
110 assertEquals("'Transponder 100GE' node -rule-group should contain 2 NEPs", nb, nodeEdgePointList.size());
111 List<Rule> ruleList = new ArrayList<>(nrgList.get(0).nonnullRule().values());
112 assertEquals("node-rule-group should contain a single rule", 1, ruleList.size());
113 assertEquals("local-id of the rule should be 'forward'",
114 "forward", ruleList.get(0).getLocalId());
115 assertEquals("the forwarding rule should be 'MAYFORWARDACROSSGROUP'",
116 ForwardingRule.MAYFORWARDACROSSGROUP, ruleList.get(0).getForwardingRule());
117 assertEquals("the rule type should be 'FORWARDING'",
118 RuleType.FORWARDING, ruleList.get(0).getRuleType());
122 public void getTopologyDetailsForOtnTopologyWithOtnLinksWhenSuccessful()
123 throws ExecutionException, InterruptedException {
124 GetTopologyDetailsInput input = TapiTopologyDataUtils.buildGetTopologyDetailsInput(TopologyUtils.T0_MULTILAYER);
125 TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(getDataBroker());
126 ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
127 result.addListener(new Runnable() {
130 endSignal.countDown();
134 RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
136 Topology topology = rpcResult.getResult().getTopology();
137 assertNotNull("Topology should not be null", topology);
138 assertEquals("Node list size should be 13", 13, topology.getNode().size());
139 long nb1 = topology.getNode().values().stream()
140 .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
141 .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("XPDR-A1-XPDR1"))
142 .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
143 .filter(nep -> nep.getName().containsKey(new NameKey("100G-tpdr"))))
145 assertEquals("XPDR-A1-XPDR1 should only have one client nep", 1, nb1);
146 long nb2 = topology.getNode().values().stream()
147 .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
148 .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR1"))
149 .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
150 .filter(nep -> nep.getName().containsKey(new NameKey("NodeEdgePoint_C"))))
152 assertEquals("SPDR-SA1-XPDR1 (mux) should have 4 client neps", 4, nb2);
153 long nb3 = topology.getNode().values().stream()
154 .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
155 .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR1"))
156 .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
157 .filter(nep -> nep.getName().containsKey(new NameKey("NodeEdgePoint_N"))))
159 assertEquals("SPDR-SA1-XPDR1 (mux) should have a single network nep", 1, nb3);
160 long nb4 = topology.getNode().values().stream()
161 .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
162 .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR2"))
163 .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
164 .filter(nep -> nep.getName().containsKey(new NameKey("NodeEdgePoint_C"))))
166 assertEquals("SPDR-SA1-XPDR2 (switch) should have 4 client neps", 4, nb4);
167 long nb5 = topology.getNode().values().stream()
168 .filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
169 .filter(node -> node.getName().values().stream().findFirst().get().getValue().equals("SPDR-SA1-XPDR2"))
170 .flatMap(node -> node.getOwnedNodeEdgePoint().values().stream()
171 .filter(nep -> nep.getName().containsKey(new NameKey("NodeEdgePoint_N"))))
173 assertEquals("SPDR-SA1-XPDR2 (switch) should have 2 network neps", 2, nb5);
174 assertEquals("Link list size should be 18", 18, topology.getLink().size());
175 Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes("T0 - Multi-layer topology".getBytes()).toString());
176 assertEquals("incorrect topology uuid", topoUuid, topology.getUuid());
177 assertEquals("topology name should be T0 - Multi-layer topology",
178 "T0 - Multi-layer topology",
179 topology.nonnullName().values().stream().findFirst().get().getValue());
181 long nbDsrOduNodes = topology.nonnullNode().values().stream()
182 .filter(n -> n.getName().containsKey(new NameKey("dsr/odu node name"))).count();
183 long nbPhotonicNodes = topology.nonnullNode().values().stream()
184 .filter(n -> n.getName().containsKey(new NameKey("otsi node name"))).count();
185 assertEquals("Node list should contain 6 DSR-ODU nodes", 6, nbDsrOduNodes);
186 assertEquals("Node list should contain 7 Photonics nodes", 7, nbPhotonicNodes);
187 long nbTransititionalLinks = topology.getLink().values().stream()
188 .filter(l -> l.getName().containsKey(new NameKey("transitional link name"))).count();
189 long nbOmsLinks = topology.getLink().values().stream()
190 .filter(l -> l.getName().containsKey(new NameKey("OMS link name"))).count();
191 long nbOtnLinks = topology.getLink().values().stream()
192 .filter(l -> l.getName().containsKey(new NameKey("otn link name"))).count();
193 assertEquals("Link list should contain 8 transitional links", 8, nbTransititionalLinks);
194 assertEquals("Link list should contain 8 transitional links", 8, nbOmsLinks);
195 assertEquals("Link list should contain 2 OTN links", 2, nbOtnLinks);
197 Uuid node1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
199 Uuid node2Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
201 Uuid node3Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
203 Uuid node4Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
205 Uuid tp1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+DSR+XPDR1-NETWORK1"
206 .getBytes(Charset.forName("UTF-8"))).toString());
207 Uuid tp2Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+DSR+XPDR1-NETWORK1"
208 .getBytes(Charset.forName("UTF-8"))).toString());
209 Uuid tp3Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+iOTSi+XPDR1-NETWORK1"
210 .getBytes(Charset.forName("UTF-8"))).toString());
211 Uuid tp4Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+iOTSi+XPDR1-NETWORK1"
212 .getBytes(Charset.forName("UTF-8"))).toString());
214 new Uuid(UUID.nameUUIDFromBytes("ODU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1"
215 .getBytes(Charset.forName("UTF-8"))).toString());
217 new Uuid(UUID.nameUUIDFromBytes("OTU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1"
218 .getBytes(Charset.forName("UTF-8"))).toString());
220 List<Link> links = topology.nonnullLink().values().stream()
221 .filter(l -> l.getName().containsKey(new NameKey("otn link name")))
222 .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
223 .collect(Collectors.toList());
224 checkOtnLink(links.get(0), topoUuid, node1Uuid, node2Uuid, tp1Uuid, tp2Uuid, link1Uuid,
225 "ODU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1");
226 checkOtnLink(links.get(1), topoUuid, node3Uuid, node4Uuid, tp3Uuid, tp4Uuid, link2Uuid,
227 "OTU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1");
230 private void checkOtnLink(Link link, Uuid topoUuid, Uuid node1Uuid, Uuid node2Uuid, Uuid tp1Uuid, Uuid tp2Uuid,
231 Uuid linkUuid, String linkName) {
232 assertEquals("bad name for the link", linkName, link.getName().get(new NameKey("otn link name")).getValue());
233 assertEquals("bad uuid for link", linkUuid, link.getUuid());
234 assertEquals("Available capacity unit should be MBPS",
235 CapacityUnit.MBPS, link.getAvailableCapacity().getTotalSize().getUnit());
236 String prefix = linkName.split("-")[0];
237 if ("OTU4".equals(prefix)) {
238 assertEquals("Available capacity -total size value should be 0",
239 Uint64.valueOf(0), link.getAvailableCapacity().getTotalSize().getValue());
240 } else if ("ODU4".equals(prefix)) {
241 assertEquals("Available capacity -total size value should be 100 000",
242 Uint64.valueOf(100000), link.getAvailableCapacity().getTotalSize().getValue());
244 assertEquals("Total capacity unit should be GBPS",
245 CapacityUnit.GBPS, link.getTotalPotentialCapacity().getTotalSize().getUnit());
246 assertEquals("Total capacity -total size value should be 100",
247 Uint64.valueOf(100), link.getTotalPotentialCapacity().getTotalSize().getValue());
248 if ("OTU4".equals(prefix)) {
249 assertEquals("otn link should be between 2 nodes of protocol layers PHOTONIC_MEDIA",
250 LayerProtocolName.PHOTONICMEDIA.getName(), link.getLayerProtocolName().get(0).getName());
251 } else if ("ODU4".equals(prefix)) {
252 assertEquals("otn link should be between 2 nodes of protocol layers ODU",
253 LayerProtocolName.ODU.getName(), link.getLayerProtocolName().get(0).getName());
255 assertEquals("transitional link should be BIDIRECTIONAL",
256 ForwardingDirection.BIDIRECTIONAL, link.getDirection());
257 List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
258 .link.NodeEdgePoint> nodeEdgePointList = new ArrayList<>(link.nonnullNodeEdgePoint().values());
259 assertEquals("topology uuid should be the same for the two termination point of the link",
260 topoUuid, nodeEdgePointList.get(0).getTopologyUuid());
261 assertEquals("topology uuid should be the same for the two termination point of the link",
262 topoUuid, nodeEdgePointList.get(1).getTopologyUuid());
263 assertThat("otn links should terminate on two distinct nodes",
264 nodeEdgePointList.get(0).getNodeUuid().getValue(),
265 either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
266 assertThat("otn links should terminate on two distinct nodes",
267 nodeEdgePointList.get(1).getNodeUuid().getValue(),
268 either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
269 assertThat("otn links should terminate on two distinct tps",
270 nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
271 either(containsString(tp1Uuid.getValue())).or(containsString(tp2Uuid.getValue())));
272 assertThat("otn links should terminate on two distinct tps",
273 nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
274 either(containsString(tp1Uuid.getValue())).or(containsString(tp2Uuid.getValue())));
275 assertEquals("operational state should be ENABLED",
276 OperationalState.ENABLED, link.getOperationalState());
277 assertEquals("administrative state should be UNLOCKED",
278 AdministrativeState.UNLOCKED, link.getAdministrativeState());