hs-test: abstract away topology from test cases
[vpp.git] / extras / hs-test / vcl_test.go
1 package main
2
3 import (
4         "fmt"
5         "time"
6 )
7
8 func (s *VethsSuite) TestVclEchoQuic() {
9         s.T().Skip("quic test skipping..")
10         s.testVclEcho("quic")
11 }
12
13 func (s *VethsSuite) TestVclEchoUdp() {
14         s.T().Skip("udp echo currently broken in vpp, skipping..")
15         s.testVclEcho("udp")
16 }
17
18 func (s *VethsSuite) TestVclEchoTcp() {
19         s.testVclEcho("tcp")
20 }
21
22 func (s *VethsSuite) testVclEcho(proto string) {
23         srvVppContainer := s.getContainerByName("server-vpp")
24
25         _, err := srvVppContainer.execAction("Configure2Veths srv")
26         s.assertNil(err)
27
28         clnVppContainer := s.getContainerByName("client-vpp")
29
30         _, err = clnVppContainer.execAction("Configure2Veths cln")
31         s.assertNil(err)
32
33         echoSrvContainer := s.getContainerByName("server-application")
34
35         // run server app
36         _, err = echoSrvContainer.execAction("RunEchoServer "+proto)
37         s.assertNil(err)
38
39         echoClnContainer := s.getContainerByName("client-application")
40
41         o, err := echoClnContainer.execAction("RunEchoClient "+proto)
42         s.assertNil(err)
43
44         fmt.Println(o)
45 }
46
47 func (s *VethsSuite) TestVclRetryAttach() {
48         s.T().Skip()
49         s.testRetryAttach("tcp")
50 }
51
52 func (s *VethsSuite) testRetryAttach(proto string) {
53         srvVppContainer := s.getContainerByName("server-vpp")
54
55         _, err := srvVppContainer.execAction("Configure2Veths srv-with-preset-hw-addr")
56         s.assertNil(err)
57
58         clnVppContainer := s.getContainerByName("client-vpp")
59
60         _, err = clnVppContainer.execAction("Configure2Veths cln")
61         s.assertNil(err)
62
63         echoSrvContainer := s.getContainerByName("server-application")
64         _, err = echoSrvContainer.execAction("RunVclEchoServer "+proto)
65         s.assertNil(err)
66
67         fmt.Println("This whole test case can take around 3 minutes to run. Please be patient.")
68         fmt.Println("... Running first echo client test, before disconnect.")
69         echoClnContainer := s.getContainerByName("client-application")
70         _, err = echoClnContainer.execAction("RunVclEchoClient "+proto)
71         s.assertNil(err)
72         fmt.Println("... First test ended. Stopping VPP server now.")
73
74         // Stop server-vpp-instance, start it again and then run vcl-test-client once more
75         stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'"
76         _, err = srvVppContainer.exec(stopVppCommand)
77         s.assertNil(err)
78         time.Sleep(5 * time.Second) // Give parent process time to reap the killed child process
79         stopVppCommand = "/bin/bash -c 'ps -C hs-test -o pid= | xargs kill -9'"
80         _, err = srvVppContainer.exec(stopVppCommand)
81         s.assertNil(err)
82         _, err = srvVppContainer.execAction("Configure2Veths srv-with-preset-hw-addr")
83         s.assertNil(err)
84
85         fmt.Println("... VPP server is starting again, so waiting for a bit.")
86         time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
87
88         fmt.Println("... Running second echo client test, after disconnect and re-attachment.")
89         _, err = echoClnContainer.execAction("RunVclEchoClient "+proto)
90         s.assertNil(err)
91         fmt.Println("Done.")
92 }
93
94 func (s *VethsSuite) TestTcpWithLoss() {
95         serverContainer := s.getContainerByName("server-vpp")
96
97         serverVpp := NewVppInstance(serverContainer)
98         s.assertNotNil(serverVpp)
99         serverVpp.set2VethsServer()
100         err := serverVpp.start()
101         s.assertNil(err, "starting VPP failed")
102
103         _, err = serverVpp.vppctl("test echo server uri tcp://10.10.10.1/20022")
104         s.assertNil(err, "starting echo server failed")
105
106         clientContainer := s.getContainerByName("client-vpp")
107
108         clientVpp := NewVppInstance(clientContainer)
109         s.assertNotNil(clientVpp)
110         clientVpp.set2VethsClient()
111         err = clientVpp.start()
112         s.assertNil(err, "starting VPP failed")
113
114         // Ensure that VPP doesn't abort itself with NSIM enabled
115         // Warning: Removing this ping will make the test fail!
116         _, err = serverVpp.vppctl("ping 10.10.10.2")
117         s.assertNil(err, "ping failed")
118
119         // Add loss of packets with Network Delay Simulator
120         _, err = clientVpp.vppctl("set nsim poll-main-thread delay 0.01 ms bandwidth 40 gbit packet-size 1400 packets-per-drop 1000")
121         s.assertNil(err, "configuring NSIM failed")
122         _, err = clientVpp.vppctl("nsim output-feature enable-disable host-vppcln")
123         s.assertNil(err, "enabling NSIM failed")
124
125         // Do echo test from client-vpp container
126         output, err := clientVpp.vppctl("test echo client uri tcp://10.10.10.1/20022 mbytes 50")
127         s.assertNil(err)
128         s.assertEqual(true, len(output) != 0)
129         s.assertNotContains(output, "failed: timeout")
130         fmt.Println(output)
131 }