4 . "fd.io/hs-test/infra"
10 RegisterVethTests(XEchoVclClientUdpTest, XEchoVclClientTcpTest, XEchoVclServerUdpTest,
11 XEchoVclServerTcpTest, VclEchoTcpTest, VclEchoUdpTest, VclRetryAttachTest)
14 func getVclConfig(c *Container, ns_id_optional ...string) string {
17 if len(ns_id_optional) > 0 {
18 ns_id = ns_id_optional[0]
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")
25 if len(ns_id_optional) > 0 {
26 s.Append(fmt.Sprintf("namespace-id %[1]s", ns_id)).
27 Append(fmt.Sprintf("namespace-secret %[1]s", ns_id))
29 return s.Close().ToString()
32 func XEchoVclClientUdpTest(s *VethsSuite) {
33 testXEchoVclClient(s, "udp")
36 func XEchoVclClientTcpTest(s *VethsSuite) {
37 testXEchoVclClient(s, "tcp")
40 func testXEchoVclClient(s *VethsSuite, proto string) {
42 serverVpp := s.GetContainerByName("server-vpp").VppInstance
44 serverVeth := s.GetInterfaceByName(ServerInterfaceName)
45 serverVpp.Vppctl("test echo server uri %s://%s/%s fifo-size 64k", proto, serverVeth.Ip4AddressString(), port)
47 echoClnContainer := s.GetTransientContainerByName("client-app")
48 echoClnContainer.CreateFile("/vcl.conf", getVclConfig(echoClnContainer))
50 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)
55 s.AssertContains(o, "CLIENT RESULTS")
58 func XEchoVclServerUdpTest(s *VethsSuite) {
59 testXEchoVclServer(s, "udp")
62 func XEchoVclServerTcpTest(s *VethsSuite) {
63 testXEchoVclServer(s, "tcp")
66 func testXEchoVclServer(s *VethsSuite, proto string) {
68 srvVppCont := s.GetContainerByName("server-vpp")
69 srvAppCont := s.GetContainerByName("server-app")
71 srvAppCont.CreateFile("/vcl.conf", getVclConfig(srvVppCont))
72 srvAppCont.AddEnvVar("VCL_CONFIG", "/vcl.conf")
73 vclSrvCmd := fmt.Sprintf("vcl_test_server -p %s %s", proto, port)
74 srvAppCont.ExecServer(vclSrvCmd)
76 serverVeth := s.GetInterfaceByName(ServerInterfaceName)
77 serverVethAddress := serverVeth.Ip4AddressString()
79 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)
82 s.AssertContains(o, "Test finished at")
85 func testVclEcho(s *VethsSuite, proto string) {
87 srvVppCont := s.GetContainerByName("server-vpp")
88 srvAppCont := s.GetContainerByName("server-app")
90 srvAppCont.CreateFile("/vcl.conf", getVclConfig(srvVppCont))
91 srvAppCont.AddEnvVar("VCL_CONFIG", "/vcl.conf")
92 srvAppCont.ExecServer("vcl_test_server " + port)
94 serverVeth := s.GetInterfaceByName(ServerInterfaceName)
95 serverVethAddress := serverVeth.Ip4AddressString()
97 echoClnContainer := s.GetTransientContainerByName("client-app")
98 echoClnContainer.CreateFile("/vcl.conf", getVclConfig(echoClnContainer))
100 testClientCommand := "vcl_test_client -p " + proto + " " + serverVethAddress + " " + port
101 echoClnContainer.AddEnvVar("VCL_CONFIG", "/vcl.conf")
102 o := echoClnContainer.Exec(testClientCommand)
106 func VclEchoTcpTest(s *VethsSuite) {
107 testVclEcho(s, "tcp")
110 func VclEchoUdpTest(s *VethsSuite) {
111 testVclEcho(s, "udp")
114 func VclRetryAttachTest(s *VethsSuite) {
115 testRetryAttach(s, "tcp")
118 func testRetryAttach(s *VethsSuite, proto string) {
119 srvVppContainer := s.GetTransientContainerByName("server-vpp")
121 echoSrvContainer := s.GetContainerByName("server-app")
123 echoSrvContainer.CreateFile("/vcl.conf", getVclConfig(echoSrvContainer))
125 echoSrvContainer.AddEnvVar("VCL_CONFIG", "/vcl.conf")
126 echoSrvContainer.ExecServer("vcl_test_server -p " + proto + " 12346")
128 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.")
131 serverVeth := s.GetInterfaceByName(ServerInterfaceName)
132 serverVethAddress := serverVeth.Ip4AddressString()
134 echoClnContainer := s.GetTransientContainerByName("client-app")
135 echoClnContainer.CreateFile("/vcl.conf", getVclConfig(echoClnContainer))
137 testClientCommand := "vcl_test_client -U -p " + proto + " " + serverVethAddress + " 12346"
138 echoClnContainer.AddEnvVar("VCL_CONFIG", "/vcl.conf")
139 o := echoClnContainer.Exec(testClientCommand)
141 s.Log("... First test ended. Stopping VPP server now.")
143 // Stop server-vpp-instance, start it again and then run vcl-test-client once more
144 srvVppContainer.VppInstance.Disconnect()
145 stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'"
146 srvVppContainer.Exec(stopVppCommand)
150 s.Log("... VPP server is starting again, so waiting for a bit.")
151 time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
153 s.Log("... Running second echo client test, after disconnect and re-attachment.")
154 o = echoClnContainer.Exec(testClientCommand)