summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/pnat/tests/test_genpackets.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/nat/pnat/tests/test_genpackets.py')
-rwxr-xr-xsrc/plugins/nat/pnat/tests/test_genpackets.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/plugins/nat/pnat/tests/test_genpackets.py b/src/plugins/nat/pnat/tests/test_genpackets.py
new file mode 100755
index 00000000000..9d32d3e3656
--- /dev/null
+++ b/src/plugins/nat/pnat/tests/test_genpackets.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+
+import sys
+import os
+from importlib.machinery import SourceFileLoader
+from scapy.all import *
+from scapy.contrib.geneve import GENEVE
+
+def hexstring(p):
+ s = bytes(p.__class__(p))
+ return ",".join("0x{:02x}".format(c) for c in s)
+
+def output_test(filename, tests):
+ (name, ext) = os.path.basename(filename).split(".")
+ print('/* DO NOT EDIT: automatically generated by test_genpackets.py */')
+ print('/* clang-format off */')
+ print('test_t tests_{}[] = {{'.format(name))
+
+ for t in tests:
+ print(' {')
+ print(' .name = "{}",'.format(t[0]))
+ print(' .nsend = {},'.format(len(t[1])))
+ print(' .send = (char []){{{}}},'.format(hexstring(t[1])))
+ print(' .nexpect = {},'.format(len(t[2])))
+ print(' .expect = (char []){{{}}},'.format(hexstring(t[2])))
+ print(' .expect_next_index = {}'.format(t[3]))
+ print(' },')
+ print('};')
+ print('/* clang-format on */')
+
+# Read tests from file
+for filename in sys.argv[1:]:
+ with open(filename) as f:
+ content = f.read().replace('\n', '')
+
+ tests = eval(content)
+ output_test(filename, tests)
+