summaryrefslogtreecommitdiffstats
path: root/tests/data_plane/vpp_lite_topo/scripts/dhcp_client.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/data_plane/vpp_lite_topo/scripts/dhcp_client.py')
-rw-r--r--tests/data_plane/vpp_lite_topo/scripts/dhcp_client.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/data_plane/vpp_lite_topo/scripts/dhcp_client.py b/tests/data_plane/vpp_lite_topo/scripts/dhcp_client.py
new file mode 100644
index 0000000..8e49426
--- /dev/null
+++ b/tests/data_plane/vpp_lite_topo/scripts/dhcp_client.py
@@ -0,0 +1,31 @@
+import sys
+from scapy.all import *
+
+def p(s):
+ print 'DHCP client: {}'.format(s)
+
+def main(argv):
+ src_mac = argv[1]
+ dhcp_src = argv[2]
+
+ # needed for scapy not to match replies since DHCP uses broadcast addresses
+ # which wouldn't work
+ conf.checkIPaddr = False
+
+ while True:
+ discover = Ether(dst='ff:ff:ff:ff:ff:ff', src=src_mac)/ \
+ IP(src='0.0.0.0', dst='255.255.255.255')/ \
+ UDP(dport=67,sport=68)/ \
+ BOOTP(op=1, chaddr=src_mac)/ \
+ DHCP(options=[('message-type', 'discover'), ('end')])
+
+ ans,unans = srp(discover, timeout=3)
+ for snd,rcv in ans:
+ if rcv[IP].src == dhcp_src:
+ exit(0)
+ else:
+ p('Unexpected DHCP packet source address! ({})'.format(rcv[IP].src))
+ exit(1)
+
+if __name__ == "__main__":
+ main(sys.argv)