Remove reliance on BGPMessageFactory
[bgpcep.git] / bgp / testtool / src / main / java / org / opendaylight / protocol / bgp / testtool / Main.java
index be5f26d2c4d2328baa36f947c177c2028e8ca7a8..059788c5a24445cb1a28a047a70c9ce87d4a1038 100644 (file)
@@ -7,14 +7,14 @@
  */
 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.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;
@@ -29,10 +29,11 @@ import org.slf4j.LoggerFactory;
  */
 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" +
 
@@ -46,20 +47,24 @@ public class Main {
 
                        "With no parameters, this help is printed.";
 
-       BGPDispatcherImpl dispatcher;
+       private final BGPDispatcherImpl dispatcher;
 
-       public Main() throws IOException {
-               this.dispatcher = new BGPDispatcherImpl(BGPMessageFactoryImpl.INSTANCE);
+       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;
@@ -75,7 +80,7 @@ public class Main {
                                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++;
                }
@@ -91,6 +96,7 @@ public class Main {
                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));
        }
 }