Skip to content

Commit 08a66e0

Browse files
authored
Merge pull request kubernetes#127223 from aojea/iperf2
adapt iperf2 parser to new version format
2 parents f5c5384 + e90b6b9 commit 08a66e0

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

test/e2e/network/util_iperf.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ func (i *IPerfResults) ToTSV() string {
8080
// NewIPerf parses an IPerf CSV output line into an IPerfCSVResult.
8181
func NewIPerf(csvLine string) (*IPerfCSVResult, error) {
8282
if len(csvLine) == 0 {
83-
return nil, fmt.Errorf("No iperf output received in csv line")
83+
return nil, fmt.Errorf("no iperf output received in csv line")
8484
}
8585
csvLine = strings.Trim(csvLine, "\n")
8686
slice := StrSlice(strings.Split(csvLine, ","))
87-
if len(slice) != 9 {
88-
return nil, fmt.Errorf("Incorrect fields in the output: %v (%v out of 9)", slice, len(slice))
87+
// iperf 2.19+ reports 15 fields, before it was just 9
88+
if len(slice) != 15 {
89+
return nil, fmt.Errorf("incorrect fields in the output: %v (%v out of 15)", slice, len(slice))
8990
}
9091
i := IPerfCSVResult{}
9192
i.date = slice.get(0)
@@ -127,17 +128,19 @@ type IPerf2EnhancedCSVResults struct {
127128

128129
// ParseIPerf2EnhancedResultsFromCSV parses results from iperf2 when given the -e (--enhancedreports)
129130
// and `--reportstyle C` options.
130-
// Example output:
131+
// Example output for version < 2.19 (agnhost < 2.53):
131132
// 20201210141800.884,10.244.2.24,47880,10.96.114.79,6789,3,0.0-1.0,1677852672,13422821376
132133
// 20201210141801.881,10.244.2.24,47880,10.96.114.79,6789,3,1.0-2.0,1980760064,15846080512
133134
// 20201210141802.883,10.244.2.24,47880,10.96.114.79,6789,3,2.0-3.0,1886650368,15093202944
134-
// 20201210141803.882,10.244.2.24,47880,10.96.114.79,6789,3,3.0-4.0,2035417088,16283336704
135-
// 20201210141804.879,10.244.2.24,47880,10.96.114.79,6789,3,4.0-5.0,1922957312,15383658496
136-
// 20201210141805.881,10.244.2.24,47880,10.96.114.79,6789,3,5.0-6.0,2095316992,16762535936
137-
// 20201210141806.882,10.244.2.24,47880,10.96.114.79,6789,3,6.0-7.0,1741291520,13930332160
138-
// 20201210141807.879,10.244.2.24,47880,10.96.114.79,6789,3,7.0-8.0,1862926336,14903410688
139-
// 20201210141808.878,10.244.2.24,47880,10.96.114.79,6789,3,8.0-9.0,1821245440,14569963520
140-
// 20201210141809.849,10.244.2.24,47880,10.96.114.79,6789,3,0.0-10.0,18752208896,15052492511
135+
// Example output with version >= 2.19 (agnhost >= 2.53)
136+
// +0000:20240908113035.128,192.168.9.3,58256,192.168.9.4,5001,1,0.0-1.0,5220466748,41763733984,-1,-1,-1,-1,0,0
137+
// +0000:20240908113036.128,192.168.9.3,58256,192.168.9.4,5001,1,1.0-2.0,5127667712,41021341696,-1,-1,-1,-1,0,0
138+
// +0000:20240908113037.128,192.168.9.3,58256,192.168.9.4,5001,1,2.0-3.0,5127405568,41019244544,-1,-1,-1,-1,0,0
139+
// +0000:20240908113038.128,192.168.9.3,58256,192.168.9.4,5001,1,3.0-4.0,5173018624,41384148992,-1,-1,-1,-1,0,0
140+
// +0000:20240908113039.128,192.168.9.3,58256,192.168.9.4,5001,1,4.0-5.0,5245894656,41967157248,-1,-1,-1,-1,0,0
141+
// +0000:20240908113040.128,192.168.9.3,58256,192.168.9.4,5001,1,5.0-6.0,5213257728,41706061824,-1,-1,-1,-1,0,0
142+
// +0000:20240908113041.128,192.168.9.3,58256,192.168.9.4,5001,1,6.0-7.0,5113118720,40904949760,-1,-1,-1,-1,0,0
143+
// +0000:20240908113042.128,192.168.9.3,58256,192.168.9.4,5001,1,7.0-8.0,5242748928,41941991424,-1,-1,-1,-1,0,0
141144
func ParseIPerf2EnhancedResultsFromCSV(output string) (*IPerf2EnhancedCSVResults, error) {
142145
var parsedResults []*IPerfCSVResult
143146
for _, line := range strings.Split(output, "\n") {
@@ -147,7 +150,7 @@ func ParseIPerf2EnhancedResultsFromCSV(output string) (*IPerf2EnhancedCSVResults
147150
}
148151
parsedResults = append(parsedResults, parsed)
149152
}
150-
if parsedResults == nil || len(parsedResults) == 0 {
153+
if len(parsedResults) == 0 {
151154
return nil, fmt.Errorf("no results parsed from iperf2 output")
152155
}
153156
// format:

0 commit comments

Comments
 (0)