Skip to content

Commit c9903d3

Browse files
committed
Allow skipping ICMP pings
1 parent 5cf383b commit c9903d3

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

defs/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const (
88
OptionIPv6Alt = "6"
99
OptionNoDownload = "no-download"
1010
OptionNoUpload = "no-upload"
11+
OptionNoICMP = "no-icmp"
1112
OptionConcurrent = "concurrent"
1213
OptionBytes = "bytes"
1314
OptionMebiBytes = "mebibytes"

defs/server.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ type Server struct {
3232
SponsorName string `json:"sponsorName"`
3333
SponsorURL string `json:"sponsorURL"`
3434

35-
icmpFailed bool `json:"-"`
36-
TLog TelemetryLog `json:"-"`
35+
NoICMP bool `json:"-"`
36+
TLog TelemetryLog `json:"-"`
3737
}
3838

3939
// IsUp checks the speed test backend is up by accessing the ping URL
@@ -71,8 +71,8 @@ func (s *Server) ICMPPingAndJitter(count int, srcIp, network string) (float64, f
7171
s.TLog.Logf("ICMP ping took %s", time.Now().Sub(t).String())
7272
}()
7373

74-
if s.icmpFailed {
75-
log.Debug("ICMP ping failed already, using HTTP ping")
74+
if s.NoICMP {
75+
log.Debugf("Skipping ICMP for server %s, will use HTTP ping", s.Name)
7676
return s.PingAndJitter(count + 2)
7777
}
7878

@@ -116,7 +116,7 @@ func (s *Server) ICMPPingAndJitter(count int, srcIp, network string) (float64, f
116116
}
117117

118118
if len(stats.Rtts) == 0 {
119-
s.icmpFailed = true
119+
s.NoICMP = true
120120
log.Debugf("No ICMP pings returned for server %s (%s), trying TCP ping", s.Name, u.Hostname())
121121
return s.PingAndJitter(count + 2)
122122
}

main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ func main() {
5656
Name: defs.OptionNoUpload,
5757
Usage: "Do not perform upload test",
5858
},
59+
&cli.BoolFlag{
60+
Name: defs.OptionNoICMP,
61+
Usage: "Do not use ICMP ping. ICMP doesn't work well under Linux\n" +
62+
"at this moment, so you might want to disable it",
63+
},
5964
&cli.IntFlag{
6065
Name: defs.OptionConcurrent,
6166
Usage: "Concurrent HTTP requests being made",

speedtest/helper.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ func doSpeedTest(c *cli.Context, servers []defs.Server, telemetryServer defs.Tel
6565
pb.Start()
6666
}
6767

68+
// skip ICMP if option given
69+
currentServer.NoICMP = c.Bool(defs.OptionNoICMP)
70+
6871
p, jitter, err := currentServer.ICMPPingAndJitter(pingCount, c.String(defs.OptionSource), network)
6972
if err != nil {
7073
log.Errorf("Failed to get ping and jitter: %s", err)

speedtest/speedtest.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func SpeedTest(c *cli.Context) error {
262262

263263
// spawn 10 concurrent pingers
264264
for i := 0; i < 10; i++ {
265-
go pingWorker(jobs, results, &wg, c.String(defs.OptionSource), network)
265+
go pingWorker(jobs, results, &wg, c.String(defs.OptionSource), network, c.Bool(defs.OptionNoICMP))
266266
}
267267

268268
// send ping jobs to workers
@@ -303,7 +303,7 @@ func SpeedTest(c *cli.Context) error {
303303
}
304304
}
305305

306-
func pingWorker(jobs <-chan PingJob, results chan<- PingResult, wg *sync.WaitGroup, srcIp, network string) {
306+
func pingWorker(jobs <-chan PingJob, results chan<- PingResult, wg *sync.WaitGroup, srcIp, network string, noICMP bool) {
307307
for {
308308
job := <-jobs
309309
server := job.Server
@@ -317,6 +317,9 @@ func pingWorker(jobs <-chan PingJob, results chan<- PingResult, wg *sync.WaitGro
317317

318318
// check the server is up by accessing the ping URL and checking its returned value == empty and status code == 200
319319
if server.IsUp() {
320+
// skip ICMP if option given
321+
server.NoICMP = noICMP
322+
320323
// if server is up, get ping
321324
ping, _, err := server.ICMPPingAndJitter(1, srcIp, network)
322325
if err != nil {

0 commit comments

Comments
 (0)