*/
package org.opendaylight.protocol.bgp.testtool;
+import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.GlobalEventExecutor;
-import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
-import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
-import org.opendaylight.protocol.bgp.parser.spi.pojo.BGPExtensionConsumerContextImpl;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
import org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl;
import org.opendaylight.protocol.bgp.rib.impl.BGPSessionProposalImpl;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
*/
public class Main {
- private final static Logger logger = LoggerFactory.getLogger(Main.class);
+ private static final Logger logger = LoggerFactory.getLogger(Main.class);
- public static 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"
+ private static 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" +
"With no parameters, this help is printed.";
- BGPDispatcherImpl dispatcher;
+ private final BGPDispatcherImpl dispatcher;
- public Main() throws IOException {
- this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactoryImpl(BGPExtensionConsumerContextImpl.getSingletonInstance().getMessageRegistry()));
+ private static final int INITIAL_HOLD_TIME = 90;
+
+ private static final int RECONNECT_MILLIS = 5000;
+
+ private Main() throws Exception {
+ this.dispatcher = new BGPDispatcherImpl(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry(), new NioEventLoopGroup(), new NioEventLoopGroup());
}
- public static void main(final String[] args) throws NumberFormatException, IOException {
+ public static void main(final String[] args) throws Exception {
if (args.length == 0 || args.length == 1 && args[0].equalsIgnoreCase("--help")) {
System.out.println(Main.usage);
return;
}
InetSocketAddress address = null;
- short holdTimerValue = 90;
+ short holdTimerValue = INITIAL_HOLD_TIME;
AsNumber as = null;
int i = 0;
as = new AsNumber(Long.valueOf(args[i + 1]));
i++;
} else {
- System.out.println("WARNING: Unrecognized argument: " + args[i]);
+ logger.error("WARNING: Unrecognized argument: " + args[i]);
}
i++;
}
logger.debug("{} {} {}", address, sessionListener, proposal);
final InetSocketAddress addr = address;
- m.dispatcher.createClient(addr, proposal, sessionListener, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000));
+ m.dispatcher.createClient(addr, proposal, sessionListener,
+ new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, RECONNECT_MILLIS));
}
}