Virtual network setup for QEMU TCP Demo

Hi,

I’ve been trying to run FreeRTOS_Plus_TCP_Echo_Qemu_mps2, but it doesn’t seem to work, and not sure what I’m doing wrong.
FreeRTOS/FreeRTOS/tree/main/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Echo_Qemu_mps2

I have setup my virtual network using this script with virsh command.

<network>
  <name>default</name>
  <uuid>465735a6-7436-4a72-a4ea-0eff08266605</uuid>
  <forward mode='nat'/>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='52:54:00:40:ed:25'/>
  <ip address='192.168.122.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.122.100' end='192.168.122.254'/>
      <host mac='52:54:00:12:34:AD' name='FreeRTOS' ip='192.168.122.45'/>
    </dhcp>
  </ip>
</network>

with following IP address macros


#define configECHO_SERVER_ADDR0 192
#define configECHO_SERVER_ADDR1 168
#define configECHO_SERVER_ADDR2 0
#define configECHO_SERVER_ADDR3 111

/* Default MAC address configuration.  The demo creates a virtual network
connection that uses this MAC address by accessing the raw Ethernet/WiFi data
to and from a real network connection on the host PC.  See the
configNETWORK_INTERFACE_TO_USE definition above for information on how to
configure the real network connection to use. */

#define configMAC_ADDR0    0x52
#define configMAC_ADDR1    0x54
#define configMAC_ADDR2    0x00
#define configMAC_ADDR3    0x12
#define configMAC_ADDR4    0x34
#define configMAC_ADDR5    0xAD

/* Default IP address configuration.  Used in ipconfigUSE_DNS is set to 0, or
ipconfigUSE_DNS is set to 1 but a DNS server cannot be contacted. */

#define configIP_ADDR0      192
#define configIP_ADDR1      168
#define configIP_ADDR2      122
#define configIP_ADDR3      45

/* Default gateway IP address configuration.  Used in ipconfigUSE_DNS is set to
0, or ipconfigUSE_DNS is set to 1 but a DNS server cannot be contacted. */

#define configGATEWAY_ADDR0 192
#define configGATEWAY_ADDR1 168
#define configGATEWAY_ADDR2 122
#define configGATEWAY_ADDR3 1

/* Default DNS server configuration.  OpenDNS addresses are 208.67.222.222 and
208.67.220.220.  Used in ipconfigUSE_DNS is set to 0, or ipconfigUSE_DNS is set
to 1 but a DNS server cannot be contacted.*/

#define configDNS_SERVER_ADDR0  192
#define configDNS_SERVER_ADDR1  168
#define configDNS_SERVER_ADDR2  122
#define configDNS_SERVER_ADDR3  1

/* Default netmask configuration.  Used in ipconfigUSE_DNS is set to 0, or
ipconfigUSE_DNS is set to 1 but a DNS server cannot be contacted. */
#define configNET_MASK0     255
#define configNET_MASK1     255
#define configNET_MASK2     255
#define configNET_MASK3     0

When I run the demo I get the following output

$> sudo qemu-system-arm -machine mps2-an385 -cpu cortex-m3 \
          -kernel ./build/RTOSDemo.axf \
          -netdev tap,id=mynet0,ifname=virbr0-nic,script=no \
          -net nic,macaddr=52:54:00:12:34:AD,model=lan9118,netdev=mynet0 \
          -object filter-dump,id=tap_dump,netdev=mynet0,file=/tmp/qemu_tap_dump\
          -display gtk -m 16M  -nographic -serial stdio \
          -monitor null -semihosting -semihosting-config enable=on,target=native
0->prvMiscInitialisation 264: Seed for randomiser: 32
0->prvMiscInitialisation 271: Random numbers: 000078A4 00006CD3 00007BE1 00005F97
0->main_tcp_echo_client_tasks 160: FreeRTOS_IPInit
0x2000bb68->main_tcp_echo_client_tasks 168: vTaskStartScheduler
0x2000bb68->prvIPTask 407: prvIPTask started
0x2000bb68->vApplicationIPNetworkEventHook 221: 

IP Address: 192.168.122.45
0x2000bb68->vApplicationIPNetworkEventHook 224: Subnet Mask: 255.255.255.0
0x2000bb68->vApplicationIPNetworkEventHook 227: Gateway Address: 192.168.122.1
0x2000bb68->vApplicationIPNetworkEventHook 230: DNS Server Address: 192.168.122.1


connecting to echo server....
0x200159b0->prvTCPConnectStart 2986: FreeRTOS_connect: 11253 to c0a8006fip:7
0x200159b0->vTCPStateChange 1945: Socket 11253 -> c0a8006fip:7 State eCLOSED->eCONNECT_SYN
0x2000bb68->prvTCPPrepareConnect 1191: ARP for c0a8006fip (using c0a87a01ip): rc=0 00:00:00 00:00:00
0x2000bb68->prvTCPNextTimeout 2324: Connect[c0a8006fip:7]: next timeout 1: 500 ms
0x2000bb68->prvTCPPrepareConnect 1191: ARP for c0a8006fip (using c0a87a01ip): rc=0 00:00:00 00:00:00
0x2000bb68->prvTCPNextTimeout 2324: Connect[c0a8006fip:7]: next timeout 2: 500 ms
0x2000bb68->prvTCPPrepareConnect 1191: ARP for c0a8006fip (using c0a87a01ip): rc=0 00:00:00 00:00:00
0x2000bb68->prvTCPNextTimeout 2324: Connect[c0a8006fip:7]: next timeout 3: 500 ms

With tapdump as the following

sudo tcpdump -r /tmp/qemu_tap_dump  | less

reading from file /tmp/qemu_tap_dump, link-type EN10MB (Ethernet)
22:43:53.011608 IP6 ubuntu-box > ff02::16: HBH ICMP6, multicast listener report v2, 2 group record(s), length 48
22:43:53.719625 STP 802.1d, Config, Flags [Topology change], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:43:53.943662 IP6 ubuntu-box > ff02::16: HBH ICMP6, multicast listener report v2, 2 group record(s), length 48
22:43:54.728023 ARP, Request who-has ubuntu-box tell 192.168.122.45, length 28
22:43:55.128470 ARP, Request who-has ubuntu-box tell 192.168.122.45, length 28
22:43:55.528359 ARP, Request who-has ubuntu-box tell 192.168.122.45, length 28
22:43:55.735619 STP 802.1d, Config, Flags [Topology change], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:43:57.719620 STP 802.1d, Config, Flags [Topology change], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:43:59.735658 STP 802.1d, Config, Flags [Topology change], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:44:01.719618 STP 802.1d, Config, Flags [Topology change], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:44:03.735591 STP 802.1d, Config, Flags [Topology change], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:44:05.723642 STP 802.1d, Config, Flags [Topology change], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:44:07.735563 STP 802.1d, Config, Flags [Topology change], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:44:09.719563 STP 802.1d, Config, Flags [Topology change], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:44:11.735566 STP 802.1d, Config, Flags [Topology change], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:44:13.719562 STP 802.1d, Config, Flags [Topology change], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:44:15.735567 STP 802.1d, Config, Flags [Topology change], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:44:17.719585 STP 802.1d, Config, Flags [Topology change], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:44:19.735590 STP 802.1d, Config, Flags [none], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:44:21.719563 STP 802.1d, Config, Flags [none], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:44:23.735562 STP 802.1d, Config, Flags [none], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:44:25.719563 STP 802.1d, Config, Flags [none], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:44:27.735563 STP 802.1d, Config, Flags [none], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:44:29.719640 STP 802.1d, Config, Flags [none], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:44:31.735573 STP 802.1d, Config, Flags [none], bridge-id 8000.52:54:00:40:ed:25.8001, length 35
22:44:33.723581 STP 802.1d, Config, Flags [none], bridge-id 8000.52:54:00:40:ed:25.8001, length 35

The echo server is running on another computer.

And the FreeRTOS app doesn’t show up when I run virsh net-dhcp-leases --network default command.

I tested that this virtual network setup works with running

qemu-system-x86_64 -smp $(nproc) -boot d -cdrom MX-21_x64.iso -m 4096 -netdev tap,id=mynet0,ifname=virbr0-nic,script=no,downscript=no -device e1000,netdev=mynet0,mac=52:55:00:d1:55:01

command with LinuxMX iso image. I was able to send request to the echo server from the LinuxMX using above qemu command.

I appreciate any help.

I am not familiar with this demo, and I run on Windows rather than Linux, so don’t know the details exactly, but it looks like you are using incompatible IP addresses - unless you are using DHCP. Your IP address is 192.168.122.45 and your netmask is 255.255.255.0 - so you can access IP addresses in the range 192.168.122.1 to 192.168.122.254 - but the echo server is at address 192.168.0.111 (not 192.168.122.111). Subnet and netmask