blob: 6c809f4caec767f7ad5b3e673556dc7f5479fca4 [file] [log] [blame]
Filip Tehlar229f5fc2022-08-09 14:44:47 +00001package main
2
3import (
Maros Ondrejickaffa3f602023-01-26 10:07:29 +01004 "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() {
Maros Ondrejicka87531802022-12-19 20:35:27 +01009 s.skip("quic test skipping..")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000010 s.testVclEcho("quic")
11}
12
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010013func (s *VethsSuite) TestVclEchoUdp() {
Maros Ondrejicka87531802022-12-19 20:35:27 +010014 s.skip("udp echo currently broken in vpp, skipping..")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000015 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 Ondrejickaffa3f602023-01-26 10:07:29 +010023 serverVethAddress := s.veths["vppsrv"].Address()
24 uri := proto + "://" + serverVethAddress + "/12344"
Filip Tehlar229f5fc2022-08-09 14:44:47 +000025
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010026 echoSrvContainer := s.getContainerByName("server-application")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010027 serverCommand := "vpp_echo server TX=RX" +
28 " socket-name " + echoSrvContainer.GetContainerWorkDir() + "/var/run/app_ns_sockets/1" +
29 " use-app-socket-api" +
30 " uri " + uri
31 s.log(serverCommand)
32 err := echoSrvContainer.execServer(serverCommand)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010033 s.assertNil(err)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000034
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010035 echoClnContainer := s.getContainerByName("client-application")
36
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010037 clientCommand := "vpp_echo client" +
38 " socket-name " + echoClnContainer.GetContainerWorkDir() + "/var/run/app_ns_sockets/2" +
39 " use-app-socket-api uri " + uri
40 s.log(clientCommand)
41 o, err := echoClnContainer.exec(clientCommand)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010042 s.assertNil(err)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010043
Maros Ondrejicka87531802022-12-19 20:35:27 +010044 s.log(o)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000045}
Maros Ondrejicka0db15752022-10-12 22:58:01 +020046
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010047func (s *VethsSuite) TestVclRetryAttach() {
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010048 s.skip("this test takes too long, for now it's being skipped")
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 Ondrejickaffa3f602023-01-26 10:07:29 +010053 srvVppContainer := s.getContainerCopyByName("server-vpp")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020054
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010055 echoSrvContainer := s.getContainerByName("server-application")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010056
57 serverVclConfContent := fmt.Sprintf(vclTemplate, echoSrvContainer.GetContainerWorkDir(), "1")
58 echoSrvContainer.createFile("/vcl.conf", serverVclConfContent)
59
60 echoSrvContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
61 err := echoSrvContainer.execServer("vcl_test_server -p " + proto + " 12346")
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010062 s.assertNil(err)
Maros Ondrejicka0db15752022-10-12 22:58:01 +020063
Maros Ondrejicka87531802022-12-19 20:35:27 +010064 s.log("This whole test case can take around 3 minutes to run. Please be patient.")
65 s.log("... Running first echo client test, before disconnect.")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010066
67 serverVeth := s.veths[serverInterfaceName]
68 serverVethAddress := serverVeth.Address()
69
70 echoClnContainer := s.getContainerCopyByName("client-application")
71 clientVclConfContent := fmt.Sprintf(vclTemplate, echoClnContainer.GetContainerWorkDir(), "2")
72 echoClnContainer.createFile("/vcl.conf", clientVclConfContent)
73
74 testClientCommand := "vcl_test_client -U -p " + proto + " " + serverVethAddress + " 12346"
75 echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
76 o, err := echoClnContainer.exec(testClientCommand)
77 s.log(o)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010078 s.assertNil(err)
Maros Ondrejicka87531802022-12-19 20:35:27 +010079 s.log("... First test ended. Stopping VPP server now.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020080
81 // Stop server-vpp-instance, start it again and then run vcl-test-client once more
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010082 srvVppContainer.vppInstance.disconnect()
Maros Ondrejicka0db15752022-10-12 22:58:01 +020083 stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'"
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010084 _, err = srvVppContainer.exec(stopVppCommand)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010085 s.assertNil(err)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010086
87 s.setupServerVpp()
Maros Ondrejicka0db15752022-10-12 22:58:01 +020088
Maros Ondrejicka87531802022-12-19 20:35:27 +010089 s.log("... VPP server is starting again, so waiting for a bit.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020090 time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
91
Maros Ondrejicka87531802022-12-19 20:35:27 +010092 s.log("... Running second echo client test, after disconnect and re-attachment.")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010093 o, err = echoClnContainer.exec(testClientCommand)
94 s.log(o)
Maros Ondrejicka0e79abb2022-12-06 19:46:24 +010095 s.assertNil(err)
Maros Ondrejicka87531802022-12-19 20:35:27 +010096 s.log("Done.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020097}
Maros Ondrejicka5b746312022-11-16 12:51:11 +010098
99func (s *VethsSuite) TestTcpWithLoss() {
Maros Ondrejickadb823ed2022-12-14 16:30:04 +0100100 serverContainer := s.getContainerByName("server-vpp")
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100101
102 serverVpp := NewVppInstance(serverContainer)
103 s.assertNotNil(serverVpp)
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100104 serverVpp.set2VethsServer()
Maros Ondrejickadb823ed2022-12-14 16:30:04 +0100105 err := serverVpp.start()
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100106 s.assertNil(err, "starting VPP failed")
107
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100108 serverVeth := s.veths[serverInterfaceName]
109 _, err = serverVpp.vppctl("test echo server uri tcp://%s/20022", serverVeth.Address())
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100110 s.assertNil(err, "starting echo server failed")
111
Maros Ondrejickadb823ed2022-12-14 16:30:04 +0100112 clientContainer := s.getContainerByName("client-vpp")
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100113
114 clientVpp := NewVppInstance(clientContainer)
115 s.assertNotNil(clientVpp)
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100116 clientVpp.set2VethsClient()
117 err = clientVpp.start()
118 s.assertNil(err, "starting VPP failed")
119
120 // Ensure that VPP doesn't abort itself with NSIM enabled
121 // Warning: Removing this ping will make the test fail!
122 _, err = serverVpp.vppctl("ping 10.10.10.2")
123 s.assertNil(err, "ping failed")
124
125 // Add loss of packets with Network Delay Simulator
126 _, err = clientVpp.vppctl("set nsim poll-main-thread delay 0.01 ms bandwidth 40 gbit packet-size 1400 packets-per-drop 1000")
127 s.assertNil(err, "configuring NSIM failed")
128 _, err = clientVpp.vppctl("nsim output-feature enable-disable host-vppcln")
129 s.assertNil(err, "enabling NSIM failed")
130
131 // Do echo test from client-vpp container
132 output, err := clientVpp.vppctl("test echo client uri tcp://10.10.10.1/20022 mbytes 50")
133 s.assertNil(err)
134 s.assertEqual(true, len(output) != 0)
135 s.assertNotContains(output, "failed: timeout")
Maros Ondrejicka87531802022-12-19 20:35:27 +0100136 s.log(output)
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100137}