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 | |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 7 | ) |
| 8 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 9 | func (s *VethsSuite) TestVclEchoQuic() { |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 10 | s.T().Skip("quic test skipping..") |
| 11 | s.testVclEcho("quic") |
| 12 | } |
| 13 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 14 | func (s *VethsSuite) TestVclEchoUdp() { |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 15 | s.T().Skip("udp echo currently broken in vpp, skipping..") |
| 16 | s.testVclEcho("udp") |
| 17 | } |
| 18 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 19 | func (s *VethsSuite) TestVclEchoTcp() { |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 20 | s.testVclEcho("tcp") |
| 21 | } |
| 22 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 23 | func (s *VethsSuite) testVclEcho(proto string) { |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 24 | serverVolume := "echo-srv-vol" |
| 25 | s.NewVolume(serverVolume) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 26 | |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 27 | clientVolume := "echo-cln-vol" |
| 28 | s.NewVolume(clientVolume) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 29 | |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 30 | srvInstance := "vpp-vcl-test-srv" |
| 31 | serverVppContainer, err := s.NewContainer(srvInstance) |
| 32 | s.assertNil(err) |
| 33 | serverVppContainer.addVolume(serverVolume, "/tmp/Configure2Veths") |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 34 | s.assertNil(serverVppContainer.run()) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 35 | |
| 36 | clnInstance := "vpp-vcl-test-cln" |
| 37 | clientVppContainer, err := s.NewContainer(clnInstance) |
| 38 | s.assertNil(err) |
| 39 | clientVppContainer.addVolume(clientVolume, "/tmp/Configure2Veths") |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 40 | s.assertNil(clientVppContainer.run()) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 41 | |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 42 | echoSrv := "echo-srv" |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 43 | serverEchoContainer, err := s.NewContainer(echoSrv) |
| 44 | s.assertNil(err) |
| 45 | serverEchoContainer.addVolume(serverVolume, "/tmp/" + echoSrv) |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 46 | s.assertNil(serverEchoContainer.run()) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 47 | |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 48 | echoCln := "echo-cln" |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 49 | clientEchoContainer, err := s.NewContainer(echoCln) |
| 50 | s.assertNil(err) |
| 51 | clientEchoContainer.addVolume(clientVolume, "/tmp/" + echoCln) |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 52 | s.assertNil(clientEchoContainer.run()) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 53 | |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 54 | _, err = hstExec("Configure2Veths srv", srvInstance) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 55 | s.assertNil(err) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 56 | |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 57 | _, err = hstExec("Configure2Veths cln", clnInstance) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 58 | s.assertNil(err) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 59 | |
| 60 | // run server app |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 61 | _, err = hstExec("RunEchoServer "+proto, echoSrv) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 62 | s.assertNil(err) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 63 | |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 64 | o, err := hstExec("RunEchoClient "+proto, echoCln) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 65 | s.assertNil(err) |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 66 | |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 67 | fmt.Println(o) |
| 68 | } |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 69 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 70 | func (s *VethsSuite) TestVclRetryAttach() { |
Filip Tehlar | 468d787 | 2022-11-11 10:37:33 +0100 | [diff] [blame] | 71 | s.T().Skip() |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 72 | s.testRetryAttach("tcp") |
| 73 | } |
| 74 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 75 | func (s *VethsSuite) testRetryAttach(proto string) { |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 76 | serverVolume := "echo-srv-vol" |
| 77 | s.NewVolume(serverVolume) |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 78 | |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 79 | clientVolume := "echo-cln-vol" |
| 80 | s.NewVolume(clientVolume) |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 81 | |
| 82 | srvInstance := "vpp-vcl-test-srv" |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 83 | serverVppContainer, err := s.NewContainer(srvInstance) |
| 84 | s.assertNil(err) |
| 85 | serverVppContainer.addVolume(serverVolume, "/tmp/Configure2Veths") |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 86 | s.assertNil(serverVppContainer.run()) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 87 | |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 88 | clnInstance := "vpp-vcl-test-cln" |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 89 | clientVppContainer, err := s.NewContainer(clnInstance) |
| 90 | s.assertNil(err) |
| 91 | clientVppContainer.addVolume(clientVolume, "/tmp/Configure2Veths") |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 92 | s.assertNil(clientVppContainer.run()) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 93 | |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 94 | echoSrv := "echo-srv" |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 95 | serverEchoContainer, err := s.NewContainer(echoSrv) |
| 96 | s.assertNil(err) |
| 97 | serverEchoContainer.addVolume(serverVolume, "/tmp/" + echoSrv) |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 98 | s.assertNil(serverEchoContainer.run()) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 99 | |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 100 | echoCln := "echo-cln" |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 101 | clientEchoContainer, err := s.NewContainer(echoCln) |
| 102 | s.assertNil(err) |
| 103 | clientEchoContainer.addVolume(clientVolume, "/tmp/" + echoCln) |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 104 | s.assertNil(clientEchoContainer.run()) |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 105 | |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 106 | _, err = hstExec("Configure2Veths srv-with-preset-hw-addr", srvInstance) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 107 | s.assertNil(err) |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 108 | |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 109 | _, err = hstExec("Configure2Veths cln", clnInstance) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 110 | s.assertNil(err) |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 111 | |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 112 | _, err = hstExec("RunVclEchoServer "+proto, echoSrv) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 113 | s.assertNil(err) |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 114 | |
| 115 | fmt.Println("This whole test case can take around 3 minutes to run. Please be patient.") |
| 116 | fmt.Println("... Running first echo client test, before disconnect.") |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 117 | _, err = hstExec("RunVclEchoClient "+proto, echoCln) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 118 | s.assertNil(err) |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 119 | fmt.Println("... First test ended. Stopping VPP server now.") |
| 120 | |
| 121 | // Stop server-vpp-instance, start it again and then run vcl-test-client once more |
| 122 | stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'" |
| 123 | _, err = dockerExec(stopVppCommand, srvInstance) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 124 | s.assertNil(err) |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 125 | time.Sleep(5 * time.Second) // Give parent process time to reap the killed child process |
| 126 | stopVppCommand = "/bin/bash -c 'ps -C hs-test -o pid= | xargs kill -9'" |
| 127 | _, err = dockerExec(stopVppCommand, srvInstance) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 128 | s.assertNil(err) |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 129 | _, err = hstExec("Configure2Veths srv-with-preset-hw-addr", srvInstance) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 130 | s.assertNil(err) |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 131 | |
| 132 | fmt.Println("... VPP server is starting again, so waiting for a bit.") |
| 133 | time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen |
| 134 | |
| 135 | fmt.Println("... Running second echo client test, after disconnect and re-attachment.") |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 136 | _, err = hstExec("RunVclEchoClient "+proto, echoCln) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 137 | s.assertNil(err) |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 138 | fmt.Println("Done.") |
| 139 | } |
Maros Ondrejicka | 5b74631 | 2022-11-16 12:51:11 +0100 | [diff] [blame] | 140 | |
| 141 | func (s *VethsSuite) TestTcpWithLoss() { |
| 142 | serverContainer, err := s.NewContainer("server") |
| 143 | s.assertNil(err, "creating container failed") |
| 144 | err = serverContainer.run() |
| 145 | s.assertNil(err) |
| 146 | |
| 147 | serverVpp := NewVppInstance(serverContainer) |
| 148 | s.assertNotNil(serverVpp) |
| 149 | serverVpp.setCliSocket("/var/run/vpp/cli.sock") |
| 150 | serverVpp.set2VethsServer() |
| 151 | err = serverVpp.start() |
| 152 | s.assertNil(err, "starting VPP failed") |
| 153 | |
| 154 | _, err = serverVpp.vppctl("test echo server uri tcp://10.10.10.1/20022") |
| 155 | s.assertNil(err, "starting echo server failed") |
| 156 | |
| 157 | clientContainer, err := s.NewContainer("client") |
| 158 | s.assertNil(err, "creating container failed") |
| 159 | err = clientContainer.run() |
| 160 | s.assertNil(err, "starting container failed") |
| 161 | |
| 162 | clientVpp := NewVppInstance(clientContainer) |
| 163 | s.assertNotNil(clientVpp) |
| 164 | clientVpp.setCliSocket("/var/run/vpp/cli.sock") |
| 165 | clientVpp.set2VethsClient() |
| 166 | err = clientVpp.start() |
| 167 | s.assertNil(err, "starting VPP failed") |
| 168 | |
| 169 | // Ensure that VPP doesn't abort itself with NSIM enabled |
| 170 | // Warning: Removing this ping will make the test fail! |
| 171 | _, err = serverVpp.vppctl("ping 10.10.10.2") |
| 172 | s.assertNil(err, "ping failed") |
| 173 | |
| 174 | // Add loss of packets with Network Delay Simulator |
| 175 | _, err = clientVpp.vppctl("set nsim poll-main-thread delay 0.01 ms bandwidth 40 gbit packet-size 1400 packets-per-drop 1000") |
| 176 | s.assertNil(err, "configuring NSIM failed") |
| 177 | _, err = clientVpp.vppctl("nsim output-feature enable-disable host-vppcln") |
| 178 | s.assertNil(err, "enabling NSIM failed") |
| 179 | |
| 180 | // Do echo test from client-vpp container |
| 181 | output, err := clientVpp.vppctl("test echo client uri tcp://10.10.10.1/20022 mbytes 50") |
| 182 | s.assertNil(err) |
| 183 | s.assertEqual(true, len(output) != 0) |
| 184 | s.assertNotContains(output, "failed: timeout") |
| 185 | fmt.Println(output) |
| 186 | } |