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.ArrayList;
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 ArrayList<String> auth;
56 static ArgumentParser getParser() {
57 final ArgumentParser parser = ArgumentParsers.newArgumentParser("netconf stress client");
59 parser.description("Netconf stress client");
61 parser.addArgument("--ip")
63 .setDefault("127.0.0.1")
64 .help("Restconf server IP")
67 parser.addArgument("--port")
70 .help("Restconf server port")
73 parser.addArgument("--destination")
75 .setDefault("/restconf/config/network-topology:network-topology/topology/topology-netconf/node/" +
76 "{DEVICE_PORT}-sim-device/yang-ext:mount/cisco-vpp:vpp/bridge-domains/bridge-domain/a")
77 .help("Destination to send the requests to after the ip:port part of the uri. " +
78 "Use {DEVICE_PORT} tag to use the device-port-range-start argument")
81 parser.addArgument("--edits")
84 .help("Amount requests to be sent")
87 parser.addArgument("--edit-content")
89 .setDefault(new File("edit.txt"))
90 .dest("edit-content");
92 parser.addArgument("--async-requests")
97 parser.addArgument("--thread-amount")
100 .dest("thread-amount");
102 parser.addArgument("--same-device")
105 .help("If true, every thread edits the device at the first port. If false, n-th thread edits device at n-th port.")
106 .dest("same-device");
108 parser.addArgument("--device-port-range-start")
111 .dest("device-port-range-start");
113 parser.addArgument("--throttle")
116 .help("Maximum amount of async requests that can be open at a time, " +
117 "with mutltiple threads this gets divided among all threads")
120 parser.addArgument("--auth")
122 .help("Username and password for HTTP basic authentication in order username password.")
129 Preconditions.checkArgument(port > 0, "Port =< 0");
130 Preconditions.checkArgument(editCount > 0, "Edit count =< 0");
132 Preconditions.checkArgument(editContent.exists(), "Edit content file missing");
133 Preconditions.checkArgument(editContent.isDirectory() == false, "Edit content file is a dir");
134 Preconditions.checkArgument(editContent.canRead(), "Edit content file is unreadable");
136 Preconditions.checkArgument(destination.startsWith("/"), "Destination should start with a '/'");
141 public InetSocketAddress getInetAddress() {
143 return new InetSocketAddress(InetAddress.getByName(ip), port);
144 } catch (final UnknownHostException e) {
145 throw new IllegalArgumentException("Unknown ip", e);