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