2 * Copyright (c) 2013 Cisco Systems, 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.protocol.integration.pcep;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertNotSame;
12 import static org.junit.Assert.assertSame;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.verify;
15 import static org.mockito.Mockito.verifyZeroInteractions;
17 import java.lang.reflect.Method;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
22 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
23 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.topology.rev140113.NetworkTopologyContext;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.topology.rev140113.NetworkTopologyRef;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.NetworkTopologyPcepProgrammingService;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitAddLspInput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitAddLspInputBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitUpdateLspInput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev131106.SubmitUpdateLspInputBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspInput;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspInputBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInput;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInputBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.NetworkTopologyPcepService;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.PcepCreateP2pTunnelInput;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.PcepCreateP2pTunnelInputBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.PcepDestroyTunnelInput;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.PcepDestroyTunnelInputBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.tunnel.pcep.programming.rev131030.TopologyTunnelPcepProgrammingService;
41 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
42 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
43 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
44 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
45 import org.ops4j.pax.exam.junit.PaxExam;
46 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
48 @RunWith(PaxExam.class)
49 @ExamReactorStrategy(org.ops4j.pax.exam.spi.reactors.PerClass.class)
50 public class PcepRpcServicesRoutingTest extends AbstractPcepOsgiTest {
53 public void testRoutedRpcNetworkTopologyPcepService() throws Exception {
54 final NetworkTopologyPcepService pcepService1 = mock(NetworkTopologyPcepService.class, "First pcep Service");
55 final NetworkTopologyPcepService pcepService2 = mock(NetworkTopologyPcepService.class, "Second pcep Service");
57 assertNotNull(getBroker());
59 final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
60 new TopologyKey(getTopologyId("Topo1"))).toInstance();
62 BindingAwareProvider provider1 = new AbstractTestProvider() {
65 public void onSessionInitiated(final BindingAwareBroker.ProviderContext session) {
66 assertNotNull(session);
67 BindingAwareBroker.RoutedRpcRegistration<NetworkTopologyPcepService> firstReg = session.addRoutedRpcImplementation(
68 NetworkTopologyPcepService.class, pcepService1);
69 assertNotNull("Registration should not be null", firstReg);
70 assertSame(pcepService1, firstReg.getInstance());
72 firstReg.registerPath(NetworkTopologyContext.class, topology);
76 broker.registerProvider(provider1, getBundleContext());
78 final InstanceIdentifier<Topology> topology2 = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
79 new TopologyKey(getTopologyId("Topo2"))).toInstance();
81 BindingAwareProvider provider2 = new AbstractTestProvider() {
84 public void onSessionInitiated(final BindingAwareBroker.ProviderContext session) {
85 assertNotNull(session);
86 BindingAwareBroker.RoutedRpcRegistration<NetworkTopologyPcepService> secondReg = session.addRoutedRpcImplementation(
87 NetworkTopologyPcepService.class, pcepService2);
88 secondReg.registerPath(NetworkTopologyContext.class, topology2);
92 broker.registerProvider(provider2, getBundleContext());
94 BindingAwareConsumer consumer = new BindingAwareConsumer() {
96 public void onSessionInitialized(final BindingAwareBroker.ConsumerContext session) {
97 NetworkTopologyPcepService consumerPcepService = session.getRpcService(NetworkTopologyPcepService.class);
99 assertNotNull(consumerPcepService);
100 assertNotSame(pcepService1, consumerPcepService);
101 assertNotSame(pcepService2, consumerPcepService);
103 testAddLspRpce(consumerPcepService);
104 testEnsureLspRpce(consumerPcepService);
107 private void testAddLspRpce(NetworkTopologyPcepService consumerPcepService) {
108 AddLspInput addLspInput = getInputForRpc(topology, AddLspInputBuilder.class, AddLspInput.class);
109 consumerPcepService.addLsp(addLspInput);
111 verify(pcepService1).addLsp(addLspInput);
112 verifyZeroInteractions(pcepService2);
114 addLspInput = getInputForRpc(topology2, AddLspInputBuilder.class, AddLspInput.class);
116 consumerPcepService.addLsp(addLspInput);
118 verifyZeroInteractions(pcepService1);
119 verify(pcepService2).addLsp(addLspInput);
122 private void testEnsureLspRpce(NetworkTopologyPcepService consumerPcepService) {
123 EnsureLspOperationalInput ensureInput = getInputForRpc(topology, EnsureLspOperationalInputBuilder.class,
124 EnsureLspOperationalInput.class);
126 consumerPcepService.ensureLspOperational(ensureInput);
128 verify(pcepService1).ensureLspOperational(ensureInput);
129 verifyZeroInteractions(pcepService2);
131 ensureInput = getInputForRpc(topology2, EnsureLspOperationalInputBuilder.class, EnsureLspOperationalInput.class);
133 consumerPcepService.ensureLspOperational(ensureInput);
135 verifyZeroInteractions(pcepService1);
136 verify(pcepService2).ensureLspOperational(ensureInput);
139 broker.registerConsumer(consumer, getBundleContext());
142 private static <T> T getInputForRpc(final InstanceIdentifier<Topology> topology, Class<?> builderClass, Class<T> builtObjectClass) {
144 Object builderInstance = builderClass.newInstance();
145 Method method = builderClass.getMethod("setNetworkTopologyRef", NetworkTopologyRef.class);
146 method.invoke(builderInstance, new NetworkTopologyRef(topology));
147 return builtObjectClass.cast(builderClass.getMethod("build").invoke(builderInstance));
148 } catch (Exception e) {
149 throw new RuntimeException("Unable to create instance from " + builderClass, e);
154 public void testRoutedRpcNetworkTopologyPcepProgrammingService() throws Exception {
155 final NetworkTopologyPcepProgrammingService pcepService1 = mock(NetworkTopologyPcepProgrammingService.class,
156 "First pcep program Service");
157 final NetworkTopologyPcepProgrammingService pcepService2 = mock(NetworkTopologyPcepProgrammingService.class,
158 "Second pcep program Service");
160 assertNotNull(getBroker());
162 final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
163 new TopologyKey(getTopologyId("Topo1"))).toInstance();
165 BindingAwareProvider provider1 = new AbstractTestProvider() {
168 public void onSessionInitiated(final BindingAwareBroker.ProviderContext session) {
169 assertNotNull(session);
170 BindingAwareBroker.RoutedRpcRegistration<NetworkTopologyPcepProgrammingService> firstReg = session.addRoutedRpcImplementation(
171 NetworkTopologyPcepProgrammingService.class, pcepService1);
172 assertNotNull("Registration should not be null", firstReg);
173 assertSame(pcepService1, firstReg.getInstance());
175 firstReg.registerPath(NetworkTopologyContext.class, topology);
179 broker.registerProvider(provider1, getBundleContext());
181 final InstanceIdentifier<Topology> topology2 = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
182 new TopologyKey(getTopologyId("Topo2"))).toInstance();
184 BindingAwareProvider provider2 = new AbstractTestProvider() {
187 public void onSessionInitiated(final BindingAwareBroker.ProviderContext session) {
188 assertNotNull(session);
189 BindingAwareBroker.RoutedRpcRegistration<NetworkTopologyPcepProgrammingService> secondReg = session.addRoutedRpcImplementation(
190 NetworkTopologyPcepProgrammingService.class, pcepService2);
191 secondReg.registerPath(NetworkTopologyContext.class, topology2);
195 broker.registerProvider(provider2, getBundleContext());
197 BindingAwareConsumer consumer = new BindingAwareConsumer() {
199 public void onSessionInitialized(final BindingAwareBroker.ConsumerContext session) {
200 NetworkTopologyPcepProgrammingService consumerPcepService = session.getRpcService(NetworkTopologyPcepProgrammingService.class);
202 assertNotNull(consumerPcepService);
203 assertNotSame(pcepService1, consumerPcepService);
204 assertNotSame(pcepService2, consumerPcepService);
206 testSubmitAddLspRpc(consumerPcepService);
207 testSubmitUpdateLspRpc(consumerPcepService);
210 private void testSubmitAddLspRpc(NetworkTopologyPcepProgrammingService consumerPcepService) {
211 SubmitAddLspInput addLspInput = getInputForRpc(topology, SubmitAddLspInputBuilder.class, SubmitAddLspInput.class);
212 consumerPcepService.submitAddLsp(addLspInput);
214 verify(pcepService1).submitAddLsp(addLspInput);
215 verifyZeroInteractions(pcepService2);
217 addLspInput = getInputForRpc(topology2, SubmitAddLspInputBuilder.class, SubmitAddLspInput.class);
219 consumerPcepService.submitAddLsp(addLspInput);
221 verifyZeroInteractions(pcepService1);
222 verify(pcepService2).submitAddLsp(addLspInput);
225 private void testSubmitUpdateLspRpc(NetworkTopologyPcepProgrammingService consumerPcepService) {
226 SubmitUpdateLspInput submitLspInput = getInputForRpc(topology, SubmitUpdateLspInputBuilder.class,
227 SubmitUpdateLspInput.class);
228 consumerPcepService.submitUpdateLsp(submitLspInput);
230 verify(pcepService1).submitUpdateLsp(submitLspInput);
231 verifyZeroInteractions(pcepService2);
233 submitLspInput = getInputForRpc(topology2, SubmitUpdateLspInputBuilder.class, SubmitUpdateLspInput.class);
235 consumerPcepService.submitUpdateLsp(submitLspInput);
237 verifyZeroInteractions(pcepService1);
238 verify(pcepService2).submitUpdateLsp(submitLspInput);
241 broker.registerConsumer(consumer, getBundleContext());
245 public void testRoutedRpcTopologyTunnelPcepProgrammingService() throws Exception {
246 final TopologyTunnelPcepProgrammingService pcepService1 = mock(TopologyTunnelPcepProgrammingService.class,
247 "First pcep program Service");
248 final TopologyTunnelPcepProgrammingService pcepService2 = mock(TopologyTunnelPcepProgrammingService.class,
249 "Second pcep program Service");
251 assertNotNull(getBroker());
253 final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
254 new TopologyKey(getTopologyId("Topo1"))).toInstance();
256 BindingAwareProvider provider1 = new AbstractTestProvider() {
259 public void onSessionInitiated(final BindingAwareBroker.ProviderContext session) {
260 assertNotNull(session);
261 BindingAwareBroker.RoutedRpcRegistration<TopologyTunnelPcepProgrammingService> firstReg = session.addRoutedRpcImplementation(
262 TopologyTunnelPcepProgrammingService.class, pcepService1);
263 assertNotNull("Registration should not be null", firstReg);
264 assertSame(pcepService1, firstReg.getInstance());
266 firstReg.registerPath(NetworkTopologyContext.class, topology);
270 broker.registerProvider(provider1, getBundleContext());
272 final InstanceIdentifier<Topology> topology2 = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
273 new TopologyKey(getTopologyId("Topo2"))).toInstance();
275 BindingAwareProvider provider2 = new AbstractTestProvider() {
278 public void onSessionInitiated(final BindingAwareBroker.ProviderContext session) {
279 assertNotNull(session);
280 BindingAwareBroker.RoutedRpcRegistration<TopologyTunnelPcepProgrammingService> secondReg = session.addRoutedRpcImplementation(
281 TopologyTunnelPcepProgrammingService.class, pcepService2);
282 secondReg.registerPath(NetworkTopologyContext.class, topology2);
286 broker.registerProvider(provider2, getBundleContext());
288 BindingAwareConsumer consumer = new BindingAwareConsumer() {
290 public void onSessionInitialized(final BindingAwareBroker.ConsumerContext session) {
291 TopologyTunnelPcepProgrammingService consumerPcepService = session.getRpcService(TopologyTunnelPcepProgrammingService.class);
293 assertNotNull(consumerPcepService);
294 assertNotSame(pcepService1, consumerPcepService);
295 assertNotSame(pcepService2, consumerPcepService);
297 testCreateP2pTunnel(consumerPcepService);
298 testDestroyP2pTunnel(consumerPcepService);
301 private void testCreateP2pTunnel(TopologyTunnelPcepProgrammingService consumerPcepService) {
302 PcepCreateP2pTunnelInput addLspInput = getInputForRpc(topology, PcepCreateP2pTunnelInputBuilder.class,
303 PcepCreateP2pTunnelInput.class);
304 consumerPcepService.pcepCreateP2pTunnel(addLspInput);
306 verify(pcepService1).pcepCreateP2pTunnel(addLspInput);
307 verifyZeroInteractions(pcepService2);
309 addLspInput = getInputForRpc(topology2, PcepCreateP2pTunnelInputBuilder.class, PcepCreateP2pTunnelInput.class);
311 consumerPcepService.pcepCreateP2pTunnel(addLspInput);
313 verifyZeroInteractions(pcepService1);
314 verify(pcepService2).pcepCreateP2pTunnel(addLspInput);
317 private void testDestroyP2pTunnel(TopologyTunnelPcepProgrammingService consumerPcepService) {
318 PcepDestroyTunnelInput addLspInput = getInputForRpc(topology, PcepDestroyTunnelInputBuilder.class,
319 PcepDestroyTunnelInput.class);
320 consumerPcepService.pcepDestroyTunnel(addLspInput);
322 verify(pcepService1).pcepDestroyTunnel(addLspInput);
323 verifyZeroInteractions(pcepService2);
325 addLspInput = getInputForRpc(topology2, PcepDestroyTunnelInputBuilder.class, PcepDestroyTunnelInput.class);
327 consumerPcepService.pcepDestroyTunnel(addLspInput);
329 verifyZeroInteractions(pcepService1);
330 verify(pcepService2).pcepDestroyTunnel(addLspInput);
333 broker.registerConsumer(consumer, getBundleContext());