blob: a5983c6fa4d5fd4e199ebb1cc98bd609bee54f7d [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
Filip Tehlar4b3598e2023-09-02 08:54:21 +02008const vclTemplate = `vcl {
9 app-socket-api %[1]s/var/run/app_ns_sockets/%[2]s
10 app-scope-global
11 app-scope-local
12 namespace-id %[2]s
13 namespace-secret %[2]s
14 use-mq-eventfd
15}
16`
17
Filip Tehlarefe875e2023-09-04 14:17:52 +020018func (s *VethsSuite) TestXEchoVclClientUdp() {
19 s.testXEchoVclClient("udp")
20}
21
22func (s *VethsSuite) TestXEchoVclClientTcp() {
23 s.testXEchoVclClient("tcp")
24}
25
26func (s *VethsSuite) testXEchoVclClient(proto string) {
27 port := "12345"
28 serverVpp := s.getContainerByName("server-vpp").vppInstance
29
30 serverVeth := s.netInterfaces[serverInterfaceName]
31 serverVpp.vppctl("test echo server uri %s://%s/%s fifo-size 64k", proto, serverVeth.ip4AddressString(), port)
32
33 echoClnContainer := s.getTransientContainerByName("client-app")
34 clientVclConfContent := fmt.Sprintf(vclTemplate, echoClnContainer.getContainerWorkDir(), "2")
35 echoClnContainer.createFile("/vcl.conf", clientVclConfContent)
36
37 testClientCommand := "vcl_test_client -N 100 -p " + proto + " " + serverVeth.ip4AddressString() + " " + port
38 s.log(testClientCommand)
39 echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
40 o := echoClnContainer.exec(testClientCommand)
41 s.log(o)
42 s.assertContains(o, "CLIENT RESULTS")
43}
44
45func (s *VethsSuite) TestXEchoVclServerUdp() {
46 s.testXEchoVclServer("udp")
47}
48
49func (s *VethsSuite) TestXEchoVclServerTcp() {
50 s.testXEchoVclServer("tcp")
51}
52
53func (s *VethsSuite) testXEchoVclServer(proto string) {
54 port := "12345"
55 srvVppCont := s.getContainerByName("server-vpp")
56 srvAppCont := s.getContainerByName("server-app")
57
58 serverVclConfContent := fmt.Sprintf(vclTemplate, srvVppCont.getContainerWorkDir(), "1")
59 srvAppCont.createFile("/vcl.conf", serverVclConfContent)
60 srvAppCont.addEnvVar("VCL_CONFIG", "/vcl.conf")
61 vclSrvCmd := fmt.Sprintf("vcl_test_server -p %s %s", proto, port)
62 srvAppCont.execServer(vclSrvCmd)
63
64 serverVeth := s.netInterfaces[serverInterfaceName]
65 serverVethAddress := serverVeth.ip4AddressString()
66
67 clientVpp := s.getContainerByName("client-vpp").vppInstance
68 o := clientVpp.vppctl("test echo client uri %s://%s/%s fifo-size 64k verbose mbytes 2", proto, serverVethAddress, port)
69 s.log(o)
70 s.assertContains(o, "Test finished at")
71}
72
Filip Tehlar71fc1942023-05-22 15:48:51 +020073func (s *VethsSuite) testVclEcho(proto string) {
74 port := "12345"
75 srvVppCont := s.getContainerByName("server-vpp")
76 srvAppCont := s.getContainerByName("server-app")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000077
Filip Tehlar71fc1942023-05-22 15:48:51 +020078 serverVclConfContent := fmt.Sprintf(vclTemplate, srvVppCont.getContainerWorkDir(), "1")
79 srvAppCont.createFile("/vcl.conf", serverVclConfContent)
80 srvAppCont.addEnvVar("VCL_CONFIG", "/vcl.conf")
81 srvAppCont.execServer("vcl_test_server " + port)
82
83 serverVeth := s.netInterfaces[serverInterfaceName]
84 serverVethAddress := serverVeth.ip4AddressString()
85
86 echoClnContainer := s.getTransientContainerByName("client-app")
87 clientVclConfContent := fmt.Sprintf(vclTemplate, echoClnContainer.getContainerWorkDir(), "2")
88 echoClnContainer.createFile("/vcl.conf", clientVclConfContent)
89
Filip Tehlard3b47c62023-05-31 12:26:59 +020090 testClientCommand := "vcl_test_client -p " + proto + " " + serverVethAddress + " " + port
Filip Tehlar71fc1942023-05-22 15:48:51 +020091 echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
92 o := echoClnContainer.exec(testClientCommand)
93 s.log(o)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000094}
95
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010096func (s *VethsSuite) TestVclEchoTcp() {
Filip Tehlar229f5fc2022-08-09 14:44:47 +000097 s.testVclEcho("tcp")
98}
99
Filip Tehlar71fc1942023-05-22 15:48:51 +0200100func (s *VethsSuite) TestVclEchoUdp() {
101 s.testVclEcho("udp")
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000102}
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200103
Maros Ondrejicka11a03e92022-12-01 09:56:37 +0100104func (s *VethsSuite) TestVclRetryAttach() {
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100105 s.skip("this test takes too long, for now it's being skipped")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200106 s.testRetryAttach("tcp")
107}
108
Maros Ondrejicka11a03e92022-12-01 09:56:37 +0100109func (s *VethsSuite) testRetryAttach(proto string) {
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100110 srvVppContainer := s.getTransientContainerByName("server-vpp")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200111
Filip Tehlar71fc1942023-05-22 15:48:51 +0200112 echoSrvContainer := s.getContainerByName("server-app")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100113
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100114 serverVclConfContent := fmt.Sprintf(vclTemplate, echoSrvContainer.getContainerWorkDir(), "1")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100115 echoSrvContainer.createFile("/vcl.conf", serverVclConfContent)
116
117 echoSrvContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100118 echoSrvContainer.execServer("vcl_test_server -p " + proto + " 12346")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200119
Maros Ondrejicka87531802022-12-19 20:35:27 +0100120 s.log("This whole test case can take around 3 minutes to run. Please be patient.")
121 s.log("... Running first echo client test, before disconnect.")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100122
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100123 serverVeth := s.netInterfaces[serverInterfaceName]
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100124 serverVethAddress := serverVeth.ip4AddressString()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100125
Filip Tehlar71fc1942023-05-22 15:48:51 +0200126 echoClnContainer := s.getTransientContainerByName("client-app")
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100127 clientVclConfContent := fmt.Sprintf(vclTemplate, echoClnContainer.getContainerWorkDir(), "2")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100128 echoClnContainer.createFile("/vcl.conf", clientVclConfContent)
129
130 testClientCommand := "vcl_test_client -U -p " + proto + " " + serverVethAddress + " 12346"
131 echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100132 o := echoClnContainer.exec(testClientCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100133 s.log(o)
Maros Ondrejicka87531802022-12-19 20:35:27 +0100134 s.log("... First test ended. Stopping VPP server now.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200135
136 // Stop server-vpp-instance, start it again and then run vcl-test-client once more
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100137 srvVppContainer.vppInstance.disconnect()
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200138 stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'"
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100139 srvVppContainer.exec(stopVppCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100140
141 s.setupServerVpp()
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200142
Maros Ondrejicka87531802022-12-19 20:35:27 +0100143 s.log("... VPP server is starting again, so waiting for a bit.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200144 time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
145
Maros Ondrejicka87531802022-12-19 20:35:27 +0100146 s.log("... Running second echo client test, after disconnect and re-attachment.")
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100147 o = echoClnContainer.exec(testClientCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100148 s.log(o)
Maros Ondrejicka87531802022-12-19 20:35:27 +0100149 s.log("Done.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200150}