Skip to content

Commit

Permalink
tc-testing: add support for sending various scapy packets
Browse files Browse the repository at this point in the history
It can be worth sending different scapy packets on a given test, as in the
last patch of this series. For that, lets listify the scapy attribute and
simply iterate over it.

Signed-off-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Marcelo Ricardo Leitner authored and David S. Miller committed Jun 22, 2021
1 parent b4fd096 commit 11f04de
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions tools/testing/selftests/tc-testing/plugin-lib/scapyPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,26 @@ def post_execute(self):
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.append(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'])
lscapyinfo = self.args.caseinfo['scapy']
if type(lscapyinfo) != list:
lscapyinfo = [ lscapyinfo, ]

for scapyinfo in lscapyinfo:
scapy_keys = ['iface', 'count', 'packet']
missing_keys = []
keyfail = False
for k in scapy_keys:
if k not in scapyinfo:
keyfail = True
missing_keys.append(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'])

0 comments on commit 11f04de

Please sign in to comment.