private static final int CONNECT_TIMEOUT = 5000;
private static final int INITIAL_BACKOFF = 30_000;
private static final int MAXIMUM_BACKOFF = 720_000;
+ private static final long TIMEOUT = 10;
private final BmpHandlerFactory hf;
private final EventLoopGroup bossGroup;
@Override
public void close() {
if (Epoll.isAvailable()) {
- this.workerGroup.shutdownGracefully().awaitUninterruptibly();
- this.bossGroup.shutdownGracefully().awaitUninterruptibly();
+ this.workerGroup.shutdownGracefully(0, TIMEOUT, TimeUnit.SECONDS);
+ this.bossGroup.shutdownGracefully(0, TIMEOUT, TimeUnit.SECONDS);
}
}
return;
}
final EventLoop loop = cf.channel().eventLoop();
- loop.schedule(() -> BootstrapListener.this.bootstrap.connect().addListener(BootstrapListener.this), this.delay, TimeUnit.MILLISECONDS);
+ loop.schedule(() -> this.bootstrap.connect().addListener(this), this.delay, TimeUnit.MILLISECONDS);
LOG.info("The connection try to BMP router {} failed. Next reconnection attempt in {} milliseconds.", this.address, this.delay);
this.delay *= 2;
}
@Override
public void onFailure(final Throwable throwable) {
- LOG.error("Failed to register Application Peer Listener", throwable);
+ if(registerAppPeerListener != null) {
+ LOG.error("Failed to create Empty Structure, Application Peer Listener won't be registered",
+ throwable);
+ } else {
+ LOG.error("Failed to create Empty Structure", throwable);
+ }
}
});
return new AdjRibInWriter(this.ribPath, this.chain, this.role, this.simpleRoutingPolicy, newPeerPath, tb);
import io.netty.util.concurrent.GlobalEventExecutor;
import io.netty.util.concurrent.Promise;
import java.net.InetSocketAddress;
+import java.util.concurrent.TimeUnit;
import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
import org.opendaylight.protocol.bgp.rib.impl.protocol.BGPProtocolSessionPromise;
import org.opendaylight.protocol.bgp.rib.impl.protocol.BGPReconnectPromise;
private static final int SOCKET_BACKLOG_SIZE = 128;
private static final int HIGH_WATER_MARK = 256 * 1024;
private static final int LOW_WATER_MARK = 128 * 1024;
+ private static final long TIMEOUT = 10;
private final BGPHandlerFactory handlerFactory;
private final EventLoopGroup bossGroup;
private synchronized Future<BGPSessionImpl> createClient(final InetSocketAddress remoteAddress, final BGPPeerRegistry listener, final int retryTimer,
final Bootstrap clientBootStrap) {
final BGPClientSessionNegotiatorFactory snf = new BGPClientSessionNegotiatorFactory(listener);
- final ChannelPipelineInitializer initializer = BGPChannel.createChannelPipelineInitializer(BGPDispatcherImpl.this.handlerFactory, snf);
+ final ChannelPipelineInitializer initializer = BGPChannel.createChannelPipelineInitializer(this.handlerFactory, snf);
final BGPProtocolSessionPromise sessionPromise = new BGPProtocolSessionPromise(remoteAddress, retryTimer, clientBootStrap, listener);
clientBootStrap.handler(BGPChannel.createClientChannelHandler(initializer, sessionPromise));
}
@Override
- public synchronized void close() {
+ public synchronized void close() throws InterruptedException {
if (Epoll.isAvailable()) {
- this.workerGroup.shutdownGracefully().awaitUninterruptibly();
- this.bossGroup.shutdownGracefully().awaitUninterruptibly();
+ LOG.debug("Closing Dispatcher");
+ this.workerGroup.shutdownGracefully(0, TIMEOUT, TimeUnit.SECONDS);
+ this.bossGroup.shutdownGracefully(0, TIMEOUT, TimeUnit.SECONDS);
}
}
final Bootstrap bootstrap = createClientBootStrap(keys, reuseAddress);
bootstrap.localAddress(localAddress);
final BGPReconnectPromise reconnectPromise = new BGPReconnectPromise(GlobalEventExecutor.INSTANCE, remoteAddress,
- retryTimer, bootstrap, peerRegistry, BGPChannel.createChannelPipelineInitializer(BGPDispatcherImpl.this.handlerFactory, snf));
+ retryTimer, bootstrap, peerRegistry, BGPChannel.createChannelPipelineInitializer(this.handlerFactory, snf));
reconnectPromise.connect();
return reconnectPromise;
}
@Override
public synchronized ChannelFuture createServer(final BGPPeerRegistry registry, final InetSocketAddress serverAddress) {
final BGPServerSessionNegotiatorFactory snf = new BGPServerSessionNegotiatorFactory(registry);
- final ChannelPipelineInitializer initializer = BGPChannel.createChannelPipelineInitializer(BGPDispatcherImpl.this.handlerFactory, snf);
+ final ChannelPipelineInitializer initializer = BGPChannel.createChannelPipelineInitializer(this.handlerFactory, snf);
final ServerBootstrap serverBootstrap = createServerBootstrap(initializer);
final ChannelFuture channelFuture = serverBootstrap.bind(serverAddress);
LOG.debug("Initiated server {} at {}.", channelFuture, serverAddress);
import static org.opendaylight.protocol.bgp.rib.impl.CheckUtil.waitFutureSuccess;
import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.net.InetAddresses;
import io.netty.channel.epoll.Epoll;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
import javassist.ClassPool;
import org.junit.After;
import org.junit.Assert;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
import org.opendaylight.protocol.bgp.inet.RIBActivator;
import org.opendaylight.protocol.bgp.parser.BGPError;
+import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
import org.opendaylight.protocol.bgp.parser.impl.BGPActivator;
import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.message.WithdrawnRoutesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.Attributes1Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.CParameters1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.CParameters1Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.SendReceive;
static final Update UPD_200 = createSimpleUpdate(PREFIX1, new PathId(3L), CLUSTER_ID, 200);
static final Update UPD_20 = createSimpleUpdate(PREFIX1, new PathId(1L), CLUSTER_ID, 20);
static final Update UPD_NA_100 = createSimpleUpdate(PREFIX1, null, CLUSTER_ID, 100);
- static final Update UPD_NA_100_EBGP = createSimpleUpdateEbgp(PREFIX1, null);
+ static final Update UPD_NA_100_EBGP = createSimpleUpdateEbgp(PREFIX1);
static final Update UPD_NA_200 = createSimpleUpdate(PREFIX1, null, CLUSTER_ID, 200);
- static final Update UPD_NA_200_EBGP = createSimpleUpdateEbgp(PREFIX1, null);
+ static final Update UPD_NA_200_EBGP = createSimpleUpdateEbgp(PREFIX1);
static final TablesKey TABLES_KEY = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+ static final List<BgpTableType> TABLES_TYPE = ImmutableList.of(new BgpTableTypeImpl(TABLES_KEY.getAfi(),
+ TABLES_KEY.getSafi()));
static final Set<TablesKey> AFI_SAFIS_ADVERTIZED = Collections.singleton(TABLES_KEY);
- protected BGPExtensionProviderContext context;
+ private BGPExtensionProviderContext context;
private static final InstanceIdentifier<BgpRib> BGP_IID = InstanceIdentifier.create(BgpRib.class);
protected SchemaContext schemaContext;
@Mock
this.bgpActivator.start(this.context);
this.inetActivator.start(this.context);
- this.mappingService = new BindingToNormalizedNodeCodec(GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(),
- new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(JavassistUtils.forClassPool(ClassPool.getDefault()))));
+ this.mappingService = new BindingToNormalizedNodeCodec(
+ GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(),
+ new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(
+ JavassistUtils.forClassPool(ClassPool.getDefault()))));
final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(BgpParameters.class));
moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(MultiprotocolCapability.class));
}
@After
- public void tearDown() {
+ public void tearDown() throws ExecutionException, InterruptedException {
this.dispatcher.close();
if (!Epoll.isAvailable()) {
- this.worker.shutdownGracefully().awaitUninterruptibly();
- this.boss.shutdownGracefully().awaitUninterruptibly();
+ this.worker.shutdownGracefully(0, 0, TimeUnit.SECONDS);
+ this.boss.shutdownGracefully(0, 0, TimeUnit.SECONDS);
}
this.mappingService.close();
this.ribActivator.close();
this.bgpActivator.close();
}
- void sendRouteAndCheckIsOnLocRib(final BGPSessionImpl session, final Ipv4Prefix prefix, final long localPreference, final int expectedRoutesOnDS)
- throws Exception {
+ void sendRouteAndCheckIsOnLocRib(final BGPSessionImpl session, final Ipv4Prefix prefix, final long localPreference,
+ final int expectedRoutesOnDS) throws Exception {
waitFutureSuccess(session.writeAndFlush(createSimpleUpdate(prefix, null, null, localPreference)));
checkLocRib(expectedRoutesOnDS);
}
- void sendWithdrawalRouteAndCheckIsOnLocRib(final BGPSessionImpl session, final Ipv4Prefix prefix, final long localPreference, final int expectedRoutesOnDS)
- throws Exception {
+ void sendWithdrawalRouteAndCheckIsOnLocRib(final BGPSessionImpl session, final Ipv4Prefix prefix,
+ final long localPreference, final int expectedRoutesOnDS) throws Exception {
waitFutureSuccess(session.writeAndFlush(createSimpleWithdrawalUpdate(prefix, localPreference)));
checkLocRib(expectedRoutesOnDS);
}
void sendNotification(final BGPSessionImpl session) {
- Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode()).setErrorSubcode(
- BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
+ final Notification notMsg = new NotifyBuilder().setErrorCode(BGPError.OPT_PARAM_NOT_SUPPORTED.getCode())
+ .setErrorSubcode(BGPError.OPT_PARAM_NOT_SUPPORTED.getSubcode()).setData(new byte[] { 4, 9 }).build();
waitFutureSuccess(session.writeAndFlush(notMsg));
}
private void checkLocRib(final int expectedRoutesOnDS) throws Exception {
Thread.sleep(100);
readData(getDataBroker(), BGP_IID, bgpRib -> {
- final Ipv4RoutesCase routes = ((Ipv4RoutesCase) bgpRib.getRib().get(0).getLocRib().getTables().get(0).getRoutes());
+ final Ipv4RoutesCase routes = ((Ipv4RoutesCase) bgpRib.getRib().get(0).getLocRib().getTables().get(0)
+ .getRoutes());
final List<Ipv4Route> routeList = routes.getIpv4Routes().getIpv4Route();
Assert.assertEquals(expectedRoutesOnDS, routeList.size());
return bgpRib;
return new UpdateBuilder().setAttributes(attBuilder.build()).build();
}
- private static Update createSimpleUpdateEbgp(final Ipv4Prefix prefix, final PathId pathId) {
+ private static Update createSimpleUpdateEbgp(final Ipv4Prefix prefix) {
final AttributesBuilder attBuilder = new AttributesBuilder();
attBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.singletonList(
new SegmentsBuilder().setAsSequence(Collections.singletonList(AS_NUMBER)).build())).build());
- addAttributeAugmentation(attBuilder, prefix, pathId);
+ addAttributeAugmentation(attBuilder, prefix, null);
return new UpdateBuilder().setAttributes(attBuilder.build()).build();
}
- private static void addAttributeAugmentation(final AttributesBuilder attBuilder, final Ipv4Prefix prefix, final PathId pathId) {
+ private static void addAttributeAugmentation(final AttributesBuilder attBuilder, final Ipv4Prefix prefix,
+ final PathId pathId) {
attBuilder.setUnrecognizedAttributes(Collections.emptyList());
attBuilder.addAugmentation(Attributes1.class,
new Attributes1Builder().setMpReachNlri(
new MpReachNlriBuilder()
- .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(NH1).build()).build())
+ .setCNextHop(new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(NH1)
+ .build()).build())
.setAfi(Ipv4AddressFamily.class)
.setSafi(UnicastSubsequentAddressFamily.class)
.setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
new DestinationIpv4CaseBuilder().setDestinationIpv4(
new DestinationIpv4Builder().setIpv4Prefixes(Collections.singletonList(
- new Ipv4PrefixesBuilder().setPathId(pathId).setPrefix(new Ipv4Prefix(prefix)).build())).build())
+ new Ipv4PrefixesBuilder().setPathId(pathId).setPrefix(new Ipv4Prefix(prefix)).build()))
+ .build())
.build()).build())
.build()).build());
}
attBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build());
attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
attBuilder.setUnrecognizedAttributes(Collections.emptyList());
- return new UpdateBuilder().setWithdrawnRoutes(new WithdrawnRoutesBuilder().setWithdrawnRoutes(Collections.singletonList(prefix)).build()).build();
+ return new UpdateBuilder().setWithdrawnRoutes(new WithdrawnRoutesBuilder()
+ .setWithdrawnRoutes(Collections.singletonList(prefix)).build()).build();
}
}
this.serverDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker);
this.clientAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
- final IpAddress clientPeerIp = new IpAddress(new Ipv4Address(clientAddress.getAddress().getHostAddress()));
- this.registry.addPeer(clientPeerIp, this.clientListener, createPreferences(clientAddress));
+ final IpAddress clientPeerIp = new IpAddress(new Ipv4Address(this.clientAddress.getAddress().getHostAddress()));
+ this.registry.addPeer(clientPeerIp, this.clientListener, createPreferences(this.clientAddress));
this.clientDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker);
}
this.serverDispatcher.close();
this.registry.close();
if (!Epoll.isAvailable()) {
- this.worker.shutdownGracefully().awaitUninterruptibly();
- this.boss.shutdownGracefully().awaitUninterruptibly();
- }
- }
-
- private void configureClient(final BGPExtensionProviderContext ctx) {
- final InetSocketAddress clientAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
- final IpAddress clientPeerIp = new IpAddress(new Ipv4Address(clientAddress.getAddress().getHostAddress()));
- this.registry.addPeer(clientPeerIp, this.clientListener, createPreferences(clientAddress));
- this.clientDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker);
- if (!Epoll.isAvailable()) {
- this.worker.shutdownGracefully().awaitUninterruptibly();
- this.boss.shutdownGracefully().awaitUninterruptibly();
+ this.worker.shutdownGracefully(0, 0, TimeUnit.SECONDS);;
+ this.boss.shutdownGracefully(0, 0, TimeUnit.SECONDS);;
}
}
}
public static void checkIdleState(final SimpleSessionListener listener) {
- Stopwatch sw = Stopwatch.createStarted();
+ final Stopwatch sw = Stopwatch.createStarted();
while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
if (State.IDLE != listener.getState()) {
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.Uninterruptibles;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
+import org.junit.After;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
import org.opendaylight.protocol.bgp.mode.impl.add.all.paths.AllPathSelection;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
public class AddPathAllPathsTest extends AbstractAddPathTest {
+ private RIBImpl ribImpl;
+ private Channel serverChannel;
+
@FunctionalInterface
private interface CheckEquals {
void check();
}
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY, new AllPathSelection());
+
+ this.ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"),
+ AS_NUMBER, BGP_ID, null, this.ribExtension, this.dispatcher, this.mappingService.getCodecFactory(),
+ getDomBroker(), TABLES_TYPE, pathTables, this.ribExtension.getClassLoadingStrategy(), null);
+
+ this.ribImpl.instantiateServiceInstance();
+ this.ribImpl.onGlobalContextUpdated(this.schemaContext);
+ final ChannelFuture channelFuture = this.dispatcher.createServer(StrictBGPPeerRegistry.GLOBAL,
+ new InetSocketAddress(RIB_ID, PORT));
+ waitFutureSuccess(channelFuture);
+ this.serverChannel = channelFuture.channel();
+ }
+
+ @After
+ public void tearDown() throws ExecutionException, InterruptedException {
+ waitFutureSuccess(this.serverChannel.close());
+ super.tearDown();
+ }
/*
* All-Paths
* ___________________
*/
@Test
public void testUseCase1() throws Exception {
-
- final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
- final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(TABLES_KEY, new AllPathSelection());
-
-
- final RIBImpl ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"), AS_NUMBER, BGP_ID, null, this.ribExtension,
- this.dispatcher, this.mappingService.getCodecFactory(), getDomBroker(), tables, pathTables, this.ribExtension.getClassLoadingStrategy(), null);
-
- ribImpl.instantiateServiceInstance();
- ribImpl.onGlobalContextUpdated(this.schemaContext);
-
- waitFutureSuccess(this.dispatcher.createServer(StrictBGPPeerRegistry.GLOBAL, new InetSocketAddress(RIB_ID, PORT)));
final BgpParameters nonAddPathParams = createParameter(false);
final BgpParameters addPathParams = createParameter(true);
- final BGPPeer peer1 = configurePeer(PEER1, ribImpl, nonAddPathParams, PeerRole.Ibgp);
+ final BGPPeer peer1 = configurePeer(PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
final BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
- configurePeer(PEER2, ribImpl, nonAddPathParams, PeerRole.Ibgp);
+ configurePeer(PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
- configurePeer(PEER3, ribImpl, nonAddPathParams, PeerRole.Ibgp);
+ configurePeer(PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
final BGPSessionImpl session3 = createPeerSession(PEER3, nonAddPathParams, new SimpleSessionListener());
final SimpleSessionListener listener4 = new SimpleSessionListener();
- final BGPPeer peer4 = configurePeer(PEER4, ribImpl, nonAddPathParams, PeerRole.RrClient);
+ final BGPPeer peer4 = configurePeer(PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
BGPPeerState peer4State = peer4.getPeerState();
assertNull(peer4State.getGroupId());
final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
final SimpleSessionListener listener5 = new SimpleSessionListener();
- configurePeer(PEER5, ribImpl, addPathParams, PeerRole.RrClient);
+ configurePeer(PEER5, this.ribImpl, addPathParams, PeerRole.RrClient);
final BGPSessionImpl session5 = createPeerSession(PEER5, addPathParams, listener5);
checkPeersPresentOnDataStore(5);
assertFalse(afiSafiStatePeer1.isPeerRestarting());
assertTrue(afiSafiStatePeer1.isAfiSafiSupported(TABLES_KEY));
- final BGPRIBState ribState = ribImpl.getRIBState();
+ final BGPRIBState ribState = this.ribImpl.getRIBState();
assertEquals(1, ribState.getPathsCount().size());
assertEquals(1L, ribState.getPrefixesCount().size());
assertEquals(BGP_ID, ribState.getRouteId());
assertEquals(1L, ribState.getTotalPrefixesCount());
final SimpleSessionListener listener6 = new SimpleSessionListener();
- final BGPPeer peer6 = configurePeer(PEER6, ribImpl, nonAddPathParams, PeerRole.RrClient);
+ final BGPPeer peer6 = configurePeer(PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
checkPeersPresentOnDataStore(6);
checkReceivedMessages(listener6, 1);
private static void checkEquals(final CheckEquals function) throws Exception {
AssertionError lastError = null;
- Stopwatch sw = Stopwatch.createStarted();
+ final Stopwatch sw = Stopwatch.createStarted();
while (sw.elapsed(TimeUnit.SECONDS) <= 10) {
try {
function.check();
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
import org.opendaylight.protocol.bgp.mode.impl.base.BasePathSelectionModeFactory;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
public class AddPathBasePathsTest extends AbstractAddPathTest {
+ private RIBImpl ribImpl;
+ private Channel serverChannel;
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ final TablesKey tk = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+ final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(tk,
+ BasePathSelectionModeFactory.createBestPathSelectionStrategy());
+
+ this.ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"),
+ AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension, this.dispatcher,
+ this.mappingService.getCodecFactory(), getDomBroker(), TABLES_TYPE, pathTables,
+ this.ribExtension.getClassLoadingStrategy(), null);
+ this.ribImpl.instantiateServiceInstance();
+ this.ribImpl.onGlobalContextUpdated(this.schemaContext);
+ final ChannelFuture channelFuture = this.dispatcher.createServer(StrictBGPPeerRegistry.GLOBAL,
+ new InetSocketAddress(RIB_ID, PORT));
+ waitFutureSuccess(channelFuture);
+ this.serverChannel = channelFuture.channel();
+ }
+
+ @After
+ public void tearDown() throws ExecutionException, InterruptedException {
+ waitFutureSuccess(this.serverChannel.close());
+ super.tearDown();
+ }
/*
* Base-Paths
* ___________________
*/
@Test
public void testUseCase1() throws Exception {
-
- final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
- final TablesKey tk = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
- final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(tk, BasePathSelectionModeFactory.createBestPathSelectionStrategy());
-
- final RIBImpl ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"), AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension,
- this.dispatcher, this.mappingService.getCodecFactory(), getDomBroker(), tables, pathTables, this.ribExtension.getClassLoadingStrategy(), null);
-
- ribImpl.instantiateServiceInstance();
- ribImpl.onGlobalContextUpdated(this.schemaContext);
-
- waitFutureSuccess(this.dispatcher.createServer(StrictBGPPeerRegistry.GLOBAL, new InetSocketAddress(RIB_ID, PORT)));
final BgpParameters nonAddPathParams = createParameter(false);
- configurePeer(PEER1, ribImpl, nonAddPathParams, PeerRole.Ibgp);
+ configurePeer(PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
final BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
- configurePeer(PEER2, ribImpl, nonAddPathParams, PeerRole.Ibgp);
+ configurePeer(PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
- configurePeer(PEER3, ribImpl, nonAddPathParams, PeerRole.Ibgp);
+ configurePeer(PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
final BGPSessionImpl session3 = createPeerSession(PEER3,nonAddPathParams, new SimpleSessionListener());
final SimpleSessionListener listener4 = new SimpleSessionListener();
- configurePeer(PEER4, ribImpl, nonAddPathParams, PeerRole.RrClient);
+ configurePeer(PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
final SimpleSessionListener listener5 = new SimpleSessionListener();
- configurePeer(PEER5, ribImpl, nonAddPathParams, PeerRole.Ebgp);
+ configurePeer(PEER5, this.ribImpl, nonAddPathParams, PeerRole.Ebgp);
final BGPSessionImpl session5 = createPeerSession(PEER5, nonAddPathParams, listener5);
checkPeersPresentOnDataStore(5);
assertEquals(UPD_NA_200_EBGP, listener5.getListMsg().get(1));
final SimpleSessionListener listener6 = new SimpleSessionListener();
- configurePeer(PEER6, ribImpl, nonAddPathParams, PeerRole.RrClient);
+ configurePeer(PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
checkPeersPresentOnDataStore(6);
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
import org.opendaylight.protocol.bgp.mode.impl.add.n.paths.AddPathBestNPathSelection;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
public class AddPathNPathsTest extends AbstractAddPathTest {
+ private RIBImpl ribImpl;
+ private Channel serverChannel;
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ final TablesKey tk = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
+ final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(tk, new AddPathBestNPathSelection(2L));
+
+ this.ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"),
+ AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension, this.dispatcher,
+ this.mappingService.getCodecFactory(), getDomBroker(), TABLES_TYPE, pathTables,
+ this.ribExtension.getClassLoadingStrategy(), null);
+
+ this.ribImpl.instantiateServiceInstance();
+ this.ribImpl.onGlobalContextUpdated(this.schemaContext);
+ final ChannelFuture channelFuture = this.dispatcher.createServer(StrictBGPPeerRegistry.GLOBAL,
+ new InetSocketAddress(RIB_ID, PORT));
+ waitFutureSuccess(channelFuture);
+ this.serverChannel = channelFuture.channel();
+ }
+
+ @After
+ public void tearDown() throws ExecutionException, InterruptedException {
+ waitFutureSuccess(this.serverChannel.close());
+ super.tearDown();
+ }
/*
* N-Paths
* ___________________
*/
@Test
public void testUseCase1() throws Exception {
-
- final List<BgpTableType> tables = ImmutableList.of(new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class));
- final TablesKey tk = new TablesKey(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
- final Map<TablesKey, PathSelectionMode> pathTables = ImmutableMap.of(tk, new AddPathBestNPathSelection(2L));
-
- final RIBImpl ribImpl = new RIBImpl(this.clusterSingletonServiceProvider, new RibId("test-rib"), AS_NUMBER, new BgpId(RIB_ID), null, this.ribExtension,
- this.dispatcher, this.mappingService.getCodecFactory(), getDomBroker(), tables, pathTables, this.ribExtension.getClassLoadingStrategy(), null);
-
- ribImpl.instantiateServiceInstance();
- ribImpl.onGlobalContextUpdated(this.schemaContext);
-
- waitFutureSuccess(this.dispatcher.createServer(StrictBGPPeerRegistry.GLOBAL, new InetSocketAddress(RIB_ID, PORT)));
final BgpParameters nonAddPathParams = createParameter(false);
final BgpParameters addPathParams = createParameter(true);
- configurePeer(PEER1, ribImpl, nonAddPathParams, PeerRole.Ibgp);
+ configurePeer(PEER1, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
final BGPSessionImpl session1 = createPeerSession(PEER1, nonAddPathParams, new SimpleSessionListener());
- configurePeer(PEER2, ribImpl, nonAddPathParams, PeerRole.Ibgp);
+ configurePeer(PEER2, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
final BGPSessionImpl session2 = createPeerSession(PEER2, nonAddPathParams, new SimpleSessionListener());
- configurePeer(PEER3, ribImpl, nonAddPathParams, PeerRole.Ibgp);
+ configurePeer(PEER3, this.ribImpl, nonAddPathParams, PeerRole.Ibgp);
final BGPSessionImpl session3 = createPeerSession(PEER3, nonAddPathParams, new SimpleSessionListener());
final SimpleSessionListener listener4 = new SimpleSessionListener();
- configurePeer(PEER4, ribImpl, nonAddPathParams, PeerRole.RrClient);
+ configurePeer(PEER4, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
final BGPSessionImpl session4 = createPeerSession(PEER4, nonAddPathParams, listener4);
final SimpleSessionListener listener5 = new SimpleSessionListener();
- configurePeer(PEER5, ribImpl, addPathParams, PeerRole.RrClient);
+ configurePeer(PEER5, this.ribImpl, addPathParams, PeerRole.RrClient);
final BGPSessionImpl session5 = createPeerSession(PEER5, addPathParams, listener5);
checkPeersPresentOnDataStore(5);
assertEquals(UPD_100, listener5.getListMsg().get(0));
final SimpleSessionListener listener6 = new SimpleSessionListener();
- configurePeer(PEER6, ribImpl, nonAddPathParams, PeerRole.RrClient);
+ configurePeer(PEER6, this.ribImpl, nonAddPathParams, PeerRole.RrClient);
final BGPSessionImpl session6 = createPeerSession(PEER6, nonAddPathParams, listener6);
checkPeersPresentOnDataStore(6);
checkReceivedMessages(listener6, 1);
private static final int LATCH_TIMEOUT = 10;
private static final int SLEEP_FOR = 20;
private static final int SLEEP_UNINTERRUPTIBLY = 50;
- public static void checkReceivedMessages(final SimpleSessionListener listener, final int numberOfMessages)
+ static void checkReceivedMessages(final SimpleSessionListener listener, final int numberOfMessages)
throws ReadFailedException {
- Stopwatch sw = Stopwatch.createStarted();
+ final Stopwatch sw = Stopwatch.createStarted();
while (sw.elapsed(TimeUnit.SECONDS) <= TIMEOUT) {
if (listener.getListMsg().size() != numberOfMessages) {
Uninterruptibles.sleepUninterruptibly(SLEEP_UNINTERRUPTIBLY, TimeUnit.MILLISECONDS);
Assert.fail();
}
- public static <R, T extends DataObject> R readData(final DataBroker dataBroker, final InstanceIdentifier<T> iid, final Function<T, R> function)
+ public static <R, T extends DataObject> R readData(final DataBroker dataBroker, final InstanceIdentifier<T> iid,
+ final Function<T, R> function)
throws ReadFailedException {
AssertionError lastError = null;
final Stopwatch sw = Stopwatch.createStarted();
import io.netty.util.concurrent.Promise;
import java.io.Closeable;
import java.net.InetSocketAddress;
+import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.protocol.concepts.KeyMapping;
public class PCEPDispatcherImpl implements PCEPDispatcher, Closeable {
private static final Logger LOG = LoggerFactory.getLogger(PCEPDispatcherImpl.class);
private static final Integer SOCKET_BACKLOG_SIZE = 128;
+ private static final long TIMEOUT = 10;
private final PCEPSessionNegotiatorFactory snf;
private final PCEPHandlerFactory hf;
private final EventLoopGroup bossGroup;
@Override
public final void close() {
if (Epoll.isAvailable()) {
- this.workerGroup.shutdownGracefully().awaitUninterruptibly();
- this.bossGroup.shutdownGracefully().awaitUninterruptibly();
+ this.workerGroup.shutdownGracefully(0, TIMEOUT, TimeUnit.SECONDS);;
+ this.bossGroup.shutdownGracefully(0, TIMEOUT, TimeUnit.SECONDS);;
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
}
private void closeEventLoopGroups() throws ExecutionException, InterruptedException {
- this.workerGroup.shutdownGracefully().get();
- this.bossGroup.shutdownGracefully().get();
+ this.workerGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS);
+ this.bossGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS);
}
@Test