Add L3 test

Listen for ARP packets and print something out when we see them.
This commit is contained in:
Avi Kivity
2014-08-31 13:29:54 +03:00
parent 4baf051763
commit 3aec580cbe
2 changed files with 30 additions and 1 deletions

View File

@@ -19,7 +19,7 @@ CXXFLAGS += -pthread
# Ubuntu fails without this, see https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1228201
CXXFLAGS += -Wl,--no-as-needed
tests = test-reactor fileiotest virtiotest
tests = test-reactor fileiotest virtiotest l3_test
link = $(CXX) $(CXXFLAGS) -o $@ $^
@@ -42,4 +42,6 @@ fileiotest: fileiotest.o reactor.o
virtiotest: virtiotest.o virtio.o reactor.o net.o ip.o
l3_test: l3_test.o virtio.o reactor.o net.o ip.o
-include *.d

27
l3_test.cc Normal file
View File

@@ -0,0 +1,27 @@
/*
* Copyright (C) 2014 Cloudius Systems, Ltd.
*/
#include "net.hh"
#include "reactor.hh"
#include "virtio.hh"
using namespace net;
void dump_arp_packets(l3_protocol& proto) {
proto.receive().then([&proto] (packet p, ethernet_address from) {
std::cout << "seen arp packet\n";
dump_arp_packets(proto);
});
}
int main(int ac, char** av) {
auto vnet = create_virtio_net_device("tap0");
interface netif(std::move(vnet));
netif.run();
l3_protocol arp(&netif, 0x0806);
dump_arp_packets(arp);
the_reactor.run();
return 0;
}