4921df1365c2d1b233d8d42438337d7d9b49a348
[one.git] / tests / data_plane / vpp_lite_topo / scripts / port_flood.py
1 #/usr/bin/env python
2
3 import sys
4 import socket
5
6
7 def do_flood(host, num):
8   try:
9     socket.inet_aton(host)
10     is_ip4 = True
11   except socket.error:
12     try:
13       socket.inet_pton(socket.AF_INET6, host)
14       is_ip4 = False
15     except socket.error:
16         raise Exception('Invlid ip4/6 address!')
17
18   family = socket.AF_INET if is_ip4 else socket.AF_INET6
19
20   for port in range(num):
21     sock = socket.socket(family, socket.SOCK_DGRAM)
22     sock.sendto('test', (host, port + 1))
23
24
25 if __name__ == '__main__':
26   if len(sys.argv) < 2:
27     raise Exception('IP and packet count expected!')
28   do_flood(sys.argv[1], int(sys.argv[2]))