Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 5 | "time" |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 6 | |
| 7 | "github.com/edwarnicke/exechelper" |
| 8 | ) |
| 9 | |
| 10 | func (s *Veths2Suite) TestVclEchoQuic() { |
| 11 | s.T().Skip("quic test skipping..") |
| 12 | s.testVclEcho("quic") |
| 13 | } |
| 14 | |
| 15 | func (s *Veths2Suite) TestVclEchoUdp() { |
| 16 | s.T().Skip("udp echo currently broken in vpp, skipping..") |
| 17 | s.testVclEcho("udp") |
| 18 | } |
| 19 | |
| 20 | func (s *Veths2Suite) TestVclEchoTcp() { |
| 21 | s.testVclEcho("tcp") |
| 22 | } |
| 23 | |
| 24 | func (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 Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 35 | err := dockerRun(srvInstance, "-v echo-srv-vol:/tmp/Configure2Veths") |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 36 | if err != nil { |
| 37 | t.Errorf("%v", err) |
| 38 | return |
| 39 | } |
| 40 | defer func() { exechelper.Run("docker stop " + srvInstance) }() |
| 41 | |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 42 | err = dockerRun(clnInstance, "-v echo-cln-vol:/tmp/Configure2Veths") |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 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 | |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 63 | _, err = hstExec("Configure2Veths srv", srvInstance) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 64 | if err != nil { |
| 65 | t.Errorf("%v", err) |
| 66 | return |
| 67 | } |
| 68 | |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 69 | _, err = hstExec("Configure2Veths cln", clnInstance) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 70 | if err != nil { |
| 71 | t.Errorf("%v", err) |
| 72 | return |
| 73 | } |
| 74 | |
| 75 | // run server app |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 76 | _, err = hstExec("RunEchoServer "+proto, echoSrv) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 77 | if err != nil { |
| 78 | t.Errorf("echo server: %v", err) |
| 79 | return |
| 80 | } |
| 81 | |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 82 | o, err := hstExec("RunEchoClient "+proto, echoCln) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 83 | if err != nil { |
| 84 | t.Errorf("echo client: %v", err) |
| 85 | } |
| 86 | fmt.Println(o) |
| 87 | } |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 88 | |
| 89 | func (s *Veths2Suite) TestVclRetryAttach() { |
Filip Tehlar | 468d787 | 2022-11-11 10:37:33 +0100 | [diff] [blame] | 90 | s.T().Skip() |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 91 | s.testRetryAttach("tcp") |
| 92 | } |
| 93 | |
| 94 | func (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 Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 105 | err := dockerRun(srvInstance, "-v echo-srv-vol:/tmp/Configure2Veths") |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 106 | if err != nil { |
| 107 | t.Errorf("%v", err) |
| 108 | return |
| 109 | } |
| 110 | defer func() { exechelper.Run("docker stop " + srvInstance) }() |
| 111 | |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 112 | err = dockerRun(clnInstance, "-v echo-cln-vol:/tmp/Configure2Veths") |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 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 | |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 133 | _, err = hstExec("Configure2Veths srv-with-preset-hw-addr", srvInstance) |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 134 | if err != nil { |
| 135 | t.Errorf("%v", err) |
| 136 | return |
| 137 | } |
| 138 | |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 139 | _, err = hstExec("Configure2Veths cln", clnInstance) |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 140 | if err != nil { |
| 141 | t.Errorf("%v", err) |
| 142 | return |
| 143 | } |
| 144 | |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 145 | _, err = hstExec("RunVclEchoServer "+proto, echoSrv) |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 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.") |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 153 | _, err = hstExec("RunVclEchoClient "+proto, echoCln) |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 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 | } |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 174 | _, err = hstExec("Configure2Veths srv-with-preset-hw-addr", srvInstance) |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 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.") |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 184 | _, err = hstExec("RunVclEchoClient "+proto, echoCln) |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 185 | if err != nil { |
| 186 | t.Errorf("vcl test client: %v", err) |
| 187 | } |
| 188 | fmt.Println("Done.") |
| 189 | } |