f4273c87b14f2a51f0b6471ddab1ab36dd9180a9
[vpp.git] / extras / hs-test / vcl_test.go
1 package main
2
3 import (
4         "time"
5 )
6
7 func (s *VethsSuite) TestVclEchoQuic() {
8         s.skip("quic test skipping..")
9         s.testVclEcho("quic")
10 }
11
12 func (s *VethsSuite) TestVclEchoUdp() {
13         s.skip("udp echo currently broken in vpp, skipping..")
14         s.testVclEcho("udp")
15 }
16
17 func (s *VethsSuite) TestVclEchoTcp() {
18         s.testVclEcho("tcp")
19 }
20
21 func (s *VethsSuite) testVclEcho(proto string) {
22         srvVppContainer := s.getContainerByName("server-vpp")
23
24         _, err := srvVppContainer.execAction("Configure2Veths srv")
25         s.assertNil(err)
26
27         clnVppContainer := s.getContainerByName("client-vpp")
28
29         _, err = clnVppContainer.execAction("Configure2Veths cln")
30         s.assertNil(err)
31
32         echoSrvContainer := s.getContainerByName("server-application")
33
34         // run server app
35         _, err = echoSrvContainer.execAction("RunEchoServer " + proto)
36         s.assertNil(err)
37
38         echoClnContainer := s.getContainerByName("client-application")
39
40         o, err := echoClnContainer.execAction("RunEchoClient " + proto)
41         s.assertNil(err)
42
43         s.log(o)
44 }
45
46 func (s *VethsSuite) TestVclRetryAttach() {
47         s.skip()
48         s.testRetryAttach("tcp")
49 }
50
51 func (s *VethsSuite) testRetryAttach(proto string) {
52         srvVppContainer := s.getContainerByName("server-vpp")
53
54         _, err := srvVppContainer.execAction("Configure2Veths srv-with-preset-hw-addr")
55         s.assertNil(err)
56
57         clnVppContainer := s.getContainerByName("client-vpp")
58
59         _, err = clnVppContainer.execAction("Configure2Veths cln")
60         s.assertNil(err)
61
62         echoSrvContainer := s.getContainerByName("server-application")
63         _, err = echoSrvContainer.execAction("RunVclEchoServer " + proto)
64         s.assertNil(err)
65
66         s.log("This whole test case can take around 3 minutes to run. Please be patient.")
67         s.log("... Running first echo client test, before disconnect.")
68         echoClnContainer := s.getContainerByName("client-application")
69         _, err = echoClnContainer.execAction("RunVclEchoClient " + proto)
70         s.assertNil(err)
71         s.log("... First test ended. Stopping VPP server now.")
72
73         // Stop server-vpp-instance, start it again and then run vcl-test-client once more
74         stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'"
75         _, err = srvVppContainer.exec(stopVppCommand)
76         s.assertNil(err)
77         time.Sleep(5 * time.Second) // Give parent process time to reap the killed child process
78         stopVppCommand = "/bin/bash -c 'ps -C hs-test -o pid= | xargs kill -9'"
79         _, err = srvVppContainer.exec(stopVppCommand)
80         s.assertNil(err)
81         _, err = srvVppContainer.execAction("Configure2Veths srv-with-preset-hw-addr")
82         s.assertNil(err)
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         _, err = echoClnContainer.execAction("RunVclEchoClient " + proto)
89         s.assertNil(err)
90         s.log("Done.")
91 }
92
93 func (s *VethsSuite) TestTcpWithLoss() {
94         serverContainer := s.getContainerByName("server-vpp")
95
96         serverVpp := NewVppInstance(serverContainer)
97         s.assertNotNil(serverVpp)
98         serverVpp.set2VethsServer()
99         err := serverVpp.start()
100         s.assertNil(err, "starting VPP failed")
101
102         _, err = serverVpp.vppctl("test echo server uri tcp://10.10.10.1/20022")
103         s.assertNil(err, "starting echo server failed")
104
105         clientContainer := s.getContainerByName("client-vpp")
106
107         clientVpp := NewVppInstance(clientContainer)
108         s.assertNotNil(clientVpp)
109         clientVpp.set2VethsClient()
110         err = clientVpp.start()
111         s.assertNil(err, "starting VPP failed")
112
113         // Ensure that VPP doesn't abort itself with NSIM enabled
114         // Warning: Removing this ping will make the test fail!
115         _, err = serverVpp.vppctl("ping 10.10.10.2")
116         s.assertNil(err, "ping failed")
117
118         // Add loss of packets with Network Delay Simulator
119         _, err = clientVpp.vppctl("set nsim poll-main-thread delay 0.01 ms bandwidth 40 gbit packet-size 1400 packets-per-drop 1000")
120         s.assertNil(err, "configuring NSIM failed")
121         _, err = clientVpp.vppctl("nsim output-feature enable-disable host-vppcln")
122         s.assertNil(err, "enabling NSIM failed")
123
124         // Do echo test from client-vpp container
125         output, err := clientVpp.vppctl("test echo client uri tcp://10.10.10.1/20022 mbytes 50")
126         s.assertNil(err)
127         s.assertEqual(true, len(output) != 0)
128         s.assertNotContains(output, "failed: timeout")
129         s.log(output)
130 }