7 #if !LWIP_STATS || !UDP_STATS || !MEMP_STATS || !ETHARP_STATS
8 #error "This tests needs UDP-, MEMP- and ETHARP-statistics enabled"
10 #if !ETHARP_SUPPORT_STATIC_ENTRIES
11 #error "This test needs ETHARP_SUPPORT_STATIC_ENTRIES enabled"
14 static struct netif test_netif;
15 static ip_addr_t test_ipaddr, test_netmask, test_gw;
20 static int linkoutput_ctr;
24 etharp_remove_all(
void)
28 for(i = 0; i < 0xff; i++) {
36 fail_unless(netif == &test_netif);
37 fail_unless(p !=
NULL);
45 fail_unless(netif !=
NULL);
47 netif->
output = etharp_output;
55 default_netif_add(
void)
59 IP4_ADDR(&test_netmask, 255,255,0,0);
63 &test_gw,
NULL, default_netif_init,
NULL));
68 default_netif_remove(
void)
78 struct eth_hdr *ethhdr;
79 struct etharp_hdr *etharphdr;
84 ethhdr = (
struct eth_hdr*)p->
payload;
85 etharphdr = (
struct etharp_hdr*)(ethhdr + 1);
89 ethhdr->type =
htons(ETHTYPE_ARP);
91 etharphdr->hwtype =
htons( 1);
92 etharphdr->proto =
htons(ETHTYPE_IP);
93 etharphdr->_hwlen_protolen =
htons((ETHARP_HWADDR_LEN << 8) |
sizeof(
ip_addr_t));
94 etharphdr->opcode =
htons(ARP_REPLY);
110 ethernet_input(p, &test_netif);
123 etharp_teardown(
void)
126 default_netif_remove();
134 #if ETHARP_SUPPORT_STATIC_ENTRIES
139 struct eth_addr *unused_ethaddr;
144 fail(
"This test needs a default netif");
150 fail_unless(pcb !=
NULL);
160 fail_unless(p !=
NULL);
162 err_t err = udp_sendto(pcb, p, &adrs[i], 123);
163 fail_unless(err ==
ERR_OK);
165 fail_unless(linkoutput_ctr == (2*i) + 1);
169 create_arp_response(&adrs[i]);
171 fail_unless(linkoutput_ctr == (2*i) + 2);
173 idx = etharp_find_addr(
NULL, &adrs[i], &unused_ethaddr, &unused_ipaddr);
174 fail_unless(idx == i);
179 #if ETHARP_SUPPORT_STATIC_ENTRIES
181 err = etharp_add_static_entry(&adrs[ARP_TABLE_SIZE], &
test_ethaddr3);
182 fail_unless(err ==
ERR_OK);
183 idx = etharp_find_addr(
NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
184 fail_unless(idx == 0);
185 fail_unless(linkoutput_ctr == 0);
192 fail_unless(p !=
NULL);
194 err_t err = udp_sendto(pcb, p, &adrs[i], 123);
195 fail_unless(err ==
ERR_OK);
197 fail_unless(linkoutput_ctr == (2*i) + 1);
201 create_arp_response(&adrs[i]);
203 fail_unless(linkoutput_ctr == (2*i) + 2);
205 idx = etharp_find_addr(
NULL, &adrs[i], &unused_ethaddr, &unused_ipaddr);
206 if (i < ARP_TABLE_SIZE - 1) {
207 fail_unless(idx == i+1);
210 fail_unless(idx == 1);
215 #if ETHARP_SUPPORT_STATIC_ENTRIES
217 err = etharp_add_static_entry(&adrs[ARP_TABLE_SIZE+1], &
test_ethaddr4);
218 fail_unless(err ==
ERR_OK);
219 idx = etharp_find_addr(
NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
220 fail_unless(idx == 0);
221 idx = etharp_find_addr(
NULL, &adrs[ARP_TABLE_SIZE+1], &unused_ethaddr, &unused_ipaddr);
222 fail_unless(idx == 2);
224 err = etharp_remove_static_entry(&adrs[ARP_TABLE_SIZE+1]);
225 fail_unless(err ==
ERR_OK);
226 idx = etharp_find_addr(
NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
227 fail_unless(idx == 0);
228 idx = etharp_find_addr(
NULL, &adrs[ARP_TABLE_SIZE+1], &unused_ethaddr, &unused_ipaddr);
229 fail_unless(idx == -1);
234 idx = etharp_find_addr(
NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
235 fail_unless(idx == 0);
237 #if ETHARP_SUPPORT_STATIC_ENTRIES
239 err = etharp_remove_static_entry(&adrs[ARP_TABLE_SIZE]);
240 fail_unless(err ==
ERR_OK);
241 idx = etharp_find_addr(
NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
242 fail_unless(idx == -1);
243 idx = etharp_find_addr(
NULL, &adrs[ARP_TABLE_SIZE+1], &unused_ethaddr, &unused_ipaddr);
244 fail_unless(idx == -1);
260 return create_suite(
"ETHARP", tests,
sizeof(tests)/
sizeof(TFun), etharp_setup, etharp_teardown);