blob: 3b413b26bed736278a6b6a1f0282766d73ca0486 [file] [log] [blame]
Filip Tehlar229f5fc2022-08-09 14:44:47 +00001package main
2
3import (
Adrian Villin4677d922024-06-14 09:32:39 +02004 . "fd.io/hs-test/infra"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +01005 "fmt"
Maros Ondrejicka0db15752022-10-12 22:58:01 +02006 "time"
Filip Tehlar229f5fc2022-08-09 14:44:47 +00007)
8
Adrian Villincee15aa2024-03-14 11:42:55 -04009func init() {
Adrian Villin4677d922024-06-14 09:32:39 +020010 RegisterVethTests(XEchoVclClientUdpTest, XEchoVclClientTcpTest, XEchoVclServerUdpTest,
Adrian Villincee15aa2024-03-14 11:42:55 -040011 XEchoVclServerTcpTest, VclEchoTcpTest, VclEchoUdpTest, VclRetryAttachTest)
12}
13
Filip Tehlar5ebdd512023-12-14 13:06:54 +010014func getVclConfig(c *Container, ns_id_optional ...string) string {
15 var s Stanza
16 ns_id := "default"
17 if len(ns_id_optional) > 0 {
18 ns_id = ns_id_optional[0]
19 }
Adrian Villin4677d922024-06-14 09:32:39 +020020 s.NewStanza("vcl").
21 Append(fmt.Sprintf("app-socket-api %[1]s/var/run/app_ns_sockets/%[2]s", c.GetContainerWorkDir(), ns_id)).
22 Append("app-scope-global").
23 Append("app-scope-local").
24 Append("use-mq-eventfd")
Filip Tehlar5ebdd512023-12-14 13:06:54 +010025 if len(ns_id_optional) > 0 {
Adrian Villin4677d922024-06-14 09:32:39 +020026 s.Append(fmt.Sprintf("namespace-id %[1]s", ns_id)).
27 Append(fmt.Sprintf("namespace-secret %[1]s", ns_id))
Filip Tehlar5ebdd512023-12-14 13:06:54 +010028 }
Adrian Villin4677d922024-06-14 09:32:39 +020029 return s.Close().ToString()
Filip Tehlar4b3598e2023-09-02 08:54:21 +020030}
Filip Tehlar4b3598e2023-09-02 08:54:21 +020031
Adrian Villincee15aa2024-03-14 11:42:55 -040032func XEchoVclClientUdpTest(s *VethsSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +020033 testXEchoVclClient(s, "udp")
Filip Tehlarefe875e2023-09-04 14:17:52 +020034}
35
Adrian Villincee15aa2024-03-14 11:42:55 -040036func XEchoVclClientTcpTest(s *VethsSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +020037 testXEchoVclClient(s, "tcp")
Filip Tehlarefe875e2023-09-04 14:17:52 +020038}
39
Adrian Villin4677d922024-06-14 09:32:39 +020040func testXEchoVclClient(s *VethsSuite, proto string) {
Filip Tehlarefe875e2023-09-04 14:17:52 +020041 port := "12345"
Adrian Villin4677d922024-06-14 09:32:39 +020042 serverVpp := s.GetContainerByName("server-vpp").VppInstance
Filip Tehlarefe875e2023-09-04 14:17:52 +020043
Adrian Villin4677d922024-06-14 09:32:39 +020044 serverVeth := s.GetInterfaceByName(ServerInterfaceName)
45 serverVpp.Vppctl("test echo server uri %s://%s/%s fifo-size 64k", proto, serverVeth.Ip4AddressString(), port)
Filip Tehlarefe875e2023-09-04 14:17:52 +020046
Adrian Villin4677d922024-06-14 09:32:39 +020047 echoClnContainer := s.GetTransientContainerByName("client-app")
48 echoClnContainer.CreateFile("/vcl.conf", getVclConfig(echoClnContainer))
Filip Tehlarefe875e2023-09-04 14:17:52 +020049
Adrian Villin4677d922024-06-14 09:32:39 +020050 testClientCommand := "vcl_test_client -N 100 -p " + proto + " " + serverVeth.Ip4AddressString() + " " + port
51 s.Log(testClientCommand)
52 echoClnContainer.AddEnvVar("VCL_CONFIG", "/vcl.conf")
53 o := echoClnContainer.Exec(testClientCommand)
54 s.Log(o)
55 s.AssertContains(o, "CLIENT RESULTS")
Filip Tehlarefe875e2023-09-04 14:17:52 +020056}
57
Adrian Villincee15aa2024-03-14 11:42:55 -040058func XEchoVclServerUdpTest(s *VethsSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +020059 testXEchoVclServer(s, "udp")
Filip Tehlarefe875e2023-09-04 14:17:52 +020060}
61
Adrian Villincee15aa2024-03-14 11:42:55 -040062func XEchoVclServerTcpTest(s *VethsSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +020063 testXEchoVclServer(s, "tcp")
Filip Tehlarefe875e2023-09-04 14:17:52 +020064}
65
Adrian Villin4677d922024-06-14 09:32:39 +020066func testXEchoVclServer(s *VethsSuite, proto string) {
Filip Tehlarefe875e2023-09-04 14:17:52 +020067 port := "12345"
Adrian Villin4677d922024-06-14 09:32:39 +020068 srvVppCont := s.GetContainerByName("server-vpp")
69 srvAppCont := s.GetContainerByName("server-app")
Filip Tehlarefe875e2023-09-04 14:17:52 +020070
Adrian Villin4677d922024-06-14 09:32:39 +020071 srvAppCont.CreateFile("/vcl.conf", getVclConfig(srvVppCont))
72 srvAppCont.AddEnvVar("VCL_CONFIG", "/vcl.conf")
Filip Tehlarefe875e2023-09-04 14:17:52 +020073 vclSrvCmd := fmt.Sprintf("vcl_test_server -p %s %s", proto, port)
Adrian Villin4677d922024-06-14 09:32:39 +020074 srvAppCont.ExecServer(vclSrvCmd)
Filip Tehlarefe875e2023-09-04 14:17:52 +020075
Adrian Villin4677d922024-06-14 09:32:39 +020076 serverVeth := s.GetInterfaceByName(ServerInterfaceName)
77 serverVethAddress := serverVeth.Ip4AddressString()
Filip Tehlarefe875e2023-09-04 14:17:52 +020078
Adrian Villin4677d922024-06-14 09:32:39 +020079 clientVpp := s.GetContainerByName("client-vpp").VppInstance
80 o := clientVpp.Vppctl("test echo client uri %s://%s/%s fifo-size 64k verbose mbytes 2", proto, serverVethAddress, port)
81 s.Log(o)
82 s.AssertContains(o, "Test finished at")
Filip Tehlarefe875e2023-09-04 14:17:52 +020083}
84
Adrian Villin4677d922024-06-14 09:32:39 +020085func testVclEcho(s *VethsSuite, proto string) {
Filip Tehlar71fc1942023-05-22 15:48:51 +020086 port := "12345"
Adrian Villin4677d922024-06-14 09:32:39 +020087 srvVppCont := s.GetContainerByName("server-vpp")
88 srvAppCont := s.GetContainerByName("server-app")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000089
Adrian Villin4677d922024-06-14 09:32:39 +020090 srvAppCont.CreateFile("/vcl.conf", getVclConfig(srvVppCont))
91 srvAppCont.AddEnvVar("VCL_CONFIG", "/vcl.conf")
92 srvAppCont.ExecServer("vcl_test_server " + port)
Filip Tehlar71fc1942023-05-22 15:48:51 +020093
Adrian Villin4677d922024-06-14 09:32:39 +020094 serverVeth := s.GetInterfaceByName(ServerInterfaceName)
95 serverVethAddress := serverVeth.Ip4AddressString()
Filip Tehlar71fc1942023-05-22 15:48:51 +020096
Adrian Villin4677d922024-06-14 09:32:39 +020097 echoClnContainer := s.GetTransientContainerByName("client-app")
98 echoClnContainer.CreateFile("/vcl.conf", getVclConfig(echoClnContainer))
Filip Tehlar71fc1942023-05-22 15:48:51 +020099
Filip Tehlard3b47c62023-05-31 12:26:59 +0200100 testClientCommand := "vcl_test_client -p " + proto + " " + serverVethAddress + " " + port
Adrian Villin4677d922024-06-14 09:32:39 +0200101 echoClnContainer.AddEnvVar("VCL_CONFIG", "/vcl.conf")
102 o := echoClnContainer.Exec(testClientCommand)
103 s.Log(o)
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000104}
105
Adrian Villincee15aa2024-03-14 11:42:55 -0400106func VclEchoTcpTest(s *VethsSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200107 testVclEcho(s, "tcp")
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000108}
109
Adrian Villincee15aa2024-03-14 11:42:55 -0400110func VclEchoUdpTest(s *VethsSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200111 testVclEcho(s, "udp")
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000112}
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200113
Adrian Villincee15aa2024-03-14 11:42:55 -0400114func VclRetryAttachTest(s *VethsSuite) {
Adrian Villin4677d922024-06-14 09:32:39 +0200115 testRetryAttach(s, "tcp")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200116}
117
Adrian Villin4677d922024-06-14 09:32:39 +0200118func testRetryAttach(s *VethsSuite, proto string) {
119 srvVppContainer := s.GetTransientContainerByName("server-vpp")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200120
Adrian Villin4677d922024-06-14 09:32:39 +0200121 echoSrvContainer := s.GetContainerByName("server-app")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100122
Adrian Villin4677d922024-06-14 09:32:39 +0200123 echoSrvContainer.CreateFile("/vcl.conf", getVclConfig(echoSrvContainer))
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100124
Adrian Villin4677d922024-06-14 09:32:39 +0200125 echoSrvContainer.AddEnvVar("VCL_CONFIG", "/vcl.conf")
126 echoSrvContainer.ExecServer("vcl_test_server -p " + proto + " 12346")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200127
Adrian Villin4677d922024-06-14 09:32:39 +0200128 s.Log("This whole test case can take around 3 minutes to run. Please be patient.")
129 s.Log("... Running first echo client test, before disconnect.")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100130
Adrian Villin4677d922024-06-14 09:32:39 +0200131 serverVeth := s.GetInterfaceByName(ServerInterfaceName)
132 serverVethAddress := serverVeth.Ip4AddressString()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100133
Adrian Villin4677d922024-06-14 09:32:39 +0200134 echoClnContainer := s.GetTransientContainerByName("client-app")
135 echoClnContainer.CreateFile("/vcl.conf", getVclConfig(echoClnContainer))
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100136
137 testClientCommand := "vcl_test_client -U -p " + proto + " " + serverVethAddress + " 12346"
Adrian Villin4677d922024-06-14 09:32:39 +0200138 echoClnContainer.AddEnvVar("VCL_CONFIG", "/vcl.conf")
139 o := echoClnContainer.Exec(testClientCommand)
140 s.Log(o)
141 s.Log("... First test ended. Stopping VPP server now.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200142
143 // Stop server-vpp-instance, start it again and then run vcl-test-client once more
Adrian Villin4677d922024-06-14 09:32:39 +0200144 srvVppContainer.VppInstance.Disconnect()
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200145 stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'"
Adrian Villin4677d922024-06-14 09:32:39 +0200146 srvVppContainer.Exec(stopVppCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +0100147
Adrian Villin4677d922024-06-14 09:32:39 +0200148 s.SetupServerVpp()
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200149
Adrian Villin4677d922024-06-14 09:32:39 +0200150 s.Log("... VPP server is starting again, so waiting for a bit.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200151 time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
152
Adrian Villin4677d922024-06-14 09:32:39 +0200153 s.Log("... Running second echo client test, after disconnect and re-attachment.")
154 o = echoClnContainer.Exec(testClientCommand)
155 s.Log(o)
156 s.Log("Done.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200157}