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