Fix multihoming tests
[one.git] / tests / data_plane / vpp_lite_topo / scripts / port_flood.py
diff --git a/tests/data_plane/vpp_lite_topo/scripts/port_flood.py b/tests/data_plane/vpp_lite_topo/scripts/port_flood.py
new file mode 100755 (executable)
index 0000000..4921df1
--- /dev/null
@@ -0,0 +1,28 @@
+#/usr/bin/env python
+
+import sys
+import socket
+
+
+def do_flood(host, num):
+  try:
+    socket.inet_aton(host)
+    is_ip4 = True
+  except socket.error:
+    try:
+      socket.inet_pton(socket.AF_INET6, host)
+      is_ip4 = False
+    except socket.error:
+        raise Exception('Invlid ip4/6 address!')
+
+  family = socket.AF_INET if is_ip4 else socket.AF_INET6
+
+  for port in range(num):
+    sock = socket.socket(family, socket.SOCK_DGRAM)
+    sock.sendto('test', (host, port + 1))
+
+
+if __name__ == '__main__':
+  if len(sys.argv) < 2:
+    raise Exception('IP and packet count expected!')
+  do_flood(sys.argv[1], int(sys.argv[2]))