Fix junit dependencies in poms. Reuse existing from parent,
[bgpcep.git] / pcep / testtool / src / main / java / org / opendaylight / protocol / pcep / testtool / Main.java
index 7bd16b0137a84a6d52da30fe5889536c4c1873fb..006d336288677fa85da92c70aaeb885456ab1daa 100644 (file)
@@ -7,24 +7,16 @@
  */
 package org.opendaylight.protocol.pcep.testtool;
 
-import org.opendaylight.protocol.framework.DispatcherImpl;
-import org.opendaylight.protocol.pcep.PCEPConnection;
-import org.opendaylight.protocol.pcep.PCEPConnectionFactory;
-import org.opendaylight.protocol.pcep.PCEPSessionListener;
-import org.opendaylight.protocol.pcep.PCEPSessionListenerFactory;
-import org.opendaylight.protocol.pcep.PCEPSessionProposal;
-import org.opendaylight.protocol.pcep.PCEPSessionProposalChecker;
-import org.opendaylight.protocol.pcep.PCEPSessionProposalCheckerFactory;
-import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
-import org.opendaylight.protocol.pcep.impl.PCEPConnectionImpl;
-import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
-import org.opendaylight.protocol.pcep.impl.PCEPSessionProposalCheckerFactoryImpl;
-import org.opendaylight.protocol.pcep.impl.PCEPSessionProposalFactoryImpl;
+import io.netty.util.HashedWheelTimer;
 
-import java.io.IOException;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
-import java.util.concurrent.Executors;
+
+import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
+import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
+import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
+import org.opendaylight.protocol.pcep.impl.PCEPSessionProposalFactoryImpl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject;
 
 public class Main {
 
@@ -65,8 +57,8 @@ public class Main {
 
                        "With no parameters, this help is printed.";
 
-       public static void main(final String[] args) throws IOException {
-               if (args.length == 0 || (args.length == 1 && args[0].equalsIgnoreCase("--help"))) {
+       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;
                }
@@ -78,10 +70,6 @@ public class Main {
                boolean active = false;
                boolean versioned = false;
                boolean instant = false;
-               String autoResponseMessagesSrc = null;
-               String sendNowMessageSrc = null;
-               String periodicallySendMessagesSrc = null;
-               int period = 0;
                int timeout = 0;
 
                int i = 0;
@@ -107,21 +95,12 @@ public class Main {
                        } else if (args[i].equalsIgnoreCase("--instant")) {
                                stateful = true;
                                instant = true;
-                               if (Integer.valueOf(args[i + 1]) > 0 && Integer.valueOf(args[i + 1]) < Integer.MAX_VALUE) {
+                               if (i == args.length - 1) {
+                                       timeout = 0;
+                               } else if (Integer.valueOf(args[i + 1]) > 0 && Integer.valueOf(args[i + 1]) < Integer.MAX_VALUE) {
                                        timeout = Integer.valueOf(args[i + 1]);
                                        i++;
                                }
-                       } else if (args[i].equalsIgnoreCase("--autoResponseMessages") || args[i].equalsIgnoreCase("-arm")) {
-                               autoResponseMessagesSrc = args[i + 1];
-                               i++;
-                       } else if (args[i].equalsIgnoreCase("--periodicallySendMessages") || args[i].equalsIgnoreCase("-psm")) {
-                               periodicallySendMessagesSrc = args[i + 1];
-                               i++;
-                               period = Integer.valueOf(args[i + 1]);
-                               i++;
-                       } else if (args[i].equalsIgnoreCase("--sendNowMessage") || args[i].equalsIgnoreCase("-snm")) {
-                               sendNowMessageSrc = args[i + 1];
-                               i++;
                        } else {
                                System.out.println("WARNING: Unrecognized argument: " + args[i]);
                        }
@@ -134,42 +113,12 @@ public class Main {
                        deadTimerValue = keepAliveValue * 4;
                }
 
-               final PCEPSessionListenerFactory slf = new TestingSessionListenerFactory(autoResponseMessagesSrc, periodicallySendMessagesSrc, period, sendNowMessageSrc);
                final PCEPSessionProposalFactory spf = new PCEPSessionProposalFactoryImpl(deadTimerValue, keepAliveValue, stateful, active, versioned, instant, timeout);
-               final PCEPSessionProposalCheckerFactory spcf = new PCEPSessionProposalCheckerFactoryImpl();
-
-               final PCEPSessionProposal prefs = spf.getSessionProposal(address, 0);
 
-               final DispatcherImpl d = new DispatcherImpl(Executors.defaultThreadFactory());
-               final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(d, spf);
+               final OpenObject prefs = spf.getSessionProposal(address, 0);
 
-               try {
-                       dispatcher.createServer(address, new PCEPConnectionFactory() {
-                               @Override
-                               public PCEPConnection createProtocolConnection(final InetSocketAddress address) {
-                                       final PCEPSessionProposalChecker checker = spcf.getPreferencesChecker(address);
-                                       final PCEPSessionListener lsnr = slf.getSessionListener(address.getAddress());
+               final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), prefs, 5));
 
-                                       return new PCEPConnectionImpl(address, lsnr, prefs.getProposal(), checker);
-                               }
-
-                               @Override
-                               public void setProposal(final PCEPSessionProposalFactory proposals, final InetSocketAddress address, final int sessionId) {
-                               }
-                       });
-                       // final ProtocolServer s = dispatcher.createServer(address, slf, spf, spcf);
-
-                       // try {
-                       // Thread.sleep(10000);
-                       // } catch (final InterruptedException e) {
-                       // e.printStackTrace();
-                       // }
-                       //
-                       // s.close();
-
-               } finally {
-                       ((PCEPSessionProposalCheckerFactoryImpl) spcf).close();
-                       d.stop();
-               }
+               dispatcher.createServer(address, new TestingSessionListenerFactory()).get();
        }
 }