summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/pnat/tests/test_genpackets.py
diff options
context:
space:
mode:
authorAndrew Yourtchenko <ayourtch@gmail.com>2021-02-23 08:56:27 +0000
committerDamjan Marion <dmarion@me.com>2021-03-15 17:53:05 +0000
commitab3151c52e3686c629c79a6447cf9df4f73d5c6d (patch)
tree9ac5439beef669ad54fda1a6779b99b7e659a48b /src/plugins/nat/pnat/tests/test_genpackets.py
parent73d9c9da6a66ca8658f4ff2a0f8421f3d755cb95 (diff)
nat: pnat copy and clear byte instructions
Type: feature Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: I8e48bdcc4c311717e067bb0a4e0b409a2eb8e83d Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com> Signed-off-by: Ole Troan <ot@cisco.com>
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)
+