blob: 8b045bfe131ae545da7a3d862bc7b6b8a35490f6 [file] [log] [blame]
Dave Barach82192ca2020-04-24 09:43:14 -04001#!/usr/bin/env python3
2
3import unittest
4
5from framework import VppTestCase, VppTestRunner, running_gcov_tests
6from vpp_ip_route import VppIpTable, VppIpRoute, VppRoutePath
7
8
9class TestOffload(VppTestCase):
10 """ Offload Unit Test Cases """
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):
27 """ Checksum Offload Test """
28 cmds = ["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-ip-cksum offload-udp-cksum\n"
43 " data {\n"
44 " IP4: 1.2.3 -> dead.0000.0001\n"
45 " UDP: 11.22.33.44 -> 11.22.34.44\n"
46 " ttl 2 checksum 13\n"
47 " UDP: 1234 -> 2345\n"
48 " checksum 11\n"
49 " incrementing 114\n"
50 " }\n"
51 "}",
52 "trace add pg-input 1",
53 "pa en",
54 "show error"]
55
56 for cmd in cmds:
57 r = self.vapi.cli_return_response(cmd)
58 if r.retval != 0:
59 if hasattr(r, 'reply'):
60 self.logger.info(cmd + " FAIL reply " + r.reply)
61 else:
62 self.logger.info(cmd + " FAIL retval " + str(r.retval))
63
64 r = self.vapi.cli_return_response("show trace")
65 self.assertTrue(r.retval == 0)
66 self.assertTrue(hasattr(r, 'reply'))
67 rv = r.reply
68 look_here = rv.find('ethernet-input')
69 self.assertFalse(look_here == -1)
70 bad_checksum_index = rv[look_here:].find('should be')
71 self.assertTrue(bad_checksum_index == -1)
72
73if __name__ == '__main__':
74 unittest.main(testRunner=VppTestRunner)