Hi,
I am currently writing a network stack for my OS and I'd like test it on a virtual machine.
More precisely, for the time being, I'm trying to write a driver for the RTL8139 NIC. I am running under Ubuntu 12.04 and I most often use Qemu (sometimes Bochs) for testing.
If anyone here has developped a network stack, could they tell me how they did the tests ? I have read about bridging and tap devices, but all my trials with Qemu proved fruitless.
Thanks for your help.
Testing network under VM : which method do you use ?
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Testing network under VM : which method do you use ?
Your message is very vague. What have you tried and failed with? What kind of network stack (it seems like you're just writing a NIC driver for now)? What kinds of tests do you have in mind? What is your testing platform?
So I don't leave the question completely unanswered, you might want to look into Nmap, tcpdump (the Windows port is WinDump). Also, take a closer look at QEMU's documentation.
So I don't leave the question completely unanswered, you might want to look into Nmap, tcpdump (the Windows port is WinDump). Also, take a closer look at QEMU's documentation.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
Re: Testing network under VM : which method do you use ?
I have tried to start Qemu with the following options :
Concerning the tests I have in mind, first I'd like to send ethernet frames to my virtual machine and check whether my driver detects them.
Code: Select all
-net nic,model=rtl8139 -net tap,script=no
Re: Testing network under VM : which method do you use ?
Can you detect the device on PCI configuration space?
Anyway, you can launch qemu with the following command:
The first one create a user-space NIC (aka host-only networking), and I can get IRQ on it (but I don't have time to write the network stack to verify the packet).
The second one require additional configuration on the host for bridged network.
Anyway, you can launch qemu with the following command:
Code: Select all
-netdev type=user,id=net -device rtl8139,netdev=net
OR
-netdev type=tap,id=br0 -device rtl8139,netdev=br0
The second one require additional configuration on the host for bridged network.
Re: Testing network under VM : which method do you use ?
The NIC is detected on the PCI configuration space. I have tried to send frames, and it seems to work : I get a IRQ and no transmission error is detected.
However, as concerns receiving, I can't get any IRQ with
.
However, as concerns receiving, I can't get any IRQ with
Code: Select all
-netdev type=user,id=net -device rtl8139,netdev=net
Re: Testing network under VM : which method do you use ?
I'm pretty sure that using script=no while at the same time letting qemu create the tap device can't work because the device won't be brougt up. As far as I know it also only works as root, and you don't want to run qemu as root.
I get a minimal working setup like this:
With this setup, you can watch the traffic that the guest sends on tap0 with tools like Wireshark. If you want to actually establish a connection between the host and the guest, you need to assign an IP address to the tap device while bringing it up; read the ifconfig man page if you're not sure how to do it. If you want to have your guest access your physical network, you need to deal with it as if you had a physical second network card that is directly connected to your guest. You can setup bridging with your physical network card (this is what I usually do for debugging), but in theory you can also do NAT or basically anything you want.
For just running a guest, of course, I usually use the user mode networking because it's so much easier to set up. However, in this case your guest is in a virtual network that is connected to the host via a virtual router at 10.0.2.2. You can't use Wireshark on the host to watch the traffic, so it's not quite as convenient for debugging, but if you need it, qemu can dump all network traffic even in user mode networking:
If you want to initiate connections from the host to the guest, you also need to enable port forwarding for the specific TCP or UDP port because of the virtual router that sits in the middle. The normal mode of operation is that connections are initiated by the guest.
I get a minimal working setup like this:
Code: Select all
# tunctl -u kevin
Set 'tap0' persistent and owned by uid 1001
# ifconfig tap0 up
$ qemu-system-x86_64 -hda hd.img -netdev type=tap,ifname=tap0,id=nic1,script=no -device rtl8139,netdev=nic1
For just running a guest, of course, I usually use the user mode networking because it's so much easier to set up. However, in this case your guest is in a virtual network that is connected to the host via a virtual router at 10.0.2.2. You can't use Wireshark on the host to watch the traffic, so it's not quite as convenient for debugging, but if you need it, qemu can dump all network traffic even in user mode networking:
Code: Select all
$ qemu-system-x86_64 -hda hd.img -net nic,model=rtl8139 -net user -net dump,file=/tmp/dump.pcap
Re: Testing network under VM : which method do you use ?
Thanks, it works now.