From 9e79aa6f9d6e808c60aa201d0c25fc18057bb5c1 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Tue, 2 Feb 2016 17:54:54 +0200 Subject: net: apps: echo-server refactoring to work in microkernel The echo-server uses only one code base for both microkernel and nanokernel. Change-Id: I7abdf76dc13c31e4f91d0fd9d3b870ffe20ac71b Signed-off-by: Jukka Rissanen --- samples/microkernel/apps/net/echo_server/prj.mdef | 4 +- samples/net/echo_server/src/echo-server.c | 78 ++++++++++++----------- 2 files changed, 44 insertions(+), 38 deletions(-) (limited to 'samples') diff --git a/samples/microkernel/apps/net/echo_server/prj.mdef b/samples/microkernel/apps/net/echo_server/prj.mdef index d14a3c083..970ed645d 100644 --- a/samples/microkernel/apps/net/echo_server/prj.mdef +++ b/samples/microkernel/apps/net/echo_server/prj.mdef @@ -1,5 +1,5 @@ -% Application : Network echo server +% Application : echo server % TASK NAME PRIO ENTRY STACK GROUPS % ================================== - TASK TASKA 7 task_receive 2048 [EXE] + TASK MAIN 7 main 2048 [EXE] diff --git a/samples/net/echo_server/src/echo-server.c b/samples/net/echo_server/src/echo-server.c index 88618e5f4..64a6717eb 100644 --- a/samples/net/echo_server/src/echo-server.c +++ b/samples/net/echo_server/src/echo-server.c @@ -16,12 +16,6 @@ * limitations under the License. */ -/* - * Note that both the nano and microkernel images in this example - * have a dummy fiber/task that does nothing. This is just here to - * simulate a multi application scenario. - */ - #if defined(CONFIG_STDOUT_CONSOLE) #include #define PRINT printf @@ -31,11 +25,16 @@ #endif #include +#include #include #include #include +#include +#include +#include + #ifndef CONFIG_ETHERNET /* The peer is the client in our case. Just invent a mac * address for it because lower parts of the stack cannot set it @@ -51,9 +50,13 @@ static uint8_t my_mac[] = { 0x0a, 0xbe, 0xef, 0x15, 0xf0, 0x0d }; #ifdef CONFIG_NETWORKING_WITH_IPV6 /* The 2001:db8::/32 is the private address space for documentation RFC 3849 */ #define MY_IPADDR { { { 0x20,0x01,0x0d,0xb8,0,0,0,0,0,0,0,0,0,0,0,0x1 } } } +#define PEER_IPADDR { { { 0x20,0x01,0x0d,0xb8,0,0,0,0,0,0,0,0,0,0,0,0x2 } } } /* admin-local, dynamically allocated multicast address */ #define MCAST_IPADDR { { { 0xff,0x84,0,0,0,0,0,0,0,0,0,0,0,0,0,0x2 } } } + +static const struct in6_addr in6addr_peer = PEER_IPADDR; +static struct in6_addr in6addr_my = MY_IPADDR; #else /* The 192.0.2.0/24 is the private address space for documentation RFC 5737 */ #define MY_IPADDR { { { 192,0,2,2 } } } @@ -77,6 +80,30 @@ static inline void init_server() uip_ipaddr(&addr, 192,0,2,2); uip_sethostaddr(&addr); } +#else /* IPv6 */ + { + uip_ipaddr_t *addr; + +#ifdef CONFIG_NETWORKING_IPV6_NO_ND + /* Set the routes and neighbor cache only if we do not have + * neighbor discovery enabled. This setting should only be + * used if running in qemu and using slip (tun device). + */ + const uip_lladdr_t *lladdr = (const uip_lladdr_t *)&peer_mac; + + addr = (uip_ipaddr_t *)&in6addr_peer; + uip_ds6_defrt_add(addr, 0); + + /* We cannot send to peer unless it is in neighbor + * cache. Neighbor cache should be populated automatically + * but do it here so that test works from first packet. + */ + uip_ds6_nbr_add(addr, lladdr, 0, NBR_REACHABLE); +#endif + + addr = (uip_ipaddr_t *)&in6addr_my; + uip_ds6_addr_add(addr, 0, ADDR_MANUAL); + } #endif } @@ -160,7 +187,6 @@ static inline bool get_context(struct net_context **recv, #ifdef CONFIG_NETWORKING_WITH_IPV6 static const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT; static const struct in6_addr in6addr_mcast = MCAST_IPADDR; - static struct in6_addr in6addr_my = MY_IPADDR; mcast_addr.in6_addr = in6addr_mcast; mcast_addr.family = AF_INET6; @@ -205,34 +231,12 @@ static inline bool get_context(struct net_context **recv, return true; } -#ifdef CONFIG_MICROKERNEL - -void task_receive(void) -{ - static struct net_context *recv; - static struct net_context *mcast_recv; - - net_init(); - - init_server(); - - if (!get_context(&recv, &mcast_recv)) { - PRINT("%s: Cannot get network contexts\n", __func__); - return; - } - - while (1) { - receive_and_reply(__func__, recv, mcast_recv); - } -} - -#else /* CONFIG_NANOKERNEL */ - +#ifdef CONFIG_NANOKERNEL #define STACKSIZE 2000 +char __noinit __stack fiberStack[STACKSIZE]; +#endif -char fiberStack[STACKSIZE]; - -void fiber_receive(void) +void receive(void) { static struct net_context *recv; static struct net_context *mcast_recv; @@ -253,8 +257,10 @@ void main(void) init_server(); +#ifdef CONFIG_MICROKERNEL + receive(); +#else task_fiber_start (&fiberStack[0], STACKSIZE, - (nano_fiber_entry_t)fiber_receive, 0, 0, 7, 0); + (nano_fiber_entry_t)receive, 0, 0, 7, 0); +#endif } - -#endif /* CONFIG_MICROKERNEL || CONFIG_NANOKERNEL */ -- cgit v1.2.3