-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'tc-testing-Add-plugin-for-simple-traffic-generation'
Lucas Bates says: ==================== tc-testing: Add plugin for simple traffic generation This series supersedes the previous submission that included a patch for test case verification using JSON output. It adds a new tdc plugin, scapyPlugin, as a way to send traffic to test tc filters and actions. The first patch makes a change to the TdcPlugin module that will allow tdc plugins to examine the test case currently being executed, so plugins can play a more active role in testing by accepting information or commands from the test case. This is required for scapyPlugin to work. The second patch adds scapyPlugin itself, and an example test case file to demonstrate how the scapy block works in the test cases. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
- Loading branch information
Showing
4 changed files
with
155 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
tools/testing/selftests/tc-testing/creating-testcases/scapy-example.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
[ | ||
{ | ||
"id": "b1e9", | ||
"name": "Test matching of source IP", | ||
"category": [ | ||
"actions", | ||
"scapy" | ||
], | ||
"plugins": { | ||
"requires": [ | ||
"nsPlugin", | ||
"scapyPlugin" | ||
] | ||
}, | ||
"setup": [ | ||
[ | ||
"$TC qdisc del dev $DEV1 ingress", | ||
0, | ||
1, | ||
2, | ||
255 | ||
], | ||
"$TC qdisc add dev $DEV1 ingress" | ||
], | ||
"cmdUnderTest": "$TC filter add dev $DEV1 parent ffff: prio 3 protocol ip flower src_ip 16.61.16.61 flowid 1:1 action ok", | ||
"scapy": { | ||
"iface": "$DEV0", | ||
"count": 1, | ||
"packet": "Ether(type=0x800)/IP(src='16.61.16.61')/ICMP()" | ||
}, | ||
"expExitCode": "0", | ||
"verifyCmd": "$TC -s -j filter ls dev $DEV1 ingress prio 3", | ||
"matchJSON": [ | ||
{ | ||
"path": [ | ||
1, | ||
"options", | ||
"actions", | ||
0, | ||
"stats", | ||
"packets" | ||
], | ||
"value": 1 | ||
} | ||
], | ||
"teardown": [ | ||
"$TC qdisc del dev $DEV1 ingress" | ||
] | ||
}, | ||
{ | ||
"id": "e9c4", | ||
"name": "Test matching of source IP with wrong count", | ||
"category": [ | ||
"actions", | ||
"scapy" | ||
], | ||
"plugins": { | ||
"requires": [ | ||
"nsPlugin", | ||
"scapyPlugin" | ||
] | ||
}, | ||
"setup": [ | ||
[ | ||
"$TC qdisc del dev $DEV1 ingress", | ||
0, | ||
1, | ||
2, | ||
255 | ||
], | ||
"$TC qdisc add dev $DEV1 ingress" | ||
], | ||
"cmdUnderTest": "$TC filter add dev $DEV1 parent ffff: prio 3 protocol ip flower src_ip 16.61.16.61 flowid 1:1 action ok", | ||
"scapy": { | ||
"iface": "$DEV0", | ||
"count": 3, | ||
"packet": "Ether(type=0x800)/IP(src='16.61.16.61')/ICMP()" | ||
}, | ||
"expExitCode": "0", | ||
"verifyCmd": "$TC -s -j filter ls dev $DEV1 parent ffff:", | ||
"matchJSON": [ | ||
{ | ||
"path": [ | ||
1, | ||
"options", | ||
"actions", | ||
0, | ||
"stats", | ||
"packets" | ||
], | ||
"value": 1 | ||
} | ||
], | ||
"teardown": [ | ||
"$TC qdisc del dev $DEV1 ingress" | ||
] | ||
} | ||
] |
50 changes: 50 additions & 0 deletions
50
tools/testing/selftests/tc-testing/plugin-lib/scapyPlugin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import signal | ||
from string import Template | ||
import subprocess | ||
import time | ||
from TdcPlugin import TdcPlugin | ||
|
||
from tdc_config import * | ||
|
||
try: | ||
from scapy.all import * | ||
except ImportError: | ||
print("Unable to import the scapy python module.") | ||
print("\nIf not already installed, you may do so with:") | ||
print("\t\tpip3 install scapy==2.4.2") | ||
exit(1) | ||
|
||
class SubPlugin(TdcPlugin): | ||
def __init__(self): | ||
self.sub_class = 'scapy/SubPlugin' | ||
super().__init__() | ||
|
||
def post_execute(self): | ||
if 'scapy' not in self.args.caseinfo: | ||
if self.args.verbose: | ||
print('{}.post_execute: no scapy info in test case'.format(self.sub_class)) | ||
return | ||
|
||
# Check for required fields | ||
scapyinfo = self.args.caseinfo['scapy'] | ||
scapy_keys = ['iface', 'count', 'packet'] | ||
missing_keys = [] | ||
keyfail = False | ||
for k in scapy_keys: | ||
if k not in scapyinfo: | ||
keyfail = True | ||
missing_keys.add(k) | ||
if keyfail: | ||
print('{}: Scapy block present in the test, but is missing info:' | ||
.format(self.sub_class)) | ||
print('{}'.format(missing_keys)) | ||
|
||
pkt = eval(scapyinfo['packet']) | ||
if '$' in scapyinfo['iface']: | ||
tpl = Template(scapyinfo['iface']) | ||
scapyinfo['iface'] = tpl.safe_substitute(NAMES) | ||
for count in range(scapyinfo['count']): | ||
sendp(pkt, iface=scapyinfo['iface']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters