lwIP - A Minimal TCP/IP implementation - Wikia
lwIP - A Minimal TCP/IP implementation - Wikia
lwIP - A Minimal TCP/IP implementation - Wikia
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
10 <strong>TCP</strong> PROCESSING 10.6 Accepting new connections<br />
In <strong>lw<strong>IP</strong></strong>, whenever a PCB match is found when demultiplexing a segment, the PCB is moved<br />
to the front of the list of PCBs. PCBs for connections in the LISTEN state are not moved to the<br />
front however, since such connections are not expected to receive segments as often as connections<br />
that are in a state in which they receive data.<br />
10.5.2 Receiving data<br />
The actual processing of incoming segments is made in the function tcp receive(). The acknowledgment<br />
number of the segment is compared with the segments on the unacked queue of<br />
the connection. If the acknowledgment number is higher than the sequence number of a segment<br />
on the unacked queue, that segment is removed from the queue and the allocated memory for the<br />
segment is deallocated.<br />
An incoming segment is out of sequence if the sequence number of the segment is higher than<br />
the rcv nxt variable in the PCB. Out of sequence segments are queued on the ooseq queue in<br />
the PCB. If the sequence number of the incoming segment is equal to rcv nxt, the segment is<br />
delivered to the upper layer by calling the recv function in the PCB and rcv nxt is increased by<br />
the length of the incoming segment. Since the reception of an in-sequence segment might mean<br />
that a previously received out of sequence segment now is the next segment expected, the ooseq<br />
queued is checked. If it contains a segment with sequence number equal to rcv nxt, this segment<br />
is delivered to the application by a call to to recv function and rcv nxt is updated. This process<br />
continues until either the ooseq queue is empty or the next segment on ooseq is out of sequence.<br />
10.6 Accepting new connections<br />
<strong>TCP</strong> connections that are in the LISTEN state, i.e., that are passively open, are ready to accept<br />
new connections from a remote host. For those connections a new <strong>TCP</strong> PCB is created and must<br />
be passed to the application program that opened the initial listening <strong>TCP</strong> connection. In <strong>lw<strong>IP</strong></strong><br />
this is done by letting the application register a callback function that is to be called when a new<br />
connection has been established.<br />
When a connection in the LISTEN state receives a <strong>TCP</strong> segment with the SYN flag set, a<br />
new connection is created and a segment with the SYN and ACK flags are sent in response to<br />
the SYN segment. The connection then enters the SYN-RCVD state and waits for an acknowledgment<br />
for the sent SYN segment. When the acknowledgment arrives, the connection enters the<br />
ESTABLISHED state, and the accept function (the accept field in the PCB structure in Figure<br />
10) is called.<br />
10.7 Fast retransmit<br />
Fast retransmit and fast recovery is implemented in <strong>lw<strong>IP</strong></strong> by keeping track of the last sequence<br />
number acknowledged. If another acknowledgment for the same sequence number is received, the<br />
dupacks counter in the <strong>TCP</strong> PCB is increased. When dupacks reaches three, the first segment<br />
on the unacked queue is retransmitted and fast recovery is initialized. The <strong>implementation</strong> of fast<br />
recovery follows the steps laid out in [APS99]. Whenever an ACK for new data is received, the<br />
dupacks counter is reset to zero.<br />
10.8 Timers<br />
As in the the BSD <strong>TCP</strong> <strong>implementation</strong>, <strong>lw<strong>IP</strong></strong> uses two periodical timers that goes off every 200<br />
ms and 500 ms. Those two timers are then used to implement more complex logical timers such<br />
as the retransmission timers, the TIME-WAIT timer and the delayed ACK timer.<br />
The fine grained timer, tcp timer fine() goes through every <strong>TCP</strong> PCB checking if there are<br />
any delayed ACKs that should be sent, as indicated by the flag field in the tcp pcb structure<br />
(Figure 10). If the delayed ACK flag is set, an empty <strong>TCP</strong> acknowledgment segment is sent and<br />
the flag is cleared.<br />
14