ReactOS 0.4.15-dev-7961-gdcf9eb0
test_etharp.c File Reference
#include "test_etharp.h"
#include "lwip/udp.h"
#include "netif/etharp.h"
#include "lwip/stats.h"
Include dependency graph for test_etharp.c:

Go to the source code of this file.

Functions

static void etharp_remove_all (void)
 
static err_t default_netif_linkoutput (struct netif *netif, struct pbuf *p)
 
static err_t default_netif_init (struct netif *netif)
 
static void default_netif_add (void)
 
static void default_netif_remove (void)
 
static void create_arp_response (ip_addr_t *adr)
 
static void etharp_setup (void)
 
static void etharp_teardown (void)
 
 START_TEST (test_etharp_table)
 
END_TEST Suite * etharp_suite (void)
 

Variables

static struct netif test_netif
 
static ip_addr_t test_ipaddr
 
static ip_addr_t test_netmask
 
static ip_addr_t test_gw
 
struct eth_addr test_ethaddr = {1,1,1,1,1,1}
 
struct eth_addr test_ethaddr2 = {1,1,1,1,1,2}
 
struct eth_addr test_ethaddr3 = {1,1,1,1,1,3}
 
struct eth_addr test_ethaddr4 = {1,1,1,1,1,4}
 
static int linkoutput_ctr
 

Function Documentation

◆ create_arp_response()

static void create_arp_response ( ip_addr_t adr)
static

Definition at line 75 of file test_etharp.c.

76{
77 int k;
78 struct eth_hdr *ethhdr;
79 struct etharp_hdr *etharphdr;
80 struct pbuf *p = pbuf_alloc(PBUF_RAW, sizeof(struct eth_hdr) + sizeof(struct etharp_hdr), PBUF_RAM);
81 if(p == NULL) {
82 FAIL_RET();
83 }
84 ethhdr = (struct eth_hdr*)p->payload;
85 etharphdr = (struct etharp_hdr*)(ethhdr + 1);
86
87 ethhdr->dest = test_ethaddr;
88 ethhdr->src = test_ethaddr2;
89 ethhdr->type = htons(ETHTYPE_ARP);
90
91 etharphdr->hwtype = htons(/*HWTYPE_ETHERNET*/ 1);
92 etharphdr->proto = htons(ETHTYPE_IP);
93 etharphdr->hwlen = ETHARP_HWADDR_LEN;
94 etharphdr->protolen = sizeof(ip_addr_t);
95 etharphdr->opcode = htons(ARP_REPLY);
96
97 SMEMCPY(&etharphdr->sipaddr, adr, sizeof(ip_addr_t));
98 SMEMCPY(&etharphdr->dipaddr, &test_ipaddr, sizeof(ip_addr_t));
99
100 k = 6;
101 while(k > 0) {
102 k--;
103 /* Write the ARP MAC-Addresses */
104 etharphdr->shwaddr.addr[k] = test_ethaddr2.addr[k];
105 etharphdr->dhwaddr.addr[k] = test_ethaddr.addr[k];
106 /* Write the Ethernet MAC-Addresses */
107 ethhdr->dest.addr[k] = test_ethaddr.addr[k];
108 ethhdr->src.addr[k] = test_ethaddr2.addr[k];
109 }
110
111 ethernet_input(p, &test_netif);
112}
#define NULL
Definition: types.h:112
GLfloat GLfloat p
Definition: glext.h:8902
typedefPACK_STRUCT_END struct ip_addr ip_addr_t
Definition: ip_addr.h:64
#define FAIL_RET()
Definition: lwip_check.h:10
#define htons(x)
Definition: module.h:215
int k
Definition: mpi.c:3369
#define SMEMCPY(dst, src, len)
Definition: opt.h:92
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
Definition: pbuf.c:207
@ PBUF_RAM
Definition: pbuf.h:58
@ PBUF_RAW
Definition: pbuf.h:54
Definition: pbuf.h:79
struct eth_addr test_ethaddr2
Definition: test_etharp.c:17
static struct netif test_netif
Definition: test_etharp.c:14
static ip_addr_t test_ipaddr
Definition: test_etharp.c:15
struct eth_addr test_ethaddr
Definition: test_etharp.c:16

Referenced by START_TEST().

◆ default_netif_add()

static void default_netif_add ( void  )
static

Definition at line 55 of file test_etharp.c.

56{
57 IP4_ADDR(&test_gw, 192,168,0,1);
58 IP4_ADDR(&test_ipaddr, 192,168,0,1);
59 IP4_ADDR(&test_netmask, 255,255,0,0);
60
61 fail_unless(netif_default == NULL);
65}
#define IP4_ADDR(ipaddr, a, b, c, d)
Definition: ip_addr.h:139
struct netif * netif_default
Definition: netif.c:76
struct netif * netif_add(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw, void *state, netif_init_fn init, netif_input_fn input)
Definition: netif.c:139
void netif_set_default(struct netif *netif)
Definition: netif.c:430
void netif_set_up(struct netif *netif)
Definition: netif.c:453
static ip_addr_t test_netmask
Definition: test_etharp.c:15
static err_t default_netif_init(struct netif *netif)
Definition: test_etharp.c:43
static ip_addr_t test_gw
Definition: test_etharp.c:15

Referenced by etharp_setup().

◆ default_netif_init()

static err_t default_netif_init ( struct netif netif)
static

Definition at line 43 of file test_etharp.c.

44{
45 fail_unless(netif != NULL);
47 netif->output = etharp_output;
48 netif->mtu = 1500;
50 netif->hwaddr_len = ETHARP_HWADDR_LEN;
51 return ERR_OK;
52}
#define ERR_OK
Definition: err.h:52
#define NETIF_FLAG_LINK_UP
Definition: netif.h:84
#define NETIF_FLAG_ETHARP
Definition: netif.h:88
#define NETIF_FLAG_BROADCAST
Definition: netif.h:72
Definition: netif.h:136
u8_t flags
Definition: netif.h:192
netif_output_fn output
Definition: netif.h:151
u16_t mtu
Definition: netif.h:186
netif_linkoutput_fn linkoutput
Definition: netif.h:155
u8_t hwaddr_len
Definition: netif.h:188
static err_t default_netif_linkoutput(struct netif *netif, struct pbuf *p)
Definition: test_etharp.c:34

Referenced by default_netif_add().

◆ default_netif_linkoutput()

static err_t default_netif_linkoutput ( struct netif netif,
struct pbuf p 
)
static

Definition at line 34 of file test_etharp.c.

35{
36 fail_unless(netif == &test_netif);
37 fail_unless(p != NULL);
39 return ERR_OK;
40}
static int linkoutput_ctr
Definition: test_etharp.c:20

Referenced by default_netif_init().

◆ default_netif_remove()

static void default_netif_remove ( void  )
static

Definition at line 68 of file test_etharp.c.

69{
70 fail_unless(netif_default == &test_netif);
72}
void netif_remove(struct netif *netif)
Definition: netif.c:235

Referenced by etharp_teardown().

◆ etharp_remove_all()

static void etharp_remove_all ( void  )
static

Definition at line 24 of file test_etharp.c.

25{
26 int i;
27 /* call etharp_tmr often enough to have all entries cleaned */
28 for(i = 0; i < 0xff; i++) {
29 etharp_tmr();
30 }
31}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248

Referenced by etharp_setup(), etharp_teardown(), and START_TEST().

◆ etharp_setup()

static void etharp_setup ( void  )
static

Definition at line 117 of file test_etharp.c.

118{
121}
static void etharp_remove_all(void)
Definition: test_etharp.c:24
static void default_netif_add(void)
Definition: test_etharp.c:55

Referenced by etharp_suite().

◆ etharp_suite()

END_TEST Suite * etharp_suite ( void  )

Create the suite including all tests for this module

Definition at line 256 of file test_etharp.c.

257{
258 TFun tests[] = {
259 test_etharp_table
260 };
261 return create_suite("ETHARP", tests, sizeof(tests)/sizeof(TFun), etharp_setup, etharp_teardown);
262}
static Suite * create_suite(const char *name, TFun *tests, size_t num_tests, SFun setup, SFun teardown)
Definition: lwip_check.h:20
static struct test_info tests[]
static void etharp_setup(void)
Definition: test_etharp.c:117
static void etharp_teardown(void)
Definition: test_etharp.c:124

Referenced by main().

◆ etharp_teardown()

static void etharp_teardown ( void  )
static

Definition at line 124 of file test_etharp.c.

125{
128}
static void default_netif_remove(void)
Definition: test_etharp.c:68

Referenced by etharp_suite().

◆ START_TEST()

START_TEST ( test_etharp_table  )

Definition at line 133 of file test_etharp.c.

134{
135#if ETHARP_SUPPORT_STATIC_ENTRIES
136 err_t err;
137#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
138 s8_t idx;
139 ip_addr_t *unused_ipaddr;
140 struct eth_addr *unused_ethaddr;
141 struct udp_pcb* pcb;
142 LWIP_UNUSED_ARG(_i);
143
144 if (netif_default != &test_netif) {
145 fail("This test needs a default netif");
146 }
147
148 linkoutput_ctr = 0;
149
150 pcb = udp_new();
151 fail_unless(pcb != NULL);
152 if (pcb != NULL) {
153 ip_addr_t adrs[ARP_TABLE_SIZE + 2];
154 int i;
155 for(i = 0; i < ARP_TABLE_SIZE + 2; i++) {
156 IP4_ADDR(&adrs[i], 192,168,0,i+2);
157 }
158 /* fill ARP-table with dynamic entries */
159 for(i = 0; i < ARP_TABLE_SIZE; i++) {
160 struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, 10, PBUF_RAM);
161 fail_unless(p != NULL);
162 if (p != NULL) {
163 err_t err = udp_sendto(pcb, p, &adrs[i], 123);
164 fail_unless(err == ERR_OK);
165 /* etharp request sent? */
166 fail_unless(linkoutput_ctr == (2*i) + 1);
167 pbuf_free(p);
168
169 /* create an ARP response */
170 create_arp_response(&adrs[i]);
171 /* queued UDP packet sent? */
172 fail_unless(linkoutput_ctr == (2*i) + 2);
173
174 idx = etharp_find_addr(NULL, &adrs[i], &unused_ethaddr, &unused_ipaddr);
175 fail_unless(idx == i);
176 etharp_tmr();
177 }
178 }
179 linkoutput_ctr = 0;
180#if ETHARP_SUPPORT_STATIC_ENTRIES
181 /* create one static entry */
182 err = etharp_add_static_entry(&adrs[ARP_TABLE_SIZE], &test_ethaddr3);
183 fail_unless(err == ERR_OK);
184 idx = etharp_find_addr(NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
185 fail_unless(idx == 0);
186 fail_unless(linkoutput_ctr == 0);
187#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
188
189 linkoutput_ctr = 0;
190 /* fill ARP-table with dynamic entries */
191 for(i = 0; i < ARP_TABLE_SIZE; i++) {
192 struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, 10, PBUF_RAM);
193 fail_unless(p != NULL);
194 if (p != NULL) {
195 err_t err = udp_sendto(pcb, p, &adrs[i], 123);
196 fail_unless(err == ERR_OK);
197 /* etharp request sent? */
198 fail_unless(linkoutput_ctr == (2*i) + 1);
199 pbuf_free(p);
200
201 /* create an ARP response */
202 create_arp_response(&adrs[i]);
203 /* queued UDP packet sent? */
204 fail_unless(linkoutput_ctr == (2*i) + 2);
205
206 idx = etharp_find_addr(NULL, &adrs[i], &unused_ethaddr, &unused_ipaddr);
207 if (i < ARP_TABLE_SIZE - 1) {
208 fail_unless(idx == i+1);
209 } else {
210 /* the last entry must not overwrite the static entry! */
211 fail_unless(idx == 1);
212 }
213 etharp_tmr();
214 }
215 }
216#if ETHARP_SUPPORT_STATIC_ENTRIES
217 /* create a second static entry */
218 err = etharp_add_static_entry(&adrs[ARP_TABLE_SIZE+1], &test_ethaddr4);
219 fail_unless(err == ERR_OK);
220 idx = etharp_find_addr(NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
221 fail_unless(idx == 0);
222 idx = etharp_find_addr(NULL, &adrs[ARP_TABLE_SIZE+1], &unused_ethaddr, &unused_ipaddr);
223 fail_unless(idx == 2);
224 /* and remove it again */
225 err = etharp_remove_static_entry(&adrs[ARP_TABLE_SIZE+1]);
226 fail_unless(err == ERR_OK);
227 idx = etharp_find_addr(NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
228 fail_unless(idx == 0);
229 idx = etharp_find_addr(NULL, &adrs[ARP_TABLE_SIZE+1], &unused_ethaddr, &unused_ipaddr);
230 fail_unless(idx == -1);
231#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
232
233 /* check that static entries don't time out */
235 idx = etharp_find_addr(NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
236 fail_unless(idx == 0);
237
238#if ETHARP_SUPPORT_STATIC_ENTRIES
239 /* remove the first static entry */
240 err = etharp_remove_static_entry(&adrs[ARP_TABLE_SIZE]);
241 fail_unless(err == ERR_OK);
242 idx = etharp_find_addr(NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
243 fail_unless(idx == -1);
244 idx = etharp_find_addr(NULL, &adrs[ARP_TABLE_SIZE+1], &unused_ethaddr, &unused_ipaddr);
245 fail_unless(idx == -1);
246#endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
247
248 udp_remove(pcb);
249 }
250}
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:73
unsigned int idx
Definition: utils.c:41
signed char s8_t
Definition: cc.h:28
s8_t err_t
Definition: err.h:47
#define ARP_TABLE_SIZE
Definition: opt.h:433
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:618
@ PBUF_TRANSPORT
Definition: pbuf.h:51
#define err(...)
struct eth_addr test_ethaddr3
Definition: test_etharp.c:18
static void create_arp_response(ip_addr_t *adr)
Definition: test_etharp.c:75
struct eth_addr test_ethaddr4
Definition: test_etharp.c:19

Variable Documentation

◆ linkoutput_ctr

int linkoutput_ctr
static

Definition at line 20 of file test_etharp.c.

Referenced by default_netif_linkoutput(), and START_TEST().

◆ test_ethaddr

struct eth_addr test_ethaddr = {1,1,1,1,1,1}

Definition at line 16 of file test_etharp.c.

Referenced by create_arp_response().

◆ test_ethaddr2

struct eth_addr test_ethaddr2 = {1,1,1,1,1,2}

Definition at line 17 of file test_etharp.c.

Referenced by create_arp_response().

◆ test_ethaddr3

struct eth_addr test_ethaddr3 = {1,1,1,1,1,3}

Definition at line 18 of file test_etharp.c.

Referenced by START_TEST().

◆ test_ethaddr4

struct eth_addr test_ethaddr4 = {1,1,1,1,1,4}

Definition at line 19 of file test_etharp.c.

Referenced by START_TEST().

◆ test_gw

ip_addr_t test_gw
static

Definition at line 15 of file test_etharp.c.

Referenced by default_netif_add().

◆ test_ipaddr

ip_addr_t test_ipaddr
static

Definition at line 15 of file test_etharp.c.

Referenced by create_arp_response(), and default_netif_add().

◆ test_netif

◆ test_netmask

ip_addr_t test_netmask
static

Definition at line 15 of file test_etharp.c.

Referenced by default_netif_add().