blob: fddd70d49d8dc480a08a59b498d47d3561d99ee8 [file] [log] [blame]
Filip Tehlar229f5fc2022-08-09 14:44:47 +00001package main
2
3import (
4 "fmt"
Maros Ondrejicka0db15752022-10-12 22:58:01 +02005 "time"
Filip Tehlar229f5fc2022-08-09 14:44:47 +00006
7 "github.com/edwarnicke/exechelper"
8)
9
10func (s *Veths2Suite) TestVclEchoQuic() {
11 s.T().Skip("quic test skipping..")
12 s.testVclEcho("quic")
13}
14
15func (s *Veths2Suite) TestVclEchoUdp() {
16 s.T().Skip("udp echo currently broken in vpp, skipping..")
17 s.testVclEcho("udp")
18}
19
20func (s *Veths2Suite) TestVclEchoTcp() {
21 s.testVclEcho("tcp")
22}
23
24func (s *Veths2Suite) testVclEcho(proto string) {
25 t := s.T()
26
27 exechelper.Run("docker volume create --name=echo-srv-vol")
28 exechelper.Run("docker volume create --name=echo-cln-vol")
29
30 srvInstance := "vpp-echo-srv"
31 clnInstance := "vpp-echo-cln"
32 echoSrv := "echo-srv"
33 echoCln := "echo-cln"
34
35 err := dockerRun(srvInstance, "-v echo-srv-vol:/tmp/2veths")
36 if err != nil {
37 t.Errorf("%v", err)
38 return
39 }
40 defer func() { exechelper.Run("docker stop " + srvInstance) }()
41
42 err = dockerRun(clnInstance, "-v echo-cln-vol:/tmp/2veths")
43 if err != nil {
44 t.Errorf("%v", err)
45 return
46 }
47 defer func() { exechelper.Run("docker stop " + clnInstance) }()
48
49 err = dockerRun(echoSrv, fmt.Sprintf("-v echo-srv-vol:/tmp/%s", echoSrv))
50 if err != nil {
51 t.Errorf("%v", err)
52 return
53 }
54 defer func() { exechelper.Run("docker stop " + echoSrv) }()
55
56 err = dockerRun(echoCln, fmt.Sprintf("-v echo-cln-vol:/tmp/%s", echoCln))
57 if err != nil {
58 t.Errorf("%v", err)
59 return
60 }
61 defer func() { exechelper.Run("docker stop " + echoCln) }()
62
63 _, err = hstExec("2veths srv", srvInstance)
64 if err != nil {
65 t.Errorf("%v", err)
66 return
67 }
68
69 _, err = hstExec("2veths cln", clnInstance)
70 if err != nil {
71 t.Errorf("%v", err)
72 return
73 }
74
75 // run server app
76 _, err = hstExec("echo-server "+proto, echoSrv)
77 if err != nil {
78 t.Errorf("echo server: %v", err)
79 return
80 }
81
82 o, err := hstExec("echo-client "+proto, echoCln)
83 if err != nil {
84 t.Errorf("echo client: %v", err)
85 }
86 fmt.Println(o)
87}
Maros Ondrejicka0db15752022-10-12 22:58:01 +020088
89func (s *Veths2Suite) TestVclRetryAttach() {
Filip Tehlar468d7872022-11-11 10:37:33 +010090 s.T().Skip()
Maros Ondrejicka0db15752022-10-12 22:58:01 +020091 s.testRetryAttach("tcp")
92}
93
94func (s *Veths2Suite) testRetryAttach(proto string) {
95 t := s.T()
96
97 exechelper.Run("docker volume create --name=echo-srv-vol")
98 exechelper.Run("docker volume create --name=echo-cln-vol")
99
100 srvInstance := "vpp-vcl-test-srv"
101 clnInstance := "vpp-vcl-test-cln"
102 echoSrv := "echo-srv"
103 echoCln := "echo-cln"
104
105 err := dockerRun(srvInstance, "-v echo-srv-vol:/tmp/2veths")
106 if err != nil {
107 t.Errorf("%v", err)
108 return
109 }
110 defer func() { exechelper.Run("docker stop " + srvInstance) }()
111
112 err = dockerRun(clnInstance, "-v echo-cln-vol:/tmp/2veths")
113 if err != nil {
114 t.Errorf("%v", err)
115 return
116 }
117 defer func() { exechelper.Run("docker stop " + clnInstance) }()
118
119 err = dockerRun(echoSrv, fmt.Sprintf("-v echo-srv-vol:/tmp/%s", echoSrv))
120 if err != nil {
121 t.Errorf("%v", err)
122 return
123 }
124 defer func() { exechelper.Run("docker stop " + echoSrv) }()
125
126 err = dockerRun(echoCln, fmt.Sprintf("-v echo-cln-vol:/tmp/%s", echoCln))
127 if err != nil {
128 t.Errorf("%v", err)
129 return
130 }
131 defer func() { exechelper.Run("docker stop " + echoCln) }()
132
133 _, err = hstExec("2veths srv-with-preset-hw-addr", srvInstance)
134 if err != nil {
135 t.Errorf("%v", err)
136 return
137 }
138
139 _, err = hstExec("2veths cln", clnInstance)
140 if err != nil {
141 t.Errorf("%v", err)
142 return
143 }
144
145 _, err = hstExec("vcl-test-server "+proto, echoSrv)
146 if err != nil {
147 t.Errorf("vcl test server: %v", err)
148 return
149 }
150
151 fmt.Println("This whole test case can take around 3 minutes to run. Please be patient.")
152 fmt.Println("... Running first echo client test, before disconnect.")
153 _, err = hstExec("vcl-test-client "+proto, echoCln)
154 if err != nil {
155 t.Errorf("vcl test client: %v", err)
156 return
157 }
158 fmt.Println("... First test ended. Stopping VPP server now.")
159
160 // Stop server-vpp-instance, start it again and then run vcl-test-client once more
161 stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'"
162 _, err = dockerExec(stopVppCommand, srvInstance)
163 if err != nil {
164 t.Errorf("error while stopping vpp: %v", err)
165 return
166 }
167 time.Sleep(5 * time.Second) // Give parent process time to reap the killed child process
168 stopVppCommand = "/bin/bash -c 'ps -C hs-test -o pid= | xargs kill -9'"
169 _, err = dockerExec(stopVppCommand, srvInstance)
170 if err != nil {
171 t.Errorf("error while stopping hs-test: %v", err)
172 return
173 }
174 _, err = hstExec("2veths srv-with-preset-hw-addr", srvInstance)
175 if err != nil {
176 t.Errorf("%v", err)
177 return
178 }
179
180 fmt.Println("... VPP server is starting again, so waiting for a bit.")
181 time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
182
183 fmt.Println("... Running second echo client test, after disconnect and re-attachment.")
184 _, err = hstExec("vcl-test-client "+proto, echoCln)
185 if err != nil {
186 t.Errorf("vcl test client: %v", err)
187 }
188 fmt.Println("Done.")
189}