mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-08 03:45:24 +00:00
nic_bridge: Add tests for static IP address configuration
This commit is contained in:
parent
bc18e2991b
commit
291064b5c1
119
libports/run/test-nicbridge_static.run
Normal file
119
libports/run/test-nicbridge_static.run
Normal file
@ -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 {
|
||||
<config>
|
||||
<parent-provides>
|
||||
<service name="ROM"/>
|
||||
<service name="RAM"/>
|
||||
<service name="IRQ"/>
|
||||
<service name="IO_MEM"/>
|
||||
<service name="IO_PORT"/>
|
||||
<service name="CAP"/>
|
||||
<service name="PD"/>
|
||||
<service name="RM"/>
|
||||
<service name="CPU"/>
|
||||
<service name="LOG"/>
|
||||
<service name="SIGNAL"/>
|
||||
</parent-provides>
|
||||
<default-route>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</default-route>}
|
||||
|
||||
append_if [have_spec pci] config {
|
||||
<start name="pci_drv">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides><service name="PCI"/></provides>
|
||||
</start>}
|
||||
|
||||
|
||||
append config {
|
||||
<start name="timer">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides><service name="Timer"/></provides>
|
||||
</start>
|
||||
<start name="nic_drv">
|
||||
<resource name="RAM" quantum="2M"/>
|
||||
<provides><service name="Nic"/></provides>
|
||||
</start>
|
||||
<start name="nic_bridge">
|
||||
<resource name="RAM" quantum="24M"/>
|
||||
<provides><service name="Nic"/></provides>
|
||||
<config>
|
||||
<policy label="test-lwip_httpsrv_static" ip_addr="10.0.2.55"/>
|
||||
</config>
|
||||
<route>
|
||||
<service name="Nic"> <child name="nic_drv"/> </service>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</route>
|
||||
</start>
|
||||
<start name="test-lwip_httpsrv_static">
|
||||
<resource name="RAM" quantum="32M"/>
|
||||
<route>
|
||||
<service name="Nic"> <child name="nic_bridge"/> </service>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</route>
|
||||
</start>
|
||||
<start name="test-http_clnt">
|
||||
<resource name="RAM" quantum="32M"/>
|
||||
<route>
|
||||
<service name="Nic"> <child name="nic_bridge"/> </service>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</route>
|
||||
</start>
|
||||
</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
|
170
libports/run/test-nicbridge_static2.run
Normal file
170
libports/run/test-nicbridge_static2.run
Normal file
@ -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 {
|
||||
<config>
|
||||
<parent-provides>
|
||||
<service name="ROM"/>
|
||||
<service name="RAM"/>
|
||||
<service name="IRQ"/>
|
||||
<service name="IO_MEM"/>
|
||||
<service name="IO_PORT"/>
|
||||
<service name="CAP"/>
|
||||
<service name="PD"/>
|
||||
<service name="RM"/>
|
||||
<service name="CPU"/>
|
||||
<service name="LOG"/>
|
||||
<service name="SIGNAL"/>
|
||||
</parent-provides>
|
||||
<default-route>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</default-route>}
|
||||
|
||||
append_if [have_spec pci] config {
|
||||
<start name="pci_drv">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides><service name="PCI"/></provides>
|
||||
</start>}
|
||||
|
||||
|
||||
append config {
|
||||
<start name="timer">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides><service name="Timer"/></provides>
|
||||
</start>
|
||||
<start name="nic_drv">
|
||||
<resource name="RAM" quantum="2M"/>
|
||||
<provides><service name="Nic"/></provides>
|
||||
</start>
|
||||
<start name="nic_bridge">
|
||||
<resource name="RAM" quantum="24M"/>
|
||||
<provides><service name="Nic"/></provides>
|
||||
<config>
|
||||
<policy label="lighttpd" ip_addr="10.0.2.55"/>
|
||||
</config>
|
||||
<route>
|
||||
<service name="Nic"> <child name="nic_drv"/> </service>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</route>
|
||||
</start>
|
||||
<start name="ram_fs">
|
||||
<resource name="RAM" quantum="10M"/>
|
||||
<provides><service name="File_system"/></provides>
|
||||
<config>
|
||||
<policy label="lighttpd" root="/" />
|
||||
<content>
|
||||
<dir name="etc">
|
||||
<dir name="lighttpd">
|
||||
<inline name="lighttpd.conf">
|
||||
# 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"
|
||||
)
|
||||
</inline>
|
||||
</dir>
|
||||
</dir>
|
||||
<dir name="website">
|
||||
<inline name="index.html">
|
||||
<html>
|
||||
<head>
|
||||
<title>Hello</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Hello Genode!</p>
|
||||
<b>I am bold ;-)</b>
|
||||
</body>
|
||||
</html>
|
||||
</inline>
|
||||
</dir>
|
||||
</content>
|
||||
</config>
|
||||
</start>
|
||||
<start name="lighttpd">
|
||||
<resource name="RAM" quantum="256M" />
|
||||
<config>
|
||||
<interface ip_addr="10.0.2.55" netmask="255.255.255.0" gateway="10.0.2.1"/>
|
||||
<arg value="lighttpd" />
|
||||
<arg value="-f" />
|
||||
<arg value="/etc/lighttpd/lighttpd.conf" />
|
||||
<arg value="-D" />
|
||||
</config>
|
||||
<route>
|
||||
<service name="Nic"> <child name="nic_bridge"/> </service>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</route>
|
||||
</start>
|
||||
<start name="test-http_clnt">
|
||||
<resource name="RAM" quantum="32M"/>
|
||||
<route>
|
||||
<service name="Nic"> <child name="nic_bridge"/> </service>
|
||||
<any-service> <parent/> <any-child/> </any-service>
|
||||
</route>
|
||||
</start>
|
||||
</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
|
||||
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
|
102
libports/src/test/lwip/http_clnt/main.cc
Normal file
102
libports/src/test/lwip/http_clnt/main.cc
Normal file
@ -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 <base/printf.h>
|
||||
#include <base/thread.h>
|
||||
#include <util/string.h>
|
||||
#include <timer_session/connection.h>
|
||||
|
||||
extern "C" {
|
||||
#include <lwip/sockets.h>
|
||||
#include <lwip/api.h>
|
||||
#include <netif/etharp.h>
|
||||
}
|
||||
|
||||
#include <lwip/genode.h>
|
||||
|
||||
|
||||
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;
|
||||
}
|
6
libports/src/test/lwip/http_clnt/target.mk
Normal file
6
libports/src/test/lwip/http_clnt/target.mk
Normal file
@ -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
|
126
libports/src/test/lwip/http_srv_static/main.cc
Normal file
126
libports/src/test/lwip/http_srv_static/main.cc
Normal file
@ -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 <base/printf.h>
|
||||
#include <base/thread.h>
|
||||
#include <util/string.h>
|
||||
|
||||
/* LwIP includes */
|
||||
extern "C" {
|
||||
#include <lwip/sockets.h>
|
||||
#include <lwip/api.h>
|
||||
}
|
||||
|
||||
#include <lwip/genode.h>
|
||||
|
||||
|
||||
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[] =
|
||||
"<html><head><title>Congrats!</title></head><body><h1>Welcome to our lwIP HTTP server!</h1><p>This is a small test page.</body></html>"; /* 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;
|
||||
}
|
5
libports/src/test/lwip/http_srv_static/target.mk
Normal file
5
libports/src/test/lwip/http_srv_static/target.mk
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user