Commit 11f04de9 authored by Marcelo Ricardo Leitner's avatar Marcelo Ricardo Leitner Committed by David S. Miller

tc-testing: add support for sending various scapy packets

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: default avatarMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b4fd096c
...@@ -29,22 +29,26 @@ class SubPlugin(TdcPlugin): ...@@ -29,22 +29,26 @@ class SubPlugin(TdcPlugin):
return return
# Check for required fields # Check for required fields
scapyinfo = self.args.caseinfo['scapy'] lscapyinfo = self.args.caseinfo['scapy']
scapy_keys = ['iface', 'count', 'packet'] if type(lscapyinfo) != list:
missing_keys = [] lscapyinfo = [ lscapyinfo, ]
keyfail = False
for k in scapy_keys: for scapyinfo in lscapyinfo:
if k not in scapyinfo: scapy_keys = ['iface', 'count', 'packet']
keyfail = True missing_keys = []
missing_keys.append(k) keyfail = False
if keyfail: for k in scapy_keys:
print('{}: Scapy block present in the test, but is missing info:' if k not in scapyinfo:
.format(self.sub_class)) keyfail = True
print('{}'.format(missing_keys)) missing_keys.append(k)
if keyfail:
pkt = eval(scapyinfo['packet']) print('{}: Scapy block present in the test, but is missing info:'
if '$' in scapyinfo['iface']: .format(self.sub_class))
tpl = Template(scapyinfo['iface']) print('{}'.format(missing_keys))
scapyinfo['iface'] = tpl.safe_substitute(NAMES)
for count in range(scapyinfo['count']): pkt = eval(scapyinfo['packet'])
sendp(pkt, iface=scapyinfo['iface']) 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'])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment