net: apps: Change dtls-client to use common testing header file

Move network testing setup from dtls-client to common net_testing.h
file which makes the application much simpler.

Change-Id: I5a727325c22f98170f12620629898e5ed052b707
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2016-03-10 20:51:19 +02:00
commit c07ac4d072
4 changed files with 32 additions and 59 deletions

View file

@ -22,6 +22,5 @@ KERNEL_TYPE ?= nano
BOARD ?= qemu_x86
CONF_FILE = prj_$(NET_IFACE).conf
QEMU_EXTRA_FLAGS = -serial none -serial unix:/tmp/slip.sock
include $(ZEPHYR_BASE)/Makefile.inc
include $(ZEPHYR_BASE)/samples/net/echo_server/Makefile.ipstack

View file

@ -1,8 +1,10 @@
CONFIG_NET_TESTING=y
CONFIG_NETWORKING_IPV6_NO_ND=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_NETWORKING=y
CONFIG_NETWORKING_WITH_LOGGING=y
CONFIG_NETWORKING_UART=y
CONFIG_IP_BUF_TX_SIZE=4
CONFIG_IP_BUF_RX_SIZE=3
CONFIG_IP_BUF_TX_SIZE=2
CONFIG_IP_BUF_RX_SIZE=10
CONFIG_NANO_TIMEOUTS=y
CONFIG_TINYDTLS=y

View file

@ -4,4 +4,9 @@ ccflags-y +=-I${srctree}/net/ip/contiki/os
ccflags-y +=-I${srctree}/net/ip/contiki/os/sys
ccflags-y +=-I${srctree}/net/ip
ifeq ($(CONFIG_NET_TESTING), y)
ccflags-y +=-I${srctree}/samples/net/common/
ccflags-y +=-DNET_TESTING_SERVER=0
endif
obj-y = dtls-client.o

View file

@ -43,6 +43,10 @@
#include <net/tinydtls.h>
#if defined(CONFIG_NET_TESTING)
#include <net_testing.h>
#endif
/* Generated by http://www.lipsum.com/
* 1202 bytes of Lorem Ipsum.
*
@ -79,75 +83,28 @@ static const unsigned char ecdsa_pub_key_y[] = {
0xD0, 0x43, 0xB1, 0xFB, 0x03, 0xE2, 0x2F, 0x4D,
0x17, 0xDE, 0x43, 0xF9, 0xF9, 0xAD, 0xEE, 0x70};
#ifdef CONFIG_NETWORKING_IPV6_NO_ND
/* The peer is the server in our case. Just invent a mac
* address for it because lower parts of the stack cannot set it
* in this test as we do not have any radios.
*/
static uint8_t peer_mac[] = { 0x0a, 0xbe, 0xef, 0x15, 0xf0, 0x0d };
#endif
/* This is my mac address
*/
static uint8_t my_mac[] = { 0x15, 0x0a, 0xbe, 0xef, 0xf0, 0x0d };
#ifdef CONFIG_NETWORKING_WITH_IPV6
#if 0
/* 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, 0x2 } } }
/* Define the peer IP address where to send messages */
#if !defined(CONFIG_NET_TESTING)
#define PEER_IPADDR { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1 } } }
#else
#define MY_IPADDR { { { 0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0x17, 0x0a, 0xbe, 0xef, 0xf0, 0x0d, 0 } } }
#define PEER_IPADDR { { { 0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0x08, 0xbe, 0xef, 0x15, 0xf0, 0x0d, 0 } } }
#endif
#else /* ipv6 */
/* The 192.0.2.0/24 is the private address space for documentation RFC 5737 */
#define MY_IPADDR { { { 192, 0, 2, 2 } } }
#if !defined(CONFIG_NET_TESTING)
#define PEER_IPADDR { { { 192, 0, 2, 1 } } }
#endif
#endif
#define MY_PORT 8484
#define PEER_PORT 4242
#ifdef CONFIG_NETWORKING_WITH_IPV6
static const struct in6_addr in6addr_peer = PEER_IPADDR;
static struct in6_addr in6addr_my = MY_IPADDR;
#else
static struct in_addr in4addr_peer = PEER_IPADDR;
static struct in_addr in4addr_my = MY_IPADDR;
#endif
static inline void init_app(void)
{
PRINT("%s: run dtls client\n", __func__);
net_set_mac(my_mac, sizeof(my_mac));
#ifdef CONFIG_NETWORKING_WITH_IPV4
{
uip_ipaddr_t addr;
uip_ipaddr(&addr, 192,0,2,2);
uip_sethostaddr(&addr);
}
#endif
#ifdef CONFIG_NETWORKING_IPV6_NO_ND
{
uip_ipaddr_t *addr;
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);
addr = (uip_ipaddr_t *)&in6addr_my;
uip_ds6_addr_add(addr, 0, ADDR_MANUAL);
}
#if defined(CONFIG_NET_TESTING)
net_testing_setup();
#endif
}
@ -218,6 +175,12 @@ static inline bool wait_reply(const char *name,
return false;
}
#ifdef CONFIG_NETWORKING_WITH_IPV6
static const struct in6_addr in6addr_peer = PEER_IPADDR;
#else
static struct in_addr in4addr_peer = PEER_IPADDR;
#endif
static inline struct net_context *get_context(void)
{
static struct net_addr peer_addr;
@ -225,12 +188,16 @@ static inline struct net_context *get_context(void)
struct net_context *ctx;
#ifdef CONFIG_NETWORKING_WITH_IPV6
static struct in6_addr in6addr_my = IN6ADDR_ANY_INIT;
peer_addr.in6_addr = in6addr_peer;
peer_addr.family = AF_INET6;
my_addr.in6_addr = in6addr_my;
my_addr.family = AF_INET6;
#else
static struct in_addr in4addr_my = { { { 0 } } };
peer_addr.in_addr = in4addr_peer;
peer_addr.family = AF_INET;
@ -494,7 +461,7 @@ void startup(void)
}
}
PRINT("Did not receive reply, closing.\n");
PRINT("ERROR: Did not receive reply, closing.\n");
dtls_close(dtls, &session);
}