blob: a949565f299296843ef7439422379fe3293c9d9f [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 Tehlar5ebdd512023-12-14 13:06:54 +01008func getVclConfig(c *Container, ns_id_optional ...string) string {
9 var s Stanza
10 ns_id := "default"
11 if len(ns_id_optional) > 0 {
12 ns_id = ns_id_optional[0]
13 }
14 s.newStanza("vcl").
15 append(fmt.Sprintf("app-socket-api %[1]s/var/run/app_ns_sockets/%[2]s", c.getContainerWorkDir(), ns_id)).
16 append("app-scope-global").
17 append("app-scope-local").
18 append("use-mq-eventfd")
19 if len(ns_id_optional) > 0 {
20 s.append(fmt.Sprintf("namespace-id %[1]s", ns_id)).
21 append(fmt.Sprintf("namespace-secret %[1]s", ns_id))
22 }
23 return s.close().toString()
Filip Tehlar4b3598e2023-09-02 08:54:21 +020024}
Filip Tehlar4b3598e2023-09-02 08:54:21 +020025
Filip Tehlarefe875e2023-09-04 14:17:52 +020026func (s *VethsSuite) TestXEchoVclClientUdp() {
27 s.testXEchoVclClient("udp")
28}
29
30func (s *VethsSuite) TestXEchoVclClientTcp() {
31 s.testXEchoVclClient("tcp")
32}
33
34func (s *VethsSuite) testXEchoVclClient(proto string) {
35 port := "12345"
36 serverVpp := s.getContainerByName("server-vpp").vppInstance
37
38 serverVeth := s.netInterfaces[serverInterfaceName]
39 serverVpp.vppctl("test echo server uri %s://%s/%s fifo-size 64k", proto, serverVeth.ip4AddressString(), port)
40
41 echoClnContainer := s.getTransientContainerByName("client-app")
Filip Tehlar5ebdd512023-12-14 13:06:54 +010042 echoClnContainer.createFile("/vcl.conf", getVclConfig(echoClnContainer))
Filip Tehlarefe875e2023-09-04 14:17:52 +020043
44 testClientCommand := "vcl_test_client -N 100 -p " + proto + " " + serverVeth.ip4AddressString() + " " + port
45 s.log(testClientCommand)
46 echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
47 o := echoClnContainer.exec(testClientCommand)
48 s.log(o)
49 s.assertContains(o, "CLIENT RESULTS")
50}
51
52func (s *VethsSuite) TestXEchoVclServerUdp() {
53 s.testXEchoVclServer("udp")
54}
55
56func (s *VethsSuite) TestXEchoVclServerTcp() {
57 s.testXEchoVclServer("tcp")
58}
59
60func (s *VethsSuite) testXEchoVclServer(proto string) {
61 port := "12345"
62 srvVppCont := s.getContainerByName("server-vpp")
63 srvAppCont := s.getContainerByName("server-app")
64
Filip Tehlar5ebdd512023-12-14 13:06:54 +010065 srvAppCont.createFile("/vcl.conf", getVclConfig(srvVppCont))
Filip Tehlarefe875e2023-09-04 14:17:52 +020066 srvAppCont.addEnvVar("VCL_CONFIG", "/vcl.conf")
67 vclSrvCmd := fmt.Sprintf("vcl_test_server -p %s %s", proto, port)
68 srvAppCont.execServer(vclSrvCmd)
69
70 serverVeth := s.netInterfaces[serverInterfaceName]
71 serverVethAddress := serverVeth.ip4AddressString()
72
73 clientVpp := s.getContainerByName("client-vpp").vppInstance
74 o := clientVpp.vppctl("test echo client uri %s://%s/%s fifo-size 64k verbose mbytes 2", proto, serverVethAddress, port)
75 s.log(o)
76 s.assertContains(o, "Test finished at")
77}
78
Filip Tehlar71fc1942023-05-22 15:48:51 +020079func (s *VethsSuite) testVclEcho(proto string) {
80 port := "12345"
81 srvVppCont := s.getContainerByName("server-vpp")
82 srvAppCont := s.getContainerByName("server-app")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000083
Filip Tehlar5ebdd512023-12-14 13:06:54 +010084 srvAppCont.createFile("/vcl.conf", getVclConfig(srvVppCont))
Filip Tehlar71fc1942023-05-22 15:48:51 +020085 srvAppCont.addEnvVar("VCL_CONFIG", "/vcl.conf")
86 srvAppCont.execServer("vcl_test_server " + port)
87
88 serverVeth := s.netInterfaces[serverInterfaceName]
89 serverVethAddress := serverVeth.ip4AddressString()
90
91 echoClnContainer := s.getTransientContainerByName("client-app")
Filip Tehlar5ebdd512023-12-14 13:06:54 +010092 echoClnContainer.createFile("/vcl.conf", getVclConfig(echoClnContainer))
Filip Tehlar71fc1942023-05-22 15:48:51 +020093
Filip Tehlard3b47c62023-05-31 12:26:59 +020094 testClientCommand := "vcl_test_client -p " + proto + " " + serverVethAddress + " " + port
Filip Tehlar71fc1942023-05-22 15:48:51 +020095 echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
96 o := echoClnContainer.exec(testClientCommand)
97 s.log(o)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000098}
99
Maros Ondrejicka11a03e92022-12-01 09:56:37 +0100100func (s *VethsSuite) TestVclEchoTcp() {
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000101 s.testVclEcho("tcp")
102}
103
Filip Tehlar71fc1942023-05-22 15:48:51 +0200104func (s *VethsSuite) TestVclEchoUdp() {
105 s.testVclEcho("udp")
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000106}
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200107
Maros Ondrejicka11a03e92022-12-01 09:56:37 +0100108func (s *VethsSuite) TestVclRetryAttach() {
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100109 s.skip("this test takes too long, for now it's being skipped")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200110 s.testRetryAttach("tcp")
111}
112
Maros Ondrejicka11a03e92022-12-01 09:56:37 +0100113func (s *VethsSuite) testRetryAttach(proto string) {
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100114 srvVppContainer := s.getTransientContainerByName("server-vpp")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200115
Filip Tehlar71fc1942023-05-22 15:48:51 +0200116 echoSrvContainer := s.getContainerByName("server-app")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100117
Filip Tehlar5ebdd512023-12-14 13:06:54 +0100118 echoSrvContainer.createFile("/vcl.conf", getVclConfig(echoSrvContainer))
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100119
120 echoSrvContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100121 echoSrvContainer.execServer("vcl_test_server -p " + proto + " 12346")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200122
Maros Ondrejicka87531802022-12-19 20:35:27 +0100123 s.log("This whole test case can take around 3 minutes to run. Please be patient.")
124 s.log("... Running first echo client test, before disconnect.")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100125
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100126 serverVeth := s.netInterfaces[serverInterfaceName]
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100127 serverVethAddress := serverVeth.ip4AddressString()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100128
Filip Tehlar71fc1942023-05-22 15:48:51 +0200129 echoClnContainer := s.getTransientContainerByName("client-app")
Filip Tehlar5ebdd512023-12-14 13:06:54 +0100130 echoClnContainer.createFile("/vcl.conf", getVclConfig(echoClnContainer))
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100131
132 testClientCommand := "vcl_test_client -U -p " + proto + " " + serverVethAddress + " 12346"
133 echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100134 o := echoClnContainer.exec(testClientCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100135 s.log(o)
Maros Ondrejicka87531802022-12-19 20:35:27 +0100136 s.log("... First test ended. Stopping VPP server now.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200137
138 // Stop server-vpp-instance, start it again and then run vcl-test-client once more
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100139 srvVppContainer.vppInstance.disconnect()
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200140 stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'"
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100141 srvVppContainer.exec(stopVppCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100142
143 s.setupServerVpp()
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200144
Maros Ondrejicka87531802022-12-19 20:35:27 +0100145 s.log("... VPP server is starting again, so waiting for a bit.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200146 time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
147
Maros Ondrejicka87531802022-12-19 20:35:27 +0100148 s.log("... Running second echo client test, after disconnect and re-attachment.")
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100149 o = echoClnContainer.exec(testClientCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100150 s.log(o)
Maros Ondrejicka87531802022-12-19 20:35:27 +0100151 s.log("Done.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200152}