dhcp.sh revision 0b237f3c
1source config.sh
2source odl_utils.sh
3source topologies/2_node_topo.sh
4
5if [ "$1" == "clean" ] ; then
6  2_node_topo_clean no_odl
7  exit 0
8fi
9
10if [[ $(id -u) != 0 ]]; then
11  echo "Error: run this as root."
12  exit 1
13fi
14
15function start_dhcp_server
16{
17  echo "starting DHCP server from namespace $1"
18  ip netns exec "$1" python scripts/dhcp_server.py &
19  dhcp_id=$!
20}
21
22function send_dhcp_discovery
23{
24  src_mac="`sudo ip netns exec vppns1 ifconfig veth_vpp1 | grep HWaddr | awk '{print $5}'`"
25  ip netns exec "$1" python scripts/dhcp_client.py "$src_mac" "$2"
26  rc=$?
27}
28
29function test_dhcp
30{
31  2_node_topo_setup no_odl
32  test_result=1
33
34  # dhcp proxy1 config
35  echo "set dhcp proxy server 6.0.2.2 src-address 6.0.1.1" | nc 0 5002
36
37  maybe_pause
38
39  # run DHCP server from namespace
40  start_dhcp_server vppns2
41
42  # send DHCP discovery from namespace and check if reply (= DHCP offer)
43  # comes from the proxy DHCP address
44  send_dhcp_discovery vppns1 "6.0.1.1"
45
46  maybe_pause
47  2_node_topo_clean no_odl
48  kill $dhcp_id
49
50  print_status $rc "DHCP test failed!"
51  exit $test_result
52}
53
54