summaryrefslogtreecommitdiff
path: root/samples/net/dhcpv4_client/README.rst
blob: 0da1e5252979d3d6d766d602790811c6e4f5f789 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
.. _dhcpv4-client-sample:

Sample DHCPv4 client application
################################

Overview
********

This application starts a DHCPv4 client, gets an IPv4 address from the
DHCPv4 server, and prints address, lease time, netmask and router
information to a serial console.

Requirements
************

- :ref:`networking with Qemu <networking_with_qemu>`

Building and Running
********************

QEMU x86
========

These are instructions for how to use this sample application using
QEMU on a Linux host to negotiate IP address from DHCPv4 server running
on Linux host.

Follow readme from:

    Run 'loop_socat' and 'loop-slip-tap' scripts from net-tools.

    https://github.com/zephyrproject-rtos/net-tools

.. code-block:: console

    $ ./loop_socat.sh

In another window:

.. code-block:: console

    $ sudo ./loop-slip-tap.sh

Here's a sample server configuration file '/etc/dhcpd/dhcp.conf'
used to configure the DHCPv4 server:

.. code-block:: console

   log-facility local7;
   default-lease-time 600;
   max-lease-time 7200;

   subnet 192.0.2.0 netmask 255.255.255.0 {
     range 192.0.2.10 192.0.2.100;
   }

Use another terminal window to start up a DHCPv4 server on the Linux host,
using this conf file:

.. code-block:: console

    $ sudo dhcpd -d -4 -cf /etc/dhcp/dhcpd.conf -lf /var/lib/dhcp/dhcpd.leases tap0

Run Zephyr samples/net/dhcpv4_client application in QEMU:

.. code-block:: console

    $ cd $ZEPHYR_BASE/samples/net/dhcpv4_client
    $ make pristine && make qemu

Once DHCPv4 client address negotiation completed with server, details
are shown like this:

.. code-block:: console

    [dhcpv4] [INF] main: In main
    [dhcpv4] [INF] main_thread: Run dhcpv4 client
    [dhcpv4] [INF] handler: Your address: 192.0.2.10
    [dhcpv4] [INF] handler: Lease time: 600
    [dhcpv4] [INF] handler: Subnet: 255.255.255.0
    [dhcpv4] [INF] handler: Router: 0.0.0.0

To verify the Zephyr application client is running and has received
an ip address by typing:

.. code-block:: console

    $ ping -I tap0 192.0.2.10


FRDM_K64F
=========

These are instructions for how to use this sample application running on
:ref:`frdm_k64f` board to negotiate IP address from DHCPv4 server running on
Linux host.

Connect ethernet cable from :ref:`Freedom-K64F board <frdm_k64f>` to Linux host
machine and check for new interfaces:

.. code-block:: console

    $ ifconfig

Add ip address and routing information to interface:

.. code-block:: console

    $ sudo ip addr add 192.0.2.2 dev eth1
    $ sudo ip route add 192.0.2.0/24 dev eth1

Here's a sample server configuration file '/etc/dhcpd/dhcp.conf'
used to configure the DHCPv4 server:

.. code-block:: console

   log-facility local7;
   default-lease-time 600;
   max-lease-time 7200;

   subnet 192.0.2.0 netmask 255.255.255.0 {
     range 192.0.2.10 192.0.2.100;
   }

Use another terminal window to start up a DHCPv4 server on the Linux host,
using this conf file:

.. code-block:: console

    $ sudo dhcpd -d -4 -cf /etc/dhcp/dhcpd.conf -lf /var/lib/dhcp/dhcpd.leases eth1

Build Zephyr samples/net/dhcpv4_client application:

.. code-block:: console

    $ cd $ZEPHYR_BASE/samples/net/dhcpv4_client
    $ make pristine && make BOARD=frdm_k64f
    $ cp outdir/frdm_k64f/zephyr.bin /media/rveerama/MBED/

Once DHCPv4 client address negotiation completed with server, details
are shown like this:

.. code-block:: console

    $ sudo screen /dev/ttyACM0 115200
    [dhcpv4] [INF] main: In main
    [dhcpv4] [INF] main_thread: Run dhcpv4 client
    [dhcpv4] [INF] handler: Your address: 192.0.2.10
    [dhcpv4] [INF] handler: Lease time: 600
    [dhcpv4] [INF] handler: Subnet: 255.255.255.0
    [dhcpv4] [INF] handler: Router: 0.0.0.0

To verify the Zephyr application client is running and has received
an ip address by typing:

.. code-block:: console

    $ ping -I eth1 192.0.2.10