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