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