Remove netconf from commons/opendaylight pom
[controller.git] / opendaylight / netconf / tools / netconf-testtool / src / main / java / org / opendaylight / controller / 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.controller.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 net.sourceforge.argparse4j.ArgumentParsers;
17 import net.sourceforge.argparse4j.annotation.Arg;
18 import net.sourceforge.argparse4j.inf.ArgumentParser;
19
20 public class Parameters {
21
22     @Arg(dest = "ip")
23     public String ip;
24
25     @Arg(dest = "port")
26     public int port;
27
28     @Arg(dest = "destination")
29     public String destination;
30
31     @Arg(dest = "edit-count")
32     public int editCount;
33
34     @Arg(dest = "edit-content")
35     public File editContent;
36
37     @Arg(dest = "async")
38     public boolean async;
39
40     @Arg(dest = "thread-amount")
41     public int threadAmount;
42
43     @Arg(dest = "same-device")
44     public boolean sameDevice;
45
46     @Arg(dest = "device-port-range-start")
47     public int devicePortRangeStart;
48
49     @Arg(dest = "throttle")
50     public int throttle;
51
52     static ArgumentParser getParser() {
53         final ArgumentParser parser = ArgumentParsers.newArgumentParser("netconf stress client");
54
55         parser.description("Netconf stress client");
56
57         parser.addArgument("--ip")
58                 .type(String.class)
59                 .setDefault("127.0.0.1")
60                 .help("Restconf server IP")
61                 .dest("ip");
62
63         parser.addArgument("--port")
64                 .type(Integer.class)
65                 .setDefault(8181)
66                 .help("Restconf server port")
67                 .dest("port");
68
69         parser.addArgument("--destination")
70                 .type(String.class)
71                 .setDefault("/restconf/config/network-topology:network-topology/topology/topology-netconf/node/" +
72                         "{DEVICE_PORT}-sim-device/yang-ext:mount/cisco-vpp:vpp/bridge-domains/bridge-domain/a")
73                 .help("Destination to send the requests to after the ip:port part of the uri. " +
74                         "Use {DEVICE_PORT} tag to use the device-port-range-start argument")
75                 .dest("destination");
76
77         parser.addArgument("--edits")
78                 .type(Integer.class)
79                 .setDefault(50000)
80                 .help("Amount requests to be sent")
81                 .dest("edit-count");
82
83         parser.addArgument("--edit-content")
84                 .type(File.class)
85                 .setDefault(new File("edit.txt"))
86                 .dest("edit-content");
87
88         parser.addArgument("--async-requests")
89                 .type(Boolean.class)
90                 .setDefault(true)
91                 .dest("async");
92
93         parser.addArgument("--thread-amount")
94                 .type(Integer.class)
95                 .setDefault(1)
96                 .dest("thread-amount");
97
98         parser.addArgument("--same-device")
99                 .type(Boolean.class)
100                 .setDefault(true)
101                 .help("If true, every thread edits the device at the first port. If false, n-th thread edits device at n-th port.")
102                 .dest("same-device");
103
104         parser.addArgument("--device-port-range-start")
105                 .type(Integer.class)
106                 .setDefault(17830)
107                 .dest("device-port-range-start");
108
109         parser.addArgument("--throttle")
110                 .type(Integer.class)
111                 .setDefault(5000)
112                 .help("Maximum amount of async requests that can be open at a time, " +
113                         "with mutltiple threads this gets divided among all threads")
114                 .dest("throttle");
115
116         return parser;
117     }
118
119     void validate() {
120         Preconditions.checkArgument(port > 0, "Port =< 0");
121         Preconditions.checkArgument(editCount > 0, "Edit count =< 0");
122
123         Preconditions.checkArgument(editContent.exists(), "Edit content file missing");
124         Preconditions.checkArgument(editContent.isDirectory() == false, "Edit content file is a dir");
125         Preconditions.checkArgument(editContent.canRead(), "Edit content file is unreadable");
126         // TODO validate
127     }
128
129     public InetSocketAddress getInetAddress() {
130         try {
131             return new InetSocketAddress(InetAddress.getByName(ip), port);
132         } catch (final UnknownHostException e) {
133             throw new IllegalArgumentException("Unknown ip", e);
134         }
135     }
136 }