blob: 8fd64f1dcd604549963c906eceaf5b9f4a9a7b43 [file] [log] [blame]
Filip Tehlar229f5fc2022-08-09 14:44:47 +00001package main
2
3import (
4 "fmt"
Maros Ondrejicka0db15752022-10-12 22:58:01 +02005 "time"
Filip Tehlar229f5fc2022-08-09 14:44:47 +00006
Filip Tehlar229f5fc2022-08-09 14:44:47 +00007)
8
Maros Ondrejicka11a03e92022-12-01 09:56:37 +01009func (s *VethsSuite) TestVclEchoQuic() {
Filip Tehlar229f5fc2022-08-09 14:44:47 +000010 s.T().Skip("quic test skipping..")
11 s.testVclEcho("quic")
12}
13
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010014func (s *VethsSuite) TestVclEchoUdp() {
Filip Tehlar229f5fc2022-08-09 14:44:47 +000015 s.T().Skip("udp echo currently broken in vpp, skipping..")
16 s.testVclEcho("udp")
17}
18
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010019func (s *VethsSuite) TestVclEchoTcp() {
Filip Tehlar229f5fc2022-08-09 14:44:47 +000020 s.testVclEcho("tcp")
21}
22
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010023func (s *VethsSuite) testVclEcho(proto string) {
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010024 serverVolume := "echo-srv-vol"
25 s.NewVolume(serverVolume)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000026
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010027 clientVolume := "echo-cln-vol"
28 s.NewVolume(clientVolume)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000029
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010030 srvInstance := "vpp-vcl-test-srv"
31 serverVppContainer, err := s.NewContainer(srvInstance)
32 s.assertNil(err)
33 serverVppContainer.addVolume(serverVolume, "/tmp/Configure2Veths")
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010034 s.assertNil(serverVppContainer.run())
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010035
36 clnInstance := "vpp-vcl-test-cln"
37 clientVppContainer, err := s.NewContainer(clnInstance)
38 s.assertNil(err)
39 clientVppContainer.addVolume(clientVolume, "/tmp/Configure2Veths")
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010040 s.assertNil(clientVppContainer.run())
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010041
Filip Tehlar229f5fc2022-08-09 14:44:47 +000042 echoSrv := "echo-srv"
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010043 serverEchoContainer, err := s.NewContainer(echoSrv)
44 s.assertNil(err)
45 serverEchoContainer.addVolume(serverVolume, "/tmp/" + echoSrv)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010046 s.assertNil(serverEchoContainer.run())
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010047
Filip Tehlar229f5fc2022-08-09 14:44:47 +000048 echoCln := "echo-cln"
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010049 clientEchoContainer, err := s.NewContainer(echoCln)
50 s.assertNil(err)
51 clientEchoContainer.addVolume(clientVolume, "/tmp/" + echoCln)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010052 s.assertNil(clientEchoContainer.run())
Filip Tehlar229f5fc2022-08-09 14:44:47 +000053
Filip Tehlar1a9dc752022-11-22 12:49:22 +010054 _, err = hstExec("Configure2Veths srv", srvInstance)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010055 s.assertNil(err)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000056
Filip Tehlar1a9dc752022-11-22 12:49:22 +010057 _, err = hstExec("Configure2Veths cln", clnInstance)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010058 s.assertNil(err)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000059
60 // run server app
Filip Tehlar1a9dc752022-11-22 12:49:22 +010061 _, err = hstExec("RunEchoServer "+proto, echoSrv)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010062 s.assertNil(err)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000063
Filip Tehlar1a9dc752022-11-22 12:49:22 +010064 o, err := hstExec("RunEchoClient "+proto, echoCln)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010065 s.assertNil(err)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010066
Filip Tehlar229f5fc2022-08-09 14:44:47 +000067 fmt.Println(o)
68}
Maros Ondrejicka0db15752022-10-12 22:58:01 +020069
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010070func (s *VethsSuite) TestVclRetryAttach() {
Filip Tehlar468d7872022-11-11 10:37:33 +010071 s.T().Skip()
Maros Ondrejicka0db15752022-10-12 22:58:01 +020072 s.testRetryAttach("tcp")
73}
74
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010075func (s *VethsSuite) testRetryAttach(proto string) {
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010076 serverVolume := "echo-srv-vol"
77 s.NewVolume(serverVolume)
Maros Ondrejicka0db15752022-10-12 22:58:01 +020078
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010079 clientVolume := "echo-cln-vol"
80 s.NewVolume(clientVolume)
Maros Ondrejicka0db15752022-10-12 22:58:01 +020081
82 srvInstance := "vpp-vcl-test-srv"
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010083 serverVppContainer, err := s.NewContainer(srvInstance)
84 s.assertNil(err)
85 serverVppContainer.addVolume(serverVolume, "/tmp/Configure2Veths")
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010086 s.assertNil(serverVppContainer.run())
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010087
Maros Ondrejicka0db15752022-10-12 22:58:01 +020088 clnInstance := "vpp-vcl-test-cln"
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010089 clientVppContainer, err := s.NewContainer(clnInstance)
90 s.assertNil(err)
91 clientVppContainer.addVolume(clientVolume, "/tmp/Configure2Veths")
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010092 s.assertNil(clientVppContainer.run())
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010093
Maros Ondrejicka0db15752022-10-12 22:58:01 +020094 echoSrv := "echo-srv"
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010095 serverEchoContainer, err := s.NewContainer(echoSrv)
96 s.assertNil(err)
97 serverEchoContainer.addVolume(serverVolume, "/tmp/" + echoSrv)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010098 s.assertNil(serverEchoContainer.run())
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010099
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200100 echoCln := "echo-cln"
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +0100101 clientEchoContainer, err := s.NewContainer(echoCln)
102 s.assertNil(err)
103 clientEchoContainer.addVolume(clientVolume, "/tmp/" + echoCln)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +0100104 s.assertNil(clientEchoContainer.run())
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200105
Filip Tehlar1a9dc752022-11-22 12:49:22 +0100106 _, err = hstExec("Configure2Veths srv-with-preset-hw-addr", srvInstance)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +0100107 s.assertNil(err)
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200108
Filip Tehlar1a9dc752022-11-22 12:49:22 +0100109 _, err = hstExec("Configure2Veths cln", clnInstance)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +0100110 s.assertNil(err)
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200111
Filip Tehlar1a9dc752022-11-22 12:49:22 +0100112 _, err = hstExec("RunVclEchoServer "+proto, echoSrv)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +0100113 s.assertNil(err)
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200114
115 fmt.Println("This whole test case can take around 3 minutes to run. Please be patient.")
116 fmt.Println("... Running first echo client test, before disconnect.")
Filip Tehlar1a9dc752022-11-22 12:49:22 +0100117 _, err = hstExec("RunVclEchoClient "+proto, echoCln)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +0100118 s.assertNil(err)
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200119 fmt.Println("... First test ended. Stopping VPP server now.")
120
121 // Stop server-vpp-instance, start it again and then run vcl-test-client once more
122 stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'"
123 _, err = dockerExec(stopVppCommand, srvInstance)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +0100124 s.assertNil(err)
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200125 time.Sleep(5 * time.Second) // Give parent process time to reap the killed child process
126 stopVppCommand = "/bin/bash -c 'ps -C hs-test -o pid= | xargs kill -9'"
127 _, err = dockerExec(stopVppCommand, srvInstance)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +0100128 s.assertNil(err)
Filip Tehlar1a9dc752022-11-22 12:49:22 +0100129 _, err = hstExec("Configure2Veths srv-with-preset-hw-addr", srvInstance)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +0100130 s.assertNil(err)
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200131
132 fmt.Println("... VPP server is starting again, so waiting for a bit.")
133 time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
134
135 fmt.Println("... Running second echo client test, after disconnect and re-attachment.")
Filip Tehlar1a9dc752022-11-22 12:49:22 +0100136 _, err = hstExec("RunVclEchoClient "+proto, echoCln)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +0100137 s.assertNil(err)
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200138 fmt.Println("Done.")
139}
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100140
141func (s *VethsSuite) TestTcpWithLoss() {
142 serverContainer, err := s.NewContainer("server")
143 s.assertNil(err, "creating container failed")
144 err = serverContainer.run()
145 s.assertNil(err)
146
147 serverVpp := NewVppInstance(serverContainer)
148 s.assertNotNil(serverVpp)
149 serverVpp.setCliSocket("/var/run/vpp/cli.sock")
150 serverVpp.set2VethsServer()
151 err = serverVpp.start()
152 s.assertNil(err, "starting VPP failed")
153
154 _, err = serverVpp.vppctl("test echo server uri tcp://10.10.10.1/20022")
155 s.assertNil(err, "starting echo server failed")
156
157 clientContainer, err := s.NewContainer("client")
158 s.assertNil(err, "creating container failed")
159 err = clientContainer.run()
160 s.assertNil(err, "starting container failed")
161
162 clientVpp := NewVppInstance(clientContainer)
163 s.assertNotNil(clientVpp)
164 clientVpp.setCliSocket("/var/run/vpp/cli.sock")
165 clientVpp.set2VethsClient()
166 err = clientVpp.start()
167 s.assertNil(err, "starting VPP failed")
168
169 // Ensure that VPP doesn't abort itself with NSIM enabled
170 // Warning: Removing this ping will make the test fail!
171 _, err = serverVpp.vppctl("ping 10.10.10.2")
172 s.assertNil(err, "ping failed")
173
174 // Add loss of packets with Network Delay Simulator
175 _, err = clientVpp.vppctl("set nsim poll-main-thread delay 0.01 ms bandwidth 40 gbit packet-size 1400 packets-per-drop 1000")
176 s.assertNil(err, "configuring NSIM failed")
177 _, err = clientVpp.vppctl("nsim output-feature enable-disable host-vppcln")
178 s.assertNil(err, "enabling NSIM failed")
179
180 // Do echo test from client-vpp container
181 output, err := clientVpp.vppctl("test echo client uri tcp://10.10.10.1/20022 mbytes 50")
182 s.assertNil(err)
183 s.assertEqual(true, len(output) != 0)
184 s.assertNotContains(output, "failed: timeout")
185 fmt.Println(output)
186}