fb11e647
vrobic
reseau statique a...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/*
* Copyright (C) 2016 INRIA
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @{
*
* @author Oliver Hahm <oliver.hahm@inria.fr>
* @file
*/
#include "embUnit.h"
#include "net/ipv6/addr.h"
#include "net/ipv6/hdr.h"
#include "net/gnrc/ipv6.h"
#include "net/gnrc/pktbuf.h"
#include "unittests-constants.h"
#include "tests-gnrc_ipv6.h"
#define DEFAULT_TEST_SRC { { \
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f \
} \
}
#define DEFAULT_TEST_DST { { \
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, \
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f \
} \
}
#define DEFAULT_TEST_V_TC_FL TEST_UINT32
#define DEFAULT_TEST_LEN TEST_UINT16
#define DEFAULT_TEST_NH TEST_UINT8
#define DEFAULT_TEST_HL TEST_UINT8
static gnrc_pktsnip_t *_pkt_w_ip_hdr, *_pkt_no_ip_hdr;
static void set_up(void)
{
ipv6_hdr_t ip = (ipv6_hdr_t) {
.v_tc_fl = byteorder_htonl(DEFAULT_TEST_V_TC_FL),
.len = byteorder_htons(DEFAULT_TEST_LEN),
.nh = DEFAULT_TEST_NH,
.hl = DEFAULT_TEST_HL,
.src = DEFAULT_TEST_SRC,
.dst = DEFAULT_TEST_DST
};
ipv6_hdr_set_version(&ip);
gnrc_pktbuf_init();
_pkt_w_ip_hdr = gnrc_pktbuf_add(NULL, NULL, 1, GNRC_NETTYPE_NETIF);
assert(_pkt_w_ip_hdr);
_pkt_w_ip_hdr = gnrc_pktbuf_add(_pkt_w_ip_hdr, &ip, sizeof(ipv6_hdr_t), GNRC_NETTYPE_IPV6);
assert(_pkt_w_ip_hdr);
_pkt_w_ip_hdr = gnrc_pktbuf_add(_pkt_w_ip_hdr, NULL, 1, GNRC_NETTYPE_UNDEF);
assert(_pkt_w_ip_hdr);
_pkt_no_ip_hdr = gnrc_pktbuf_add(NULL, NULL, 1, GNRC_NETTYPE_NETIF);
assert(_pkt_no_ip_hdr);
_pkt_no_ip_hdr = gnrc_pktbuf_add(_pkt_no_ip_hdr, NULL, 1, GNRC_NETTYPE_UNDEF);
assert(_pkt_no_ip_hdr);
}
static void tear_down(void)
{
gnrc_pktbuf_release(_pkt_w_ip_hdr->next->next);
gnrc_pktbuf_release(_pkt_no_ip_hdr->next);
}
static void test_gnrc_ipv6_get_header(void)
{
TEST_ASSERT_NOT_NULL(gnrc_ipv6_get_header(_pkt_w_ip_hdr));
}
static void test_gnrc_ipv6_get_header_no_header(void)
{
TEST_ASSERT_NULL(gnrc_ipv6_get_header(_pkt_no_ip_hdr));
}
static void test_gnrc_ipv6_get_header_check_version(void)
{
ipv6_hdr_t *hdr = gnrc_ipv6_get_header(_pkt_w_ip_hdr);
TEST_ASSERT(ipv6_hdr_get_version(hdr) == 0x06);
}
static void test_gnrc_ipv6_get_header_check_len(void)
{
ipv6_hdr_t *hdr = gnrc_ipv6_get_header(_pkt_w_ip_hdr);
TEST_ASSERT(byteorder_ntohs(hdr->len) == DEFAULT_TEST_LEN);
}
static void test_gnrc_ipv6_get_header_check_nh(void)
{
ipv6_hdr_t *hdr = gnrc_ipv6_get_header(_pkt_w_ip_hdr);
TEST_ASSERT(hdr->nh == DEFAULT_TEST_NH);
}
static void test_gnrc_ipv6_get_header_check_hl(void)
{
ipv6_hdr_t *hdr = gnrc_ipv6_get_header(_pkt_w_ip_hdr);
TEST_ASSERT(hdr->hl == DEFAULT_TEST_HL);
}
static void test_gnrc_ipv6_get_header_check_src(void)
{
ipv6_hdr_t *hdr = gnrc_ipv6_get_header(_pkt_w_ip_hdr);
ipv6_addr_t addr = DEFAULT_TEST_SRC;
TEST_ASSERT(ipv6_addr_equal(&(hdr->src), &addr));
}
static void test_gnrc_ipv6_get_header_check_dst(void)
{
ipv6_hdr_t *hdr = gnrc_ipv6_get_header(_pkt_w_ip_hdr);
ipv6_addr_t addr = DEFAULT_TEST_DST;
TEST_ASSERT(ipv6_addr_equal(&(hdr->dst), &addr));
}
Test *tests_gnrc_ipv6_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_gnrc_ipv6_get_header),
new_TestFixture(test_gnrc_ipv6_get_header_no_header),
new_TestFixture(test_gnrc_ipv6_get_header_check_version),
new_TestFixture(test_gnrc_ipv6_get_header_check_len),
new_TestFixture(test_gnrc_ipv6_get_header_check_nh),
new_TestFixture(test_gnrc_ipv6_get_header_check_hl),
new_TestFixture(test_gnrc_ipv6_get_header_check_src),
new_TestFixture(test_gnrc_ipv6_get_header_check_dst),
};
EMB_UNIT_TESTCALLER(gnrc_ipv6_tests, set_up, tear_down, fixtures);
return (Test *)&gnrc_ipv6_tests;
}
void tests_gnrc_ipv6(void)
{
TESTS_RUN(tests_gnrc_ipv6_tests());
}
/** @} */
|