blob: f699a65295c0cead419e9265b97e046efbd51ce3 [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
Filip Tehlar1a9dc752022-11-22 12:49:22 +010035 err := dockerRun(srvInstance, "-v echo-srv-vol:/tmp/Configure2Veths")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000036 if err != nil {
37 t.Errorf("%v", err)
38 return
39 }
40 defer func() { exechelper.Run("docker stop " + srvInstance) }()
41
Filip Tehlar1a9dc752022-11-22 12:49:22 +010042 err = dockerRun(clnInstance, "-v echo-cln-vol:/tmp/Configure2Veths")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000043 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
Filip Tehlar1a9dc752022-11-22 12:49:22 +010063 _, err = hstExec("Configure2Veths srv", srvInstance)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000064 if err != nil {
65 t.Errorf("%v", err)
66 return
67 }
68
Filip Tehlar1a9dc752022-11-22 12:49:22 +010069 _, err = hstExec("Configure2Veths cln", clnInstance)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000070 if err != nil {
71 t.Errorf("%v", err)
72 return
73 }
74
75 // run server app
Filip Tehlar1a9dc752022-11-22 12:49:22 +010076 _, err = hstExec("RunEchoServer "+proto, echoSrv)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000077 if err != nil {
78 t.Errorf("echo server: %v", err)
79 return
80 }
81
Filip Tehlar1a9dc752022-11-22 12:49:22 +010082 o, err := hstExec("RunEchoClient "+proto, echoCln)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000083 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
Filip Tehlar1a9dc752022-11-22 12:49:22 +0100105 err := dockerRun(srvInstance, "-v echo-srv-vol:/tmp/Configure2Veths")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200106 if err != nil {
107 t.Errorf("%v", err)
108 return
109 }
110 defer func() { exechelper.Run("docker stop " + srvInstance) }()
111
Filip Tehlar1a9dc752022-11-22 12:49:22 +0100112 err = dockerRun(clnInstance, "-v echo-cln-vol:/tmp/Configure2Veths")
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200113 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
Filip Tehlar1a9dc752022-11-22 12:49:22 +0100133 _, err = hstExec("Configure2Veths srv-with-preset-hw-addr", srvInstance)
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200134 if err != nil {
135 t.Errorf("%v", err)
136 return
137 }
138
Filip Tehlar1a9dc752022-11-22 12:49:22 +0100139 _, err = hstExec("Configure2Veths cln", clnInstance)
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200140 if err != nil {
141 t.Errorf("%v", err)
142 return
143 }
144
Filip Tehlar1a9dc752022-11-22 12:49:22 +0100145 _, err = hstExec("RunVclEchoServer "+proto, echoSrv)
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200146 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.")
Filip Tehlar1a9dc752022-11-22 12:49:22 +0100153 _, err = hstExec("RunVclEchoClient "+proto, echoCln)
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200154 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 }
Filip Tehlar1a9dc752022-11-22 12:49:22 +0100174 _, err = hstExec("Configure2Veths srv-with-preset-hw-addr", srvInstance)
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200175 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.")
Filip Tehlar1a9dc752022-11-22 12:49:22 +0100184 _, err = hstExec("RunVclEchoClient "+proto, echoCln)
Maros Ondrejicka0db15752022-10-12 22:58:01 +0200185 if err != nil {
186 t.Errorf("vcl test client: %v", err)
187 }
188 fmt.Println("Done.")
189}