diff --git a/build.mk b/build.mk index f2d9609680..fd323dd7c9 100644 --- a/build.mk +++ b/build.mk @@ -21,6 +21,7 @@ CXXFLAGS += -I $(src) CXXFLAGS += -Wl,--no-as-needed tests = tests/test-reactor tests/fileiotest tests/virtiotest tests/l3_test tests/ip_test tests/timertest +tests += tests/tcp_test link = mkdir -p $(@D) && $(CXX) $(CXXFLAGS) -o $@ $^ compile = mkdir -p $(@D) && $(CXX) $(CXXFLAGS) -c -o $@ $< @@ -51,6 +52,8 @@ tests/l3_test: tests/l3_test.o net/virtio.o core/reactor.o net/net.o net/ip.o ne tests/ip_test: tests/ip_test.o net/virtio.o core/reactor.o net/net.o net/ip.o net/arp.o net/ethernet.o +tests/tcp_test: tests/tcp_test.o net/virtio.o core/reactor.o net/net.o net/ip.o net/arp.o net/ethernet.o + tests/timertest: tests/timertest.o core/reactor.o -include $(shell find -name '*.d') diff --git a/tests/tcp_test.cc b/tests/tcp_test.cc new file mode 100644 index 0000000000..5a25b7b303 --- /dev/null +++ b/tests/tcp_test.cc @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2014 Cloudius Systems, Ltd. + */ + +#include "net/ip.hh" +#include "net/virtio.hh" + +using namespace net; + +struct tcp_test { + ipv4& inet; + using tcp = net::tcp; + struct connection { + tcp::connection tcp_conn; + explicit connection(tcp::connection tc) : tcp_conn(std::move(tc)) {} + void run() { + tcp_conn.receive().then([this] (packet p) { + tcp_conn.send(std::move(p)); + run(); + }); + } + }; + tcp_test(ipv4& inet) : inet(inet) {} + void run() { + inet.get_tcp().listen(10000).then([this] (tcp::connection conn) { + (new connection(std::move(conn)))->run(); + run(); + }); + } +}; + +int main(int ac, char** av) { + auto vnet = create_virtio_net_device("tap0"); + interface netif(std::move(vnet)); + netif.run(); + ipv4 inet(&netif); + inet.set_host_address(ipv4_address(0xc0a87a02)); + tcp_test tt(inet); + the_reactor.start().then([&tt] { tt.run(); }); + the_reactor.run(); +} + +