7985eef925204e3656fc75698cbaaf3081141dea
[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     static ArgumentParser getParser() {
57         final ArgumentParser parser = ArgumentParsers.newArgumentParser("netconf stress client");
58
59         parser.description("Netconf stress client");
60
61         parser.addArgument("--ip")
62                 .type(String.class)
63                 .setDefault("127.0.0.1")
64                 .help("Restconf server IP")
65                 .dest("ip");
66
67         parser.addArgument("--port")
68                 .type(Integer.class)
69                 .setDefault(8181)
70                 .help("Restconf server port")
71                 .dest("port");
72
73         parser.addArgument("--destination")
74                 .type(String.class)
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")
79                 .dest("destination");
80
81         parser.addArgument("--edits")
82                 .type(Integer.class)
83                 .setDefault(50000)
84                 .help("Amount requests to be sent")
85                 .dest("edit-count");
86
87         parser.addArgument("--edit-content")
88                 .type(File.class)
89                 .setDefault(new File("edit.txt"))
90                 .dest("edit-content");
91
92         parser.addArgument("--async-requests")
93                 .type(Boolean.class)
94                 .setDefault(true)
95                 .dest("async");
96
97         parser.addArgument("--thread-amount")
98                 .type(Integer.class)
99                 .setDefault(1)
100                 .dest("thread-amount");
101
102         parser.addArgument("--same-device")
103                 .type(Boolean.class)
104                 .setDefault(true)
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");
107
108         parser.addArgument("--device-port-range-start")
109                 .type(Integer.class)
110                 .setDefault(17830)
111                 .dest("device-port-range-start");
112
113         parser.addArgument("--throttle")
114                 .type(Integer.class)
115                 .setDefault(5000)
116                 .help("Maximum amount of async requests that can be open at a time, " +
117                         "with mutltiple threads this gets divided among all threads")
118                 .dest("throttle");
119
120         parser.addArgument("--auth")
121                 .nargs(2)
122                 .help("Username and password for HTTP basic authentication in order username password.")
123                 .dest("auth");
124
125         return parser;
126     }
127
128     void validate() {
129         Preconditions.checkArgument(port > 0, "Port =< 0");
130         Preconditions.checkArgument(editCount > 0, "Edit count =< 0");
131
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");
135
136         Preconditions.checkArgument(destination.startsWith("/"), "Destination should start with a '/'");
137
138         // TODO validate
139     }
140
141     public InetSocketAddress getInetAddress() {
142         try {
143             return new InetSocketAddress(InetAddress.getByName(ip), port);
144         } catch (final UnknownHostException e) {
145             throw new IllegalArgumentException("Unknown ip", e);
146         }
147     }
148 }