Bug 8153: enforce check-style rules for netconf
[netconf.git] / 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. "
109                     + "If false, n-th thread edits device at n-th port.")
110                 .dest("same-device");
111
112         parser.addArgument("--device-port-range-start")
113                 .type(Integer.class)
114                 .setDefault(17830)
115                 .dest("device-port-range-start");
116
117         parser.addArgument("--throttle")
118                 .type(Integer.class)
119                 .setDefault(5000)
120                 .help("Maximum amount of async requests that can be open at a time, "
121                         + "with mutltiple threads this gets divided among all threads")
122                 .dest("throttle");
123
124         parser.addArgument("--auth")
125                 .nargs(2)
126                 .help("Username and password for HTTP basic authentication in order username password.")
127                 .dest("auth");
128
129         parser.addArgument("--timeout")
130                 .type(Long.class)
131                 .setDefault(5)
132                 .help("Maximum time in minutes to wait for finishing all requests.")
133                 .dest("timeout");
134
135         return parser;
136     }
137
138     void validate() {
139         Preconditions.checkArgument(port > 0, "Port =< 0");
140         Preconditions.checkArgument(editCount > 0, "Edit count =< 0");
141         Preconditions.checkArgument(timeout > 0, "Timeout =< 0");
142
143         Preconditions.checkArgument(editContent.exists(), "Edit content file missing");
144         Preconditions.checkArgument(editContent.isDirectory() == false, "Edit content file is a dir");
145         Preconditions.checkArgument(editContent.canRead(), "Edit content file is unreadable");
146
147         Preconditions.checkArgument(destination.startsWith("/"), "Destination should start with a '/'");
148         Preconditions.checkArgument(threadAmount > 0, "Parameter thread-amount must be greater than 0");
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 }