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
8 package org.opendaylight.protocol.bgp.benchmark.app;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.mockito.Mockito.doNothing;
13 import static org.mockito.Mockito.doReturn;
14 import static org.opendaylight.protocol.util.CheckTestUtil.checkEquals;
15 import static org.opendaylight.protocol.util.CheckTestUtil.checkNotPresentConfiguration;
16 import static org.opendaylight.protocol.util.CheckTestUtil.readDataConfiguration;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.Mock;
21 import org.mockito.Mockito;
22 import org.mockito.MockitoAnnotations;
23 import org.opendaylight.mdsal.binding.api.RpcProviderService;
24 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev180329.ipv4.routes.Ipv4Routes;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.AddPrefixInput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.AddPrefixInputBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.AddPrefixOutput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.DeletePrefixInput;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.DeletePrefixInputBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.DeletePrefixOutput;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.OdlBgpAppPeerBenchmarkService;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.odl.bgp.app.peer.benchmark.rev160309.output.Result;
36 import org.opendaylight.yangtools.concepts.ObjectRegistration;
37 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
38 import org.opendaylight.yangtools.yang.common.RpcResult;
39 import org.opendaylight.yangtools.yang.common.Uint32;
41 public class AppPeerBenchmarkTest extends AbstractConcurrentDataBrokerTest {
43 private static final String PREFIX = "1.1.1.1/32";
44 private static final String NH = "127.0.0.1";
45 private static final String PEER_RIB_ID = "app-peer";
48 private RpcProviderService rpcRegistry;
50 private ObjectRegistration<OdlBgpAppPeerBenchmarkService> registration;
54 MockitoAnnotations.initMocks(this);
55 doReturn(this.registration).when(this.rpcRegistry).registerRpcImplementation(Mockito.any(),
56 Mockito.any(OdlBgpAppPeerBenchmarkService.class));
57 doNothing().when(this.registration).close();
61 public void testRpcs() throws Exception {
62 final AppPeerBenchmark appPeerBenchmark = new AppPeerBenchmark(getDataBroker(), this.rpcRegistry, PEER_RIB_ID);
63 appPeerBenchmark.start();
64 final InstanceIdentifier<Ipv4Routes> routesIID = appPeerBenchmark.getIpv4RoutesIID();
66 final AddPrefixInput addPrefix = new AddPrefixInputBuilder().setBatchsize(Uint32.ONE).setCount(Uint32.ONE)
67 .setNexthop(new Ipv4Address(NH)).setPrefix(new Ipv4Prefix(PREFIX)).build();
69 final RpcResult<AddPrefixOutput> addRpcResult = appPeerBenchmark.addPrefix(addPrefix).get();
70 final Result addResult = addRpcResult.getResult().getResult();
71 checkEquals(() -> assertEquals(1, addResult.getCount().intValue()));
72 checkEquals(() -> assertEquals(1, addResult.getRate().intValue()));
74 readDataConfiguration(getDataBroker(), routesIID, routes -> {
75 assertNotNull(routes.getIpv4Route());
76 assertEquals(1, routes.getIpv4Route().size());
80 final DeletePrefixInput deletePrefix = new DeletePrefixInputBuilder().setBatchsize(Uint32.ONE)
81 .setCount(Uint32.ONE).setPrefix(new Ipv4Prefix(PREFIX)).build();
82 final RpcResult<DeletePrefixOutput> deleteRpcResult = appPeerBenchmark
83 .deletePrefix(deletePrefix).get();
84 final Result deleteResult = deleteRpcResult.getResult().getResult();
85 checkEquals(() -> assertEquals(1, deleteResult.getCount().intValue()));
86 checkEquals(() -> assertEquals(1, deleteResult.getRate().intValue()));
88 checkNotPresentConfiguration(getDataBroker(), appPeerBenchmark.getIpv4RoutesIID());
90 appPeerBenchmark.close();