nat: pnat copy and clear byte instructions
[vpp.git] / src / plugins / nat / pnat / tests / test_genpackets.py
1 #!/usr/bin/env python3
2
3 import sys
4 import os
5 from importlib.machinery import SourceFileLoader
6 from scapy.all import *
7 from scapy.contrib.geneve import GENEVE
8
9 def hexstring(p):
10     s = bytes(p.__class__(p))
11     return ",".join("0x{:02x}".format(c) for c in s)
12
13 def output_test(filename, tests):
14     (name, ext) = os.path.basename(filename).split(".")
15     print('/* DO NOT EDIT: automatically generated by test_genpackets.py */')
16     print('/* clang-format off */')
17     print('test_t tests_{}[] = {{'.format(name))
18
19     for t in tests:
20         print('  {')
21         print('    .name = "{}",'.format(t[0]))
22         print('    .nsend = {},'.format(len(t[1])))
23         print('    .send = (char []){{{}}},'.format(hexstring(t[1])))
24         print('    .nexpect = {},'.format(len(t[2])))
25         print('    .expect = (char []){{{}}},'.format(hexstring(t[2])))
26         print('    .expect_next_index = {}'.format(t[3]))
27         print('  },')
28     print('};')
29     print('/* clang-format on */')
30
31 # Read tests from file
32 for filename in sys.argv[1:]:
33     with open(filename) as f:
34         content = f.read().replace('\n', '')
35
36     tests = eval(content)
37     output_test(filename, tests)
38