hs-test: log external apps
[vpp.git] / extras / hs-test / vcl_test.go
1 package main
2
3 import (
4         "fmt"
5         "time"
6 )
7
8 const vclTemplate = `vcl {
9   app-socket-api %[1]s/var/run/app_ns_sockets/%[2]s
10   app-scope-global
11   app-scope-local
12   namespace-id %[2]s
13   namespace-secret %[2]s
14   use-mq-eventfd
15 }
16 `
17
18 func (s *VethsSuite) testVclEcho(proto string) {
19         port := "12345"
20         srvVppCont := s.getContainerByName("server-vpp")
21         srvAppCont := s.getContainerByName("server-app")
22
23         serverVclConfContent := fmt.Sprintf(vclTemplate, srvVppCont.getContainerWorkDir(), "1")
24         srvAppCont.createFile("/vcl.conf", serverVclConfContent)
25         srvAppCont.addEnvVar("VCL_CONFIG", "/vcl.conf")
26         srvAppCont.execServer("vcl_test_server " + port)
27
28         serverVeth := s.netInterfaces[serverInterfaceName]
29         serverVethAddress := serverVeth.ip4AddressString()
30
31         echoClnContainer := s.getTransientContainerByName("client-app")
32         clientVclConfContent := fmt.Sprintf(vclTemplate, echoClnContainer.getContainerWorkDir(), "2")
33         echoClnContainer.createFile("/vcl.conf", clientVclConfContent)
34
35         testClientCommand := "vcl_test_client -p " + proto + " " + serverVethAddress + " " + port
36         echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
37         o := echoClnContainer.exec(testClientCommand)
38         s.log(o)
39 }
40
41 func (s *VethsSuite) TestVclEchoTcp() {
42         s.testVclEcho("tcp")
43 }
44
45 func (s *VethsSuite) TestVclEchoUdp() {
46         s.testVclEcho("udp")
47 }
48
49 func (s *VethsSuite) TestVclRetryAttach() {
50         s.skip("this test takes too long, for now it's being skipped")
51         s.testRetryAttach("tcp")
52 }
53
54 func (s *VethsSuite) testRetryAttach(proto string) {
55         srvVppContainer := s.getTransientContainerByName("server-vpp")
56
57         echoSrvContainer := s.getContainerByName("server-app")
58
59         serverVclConfContent := fmt.Sprintf(vclTemplate, echoSrvContainer.getContainerWorkDir(), "1")
60         echoSrvContainer.createFile("/vcl.conf", serverVclConfContent)
61
62         echoSrvContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
63         echoSrvContainer.execServer("vcl_test_server -p " + proto + " 12346")
64
65         s.log("This whole test case can take around 3 minutes to run. Please be patient.")
66         s.log("... Running first echo client test, before disconnect.")
67
68         serverVeth := s.netInterfaces[serverInterfaceName]
69         serverVethAddress := serverVeth.ip4AddressString()
70
71         echoClnContainer := s.getTransientContainerByName("client-app")
72         clientVclConfContent := fmt.Sprintf(vclTemplate, echoClnContainer.getContainerWorkDir(), "2")
73         echoClnContainer.createFile("/vcl.conf", clientVclConfContent)
74
75         testClientCommand := "vcl_test_client -U -p " + proto + " " + serverVethAddress + " 12346"
76         echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
77         o := echoClnContainer.exec(testClientCommand)
78         s.log(o)
79         s.log("... First test ended. Stopping VPP server now.")
80
81         // Stop server-vpp-instance, start it again and then run vcl-test-client once more
82         srvVppContainer.vppInstance.disconnect()
83         stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'"
84         srvVppContainer.exec(stopVppCommand)
85
86         s.setupServerVpp()
87
88         s.log("... VPP server is starting again, so waiting for a bit.")
89         time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
90
91         s.log("... Running second echo client test, after disconnect and re-attachment.")
92         o = echoClnContainer.exec(testClientCommand)
93         s.log(o)
94         s.log("Done.")
95 }
96
97 func (s *VethsSuite) TestTcpWithLoss() {
98         serverVpp := s.getContainerByName("server-vpp").vppInstance
99
100         serverVeth := s.netInterfaces[serverInterfaceName]
101         serverVpp.vppctl("test echo server uri tcp://%s/20022",
102                 serverVeth.ip4AddressString())
103
104         clientVpp := s.getContainerByName("client-vpp").vppInstance
105
106         // Ensure that VPP doesn't abort itself with NSIM enabled
107         // Warning: Removing this ping will make the test fail!
108         clientVpp.vppctl("ping %s", serverVeth.ip4AddressString())
109
110         // Add loss of packets with Network Delay Simulator
111         clientVpp.vppctl("set nsim poll-main-thread delay 0.01 ms bandwidth 40 gbit" +
112                 " packet-size 1400 packets-per-drop 1000")
113
114         clientVpp.vppctl("nsim output-feature enable-disable host-vppcln")
115
116         // Do echo test from client-vpp container
117         output := clientVpp.vppctl("test echo client uri tcp://%s/20022 mbytes 50",
118                 serverVeth.ip4AddressString())
119         s.assertEqual(true, len(output) != 0)
120         s.assertNotContains(output, "failed: timeout")
121         s.log(output)
122 }