2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.pcep.testtool;
10 import io.netty.channel.nio.NioEventLoopGroup;
11 import java.net.InetAddress;
12 import java.net.InetSocketAddress;
13 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
14 import org.opendaylight.protocol.pcep.ietf.initiated00.Stateful07SessionProposalFactory;
15 import org.opendaylight.protocol.pcep.ietf.stateful07.StatefulActivator;
16 import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
17 import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
18 import org.opendaylight.protocol.pcep.spi.pojo.ServiceLoaderPCEPExtensionProviderContext;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public final class Main {
25 private static final Logger LOG = LoggerFactory.getLogger(Main.class);
27 public static final String USAGE = "DESCRIPTION:\n"
28 + "\tCreates a server with given parameters. As long as it runs, it accepts connections " + "from PCCs.\n" + "USAGE:\n"
29 + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
30 + "\t\tFormat: x.x.x.x:y where y is port number.\n\n" +
32 "\t-d, --deadtimer\n" + "\t\tin seconds, value of the desired deadtimer\n"
33 + "\t\tAccording to RFC5440, recommended value for deadtimer is 4 times the value\n"
34 + "\t\tof KeepAlive timer. If it's not, a warning is printed.\n"
35 + "\t\tIf not set, it's value will be derived from KeepAlive timer value.\n\n" +
37 "\t-ka, --keepalive\n" + "\t\tin seconds, value of the desired KeepAlive timer.\n"
38 + "\t\tIf not present, KeepAlive timer will be set to recommended value (30s).\n\n" +
40 "\t--stateful\n" + "\t\tpassive stateful\n\n" +
42 "\t--active\n" + "\t\tactive stateful (implies --stateful)\n\n" +
45 + "\t\tinstantiated stateful, <seconds> cleanup timeout (default value, if not included = 0) (implies --stateful)\n\n" +
47 "\t-arm, --autoResponseMessages <path to file>\n"
48 + "\t\t <path to file> with groovy script which implements MessageGeneratorService.\n"
49 + "\t\t Messages are used as auto response for every message received. Purely for testing puposes! \n\n" +
51 "\t-psm, --periodicallySendMessages <path to file> <period>\n"
52 + "\t\t <path to file> with groovy script which implements MessageGeneratorService followed by <period> in seconds.\n"
53 + "\t\t Messages which are sent periodically. Purely for testing puposes! \n\n" +
55 "\t-snm, --sendNowMessage <path to file>\n"
56 + "\t\t <path to file> with groovy script which implements MessageGeneratorService.\n"
57 + "\t\t Messages are sent in defined states defined by programmer. Purely for testing puposes! \n\n" +
59 "\t--help\n" + "\t\tdisplay this help and exits\n\n" +
61 "With no parameters, this help is printed.";
67 public static void main(final String[] args) throws Exception {
68 if (args.length == 0 || (args.length == 1 && args[0].equalsIgnoreCase("--help"))) {
73 InetSocketAddress address = null;
74 int keepAliveValue = 30;
75 int deadTimerValue = 0;
76 boolean stateful = false;
77 boolean active = false;
78 final boolean versioned = false;
79 boolean instant = false;
82 while (i < args.length) {
83 if (args[i].equalsIgnoreCase("-a") || args[i].equalsIgnoreCase("--address")) {
84 final String[] ip = args[i + 1].split(":");
85 address = new InetSocketAddress(InetAddress.getByName(ip[0]), Integer.parseInt(ip[1]));
87 } else if (args[i].equalsIgnoreCase("-d") || args[i].equalsIgnoreCase("--deadtimer")) {
88 deadTimerValue = Integer.valueOf(args[i + 1]);
90 } else if (args[i].equalsIgnoreCase("-ka") || args[i].equalsIgnoreCase("--keepalive")) {
91 keepAliveValue = Integer.valueOf(args[i + 1]);
93 } else if (args[i].equalsIgnoreCase("--stateful")) {
95 } else if (args[i].equalsIgnoreCase("--active")) {
98 } else if (args[i].equalsIgnoreCase("--instant")) {
102 LOG.warn("WARNING: Unrecognized argument: {}", args[i]);
106 if (deadTimerValue != 0 && deadTimerValue != keepAliveValue * 4) {
107 LOG.warn("WARNING: The value of DeadTimer should be 4 times the value of KeepAlive.");
109 if (deadTimerValue == 0) {
110 deadTimerValue = keepAliveValue * 4;
113 final PCEPSessionProposalFactory spf = new Stateful07SessionProposalFactory(deadTimerValue, keepAliveValue, stateful, active, instant);
115 final Open prefs = spf.getSessionProposal(address, 0);
117 final StatefulActivator activator07 = new StatefulActivator();
118 activator07.start(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance());
120 final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(ServiceLoaderPCEPExtensionProviderContext.getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory(prefs, 5), new NioEventLoopGroup(), new NioEventLoopGroup());
122 dispatcher.createServer(address, new TestingSessionListenerFactory()).get();