2 * Copyright (c) 2014 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.rib.impl;
11 import static org.opendaylight.protocol.bgp.rib.impl.CheckUtil.checkIdleState;
13 import com.google.common.collect.Sets;
14 import io.netty.channel.Channel;
15 import io.netty.util.concurrent.Future;
16 import java.net.InetSocketAddress;
17 import java.util.concurrent.ExecutionException;
18 import org.junit.Assert;
19 import org.junit.Test;
20 import org.opendaylight.protocol.bgp.rib.spi.State;
21 import org.opendaylight.protocol.concepts.KeyMapping;
22 import org.opendaylight.protocol.util.InetSocketAddressUtil;
24 public class BGPDispatcherImplTest extends AbstractBGPDispatcherTest {
25 @Test(timeout = 20000)
26 public void testCreateClient() throws InterruptedException, ExecutionException {
27 final InetSocketAddress serverAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
28 final Channel serverChannel = createServer(serverAddress);
29 final Future<BGPSessionImpl> futureClient = this.clientDispatcher.createClient(this.clientAddress,
30 serverAddress, 2, true);
32 final BGPSessionImpl session = futureClient.get();
33 Assert.assertEquals(State.UP, this.clientListener.getState());
34 Assert.assertEquals(State.UP, this.serverListener.getState());
35 Assert.assertEquals(AS_NUMBER, session.getAsNumber());
36 Assert.assertEquals(Sets.newHashSet(IPV_4_TT), session.getAdvertisedTableTypes());
37 Assert.assertTrue(serverChannel.isWritable());
39 this.serverListener.releaseConnection();
40 checkIdleState(this.clientListener);
41 checkIdleState(this.serverListener);
45 public void testCreateReconnectingClient() throws Exception {
46 final InetSocketAddress serverAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
47 final Future<Void> future = this.clientDispatcher.createReconnectingClient(serverAddress, RETRY_TIMER,
48 KeyMapping.getKeyMapping(), this.clientAddress, true);
49 final Channel serverChannel = createServer(serverAddress);
50 Assert.assertEquals(State.UP, this.serverListener.getState());
51 Assert.assertTrue(serverChannel.isWritable());
53 this.serverListener.releaseConnection();
54 checkIdleState(this.serverListener);