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