mirror of
https://github.com/genodelabs/genode.git
synced 2025-05-24 19:24:25 +00:00
nic_router: use LwIP- instead of LxIP UDP-tests
Currently, LxIP peers need a lot of RAM (the simple test-client/server for the nic_router test need at least 28 MB per component). As the nic_router test previously used 6 instances of such components and a lot of other components, it had issues with insufficient RAM on some platforms. By using two new LwIP-based UDP tests instead, we save more than 100 MB. Ref #2543
This commit is contained in:
parent
f6dd1f9b9c
commit
657fa16f8c
@ -34,9 +34,8 @@ proc nic_drv_build { } {
|
|||||||
proc gpio_drv_build { } { if {[gpio_drv] != ""} { return drivers/gpio } }
|
proc gpio_drv_build { } { if {[gpio_drv] != ""} { return drivers/gpio } }
|
||||||
|
|
||||||
build "core init drivers/timer server/nic_router server/nic_bridge
|
build "core init drivers/timer server/nic_router server/nic_bridge
|
||||||
test/lwip/http_srv_static test/lwip/http_clnt test/lxip/udp_echo
|
test/lwip/http_srv_static test/lwip/http_clnt test/lwip/udp
|
||||||
test/lxip/udp_client [nic_drv_build] [gpio_drv_build]
|
[nic_drv_build] [gpio_drv_build] [platform_drv_build_components]"
|
||||||
[platform_drv_build_components]"
|
|
||||||
|
|
||||||
create_boot_directory
|
create_boot_directory
|
||||||
|
|
||||||
@ -81,23 +80,18 @@ proc nic_drv_config { } {
|
|||||||
}
|
}
|
||||||
|
|
||||||
proc client_bin { prot } {
|
proc client_bin { prot } {
|
||||||
if {$prot == "udp"} { return "test-lxip_udp_client" }
|
if {$prot == "udp"} { return "test-lwip-udp-client" }
|
||||||
if {$prot == "http"} { return "test-http_clnt" } }
|
if {$prot == "http"} { return "test-http_clnt" } }
|
||||||
|
|
||||||
proc server_bin { prot } {
|
proc server_bin { prot } {
|
||||||
if {$prot == "udp"} { return "test-lxip_udp_echo" }
|
if {$prot == "udp"} { return "test-lwip-udp-server" }
|
||||||
if {$prot == "http"} { return "test-lwip_httpsrv_static" } }
|
if {$prot == "http"} { return "test-lwip_httpsrv_static" } }
|
||||||
|
|
||||||
proc ram_quota { prot } {
|
|
||||||
if {$prot == "udp"} { return 29M }
|
|
||||||
if {$prot == "http"} { return 12M }
|
|
||||||
}
|
|
||||||
|
|
||||||
proc client_config { prot index ip_addr gateway netmask nic srv_port srv_ip } {
|
proc client_config { prot index ip_addr gateway netmask nic srv_port srv_ip } {
|
||||||
append result {
|
append result {
|
||||||
<start name="} $prot {_client_} $index {" caps="200" priority="-1">
|
<start name="} $prot {_client_} $index {" caps="200" priority="-1">
|
||||||
<binary name="} [client_bin $prot] {" />
|
<binary name="} [client_bin $prot] {" />
|
||||||
<resource name="RAM" quantum="} [ram_quota $prot] {"/>
|
<resource name="RAM" quantum="10M"/>
|
||||||
<route>
|
<route>
|
||||||
<service name="Nic"> <child name="} $nic {"/> </service>
|
<service name="Nic"> <child name="} $nic {"/> </service>
|
||||||
<any-service> <parent/> <any-child/> </any-service>
|
<any-service> <parent/> <any-child/> </any-service>
|
||||||
@ -115,7 +109,7 @@ proc server_config { prot index ip_addr gateway netmask nic port } {
|
|||||||
append result {
|
append result {
|
||||||
<start name="} $prot {_server_} $index {" caps="200" priority="-1">
|
<start name="} $prot {_server_} $index {" caps="200" priority="-1">
|
||||||
<binary name="} [server_bin $prot] {" />
|
<binary name="} [server_bin $prot] {" />
|
||||||
<resource name="RAM" quantum="} [ram_quota $prot] {"/>
|
<resource name="RAM" quantum="10M"/>
|
||||||
<route>
|
<route>
|
||||||
<service name="Nic"> <child name="} $nic {"/> </service>
|
<service name="Nic"> <child name="} $nic {"/> </service>
|
||||||
<any-service> <parent/> <any-child/> </any-service>
|
<any-service> <parent/> <any-child/> </any-service>
|
||||||
@ -276,9 +270,9 @@ install_config $config
|
|||||||
|
|
||||||
build_boot_image "
|
build_boot_image "
|
||||||
core init timer nic_router nic_bridge ld.lib.so libc.lib.so libm.lib.so
|
core init timer nic_router nic_bridge ld.lib.so libc.lib.so libm.lib.so
|
||||||
lwip.lib.so lxip.lib.so posix.lib.so test-http_clnt
|
lwip.lib.so posix.lib.so test-http_clnt test-lwip_httpsrv_static
|
||||||
test-lwip_httpsrv_static test-lxip_udp_echo test-lxip_udp_client
|
test-lwip-udp-client test-lwip-udp-server [nic_drv_binary] [gpio_drv]
|
||||||
[nic_drv_binary] [gpio_drv] [platform_drv_boot_modules]"
|
[platform_drv_boot_modules]"
|
||||||
|
|
||||||
proc nic_qemu_args { } {
|
proc nic_qemu_args { } {
|
||||||
if {[have_spec x86]} { return "-net nic,model=e1000" }
|
if {[have_spec x86]} { return "-net nic,model=e1000" }
|
||||||
|
87
repos/libports/src/test/lwip/udp/client/main.cc
Normal file
87
repos/libports/src/test/lwip/udp/client/main.cc
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* \brief Simple UDP test client
|
||||||
|
* \author Martin Stein
|
||||||
|
* \date 2017-10-18
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Genode Labs GmbH
|
||||||
|
*
|
||||||
|
* This file is part of the Genode OS framework, which is distributed
|
||||||
|
* under the terms of the GNU Affero General Public License version 3.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Genode includes */
|
||||||
|
#include <timer_session/connection.h>
|
||||||
|
#include <base/attached_rom_dataspace.h>
|
||||||
|
#include <libc/component.h>
|
||||||
|
#include <nic/packet_allocator.h>
|
||||||
|
#include <util/string.h>
|
||||||
|
|
||||||
|
/* libc includes */
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
using namespace Genode;
|
||||||
|
using Ipv4_addr_str = Genode::String<16>;
|
||||||
|
|
||||||
|
struct Socket_failed : Genode::Exception { };
|
||||||
|
struct Send_failed : Genode::Exception { };
|
||||||
|
struct Receive_failed : Genode::Exception { };
|
||||||
|
|
||||||
|
struct Read_server_port_attr_failed : Exception { };
|
||||||
|
struct Read_server_ip_attr_failed : Exception { };
|
||||||
|
|
||||||
|
|
||||||
|
void Libc::Component::construct(Libc::Env &env)
|
||||||
|
{
|
||||||
|
/* wait a while for the server to come up */
|
||||||
|
Timer::Connection timer(env);
|
||||||
|
timer.msleep(3000);
|
||||||
|
|
||||||
|
/* create socket */
|
||||||
|
int s = socket(AF_INET, SOCK_DGRAM, 0 );
|
||||||
|
if (s < 0) {
|
||||||
|
throw Socket_failed();
|
||||||
|
}
|
||||||
|
/* try to send and receive a message multiple times */
|
||||||
|
for (int j = 0; j != 5; ++j) {
|
||||||
|
timer.msleep(1000);
|
||||||
|
|
||||||
|
/* read server IP address and port */
|
||||||
|
Ipv4_addr_str serv_addr;
|
||||||
|
unsigned port = 0;
|
||||||
|
Attached_rom_dataspace config(env, "config");
|
||||||
|
Xml_node config_node = config.xml();
|
||||||
|
try { config_node.attribute("server_ip").value(&serv_addr); }
|
||||||
|
catch (...) {
|
||||||
|
throw Read_server_port_attr_failed();
|
||||||
|
}
|
||||||
|
try { config_node.attribute("server_port").value(&port); }
|
||||||
|
catch (...) {
|
||||||
|
throw Read_server_port_attr_failed();
|
||||||
|
}
|
||||||
|
/* create server socket address */
|
||||||
|
struct sockaddr_in addr;
|
||||||
|
socklen_t addr_sz = sizeof(addr);
|
||||||
|
addr.sin_port = htons(port);
|
||||||
|
addr.sin_family = AF_INET;
|
||||||
|
addr.sin_addr.s_addr = inet_addr(serv_addr.string());
|
||||||
|
|
||||||
|
/* send test message */
|
||||||
|
enum { BUF_SZ = 1024 };
|
||||||
|
char buf[BUF_SZ];
|
||||||
|
::snprintf(buf, BUF_SZ, "UDP server at %s:%u", serv_addr.string(), port);
|
||||||
|
if (sendto(s, buf, BUF_SZ, 0, (struct sockaddr*)&addr, addr_sz) != BUF_SZ) {
|
||||||
|
throw Send_failed();
|
||||||
|
}
|
||||||
|
/* receive and print what has been received */
|
||||||
|
if (recvfrom(s, buf, BUF_SZ, 0, (struct sockaddr*)&addr, &addr_sz) != BUF_SZ) {
|
||||||
|
throw Receive_failed();
|
||||||
|
}
|
||||||
|
log("Received \"", String<64>(buf), " ...\"");
|
||||||
|
}
|
||||||
|
log("Test done");
|
||||||
|
}
|
5
repos/libports/src/test/lwip/udp/client/target.mk
Normal file
5
repos/libports/src/test/lwip/udp/client/target.mk
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
TARGET = test-lwip-udp-client
|
||||||
|
LIBS = posix libc_lwip_nic_dhcp libc_lwip lwip
|
||||||
|
SRC_CC = main.cc
|
||||||
|
|
||||||
|
INC_DIR += $(REP_DIR)/src/lib/lwip/include
|
80
repos/libports/src/test/lwip/udp/server/main.cc
Normal file
80
repos/libports/src/test/lwip/udp/server/main.cc
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* \brief Simple UDP test server
|
||||||
|
* \author Martin Stein
|
||||||
|
* \date 2017-10-18
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Genode Labs GmbH
|
||||||
|
*
|
||||||
|
* This file is part of the Genode OS framework, which is distributed
|
||||||
|
* under the terms of the GNU Affero General Public License version 3.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Genode includes */
|
||||||
|
#include <base/attached_rom_dataspace.h>
|
||||||
|
#include <libc/component.h>
|
||||||
|
#include <nic/packet_allocator.h>
|
||||||
|
#include <util/string.h>
|
||||||
|
|
||||||
|
/* libc includes */
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
using namespace Genode;
|
||||||
|
using Ipv4_addr_str = Genode::String<16>;
|
||||||
|
|
||||||
|
struct Socket_failed : Genode::Exception { };
|
||||||
|
struct Send_failed : Genode::Exception { };
|
||||||
|
struct Receive_failed : Genode::Exception { };
|
||||||
|
struct Bind_failed : Genode::Exception { };
|
||||||
|
|
||||||
|
struct Read_port_attr_failed : Genode::Exception { };
|
||||||
|
|
||||||
|
|
||||||
|
void Libc::Component::construct(Libc::Env & env)
|
||||||
|
{
|
||||||
|
/* create socket */
|
||||||
|
int s = socket(AF_INET, SOCK_DGRAM, 0 );
|
||||||
|
if (s < 0) {
|
||||||
|
throw Socket_failed();
|
||||||
|
}
|
||||||
|
/* read server port */
|
||||||
|
unsigned port = 0;
|
||||||
|
Attached_rom_dataspace config(env, "config");
|
||||||
|
Xml_node config_node = config.xml();
|
||||||
|
try { config_node.attribute("port").value(&port); }
|
||||||
|
catch (...) {
|
||||||
|
throw Read_port_attr_failed();
|
||||||
|
}
|
||||||
|
/* create server socket address */
|
||||||
|
struct sockaddr_in in_addr;
|
||||||
|
in_addr.sin_family = AF_INET;
|
||||||
|
in_addr.sin_port = htons(port);
|
||||||
|
in_addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
|
||||||
|
/* bind server socket address to socket */
|
||||||
|
if (bind(s, (struct sockaddr*)&in_addr, sizeof(in_addr))) {
|
||||||
|
throw Bind_failed();
|
||||||
|
}
|
||||||
|
/* prepare client socket address */
|
||||||
|
struct sockaddr_in addr;
|
||||||
|
addr.sin_family = AF_INET;
|
||||||
|
socklen_t addr_sz = sizeof(addr);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
/* receive and send back one message without any modifications */
|
||||||
|
char buf[4096];
|
||||||
|
::memset(buf, 0, sizeof(buf));
|
||||||
|
ssize_t rcv_sz = recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr*)&addr, &addr_sz);
|
||||||
|
if (rcv_sz < 0) {
|
||||||
|
throw Receive_failed();
|
||||||
|
}
|
||||||
|
if (sendto(s, buf, rcv_sz, 0, (struct sockaddr*)&addr, addr_sz) != rcv_sz) {
|
||||||
|
throw Send_failed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
5
repos/libports/src/test/lwip/udp/server/target.mk
Normal file
5
repos/libports/src/test/lwip/udp/server/target.mk
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
TARGET = test-lwip-udp-server
|
||||||
|
LIBS = posix libc_lwip_nic_dhcp libc_lwip lwip
|
||||||
|
SRC_CC = main.cc
|
||||||
|
|
||||||
|
INC_DIR += $(REP_DIR)/src/lib/lwip/include
|
Loading…
x
Reference in New Issue
Block a user