ReactOS 0.4.16-dev-297-gc569aee
test_etharp.c File Reference
#include "test_etharp.h"
#include "lwip/udp.h"
#include "lwip/etharp.h"
#include "lwip/inet.h"
#include "netif/ethernet.h"
#include "lwip/stats.h"
#include "lwip/prot/iana.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 (ip4_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 ip4_addr_t test_ipaddr
 
static ip4_addr_t test_netmask
 
static ip4_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 ( ip4_addr_t *  adr)
static

Definition at line 78 of file test_etharp.c.

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

Referenced by START_TEST().

◆ default_netif_add()

static void default_netif_add ( void  )
static

Definition at line 58 of file test_etharp.c.

59{
60 IP4_ADDR(&test_gw, 192,168,0,1);
61 IP4_ADDR(&test_ipaddr, 192,168,0,1);
62 IP4_ADDR(&test_netmask, 255,255,0,0);
63
64 fail_unless(netif_default == NULL);
68}
struct netif * netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
Definition: netif.c:287
void netif_set_default(struct netif *netif)
Definition: netif.c:849
void netif_set_up(struct netif *netif)
Definition: netif.c:871
struct netif * netif_default
Definition: netif.c:115
static ip4_addr_t test_netmask
Definition: test_etharp.c:18
static ip4_addr_t test_gw
Definition: test_etharp.c:18
static err_t default_netif_init(struct netif *netif)
Definition: test_etharp.c:46

Referenced by etharp_setup().

◆ default_netif_init()

static err_t default_netif_init ( struct netif netif)
static

Definition at line 46 of file test_etharp.c.

47{
48 fail_unless(netif != NULL);
50 netif->output = etharp_output;
51 netif->mtu = 1500;
54 return ERR_OK;
55}
@ ERR_OK
Definition: err.h:55
#define NETIF_FLAG_LINK_UP
Definition: netif.h:93
#define NETIF_FLAG_ETHARP
Definition: netif.h:97
#define NETIF_FLAG_BROADCAST
Definition: netif.h:87
Definition: netif.h:269
u8_t flags
Definition: netif.h:354
u16_t mtu
Definition: netif.h:344
netif_linkoutput_fn linkoutput
Definition: netif.h:308
u8_t hwaddr_len
Definition: netif.h:352
static err_t default_netif_linkoutput(struct netif *netif, struct pbuf *p)
Definition: test_etharp.c:37

Referenced by default_netif_add().

◆ default_netif_linkoutput()

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

Definition at line 37 of file test_etharp.c.

38{
39 fail_unless(netif == &test_netif);
40 fail_unless(p != NULL);
42 return ERR_OK;
43}
static int linkoutput_ctr
Definition: test_etharp.c:23

Referenced by default_netif_init().

◆ default_netif_remove()

static void default_netif_remove ( void  )
static

Definition at line 71 of file test_etharp.c.

72{
73 fail_unless(netif_default == &test_netif);
75}
void netif_remove(struct netif *netif)
Definition: netif.c:764

Referenced by etharp_teardown().

◆ etharp_remove_all()

static void etharp_remove_all ( void  )
static

Definition at line 27 of file test_etharp.c.

28{
29 int i;
30 /* call etharp_tmr often enough to have all entries cleaned */
31 for(i = 0; i < 0xff; i++) {
32 etharp_tmr();
33 }
34}
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 120 of file test_etharp.c.

121{
124 lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
125}
#define SKIP_POOL(x)
Definition: lwip_check.h:48
void lwip_check_ensure_no_alloc(unsigned int skip)
static void etharp_remove_all(void)
Definition: test_etharp.c:27
static void default_netif_add(void)
Definition: test_etharp.c:58

Referenced by etharp_suite().

◆ etharp_suite()

END_TEST Suite * etharp_suite ( void  )

Create the suite including all tests for this module

Definition at line 267 of file test_etharp.c.

268{
269 testfunc tests[] = {
270 TESTFUNC(test_etharp_table)
271 };
272 return create_suite("ETHARP", tests, sizeof(tests)/sizeof(testfunc), etharp_setup, etharp_teardown);
273}
Suite * create_suite(const char *name, testfunc *tests, size_t num_tests, SFun setup, SFun teardown)
#define TESTFUNC(x)
Definition: lwip_check.h:22
static struct test_info tests[]
static void etharp_setup(void)
Definition: test_etharp.c:120
static void etharp_teardown(void)
Definition: test_etharp.c:128

Referenced by main().

◆ etharp_teardown()

static void etharp_teardown ( void  )
static

Definition at line 128 of file test_etharp.c.

129{
132 lwip_check_ensure_no_alloc(SKIP_POOL(MEMP_SYS_TIMEOUT));
133}
static void default_netif_remove(void)
Definition: test_etharp.c:71

Referenced by etharp_suite().

◆ START_TEST()

START_TEST ( test_etharp_table  )

Definition at line 138 of file test_etharp.c.

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

Variable Documentation

◆ linkoutput_ctr

int linkoutput_ctr
static

Definition at line 23 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 19 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 20 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 21 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 22 of file test_etharp.c.

Referenced by START_TEST().

◆ test_gw

ip4_addr_t test_gw
static

Definition at line 18 of file test_etharp.c.

Referenced by default_netif_add().

◆ test_ipaddr

ip4_addr_t test_ipaddr
static

Definition at line 18 of file test_etharp.c.

Referenced by create_arp_response(), and default_netif_add().

◆ test_netif

◆ test_netmask