BUG 5413 - RestPerfClient: Hang on java.util.concurrent.CancellationException.
[netconf.git] / opendaylight / netconf / tools / netconf-testtool / src / main / java / org / opendaylight / netconf / test / tool / client / http / perf / Parameters.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.netconf.test.tool.client.http.perf;
10
11 import com.google.common.base.Preconditions;
12 import java.io.File;
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;
20
21 public class Parameters {
22
23     @Arg(dest = "ip")
24     public String ip;
25
26     @Arg(dest = "port")
27     public int port;
28
29     @Arg(dest = "destination")
30     public String destination;
31
32     @Arg(dest = "edit-count")
33     public int editCount;
34
35     @Arg(dest = "edit-content")
36     public File editContent;
37
38     @Arg(dest = "async")
39     public boolean async;
40
41     @Arg(dest = "thread-amount")
42     public int threadAmount;
43
44     @Arg(dest = "same-device")
45     public boolean sameDevice;
46
47     @Arg(dest = "device-port-range-start")
48     public int devicePortRangeStart;
49
50     @Arg(dest = "throttle")
51     public int throttle;
52
53     @Arg(dest = "auth")
54     public ArrayList<String> auth;
55
56     @Arg(dest = "timeout")
57     public long timeout;
58
59     static ArgumentParser getParser() {
60         final ArgumentParser parser = ArgumentParsers.newArgumentParser("netconf stress client");
61
62         parser.description("Netconf stress client");
63
64         parser.addArgument("--ip")
65                 .type(String.class)
66                 .setDefault("127.0.0.1")
67                 .help("Restconf server IP")
68                 .dest("ip");
69
70         parser.addArgument("--port")
71                 .type(Integer.class)
72                 .setDefault(8181)
73                 .help("Restconf server port")
74                 .dest("port");
75
76         parser.addArgument("--destination")
77                 .type(String.class)
78                 .setDefault("/restconf/config/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")
82                 .dest("destination");
83
84         parser.addArgument("--edits")
85                 .type(Integer.class)
86                 .setDefault(50000)
87                 .help("Amount requests to be sent")
88                 .dest("edit-count");
89
90         parser.addArgument("--edit-content")
91                 .type(File.class)
92                 .setDefault(new File("edit.txt"))
93                 .dest("edit-content");
94
95         parser.addArgument("--async-requests")
96                 .type(Boolean.class)
97                 .setDefault(true)
98                 .dest("async");
99
100         parser.addArgument("--thread-amount")
101                 .type(Integer.class)
102                 .setDefault(1)
103                 .dest("thread-amount");
104
105         parser.addArgument("--same-device")
106                 .type(Boolean.class)
107                 .setDefault(true)
108                 .help("If true, every thread edits the device at the first port. If false, n-th thread edits device at n-th port.")
109                 .dest("same-device");
110
111         parser.addArgument("--device-port-range-start")
112                 .type(Integer.class)
113                 .setDefault(17830)
114                 .dest("device-port-range-start");
115
116         parser.addArgument("--throttle")
117                 .type(Integer.class)
118                 .setDefault(5000)
119                 .help("Maximum amount of async requests that can be open at a time, " +
120                         "with mutltiple threads this gets divided among all threads")
121                 .dest("throttle");
122
123         parser.addArgument("--auth")
124                 .nargs(2)
125                 .help("Username and password for HTTP basic authentication in order username password.")
126                 .dest("auth");
127
128         parser.addArgument("--timeout")
129                 .type(Long.class)
130                 .setDefault(5)
131                 .help("Maximum time in minutes to wait for finishing all requests.")
132                 .dest("timeout");
133
134         return parser;
135     }
136
137     void validate() {
138         Preconditions.checkArgument(port > 0, "Port =< 0");
139         Preconditions.checkArgument(editCount > 0, "Edit count =< 0");
140         Preconditions.checkArgument(timeout > 0, "Timeout =< 0");
141
142         Preconditions.checkArgument(editContent.exists(), "Edit content file missing");
143         Preconditions.checkArgument(editContent.isDirectory() == false, "Edit content file is a dir");
144         Preconditions.checkArgument(editContent.canRead(), "Edit content file is unreadable");
145
146         Preconditions.checkArgument(destination.startsWith("/"), "Destination should start with a '/'");
147
148         // TODO validate
149     }
150
151     public InetSocketAddress getInetAddress() {
152         try {
153             return new InetSocketAddress(InetAddress.getByName(ip), port);
154         } catch (final UnknownHostException e) {
155             throw new IllegalArgumentException("Unknown ip", e);
156         }
157     }
158 }