tc-testing: Scapy plugin and JSON verification for tdc
Subsystems (4)
RFC PATCH 1/1 tc-testing: Scapy plugin and JSON verification for tdc
This is a draft version of two new tdc features.
First, the scapy plugin. This requires the scapy Python module installed on the system (plugin was tested against v2.4.2). The intent is to install a given rule (as the command under test) and then generate packets to create statistics for that rule. The stats are checked in the verify phase.
A new "scapy" entry appears in the test cases, which currently have three requirements: the source interface for the packets, the number of packets to be sent, and a string that is processed by scapy's eval() function to construct the packets.
Limitations: For now, only one type of packet can be crafted per test case. Also, knowledge of scapy's syntax is required.
Secondly, we add JSON processing as a method of performing the verification stage. Each test case can now have a "matchPattern" or "matchJSON" field which governs the method tdc will use to process the results. The intent is to make it easier to handle the verify stage by not requiring complex regular expressions
matchJSON has two fields, path and value. Path is a list of strings and integers which indicate the path through the nested JSON data - an asterisk is also acceptable in place of a number if the specific index of a list is unknown.
This structure may not be the best method of handling JSON verification - suggestions have been made that include using a third party module to process the JSON, but that creates an external dependency for tdc.
To try the sample tests in this patch:
1) Ensure nsPlugin and scapyPlugin are linked in the plugins/ subdirectory
2) Run:
sudo ./tdc.py -f tc-tests/actions/scapy-example.json -n
The second test is designed to fail.
Comments and discussion are encouraged!
--- tools/testing/selftests/tc-testing/TdcPlugin.py | 5 +- .../selftests/tc-testing/plugin-lib/scapyPlugin.py | 49 +++++++ .../tc-testing/tc-tests/actions/scapy-example.json | 86 ++++++++++++ tools/testing/selftests/tc-testing/tdc.py | 149 ++++++++++++++++++--- 4 files changed, 268 insertions(+), 21 deletions(-) create mode 100644 tools/testing/selftests/tc-testing/plugin-lib/scapyPlugin.py create mode 100644 tools/testing/selftests/tc-testing/tc-tests/actions/scapy-example.json
tools/testing/selftests/tc-testing/TdcPlugin.py +2 -3
@@ -18,12 +18,11 @@ class TdcPlugin: if self.args.verbose > 1: print(' -- {}.post_suite'.format(self.sub_class)) - def pre_case(self, testid, test_name, test_skip): + def pre_case(self, caseinfo, test_skip): '''run commands before test_runner does one test''' if self.args.verbose > 1: print(' -- {}.pre_case'.format(self.sub_class)) - self.args.testid = testid - self.args.test_name = test_name + self.args.caseinfo = caseinfo self.args.test_skip = test_skip def post_case(self):
tools/testing/selftests/tc-testing/plugin-lib/scapyPlugin.py new file +49 -0
49 lines not on this page · raw message
tools/testing/selftests/tc-testing/tc-tests/actions/scapy-example.json new file +86 -0
86 lines not on this page · raw message
tools/testing/selftests/tc-testing/tdc.py +131 -18
199 lines not on this page · raw message
--
2.7.4
Hi Lucas,
Quoted 8 lines · Lucas Bates
This is a draft version of two new tdc features.
First, the scapy plugin. This requires the scapy Python module installed on the system (plugin was tested against v2.4.2). The intent is to install a given rule (as the command under test) and then generate packets to create statistics for that rule. The stats are checked in the verify phase.
Quoted 4 lines
A new "scapy" entry appears in the test cases, which currently have three requirements: the source interface for the packets, the number of packets to be sent, and a string that is processed by scapy's
eval()function to construct the packets.
eval() is not a function of scapy, it is a python thing.
You need to be careful with that, people can introduce weird code. Since everything is here under review I think it is okay... so far we don't introduce a tdc restful API for that.
Quoted 4 lines
Limitations: For now, only one type of packet can be crafted per test case. Also, knowledge of scapy's syntax is required.
Why not add a list of eval() strings and send them out in order?
Quoted 11 lines
Secondly, we add JSON processing as a method of performing the verification stage. Each test case can now have a "matchPattern" or "matchJSON" field which governs the method tdc will use to process the results. The intent is to make it easier to handle the verify stage by not requiring complex regular expressions
matchJSON has two fields, path and value. Path is a list of strings and integers which indicate the path through the nested JSON data - an asterisk is also acceptable in place of a number if the specific index of a list is unknown.
Can you provide an example?
Quoted 7 lines
This structure may not be the best method of handling JSON verification - suggestions have been made that include using a third party module to process the JSON, but that creates an external dependency for tdc.
To try the sample tests in this patch:
Quoted 8 lines
1) Ensure nsPlugin and scapyPlugin are linked in the plugins/ subdirectory
2) Run:
sudo ./tdc.py -ftc-tests/actions/scapy-example.json-nThe second test is designed to fail.
Comments and discussion are encouraged!
Can you please split these patches according to your commit message.
1. JSON processing (new core feature?)
2. scapy plugin (should not touch core code)
3. scapy example
- Alex