<classifier>config</classifier>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>testtool-util</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rsvp-api</artifactId>
<artifactId>argparse4j</artifactId>
<version>0.7.0</version>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>testtool-util</artifactId>
+ </dependency>
<!-- test-scope dependencies -->
<dependency>
<groupId>junit</groupId>
package org.opendaylight.protocol.bmp.mock;
-import ch.qos.logback.classic.LoggerContext;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
import com.google.common.net.InetAddresses;
import io.netty.channel.Channel;
import java.net.InetAddress;
import org.opendaylight.protocol.bmp.spi.registry.BmpExtensionProviderActivator;
import org.opendaylight.protocol.bmp.spi.registry.BmpExtensionProviderContext;
import org.opendaylight.protocol.bmp.spi.registry.SimpleBmpExtensionProviderContext;
+import org.opendaylight.protocol.util.LoggerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private BmpMock() {
throw new UnsupportedOperationException();
}
+
public static void main(final String[] args) {
LOG.info("Starting BMP test tool.");
final BmpMockArguments arguments = BmpMockArguments.parseArguments(args);
- initiateLogger(arguments);
+ LoggerUtil.initiateLogger(arguments);
+
final BmpMockDispatcher dispatcher = initiateMock(arguments);
// now start the server / client
if (arguments.isOnPassiveMode()) {
}
}
- private static void initiateLogger(final BmpMockArguments arguments) {
- getRootLogger((LoggerContext) LoggerFactory.getILoggerFactory()).setLevel(arguments.getLogLevel());
- }
private static BmpMockDispatcher initiateMock(final BmpMockArguments arguments) {
final BmpExtensionProviderContext ctx = new SimpleBmpExtensionProviderContext();
final BmpExtensionProviderActivator bmpActivator = new BmpActivator(
- ServiceLoaderBGPExtensionProviderContext.getSingletonInstance());
+ ServiceLoaderBGPExtensionProviderContext.getSingletonInstance());
bmpActivator.start(ctx);
return new BmpMockDispatcher(ctx.getBmpMessageRegistry(),
- new BmpSessionFactory() {
- @Override
- public BmpSession getSession(final Channel channel,
- final BmpSessionListenerFactory sessionListenerFactory) {
- return new BmpMockSession(arguments.getPeersCount(), arguments.getPrePolicyRoutesCount(), arguments.getPostPolicyRoutesCount());
- }
- });
+ new BmpSessionFactory() {
+ @Override
+ public BmpSession getSession(final Channel channel,
+ final BmpSessionListenerFactory sessionListenerFactory) {
+ return new BmpMockSession(arguments.getPeersCount(), arguments.getPrePolicyRoutesCount(), arguments.getPostPolicyRoutesCount());
+ }
+ });
}
private static void deployClients(final BmpMockDispatcher dispatcher, final BmpMockArguments arguments) {
currentLocal = InetAddresses.increment(currentLocal);
}
}
-
- private static ch.qos.logback.classic.Logger getRootLogger(final LoggerContext lc) {
- return Iterables.find(lc.getLoggerList(), new Predicate<Logger>() {
- @Override
- public boolean apply(final Logger input) {
- return (input != null) ? input.getName().equals(Logger.ROOT_LOGGER_NAME) : false;
- }
- });
- }
}
package org.opendaylight.protocol.bmp.mock;
+import static org.opendaylight.protocol.util.InetSocketAddressUtil.getInetSocketAddress;
+
import ch.qos.logback.classic.Level;
-import com.google.common.net.HostAndPort;
import com.google.common.net.InetAddresses;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import net.sourceforge.argparse4j.inf.ArgumentParserException;
import net.sourceforge.argparse4j.inf.ArgumentType;
import net.sourceforge.argparse4j.inf.Namespace;
+import org.opendaylight.protocol.util.ArgumentsInput;
-public final class BmpMockArguments {
+public final class BmpMockArguments implements ArgumentsInput {
private static final int DEFAULT_LOCAL_PORT = 0;
private static final int DEFAULT_REMOTE_PORT = 12345;
return this.parseArgs.get(REMOTE_ADDRESS_DST);
}
+ @Override
public Level getLogLevel() {
return this.parseArgs.get(LOG_LEVEL_DST);
}
return parser;
}
- private static InetSocketAddress getInetSocketAddress(final String hostPortString, final int defaultPort) {
- final HostAndPort hostAndPort = HostAndPort.fromString(hostPortString).withDefaultPort(defaultPort);
- return new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPort());
- }
-
private static String toArgName(final String dst) {
return ARG_PREFIX + dst;
}
package org.opendaylight.protocol.bmp.mock;
+import static org.opendaylight.protocol.util.Ipv4Util.incrementIpv4Address;
+import static org.opendaylight.protocol.util.Ipv4Util.incrementIpv4Prefix;
+
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
LOG.debug("BMP router {} advertized peer {}", channel.localAddress(), peerAddress);
advertizeRoutes(this.prePolicyRoutesCount, AdjRibInType.PrePolicy, channel, peerAddress);
advertizeRoutes(this.postPolicyRoutesCount, AdjRibInType.PostPolicy, channel, peerAddress);
- peerAddress = BmpMockUtil.incrementIpv4Address(peerAddress);
+ peerAddress = incrementIpv4Address(peerAddress);
}
}
Ipv4Prefix prefix = PREFIX;
for (int i = 0; i < count; i++) {
channel.writeAndFlush(BmpMockUtil.createRouteMonitoring(peerAddress, type, prefix));
- prefix = BmpMockUtil.incrementIpv4Prefix(prefix);
+ prefix = incrementIpv4Prefix(prefix);
}
}
package org.opendaylight.protocol.bmp.mock;
-import com.google.common.net.InetAddresses;
import java.net.InetAddress;
import java.util.Collections;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.route.monitoring.message.Update;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.route.monitoring.message.UpdateBuilder;
-public final class BmpMockUtil {
+final class BmpMockUtil {
- private static final String SLASH = "/";
private static final String DESCRIPTION = "OpenDaylight";
private static final String NAME = "BMP mock";
private static final int HOLD_TIMER = 180;
public static InitiationMessage createInitiation() {
final InitiationMessageBuilder msgBuilder = new InitiationMessageBuilder();
msgBuilder.setTlvs(
- new TlvsBuilder()
- .setDescriptionTlv(new DescriptionTlvBuilder().setDescription(DESCRIPTION).build())
- .setNameTlv(new NameTlvBuilder().setName(NAME).build())
- .build());
+ new TlvsBuilder()
+ .setDescriptionTlv(new DescriptionTlvBuilder().setDescription(DESCRIPTION).build())
+ .setNameTlv(new NameTlvBuilder().setName(NAME).build())
+ .build());
return msgBuilder.build();
}
private static PeerHeader createPeerHeader(final Ipv4Address bgpId, final AdjRibInType ribType) {
return new PeerHeaderBuilder()
- .setAddress(new IpAddress(bgpId))
- .setAdjRibInType(AdjRibInType.PrePolicy)
- .setAs(new AsNumber(ASN))
- .setBgpId(bgpId)
- .setIpv4(true)
- .setType(PeerType.Global)
- .build();
+ .setAddress(new IpAddress(bgpId))
+ .setAdjRibInType(AdjRibInType.PrePolicy)
+ .setAs(new AsNumber(ASN))
+ .setBgpId(bgpId)
+ .setIpv4(true)
+ .setType(PeerType.Global)
+ .build();
}
public static RouteMonitoringMessage createRouteMonitoring(final Ipv4Address bgpId, final AdjRibInType ribType, final Ipv4Prefix prefix) {
private static Update createUpdate(final Ipv4Prefix prefix) {
final UpdateBuilder updateBuilder = new UpdateBuilder()
.setAttributes(new AttributesBuilder().setOrigin(ORIGIN).setAsPath(AS_PATH).setCNextHop(
- new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(NEXT_HOP).build()).build()).build())
+ new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(NEXT_HOP).build()).build()).build())
.setNlri(new NlriBuilder().setNlri(Collections.singletonList(prefix)).build());
return updateBuilder.build();
}
-
- private static String incrementIpv4Address(final String ipv4Address) {
- return InetAddresses.increment(InetAddresses.forString(ipv4Address)).getHostAddress();
- }
-
- public static Ipv4Address incrementIpv4Address(final Ipv4Address ipv4Address) {
- return new Ipv4Address(incrementIpv4Address(ipv4Address.getValue()));
- }
-
- public static Ipv4Prefix incrementIpv4Prefix(final Ipv4Prefix ipv4Prefix) {
- final String prefixStringValue = ipv4Prefix.getValue();
- final String[] split = prefixStringValue.split(SLASH);
- return new Ipv4Prefix(incrementIpv4Address(split[0]) + SLASH + split[1]);
- }
-
}
assertEquals(AdjRibInType.PrePolicy, routeMonitoring.getPeerHeader().getAdjRibInType());
}
- @Test
- public void testIncrementIpv4Address() {
- final Ipv4Address incremented = BmpMockUtil.incrementIpv4Address(PEER_IP);
- assertEquals("127.0.0.2", incremented.getValue());
- }
-
- @Test
- public void testIncrementIpv4Prefix() {
- final Ipv4Prefix incremented = BmpMockUtil.incrementIpv4Prefix(new Ipv4Prefix("1.2.3.4/32"));
- assertEquals("1.2.3.5/32", incremented.getValue());
- }
-
@Test(expected=UnsupportedOperationException.class)
public void testPrivateConstructor() throws Throwable {
final Constructor<BmpMockUtil> c = BmpMockUtil.class.getDeclaredConstructor();
this(messageRegistry, bossGroup, workerGroup, null, null);
}
- public BGPDispatcherImpl(final MessageRegistry messageRegistry, final EventLoopGroup bossGroup, final EventLoopGroup workerGroup, final MD5ChannelFactory<?> cf, final MD5ServerChannelFactory<?> scf) {
+ public BGPDispatcherImpl(final MessageRegistry messageRegistry, final EventLoopGroup bossGroup, final EventLoopGroup workerGroup,
+ final MD5ChannelFactory<?> cf, final MD5ServerChannelFactory<?> scf) {
this.bossGroup = Preconditions.checkNotNull(bossGroup);
this.workerGroup = Preconditions.checkNotNull(workerGroup);
this.handlerFactory = new BGPHandlerFactory(messageRegistry);
}
@Override
- public synchronized Future<BGPSessionImpl> createClient(final InetSocketAddress address, final BGPPeerRegistry listener, final int retryTimer) {
+ public synchronized Future<BGPSessionImpl> createClient(final InetSocketAddress remoteAddress, final BGPPeerRegistry listener, final int retryTimer) {
+ return createClient(remoteAddress, listener, retryTimer, createClientBootStrap());
+ }
+
+ private 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 Bootstrap bootstrap = createClientBootStrap();
- final BGPProtocolSessionPromise sessionPromise = new BGPProtocolSessionPromise(address, retryTimer, bootstrap);
- bootstrap.handler(BGPChannel.createClientChannelHandler(initializer, sessionPromise));
+ final BGPProtocolSessionPromise sessionPromise = new BGPProtocolSessionPromise(remoteAddress, retryTimer, clientBootStrap);
+ clientBootStrap.handler(BGPChannel.createClientChannelHandler(initializer, sessionPromise));
sessionPromise.connect();
LOG.debug("Client created.");
return sessionPromise;
}
+ public Future<BGPSessionImpl> createClient(final InetSocketAddress localAddress, final InetSocketAddress remoteAddress,
+ final StrictBGPPeerRegistry strictBGPPeerRegistry, final int retryTimer) {
+ final Bootstrap clientBootStrap = createClientBootStrap();
+ clientBootStrap.localAddress(localAddress);
+ return createClient(remoteAddress, strictBGPPeerRegistry, retryTimer, clientBootStrap);
+ }
+
protected Bootstrap createClientBootStrap() {
+ return createClientBootStrap(this.keys, this.channelFactory, this.workerGroup);
+ }
+
+ private static Bootstrap createClientBootStrap(final Optional<KeyMapping> keys, final MD5ChannelFactory<?> channelFactory, final EventLoopGroup
+ workerGroup) {
final Bootstrap bootstrap = new Bootstrap();
- if (this.keys.isPresent()) {
- if (this.channelFactory == null) {
+ if (keys.isPresent()) {
+ if (channelFactory == null) {
throw new UnsupportedOperationException("No key access instance available, cannot use key mapping");
}
- bootstrap.channelFactory(this.channelFactory);
- bootstrap.option(MD5ChannelOption.TCP_MD5SIG, this.keys.get());
+ bootstrap.channelFactory(channelFactory);
+ bootstrap.option(MD5ChannelOption.TCP_MD5SIG, keys.get());
} else {
bootstrap.channel(NioSocketChannel.class);
}
bootstrap.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, LOW_WATER_MARK);
if (bootstrap.group() == null) {
- bootstrap.group(this.workerGroup);
+ bootstrap.group(workerGroup);
}
return bootstrap;
}
@Override
- public synchronized Future<Void> createReconnectingClient(final InetSocketAddress address, final BGPPeerRegistry peerRegistry,
+ public synchronized Future<Void> createReconnectingClient(final InetSocketAddress remoteAddress, final BGPPeerRegistry peerRegistry,
final int retryTimer, final Optional<KeyMapping> keys) {
final BGPClientSessionNegotiatorFactory snf = new BGPClientSessionNegotiatorFactory(peerRegistry);
this.keys = keys;
final Bootstrap bootstrap = createClientBootStrap();
- final BGPReconnectPromise reconnectPromise = new BGPReconnectPromise(GlobalEventExecutor.INSTANCE, address,
+ final BGPReconnectPromise reconnectPromise = new BGPReconnectPromise(GlobalEventExecutor.INSTANCE, remoteAddress,
retryTimer, bootstrap, BGPChannel.createChannelPipelineInitializer(BGPDispatcherImpl.this.handlerFactory, snf));
reconnectPromise.connect();
this.keys = Optional.absent();
}
@Override
- public ChannelFuture createServer(final BGPPeerRegistry registry, final InetSocketAddress address) {
+ public ChannelFuture createServer(final BGPPeerRegistry registry, final InetSocketAddress localAddress) {
final BGPServerSessionNegotiatorFactory snf = new BGPServerSessionNegotiatorFactory(registry);
final ChannelPipelineInitializer initializer = BGPChannel.createChannelPipelineInitializer(BGPDispatcherImpl.this.handlerFactory, snf);
- final ServerBootstrap serverBootstrap = createServerBootstrap(initializer);
- final ChannelFuture channelFuture = serverBootstrap.bind(address);
- LOG.debug("Initiated server {} at {}.", channelFuture, address);
+ final ServerBootstrap serverBootstrap = createServerBootstrap(initializer, this.keys, serverChannelFactory, this.bossGroup, this.workerGroup);
+ final ChannelFuture channelFuture = serverBootstrap.bind(localAddress);
+ LOG.debug("Initiated server {} at {}.", channelFuture, localAddress);
return channelFuture;
}
- private ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer) {
+ public static ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer, final Optional<KeyMapping> keys,
+ final MD5ServerChannelFactory<?> serverChannelFactory, final EventLoopGroup bossGroup, final EventLoopGroup workerGroup) {
final ServerBootstrap serverBootstrap = new ServerBootstrap();
final ChannelHandler serverChannelHandler = BGPChannel.createServerChannelHandler(initializer);
serverBootstrap.childHandler(serverChannelHandler);
serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, HIGH_WATER_MARK);
serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, LOW_WATER_MARK);
- if (this.keys.isPresent()) {
- if (this.serverChannelFactory == null) {
+ if (keys.isPresent()) {
+ if (serverChannelFactory == null) {
throw new UnsupportedOperationException("No key access instance available, cannot use key mapping");
}
- serverBootstrap.channelFactory(this.serverChannelFactory);
- serverBootstrap.option(MD5ChannelOption.TCP_MD5SIG, this.keys.get());
+ serverBootstrap.channelFactory(serverChannelFactory);
+ serverBootstrap.option(MD5ChannelOption.TCP_MD5SIG, keys.get());
} else {
serverBootstrap.channel(NioServerSocketChannel.class);
}
serverBootstrap.option(ChannelOption.MAX_MESSAGES_PER_READ, 1);
if (serverBootstrap.group() == null) {
- serverBootstrap.group(this.bossGroup, this.workerGroup);
+ serverBootstrap.group(bossGroup, workerGroup);
}
return serverBootstrap;
}
- private static final class BGPChannel {
+ public static final class BGPChannel {
private static final String NEGOTIATOR = "negotiator";
private BGPChannel() {
this.sessionStats.resetStats();
}
- ChannelOutputLimiter getLimiter() {
+ public ChannelOutputLimiter getLimiter() {
return this.limiter;
}
* for a sessions' channel.
*/
@ThreadSafe
-final class ChannelOutputLimiter extends ChannelInboundHandlerAdapter {
+public final class ChannelOutputLimiter extends ChannelInboundHandlerAdapter {
private static final Logger LOG = LoggerFactory.getLogger(ChannelOutputLimiter.class);
private final BGPSessionImpl session;
private volatile boolean blocked;
}
}
- void write(final Notification msg) {
+ public void write(final Notification msg) {
ensureWritable();
this.session.write(msg);
}
return this.session.writeAndFlush(msg);
}
- void flush() {
+ public void flush() {
this.session.flush();
}
@GuardedBy("this")
private Future<?> pending;
- public BGPProtocolSessionPromise(InetSocketAddress address, int retryTimer, Bootstrap bootstrap) {
+ public BGPProtocolSessionPromise(InetSocketAddress remoteAddress, int retryTimer, Bootstrap bootstrap) {
super(GlobalEventExecutor.INSTANCE);
- this.address = Preconditions.checkNotNull(address);
+ this.address = Preconditions.checkNotNull(remoteAddress);
this.retryTimer = retryTimer;
this.bootstrap = Preconditions.checkNotNull(bootstrap);
}
/**
* Creates BGP client.
*
- * @param address Peer address
+ * @param remoteAddress remote Peer address
* @param peerRegistry BGP peer registry
* @param retryTimer Retry timer
* @return Future promising a client session
*/
- Future<? extends BGPSession> createClient(InetSocketAddress address, BGPPeerRegistry peerRegistry, int retryTimer);
+ Future<? extends BGPSession> createClient(InetSocketAddress remoteAddress, BGPPeerRegistry peerRegistry, int retryTimer);
/**
* Creates Reconnecting client.
*
- * @param address Peer address
+ * @param remoteAddress remote Peer Address
* @param peerRegistry BGP peer registry
* @param retryTimer Retry timer
* @param keys for TCPMD5
* @return Future promising a client session
*/
- Future<Void> createReconnectingClient(InetSocketAddress address,
+ Future<Void> createReconnectingClient(InetSocketAddress remoteAddress,
BGPPeerRegistry peerRegistry, int retryTimer, Optional<KeyMapping> keys);
/**
- * Create new BGP server to accept incoming bgp connections (bound to provided socket address).
+ * Create new BGP server to accept incoming bgp connections (bound to provided socket localAddress).
*
* @param peerRegistry BGP peer registry
- * @param address Peer address
+ * @param localAddress Peer localAddress
*
* @return ChannelFuture promising a client session
*/
- ChannelFuture createServer(BGPPeerRegistry peerRegistry, InetSocketAddress address);
+ ChannelFuture createServer(BGPPeerRegistry peerRegistry, InetSocketAddress localAddress);
}
<groupId>${project.groupId}</groupId>
<artifactId>bgp-rib-impl</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>testtool-util</artifactId>
+ </dependency>
<dependency>
<groupId>org.opendaylight.mdsal</groupId>
<artifactId>yang-binding</artifactId>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
- <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.argparse4j</groupId>
+ <artifactId>argparse4j</artifactId>
+ <version>0.7.0</version>
</dependency>
</dependencies>
<goal>shade</goal>
</goals>
<configuration>
+ <filters>
+ <filter>
+ <artifact>*:*</artifact>
+ <excludes>
+ <exclude>org/datanucleus/**</exclude>
+ <exclude>META-INF/*.SF</exclude>
+ <exclude>META-INF/*.DSA</exclude>
+ <exclude>META-INF/*.RSA</exclude>
+ </excludes>
+ </filter>
+ </filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.opendaylight.protocol.bgp.testtool.Main</mainClass>
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.testtool;
+
+import static org.opendaylight.protocol.util.InetSocketAddressUtil.getInetSocketAddress;
+
+import ch.qos.logback.classic.Level;
+import com.google.common.net.InetAddresses;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import net.sourceforge.argparse4j.ArgumentParsers;
+import net.sourceforge.argparse4j.inf.Argument;
+import net.sourceforge.argparse4j.inf.ArgumentParser;
+import net.sourceforge.argparse4j.inf.ArgumentParserException;
+import net.sourceforge.argparse4j.inf.ArgumentType;
+import net.sourceforge.argparse4j.inf.Namespace;
+import org.opendaylight.protocol.util.ArgumentsInput;
+import org.opendaylight.protocol.util.InetSocketAddressUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+
+final class Arguments implements ArgumentsInput {
+ private static final String PROGRAM_NAME = "BGP testing tool.";
+ private static final String ARG_PREFIX = "--";
+ private static final int DEFAULT_LOCAL_PORT = 0;
+ private static final int DEFAULT_REMOTE_PORT = 1790;
+ private static final InetAddress LOCALHOST = InetAddresses.forString("127.0.0.1");
+ private static final InetSocketAddress REMOTE_ADDRESS = new InetSocketAddress(LOCALHOST, DEFAULT_REMOTE_PORT);
+ private static final InetSocketAddress LOCAL_ADDRESS = new InetSocketAddress(LOCALHOST, DEFAULT_LOCAL_PORT);
+ private static final int INITIAL_HOLD_TIME = 90;
+ private static final String LOG_LEVEL = "log_level";
+ private static final String REMOTE_ADDRESS_PARAMETER = "remoteAddress";
+ private static final String REMOTE_ADDRESS_PARAMETER_HELP = "IP address of remote BGP peer, which the tool can accept or initiate connect to that " +
+ "address (based on the mode)";
+ private static final String LOCAL_ADDRESS_PARAMETER = "localAddress";
+ private static final String LOCAL_ADDRESS_PARAMETER_HELP = "IP address of BGP speakers which the tools simulates";
+ private static final String EXTENDED_COMMUNITIES_PARAMETER = "extended_communities";
+ private static final String EXTENDED_COMMUNITIES_PARAMETER_HELP = "Extended communities to be send. Format: x,x,x where x is each extended " +
+ "community from bgp-types.yang as as-4-generic-spec-extended-community, link-bandwidth-extended-community, ...";
+ private static final String ACTIVE_CONNECTION_PARAMETER = "active";
+ private static final String ACTIVE_CONNECTION_HELP = "Active initialization of the connection, by default false";
+ private static final String HOLD_TIMER_PARAMETER = "holdtimer";
+ private static final String INITIAL_HOLD_TIME_HELP = "In seconds, value of the desired holdtimer. According to RFC4271, recommended value for " +
+ "deadtimer is 90 seconds(set by default)";
+ private static final String PREFIXES_PARAMETER = "prefixes";
+ private static final String PREFIXES_PARAMETER_HELP = "Number of prefixes to be sent";
+ private static final String MULTIPATH_PARAMETER = "multiPathSupport";
+ private static final String MULTIPATH_PARAMETER_HELP = "Active Multipart support";
+ private static final String AS_PARAMETER = "as";
+ private static final String AS_PARAMETER_HELP = "Value of AS in the initial open message";
+ private static final String SPEAKERS_COUNT = "speakersCount";
+ private static final String SPEAKERS_COUNT_HELP = "Number of simulated BGP speakers, when creating each speaker, use incremented " +
+ "local-address for binding";
+ private static final ArgumentParser ARGUMENT_PARSER = initializeArgumentParser();
+ private final Namespace parseArgs;
+
+ private Arguments(final Namespace parseArgs) {
+ this.parseArgs = parseArgs;
+ }
+
+ private interface ArgumentTypeTool<T> extends ArgumentType<T> {
+ default T convert(ArgumentParser var1, Argument var2, String input) throws ArgumentParserException {
+ return convert(input);
+ }
+
+ T convert(String input) throws ArgumentParserException;
+ }
+
+ static Arguments parseArguments(final String[] args) {
+ try {
+ final Namespace namespace = ARGUMENT_PARSER.parseArgs(args);
+ return new Arguments(namespace);
+ } catch (final ArgumentParserException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ private static ArgumentParser initializeArgumentParser() {
+ final ArgumentParser parser = ArgumentParsers.newArgumentParser(PROGRAM_NAME);
+
+ parser.addArgument("-i", toArgName(ACTIVE_CONNECTION_PARAMETER)).type(Boolean.class).setDefault(false).help(ACTIVE_CONNECTION_HELP);
+ parser.addArgument("-ho", toArgName(HOLD_TIMER_PARAMETER)).type(Integer.class).setDefault(INITIAL_HOLD_TIME).help(INITIAL_HOLD_TIME_HELP);
+ parser.addArgument("-pr", toArgName(PREFIXES_PARAMETER)).type(Integer.class).setDefault(0).help(PREFIXES_PARAMETER_HELP);
+ parser.addArgument("-sc", toArgName(SPEAKERS_COUNT)).type(Integer.class).setDefault(0).help(SPEAKERS_COUNT_HELP);
+ parser.addArgument("-mp", toArgName(MULTIPATH_PARAMETER)).type(Boolean.class).setDefault(false).help(MULTIPATH_PARAMETER_HELP);
+ parser.addArgument("-" + AS_PARAMETER, toArgName(AS_PARAMETER)).type((ArgumentTypeTool<AsNumber>) as -> new AsNumber(Long.valueOf(as)))
+ .setDefault(new AsNumber(64496L)).help(AS_PARAMETER_HELP);
+ parser.addArgument("-ec", toArgName(EXTENDED_COMMUNITIES_PARAMETER)).type((ArgumentTypeTool<List<String>>) extComInput ->
+ Arrays.asList(extComInput.split(","))).setDefault(Collections.emptyList()).help(EXTENDED_COMMUNITIES_PARAMETER_HELP);
+ parser.addArgument("-ll", toArgName(LOG_LEVEL)).type((ArgumentTypeTool<Level>) Level::toLevel).setDefault(Level.INFO).help("log levels");
+ parser.addArgument("-ra", toArgName(REMOTE_ADDRESS_PARAMETER)).type((ArgumentTypeTool<List<InetSocketAddress>>) input ->
+ InetSocketAddressUtil.parseAddresses(input, DEFAULT_REMOTE_PORT)).setDefault(Collections.singletonList(REMOTE_ADDRESS))
+ .help(REMOTE_ADDRESS_PARAMETER_HELP);
+ parser.addArgument("-la", toArgName(LOCAL_ADDRESS_PARAMETER)).type((ArgumentTypeTool<InetSocketAddress>) input ->
+ getInetSocketAddress(input, DEFAULT_LOCAL_PORT)).setDefault(LOCAL_ADDRESS).help(LOCAL_ADDRESS_PARAMETER_HELP);
+ return parser;
+ }
+
+
+ private static String toArgName(final String dst) {
+ return ARG_PREFIX + dst;
+ }
+
+ @Override
+ public Level getLogLevel() {
+ return this.parseArgs.get(LOG_LEVEL);
+ }
+
+ AsNumber getAs() {
+ return this.parseArgs.get("as");
+ }
+
+ InetSocketAddress getLocalAddresses() {
+ return this.parseArgs.get(LOCAL_ADDRESS_PARAMETER);
+ }
+
+ List<InetSocketAddress> getRemoteAddresses() {
+ return this.parseArgs.get(REMOTE_ADDRESS_PARAMETER);
+ }
+
+ int getNumberOfPrefixes() {
+ return this.parseArgs.get(PREFIXES_PARAMETER);
+ }
+
+ List<String> getExtendedCommunities() {
+ return this.parseArgs.get(EXTENDED_COMMUNITIES_PARAMETER);
+ }
+
+ int getHoldTimer() {
+ return this.parseArgs.get(HOLD_TIMER_PARAMETER);
+ }
+
+ boolean getInitiateConnection() {
+ return this.parseArgs.get(ACTIVE_CONNECTION_PARAMETER);
+ }
+
+ boolean getMultiPathSupport() {
+ return this.parseArgs.get(MULTIPATH_PARAMETER);
+ }
+
+ int getSpeakerCount() {
+ return this.parseArgs.get(SPEAKERS_COUNT);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.testtool;
+
+import com.google.common.base.Preconditions;
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.GenericFutureListener;
+import java.net.InetSocketAddress;
+import java.util.Collections;
+import java.util.concurrent.ExecutionException;
+import org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl;
+import org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry;
+import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
+import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
+import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.BgpParameters;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class BGPPeerBuilder {
+ private static final int RETRY_TIMER = 10;
+ private static final Logger LOG = LoggerFactory.getLogger(BGPPeerBuilder.class);
+
+ private BGPPeerBuilder() {
+ throw new UnsupportedOperationException();
+ }
+
+ static void createPeer(final BGPDispatcher dispatcher, final Arguments arguments, final InetSocketAddress localAddress,
+ final BGPSessionListener sessionListener, final BgpParameters bgpParameters) {
+ final AsNumber as = arguments.getAs();
+ final BGPSessionPreferences proposal = new BGPSessionPreferences(as, arguments.getHoldTimer(), new Ipv4Address(localAddress.getAddress().getHostAddress()),
+ as, Collections.singletonList(bgpParameters));
+ final StrictBGPPeerRegistry strictBGPPeerRegistry = new StrictBGPPeerRegistry();
+ if (arguments.getInitiateConnection()) {
+ for (final InetSocketAddress remoteAddress : arguments.getRemoteAddresses()) {
+ strictBGPPeerRegistry.addPeer(StrictBGPPeerRegistry.getIpAddress(remoteAddress), sessionListener, proposal);
+ addFutureListener(localAddress, ((BGPDispatcherImpl) dispatcher).createClient(localAddress, remoteAddress, strictBGPPeerRegistry, RETRY_TIMER));
+ }
+ } else {
+ for (final InetSocketAddress remoteAddress : arguments.getRemoteAddresses()) {
+ strictBGPPeerRegistry.addPeer(StrictBGPPeerRegistry.getIpAddress(remoteAddress), sessionListener, proposal);
+ }
+ addFutureListener(localAddress, dispatcher.createServer(strictBGPPeerRegistry, localAddress));
+ }
+ LOG.debug("{} {}", sessionListener, proposal);
+ }
+
+ private static <T> void addFutureListener(final InetSocketAddress localAddress, final Future<T> future) {
+ future.addListener(new GenericFutureListener<Future<T>>() {
+ @Override
+ public void operationComplete(final Future<T> future) throws ExecutionException, InterruptedException {
+ Preconditions.checkArgument(future.isSuccess(), "Unable to start bgp session on %s", localAddress, future.cause());
+ }
+ });
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.testtool;
+
+import static org.opendaylight.protocol.bgp.testtool.BGPPeerBuilder.createPeer;
+
+import com.google.common.collect.Lists;
+import com.google.common.net.InetAddresses;
+import io.netty.channel.nio.NioEventLoopGroup;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.opendaylight.protocol.bgp.parser.impl.BGPActivator;
+import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
+import org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl;
+import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
+import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.BgpParameters;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.BgpParametersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.OptionalCapabilities;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.OptionalCapabilitiesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.CParametersBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapabilityBuilder;
+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;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.AddPathCapabilityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.MultiprotocolCapabilityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.add.path.capability.AddressFamiliesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+
+final class BGPTestTool {
+ private final Map<String, BGPSessionListener> listeners = new HashMap<>();
+
+ void start(final Arguments arguments) {
+ final BGPDispatcher dispatcher = initializeActivator();
+
+ final ArrayList<OptionalCapabilities> optCap = Lists.newArrayList(createMPCapability(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class),
+ createMPCapability(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class), createAs4BytesMPCapability(arguments.getAs()));
+ if (arguments.getMultiPathSupport()) {
+ optCap.add(createAddPathCapability());
+ }
+ final BgpParameters bgpParameters = createBgpParameters(optCap);
+
+ final InetSocketAddress localAddress = arguments.getLocalAddresses();
+ final int port = localAddress.getPort();
+ InetAddress address = localAddress.getAddress();
+ int numberOfSpeakers = arguments.getSpeakerCount();
+ do {
+ final BGPSessionListener sessionListener = new TestingListener(arguments.getNumberOfPrefixes(), arguments.getExtendedCommunities(),
+ arguments.getMultiPathSupport());
+ this.listeners.put(address.getHostAddress(), sessionListener);
+ createPeer(dispatcher, arguments, new InetSocketAddress(address, port), sessionListener, bgpParameters);
+ numberOfSpeakers--;
+ address = InetAddresses.increment(address);
+ } while (numberOfSpeakers > 0);
+ }
+
+ private BGPDispatcher initializeActivator() {
+ final BGPActivator activator = new BGPActivator();
+ final BGPExtensionProviderContext ctx = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance();
+ activator.start(ctx);
+ return new BGPDispatcherImpl(ctx.getMessageRegistry(), new NioEventLoopGroup(), new NioEventLoopGroup());
+ }
+
+ private static OptionalCapabilities createMPCapability(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
+ return new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder()
+ .setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(afi).setSafi(safi).build()).build()).build()).build();
+ }
+
+ private static OptionalCapabilities createAs4BytesMPCapability(final AsNumber as) {
+ return new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder()
+ .setAs4BytesCapability(new As4BytesCapabilityBuilder().setAsNumber(as).build()).build()).build();
+ }
+
+ private static BgpParameters createBgpParameters(final List<OptionalCapabilities> optionalCapabilities) {
+ return new BgpParametersBuilder().setOptionalCapabilities(optionalCapabilities).build();
+ }
+
+ private static OptionalCapabilities createAddPathCapability() {
+ return new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder()
+ .setAddPathCapability(new AddPathCapabilityBuilder().setAddressFamilies(Lists.newArrayList(new AddressFamiliesBuilder()
+ .setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).setSendReceive(SendReceive.Both).build()
+ )).build()).build()).build()).build();
+ }
+
+ void printCount(final String localAddress) {
+ final BGPSessionListener listener = this.listeners.get(localAddress);
+ if (listener != null) {
+ ((TestingListener) listener).printCount(localAddress);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.testtool;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.ExtendedCommunities;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.ExtendedCommunitiesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ShortAsNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as._4.spec.common.As4SpecificCommon;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.as._4.spec.common.As4SpecificCommonBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.ExtendedCommunity;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4GenericSpecExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4RouteOriginExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.As4RouteTargetExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.AsSpecificExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.Inet4SpecificExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.LinkBandwidthCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.OpaqueExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteOriginExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteOriginIpv4CaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteTargetExtendedCommunityCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.RouteTargetIpv4CaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.as._4.generic.spec.extended.community._case.As4GenericSpecExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.as._4.route.origin.extended.community._case.As4RouteOriginExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.as._4.route.target.extended.community._case.As4RouteTargetExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.as.specific.extended.community._case.AsSpecificExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.inet4.specific.extended.community._case.Inet4SpecificExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.link.bandwidth._case.LinkBandwidthExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.opaque.extended.community._case.OpaqueExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.route.origin.extended.community._case.RouteOriginExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.route.origin.ipv4._case.RouteOriginIpv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.route.target.extended.community._case.RouteTargetExtendedCommunityBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.extended.community.extended.community.route.target.ipv4._case.RouteTargetIpv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class CommunitiesBuilder {
+ private static final Logger LOG = LoggerFactory.getLogger(CommunitiesBuilder.class);
+ private final static As4SpecificCommon AS_4_COMMON = new As4SpecificCommonBuilder().setAsNumber(new AsNumber(20L)).setLocalAdministrator(100).build();
+ private final static Ipv4Address IPV4 = new Ipv4Address("192.168.1.0");
+ private final static byte[] BYTE = new byte[]{(byte) 0x4f, (byte) 0x70, (byte) 0x00, (byte) 0x00};
+ private final static int LA = 4660;
+ private final static ShortAsNumber SHORT_AS = new ShortAsNumber(20L);
+
+ private CommunitiesBuilder() {
+ throw new UnsupportedOperationException();
+ }
+
+ static List<ExtendedCommunities> createExtComm(final List<String> extCom) {
+ final List<ExtendedCommunities> extendedCommunities = Lists.newArrayList();
+ for (String ec : extCom) {
+ ExtendedCommunity community = null;
+ switch (ec) {
+ case "as-4-generic-spec-extended-community":
+ community = CommunitiesBuilder.as4GenSpecBuild();
+ break;
+ case "as-4-route-target-extended-community":
+ community = CommunitiesBuilder.as4RTBuild();
+ break;
+ case "as-4-route-origin-extended-community":
+ community = CommunitiesBuilder.as4ROBuild();
+ break;
+ case "route-origin":
+ community = CommunitiesBuilder.rOBuild();
+ break;
+ case "route-target":
+ community = CommunitiesBuilder.rTBuild();
+ break;
+ case "route-origin-extended-community":
+ community = CommunitiesBuilder.rOECBuild();
+ break;
+ case "route-target-extended-community":
+ community = CommunitiesBuilder.rTECBuild();
+ break;
+ case "link-bandwidth-extended-community":
+ community = CommunitiesBuilder.linkBandBuild();
+ break;
+ case "opaque-extended-community":
+ community = CommunitiesBuilder.opaqueBuild();
+ break;
+ case "inet4-specific-extended-community":
+ community = CommunitiesBuilder.inet4Build();
+ break;
+ case "as-specific-extended-community":
+ community = CommunitiesBuilder.asSpecBuild();
+ break;
+ default:
+ LOG.debug("Not recognized Extended Community {}", ec);
+ break;
+ }
+ extendedCommunities.add(new ExtendedCommunitiesBuilder().setTransitive(true).setExtendedCommunity(community).build());
+ }
+ return extendedCommunities;
+ }
+
+ private static ExtendedCommunity as4GenSpecBuild() {
+ return new As4GenericSpecExtendedCommunityCaseBuilder()
+ .setAs4GenericSpecExtendedCommunity(new As4GenericSpecExtendedCommunityBuilder()
+ .setAs4SpecificCommon(AS_4_COMMON).build()).build();
+ }
+
+ private static ExtendedCommunity as4RTBuild() {
+ return new As4RouteTargetExtendedCommunityCaseBuilder().setAs4RouteTargetExtendedCommunity(
+ new As4RouteTargetExtendedCommunityBuilder().setAs4SpecificCommon(AS_4_COMMON).build()).build();
+ }
+
+ private static ExtendedCommunity as4ROBuild() {
+ return new As4RouteOriginExtendedCommunityCaseBuilder().setAs4RouteOriginExtendedCommunity(
+ new As4RouteOriginExtendedCommunityBuilder().setAs4SpecificCommon(AS_4_COMMON).build()).build();
+ }
+
+ private static ExtendedCommunity rTBuild() {
+ return new RouteTargetIpv4CaseBuilder().setRouteTargetIpv4(
+ new RouteTargetIpv4Builder().setGlobalAdministrator(IPV4).setLocalAdministrator(LA).build()).build();
+ }
+
+ private static ExtendedCommunity rOBuild() {
+ return new RouteOriginIpv4CaseBuilder().setRouteOriginIpv4(
+ new RouteOriginIpv4Builder().setGlobalAdministrator(IPV4).setLocalAdministrator(LA).build()).build();
+ }
+
+ private static ExtendedCommunity linkBandBuild() {
+ return new LinkBandwidthCaseBuilder().setLinkBandwidthExtendedCommunity(new LinkBandwidthExtendedCommunityBuilder()
+ .setBandwidth(new Bandwidth(new Float32(BYTE))).build()).build();
+ }
+
+ private static ExtendedCommunity rOECBuild() {
+ return new RouteOriginExtendedCommunityCaseBuilder().setRouteOriginExtendedCommunity(
+ new RouteOriginExtendedCommunityBuilder().setGlobalAdministrator(SHORT_AS).setLocalAdministrator(BYTE).build()).build();
+ }
+
+ private static ExtendedCommunity rTECBuild() {
+ return new RouteTargetExtendedCommunityCaseBuilder().setRouteTargetExtendedCommunity(
+ new RouteTargetExtendedCommunityBuilder().setGlobalAdministrator(SHORT_AS).setLocalAdministrator(BYTE).build()).build();
+ }
+
+ private static ExtendedCommunity opaqueBuild() {
+ return new OpaqueExtendedCommunityCaseBuilder().setOpaqueExtendedCommunity(
+ new OpaqueExtendedCommunityBuilder().setValue(BYTE).build()).build();
+ }
+
+ private static ExtendedCommunity inet4Build() {
+ return new Inet4SpecificExtendedCommunityCaseBuilder().setInet4SpecificExtendedCommunity(
+ new Inet4SpecificExtendedCommunityBuilder().setGlobalAdministrator(IPV4).setLocalAdministrator(BYTE).build()).build();
+ }
+
+ private static ExtendedCommunity asSpecBuild() {
+ return new AsSpecificExtendedCommunityCaseBuilder().setAsSpecificExtendedCommunity(
+ new AsSpecificExtendedCommunityBuilder().setGlobalAdministrator(SHORT_AS).setLocalAdministrator(BYTE).build()).build();
+ }
+}
*/
package org.opendaylight.protocol.bgp.testtool;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.Lists;
-import io.netty.channel.nio.NioEventLoopGroup;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.UnknownHostException;
-import java.util.Collections;
-import java.util.List;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
-import org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl;
-import org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry;
-import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
-import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.BgpParameters;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.BgpParametersBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.OptionalCapabilities;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.OptionalCapabilitiesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.CParametersBuilder;
-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.mp.capabilities.MultiprotocolCapabilityBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.SubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import org.opendaylight.protocol.util.LoggerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* Starter class for testing.
*/
public final class Main {
-
private static final Logger LOG = LoggerFactory.getLogger(Main.class);
- private static final String USAGE = "DESCRIPTION:\n"
- + "\tCreates a server with given parameters. As long as it runs, it accepts connections " + "from PCCs.\n" + "USAGE:\n"
- + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
- + "\t\tFormat: x.x.x.x:y where y is port number.\n\n"
- + "\t\tThis IP address will appear in BGP Open message as BGP Identifier of the server.\n" +
-
- "\t-as\n" + "\t\t value of AS in the initial open message\n\n" +
-
- "\t-h, --holdtimer\n" + "\t\tin seconds, value of the desired holdtimer\n"
- + "\t\tAccording to RFC4271, recommended value for deadtimer is 90 seconds.\n"
- + "\t\tIf not set, this will be the default value.\n\n" +
-
- "\t--help\n" + "\t\tdisplay this help and exits\n\n" +
-
- "With no parameters, this help is printed.";
-
- private final BGPDispatcherImpl dispatcher;
-
- private static final int INITIAL_HOLD_TIME = 90;
-
- private static final int RETRY_TIMER = 10;
-
private Main() {
- this.dispatcher = new BGPDispatcherImpl(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry(), new NioEventLoopGroup(), new NioEventLoopGroup());
+ throw new UnsupportedOperationException();
}
- public static void main(final String[] args) throws UnknownHostException {
- if (args.length == 0 || (args.length == 1 && args[0].equalsIgnoreCase("--help"))) {
- LOG.info(Main.USAGE);
- return;
- }
-
- InetSocketAddress address = null;
- int holdTimerValue = INITIAL_HOLD_TIME;
- AsNumber as = null;
-
- int i = 0;
- while (i < args.length) {
- if (args[i].equalsIgnoreCase("-a") || args[i].equalsIgnoreCase("--address")) {
- final String[] ip = args[i + 1].split(":");
- address = new InetSocketAddress(InetAddress.getByName(ip[0]), Integer.parseInt(ip[1]));
- i++;
- } else if (args[i].equalsIgnoreCase("-h") || args[i].equalsIgnoreCase("--holdtimer")) {
- holdTimerValue = Integer.valueOf(args[i + 1]);
- i++;
- } else if (args[i].equalsIgnoreCase("-as")) {
- as = new AsNumber(Long.valueOf(args[i + 1]));
- i++;
- } else {
- LOG.error("WARNING: Unrecognized argument: {}", args[i]);
- }
- i++;
+ public static void main(final String[] args) throws IOException {
+ final Arguments arguments = Arguments.parseArguments(args);
+ LoggerUtil.initiateLogger(arguments);
+
+ final BGPTestTool bgpTestTool = new BGPTestTool();
+ final InputStreamReader isr = new InputStreamReader(System.in);
+ final BufferedReader br = new BufferedReader(isr);
+ bgpTestTool.start(arguments);
+ for (;;) {
+ LOG.info("Insert local address:");
+ bgpTestTool.printCount(br.readLine());
}
-
- final Main m = new Main();
-
- final BGPSessionListener sessionListener = new TestingListener();
-
- final BgpParameters bgpParameters = createBgpParameters(Lists.newArrayList(
- createMPCapability(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class),
- createMPCapability(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class)));
-
- final BGPSessionPreferences proposal = new BGPSessionPreferences(as, holdTimerValue, new Ipv4Address("25.25.25.2"), as,
- Collections.singletonList(bgpParameters));
-
- LOG.debug("{} {} {}", address, sessionListener, proposal);
-
- final InetSocketAddress addr = address;
- final StrictBGPPeerRegistry strictBGPPeerRegistry = new StrictBGPPeerRegistry();
- strictBGPPeerRegistry.addPeer(StrictBGPPeerRegistry.getIpAddress(address), sessionListener, proposal);
-
- m.dispatcher.createClient(addr, strictBGPPeerRegistry, RETRY_TIMER);
- }
-
- @VisibleForTesting
- protected static BgpParameters createBgpParameters(final List<OptionalCapabilities> optionalCapabilities) {
- return new BgpParametersBuilder().setOptionalCapabilities(optionalCapabilities).build();
- }
-
- @VisibleForTesting
- protected static OptionalCapabilities createMPCapability(final Class<? extends AddressFamily> afi, final Class<? extends SubsequentAddressFamily> safi) {
- return new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(CParameters1.class,
- new CParameters1Builder().setMultiprotocolCapability(
- new MultiprotocolCapabilityBuilder().setAfi(afi).setSafi(safi).build()).build()).build()).build();
}
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.testtool;
+
+import static org.opendaylight.protocol.bgp.testtool.CommunitiesBuilder.createExtComm;
+import static org.opendaylight.protocol.util.Ipv4Util.incrementIpv4Prefix;
+
+import java.util.Collections;
+import java.util.List;
+import org.opendaylight.protocol.bgp.rib.impl.ChannelOutputLimiter;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.prefixes.DestinationIpv4Builder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.ipv4.prefixes.destination.ipv4.Ipv4PrefixesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.inet.rev150305.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationIpv4CaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.UpdateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.Attributes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.AttributesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.AsPathBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.LocalPrefBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.MultiExitDiscBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.path.attributes.attributes.OriginBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.message.NlriBuilder;
+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.update.attributes.MpReachNlriBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpOrigin;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.Ipv4NextHopCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.next.hop.c.next.hop.ipv4.next.hop._case.Ipv4NextHopBuilder;
+
+final class PrefixesBuilder {
+ private final static Ipv4NextHopCase NEXT_HOP;
+
+ static {
+ NEXT_HOP = new Ipv4NextHopCaseBuilder().setIpv4NextHop(new Ipv4NextHopBuilder().setGlobal(new Ipv4Address("127.1.1.1")).build()).build();
+ }
+
+ private PrefixesBuilder() {
+ throw new UnsupportedOperationException();
+ }
+
+ static void AdvertiseIpv4Prefixes(final ChannelOutputLimiter session, final int nPrefixes, final List<String> extCom, final boolean multipartSupport) {
+ Ipv4Prefix addressPrefix = new Ipv4Prefix("1.1.1.1/31");
+ for (int i = 0; i < nPrefixes; i++) {
+ buildAndSend(session, addressPrefix, extCom, multipartSupport);
+ addressPrefix = incrementIpv4Prefix(addressPrefix);
+ }
+ }
+
+ private static void buildAndSend(final ChannelOutputLimiter session, final Ipv4Prefix addressPrefix, final List<String> extCom,
+ final boolean multipartSupport) {
+ final Update upd = new UpdateBuilder().setNlri(new NlriBuilder().build())
+ .setAttributes(createAttributes(extCom, multipartSupport, addressPrefix)).build();
+ session.write(upd);
+ session.flush();
+ }
+
+ private static Attributes createAttributes(final List<String> extCom, final boolean multiPathSupport, final Ipv4Prefix addressPrefix) {
+ final AttributesBuilder attBuilder = new AttributesBuilder();
+ attBuilder.setOrigin(new OriginBuilder().setValue(BgpOrigin.Egp).build());
+ attBuilder.setAsPath(new AsPathBuilder().setSegments(Collections.emptyList()).build());
+ attBuilder.setMultiExitDisc(new MultiExitDiscBuilder().setMed((long) 0).build());
+ attBuilder.setLocalPref(new LocalPrefBuilder().setPref(100L).build());
+ attBuilder.setExtendedCommunities(createExtComm(extCom));
+ attBuilder.setUnrecognizedAttributes(Collections.emptyList());
+
+ final Ipv4PrefixesBuilder prefixes = new Ipv4PrefixesBuilder().setPrefix(addressPrefix);
+ if (multiPathSupport) {
+ prefixes.setPathId(new PathId(5L));
+ }
+ attBuilder.addAugmentation(Attributes1.class, new Attributes1Builder().setMpReachNlri(
+ new MpReachNlriBuilder().setCNextHop(NEXT_HOP).setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class)
+ .setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(
+ new DestinationIpv4CaseBuilder().setDestinationIpv4(new DestinationIpv4Builder()
+ .setIpv4Prefixes(Collections.singletonList(prefixes.build())).build()).build()).build()).build()).build());
+
+ return attBuilder.build();
+ }
+
+}
*/
package org.opendaylight.protocol.bgp.testtool;
+import java.util.List;
+import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
import org.opendaylight.yangtools.yang.binding.Notification;
import org.slf4j.Logger;
/**
* Testing BGP Listener.
*/
-public class TestingListener implements BGPSessionListener {
+final class TestingListener implements BGPSessionListener {
private static final Logger LOG = LoggerFactory.getLogger(TestingListener.class);
+ private final int nPrefixes;
+ private final List<String> extCom;
+ private final boolean multiPathSupport;
+ private int messageCounter = 0;
+
+ TestingListener(final int nPrefixes, final List<String> extCom, final boolean multiPathSupport) {
+ this.nPrefixes = nPrefixes;
+ this.extCom = extCom;
+ this.multiPathSupport = multiPathSupport;
+ }
@Override
- public void onMessage(final BGPSession session, final Notification message) {
- LOG.info("Client Listener: message received: {}", message.toString());
+ public boolean isSessionActive() {
+ return true;
+ }
+
+ @Override
+ public void markUptodate(final TablesKey tablesKey) {
+ LOG.debug("Table marked as up-to-date {}", tablesKey);
}
@Override
public void onSessionUp(final BGPSession session) {
LOG.info("Client Listener: Session Up.");
+ if (this.nPrefixes > 0) {
+ PrefixesBuilder.AdvertiseIpv4Prefixes(((BGPSessionImpl) session).getLimiter(), this.nPrefixes, this.extCom, this.multiPathSupport);
+ }
}
@Override
}
@Override
- public void releaseConnection() {
- LOG.info("Client Listener: Connection released.");
+ public void onMessage(final BGPSession session, final Notification message) {
+ if (message instanceof Update) {
+ messageCounter++;
+ }
+ LOG.debug("Message received: {}", message.toString());
}
@Override
- public boolean isSessionActive() {
- return true;
+ public void releaseConnection() {
+ LOG.info("Client Listener: Connection released.");
}
- @Override
- public void markUptodate(final TablesKey tablesKey) {
- LOG.debug("Table marked as up-to-date {}", tablesKey);
+ void printCount(final String localAddress) {
+ LOG.info("Peer {} received {} update messages.", localAddress, messageCounter);
}
}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<!--
- Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
-
- This program and the accompanying materials are made available under the
- terms of the Eclipse Public License v1.0 which accompanies this distribution,
- and is available at http://www.eclipse.org/legal/epl-v10.html
--->
-<configuration>
- <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
- <level>TRACE</level>
- </filter>
- <encoder>
- <pattern>[%d{HH:mm:ss.SSS}] [%thread] %-5level %logger{10} - %msg%n</pattern>
- </encoder>
- </appender>
-
- <logger name="org.opendaylight.protocol" level="TRACE" />
-
- <root level="TRACE">
- <appender-ref ref="STDOUT" />
- </root>
-</configuration>
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.testtool;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.util.concurrent.DefaultPromise;
-import io.netty.util.concurrent.GlobalEventExecutor;
-import java.net.InetSocketAddress;
-import java.util.Collections;
-import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
-import org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl;
-import org.opendaylight.protocol.bgp.rib.impl.BGPHandlerFactory;
-import org.opendaylight.protocol.bgp.rib.impl.BGPServerSessionNegotiatorFactory;
-import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
-import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
-import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
-import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210.LinkstateSubsequentAddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.BgpParameters;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
-
-public class BGPSpeakerMock {
-
- private final BGPServerSessionNegotiatorFactory negotiatorFactory;
- private final BGPHandlerFactory factory;
- private final BGPDispatcherImpl disp;
- private final BGPPeerRegistry peerRegistry;
-
- private BGPSpeakerMock(final BGPServerSessionNegotiatorFactory negotiatorFactory, final BGPHandlerFactory factory,
- final DefaultPromise<BGPSessionImpl> defaultPromise) {
- this.disp = new BGPDispatcherImpl(null, new NioEventLoopGroup(), new NioEventLoopGroup());
- this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory);
- this.factory = Preconditions.checkNotNull(factory);
-
-
- this.peerRegistry = new BGPPeerRegistry() {
- @Override
- public void addPeer(final IpAddress ip, final BGPSessionListener peer, final BGPSessionPreferences prefs) {
- }
-
- @Override
- public void removePeer(final IpAddress ip) {
- }
-
- @Override
- public boolean isPeerConfigured(final IpAddress ip) {
- return true;
- }
-
- @Override
- public BGPSessionListener getPeer(final IpAddress ip, final Ipv4Address sourceId, final Ipv4Address remoteId, final Open open) throws BGPDocumentedException {
- return new SpeakerSessionListener();
- }
-
- @Override
- public BGPSessionPreferences getPeerPreferences(final IpAddress ip) {
- final BgpParameters bgpParameters = Main.createBgpParameters(Lists.newArrayList(
- Main.createMPCapability(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class),
- Main.createMPCapability(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class)));
- return new BGPSessionPreferences(new AsNumber(72L), (short) 90, new Ipv4Address("127.0.0.2"), new AsNumber(72L), Collections.singletonList(bgpParameters));
- }
-
- @Override
- public void close() throws Exception {
-
- }
-
- @Override
- public void removePeerSession(final IpAddress ip) {
- }
- };
- }
-
- public void main(final String[] args) {
-
- final BGPServerSessionNegotiatorFactory snf = new BGPServerSessionNegotiatorFactory(this.peerRegistry);
-
- final BGPSpeakerMock mock = new BGPSpeakerMock(snf, new BGPHandlerFactory(ServiceLoaderBGPExtensionProviderContext.getSingletonInstance().getMessageRegistry()), new DefaultPromise<BGPSessionImpl>(GlobalEventExecutor.INSTANCE));
-
- mock.createServer(new InetSocketAddress("127.0.0.2", 12345));
- }
-
- private void createServer(final InetSocketAddress address) {
- this.disp.createServer(this.peerRegistry,address);
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.bgp.testtool;
-
-import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
-import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
-import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
-import org.opendaylight.yangtools.yang.binding.Notification;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class SpeakerSessionListener implements BGPSessionListener {
- private static final Logger LOG = LoggerFactory.getLogger(SpeakerSessionListener.class);
-
- @Override
- public void onSessionUp(final BGPSession session) {
- LOG.info("Server: Session is up.");
- }
-
- @Override
- public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
- LOG.info("Server: Session terminated: {}", cause);
- }
-
- @Override
- public void onSessionDown(final BGPSession session, final Exception e) {
- LOG.info("Server: Session down.");
- try {
- session.close();
- } catch (Exception ie) {
- LOG.warn("Error closing session", ie);
- }
- // this.d.stop();
- }
-
- @Override
- public void onMessage(final BGPSession session, final Notification message) {
- LOG.info("Server: Message received: {}", message);
- // this.d.stop();
- }
-
- @Override
- public void releaseConnection() {
-
- }
-
- @Override
- public boolean isSessionActive() {
- return true;
- }
-
- @Override
- public void markUptodate(final TablesKey tablesKey) {
- LOG.debug("Table marked as up-to-date {}", tablesKey);
- }
-}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opendaylight.bgpcep</groupId>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<sourceDirectory>${project.basedir}</sourceDirectory>
<includes>**\/*.java,**\/*.xml,**\/*.ini,**\/*.sh,**\/*.bat,**\/*.yang</includes>
- <excludes>**\/target\/,**\/bin\/,**\/target-ide\/,**\/src/main/yang-gen-config\/,**\/src/main/yang-gen-sal\/,**\/.m2repo\/</excludes>
+ <excludes>**\/target\/,**\/bin\/,**\/target-ide\/,**\/src/main/yang-gen-config\/,**\/src/main/yang-gen-sal\/,**\/
+ .m2repo\/,**\/org/opendaylight/protocol/util/LoggerUtil.java</excludes>
</configuration>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>pcep-ietf-stateful07</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>testtool-util</artifactId>
+ </dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
-import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
-import com.google.common.net.HostAndPort;
import com.google.common.net.InetAddresses;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
-import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;
import org.opendaylight.protocol.pcep.PCEPCapability;
import org.opendaylight.protocol.pcep.ietf.stateful07.PCEPStatefulCapability;
+import org.opendaylight.protocol.util.InetSocketAddressUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
int argIdx = 0;
while (argIdx < args.length) {
if (args[argIdx].equals("--local-address")) {
- localAddress = getInetSocketAddress(args[++argIdx], DEFAULT_LOCAL_PORT);
+ localAddress = InetSocketAddressUtil.getInetSocketAddress(args[++argIdx], DEFAULT_LOCAL_PORT);
} else if (args[argIdx].equals("--remote-address")) {
- remoteAddress = parseAddresses(args[++argIdx], DEFAULT_REMOTE_PORT);
+ remoteAddress = InetSocketAddressUtil.parseAddresses(args[++argIdx], DEFAULT_REMOTE_PORT);
} else if (args[argIdx].equals("--pcc")) {
pccCount = Integer.valueOf(args[++argIdx]);
} else if (args[argIdx].equals("--lsp")) {
}
});
}
-
- private static List<InetSocketAddress> parseAddresses(final String address, final int defaultPort) {
- return Lists.transform(Arrays.asList(address.split(",")), new Function<String, InetSocketAddress>() {
- @Override
- public InetSocketAddress apply(final String input) {
- return getInetSocketAddress(input, defaultPort);
- }
- });
- }
-
- private static InetSocketAddress getInetSocketAddress(final String hostPortString, final int defaultPort) {
- final HostAndPort hostAndPort = HostAndPort.fromString(hostPortString).withDefaultPort(defaultPort);
- return new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPort());
- }
-
}
<!--Test tools -->
<module>data-change-counter</module>
+ <module>testtool-util</module>
<module>data-change-counter-controller-config</module>
<module>distribution-karaf</module>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ ~
+ ~ This program and the accompanying materials are made available under the
+ ~ terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ ~ and is available at http://www.eclipse.org/legal/epl-v10.html
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.opendaylight.bgpcep</groupId>
+ <artifactId>bgpcep-parent</artifactId>
+ <version>0.6.0-SNAPSHOT</version>
+ <relativePath>../parent</relativePath>
+ </parent>
+
+ <artifactId>testtool-util</artifactId>
+ <packaging>bundle</packaging>
+ <prerequisites>
+ <maven>3.0.4</maven>
+ </prerequisites>
+ <dependencies>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </dependency>
+ <!-- Testing dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <!--
+ Maven Site Configuration
+
+ The following configuration is necessary for maven-site-plugin to
+ correctly identify the correct deployment path for OpenDaylight Maven
+ sites.
+ -->
+ <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
+
+ <distributionManagement>
+ <site>
+ <id>opendaylight-site</id>
+ <url>${nexus.site.url}/${project.artifactId}/</url>
+ </site>
+ </distributionManagement>
+</project>
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.util;
+
+import ch.qos.logback.classic.Level;
+
+/** Marker for LoggerUtil **/
+public interface ArgumentsInput {
+ Level getLogLevel();
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.util;
+
+import com.google.common.collect.Lists;
+import com.google.common.net.HostAndPort;
+import java.net.InetSocketAddress;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Created as a util for test tools
+ */
+public final class InetSocketAddressUtil {
+ private static final String SEPARATOR = ",";
+
+ private InetSocketAddressUtil() {
+ throw new UnsupportedOperationException();
+ }
+
+ public static List<InetSocketAddress> parseAddresses(final String address, final int defaultPort) {
+ return Lists.transform(Arrays.asList(address.split(SEPARATOR)), input -> getInetSocketAddress(input, defaultPort));
+ }
+
+ public static List<InetSocketAddress> parseAddresses(final String address) {
+ return Lists.transform(Arrays.asList(address.split(SEPARATOR)), input -> getInetSocketAddress(input, null));
+ }
+
+ public static InetSocketAddress getInetSocketAddress(final String hostPortString, final Integer defaultPort) {
+ final HostAndPort hostAndPort = HostAndPort.fromString(hostPortString);
+ if (defaultPort != null) {
+ return new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPortOrDefault(defaultPort));
+ }
+ return new InetSocketAddress(hostAndPort.getHostText(), hostAndPort.getPort());
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.util;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.ConsoleAppender;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class LoggerUtil {
+ private LoggerUtil() {
+ throw new UnsupportedOperationException();
+ }
+
+ public static void initiateLogger(final ArgumentsInput arguments) {
+ final LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
+ final ConsoleAppender<ILoggingEvent> consoleAppender = createConsoleAppender(loggerContext);
+ setLogLevel(consoleAppender, Level.OFF, Logger.ROOT_LOGGER_NAME);
+ setLogLevel(consoleAppender, arguments.getLogLevel(), "org.opendaylight.protocol");
+ }
+
+ private static ConsoleAppender<ILoggingEvent> createConsoleAppender(final LoggerContext loggerContext) {
+ final PatternLayoutEncoder ple = new PatternLayoutEncoder();
+ ple.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{10} - %msg%n");
+ ple.setContext(loggerContext);
+ ple.start();
+
+ final ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>();
+ consoleAppender.setContext(loggerContext);
+ consoleAppender.setEncoder(ple);
+ consoleAppender.setName("STDOUT");
+ consoleAppender.start();
+ return consoleAppender;
+ }
+
+ private static void setLogLevel(final ConsoleAppender<ILoggingEvent> consoleAppender, final Level level, final String clazz) {
+ final ch.qos.logback.classic.Logger protocolLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(clazz);
+ protocolLogger.addAppender(consoleAppender);
+ protocolLogger.setLevel(level);
+ protocolLogger.setAdditive(false);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.util;
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.InetSocketAddress;
+import java.util.Arrays;
+import java.util.List;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class InetSocketAddressUtilTest {
+ private static String ADDRESS1 = "1.1.1.1";
+ private static String ADDRESS2 = "2.2.2.2";
+ private static int PORT1 = 123;
+ private static int PORT2 = 321;
+ private static String ADDRESSES_WO_PORT = ADDRESS1 + "," + ADDRESS2;
+ private static String ADDRESSES = ADDRESS1 + ":" + PORT1 + "," + ADDRESS2 + ":" + PORT2;
+ private static int DEFAULT_PORT = 179;
+
+ @Test
+ public void parseAddresses() throws Exception {
+ final List<InetSocketAddress> actualResult = InetSocketAddressUtil.parseAddresses(ADDRESSES, DEFAULT_PORT);
+ Assert.assertEquals(Arrays.asList(new InetSocketAddress(ADDRESS1, PORT1), new InetSocketAddress(ADDRESS2, PORT2)), actualResult);
+ }
+
+ @Test
+ public void parseAddressesDefaultPort() throws Exception {
+ final List<InetSocketAddress> actualResult = InetSocketAddressUtil.parseAddresses(ADDRESSES_WO_PORT, DEFAULT_PORT);
+ final List<InetSocketAddress> expected = Arrays.asList(new InetSocketAddress(ADDRESS1, DEFAULT_PORT), new InetSocketAddress(ADDRESS2, DEFAULT_PORT));
+ Assert.assertEquals(expected, actualResult);
+ }
+
+ @Test
+ public void parseAddressesWithoutPort() throws Exception {
+ final List<InetSocketAddress> actualResult = InetSocketAddressUtil.parseAddresses(ADDRESSES);
+ Assert.assertEquals(Arrays.asList(new InetSocketAddress(ADDRESS1, PORT1), new InetSocketAddress(ADDRESS2, PORT2)), actualResult);
+ }
+
+ @Test
+ public void getInetSocketAddress() throws Exception {
+ assertEquals(new InetSocketAddress(ADDRESS1, PORT1), InetSocketAddressUtil.getInetSocketAddress(ADDRESS1 + ":" + PORT1, DEFAULT_PORT));
+ assertEquals(new InetSocketAddress(ADDRESS1, DEFAULT_PORT), InetSocketAddressUtil.getInetSocketAddress(ADDRESS1, DEFAULT_PORT));
+ }
+}
\ No newline at end of file
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IetfInetUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
}
return new InetSocketAddress(InetAddresses.forString(ipString), port.getValue());
}
+
+ /**
+ * Increment Address
+ *
+ * @param ipv4Address String containing Ipv4Address
+ * @return String containing Ipv4Address incremented by 1
+ */
+ public static String incrementIpv4Address(final String ipv4Address) {
+ return InetAddresses.increment(InetAddresses.forString(ipv4Address)).getHostAddress();
+ }
+
+ /**
+ * Increment Address
+ *
+ * @param ipv4Address ipv4 address to be incremented
+ * @return new ipv4 address
+ */
+ public static Ipv4Address incrementIpv4Address(final Ipv4Address ipv4Address) {
+ return new Ipv4Address(incrementIpv4Address(ipv4Address.getValue()));
+ }
+
+ public static Ipv4Prefix incrementIpv4Prefix(final Ipv4Prefix ipv4Prefix) {
+ final Map.Entry<Ipv4Address, Integer> splitIpv4Prefix = IetfInetUtil.INSTANCE.splitIpv4Prefix(ipv4Prefix);
+ return IetfInetUtil.INSTANCE.ipv4PrefixFor(incrementIpv4Address(splitIpv4Prefix.getKey()), splitIpv4Prefix.getValue());
+ }
}