2 * Copyright (c) 2016 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
9 package org.opendaylight.protocol.bgp.benchmark.app;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.mockito.Mockito.doNothing;
15 import static org.mockito.Mockito.doReturn;
16 import static org.opendaylight.protocol.util.CheckUtil.checkEquals;
17 import static org.opendaylight.protocol.util.CheckUtil.readDataConfiguration;
19 import javax.management.MalformedObjectNameException;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.mockito.Mock;
23 import org.mockito.Mockito;
24 import org.mockito.MockitoAnnotations;
25 import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
26 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
27 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
28 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.Ipv4Routes;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.AddPrefixInput;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.AddPrefixInputBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.AddPrefixOutput;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.DeletePrefixInput;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.DeletePrefixInputBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.DeletePrefixOutput;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.OdlBgpAppPeerBenchmarkService;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.output.Result;
40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
41 import org.opendaylight.yangtools.yang.common.RpcResult;
43 public class AppPeerBenchmarkTest extends AbstractConcurrentDataBrokerTest {
45 private static final String PREFIX = "1.1.1.1/32";
46 private static final String NH = "127.0.0.1";
47 private static final String PEER_RIB_ID = "app-peer";
50 private RpcProviderRegistry rpcRegistry;
52 private RoutedRpcRegistration<OdlBgpAppPeerBenchmarkService> registration;
55 public void setUp() throws MalformedObjectNameException, TransactionCommitFailedException {
56 MockitoAnnotations.initMocks(this);
57 doReturn(this.registration).when(this.rpcRegistry).addRpcImplementation(Mockito.any(),
58 Mockito.any(OdlBgpAppPeerBenchmarkService.class));
59 doNothing().when(this.registration).close();
63 public void testRpcs() throws Exception {
64 final AppPeerBenchmark appPeerBenchmark = new AppPeerBenchmark(getDataBroker(), this.rpcRegistry, PEER_RIB_ID);
65 appPeerBenchmark.start();
66 final InstanceIdentifier<Ipv4Routes> routesIID = appPeerBenchmark.getIpv4RoutesIID();
68 final AddPrefixInput addPrefix = new AddPrefixInputBuilder().setBatchsize(1L).setCount(1L)
69 .setNexthop(new Ipv4Address(NH)).setPrefix(new Ipv4Prefix(PREFIX)).build();
71 final RpcResult<AddPrefixOutput> addRpcResult = appPeerBenchmark.addPrefix(addPrefix).get();
72 final Result addResult = addRpcResult.getResult().getResult();
73 checkEquals(() -> assertEquals(1, addResult.getCount().intValue()));
74 checkEquals(() -> assertEquals(1, addResult.getRate().intValue()));
76 readDataConfiguration(getDataBroker(), routesIID, routes -> {
77 assertNotNull(routes.getIpv4Route());
78 assertEquals(1, routes.getIpv4Route().size());
82 final DeletePrefixInput deletePrefix = new DeletePrefixInputBuilder().setBatchsize(1L).setCount(1L)
83 .setPrefix(new Ipv4Prefix(PREFIX)).build();
84 final RpcResult<DeletePrefixOutput> deleteRpcResult = appPeerBenchmark
85 .deletePrefix(deletePrefix).get();
86 final Result deleteResult = deleteRpcResult.getResult().getResult();
87 checkEquals(() -> assertEquals(1, deleteResult.getCount().intValue()));
88 checkEquals(() -> assertEquals(1, deleteResult.getRate().intValue()));
89 readDataConfiguration(getDataBroker(), routesIID, routes -> {
90 assertNotNull(routes.getIpv4Route());
91 assertTrue(routes.getIpv4Route().isEmpty());
95 appPeerBenchmark.close();