net: tests: Add IPv6 address manipulation unit tests
Change-Id: Ide3bce35dcfd3ec31bfe3cd842a87ca3b639ba4f Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
208d558f68
commit
eb87a36e44
2 changed files with 147 additions and 0 deletions
|
@ -9,3 +9,4 @@ CONFIG_NET_NBUF_TX_COUNT=2
|
|||
CONFIG_NET_NBUF_DATA_COUNT=5
|
||||
CONFIG_NET_LOG=y
|
||||
CONFIG_SYS_LOG_SHOW_COLOR=y
|
||||
CONFIG_TEST_RANDOM_GENERATOR=y
|
||||
|
|
|
@ -21,9 +21,12 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <device.h>
|
||||
#include <init.h>
|
||||
#include <misc/printk.h>
|
||||
#include <net/net_core.h>
|
||||
#include <net/nbuf.h>
|
||||
#include <net/net_ip.h>
|
||||
|
||||
#define NET_DEBUG 1
|
||||
#include "net_private.h"
|
||||
|
@ -104,12 +107,78 @@
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
extern struct net_if __net_if_start[];
|
||||
|
||||
struct net_test_context {
|
||||
uint8_t mac_addr[6];
|
||||
struct net_linkaddr ll_addr;
|
||||
};
|
||||
|
||||
int net_test_init(struct device *dev)
|
||||
{
|
||||
struct net_test_context *net_test_context = dev->driver_data;
|
||||
|
||||
dev->driver_api = NULL;
|
||||
net_test_context = net_test_context;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t *net_test_get_mac(struct device *dev)
|
||||
{
|
||||
struct net_test_context *context = dev->driver_data;
|
||||
|
||||
if (context->mac_addr[0] == 0x00) {
|
||||
/* 10-00-00-00-00 to 10-00-00-00-FF Documentation RFC7042 */
|
||||
context->mac_addr[0] = 0x10;
|
||||
context->mac_addr[1] = 0x00;
|
||||
context->mac_addr[2] = 0x00;
|
||||
context->mac_addr[3] = 0x00;
|
||||
context->mac_addr[4] = 0x00;
|
||||
context->mac_addr[5] = sys_rand32_get();
|
||||
}
|
||||
|
||||
return context->mac_addr;
|
||||
}
|
||||
|
||||
static void net_test_iface_init(struct net_if *iface)
|
||||
{
|
||||
uint8_t *mac = net_test_get_mac(net_if_get_device(iface));
|
||||
|
||||
net_if_set_link_addr(iface, mac, 8);
|
||||
}
|
||||
|
||||
struct net_test_context net_test_context_data;
|
||||
|
||||
static struct net_if_api net_test_if_api = {
|
||||
.init = net_test_iface_init
|
||||
};
|
||||
|
||||
NET_DEVICE_INIT(net_addr_test, "net_addr_test",
|
||||
net_test_init, &net_test_context_data, NULL,
|
||||
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
|
||||
&net_test_if_api, 127);
|
||||
|
||||
#ifdef CONFIG_MICROKERNEL
|
||||
void mainloop(void)
|
||||
#else
|
||||
void main(void)
|
||||
#endif
|
||||
{
|
||||
struct in6_addr loopback = IN6ADDR_LOOPBACK_INIT;
|
||||
struct in6_addr mcast = { { { 0xff, 0x84, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0x2 } } };
|
||||
struct in6_addr addr6 = { { { 0xfe, 0x80, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0x1 } } };
|
||||
struct in6_addr addr6_pref1 = { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0x1 } } };
|
||||
struct in6_addr addr6_pref2 = { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0x2 } } };
|
||||
struct in6_addr addr6_pref3 = { { { 0x20, 0x01, 0x0d, 0xb8, 0x64, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0x2 } } };
|
||||
struct net_if_addr *ifaddr1, *ifaddr2;
|
||||
struct net_if_mcast_addr *ifmaddr1;
|
||||
|
||||
TEST_BYTE_1(0xde, "DE");
|
||||
TEST_BYTE_1(0x09, "09");
|
||||
TEST_BYTE_2(0xa9, "a9");
|
||||
|
@ -146,4 +215,81 @@ void main(void)
|
|||
TEST_IPV4(127, 0, 0, 1, "127.0.0.1");
|
||||
|
||||
printk("IP address print tests passed\n");
|
||||
|
||||
if (!net_is_ipv6_addr_loopback(&loopback)) {
|
||||
printk("IPv6 loopback address check failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!net_is_ipv6_addr_mcast(&mcast)) {
|
||||
printk("IPv6 multicast address check failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ifaddr1 = net_if_ipv6_addr_add(__net_if_start,
|
||||
&addr6,
|
||||
NET_ADDR_MANUAL,
|
||||
0);
|
||||
if (!ifaddr1) {
|
||||
printk("IPv6 interface address add failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ifaddr2 = net_if_ipv6_addr_lookup(&addr6);
|
||||
if (ifaddr1 != ifaddr2) {
|
||||
printk("IPv6 interface address mismatch\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (net_is_my_ipv6_addr(&loopback)) {
|
||||
printk("My IPv6 loopback address check failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!net_is_my_ipv6_addr(&addr6)) {
|
||||
printk("My IPv6 address check failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!net_is_ipv6_prefix((uint8_t *)&addr6_pref1,
|
||||
(uint8_t *)&addr6_pref2,
|
||||
64)) {
|
||||
printk("Same IPv6 prefix test failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (net_is_ipv6_prefix((uint8_t *)&addr6_pref1,
|
||||
(uint8_t *)&addr6_pref3,
|
||||
64)) {
|
||||
printk("Different IPv6 prefix test failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (net_is_ipv6_prefix((uint8_t *)&addr6_pref1,
|
||||
(uint8_t *)&addr6_pref2,
|
||||
128)) {
|
||||
printk("Different full IPv6 prefix test failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (net_is_ipv6_prefix((uint8_t *)&addr6_pref1,
|
||||
(uint8_t *)&addr6_pref3,
|
||||
255)) {
|
||||
printk("Too long prefix test failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ifmaddr1 = net_if_ipv6_maddr_add(__net_if_start, &mcast);
|
||||
if (!ifmaddr1) {
|
||||
printk("IPv6 multicast address add failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ifmaddr1 = net_if_ipv6_maddr_add(__net_if_start, &addr6);
|
||||
if (ifmaddr1) {
|
||||
printk("IPv6 multicast address could be added failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printk("IP address checks passed\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue