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