blob: 68ca9d0209738291983664116609ab72bb0a6878 [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"
Aritra Basu70d2a082024-08-28 14:02:34 -07006
7 . "fd.io/hs-test/infra"
Filip Tehlar229f5fc2022-08-09 14:44:47 +00008)
9
Adrian Villincee15aa2024-03-14 11:42:55 -040010func init() {
Adrian Villin4677d922024-06-14 09:32:39 +020011 RegisterVethTests(XEchoVclClientUdpTest, XEchoVclClientTcpTest, XEchoVclServerUdpTest,
Aritra Basu70d2a082024-08-28 14:02:34 -070012 XEchoVclServerTcpTest, VclEchoTcpTest, VclEchoUdpTest, VclHttpPostTest, VclRetryAttachTest)
Adrian Villincee15aa2024-03-14 11:42:55 -040013}
14
Filip Tehlar5ebdd512023-12-14 13:06:54 +010015func getVclConfig(c *Container, ns_id_optional ...string) string {
16 var s Stanza
17 ns_id := "default"
18 if len(ns_id_optional) > 0 {
19 ns_id = ns_id_optional[0]
20 }
Adrian Villin4677d922024-06-14 09:32:39 +020021 s.NewStanza("vcl").
22 Append(fmt.Sprintf("app-socket-api %[1]s/var/run/app_ns_sockets/%[2]s", c.GetContainerWorkDir(), ns_id)).
23 Append("app-scope-global").
24 Append("app-scope-local").
25 Append("use-mq-eventfd")
Filip Tehlar5ebdd512023-12-14 13:06:54 +010026 if len(ns_id_optional) > 0 {
Adrian Villin4677d922024-06-14 09:32:39 +020027 s.Append(fmt.Sprintf("namespace-id %[1]s", ns_id)).
28 Append(fmt.Sprintf("namespace-secret %[1]s", ns_id))
Filip Tehlar5ebdd512023-12-14 13:06:54 +010029 }
Adrian Villin4677d922024-06-14 09:32:39 +020030 return s.Close().ToString()
Filip Tehlar4b3598e2023-09-02 08:54:21 +020031}
Filip Tehlar4b3598e2023-09-02 08:54:21 +020032
Adrian Villincee15aa2024-03-14 11:42:55 -040033func XEchoVclClientUdpTest(s *VethsSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +020034 testXEchoVclClient(s, "udp")
Filip Tehlarefe875e2023-09-04 14:17:52 +020035}
36
Adrian Villincee15aa2024-03-14 11:42:55 -040037func XEchoVclClientTcpTest(s *VethsSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +020038 testXEchoVclClient(s, "tcp")
Filip Tehlarefe875e2023-09-04 14:17:52 +020039}
40
Adrian Villin4677d922024-06-14 09:32:39 +020041func testXEchoVclClient(s *VethsSuite, proto string) {
Filip Tehlarefe875e2023-09-04 14:17:52 +020042 port := "12345"
Adrian Villin4677d922024-06-14 09:32:39 +020043 serverVpp := s.GetContainerByName("server-vpp").VppInstance
Filip Tehlarefe875e2023-09-04 14:17:52 +020044
Adrian Villin4677d922024-06-14 09:32:39 +020045 serverVeth := s.GetInterfaceByName(ServerInterfaceName)
46 serverVpp.Vppctl("test echo server uri %s://%s/%s fifo-size 64k", proto, serverVeth.Ip4AddressString(), port)
Filip Tehlarefe875e2023-09-04 14:17:52 +020047
Adrian Villin4677d922024-06-14 09:32:39 +020048 echoClnContainer := s.GetTransientContainerByName("client-app")
49 echoClnContainer.CreateFile("/vcl.conf", getVclConfig(echoClnContainer))
Filip Tehlarefe875e2023-09-04 14:17:52 +020050
Adrian Villin4677d922024-06-14 09:32:39 +020051 testClientCommand := "vcl_test_client -N 100 -p " + proto + " " + serverVeth.Ip4AddressString() + " " + port
52 s.Log(testClientCommand)
53 echoClnContainer.AddEnvVar("VCL_CONFIG", "/vcl.conf")
Adrian Villin2acdf1e2024-09-25 14:49:11 +020054 o := echoClnContainer.Exec(true, testClientCommand)
Adrian Villin4677d922024-06-14 09:32:39 +020055 s.Log(o)
56 s.AssertContains(o, "CLIENT RESULTS")
Filip Tehlarefe875e2023-09-04 14:17:52 +020057}
58
Adrian Villincee15aa2024-03-14 11:42:55 -040059func XEchoVclServerUdpTest(s *VethsSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +020060 testXEchoVclServer(s, "udp")
Filip Tehlarefe875e2023-09-04 14:17:52 +020061}
62
Adrian Villincee15aa2024-03-14 11:42:55 -040063func XEchoVclServerTcpTest(s *VethsSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +020064 testXEchoVclServer(s, "tcp")
Filip Tehlarefe875e2023-09-04 14:17:52 +020065}
66
Adrian Villin4677d922024-06-14 09:32:39 +020067func testXEchoVclServer(s *VethsSuite, proto string) {
Filip Tehlarefe875e2023-09-04 14:17:52 +020068 port := "12345"
Adrian Villin4677d922024-06-14 09:32:39 +020069 srvVppCont := s.GetContainerByName("server-vpp")
70 srvAppCont := s.GetContainerByName("server-app")
Filip Tehlarefe875e2023-09-04 14:17:52 +020071
Adrian Villin4677d922024-06-14 09:32:39 +020072 srvAppCont.CreateFile("/vcl.conf", getVclConfig(srvVppCont))
73 srvAppCont.AddEnvVar("VCL_CONFIG", "/vcl.conf")
Filip Tehlarefe875e2023-09-04 14:17:52 +020074 vclSrvCmd := fmt.Sprintf("vcl_test_server -p %s %s", proto, port)
Adrian Villin2acdf1e2024-09-25 14:49:11 +020075 srvAppCont.ExecServer(true, vclSrvCmd)
Filip Tehlarefe875e2023-09-04 14:17:52 +020076
Adrian Villin4677d922024-06-14 09:32:39 +020077 serverVeth := s.GetInterfaceByName(ServerInterfaceName)
78 serverVethAddress := serverVeth.Ip4AddressString()
Filip Tehlarefe875e2023-09-04 14:17:52 +020079
Adrian Villin4677d922024-06-14 09:32:39 +020080 clientVpp := s.GetContainerByName("client-vpp").VppInstance
81 o := clientVpp.Vppctl("test echo client uri %s://%s/%s fifo-size 64k verbose mbytes 2", proto, serverVethAddress, port)
82 s.Log(o)
83 s.AssertContains(o, "Test finished at")
Filip Tehlarefe875e2023-09-04 14:17:52 +020084}
85
Adrian Villin4677d922024-06-14 09:32:39 +020086func testVclEcho(s *VethsSuite, proto string) {
Filip Tehlar71fc1942023-05-22 15:48:51 +020087 port := "12345"
Adrian Villin4677d922024-06-14 09:32:39 +020088 srvVppCont := s.GetContainerByName("server-vpp")
89 srvAppCont := s.GetContainerByName("server-app")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000090
Adrian Villin4677d922024-06-14 09:32:39 +020091 srvAppCont.CreateFile("/vcl.conf", getVclConfig(srvVppCont))
92 srvAppCont.AddEnvVar("VCL_CONFIG", "/vcl.conf")
Adrian Villin2acdf1e2024-09-25 14:49:11 +020093 srvAppCont.ExecServer(true, "vcl_test_server -p "+proto+" "+port)
Filip Tehlar71fc1942023-05-22 15:48:51 +020094
Adrian Villin4677d922024-06-14 09:32:39 +020095 serverVeth := s.GetInterfaceByName(ServerInterfaceName)
96 serverVethAddress := serverVeth.Ip4AddressString()
Filip Tehlar71fc1942023-05-22 15:48:51 +020097
Adrian Villin4677d922024-06-14 09:32:39 +020098 echoClnContainer := s.GetTransientContainerByName("client-app")
99 echoClnContainer.CreateFile("/vcl.conf", getVclConfig(echoClnContainer))
Filip Tehlar71fc1942023-05-22 15:48:51 +0200100
Filip Tehlard3b47c62023-05-31 12:26:59 +0200101 testClientCommand := "vcl_test_client -p " + proto + " " + serverVethAddress + " " + port
Adrian Villin4677d922024-06-14 09:32:39 +0200102 echoClnContainer.AddEnvVar("VCL_CONFIG", "/vcl.conf")
Adrian Villin2acdf1e2024-09-25 14:49:11 +0200103 o := echoClnContainer.Exec(true, testClientCommand)
Adrian Villin4677d922024-06-14 09:32:39 +0200104 s.Log(o)
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000105}
106
Adrian Villincee15aa2024-03-14 11:42:55 -0400107func VclEchoTcpTest(s *VethsSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200108 testVclEcho(s, "tcp")
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000109}
110
Adrian Villincee15aa2024-03-14 11:42:55 -0400111func VclEchoUdpTest(s *VethsSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200112 testVclEcho(s, "udp")
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000113}
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200114
Aritra Basu70d2a082024-08-28 14:02:34 -0700115func VclHttpPostTest(s *VethsSuite) {
116 testVclEcho(s, "http")
117}
118
Adrian Villincee15aa2024-03-14 11:42:55 -0400119func VclRetryAttachTest(s *VethsSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200120 testRetryAttach(s, "tcp")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200121}
122
Adrian Villin4677d922024-06-14 09:32:39 +0200123func testRetryAttach(s *VethsSuite, proto string) {
124 srvVppContainer := s.GetTransientContainerByName("server-vpp")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200125
Adrian Villin4677d922024-06-14 09:32:39 +0200126 echoSrvContainer := s.GetContainerByName("server-app")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100127
Adrian Villin4677d922024-06-14 09:32:39 +0200128 echoSrvContainer.CreateFile("/vcl.conf", getVclConfig(echoSrvContainer))
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100129
Adrian Villin4677d922024-06-14 09:32:39 +0200130 echoSrvContainer.AddEnvVar("VCL_CONFIG", "/vcl.conf")
Adrian Villin2acdf1e2024-09-25 14:49:11 +0200131 echoSrvContainer.ExecServer(true, "vcl_test_server -p "+proto+" 12346")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200132
Adrian Villin4677d922024-06-14 09:32:39 +0200133 s.Log("This whole test case can take around 3 minutes to run. Please be patient.")
134 s.Log("... Running first echo client test, before disconnect.")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100135
Adrian Villin4677d922024-06-14 09:32:39 +0200136 serverVeth := s.GetInterfaceByName(ServerInterfaceName)
137 serverVethAddress := serverVeth.Ip4AddressString()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100138
Adrian Villin4677d922024-06-14 09:32:39 +0200139 echoClnContainer := s.GetTransientContainerByName("client-app")
140 echoClnContainer.CreateFile("/vcl.conf", getVclConfig(echoClnContainer))
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100141
142 testClientCommand := "vcl_test_client -U -p " + proto + " " + serverVethAddress + " 12346"
Adrian Villin4677d922024-06-14 09:32:39 +0200143 echoClnContainer.AddEnvVar("VCL_CONFIG", "/vcl.conf")
Adrian Villin2acdf1e2024-09-25 14:49:11 +0200144 o := echoClnContainer.Exec(true, testClientCommand)
Adrian Villin4677d922024-06-14 09:32:39 +0200145 s.Log(o)
146 s.Log("... First test ended. Stopping VPP server now.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200147
148 // Stop server-vpp-instance, start it again and then run vcl-test-client once more
Adrian Villin4677d922024-06-14 09:32:39 +0200149 srvVppContainer.VppInstance.Disconnect()
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200150 stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'"
Adrian Villin2acdf1e2024-09-25 14:49:11 +0200151 srvVppContainer.Exec(false, stopVppCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100152
Adrian Villin4677d922024-06-14 09:32:39 +0200153 s.SetupServerVpp()
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200154
Adrian Villin4677d922024-06-14 09:32:39 +0200155 s.Log("... VPP server is starting again, so waiting for a bit.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200156 time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
157
Adrian Villin4677d922024-06-14 09:32:39 +0200158 s.Log("... Running second echo client test, after disconnect and re-attachment.")
Adrian Villin2acdf1e2024-09-25 14:49:11 +0200159 o = echoClnContainer.Exec(true, testClientCommand)
Adrian Villin4677d922024-06-14 09:32:39 +0200160 s.Log(o)
161 s.Log("Done.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200162}