6c809f4caec767f7ad5b3e673556dc7f5479fca4
[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.veths["vppsrv"].Address()
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         err := echoSrvContainer.execServer(serverCommand)
33         s.assertNil(err)
34
35         echoClnContainer := s.getContainerByName("client-application")
36
37         clientCommand := "vpp_echo client" +
38                 " socket-name " + echoClnContainer.GetContainerWorkDir() + "/var/run/app_ns_sockets/2" +
39                 " use-app-socket-api uri " + uri
40         s.log(clientCommand)
41         o, err := echoClnContainer.exec(clientCommand)
42         s.assertNil(err)
43
44         s.log(o)
45 }
46
47 func (s *VethsSuite) TestVclRetryAttach() {
48         s.skip("this test takes too long, for now it's being skipped")
49         s.testRetryAttach("tcp")
50 }
51
52 func (s *VethsSuite) testRetryAttach(proto string) {
53         srvVppContainer := s.getContainerCopyByName("server-vpp")
54
55         echoSrvContainer := s.getContainerByName("server-application")
56
57         serverVclConfContent := fmt.Sprintf(vclTemplate, echoSrvContainer.GetContainerWorkDir(), "1")
58         echoSrvContainer.createFile("/vcl.conf", serverVclConfContent)
59
60         echoSrvContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
61         err := echoSrvContainer.execServer("vcl_test_server -p " + proto + " 12346")
62         s.assertNil(err)
63
64         s.log("This whole test case can take around 3 minutes to run. Please be patient.")
65         s.log("... Running first echo client test, before disconnect.")
66
67         serverVeth := s.veths[serverInterfaceName]
68         serverVethAddress := serverVeth.Address()
69
70         echoClnContainer := s.getContainerCopyByName("client-application")
71         clientVclConfContent := fmt.Sprintf(vclTemplate, echoClnContainer.GetContainerWorkDir(), "2")
72         echoClnContainer.createFile("/vcl.conf", clientVclConfContent)
73
74         testClientCommand := "vcl_test_client -U -p " + proto + " " + serverVethAddress + " 12346"
75         echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
76         o, err := echoClnContainer.exec(testClientCommand)
77         s.log(o)
78         s.assertNil(err)
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         _, err = srvVppContainer.exec(stopVppCommand)
85         s.assertNil(err)
86
87         s.setupServerVpp()
88
89         s.log("... VPP server is starting again, so waiting for a bit.")
90         time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
91
92         s.log("... Running second echo client test, after disconnect and re-attachment.")
93         o, err = echoClnContainer.exec(testClientCommand)
94         s.log(o)
95         s.assertNil(err)
96         s.log("Done.")
97 }
98
99 func (s *VethsSuite) TestTcpWithLoss() {
100         serverContainer := s.getContainerByName("server-vpp")
101
102         serverVpp := NewVppInstance(serverContainer)
103         s.assertNotNil(serverVpp)
104         serverVpp.set2VethsServer()
105         err := serverVpp.start()
106         s.assertNil(err, "starting VPP failed")
107
108         serverVeth := s.veths[serverInterfaceName]
109         _, err = serverVpp.vppctl("test echo server uri tcp://%s/20022", serverVeth.Address())
110         s.assertNil(err, "starting echo server failed")
111
112         clientContainer := s.getContainerByName("client-vpp")
113
114         clientVpp := NewVppInstance(clientContainer)
115         s.assertNotNil(clientVpp)
116         clientVpp.set2VethsClient()
117         err = clientVpp.start()
118         s.assertNil(err, "starting VPP failed")
119
120         // Ensure that VPP doesn't abort itself with NSIM enabled
121         // Warning: Removing this ping will make the test fail!
122         _, err = serverVpp.vppctl("ping 10.10.10.2")
123         s.assertNil(err, "ping failed")
124
125         // Add loss of packets with Network Delay Simulator
126         _, err = clientVpp.vppctl("set nsim poll-main-thread delay 0.01 ms bandwidth 40 gbit packet-size 1400 packets-per-drop 1000")
127         s.assertNil(err, "configuring NSIM failed")
128         _, err = clientVpp.vppctl("nsim output-feature enable-disable host-vppcln")
129         s.assertNil(err, "enabling NSIM failed")
130
131         // Do echo test from client-vpp container
132         output, err := clientVpp.vppctl("test echo client uri tcp://10.10.10.1/20022 mbytes 50")
133         s.assertNil(err)
134         s.assertEqual(true, len(output) != 0)
135         s.assertNotContains(output, "failed: timeout")
136         s.log(output)
137 }