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 RTOS
  • generic mbed Ethernet driver
  • high performance NXP LPC1768 specific Ethernet driver
  • Multi-threading support for mbed RTOS
  • Berkeley sockets and integration with the New Socket API
  • Fork of the apps running on top of the New Socket API
  • Scheduling 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.

Files at this revision

API Documentation at this revision

Comitter:
tass
Date:
Mon Nov 04 07:54:12 2013 +0000
Parent:
110:0ece1bbbd36e
Child:
112:c4463e7a6a41
Commit message:
Issue #48 fixed.

Changed in this revision

modules/pico_ipv4.c Show annotated file Show diff for this revision Revisions of this file
modules/pico_ipv4.h Show annotated file Show diff for this revision Revisions of this file
modules/pico_tcp.c Show annotated file Show diff for this revision Revisions of this file
modules/pico_udp.c Show annotated file Show diff for this revision Revisions of this file
--- a/modules/pico_ipv4.c	Fri Nov 01 06:52:32 2013 +0000
+++ b/modules/pico_ipv4.c	Mon Nov 04 07:54:12 2013 +0000
@@ -306,6 +306,13 @@
       pfrag = fragment_find_by_hdr(hdr);
       if (pfrag) {
         pfrag->total_len = (uint16_t)(pfrag->total_len + (short_be(hdr->len) - (*f)->net_len));
+				if (pfrag->total_len > PICO_IPV4_FRAG_MAX_SIZE) {
+           reassembly_dbg("BIG frame!!!\n");
+           pfrag = pico_tree_first(&pico_ipv4_fragmented_tree);
+           pico_ipv4_fragmented_cleanup(pfrag);
+    			 pico_frame_discard(*f);
+					 return 0;
+				}
         pico_tree_insert(pfrag->t, *f);
         return 0;
       } else {
@@ -320,6 +327,13 @@
     if (pfrag) {
       pfrag->total_len = (uint16_t)(pfrag->total_len + (short_be(hdr->len) - (*f)->net_len));
       reassembly_dbg("REASSEMBLY: fragmented packet in tree, reassemble packet of %u data bytes\n", pfrag->total_len);
+			if (pfrag->total_len > PICO_IPV4_FRAG_MAX_SIZE) {
+           reassembly_dbg("BIG frame!!!\n");
+           pfrag = pico_tree_first(&pico_ipv4_fragmented_tree);
+           pico_ipv4_fragmented_cleanup(pfrag);
+    			 pico_frame_discard(*f);
+					 return 0;
+				}
       f_new = self->alloc(self, pfrag->total_len);
 
       f_frag = pico_tree_first(pfrag->t);
--- a/modules/pico_ipv4.h	Fri Nov 01 06:52:32 2013 +0000
+++ b/modules/pico_ipv4.h	Mon Nov 04 07:54:12 2013 +0000
@@ -18,6 +18,11 @@
 #define PICO_IPV4_MOREFRAG 0x2000
 #define PICO_IPV4_FRAG_MASK 0x1FFF
 #define PICO_IPV4_DEFAULT_TTL 64
+#ifndef MBED
+    #define PICO_IPV4_FRAG_MAX_SIZE (63 * 1024)
+#else
+	#define PICO_IPV4_FRAG_MAX_SIZE PICO_DEFAULT_SOCKETQ
+#endif
 
 extern struct pico_protocol pico_proto_ipv4;
 
--- a/modules/pico_tcp.c	Fri Nov 01 06:52:32 2013 +0000
+++ b/modules/pico_tcp.c	Mon Nov 04 07:54:12 2013 +0000
@@ -133,6 +133,7 @@
   uint32_t max_size;
   uint32_t size;
   uint32_t frames;
+  uint16_t overhead;
 };
 static void tcp_discard_all_segments(struct pico_tcp_queue *tq);
 static void *peek_segment(struct pico_tcp_queue *tq, uint32_t seq)
@@ -178,8 +179,8 @@
 {
   int32_t ret = -1;
   uint16_t payload_len = (uint16_t)(IS_INPUT_QUEUE(tq) ?
-		  ((struct tcp_input_segment *)f)->payload_len + TCP_INPUT_OVERHEAD:
-		  ((struct pico_frame *)f)->payload_len);
+		  ((struct tcp_input_segment *)f)->payload_len:
+		  ((struct pico_frame *)f)->buffer_len);
 
   if (payload_len <= 0) {
     tcp_dbg("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! TRIED TO ENQUEUE INVALID SEGMENT!\n");
@@ -197,7 +198,7 @@
     ret = 0;
     goto out;
   }
-  tq->size += payload_len;
+  tq->size += (uint16_t)(payload_len + tq->overhead);
   if (payload_len > 0)
     tq->frames++;
   ret = (int32_t)payload_len;
@@ -211,12 +212,12 @@
 {
   void *f1;
   uint16_t payload_len = (uint16_t)(IS_INPUT_QUEUE(tq)?
-		  ((struct tcp_input_segment *)f)->payload_len + TCP_INPUT_OVERHEAD:
-		  ((struct pico_frame *)f)->payload_len);
+		  ((struct tcp_input_segment *)f)->payload_len:
+		  ((struct pico_frame *)f)->buffer_len);
   LOCK(Mutex);
   f1 = pico_tree_delete(&tq->pool,f);
   if (f1) {
-    tq->size -= payload_len;
+    tq->size -= (uint16_t)(payload_len + tq->overhead);
     if (payload_len > 0)
       tq->frames--;
   }
@@ -780,7 +781,8 @@
   t->tcpq_in.max_size = PICO_DEFAULT_SOCKETQ;
   t->tcpq_out.max_size = PICO_DEFAULT_SOCKETQ;
   t->tcpq_hold.max_size = 2*PICO_TCP_DEFAULT_MSS;
-
+  t->tcpq_in.overhead=(sizeof(struct tcp_input_segment)+sizeof(struct pico_tree_node));
+  t->tcpq_out.overhead=t->tcpq_hold.overhead=sizeof(struct pico_frame)+sizeof(struct pico_tree_node);
   /* disable Nagle by default */
   //t->sock.opt_flags |= (1 << PICO_SOCKET_OPT_TCPNODELAY);
   /* Nagle is enabled by default */
@@ -1777,6 +1779,8 @@
   new->tcpq_in.max_size = PICO_DEFAULT_SOCKETQ;
   new->tcpq_out.max_size = PICO_DEFAULT_SOCKETQ;
   new->tcpq_hold.max_size = 2*PICO_TCP_DEFAULT_MSS;
+  new->tcpq_in.overhead=(sizeof(struct tcp_input_segment)+sizeof(struct pico_tree_node));
+  new->tcpq_out.overhead=new->tcpq_hold.overhead=sizeof(struct pico_frame)+sizeof(struct pico_tree_node);
 
   f->sock = &new->sock;
   tcp_parse_options(f);
--- a/modules/pico_udp.c	Fri Nov 01 06:52:32 2013 +0000
+++ b/modules/pico_udp.c	Mon Nov 04 07:54:12 2013 +0000
@@ -151,8 +151,10 @@
 {
   struct pico_frame *f = pico_queue_peek(&s->q_in);
   if (f) {
-    f->payload = f->transport_hdr + sizeof(struct pico_udp_hdr);
-    f->payload_len = (uint16_t)(f->transport_len - sizeof(struct pico_udp_hdr));
+		if(!f->payload_len){
+      f->payload = f->transport_hdr + sizeof(struct pico_udp_hdr);
+      f->payload_len = (uint16_t)(f->transport_len - sizeof(struct pico_udp_hdr));
+    }
 //    dbg("expected: %d, got: %d\n", len, f->payload_len);
     if (src)
       pico_store_network_origin(src, f);