Skip to content

Commit a0932ee

Browse files
authored
Merge pull request #56 from ProspectOne/feature/ipv6
Add support for IPv6 to all network tests that support it.
2 parents 464908d + 128d81b commit a0932ee

16 files changed

+124
-64
lines changed

cmd/curl.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var (
3535
if err != nil {
3636
return err
3737
}
38-
return chkRunError(runCurl(c, args[0], curlHead, curlInsecure, curlHTTP2, from, nodeIDs, curlLimit, fileOut))
38+
return chkRunError(runCurl(c, args[0], curlHead, curlInsecure, curlHTTP2, from, nodeIDs, curlLimit, fileOut, curlIpv6))
3939
},
4040
}
4141

@@ -44,6 +44,7 @@ var (
4444
curlHTTP2 bool
4545
curlLimit int
4646
fileOut string
47+
curlIpv6 bool
4748
)
4849

4950
func initCurlCmd(parentCmd *cobra.Command) {
@@ -54,21 +55,27 @@ func initCurlCmd(parentCmd *cobra.Command) {
5455
curlCmd.Flags().BoolVarP(&curlHTTP2, "http2", "", false, "Use HTTP version 2")
5556
curlCmd.Flags().IntVarP(&curlLimit, "limit", "L", 1, "The maximum number of nodes to use")
5657
curlCmd.Flags().StringVarP(&fileOut, "file", "f", "", "output to file")
58+
curlCmd.Flags().BoolVarP(&curlIpv6, "ipv6", "6", false, "Use IPv6")
5759

5860
parentCmd.AddCommand(curlCmd)
5961
}
6062

61-
func runCurl(c *perfops.Client, target string, head, insecure, http2 bool, from string, nodeIDs []int, limit int, fileOut string) error {
63+
func runCurl(c *perfops.Client, target string, head, insecure, http2 bool, from string, nodeIDs []int, limit int, fileOut string, ipv6 bool) error {
6264

6365
ctx := context.Background()
66+
ipversion := 4
67+
if ipv6 {
68+
ipversion = 6
69+
}
6470
curlReq := &perfops.CurlRequest{
65-
Target: target,
66-
Head: head,
67-
Insecure: insecure,
68-
HTTP2: http2,
69-
Location: from,
70-
Nodes: nodeIDs,
71-
Limit: limit,
71+
Target: target,
72+
Head: head,
73+
Insecure: insecure,
74+
HTTP2: http2,
75+
Location: from,
76+
Nodes: nodeIDs,
77+
Limit: limit,
78+
IPVersion: ipversion,
7279
}
7380

7481
f := internal.NewFormatter(debug && !outputJSON)

cmd/curl_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func TestInitCurlCmd(t *testing.T) {
3535
"insecure": {[]string{"--insecure"}, func() (interface{}, interface{}) { return curlInsecure, true }},
3636
"http2": {[]string{"--http2"}, func() (interface{}, interface{}) { return curlHTTP2, true }},
3737
"limit": {[]string{"--limit", "23"}, func() (interface{}, interface{}) { return curlLimit, 23 }},
38+
"ipv6": {[]string{"--ipv6"}, func() (interface{}, interface{}) { return curlIpv6, true }},
3839
}
3940
parent := &cobra.Command{}
4041
for name, tc := range testCases {
@@ -63,15 +64,17 @@ func TestRunCurlResolve(t *testing.T) {
6364
head bool
6465
insecure bool
6566
http2 bool
67+
ipv6 bool
6668
from string
6769
nodeIDs []int
6870
exp string
6971
}{
70-
"Head": {false, false, false, "From here", []int{}, `{"target":"example.com","head":false,"location":"From here","limit":12}`},
71-
"Insecure": {true, true, false, "From here", []int{}, `{"target":"example.com","head":true,"insecure":true,"location":"From here","limit":12}`},
72-
"HTTP2": {true, false, true, "From here", []int{}, `{"target":"example.com","head":true,"http2":true,"location":"From here","limit":12}`},
73-
"Location": {true, false, false, "From here", []int{}, `{"target":"example.com","head":true,"location":"From here","limit":12}`},
74-
"NodeID": {true, false, false, "", []int{123}, `{"target":"example.com","head":true,"nodes":"123","limit":12}`},
72+
"Head": {false, false, false, false, "From here", []int{}, `{"target":"example.com","head":false,"location":"From here","limit":12,"ipversion":4}`},
73+
"Insecure": {true, true, false, false, "From here", []int{}, `{"target":"example.com","head":true,"insecure":true,"location":"From here","limit":12,"ipversion":4}`},
74+
"HTTP2": {true, false, true, false, "From here", []int{}, `{"target":"example.com","head":true,"http2":true,"location":"From here","limit":12,"ipversion":4}`},
75+
"Location": {true, false, false, false, "From here", []int{}, `{"target":"example.com","head":true,"location":"From here","limit":12,"ipversion":4}`},
76+
"NodeID": {true, false, false, false, "", []int{123}, `{"target":"example.com","head":true,"nodes":"123","limit":12,"ipversion":4}`},
77+
"IPv6": {false, false, false, true, "", []int{}, `{"target":"example.com","head":false,"limit":12,"ipversion":6}`},
7578
}
7679
// We're only interested in the first HTTP call, e.g., the one to get the test ID
7780
// to validate our parameters got passed properly.
@@ -82,7 +85,7 @@ func TestRunCurlResolve(t *testing.T) {
8285
}
8386
for name, tc := range testCases {
8487
t.Run(name, func(t *testing.T) {
85-
runCurl(c, "example.com", tc.head, tc.insecure, tc.http2, tc.from, tc.nodeIDs, 12, "file.txt")
88+
runCurl(c, "example.com", tc.head, tc.insecure, tc.http2, tc.from, tc.nodeIDs, 12, "file.txt", tc.ipv6)
8689
if got, exp := tr.req.URL.Path, "/run/curl"; got != exp {
8790
t.Fatalf("expected %v; got %v", exp, got)
8891
}

cmd/dnsperf.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,38 @@ var (
3636
if err != nil {
3737
return err
3838
}
39-
return chkRunError(runDNSPerf(c, args[0], dnsPerfDNSServer, from, nodeIDs, dnsPerfLimit))
39+
return chkRunError(runDNSPerf(c, args[0], dnsPerfDNSServer, from, nodeIDs, dnsPerfLimit, dnsPerfIpv6))
4040
},
4141
}
4242

4343
dnsPerfDNSServer string
4444
dnsPerfLimit int
45+
dnsPerfIpv6 bool
4546
)
4647

4748
func initDNSPerfCmd(parentCmd *cobra.Command) {
4849
addCommonFlags(dnsPerfCmd)
4950

5051
dnsPerfCmd.Flags().StringVarP(&dnsPerfDNSServer, "dns-server", "S", "", "The DNS server to use to query for the test. You can use 127.0.0.1 to use the local resolver for location based benchmarking.")
5152
dnsPerfCmd.Flags().IntVarP(&dnsPerfLimit, "limit", "L", 1, "The maximum number of nodes to use")
53+
dnsPerfCmd.Flags().BoolVarP(&dnsPerfIpv6, "ipv6", "6", false, "Use IPv6")
5254

5355
parentCmd.AddCommand(dnsPerfCmd)
5456
}
5557

56-
func runDNSPerf(c *perfops.Client, target, dnsServer, from string, nodeIDs []int, limit int) error {
58+
func runDNSPerf(c *perfops.Client, target, dnsServer, from string, nodeIDs []int, limit int, ipv6 bool) error {
5759
ctx := context.Background()
60+
ipversion := 4
61+
if ipv6 {
62+
ipversion = 6
63+
}
5864
dnsPerfReq := &perfops.DNSPerfRequest{
5965
Target: target,
6066
DNSServer: dnsServer,
6167
Location: from,
6268
Nodes: nodeIDs,
6369
Limit: limit,
70+
IPVersion: ipversion,
6471
}
6572

6673
spinner := internal.NewSpinner()

cmd/dnsperf_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func TestInitDNSPerfCmd(t *testing.T) {
3232

3333
"dns-server": {[]string{"--dns-server", "123.234.0.1"}, func() (interface{}, interface{}) { return dnsPerfDNSServer, "123.234.0.1" }},
3434
"limit": {[]string{"--limit", "23"}, func() (interface{}, interface{}) { return dnsPerfLimit, 23 }},
35+
"ipv6": {[]string{"--ipv6"}, func() (interface{}, interface{}) { return dnsPerfIpv6, true }},
3536
}
3637
parent := &cobra.Command{}
3738
for name, tc := range testCases {
@@ -47,7 +48,7 @@ func TestInitDNSPerfCmd(t *testing.T) {
4748
t.Fatal("expected flag; got nil")
4849
}
4950

50-
got, exp := tc.gotexp();
51+
got, exp := tc.gotexp()
5152
if reflect.DeepEqual(got, exp) == false {
5253
t.Fatalf("expected %v; got %v", exp, got)
5354
}
@@ -59,10 +60,12 @@ func TestRunDNSPerf(t *testing.T) {
5960
testCases := map[string]struct {
6061
from string
6162
nodeIDs []int
63+
ipv6 bool
6264
exp string
6365
}{
64-
"Location": {"From here", []int{}, `{"target":"example.com","dnsServer":"127.0.0.1","location":"From here","limit":12}`},
65-
"NodeID": {"", []int{123}, `{"target":"example.com","dnsServer":"127.0.0.1","nodes":"123","limit":12}`},
66+
"Location": {"From here", []int{}, false, `{"target":"example.com","dnsServer":"127.0.0.1","location":"From here","limit":12,"ipversion":4}`},
67+
"NodeID": {"", []int{123}, false, `{"target":"example.com","dnsServer":"127.0.0.1","nodes":"123","limit":12,"ipversion":4}`},
68+
"IPv6": {"", []int{}, true, `{"target":"example.com","dnsServer":"127.0.0.1","limit":12,"ipversion":6}`},
6669
}
6770
// We're only interested in the first HTTP call, e.g., the one to get the test ID
6871
// to validate our parameters got passed properly.
@@ -73,7 +76,7 @@ func TestRunDNSPerf(t *testing.T) {
7376
}
7477
for name, tc := range testCases {
7578
t.Run(name, func(t *testing.T) {
76-
runDNSPerf(c, "example.com", "127.0.0.1", tc.from, tc.nodeIDs, 12)
79+
runDNSPerf(c, "example.com", "127.0.0.1", tc.from, tc.nodeIDs, 12, tc.ipv6)
7780
if got, exp := tr.req.URL.Path, "/run/dns-perf"; got != exp {
7881
t.Fatalf("expected %v; got %v", exp, got)
7982
}

cmd/internal/runtest.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ type (
5858
)
5959

6060
// RunTest runs an MTR or ping test retrieves its output and presents it to the user.
61-
func RunTest(ctx context.Context, target, location string, nodeIDs []int, limit int, debug, outputJSON bool, runTest runFunc, runOutput runOutputFunc) error {
61+
func RunTest(ctx context.Context, target, location string, nodeIDs []int, limit int, ipversion int, debug, outputJSON bool, runTest runFunc, runOutput runOutputFunc) error {
6262
runReq := &perfops.RunRequest{
63-
Target: target,
64-
Location: location,
65-
Nodes: nodeIDs,
66-
Limit: limit,
63+
Target: target,
64+
Location: location,
65+
Nodes: nodeIDs,
66+
Limit: limit,
67+
IPVersion: ipversion,
6768
}
6869

6970
f := NewFormatter(debug && !outputJSON)

cmd/internal/runtest_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestRunTest(t *testing.T) {
6565
ctx := context.Background()
6666
for name, tc := range testCases {
6767
t.Run(name, func(t *testing.T) {
68-
err := RunTest(ctx, "target", "location", []int{}, 1, false, false, tc.run, tc.output)
68+
err := RunTest(ctx, "target", "location", []int{}, 1, 4, false, false, tc.run, tc.output)
6969
if err != tc.err {
7070
t.Fatalf("expected %v; got %v", tc.err, err)
7171
}

cmd/latency.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,26 @@ var (
3434
if err != nil {
3535
return err
3636
}
37-
return chkRunError(runLatency(c, args[0], from, nodeIDs, latencyLimit))
37+
return chkRunError(runLatency(c, args[0], from, nodeIDs, latencyLimit, latencyIpv6))
3838
},
3939
}
4040

4141
latencyLimit int
42+
latencyIpv6 bool
4243
)
4344

4445
func initLatencyCmd(parentCmd *cobra.Command) {
4546
addCommonFlags(latencyCmd)
4647
parentCmd.AddCommand(latencyCmd)
4748
latencyCmd.Flags().IntVarP(&latencyLimit, "limit", "L", 1, "The maximum number of nodes to use")
49+
latencyCmd.Flags().BoolVarP(&latencyIpv6, "ipv6", "6", false, "Use IPv6")
4850
}
4951

50-
func runLatency(c *perfops.Client, target, from string, nodeIDs []int, limit int) error {
52+
func runLatency(c *perfops.Client, target, from string, nodeIDs []int, limit int, ipv6 bool) error {
5153
ctx := context.Background()
52-
return internal.RunTest(ctx, target, from, nodeIDs, limit, debug, outputJSON, c.Run.Latency, c.Run.LatencyOutput)
54+
ipversion := 4
55+
if ipv6 {
56+
ipversion = 6
57+
}
58+
return internal.RunTest(ctx, target, from, nodeIDs, limit, ipversion, debug, outputJSON, c.Run.Latency, c.Run.LatencyOutput)
5359
}

cmd/latency_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func TestInitLatencyCmd(t *testing.T) {
3131
"json": {[]string{"--json"}, func() (interface{}, interface{}) { return outputJSON, true }},
3232

3333
"limit": {[]string{"--limit", "23"}, func() (interface{}, interface{}) { return latencyLimit, 23 }},
34+
"ipv6": {[]string{"--ipv6"}, func() (interface{}, interface{}) { return latencyIpv6, true }},
3435
}
3536
parent := &cobra.Command{}
3637
for name, tc := range testCases {
@@ -40,13 +41,13 @@ func TestInitLatencyCmd(t *testing.T) {
4041
if err := latencyCmd.ParseFlags(tc.args); err != nil {
4142
t.Fatalf("exepected nil; got %v", err)
4243
}
43-
flags := dnsPerfCmd.Flags()
44+
flags := latencyCmd.Flags()
4445
f := flags.Lookup(name)
4546
if f == nil {
4647
t.Fatal("expected flag; got nil")
4748
}
4849

49-
got, exp := tc.gotexp();
50+
got, exp := tc.gotexp()
5051
if reflect.DeepEqual(got, exp) == false {
5152
t.Fatalf("expected %v; got %v", exp, got)
5253
}
@@ -58,10 +59,12 @@ func TestRunLatency(t *testing.T) {
5859
testCases := map[string]struct {
5960
from string
6061
nodeIDs []int
62+
ipv6 bool
6163
exp string
6264
}{
63-
"Location": {"From here", []int{}, `{"target":"example.com","location":"From here","limit":12}`},
64-
"NodeID": {"", []int{123}, `{"target":"example.com","nodes":"123","limit":12}`},
65+
"Location": {"From here", []int{}, false, `{"target":"example.com","location":"From here","limit":12,"ipversion":4}`},
66+
"NodeID": {"", []int{123}, false, `{"target":"example.com","nodes":"123","limit":12,"ipversion":4}`},
67+
"IPv6": {"", []int{}, true, `{"target":"example.com","limit":12,"ipversion":6}`},
6568
}
6669
// We're only interested in the first HTTP call, e.g., the one to get the test ID
6770
// to validate our parameters got passed properly.
@@ -72,7 +75,7 @@ func TestRunLatency(t *testing.T) {
7275
}
7376
for name, tc := range testCases {
7477
t.Run(name, func(t *testing.T) {
75-
runLatency(c, "example.com", tc.from, tc.nodeIDs, 12)
78+
runLatency(c, "example.com", tc.from, tc.nodeIDs, 12, tc.ipv6)
7679
if got, exp := tr.req.URL.Path, "/run/latency"; got != exp {
7780
t.Fatalf("expected %v; got %v", exp, got)
7881
}

cmd/mtr.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,26 @@ var (
3434
if err != nil {
3535
return err
3636
}
37-
return chkRunError(runMTR(c, args[0], from, nodeIDs, mtrLimit))
37+
return chkRunError(runMTR(c, args[0], from, nodeIDs, mtrLimit, mtrIpv6))
3838
},
3939
}
4040

4141
mtrLimit int
42+
mtrIpv6 bool
4243
)
4344

4445
func initMTRCmd(parentCmd *cobra.Command) {
4546
addCommonFlags(mtrCmd)
4647
mtrCmd.Flags().IntVarP(&mtrLimit, "limit", "L", 1, "The maximum number of nodes to use")
48+
mtrCmd.Flags().BoolVarP(&mtrIpv6, "ipv6", "6", false, "Use IPv6")
4749
parentCmd.AddCommand(mtrCmd)
4850
}
4951

50-
func runMTR(c *perfops.Client, target, from string, nodeIDs []int, limit int) error {
52+
func runMTR(c *perfops.Client, target, from string, nodeIDs []int, limit int, ipv6 bool) error {
5153
ctx := context.Background()
52-
return internal.RunTest(ctx, target, from, nodeIDs, limit, debug, outputJSON, c.Run.MTR, c.Run.MTROutput)
54+
ipversion := 4
55+
if ipv6 {
56+
ipversion = 6
57+
}
58+
return internal.RunTest(ctx, target, from, nodeIDs, limit, ipversion, debug, outputJSON, c.Run.MTR, c.Run.MTROutput)
5359
}

cmd/mtr_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func TestInitMTRCmd(t *testing.T) {
3131
"json": {[]string{"--json"}, func() (interface{}, interface{}) { return outputJSON, true }},
3232

3333
"limit": {[]string{"--limit", "23"}, func() (interface{}, interface{}) { return mtrLimit, 23 }},
34+
"ipv6": {[]string{"--ipv6"}, func() (interface{}, interface{}) { return mtrIpv6, true }},
3435
}
3536
parent := &cobra.Command{}
3637
for name, tc := range testCases {
@@ -46,7 +47,7 @@ func TestInitMTRCmd(t *testing.T) {
4647
t.Fatal("expected flag; got nil")
4748
}
4849

49-
got, exp := tc.gotexp();
50+
got, exp := tc.gotexp()
5051
if reflect.DeepEqual(got, exp) == false {
5152
t.Fatalf("expected %v; got %v", exp, got)
5253
}
@@ -58,10 +59,12 @@ func TestRunMTR(t *testing.T) {
5859
testCases := map[string]struct {
5960
from string
6061
nodeIDs []int
62+
ipv6 bool
6163
exp string
6264
}{
63-
"Location": {"From here", []int{}, `{"target":"example.com","location":"From here","limit":12}`},
64-
"NodeID": {"", []int{123}, `{"target":"example.com","nodes":"123","limit":12}`},
65+
"Location": {"From here", []int{}, false, `{"target":"example.com","location":"From here","limit":12,"ipversion":4}`},
66+
"NodeID": {"", []int{123}, false, `{"target":"example.com","nodes":"123","limit":12,"ipversion":4}`},
67+
"IPV6": {"", []int{}, true, `{"target":"example.com","limit":12,"ipversion":6}`},
6568
}
6669
// We're only interested in the first HTTP call, e.g., the one to get the test ID
6770
// to validate our parameters got passed properly.
@@ -72,7 +75,7 @@ func TestRunMTR(t *testing.T) {
7275
}
7376
for name, tc := range testCases {
7477
t.Run(name, func(t *testing.T) {
75-
runMTR(c, "example.com", tc.from, tc.nodeIDs, 12)
78+
runMTR(c, "example.com", tc.from, tc.nodeIDs, 12, tc.ipv6)
7679
if got, exp := tr.req.URL.Path, "/run/mtr"; got != exp {
7780
t.Fatalf("expected %v; got %v", exp, got)
7881
}

0 commit comments

Comments
 (0)