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.util.HashedWheelTimer;
12 import java.net.InetAddress;
13 import java.net.InetSocketAddress;
15 import org.opendaylight.protocol.framework.DispatcherImpl;
16 import org.opendaylight.protocol.pcep.PCEPMessage;
17 import org.opendaylight.protocol.pcep.PCEPSession;
18 import org.opendaylight.protocol.pcep.PCEPSessionListener;
19 import org.opendaylight.protocol.pcep.PCEPSessionListenerFactory;
20 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
21 import org.opendaylight.protocol.pcep.PCEPTerminationReason;
22 import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
23 import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
24 import org.opendaylight.protocol.pcep.impl.PCEPSessionProposalFactoryImpl;
25 import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
29 public static String usage = "DESCRIPTION:\n" + "\tCreates a server with given parameters. As long as it runs, it accepts connections "
30 + "from PCCs.\n" + "USAGE:\n" + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
31 + "\t\tFormat: x.x.x.x:y where y is port number.\n\n" +
33 "\t-d, --deadtimer\n" + "\t\tin seconds, value of the desired deadtimer\n"
34 + "\t\tAccording to RFC5440, recommended value for deadtimer is 4 times the value\n"
35 + "\t\tof KeepAlive timer. If it's not, a warning is printed.\n"
36 + "\t\tIf not set, it's value will be derived from KeepAlive timer value.\n\n" +
38 "\t-ka, --keepalive\n" + "\t\tin seconds, value of the desired KeepAlive timer.\n"
39 + "\t\tIf not present, KeepAlive timer will be set to recommended value (30s).\n\n" +
41 "\t--stateful\n" + "\t\tpassive stateful\n\n" +
43 "\t--active\n" + "\t\tactive stateful (implies --stateful)\n\n" +
45 "\t--versioned\n" + "\t\tversioned stateful (implies --stateful)\n\n" +
48 + "\t\tinstantiated stateful, <seconds> cleanup timeout (default value, if not included = 0) (implies --stateful)\n\n" +
50 "\t-arm, --autoResponseMessages <path to file>\n"
51 + "\t\t <path to file> with groovy script which implements MessageGeneratorService.\n"
52 + "\t\t Messages are used as auto response for every message received. Purely for testing puposes! \n\n" +
54 "\t-psm, --periodicallySendMessages <path to file> <period>\n"
55 + "\t\t <path to file> with groovy script which implements MessageGeneratorService followed by <period> in seconds.\n"
56 + "\t\t Messages which are sent periodically. Purely for testing puposes! \n\n" +
58 "\t-snm, --sendNowMessage <path to file>\n"
59 + "\t\t <path to file> with groovy script which implements MessageGeneratorService.\n"
60 + "\t\t Messages are sent in defined states defined by programmer. Purely for testing puposes! \n\n" +
62 "\t--help\n" + "\t\tdisplay this help and exits\n\n" +
64 "With no parameters, this help is printed.";
66 public static void main(final String[] args) throws Exception {
67 if (args.length == 0 || args.length == 1 && args[0].equalsIgnoreCase("--help")) {
68 System.out.println(Main.usage);
72 InetSocketAddress address = null;
73 int keepAliveValue = 30;
74 int deadTimerValue = 0;
75 boolean stateful = false;
76 boolean active = false;
77 boolean versioned = false;
78 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.valueOf(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("--versioned")) {
101 } else if (args[i].equalsIgnoreCase("--instant")) {
104 if (i == args.length - 1) {
106 } else if (Integer.valueOf(args[i + 1]) > 0 && Integer.valueOf(args[i + 1]) < Integer.MAX_VALUE) {
107 timeout = Integer.valueOf(args[i + 1]);
111 System.out.println("WARNING: Unrecognized argument: " + args[i]);
115 if (deadTimerValue != 0 && deadTimerValue != keepAliveValue * 4) {
116 System.out.println("WARNING: The value of DeadTimer should be 4 times the value of KeepAlive.");
118 if (deadTimerValue == 0) {
119 deadTimerValue = keepAliveValue * 4;
122 final PCEPSessionProposalFactory spf = new PCEPSessionProposalFactoryImpl(deadTimerValue,
123 keepAliveValue, stateful, active, versioned, instant, timeout);
125 final PCEPOpenObject prefs = spf.getSessionProposal(address, 0);
127 final DispatcherImpl d = new DispatcherImpl();
128 final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(d,
129 new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), prefs, 5));
131 dispatcher.createServer(address, new PCEPSessionListenerFactory() {
133 public PCEPSessionListener getSessionListener() {
134 return new PCEPSessionListener() {
136 public void onMessage(final PCEPSession session, final PCEPMessage message) {
137 // TODO Auto-generated method stub
141 public void onSessionUp(final PCEPSession session) {
142 // TODO Auto-generated method stub
146 public void onSessionTerminated(final PCEPSession session, final PCEPTerminationReason cause) {
147 // TODO Auto-generated method stub
151 public void onSessionDown(final PCEPSession session, final Exception e) {
152 // TODO Auto-generated method stub