aboutsummaryrefslogtreecommitdiffstats
path: root/extras/hs-test/iperf_linux_test.go
blob: 0a59f6a4e0f3c08f9c2ebca613f12e2f8f7fdbb1 (plain)
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
package main

import (
	"fmt"
	"time"

	. "fd.io/hs-test/infra"
	. "github.com/onsi/ginkgo/v2"
)

func init() {
	RegisterIperfTests(IperfUdpLinuxTest)
}

func IperfUdpLinuxTest(s *IperfSuite) {
	serverContainer := s.GetContainerByName(ServerIperfContainerName)
	serverIpAddress := s.GetInterfaceByName(ServerIperfInterfaceName).Ip4AddressString()
	clientContainer := s.GetContainerByName(ClientIperfContainerName)
	clientIpAddress := s.GetInterfaceByName(ClientIperfInterfaceName).Ip4AddressString()

	clnCh := make(chan error)
	stopServerCh := make(chan struct{})
	srvCh := make(chan error, 1)
	clnRes := make(chan []byte, 1)

	defer func() {
		stopServerCh <- struct{}{}
	}()

	go func() {
		defer GinkgoRecover()
		cmd := "iperf3 -4 -s -B " + serverIpAddress + " -p " + s.GetPortFromPpid()
		s.StartServerApp(serverContainer, "iperf3", cmd, srvCh, stopServerCh)
	}()
	err := <-srvCh
	s.AssertNil(err, fmt.Sprint(err))
	s.Log("server running")

	go func() {
		defer GinkgoRecover()
		cmd := "iperf3 -c " + serverIpAddress + " -B " + clientIpAddress +
			" -u -l 1460 -b 10g -J -p " + s.GetPortFromPpid()
		s.StartClientApp(clientContainer, cmd, clnCh, clnRes)
	}()
	s.AssertChannelClosed(time.Minute*3, clnCh)
	output := <-clnRes
	result := s.ParseJsonIperfOutput(output)
	s.LogJsonIperfOutput(result)
	s.AssertIperfMinTransfer(result, 800)
}