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.

Revision:
123:dd26752a4538
Parent:
122:5b1e9de8bf7f
Child:
128:ae39e6e81531
--- a/modules/pico_tcp.c	Thu Nov 21 09:48:05 2013 +0000
+++ b/modules/pico_tcp.c	Wed Nov 27 10:20:00 2013 +0000
@@ -48,6 +48,7 @@
 #define IS_INPUT_QUEUE(q)  (q->pool.compare==input_segment_compare)
 #define TCP_INPUT_OVERHEAD (sizeof(struct tcp_input_segment)+sizeof(struct pico_tree_node))
 
+
 #ifdef PICO_SUPPORT_TCP
 #define tcp_dbg_nagle(...) do{}while(0)
 #define tcp_dbg_options(...) do{}while(0)
@@ -335,12 +336,13 @@
   return ret;
 }
 
-static int release_all_until(struct pico_tcp_queue *q, uint32_t seq)
+static int release_all_until(struct pico_tcp_queue *q, uint32_t seq,uint32_t * timestamp)
 {
   void *f = NULL, *tmp __attribute__((unused));
   struct pico_tree_node * idx, * temp;
   int seq_result;
   int ret = 0;
+  *timestamp = 0;
 
   pico_tree_foreach_safe(idx,&q->pool,temp){
   f = idx->keyValue;
@@ -349,6 +351,8 @@
 		  seq_compare(SEQN((struct pico_frame *)f) + ((struct pico_frame *)f)->payload_len, seq);
     if (seq_result<= 0) {
       tcp_dbg("Releasing %p\n", f);
+      if(seq_result == 0)
+    	  *timestamp = ((struct pico_frame *)f)->timestamp;
       pico_discard_segment(q, f);
       ret++;
     } else
@@ -1280,9 +1284,9 @@
   }
 }
 
-static int tcp_ack_advance_una(struct pico_socket_tcp *t, struct pico_frame *f)
+static int tcp_ack_advance_una(struct pico_socket_tcp *t, struct pico_frame *f, uint32_t * timestamp)
 {
-  int ret =  release_all_until(&t->tcpq_out, ACKN(f));
+  int ret =  release_all_until(&t->tcpq_out, ACKN(f),timestamp);
   if (ret > 0)
     t->sock.ev_pending |= PICO_SOCK_EV_WR;
   return ret;
@@ -1393,6 +1397,7 @@
 				cpy = pico_frame_copy(f);
 				if (pico_enqueue(&tcp_out, cpy) > 0) {
 					t->backoff++;
+					t->snd_last_out = SEQN(cpy);
 					add_retransmission_timer(t, (t->rto << t->backoff) + pico_tick);
 					tcp_dbg("TCP_CWND, %lu, %u, %u, %u\n", pico_tick, t->cwnd, t->ssthresh, t->in_flight);
 					return;
@@ -1520,6 +1525,9 @@
   struct pico_tcp_hdr *hdr = (struct pico_tcp_hdr *) f->transport_hdr;
   uint32_t rtt = 0;
   uint16_t acked = 0;
+  uint32_t acked_timestamp = 0;
+  uint8_t restart_tmr = 0;
+
   struct pico_frame *una = NULL;
   if ((hdr->flags & PICO_TCP_ACK) == 0)
     return -1;
@@ -1531,18 +1539,27 @@
   tcp_parse_options(f);
   t->recv_wnd = short_be(hdr->rwnd);
 
-  acked = (uint16_t)tcp_ack_advance_una(t, f);
+  acked = (uint16_t)tcp_ack_advance_una(t, f,&acked_timestamp);
   una = first_segment(&t->tcpq_out);
 
   if ((t->x_mode == PICO_TCP_BLACKOUT) || 
     ((t->x_mode == PICO_TCP_WINDOW_FULL) && ((t->recv_wnd << t->recv_wnd_scale) > t->mss))) {
+	int prev_mode = t->x_mode;
     tcp_dbg("Re-entering look-ahead...\n\n\n");
     t->x_mode = PICO_TCP_LOOKAHEAD;
     t->backoff = 0;
+
+    if((prev_mode == PICO_TCP_BLACKOUT) && (acked>0) && una)
+    {
+		t->snd_nxt = SEQN(una);
+		// restart the retrans timer
+		pico_timer_cancel(t->retrans_tmr);
+		t->timer_running = 0;
+		restart_tmr = 1u;
+    }
   }
 
   /* One should be acked. */
-//  if ((acked == 0) && (t->in_flight > 0))
   if ((acked == 0) && (f->payload_len  == 0) && (t->in_flight > 0))
     t->in_flight--;
   if (!una || acked > 0) {
@@ -1556,9 +1573,9 @@
       rtt = time_diff(pico_tick, f->timestamp);
       if (rtt)
         tcp_rtt(t, rtt);
-    } else if(una && (una->timestamp != 0)) {
+    } else if(acked_timestamp) {
       /* If no timestamps are there, use conservatve estimation on the una */
-        rtt = time_diff(pico_tick, una->timestamp);
+        rtt = time_diff(pico_tick, acked_timestamp);
         if (rtt)
           tcp_rtt(t, rtt);
     }
@@ -1655,6 +1672,11 @@
     }
   }
 
+  if(restart_tmr)
+  {
+  	add_retransmission_timer(t,pico_tick+t->rto);
+  }
+
   t->snd_old_ack = ACKN(f);
   return 0;
 }
@@ -2151,8 +2173,8 @@
   int sent = 0;
 
   una = first_segment(&t->tcpq_out);
+  f = peek_segment(&t->tcpq_out, t->snd_nxt);
 
-  f = peek_segment(&t->tcpq_out, t->snd_nxt);
   while((f) && (t->cwnd >= t->in_flight)) {
     hdr = (struct pico_tcp_hdr *)f->transport_hdr;
     f->timestamp = pico_tick;