blob: fdcd60ad503d858215b38e75e86d178d2910c683 [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
Adrian Villincee15aa2024-03-14 11:42:55 -04008func init() {
9 registerVethTests(XEchoVclClientUdpTest, XEchoVclClientTcpTest, XEchoVclServerUdpTest,
10 XEchoVclServerTcpTest, VclEchoTcpTest, VclEchoUdpTest, VclRetryAttachTest)
11}
12
Filip Tehlar5ebdd512023-12-14 13:06:54 +010013func getVclConfig(c *Container, ns_id_optional ...string) string {
14 var s Stanza
15 ns_id := "default"
16 if len(ns_id_optional) > 0 {
17 ns_id = ns_id_optional[0]
18 }
19 s.newStanza("vcl").
20 append(fmt.Sprintf("app-socket-api %[1]s/var/run/app_ns_sockets/%[2]s", c.getContainerWorkDir(), ns_id)).
21 append("app-scope-global").
22 append("app-scope-local").
23 append("use-mq-eventfd")
24 if len(ns_id_optional) > 0 {
25 s.append(fmt.Sprintf("namespace-id %[1]s", ns_id)).
26 append(fmt.Sprintf("namespace-secret %[1]s", ns_id))
27 }
28 return s.close().toString()
Filip Tehlar4b3598e2023-09-02 08:54:21 +020029}
Filip Tehlar4b3598e2023-09-02 08:54:21 +020030
Adrian Villincee15aa2024-03-14 11:42:55 -040031func XEchoVclClientUdpTest(s *VethsSuite) {
Filip Tehlarefe875e2023-09-04 14:17:52 +020032 s.testXEchoVclClient("udp")
33}
34
Adrian Villincee15aa2024-03-14 11:42:55 -040035func XEchoVclClientTcpTest(s *VethsSuite) {
Filip Tehlarefe875e2023-09-04 14:17:52 +020036 s.testXEchoVclClient("tcp")
37}
38
39func (s *VethsSuite) testXEchoVclClient(proto string) {
40 port := "12345"
41 serverVpp := s.getContainerByName("server-vpp").vppInstance
42
adrianvillin28bd8f02024-02-13 06:00:02 -050043 serverVeth := s.getInterfaceByName(serverInterfaceName)
Filip Tehlarefe875e2023-09-04 14:17:52 +020044 serverVpp.vppctl("test echo server uri %s://%s/%s fifo-size 64k", proto, serverVeth.ip4AddressString(), port)
45
46 echoClnContainer := s.getTransientContainerByName("client-app")
Filip Tehlar5ebdd512023-12-14 13:06:54 +010047 echoClnContainer.createFile("/vcl.conf", getVclConfig(echoClnContainer))
Filip Tehlarefe875e2023-09-04 14:17:52 +020048
49 testClientCommand := "vcl_test_client -N 100 -p " + proto + " " + serverVeth.ip4AddressString() + " " + port
50 s.log(testClientCommand)
51 echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
52 o := echoClnContainer.exec(testClientCommand)
53 s.log(o)
54 s.assertContains(o, "CLIENT RESULTS")
55}
56
Adrian Villincee15aa2024-03-14 11:42:55 -040057func XEchoVclServerUdpTest(s *VethsSuite) {
Filip Tehlarefe875e2023-09-04 14:17:52 +020058 s.testXEchoVclServer("udp")
59}
60
Adrian Villincee15aa2024-03-14 11:42:55 -040061func XEchoVclServerTcpTest(s *VethsSuite) {
Filip Tehlarefe875e2023-09-04 14:17:52 +020062 s.testXEchoVclServer("tcp")
63}
64
65func (s *VethsSuite) testXEchoVclServer(proto string) {
66 port := "12345"
67 srvVppCont := s.getContainerByName("server-vpp")
68 srvAppCont := s.getContainerByName("server-app")
69
Filip Tehlar5ebdd512023-12-14 13:06:54 +010070 srvAppCont.createFile("/vcl.conf", getVclConfig(srvVppCont))
Filip Tehlarefe875e2023-09-04 14:17:52 +020071 srvAppCont.addEnvVar("VCL_CONFIG", "/vcl.conf")
72 vclSrvCmd := fmt.Sprintf("vcl_test_server -p %s %s", proto, port)
73 srvAppCont.execServer(vclSrvCmd)
74
adrianvillin28bd8f02024-02-13 06:00:02 -050075 serverVeth := s.getInterfaceByName(serverInterfaceName)
Filip Tehlarefe875e2023-09-04 14:17:52 +020076 serverVethAddress := serverVeth.ip4AddressString()
77
78 clientVpp := s.getContainerByName("client-vpp").vppInstance
79 o := clientVpp.vppctl("test echo client uri %s://%s/%s fifo-size 64k verbose mbytes 2", proto, serverVethAddress, port)
80 s.log(o)
81 s.assertContains(o, "Test finished at")
82}
83
Filip Tehlar71fc1942023-05-22 15:48:51 +020084func (s *VethsSuite) testVclEcho(proto string) {
85 port := "12345"
86 srvVppCont := s.getContainerByName("server-vpp")
87 srvAppCont := s.getContainerByName("server-app")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000088
Filip Tehlar5ebdd512023-12-14 13:06:54 +010089 srvAppCont.createFile("/vcl.conf", getVclConfig(srvVppCont))
Filip Tehlar71fc1942023-05-22 15:48:51 +020090 srvAppCont.addEnvVar("VCL_CONFIG", "/vcl.conf")
91 srvAppCont.execServer("vcl_test_server " + port)
92
adrianvillin28bd8f02024-02-13 06:00:02 -050093 serverVeth := s.getInterfaceByName(serverInterfaceName)
Filip Tehlar71fc1942023-05-22 15:48:51 +020094 serverVethAddress := serverVeth.ip4AddressString()
95
96 echoClnContainer := s.getTransientContainerByName("client-app")
Filip Tehlar5ebdd512023-12-14 13:06:54 +010097 echoClnContainer.createFile("/vcl.conf", getVclConfig(echoClnContainer))
Filip Tehlar71fc1942023-05-22 15:48:51 +020098
Filip Tehlard3b47c62023-05-31 12:26:59 +020099 testClientCommand := "vcl_test_client -p " + proto + " " + serverVethAddress + " " + port
Filip Tehlar71fc1942023-05-22 15:48:51 +0200100 echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
101 o := echoClnContainer.exec(testClientCommand)
102 s.log(o)
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000103}
104
Adrian Villincee15aa2024-03-14 11:42:55 -0400105func VclEchoTcpTest(s *VethsSuite) {
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000106 s.testVclEcho("tcp")
107}
108
Adrian Villincee15aa2024-03-14 11:42:55 -0400109func VclEchoUdpTest(s *VethsSuite) {
Filip Tehlar71fc1942023-05-22 15:48:51 +0200110 s.testVclEcho("udp")
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000111}
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200112
Adrian Villincee15aa2024-03-14 11:42:55 -0400113func VclRetryAttachTest(s *VethsSuite) {
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200114 s.testRetryAttach("tcp")
115}
116
Maros Ondrejicka11a03e92022-12-01 09:56:37 +0100117func (s *VethsSuite) testRetryAttach(proto string) {
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100118 srvVppContainer := s.getTransientContainerByName("server-vpp")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200119
Filip Tehlar71fc1942023-05-22 15:48:51 +0200120 echoSrvContainer := s.getContainerByName("server-app")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100121
Filip Tehlar5ebdd512023-12-14 13:06:54 +0100122 echoSrvContainer.createFile("/vcl.conf", getVclConfig(echoSrvContainer))
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100123
124 echoSrvContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100125 echoSrvContainer.execServer("vcl_test_server -p " + proto + " 12346")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200126
Maros Ondrejicka87531802022-12-19 20:35:27 +0100127 s.log("This whole test case can take around 3 minutes to run. Please be patient.")
128 s.log("... Running first echo client test, before disconnect.")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100129
adrianvillin28bd8f02024-02-13 06:00:02 -0500130 serverVeth := s.getInterfaceByName(serverInterfaceName)
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100131 serverVethAddress := serverVeth.ip4AddressString()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100132
Filip Tehlar71fc1942023-05-22 15:48:51 +0200133 echoClnContainer := s.getTransientContainerByName("client-app")
Filip Tehlar5ebdd512023-12-14 13:06:54 +0100134 echoClnContainer.createFile("/vcl.conf", getVclConfig(echoClnContainer))
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100135
136 testClientCommand := "vcl_test_client -U -p " + proto + " " + serverVethAddress + " 12346"
137 echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100138 o := echoClnContainer.exec(testClientCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100139 s.log(o)
Maros Ondrejicka87531802022-12-19 20:35:27 +0100140 s.log("... First test ended. Stopping VPP server now.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200141
142 // Stop server-vpp-instance, start it again and then run vcl-test-client once more
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100143 srvVppContainer.vppInstance.disconnect()
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200144 stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'"
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100145 srvVppContainer.exec(stopVppCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100146
147 s.setupServerVpp()
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200148
Maros Ondrejicka87531802022-12-19 20:35:27 +0100149 s.log("... VPP server is starting again, so waiting for a bit.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200150 time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
151
Maros Ondrejicka87531802022-12-19 20:35:27 +0100152 s.log("... Running second echo client test, after disconnect and re-attachment.")
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100153 o = echoClnContainer.exec(testClientCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100154 s.log(o)
Maros Ondrejicka87531802022-12-19 20:35:27 +0100155 s.log("Done.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200156}