diff --git a/libports/run/test-nicbridge_static.run b/libports/run/test-nicbridge_static.run new file mode 100644 index 000000000..14a9109ec --- /dev/null +++ b/libports/run/test-nicbridge_static.run @@ -0,0 +1,119 @@ +# +# Build +# + +set build_components { + core init + drivers/timer drivers/pci drivers/nic + server/nic_bridge + test/lwip/http_srv_static + test/lwip/http_clnt + +} + +build $build_components + +create_boot_directory + +# +# Generate config +# + +append config { + + + + + + + + + + + + + + + + + } + +append_if [have_spec pci] config { + + + + } + + +append config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +} + +install_config $config + +# +# Boot modules +# + +# generic modules +set boot_modules { + core init + timer nic_drv + nic_bridge + ld.lib.so + libc.lib.so libc_log.lib.so + lwip.lib.so + test-http_clnt + test-lwip_httpsrv_static +} + + +# platform-specific modules +lappend_if [have_spec linux] boot_modules fb_sdl +lappend_if [have_spec pci] boot_modules pci_drv +lappend_if [have_spec vesa] boot_modules vesa_drv +lappend_if [have_spec ps2] boot_modules ps2_drv +lappend_if [have_spec pl11x] boot_modules pl11x_drv + +build_boot_image $boot_modules + +append qemu_args " -m 512 " + +append_if [have_spec x86] qemu_args " -net nic,model=pcnet " +append_if [have_spec lan9118] qemu_args " -net nic,model=lan9118 " + +append qemu_args " -net user " + +run_genode_until forever diff --git a/libports/run/test-nicbridge_static2.run b/libports/run/test-nicbridge_static2.run new file mode 100644 index 000000000..775081c51 --- /dev/null +++ b/libports/run/test-nicbridge_static2.run @@ -0,0 +1,170 @@ +# +# Build +# + +set build_components { + core init + drivers/timer drivers/pci drivers/nic + server/nic_bridge + server/ram_fs + app/lighttpd + test/lwip/http_clnt + +} + +build $build_components + +create_boot_directory + +# +# Generate config +# + +append config { + + + + + + + + + + + + + + + + + } + +append_if [have_spec pci] config { + + + + } + + +append config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + +# lighttpd configuration +server.port = 80 +server.document-root = "/website" +server.event-handler = "select" +server.network-backend = "write" +index-file.names = ( + "index.xhtml", "index.html", "index.htm" +) +mimetype.assign = ( + ".html" => "text/html", + ".htm" => "text/html" +) + + + + + + + + Hello + + +

Hello Genode!

+ I am bold ;-) + + +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + +
} + +install_config $config + +# +# Boot modules +# + +# generic modules +set boot_modules { + core init + timer nic_drv + nic_bridge + ld.lib.so + libc.lib.so libc_log.lib.so + lwip.lib.so + test-http_clnt + ram_fs + libm.lib.so libc_fs.lib.so + zlib.lib.so libcrypto.lib.so libssl.lib.so + lighttpd +} + + +# platform-specific modules +lappend_if [have_spec linux] boot_modules fb_sdl +lappend_if [have_spec pci] boot_modules pci_drv +lappend_if [have_spec vesa] boot_modules vesa_drv +lappend_if [have_spec ps2] boot_modules ps2_drv +lappend_if [have_spec pl11x] boot_modules pl11x_drv + +build_boot_image $boot_modules + +append qemu_args " -m 512 " + +append_if [have_spec x86] qemu_args " -net nic,model=pcnet " +append_if [have_spec lan9118] qemu_args " -net nic,model=lan9118 " + +append qemu_args " -net user " + +run_genode_until forever diff --git a/libports/src/test/lwip/http_clnt/main.cc b/libports/src/test/lwip/http_clnt/main.cc new file mode 100644 index 000000000..82ffc0285 --- /dev/null +++ b/libports/src/test/lwip/http_clnt/main.cc @@ -0,0 +1,102 @@ +/* + * \brief HTTP client test + * \author Ivan Loskutov + * \date 2012-12-21 + */ + +/* + * Copyright (C) 2012 Ksys Labs LLC + * Copyright (C) 2012-2013 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +/* Genode includes */ +#include +#include +#include +#include + +extern "C" { +#include +#include +#include +} + +#include + + +static const char *http_get_request = +"GET / HTTP/1.0\r\nHost: localhost:80\r\n\r\n"; /* simple HTTP request header */ + + +/** + * The client thread simply loops endless, + * and sends as much 'http get' requests as possible, + * printing out the response. + */ +int main() +{ + static Timer::Connection _timer; + lwip_tcpip_init(); + + char serv_addr[] = "10.0.2.55"; + + if( lwip_nic_init(0, 0, 0)) + { + PERR("We got no IP address!"); + return 0; + } + + for(int j = 0; j != 5; ++j) { + _timer.msleep(2000); + + + PDBG("Create new socket ..."); + int s = lwip_socket(AF_INET, SOCK_STREAM, 0 ); + if (s < 0) { + PERR("No socket available!"); + continue; + } + + PDBG("Connect to server ..."); + struct sockaddr_in addr; + addr.sin_port = htons(80); + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = inet_addr(serv_addr); + + if((lwip_connect(s, (struct sockaddr *)&addr, sizeof(addr))) < 0) { + PERR("Could not connect!"); + lwip_close(s); + continue; + } + + PDBG("Send request..."); + unsigned long bytes = lwip_send(s, (char*)http_get_request, + Genode::strlen(http_get_request), 0); + if ( bytes < 0 ) { + PERR("Couldn't send request ..."); + lwip_close(s); + continue; + } + + /* Receive http header and content independently in 2 packets */ + for(int i=0; i<2; i++) { + char buf[1024]; + ssize_t buflen; + buflen = lwip_recv(s, buf, 1024, 0); + if(buflen > 0) { + buf[buflen] = 0; + PDBG("Packet received!"); + PDBG("Packet content:\n%s", buf); + } else + break; + } + + /* Close socket */ + lwip_close(s); + } + + return 0; +} diff --git a/libports/src/test/lwip/http_clnt/target.mk b/libports/src/test/lwip/http_clnt/target.mk new file mode 100644 index 000000000..fa05509f5 --- /dev/null +++ b/libports/src/test/lwip/http_clnt/target.mk @@ -0,0 +1,6 @@ +TARGET = test-http_clnt +LIBS = cxx env lwip libc libc_log +SRC_CC = main.cc +REQUIRES = foc + +INC_DIR += $(REP_DIR)/src/lib/lwip/include diff --git a/libports/src/test/lwip/http_srv_static/main.cc b/libports/src/test/lwip/http_srv_static/main.cc new file mode 100644 index 000000000..df795cdc2 --- /dev/null +++ b/libports/src/test/lwip/http_srv_static/main.cc @@ -0,0 +1,126 @@ +/* + * \brief Minimal HTTP server lwIP demonstration + * \author lwIP Team + * \author Stefan Kalkowski + * \date 2009-10-23 + * + * This small example shows how to use the LwIP in Genode directly. + * If you simply want to use LwIP's socket API, you might use + * Genode's libc together with its LwIP backend, especially useful + * when porting legacy code. + */ + +/* + * Copyright (C) 2009-2012 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +/* Genode includes */ +#include +#include +#include + +/* LwIP includes */ +extern "C" { +#include +#include +} + +#include + + +const static char http_html_hdr[] = + "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n"; /* HTTP response header */ + +const static char http_index_html[] = + "Congrats!

Welcome to our lwIP HTTP server!

This is a small test page."; /* HTML page */ + + +/** + * Handle a single client's request. + * + * \param conn socket connected to the client + */ +void http_server_serve(int conn) { + char buf[1024]; + ssize_t buflen; + + /* Read the data from the port, blocking if nothing yet there. + We assume the request (the part we care about) is in one packet */ + buflen = lwip_recv(conn, buf, 1024, 0); + PLOG("Packet received!"); + + /* Ignore all receive errors */ + if (buflen > 0) { + + /* Is this an HTTP GET command? (only check the first 5 chars, since + there are other formats for GET, and we're keeping it very simple)*/ + if (buflen >= 5 && + buf[0] == 'G' && + buf[1] == 'E' && + buf[2] == 'T' && + buf[3] == ' ' && + buf[4] == '/' ) { + + PLOG("Will send response"); + + /* Send http header */ + lwip_send(conn, http_html_hdr, Genode::strlen(http_html_hdr), 0); + + /* Send our HTML page */ + lwip_send(conn, http_index_html, Genode::strlen(http_index_html), 0); + } + } +} + + +int main() +{ + int s; + + lwip_tcpip_init(); + + /* Initialize network stack */ + if (lwip_nic_init(inet_addr("10.0.2.55"), inet_addr("255.255.255.0"), inet_addr("10.0.2.1"))) { + PERR("We got no IP address!"); + return -1; + } + + PLOG("Create new socket ..."); + if((s = lwip_socket(AF_INET, SOCK_STREAM, 0)) < 0) { + PERR("No socket available!"); + return -1; + } + + PLOG("Now, I will bind ..."); + struct sockaddr_in in_addr; + in_addr.sin_family = AF_INET; + in_addr.sin_port = htons(80); + in_addr.sin_addr.s_addr = INADDR_ANY; + if(lwip_bind(s, (struct sockaddr*)&in_addr, sizeof(in_addr))) { + PERR("bind failed!"); + return -1; + } + + PLOG("Now, I will listen ..."); + if(lwip_listen(s, 5)) { + PERR("listen failed!"); + return -1; + } + + PLOG("Start the server loop ..."); + while(true) { + struct sockaddr addr; + socklen_t len = sizeof(addr); + int client = lwip_accept(s, &addr, &len); + if(client < 0) { + PWRN("Invalid socket from accept!"); + continue; + } + http_server_serve(client); + lwip_close(client); + } + return 0; +} diff --git a/libports/src/test/lwip/http_srv_static/target.mk b/libports/src/test/lwip/http_srv_static/target.mk new file mode 100644 index 000000000..a01a6bd02 --- /dev/null +++ b/libports/src/test/lwip/http_srv_static/target.mk @@ -0,0 +1,5 @@ +TARGET = test-lwip_httpsrv_static +LIBS = cxx env lwip libc libc_log +SRC_CC = main.cc + +INC_DIR += $(REP_DIR)/src/lib/lwip/include