33Networking with QEMU
44####################
55
6- This page describes how to set up a " virtual" networking between a (Linux) host
6+ This page describes how to set up a virtual network between a (Linux) host
77and a Zephyr application running in a QEMU virtual machine (built for Zephyr
8- targets like qemu_x86, qemu_cortex_m3, etc.) In this example, the
9- ``echo_server `` sample application from Zephyr source distribution is run in
10- QEMU. The QEMU instance is connected to Linux host using serial port and SLIP is
11- used to transfer data between Zephyr and Linux (over a chain of virtual
12- connections).
8+ targets such as qemu_x86 and qemu_cortex_m3).
9+
10+ In this example, the :ref: `echo-server-sample ` sample application from
11+ the Zephyr source distribution is run in QEMU. The QEMU instance is
12+ connected to a Linux host using a serial port, and SLIP is used to
13+ transfer data between the Zephyr application and Linux (over a chain of
14+ virtual connections).
1315
1416Prerequisites
1517*************
1618
17- On the Linux Host you need to fetch Zephyr net-tools project, which is located
18- in a separate git repository:
19+ On the Linux Host, fetch the Zephyr `` net-tools `` project, which is located
20+ in a separate Git repository:
1921
2022.. code-block :: console
2123
@@ -25,18 +27,18 @@ in a separate git repository:
2527
2628 .. note ::
2729
28- If you get error about AX_CHECK_COMPILE_FLAG, install package autoconf-archive
29- package on Debian/Ubuntu.
30+ If you get an error about AX_CHECK_COMPILE_FLAG, install package
31+ `` autoconf-archive `` package on Debian/Ubuntu.
3032
3133Basic Setup
3234***********
3335
3436For the steps below, you will need at least 4 terminal windows:
3537
36- * Terminal #1 is your usual Zephyr development terminal, with Zephyr environment
38+ * Terminal #1 is your usual Zephyr development terminal, with the Zephyr environment
3739 initialized.
38- * Terminals #2, #3, #4 - fresh terminal windows with net-tools being the current
39- directory (" cd net-tools" )
40+ * Terminals #2, #3, and #4 are terminal windows with net-tools being the current
41+ directory (`` cd net-tools `` )
4042
4143Step 1 - Create helper socket
4244=============================
@@ -75,7 +77,7 @@ In terminal #1, type:
7577 :goals: run
7678 :compact:
7779
78- If you see error from QEMU about unix:/tmp/slip.sock, it means you missed Step 1
80+ If you see an error from QEMU about unix:/tmp/slip.sock, it means you missed Step 1
7981above.
8082
8183Step 4 - Run apps on host
@@ -91,7 +93,7 @@ You can start with pings:
9193 ping 192.0.2.1
9294 ping6 2001:db8::1
9395
94- For example, using netcat ("nc") utility, connecting using UDP:
96+ You can use the netcat ("nc") utility, connecting using UDP:
9597
9698.. code-block :: console
9799
@@ -104,7 +106,7 @@ For example, using netcat ("nc") utility, connecting using UDP:
104106 foobar
105107
106108 If echo_server is compiled with TCP support (now enabled by default for
107- echo_server sample, CONFIG_NET_TCP=y):
109+ the echo_server sample, CONFIG_NET_TCP=y):
108110
109111.. code-block :: console
110112
@@ -113,7 +115,7 @@ echo_server sample, CONFIG_NET_TCP=y):
113115
114116 .. note ::
115117
116- You will need to Ctrl+C manually .
118+ Use Ctrl+C to exit .
117119
118120You can also use the telnet command to achieve the above.
119121
@@ -122,36 +124,35 @@ Step 5 - Stop supporting daemons
122124
123125When you are finished with network testing using QEMU, you should stop
124126any daemons or helpers started in the initial steps, to avoid possible
125- networking or routing problems such as address conflicts in local network
126- interfaces. For example, you definitely need to stop them if you switch
127- from testing networking with QEMU to using real hardware. For example,
128- there was a report of an airport WiFi connection not working during
129- travel due to an address conflict.
127+ networking or routing problems such as address conflicts in local
128+ network interfaces. For example, stop them if you switch from testing
129+ networking with QEMU to using real hardware, or to return your host
130+ laptop to normal WiFi use.
130131
131- To stop the daemons, just press Ctrl+C in the corresponding terminal windows
132+ To stop the daemons, press Ctrl+C in the corresponding terminal windows
132133(you need to stop both ``loop-slip-tap.sh `` and ``loop-socat.sh ``).
133134
134135
135136Setting up Zephyr and NAT/masquerading on QEMU host to access Internet
136137**********************************************************************
137138
138- To access the Internet from a Zephyr application using IPv4,
139+ To access the internet from a Zephyr application using IPv4,
139140a gateway should be set via DHCP or configured manually.
140141For applications using the :ref: `net_app_api ` facility (with the config option
141142:option: `CONFIG_NET_APP ` enabled),
142143set the :option: `CONFIG_NET_APP_MY_IPV4_GW ` option to the IP address
143144of the gateway. For apps not using the :ref: `net_app_api ` facility, set up the
144145gateway by calling the :c:func: `net_if_ipv4_set_gw ` at runtime.
145146
146- To access Internet from a custom application running in a QEMU, NAT
147+ To access the internet from a custom application running in QEMU, NAT
147148(masquerading) should be set up for QEMU's source address. Assuming 192.0.2.1 is
148149used, the following command should be run as root:
149150
150151.. code-block :: console
151152
152153 iptables -t nat -A POSTROUTING -j MASQUERADE -s 192.0.2.1
153154
154- Additionally, IPv4 forwarding should be enabled on host, and you may need to
155+ Additionally, IPv4 forwarding should be enabled on the host, and you may need to
155156check that other firewall (iptables) rules don't interfere with masquerading.
156157To enable IPv4 forwarding the following command should be run as root:
157158
@@ -162,9 +163,10 @@ To enable IPv4 forwarding the following command should be run as root:
162163 Network connection between two QEMU VMs
163164***************************************
164165
165- Unlike VM-Host setup described above, VM-VM setup is automatic - for sample
166- applications which support such mode such as the echo_server and echo_client
167- samples, you will need 2 terminal windows, set up for Zephyr development.
166+ Unlike the VM-to-Host setup described above, VM-to-VM setup is
167+ automatic. For sample
168+ applications that support this mode (such as the echo_server and echo_client
169+ samples), you will need two terminal windows, set up for Zephyr development.
168170
169171Terminal #1:
170172============
@@ -177,7 +179,7 @@ Terminal #1:
177179 :build-args: server
178180 :compact:
179181
180- This will start QEMU, waiting for connection from a client QEMU.
182+ This will start QEMU, waiting for a connection from a client QEMU.
181183
182184Terminal #2:
183185============
@@ -190,18 +192,19 @@ Terminal #2:
190192 :build-args: client
191193 :compact:
192194
193- This will start 2nd QEMU instance, and you should see logging of data sent and
195+ This will start a second QEMU instance, where you should see logging of data sent and
194196received in both.
195197
196198Running multiple QEMU VMs of the same sample
197199********************************************
198200
199- If you find yourself needing to run multiple instances of the same Zephyr
200- sample application, which do not need to be able to talk to each other, the
201- ``QEMU_INSTANCE `` argument is what you need .
201+ If you find yourself wanting to run multiple instances of the same Zephyr
202+ sample application, which do not need to talk to each other, use the
203+ ``QEMU_INSTANCE `` argument.
202204
203- Start socat and tunslip6 manually (avoiding loop-x.sh scripts) for as many
204- instances as you want. Use the following as a guide, replacing MAIN or OTHER.
205+ Start ``socat `` and ``tunslip6 `` manually (instead of using the
206+ ``loop-xxx.sh `` scripts) for as many instances as you want. Use the
207+ following as a guide, replacing MAIN or OTHER.
205208
206209Terminal #1:
207210============
0 commit comments