blob: 8077554271226621883ef62edaaefe59a49f7825 [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)
7
Maros Ondrejicka11a03e92022-12-01 09:56:37 +01008func (s *VethsSuite) TestVclEchoQuic() {
Filip Tehlar229f5fc2022-08-09 14:44:47 +00009 s.T().Skip("quic test skipping..")
10 s.testVclEcho("quic")
11}
12
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010013func (s *VethsSuite) TestVclEchoUdp() {
Filip Tehlar229f5fc2022-08-09 14:44:47 +000014 s.T().Skip("udp echo currently broken in vpp, skipping..")
15 s.testVclEcho("udp")
16}
17
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010018func (s *VethsSuite) TestVclEchoTcp() {
Filip Tehlar229f5fc2022-08-09 14:44:47 +000019 s.testVclEcho("tcp")
20}
21
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010022func (s *VethsSuite) testVclEcho(proto string) {
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010023 srvVppContainer := s.getContainerByName("server-vpp")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000024
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010025 _, err := srvVppContainer.execAction("Configure2Veths srv")
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010026 s.assertNil(err)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000027
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010028 clnVppContainer := s.getContainerByName("client-vpp")
29
30 _, err = clnVppContainer.execAction("Configure2Veths cln")
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010031 s.assertNil(err)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000032
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010033 echoSrvContainer := s.getContainerByName("server-application")
34
Filip Tehlar229f5fc2022-08-09 14:44:47 +000035 // run server app
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010036 _, err = echoSrvContainer.execAction("RunEchoServer "+proto)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010037 s.assertNil(err)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000038
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010039 echoClnContainer := s.getContainerByName("client-application")
40
41 o, err := echoClnContainer.execAction("RunEchoClient "+proto)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010042 s.assertNil(err)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010043
Filip Tehlar229f5fc2022-08-09 14:44:47 +000044 fmt.Println(o)
45}
Maros Ondrejicka0db15752022-10-12 22:58:01 +020046
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010047func (s *VethsSuite) TestVclRetryAttach() {
Filip Tehlar468d7872022-11-11 10:37:33 +010048 s.T().Skip()
Maros Ondrejicka0db15752022-10-12 22:58:01 +020049 s.testRetryAttach("tcp")
50}
51
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010052func (s *VethsSuite) testRetryAttach(proto string) {
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010053 srvVppContainer := s.getContainerByName("server-vpp")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020054
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010055 _, err := srvVppContainer.execAction("Configure2Veths srv-with-preset-hw-addr")
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010056 s.assertNil(err)
Maros Ondrejicka0db15752022-10-12 22:58:01 +020057
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010058 clnVppContainer := s.getContainerByName("client-vpp")
59
60 _, err = clnVppContainer.execAction("Configure2Veths cln")
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010061 s.assertNil(err)
Maros Ondrejicka0db15752022-10-12 22:58:01 +020062
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010063 echoSrvContainer := s.getContainerByName("server-application")
64 _, err = echoSrvContainer.execAction("RunVclEchoServer "+proto)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010065 s.assertNil(err)
Maros Ondrejicka0db15752022-10-12 22:58:01 +020066
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.")
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010069 echoClnContainer := s.getContainerByName("client-application")
70 _, err = echoClnContainer.execAction("RunVclEchoClient "+proto)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010071 s.assertNil(err)
Maros Ondrejicka0db15752022-10-12 22:58:01 +020072 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'"
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010076 _, err = srvVppContainer.exec(stopVppCommand)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010077 s.assertNil(err)
Maros Ondrejicka0db15752022-10-12 22:58:01 +020078 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'"
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010080 _, err = srvVppContainer.exec(stopVppCommand)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010081 s.assertNil(err)
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010082 _, err = srvVppContainer.execAction("Configure2Veths srv-with-preset-hw-addr")
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010083 s.assertNil(err)
Maros Ondrejicka0db15752022-10-12 22:58:01 +020084
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.")
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010089 _, err = echoClnContainer.execAction("RunVclEchoClient "+proto)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010090 s.assertNil(err)
Maros Ondrejicka0db15752022-10-12 22:58:01 +020091 fmt.Println("Done.")
92}
Maros Ondrejicka5b746312022-11-16 12:51:11 +010093
94func (s *VethsSuite) TestTcpWithLoss() {
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010095 serverContainer := s.getContainerByName("server-vpp")
Maros Ondrejicka5b746312022-11-16 12:51:11 +010096
97 serverVpp := NewVppInstance(serverContainer)
98 s.assertNotNil(serverVpp)
Maros Ondrejicka5b746312022-11-16 12:51:11 +010099 serverVpp.set2VethsServer()
Maros Ondrejickadb823ed2022-12-14 16:30:04 +0100100 err := serverVpp.start()
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100101 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
Maros Ondrejickadb823ed2022-12-14 16:30:04 +0100106 clientContainer := s.getContainerByName("client-vpp")
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100107
108 clientVpp := NewVppInstance(clientContainer)
109 s.assertNotNil(clientVpp)
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100110 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}