run: adjust lwip pingpong test for foc_arndale

This commit is contained in:
Christian Prochaska 2013-04-08 20:51:28 +02:00 committed by Norman Feske
parent 0b906207bb
commit cab27dd713
19 changed files with 461 additions and 120 deletions

View File

@ -71,6 +71,17 @@ proc fiasco_external { } {
return 1
}
##
# Reset the target system via the Fiasco.OC kernel debugger
#
proc reset { {spawn_id_arg -1} } {
global spawn_id
if { $spawn_id_arg == -1 } {
set spawn_id_arg $spawn_id
}
send -i $spawn_id_arg "\033^^"
}
##################################
## Test framework API functions ##
##################################

View File

@ -0,0 +1,205 @@
#
# \brief Test ping
# \author Josef Soentgen
# \date 2013-01-06
#
#
# Client parameters
#
set packet_payload_size 24
set packet_count 1000000
#
# Build
#
set build_components {
core init
drivers/pci drivers/timer drivers/nic
test/lwip/pingpong/server
}
lappend_if $use_nic_bridge build_components server/nic_bridge
lappend_if [expr [have_spec omap4] || [have_spec exynos5]] build_components drivers/usb
build $build_components
create_boot_directory
#
# Generate config
#
set config {
<config verbose="yes">
<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>
<start name="timer">
<resource name="RAM" quantum="1M"/>
<provides> <service name="Timer"/> </provides>
</start> }
append_if $use_nic_bridge config {
<start name="nic_bridge">
<resource name="RAM" quantum="2M"/>
<provides><service name="Nic"/></provides>
<route>
<service name="Nic"> }
append_if [expr $use_nic_bridge && ([have_spec omap4] || [have_spec exynos5])] config {
<child name="usb_drv"/> }
append_if [expr $use_nic_bridge && (![have_spec omap4] && ![have_spec exynos5])] config {
<child name="nic_drv"/> }
append_if $use_nic_bridge config {
</service>
<any-service> <parent/> <any-child/> </any-service>
</route>
</start> }
append config "
<start name=\"$test_server_name\">"
append config {
<resource name="RAM" quantum="16M"/>
<config>
<argv verbose="0" listenip="0.0.0.0" />
</config>
<route> }
append_if $use_nic_bridge config {
<service name="Nic"> <child name="nic_bridge"/> </service> }
append config {
<any-service> <parent/> <any-child/> </any-service>
</route>
</start> }
append_if [expr [have_spec omap4] || [have_spec exynos5]] config {
<start name="usb_drv" priority="-1">
<resource name="RAM" quantum="12M"/>
<provides>
<service name="Nic"/>
</provides>
<config>
<nic mac="2e:60:90:0c:4e:02" />
<!--<nic mac="aa:bb:cc:dd:ee:00" />-->
</config>
</start>}
append_if [expr ![have_spec omap4] && ![have_spec exynos5]] config {
<start name="nic_drv">
<resource name="RAM" quantum="4M"/>
<provides><service name="Nic"/></provides>
</start>}
append_if [have_spec pci] config {
<start name="pci_drv">
<resource name="RAM" quantum="2M"/>
<provides> <service name="PCI"/> </provides>
</start> }
append config {
</config>
}
install_config $config
#
# Boot modules
#
# generic modules
set boot_modules {
core init timer
ld.lib.so libc.lib.so lwip.lib.so libc_log.lib.so
}
lappend_if $use_nic_bridge boot_modules nic_bridge
lappend boot_modules $test_server_name
# platform-specific modules
lappend_if [have_spec pci] boot_modules pci_drv
lappend_if [expr [have_spec omap4] || [have_spec exynos5]] boot_modules usb_drv
lappend_if [expr ![have_spec omap4] && ![have_spec exynos5]] boot_modules nic_drv
build_boot_image $boot_modules
# establish serial connection with the server system
spawn picocom -b 115200 /dev/ttyUSB0
set server_spawn_id $spawn_id
set timeout -1
expect -i $server_spawn_id "Terminal ready"
# reset the server system (if Fiasco.OC is already running)
reset $server_spawn_id
# get IP address from server
expect {
-i $server_spawn_id
-re "got IP address (.*)\033.*\n" { set ip_addr $expect_out(1,string) }
}
puts "got server IP address: $ip_addr"
# wait until the server is ready
expect -i $server_spawn_id "wait...*\n"
# build the client
set pingpong_dir $genode_dir/libports/src/test/lwip/pingpong
exec g++ -o bin/network_test_client \
$pingpong_dir/client/main.cc \
$pingpong_dir/pingpong.cc \
-I $pingpong_dir
# start the client
spawn bin/network_test_client \
-serverip $ip_addr \
-startsize $packet_payload_size \
-endsize $packet_payload_size \
-count $packet_count
# wait until the client is connected to the server
expect -i $server_spawn_id "client \[1|3\] connected..."
# start counting the execution time
set time_start [clock milliseconds]
# wait until the server received all packets
expect {
-i $server_spawn_id
-re "received .*\n" { }
}
# stop counting the execution time
set time_end [clock milliseconds]
set milliseconds [expr $time_end - $time_start]
set payload_total [expr $packet_count * $packet_payload_size]
set payload_bytes_per_second [expr $payload_total * 1000 / $milliseconds ]
set test_result "$milliseconds ms ($payload_bytes_per_second payload bytes per second)"
puts "\nTest succeeded in $test_result."
# disconnect from server system
send -i $server_spawn_id "\x01\x18" ;# Ctrl-A Ctrl-X
expect {
-i $server_spawn_id
"Thanks for using picocom"
}
exec rm -f bin/network_test_client
# vi: set ft=tcl :

View File

@ -0,0 +1,18 @@
source ${genode_dir}/libports/run/network_test_lwip.run
set test_result_lwip $test_result
source ${genode_dir}/libports/run/network_test_lwip_nic_bridge.run
set test_result_lwip_nic_bridge $test_result
source ${genode_dir}/libports/run/network_test_libc_lwip.run
set test_result_libc_lwip $test_result
source ${genode_dir}/libports/run/network_test_libc_lwip_nic_bridge.run
set test_result_libc_lwip_nic_bridge $test_result
puts "\nTest results:\n"
puts "lwip: $test_result_lwip"
puts "lwip_nic_bridge: $test_result_lwip_nic_bridge"
puts "libc_lwip: $test_result_libc_lwip"
puts "libc_lwip_nic_bridge: $test_result_libc_lwip_nic_bridge"
puts ""

View File

@ -0,0 +1,4 @@
set use_nic_bridge 0
set test_server_name "test-ping_server_libc_lwip"
source ${genode_dir}/libports/run/network_test.inc

View File

@ -0,0 +1,4 @@
set use_nic_bridge 1
set test_server_name "test-ping_server_libc_lwip"
source ${genode_dir}/libports/run/network_test.inc

View File

@ -0,0 +1,4 @@
set use_nic_bridge 0
set test_server_name "test-ping_server_lwip"
source ${genode_dir}/libports/run/network_test.inc

View File

@ -0,0 +1,4 @@
set use_nic_bridge 1
set test_server_name "test-ping_server_lwip"
source ${genode_dir}/libports/run/network_test.inc

View File

@ -14,7 +14,7 @@ set build_components {
test/lwip/pingpong/client
}
lappend_if [have_spec omap4] build_components drivers/usb
lappend_if [expr [have_spec omap4] || [have_spec exynos5]] build_components drivers/usb
build $build_components
@ -45,15 +45,9 @@ set config {
<start name="timer">
<resource name="RAM" quantum="1M"/>
<provides> <service name="Timer"/> </provides>
</start>
<start name="test-ping_client">
<resource name="RAM" quantum="16M"/>
<config>
<argv verbose="1" serverip="10.0.0.190" startsize="1024" endsize="16384" />
</config>
</start> }
append_if [have_spec omap4] config {
append_if [expr [have_spec omap4] || [have_spec exynos5]] config {
<start name="usb_drv" priority="-1">
<resource name="RAM" quantum="12M"/>
<provides>
@ -64,7 +58,7 @@ append_if [have_spec omap4] config {
</config>
</start>}
append_if [expr ![have_spec omap4]] config {
append_if [expr ![have_spec omap4] && ![have_spec exynos5]] config {
<start name="nic_drv">
<resource name="RAM" quantum="4M"/>
<provides><service name="Nic"/></provides>
@ -72,10 +66,40 @@ append_if [expr ![have_spec omap4]] config {
append_if [have_spec pci] config {
<start name="pci_drv">
<resource name="RAM" quantum="1M"/>
<resource name="RAM" quantum="2M"/>
<provides> <service name="PCI"/> </provides>
</start> }
# establish serial connection with the server system
spawn picocom -b 115200 /dev/ttyUSB0
set server_spawn_id $spawn_id
set timeout -1
expect -i $server_spawn_id "Terminal ready"
# get IP address from server
expect {
-i $server_spawn_id
-re "got IP address (.*)\033.*\n" { set ip_addr $expect_out(1,string) }
}
puts "got server IP address: $ip_addr"
append config {
<start name="test-ping_client_libc_lwip">
<resource name="RAM" quantum="16M"/>
<config>
<arg value="test-ping_client"/>
<arg value="-verbose"/>
<arg value="0"/>
<arg value="-startsize"/>
<arg value="1024"/>
<arg value="-endsize"/>
<arg value="1024"/>
<arg value="-serverip"/> }
append config "
<arg value=\"$ip_addr\"/>
</config>
</start> "
append config {
</config>
}
@ -89,8 +113,8 @@ install_config $config
# generic modules
set boot_modules {
core init timer
ld.lib.so libc.lib.so lwip.lib.so
test-ping_client
ld.lib.so libc.lib.so libc_log.lib.so lwip_nic_dhcp.lib.so lwip.lib.so
test-ping_client_libc_lwip
}
# platform-specific modules
@ -112,6 +136,22 @@ append_if [have_spec lan9118] qemu_args " -net nic,model=lan9118 "
append qemu_args " -net user "
run_genode_until forever
expect -i $server_spawn_id "wait..."
run_genode_until {Sucessfully connected to server.} 60
expect -i $server_spawn_id "client 3 connected..."
set time_start [clock milliseconds]
set timeout -1
expect {
-i $server_spawn_id
-re "received .*\n" { }
}
set time_end [clock milliseconds]
puts "\nTest succeeded in [expr $time_end - $time_start] milliseconds."
# vi: set ft=tcl :

View File

@ -14,7 +14,7 @@ set build_components {
test/lwip/pingpong/server
}
lappend_if [have_spec omap4] build_components drivers/usb
lappend_if [expr [have_spec omap4] || [have_spec exynos5]] build_components drivers/usb
build $build_components
@ -46,14 +46,14 @@ set config {
<resource name="RAM" quantum="1M"/>
<provides> <service name="Timer"/> </provides>
</start>
<start name="test-ping_server">
<start name="test-ping_server_libc_lwip">
<resource name="RAM" quantum="16M"/>
<config>
<argv verbose="1" listenip="0.0.0.0" />
<argv verbose="0" listenip="0.0.0.0" />
</config>
</start> }
append_if [have_spec omap4] config {
append_if [expr [have_spec omap4] || [have_spec exynos5]] config {
<start name="usb_drv" priority="-1">
<resource name="RAM" quantum="12M"/>
<provides>
@ -64,7 +64,7 @@ append_if [have_spec omap4] config {
</config>
</start>}
append_if [expr ![have_spec omap4]] config {
append_if [expr ![have_spec omap4] && ![have_spec exynos5]] config {
<start name="nic_drv">
<resource name="RAM" quantum="4M"/>
<provides><service name="Nic"/></provides>
@ -72,7 +72,7 @@ append_if [expr ![have_spec omap4]] config {
append_if [have_spec pci] config {
<start name="pci_drv">
<resource name="RAM" quantum="1M"/>
<resource name="RAM" quantum="2M"/>
<provides> <service name="PCI"/> </provides>
</start> }
@ -89,14 +89,14 @@ install_config $config
# generic modules
set boot_modules {
core init timer
ld.lib.so libc.lib.so lwip.lib.so
test-ping_server
ld.lib.so libc.lib.so lwip.lib.so libc_log.lib.so
test-ping_server_libc_lwip
}
# platform-specific modules
lappend_if [have_spec pci] boot_modules pci_drv
lappend_if [have_spec omap4] boot_modules usb_drv
lappend_if [expr ![have_spec omap4]] boot_modules nic_drv
lappend_if [expr [have_spec omap4] || [have_spec exynos5]] boot_modules usb_drv
lappend_if [expr ![have_spec omap4] && ![have_spec exynos5]] boot_modules nic_drv
build_boot_image $boot_modules

View File

@ -0,0 +1,8 @@
TARGET = test-ping_client_libc_lwip
LIBS = base libc libc_lwip lwip libc_lwip_nic_dhcp libc_log config_args
SRC_CC = main.cc pingpong.cc
CC_OPT_main += -fpermissive
vpath main.cc $(PRG_DIR)/..
vpath pingpong.cc $(PRG_DIR)/../..

View File

@ -0,0 +1,10 @@
TARGET = test-ping_client_lwip
LIBS = base libc lwip libc_log config_args
SRC_CC = main.cc pingpong.cc
CC_OPT_main += -fpermissive
INC_DIR += $(REP_DIR)/src/lib/lwip/include
vpath main.cc $(PRG_DIR)/..
vpath pingpong.cc $(PRG_DIR)/../..

View File

@ -12,20 +12,8 @@
* under the terms of the GNU General Public License version 2.
*/
/* Genode includes */
#include <base/printf.h>
#include <util/string.h>
#include <os/config.h>
#include <lwip/genode.h>
/* libc includes */
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <stdio.h>
#include "../pingpong.h"
@ -37,30 +25,30 @@ dial(const char *addr)
int s;
struct sockaddr_in in_addr;
PLOG("Create new socket...");
printf("Create new socket...\n");
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s == -1) {
PERR("Could not create socket!");
printf("ERROR: Could not create socket!\n");
return -1;
}
PLOG("Connect to server %s:%d...", addr, Sport);
printf("Connect to server %s:%d...\n", addr, Sport);
in_addr.sin_port = htons(Sport);
in_addr.sin_family = AF_INET;
in_addr.sin_addr.s_addr = inet_addr(addr);
if (connect(s, (struct sockaddr *)&in_addr, sizeof (in_addr)) == -1) {
PERR("Could not connect to server!");
printf("ERROR: Could not connect to server!\n");
close(s);
return -1;
}
PLOG("Sucessful connected to server.");
printf("Sucessfully connected to server.\n");
return s;
}
int
sendping(const char *addr, size_t dsize)
sendping(const char *addr, size_t dsize, int count)
{
Packet p;
int s;
@ -75,24 +63,24 @@ sendping(const char *addr, size_t dsize)
p.h.dsize = dsize;
p.d = (char *)malloc(p.h.dsize);
if (p.d == NULL) {
PERR("Out of memory!");
printf("ERROR: Out of memory!\n");
return -1;
}
PINF("Try to send %d packets...", Numpackets);
for (i = 0; i < Numpackets; i++) {
printf("Trying to send %d packets...\n", count);
for (i = 0; i < count; i++) {
forgepacket(&p, i + 1);
n = sendpacket(s, &p);
if (n <= 0)
break;
if (n != (sizeof (Packetheader) + p.h.dsize)) {
PERR("size mismatch: %ld != %lu", n, sizeof (Packetheader) + p.h.dsize);
printf("ERROR: size mismatch: %ld != %lu\n", n, sizeof (Packetheader) + p.h.dsize);
break;
}
if (verbose)
PINF("%lu %ld", p.h.id, n);
printf("%u %ld\n", p.h.id, n);
}
close(s);
@ -100,15 +88,15 @@ sendping(const char *addr, size_t dsize)
switch (n) {
case 0:
PERR("Disconnect, sent packets: %lu", i);
printf("Disconnect, sent packets: %lu\n", i);
return 0;
break;
case -1:
PERR("Error, sent packets: %lu", i);
printf("Error, sent packets: %lu\n", i);
return 1;
break;
default:
PINF("Sucessful, sent packets: %lu", i);
printf("Sucessful, sent packets: %lu\n", i);
return 0;
break;
}
@ -120,21 +108,18 @@ sendping(const char *addr, size_t dsize)
int
main(int argc, char *argv[])
{
char serverip[16];
char serverip[16] = "0.0.0.0";
unsigned int i;
unsigned int startsize, endsize;
/* DHCP */
if (lwip_nic_init(0, 0, 0)) {
PERR("We got no IP address!");
return 1;
}
unsigned int count;
/* default settings */
startsize = 1;
endsize = 32768;
count = 1024;
verbose = 0;
#if 0
Genode::Xml_node argv_node = Genode::config()->xml_node().sub_node("argv");
try {
argv_node.attribute("serverip" ).value(serverip, sizeof(serverip));
@ -142,14 +127,26 @@ main(int argc, char *argv[])
argv_node.attribute("endsize").value( &endsize );
argv_node.attribute("verbose").value( &verbose );
} catch(...) { }
#endif
for (int i = 1; i < argc; i += 2) {
if (strcmp(argv[i], "-serverip") == 0)
strncpy(serverip, argv[i+1], sizeof(serverip));
else if (strcmp(argv[i], "-startsize") == 0)
startsize = atoi(argv[i+1]);
else if (strcmp(argv[i], "-endsize") == 0)
endsize = atoi(argv[i+1]);
else if (strcmp(argv[i], "-count") == 0)
count = atoi(argv[i+1]);
}
if ((endsize + sizeof (Packetheader)) > Databuf) {
PERR("endsize is greater than the servers' data buffer");
printf("ERROR: endsize is greater than the servers' data buffer\n");
return 1;
}
for (i = startsize; i <= endsize; i <<= 1)
sendping(serverip, i);
sendping(serverip, i, count);
return 0;
}

View File

@ -1,7 +0,0 @@
TARGET = test-ping_client
LIBS = cxx env libc libc_lwip lwip
SRC_CC = main.cc ../pingpong.cc
CC_OPT_main += -fpermissive
INC_DIR += $(REP_DIR)/src/lib/lwip/include

View File

@ -12,13 +12,8 @@
* under the terms of the GNU General Public License version 2.
*/
/* Genode includes */
#include <base/printf.h>
/* libc includes */
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <stdio.h>
#include "pingpong.h"
@ -36,7 +31,7 @@ checkpacket(size_t n, Packet *p)
{
/* check size of received packet */
if (n != (sizeof (Packetheader) + p->h.dsize)) {
PERR("packetsize mismatch!");
printf("ERROR: packetsize mismatch!\n");
return -1;
}
@ -44,13 +39,13 @@ checkpacket(size_t n, Packet *p)
/* check packet type */
if (p->h.type != Tping) {
PERR("wrong packet type!");
printf("ERROR: wrong packet type!\n");
return -1;
}
/* check payload */
if (p->d[p->h.dsize - 1] != (p->h.id % 128)) {
PERR("packet payload corrupt, expected: %d got: %d", (p->h.id % 128),
printf("ERROR: packet payload corrupt, expected: %d got: %d\n", (p->h.id % 128),
p->d[p->h.dsize - 1]);
return -1;
}
@ -72,11 +67,11 @@ sendpacket(int s, Packet *p)
sent = send(s, b + nh, sizeof (Packetheader) - nh, 0);
switch (sent) {
case -1:
PERR("send(Packetheader) == -1");
printf("ERROR: send(Packetheader) == -1\n");
return nh;
break;
case 0:
PERR("send(Packetheader) == 0, connection closed");
printf("ERROR: send(Packetheader) == 0, connection closed\n");
return nh;
break;
default:
@ -92,11 +87,11 @@ sendpacket(int s, Packet *p)
sent = send(s, b + nd, dsize - nd, 0);
switch (sent) {
case -1:
PERR("send(data) == -1");
printf("ERROR: send(data) == -1\n");
return nd;
break;
case 0:
PERR("send(data) == 0, connection closed");
printf("ERROR: send(data) == 0, connection closed\n");
return nd;
break;
default:
@ -121,12 +116,12 @@ recvpacket(int s, Packet *p, char *dbuf, size_t ldbuf)
r = recv(s, b + nh, sizeof (Packetheader) - nh, 0);
switch (r) {
case -1:
PERR("recv(Packetheader) == -1");
printf("ERROR: recv(Packetheader) == -1\n");
return nh;
break;
case 0:
/* disconnect */
PERR("recv(Packetheader) == 0, connection closed");
//printf("ERROR: recv(Packetheader) == 0, connection closed\n");
return nh;
break;
default:
@ -136,7 +131,7 @@ recvpacket(int s, Packet *p, char *dbuf, size_t ldbuf)
}
if (p->h.dsize > ldbuf) {
PERR("packet payload is too large for dbuf!");
printf("ERROR: packet payload is too large for dbuf!\n");
return -1;
}
@ -147,12 +142,12 @@ recvpacket(int s, Packet *p, char *dbuf, size_t ldbuf)
r = recv(s, dbuf + nd, dsize - nd, 0);
switch (r) {
case -1:
PERR("recv(data) == -1");
printf("ERROR: recv(data) == -1\n");
return nh + nd;
break;
case 0:
/* disconnect */
PERR("recv(data) == 0, connection closed");
printf("ERROR: recv(data) == 0, connection closed\n");
return nh + nd;
break;
default:

View File

@ -15,6 +15,32 @@
#ifndef _PINGPONG_H_
#define _PINGPONG_H_
/* libc includes */
#include <stdint.h>
#ifdef LWIP_NATIVE
#include <lwip/sockets.h>
#define accept(a,b,c) lwip_accept(a,b,c)
#define bind(a,b,c) lwip_bind(a,b,c)
#define close(s) lwip_close(s)
#define connect(a,b,c) lwip_connect(a,b,c)
#define listen(a,b) lwip_listen(a,b)
#define recv(a,b,c,d) lwip_recv(a,b,c,d)
#define select(a,b,c,d,e) lwip_select(a,b,c,d,e)
#define send(a,b,c,d) lwip_send(a,b,c,d)
#define socket(a,b,c) lwip_socket(a,b,c)
#else
/* libc includes */
#include <unistd.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#endif
enum {
Databuf = 1024 * 1024, // data buffer for server
Numpackets = 1024,

View File

@ -0,0 +1,8 @@
TARGET = test-ping_server_libc_lwip
LIBS = base libc libc_lwip_nic_dhcp libc_lwip lwip libc_log config_args
SRC_CC = main.cc pingpong.cc
CC_OPT_main += -fpermissive
vpath main.cc $(PRG_DIR)/..
vpath pingpong.cc $(PRG_DIR)/../..

View File

@ -0,0 +1,12 @@
TARGET = test-ping_server_lwip
LIBS = base libc lwip libc_log config_args
SRC_CC = main.cc pingpong.cc
CC_OPT += -DLWIP_NATIVE
CC_OPT_main += -fpermissive
INC_DIR += $(REP_DIR)/src/lib/lwip/include
vpath main.cc $(PRG_DIR)/..
vpath pingpong.cc $(PRG_DIR)/../..

View File

@ -12,20 +12,12 @@
* under the terms of the GNU General Public License version 2.
*/
/* Genode includes */
#include <base/printf.h>
#include <util/string.h>
#include <os/config.h>
#include <lwip/genode.h>
/* libc includes */
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef LWIP_NATIVE
#include <lwip/genode.h>
#endif
#include "../pingpong.h"
@ -37,19 +29,19 @@ announce(const char *addr)
int s;
struct sockaddr_in in_addr;
PLOG("Create new socket...");
printf("Create new socket...\n");
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s == -1) {
PERR("Could not create socket!");
printf("ERROR: Could not create socket!\n");
return -1;
}
PLOG("Bind socket to %d", Sport);
printf("Bind socket to %d\n", Sport);
in_addr.sin_port = htons(Sport);
in_addr.sin_family = AF_INET;
in_addr.sin_addr.s_addr = inet_addr(addr);
if ( bind(s, (struct sockaddr *)&in_addr, sizeof (in_addr)) == -1) {
PERR("Could not bind!");
printf("ERROR: Could not bind!\n");
close(s);
return -1;
}
@ -69,9 +61,9 @@ recvping(const char *addr)
if (s == -1)
return -1;
PLOG("Listen on %s:%d...", addr, Sport);
printf("Listen on %s:%d...\n", addr, Sport);
if (listen(s, 5) == -1) {
PERR("Could not listen!");
printf("ERROR: Could not listen!\n");
close(s);
return -1;
}
@ -80,19 +72,20 @@ recvping(const char *addr)
Packet p;
int act;
size_t packets;
ssize_t packet_size = 0;
ssize_t n;
PINF("wait...");
printf("wait...\n");
c = accept(s, &caddr, &lcaddr);
if (c == -1) {
PERR("Invalid socket from accept()!");
printf("ERROR: Invalid socket from accept()!\n");
continue;
}
PLOG("client %d connected...", c);
printf("client %d connected...\n", c);
p.d = (char *)malloc(Databuf);
if (p.d == NULL) {
PERR("Out of memeory!");
printf("ERROR: Out of memeory!\n");
close(c);
break;
}
@ -100,14 +93,22 @@ recvping(const char *addr)
/* receive packets from client */
act = 1; packets = 0;
while (act) {
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(c, &rfds);
if (select(c + 1, &rfds, NULL, NULL, NULL) == -1)
printf("ERROR: select() == -1\n");
n = recvpacket(c, &p, p.d, Databuf);
switch (n) {
case -1:
/* error */
PERR("recvpacket() == -1");
printf("ERROR: recvpacket() == -1\n");
case 0:
/* disconnect */
PERR("disconnect");
//printf("ERROR: disconnect\n");
close(c);
act = 0;
break;
@ -115,14 +116,17 @@ recvping(const char *addr)
/* check if packet is vaid */
if (checkpacket(n, &p)) {
act = 0;
} else {
packets++;
packet_size = n;
}
break;
}
if (verbose)
PINF("%u %d", p.h.id, n);
printf("%u %d\n", p.h.id, n);
}
PINF("received packets: %u", packets);
printf("received %u packets of size %u\n", packets, packet_size);
free(p.d);
}
@ -135,16 +139,20 @@ recvping(const char *addr)
int
main(int argc, char *argv[])
{
char listenip[16];
char listenip[16] = "0.0.0.0";
#ifdef LWIP_NATIVE
lwip_tcpip_init();
/* DHCP */
if (lwip_nic_init(0, 0, 0)) {
PERR("We got no IP address!");
printf("ERROR: We got no IP address!\n");
return 1;
}
#endif
verbose = 0;
#if 0
Genode::Xml_node argv_node = Genode::config()->xml_node().sub_node("argv");
try {
argv_node.attribute("listenip" ).value(listenip, sizeof(listenip));
@ -153,6 +161,7 @@ main(int argc, char *argv[])
PERR("listenip was not specified!");
return 1;
}
#endif
recvping(listenip);

View File

@ -1,7 +0,0 @@
TARGET = test-ping_server
LIBS = cxx env libc libc_lwip lwip
SRC_CC = main.cc ../pingpong.cc
CC_OPT_main += -fpermissive
INC_DIR += $(REP_DIR)/src/lib/lwip/include