X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=tests%2Fdata_plane%2Fvpp_lite_topo%2Fscripts%2Fdhcp_server.py;fp=tests%2Fdata_plane%2Fvpp_lite_topo%2Fscripts%2Fdhcp_server.py;h=cd6f43e57f20d3043123273ea98a750cff0e0530;hb=0b237f3cd02f6c59252e8270c97c015c7a148cd2;hp=0000000000000000000000000000000000000000;hpb=9047c7fbf1c811f07c69f778914d25d2652651f3;p=one.git diff --git a/tests/data_plane/vpp_lite_topo/scripts/dhcp_server.py b/tests/data_plane/vpp_lite_topo/scripts/dhcp_server.py new file mode 100644 index 0000000..cd6f43e --- /dev/null +++ b/tests/data_plane/vpp_lite_topo/scripts/dhcp_server.py @@ -0,0 +1,32 @@ +from scapy.all import * +from scapy.layers import * + +server_ip="6.0.2.2" +client_ip="6.0.1.2" +server_mac="00:0B:CD:AE:9F:C6" +client_mac="aa:a2:a5:ea:54:20" +subnet_mask="255.255.255.0" +gateway="6.0.1.1" + +# suboption 1 Agent circuit ID; len:4; val:0x00000001 +# suboption 5 Link selection; len:4; val:6.0.1.1 +option82 = '\x01\x04\x00\x00\x00\x01\x05\x04\x06\00\x01\x01' + +def detect_dhcp(pkt): + # check if we get DHCP discover and send offer message + if pkt[DHCP] and pkt[DHCP].options[0][1] == 1: + sendp(Ether(src=server_mac,dst="ff:ff:ff:ff:ff:ff")/ + IP(src=server_ip,dst="6.0.1.1")/ + UDP(sport=67,dport=68)/ + BOOTP(op=2, yiaddr=client_ip, siaddr=server_ip, giaddr=gateway, + chaddr=client_mac, xid=pkt[BOOTP].xid)/ + DHCP(options=[('message_type', 'offer')])/ + DHCP(options=[('subnet_mask',subnet_mask)])/ + DHCP(options=[('server_id',server_ip)])/ + DHCP(options=[('relay_agent_Information', option82), ('end')])) + +#sniff DHCP requests +def start(): + sniff(filter="udp and (port 67 or 68)", prn=detect_dhcp, store=0) + +start()