Free (GPLv2) TCP/IP stack developed by TASS Belgium
Dependents: lpc1768-picotcp-demo ZeroMQ_PicoTCP_Publisher_demo TCPSocket_HelloWorld_PicoTCP Pico_TCP_UDP_Test ... more
PicoTCP. Copyright (c) 2013 TASS Belgium NV.
Released under the GNU General Public License, version 2.
Different licensing models may exist, at the sole discretion of the Copyright holders.
Official homepage: http://www.picotcp.com
Bug tracker: https://github.com/tass-belgium/picotcp/issues
Development steps:
initial integration with mbed RTOSgeneric mbed Ethernet driverhigh performance NXP LPC1768 specific Ethernet driverMulti-threading support for mbed RTOSBerkeley sockets and integration with the New Socket APIFork of the apps running on top of the New Socket APIScheduling optimizations- Debugging/benchmarking/testing
Demo application (measuring TCP sender performance):
Import programlpc1768-picotcp-demo
A PicoTCP demo app testing the ethernet throughput on the lpc1768 mbed board.
Diff: modules/pico_arp.c
- Revision:
- 152:a3d286bf94e5
- Parent:
- 149:5f4cb161cec3
- Child:
- 154:6c0e92a80c4a
--- a/modules/pico_arp.c Wed Apr 09 17:32:25 2014 +0200 +++ b/modules/pico_arp.c Mon Sep 28 13:16:18 2015 +0200 @@ -1,5 +1,5 @@ /********************************************************************* - PicoTCP. Copyright (c) 2012 TASS Belgium NV. Some rights reserved. + PicoTCP. Copyright (c) 2012-2015 Altran Intelligent Systems. Some rights reserved. See LICENSE and COPYING for usage. . @@ -18,6 +18,7 @@ extern const uint8_t PICO_ETHADDR_ALL[6]; #define PICO_ARP_TIMEOUT 600000llu #define PICO_ARP_RETRY 300lu +#define PICO_ARP_MAX_PENDING 5 #ifdef DEBUG_ARP #define arp_dbg dbg @@ -25,24 +26,24 @@ #define arp_dbg(...) do {} while(0) #endif -static struct pico_queue pending; -static int pending_timer_on = 0; static int max_arp_reqs = PICO_ARP_MAX_RATE; - +static struct pico_frame *frames_queued[PICO_ARP_MAX_PENDING] = { }; -static void check_pending(pico_time now, void *_unused) +static void pico_arp_queued_trigger(void) { - struct pico_frame *f = pico_dequeue(&pending); - IGNORE_PARAMETER(now); - IGNORE_PARAMETER(_unused); - if (!f) { - pending_timer_on = 0; - return; + int i; + struct pico_frame *f; + for (i = 0; i < PICO_ARP_MAX_PENDING; i++) + { + f = frames_queued[i]; + if (f) { + if (!pico_ethernet_send(f)) + { + pico_frame_discard(f); + frames_queued[i] = NULL; + } + } } - - pico_ethernet_send(f); - - pico_timer_add(PICO_ARP_RETRY, &check_pending, NULL); } static void update_max_arp_reqs(pico_time now, void *unused) @@ -116,12 +117,7 @@ static int arp_compare(void *ka, void *kb) { struct pico_arp *a = ka, *b = kb; - if (a->ipv4.addr < b->ipv4.addr) - return -1; - else if (a->ipv4.addr > b->ipv4.addr) - return 1; - - return 0; + return pico_ipv4_compare(&a->ipv4, &b->ipv4); } PICO_TREE_DECLARE(arp_tree, arp_compare); @@ -153,21 +149,41 @@ return NULL; } -void pico_arp_retry(struct pico_frame *f, struct pico_ip4 *where) +static void pico_arp_unreachable(struct pico_ip4 *a) +{ + int i; + struct pico_frame *f; + struct pico_ipv4_hdr *hdr; + struct pico_ip4 dst; + for (i = 0; i < PICO_ARP_MAX_PENDING; i++) + { + f = frames_queued[i]; + if (f) { + hdr = (struct pico_ipv4_hdr *) f->net_hdr; + dst = pico_ipv4_route_get_gateway(&hdr->dst); + if (!dst.addr) + dst.addr = hdr->dst.addr; + + if (dst.addr == a->addr) { + if (!pico_source_is_local(f)) { + pico_notify_dest_unreachable(f); + } + + pico_frame_discard(f); + frames_queued[i] = NULL; + } + } + } +} + +static void pico_arp_retry(struct pico_frame *f, struct pico_ip4 *where) { if (++f->failure_count < 4) { arp_dbg ("================= ARP REQUIRED: %d =============\n\n", f->failure_count); /* check if dst is local (gateway = 0), or if to use gateway */ pico_arp_request(f->dev, where, PICO_ARP_QUERY); - pico_enqueue(&pending, f); - if (!pending_timer_on) { - pending_timer_on++; - pico_timer_add(PICO_ARP_RETRY, &check_pending, NULL); - } } else { - dbg("ARP: Destination Unreachable\n"); - pico_notify_dest_unreachable(f); - pico_frame_discard(f); + pico_arp_unreachable(where); } } @@ -202,6 +218,21 @@ return a4; } + +void pico_arp_postpone(struct pico_frame *f) +{ + int i; + for (i = 0; i < PICO_ARP_MAX_PENDING; i++) + { + if (!frames_queued[i]) { + frames_queued[i] = pico_frame_copy(f); + return; + } + } + /* Not possible to enqueue: caller will discard packet */ +} + + #ifdef DEBUG_ARP void dbg_arp(void) { @@ -236,6 +267,7 @@ pico_tree_insert(&arp_tree, entry); arp_dbg("ARP ## reachable.\n"); + pico_arp_queued_trigger(); pico_timer_add(PICO_ARP_TIMEOUT, arp_expire, entry); } @@ -410,7 +442,7 @@ } -int32_t pico_arp_request_xmit(struct pico_device *dev, struct pico_frame *f, struct pico_ip4 *src, struct pico_ip4 *dst, uint8_t type) +static int32_t pico_arp_request_xmit(struct pico_device *dev, struct pico_frame *f, struct pico_ip4 *src, struct pico_ip4 *dst, uint8_t type) { struct pico_arp_hdr *ah = (struct pico_arp_hdr *) (f->start + PICO_SIZE_ETHHDR); int ret;