2 * Copyright (c) 2015 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.netconf.test.tool.client.stress;
10 import com.google.common.base.Preconditions;
11 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
13 import java.net.InetAddress;
14 import java.net.InetSocketAddress;
15 import java.net.UnknownHostException;
16 import net.sourceforge.argparse4j.ArgumentParsers;
17 import net.sourceforge.argparse4j.annotation.Arg;
18 import net.sourceforge.argparse4j.inf.ArgumentParser;
20 public class Parameters {
28 @Arg(dest = "edit-count")
31 @Arg(dest = "edit-content")
32 public File editContent;
34 @Arg(dest = "edit-batch-size")
35 @SuppressFBWarnings("PA_PUBLIC_PRIMITIVE_ATTRIBUTE")
36 public int editBatchSize;
38 @Arg(dest = "candidate-datastore")
39 public boolean candidateDatastore;
44 @Arg(dest = "legacy-framing")
45 public boolean legacyFraming;
56 @Arg(dest = "username")
57 public String username;
59 @Arg(dest = "password")
60 public String password;
62 @Arg(dest = "msg-timeout")
63 public long msgTimeout;
65 @Arg(dest = "tcp-header")
66 public String tcpHeader;
68 @Arg(dest = "thread-amount")
69 public int threadAmount;
71 @Arg(dest = "concurrent-message-limit")
72 public int concurrentMessageLimit;
74 static ArgumentParser getParser() {
75 final ArgumentParser parser = ArgumentParsers.newArgumentParser("netconf stress client");
77 parser.description("Netconf stress client");
79 parser.addArgument("--ip")
81 .setDefault("127.0.0.1")
83 .help("Netconf server IP")
86 parser.addArgument("--port")
90 .help("Netconf server port")
93 parser.addArgument("--edits")
97 .help("Netconf edit rpcs to be sent")
100 parser.addArgument("--edit-content")
102 .setDefault(new File("edit.txt"))
104 .dest("edit-content");
106 parser.addArgument("--edit-batch-size")
110 .dest("edit-batch-size");
112 parser.addArgument("--candidate-datastore")
115 .setDefault(Boolean.TRUE)
116 .help("Edit candidate or running datastore. Defaults to candidate.")
117 .dest("candidate-datastore");
119 parser.addArgument("--debug")
121 .setDefault(Boolean.FALSE)
122 .help("Whether to use debug log level instead of INFO")
125 parser.addArgument("--legacy-framing")
127 .setDefault(Boolean.FALSE)
128 .dest("legacy-framing");
130 parser.addArgument("--exi")
132 .setDefault(Boolean.FALSE)
135 parser.addArgument("--async-requests")
137 .setDefault(Boolean.TRUE)
140 parser.addArgument("--msg-timeout")
143 .dest("msg-timeout");
145 parser.addArgument("--ssh")
147 .setDefault(Boolean.FALSE)
150 parser.addArgument("--username")
155 parser.addArgument("--password")
160 parser.addArgument("--tcp-header")
165 parser.addArgument("--thread-amount")
168 .dest("thread-amount");
170 parser.addArgument("--concurrent-message-limit")
173 .help("Number of rpc messages that can be sent before receiving reply to them.")
174 .dest("concurrent-message-limit");
180 Preconditions.checkArgument(port > 0, "Port =< 0");
181 Preconditions.checkArgument(editCount > 0, "Edit count =< 0");
182 if (editBatchSize == -1) {
183 editBatchSize = editCount;
185 Preconditions.checkArgument(editBatchSize <= editCount, "Edit count =< 0");
188 Preconditions.checkArgument(editContent.exists(), "Edit content file missing");
189 Preconditions.checkArgument(!editContent.isDirectory(), "Edit content file is a dir");
190 Preconditions.checkArgument(editContent.canRead(), "Edit content file is unreadable");
191 Preconditions.checkArgument(threadAmount > 0, "Parameter thread-amount must be greater than 0");
192 Preconditions.checkArgument(msgTimeout >= 0, "Parameter msg-timeout must be greater than 0");
195 public InetSocketAddress getInetAddress() {
197 return new InetSocketAddress(InetAddress.getByName(ip), port);
198 } catch (final UnknownHostException e) {
199 throw new IllegalArgumentException("Unknown ip", e);