Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Marcelo Ricardo Leitner and committed by
David S. Miller
11f04de9 b4fd096c

+22 -18
+22 -18
tools/testing/selftests/tc-testing/plugin-lib/scapyPlugin.py
··· 29 29 return 30 30 31 31 # Check for required fields 32 - scapyinfo = self.args.caseinfo['scapy'] 33 - scapy_keys = ['iface', 'count', 'packet'] 34 - missing_keys = [] 35 - keyfail = False 36 - for k in scapy_keys: 37 - if k not in scapyinfo: 38 - keyfail = True 39 - missing_keys.append(k) 40 - if keyfail: 41 - print('{}: Scapy block present in the test, but is missing info:' 42 - .format(self.sub_class)) 43 - print('{}'.format(missing_keys)) 32 + lscapyinfo = self.args.caseinfo['scapy'] 33 + if type(lscapyinfo) != list: 34 + lscapyinfo = [ lscapyinfo, ] 44 35 45 - pkt = eval(scapyinfo['packet']) 46 - if '$' in scapyinfo['iface']: 47 - tpl = Template(scapyinfo['iface']) 48 - scapyinfo['iface'] = tpl.safe_substitute(NAMES) 49 - for count in range(scapyinfo['count']): 50 - sendp(pkt, iface=scapyinfo['iface']) 36 + for scapyinfo in lscapyinfo: 37 + scapy_keys = ['iface', 'count', 'packet'] 38 + missing_keys = [] 39 + keyfail = False 40 + for k in scapy_keys: 41 + if k not in scapyinfo: 42 + keyfail = True 43 + missing_keys.append(k) 44 + if keyfail: 45 + print('{}: Scapy block present in the test, but is missing info:' 46 + .format(self.sub_class)) 47 + print('{}'.format(missing_keys)) 48 + 49 + pkt = eval(scapyinfo['packet']) 50 + if '$' in scapyinfo['iface']: 51 + tpl = Template(scapyinfo['iface']) 52 + scapyinfo['iface'] = tpl.safe_substitute(NAMES) 53 + for count in range(scapyinfo['count']): 54 + sendp(pkt, iface=scapyinfo['iface'])