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
9 package org.opendaylight.netconf.test.tool.client.http.perf;
11 import com.google.common.base.Preconditions;
13 import java.net.InetAddress;
14 import java.net.InetSocketAddress;
15 import java.net.UnknownHostException;
16 import java.util.List;
17 import net.sourceforge.argparse4j.ArgumentParsers;
18 import net.sourceforge.argparse4j.annotation.Arg;
19 import net.sourceforge.argparse4j.inf.ArgumentParser;
21 public class Parameters {
29 @Arg(dest = "destination")
30 public String destination;
32 @Arg(dest = "edit-count")
35 @Arg(dest = "edit-content")
36 public File editContent;
41 @Arg(dest = "thread-amount")
42 public int threadAmount;
44 @Arg(dest = "same-device")
45 public boolean sameDevice;
47 @Arg(dest = "device-port-range-start")
48 public int devicePortRangeStart;
50 @Arg(dest = "throttle")
54 public List<String> auth;
56 @Arg(dest = "timeout")
59 static ArgumentParser getParser() {
60 final ArgumentParser parser = ArgumentParsers.newArgumentParser("netconf stress client");
62 parser.description("Netconf stress client");
64 parser.addArgument("--ip")
66 .setDefault("127.0.0.1")
67 .help("Restconf server IP")
70 parser.addArgument("--port")
73 .help("Restconf server port")
76 parser.addArgument("--destination")
78 .setDefault("/rests/data/network-topology:network-topology/topology=topology-netconf/node="
79 + "{DEVICE_PORT}-sim-device/yang-ext:mount/cisco-vpp:vpp/bridge-domains=bridge-domain/a")
80 .help("Destination to send the requests to after the ip:port part of the uri. "
81 + "Use {DEVICE_PORT} tag to use the device-port-range-start argument")
84 parser.addArgument("--edits")
87 .help("Amount requests to be sent")
90 parser.addArgument("--edit-content")
92 .setDefault(new File("edit.txt"))
93 .dest("edit-content");
95 parser.addArgument("--async-requests")
97 .setDefault(Boolean.TRUE)
100 parser.addArgument("--thread-amount")
103 .dest("thread-amount");
105 parser.addArgument("--same-device")
107 .setDefault(Boolean.TRUE)
108 .help("If true, every thread edits the device at the first port. "
109 + "If false, n-th thread edits device at n-th port.")
110 .dest("same-device");
112 parser.addArgument("--device-port-range-start")
115 .dest("device-port-range-start");
117 parser.addArgument("--throttle")
120 .help("Maximum amount of async requests that can be open at a time, "
121 + "with mutltiple threads this gets divided among all threads")
124 parser.addArgument("--auth")
125 .setDefault("admin", "admin")
127 .help("Username and password for HTTP basic authentication in order username password.")
130 parser.addArgument("--timeout")
133 .help("Maximum time in minutes to wait for finishing all requests.")
140 Preconditions.checkArgument(port > 0, "Port =< 0");
141 Preconditions.checkArgument(editCount > 0, "Edit count =< 0");
142 Preconditions.checkArgument(timeout > 0, "Timeout =< 0");
144 Preconditions.checkArgument(editContent.exists(), "Edit content file missing");
145 Preconditions.checkArgument(!editContent.isDirectory(), "Edit content file is a dir");
146 Preconditions.checkArgument(editContent.canRead(), "Edit content file is unreadable");
148 Preconditions.checkArgument(destination.startsWith("/"), "Destination should start with a '/'");
149 Preconditions.checkArgument(threadAmount > 0, "Parameter thread-amount must be greater than 0");
152 public InetSocketAddress getInetAddress() {
154 return new InetSocketAddress(InetAddress.getByName(ip), port);
155 } catch (final UnknownHostException e) {
156 throw new IllegalArgumentException("Unknown ip", e);