From 3aec580cbe340f9308279b17071fecbf286fe5ca Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Sun, 31 Aug 2014 13:29:54 +0300 Subject: [PATCH] Add L3 test Listen for ARP packets and print something out when we see them. --- build.mk | 4 +++- l3_test.cc | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 l3_test.cc diff --git a/build.mk b/build.mk index 908a522a06..a6ff3d2b8c 100644 --- a/build.mk +++ b/build.mk @@ -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 diff --git a/l3_test.cc b/l3_test.cc new file mode 100644 index 0000000000..205bea55b7 --- /dev/null +++ b/l3_test.cc @@ -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; +} +