-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathargs.go
85 lines (78 loc) · 2.68 KB
/
args.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"github.com/kffl/speedbump/lib"
"gopkg.in/alecthomas/kingpin.v2"
)
func parseArgs(args []string) (*lib.SpeedbumpCfg, error) {
var app = kingpin.New("speedbump", "TCP proxy for simulating variable network latency.")
var (
host = app.Flag("host", "IP or hostname to listen on. Speedbump will bind to all network interfaces if unspecified.").
Default("").
String()
port = app.Flag("port", "Port number to listen on.").Default("8000").Int()
bufferSize = app.Flag("buffer", "Size of the buffer used for TCP reads.").
Default("64KB").
Bytes()
queueSize = app.Flag("queue-size", "Size of the delay queue storing read buffers.").
Default("1024").
Int()
latency = app.Flag("latency", "Base latency added to proxied traffic.").
Default("5ms").
Duration()
logLevel = app.Flag("log-level", "Log level. Possible values: DEBUG, TRACE, INFO, WARN, ERROR.").
Default("INFO").
Enum("DEBUG", "TRACE", "INFO", "WARN", "ERROR")
sineAmplitude = app.Flag("sine-amplitude", "Amplitude of the latency sine wave.").
PlaceHolder("0").
Duration()
sinePeriod = app.Flag("sine-period", "Period of the latency sine wave.").
PlaceHolder("0").
Duration()
sawAmplitude = app.Flag("saw-amplitude", "Amplitude of the latency sawtooth wave.").
PlaceHolder("0").
Duration()
sawPeriod = app.Flag("saw-period", "Period of the latency sawtooth wave.").
PlaceHolder("0").
Duration()
squareAmplitude = app.Flag("square-amplitude", "Amplitude of the latency square wave.").
PlaceHolder("0").
Duration()
squarePeriod = app.Flag("square-period", "Period of the latency square wave.").
PlaceHolder("0").
Duration()
triangleAmplitude = app.Flag("triangle-amplitude", "Amplitude of the latency triangle wave.").
PlaceHolder("0").
Duration()
trianglePeriod = app.Flag("triangle-period", "Period of the latency triangle wave.").
PlaceHolder("0").
Duration()
destAddr = app.Arg("destination", "TCP proxy destination in host:post format.").
Required().
String()
)
app.Version("1.1.0")
_, err := app.Parse(args)
if err != nil {
return nil, err
}
var cfg = lib.SpeedbumpCfg{
Host: *host,
Port: *port,
DestAddr: *destAddr,
BufferSize: int(*bufferSize),
QueueSize: *queueSize,
Latency: &lib.LatencyCfg{
Base: *latency,
SineAmplitude: *sineAmplitude,
SinePeriod: *sinePeriod,
SawAmplitude: *sawAmplitude,
SawPeriod: *sawPeriod,
SquareAmplitude: *squareAmplitude,
SquarePeriod: *squarePeriod,
TriangleAmplitude: *triangleAmplitude,
TrianglePeriod: *trianglePeriod,
},
LogLevel: *logLevel,
}
return &cfg, err
}