Dave Barach | 82192ca | 2020-04-24 09:43:14 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | import unittest |
| 4 | |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 5 | from asfframework import VppAsfTestCase, VppTestRunner |
Dave Barach | 82192ca | 2020-04-24 09:43:14 -0400 | [diff] [blame] | 6 | |
| 7 | |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 8 | class TestOffload(VppAsfTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 9 | """Offload Unit Test Cases""" |
Dave Barach | 82192ca | 2020-04-24 09:43:14 -0400 | [diff] [blame] | 10 | |
| 11 | @classmethod |
| 12 | def setUpClass(cls): |
| 13 | super(TestOffload, cls).setUpClass() |
| 14 | |
| 15 | @classmethod |
| 16 | def tearDownClass(cls): |
| 17 | super(TestOffload, cls).tearDownClass() |
| 18 | |
| 19 | def setUp(self): |
| 20 | super(TestOffload, self).setUp() |
| 21 | |
| 22 | def tearDown(self): |
| 23 | super(TestOffload, self).tearDown() |
| 24 | |
| 25 | def test_offload_unittest(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 26 | """Checksum Offload Test""" |
| 27 | cmds = [ |
| 28 | "loop create", |
| 29 | "set int ip address loop0 11.22.33.1/24", |
| 30 | "set int state loop0 up", |
| 31 | "loop create", |
| 32 | "set int ip address loop1 11.22.34.1/24", |
| 33 | "set int state loop1 up", |
| 34 | "set ip neighbor loop1 11.22.34.44 03:00:11:22:34:44", |
| 35 | "packet-generator new {\n" |
| 36 | " name s0\n" |
| 37 | " limit 100\n" |
| 38 | " size 128-128\n" |
| 39 | " interface loop0\n" |
| 40 | " tx-interface loop1\n" |
| 41 | " node loop1-output\n" |
| 42 | " buffer-flags ip4 offload\n" |
| 43 | " buffer-offload-flags offload-ip-cksum offload-udp-cksum\n" |
| 44 | " data {\n" |
| 45 | " IP4: 1.2.3 -> dead.0000.0001\n" |
| 46 | " UDP: 11.22.33.44 -> 11.22.34.44\n" |
| 47 | " ttl 2 checksum 13\n" |
| 48 | " UDP: 1234 -> 2345\n" |
| 49 | " checksum 11\n" |
| 50 | " incrementing 114\n" |
| 51 | " }\n" |
| 52 | "}", |
| 53 | "trace add pg-input 1", |
| 54 | "pa en", |
| 55 | "show error", |
| 56 | ] |
Dave Barach | 82192ca | 2020-04-24 09:43:14 -0400 | [diff] [blame] | 57 | |
| 58 | for cmd in cmds: |
| 59 | r = self.vapi.cli_return_response(cmd) |
| 60 | if r.retval != 0: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 61 | if hasattr(r, "reply"): |
Dave Barach | 82192ca | 2020-04-24 09:43:14 -0400 | [diff] [blame] | 62 | self.logger.info(cmd + " FAIL reply " + r.reply) |
| 63 | else: |
| 64 | self.logger.info(cmd + " FAIL retval " + str(r.retval)) |
| 65 | |
| 66 | r = self.vapi.cli_return_response("show trace") |
| 67 | self.assertTrue(r.retval == 0) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 68 | self.assertTrue(hasattr(r, "reply")) |
Dave Barach | 82192ca | 2020-04-24 09:43:14 -0400 | [diff] [blame] | 69 | rv = r.reply |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 70 | look_here = rv.find("ethernet-input") |
Dave Barach | 82192ca | 2020-04-24 09:43:14 -0400 | [diff] [blame] | 71 | self.assertFalse(look_here == -1) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 72 | bad_checksum_index = rv[look_here:].find("should be") |
Dave Barach | 82192ca | 2020-04-24 09:43:14 -0400 | [diff] [blame] | 73 | self.assertTrue(bad_checksum_index == -1) |
| 74 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 75 | |
| 76 | if __name__ == "__main__": |
Dave Barach | 82192ca | 2020-04-24 09:43:14 -0400 | [diff] [blame] | 77 | unittest.main(testRunner=VppTestRunner) |