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 ip4_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);
43 default_netif_init(
struct netif *netif)
45 fail_unless(netif !=
NULL);
47 netif->output = etharp_output;
55 default_netif_add(
void)
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);
63 &test_gw,
NULL, default_netif_init,
NULL));
68 default_netif_remove(
void)
75 create_arp_response(ip4_addr_t *adr)
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 = ETHARP_HWADDR_LEN;
94 etharphdr->protolen =
sizeof(ip4_addr_t);
95 etharphdr->opcode =
htons(ARP_REPLY);
97 SMEMCPY(ðarphdr->sipaddr, adr,
sizeof(ip4_addr_t));
98 SMEMCPY(ðarphdr->dipaddr, &test_ipaddr,
sizeof(ip4_addr_t));
111 ethernet_input(p, &test_netif);
124 etharp_teardown(
void)
127 default_netif_remove();
135 #if ETHARP_SUPPORT_STATIC_ENTRIES 139 const ip4_addr_t *unused_ipaddr;
140 struct eth_addr *unused_ethaddr;
145 fail(
"This test needs a default netif");
151 fail_unless(pcb !=
NULL);
156 IP4_ADDR(&adrs[i], 192,168,0,i+2);
161 fail_unless(p !=
NULL);
165 ip_addr_copy_from_ip4(dst, adrs[i]);
166 err = udp_sendto(pcb, p, &dst, 123);
167 fail_unless(err ==
ERR_OK);
169 fail_unless(linkoutput_ctr == (2*i) + 1);
173 create_arp_response(&adrs[i]);
175 fail_unless(linkoutput_ctr == (2*i) + 2);
177 idx = etharp_find_addr(
NULL, &adrs[i], &unused_ethaddr, &unused_ipaddr);
178 fail_unless(idx == i);
183 #if ETHARP_SUPPORT_STATIC_ENTRIES 185 err = etharp_add_static_entry(&adrs[ARP_TABLE_SIZE], &
test_ethaddr3);
186 fail_unless(err ==
ERR_OK);
187 idx = etharp_find_addr(
NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
188 fail_unless(idx == 0);
189 fail_unless(linkoutput_ctr == 0);
196 fail_unless(p !=
NULL);
200 ip_addr_copy_from_ip4(dst, adrs[i]);
201 err = udp_sendto(pcb, p, &dst, 123);
202 fail_unless(err ==
ERR_OK);
204 fail_unless(linkoutput_ctr == (2*i) + 1);
208 create_arp_response(&adrs[i]);
210 fail_unless(linkoutput_ctr == (2*i) + 2);
212 idx = etharp_find_addr(
NULL, &adrs[i], &unused_ethaddr, &unused_ipaddr);
213 if (i < ARP_TABLE_SIZE - 1) {
214 fail_unless(idx == i+1);
217 fail_unless(idx == 1);
222 #if ETHARP_SUPPORT_STATIC_ENTRIES 224 err = etharp_add_static_entry(&adrs[ARP_TABLE_SIZE+1], &
test_ethaddr4);
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 == 2);
231 err = etharp_remove_static_entry(&adrs[ARP_TABLE_SIZE+1]);
232 fail_unless(err ==
ERR_OK);
233 idx = etharp_find_addr(
NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
234 fail_unless(idx == 0);
235 idx = etharp_find_addr(
NULL, &adrs[ARP_TABLE_SIZE+1], &unused_ethaddr, &unused_ipaddr);
236 fail_unless(idx == -1);
241 idx = etharp_find_addr(
NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
242 fail_unless(idx == 0);
244 #if ETHARP_SUPPORT_STATIC_ENTRIES 246 err = etharp_remove_static_entry(&adrs[ARP_TABLE_SIZE]);
247 fail_unless(err ==
ERR_OK);
248 idx = etharp_find_addr(
NULL, &adrs[ARP_TABLE_SIZE], &unused_ethaddr, &unused_ipaddr);
249 fail_unless(idx == -1);
250 idx = etharp_find_addr(
NULL, &adrs[ARP_TABLE_SIZE+1], &unused_ethaddr, &unused_ipaddr);
251 fail_unless(idx == -1);
267 return create_suite(
"ETHARP", tests,
sizeof(tests)/
sizeof(
testfunc), etharp_setup, etharp_teardown);
struct netif * netif_default
struct eth_addr test_ethaddr2
#define NETIF_FLAG_LINK_UP
void netif_set_default(struct netif *netif)
#define SMEMCPY(dst, src, len)
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
void netif_set_up(struct netif *netif)
netif_linkoutput_fn linkoutput
u8_t pbuf_free(struct pbuf *p)
#define NETIF_FLAG_ETHARP
struct eth_addr test_ethaddr4
Suite * create_suite(const char *name, testfunc *tests, size_t num_tests, SFun setup, SFun teardown)
#define NETIF_FLAG_BROADCAST
void netif_remove(struct netif *netif)
struct eth_addr test_ethaddr3
struct netif * netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
END_TEST Suite * etharp_suite(void)
struct eth_addr test_ethaddr
START_TEST(test_etharp_table)
#define LWIP_UNUSED_ARG(x)