Difference between revisions of "Unit TCP"

From Ultibo.org
Jump to: navigation, search
 
(14 intermediate revisions by the same user not shown)
Line 22: Line 22:
 
TCP Send and Recv do not use a block buffer as per UDP etc. Instead the data for each Segment is stored in memory (TCP_MAX_MSS) allocated with the Segment. The Free and Used values still track the amount of data in the buffer but this method allows OOB data to be handled correctly.
 
TCP Send and Recv do not use a block buffer as per UDP etc. Instead the data for each Segment is stored in memory (TCP_MAX_MSS) allocated with the Segment. The Free and Used values still track the amount of data in the buffer but this method allows OOB data to be handled correctly.
  
TCP Sequence numbers are compared using modulo 2^32 arithmetic. The following calculations provide the neccessary handling of wraparound etc.
+
TCP Sequence numbers are compared using modulo 2^32 arithmetic. The following calculations provide the necessary handling of wraparound etc.
  
 
LT  = (A - B) < 0
 
LT  = (A - B) < 0
Line 85: Line 85:
 
| 65536; TCP Send/Receive Buffer Sizes
 
| 65536; TCP Send/Receive Buffer Sizes
 
|-
 
|-
| <code>TCP_WINDOW_SIZE = 16060;</code>
+
| <code>TCP_WINDOW_SIZE = 64240;</code>
| 64240; Sliding Window Receive Size (44 x MSS)
+
| Sliding Window Receive Size (44 x MSS)
 
|-
 
|-
 
| <code>TCP_INITIAL_WINDOW = 8192;</code>
 
| <code>TCP_INITIAL_WINDOW = 8192;</code>
Line 93: Line 93:
 
|colspan="2"|&nbsp;  
 
|colspan="2"|&nbsp;  
 
|-
 
|-
| <code>TCP_WINDOW_TIMEOUT = 300;</code>
+
| <code>TCP_TIMEOUT_OFFSET = 10;</code>
 +
| How much time offset to allow from the designated value
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>TCP_ADVERT_TIMEOUT = 100;</code>
 +
| Time to wait before sending a window size update after closing the receive window
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>TCP_WINDOW_TIMEOUT = 5000;</code>
 
| Time to wait before probing small/zero Window
 
| Time to wait before probing small/zero Window
 
|-
 
|-
Line 133: Line 143:
 
|-
 
|-
 
| <code>TCP_HEADER_SIZE = 20;</code>
 
| <code>TCP_HEADER_SIZE = 20;</code>
| SizeOf(TTCPHeader); Does Not Allow for Options
+
| SizeOf(TTCPHeader) Does Not Allow for Options
 
|-
 
|-
 
| <code>TCP_OPTIONS_SIZE = 40;</code>
 
| <code>TCP_OPTIONS_SIZE = 40;</code>
Line 140: Line 150:
 
|colspan="2"|&nbsp;
 
|colspan="2"|&nbsp;
 
|-
 
|-
| <code>TCP_SEGMENT_SIZE = 48;</code>
+
| <code>TCP_SEGMENT_SIZE = 68;</code>
| SizeOf(TTCPSegment)
+
| SizeOf(TTCPSegment) Including TSocketTimerItem
 
|-
 
|-
 
|}
 
|}
Line 147: Line 157:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
<div style="font-size: 14px; padding-left: 12px;">'''TCP socket state constants''' <code> TCP_STATE_* </code></div>
+
<div style="font-size: 14px; padding-left: 12px;">'''TCP socket state''' <code> TCP_STATE_* </code></div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
Line 188: Line 198:
 
<br />  
 
<br />  
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
<div style="font-size: 14px; padding-left: 12px;">'''TCP header option constants''' <code> TCPOPT_* </code></div>
+
<div style="font-size: 14px; padding-left: 12px;">'''TCP header option''' <code> TCPOPT_* </code></div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
Line 232: Line 242:
 
<br />  
 
<br />  
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
<div style="font-size: 14px; padding-left: 12px;">'''TCP header flag constants''' <code> TCP_FLAG_* </code></div>
+
<div style="font-size: 14px; padding-left: 12px;">'''TCP header flag''' <code> TCP_FLAG_* </code></div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
Line 274: Line 284:
 
<br />  
 
<br />  
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;">
<div style="font-size: 14px; padding-left: 12px;">'''TCP port constants''' <code> TCP_PORT_* </code></div>
+
<div style="font-size: 14px; padding-left: 12px;">'''TCP port''' <code> TCP_PORT_* </code></div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
Line 381: Line 391:
 
|-
 
|-
 
| <code>Timeout:Int64;</code>
 
| <code>Timeout:Int64;</code>
| Transmit (Send) / Acknowledge (Recv) Timeout
+
| Transmit (Send)/Acknowledge (Recv) Timeout
 
|-
 
|-
 
| <code>Prev:PTCPSegment;</code>
 
| <code>Prev:PTCPSegment;</code>
Line 388: Line 398:
 
| <code>Next:PTCPSegment;</code>
 
| <code>Next:PTCPSegment;</code>
 
| Pointer to Next Segment
 
| Pointer to Next Segment
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>Item:TSocketTimerItem;</code>
 +
| Socket Timer Item for this Segment
 
|-
 
|-
 
|}
 
|}
Line 396: Line 411:
 
----
 
----
  
''To be documented''
+
 
 +
'''TCP specific classes'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| [[TTCPProtocolTransport|<code>TTCPProtocolTransport = class(TProtocolTransport)</code>]]
 +
|-
 +
|}
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| [[TTCPProtocol|<code>TTCPProtocol = class(TNetworkProtocol)</code>]]
 +
|-
 +
|}
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| [[TTCPSocket|<code>TTCPSocket = class(TProtocolSocket)</code>]]
 +
|-
 +
|}
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| [[TTCPState|<code>TTCPState = class(TProtocolState)</code>]]
 +
|-
 +
|}
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| [[TTCPOptions|<code>TTCPOptions = class(TProtocolOptions)</code>]]
 +
|-
 +
|}
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| [[TTCPSendBuffer|<code>TTCPSendBuffer = class(TSocketBuffer)</code>]]
 +
|-
 +
|}
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| [[TTCPRecvBuffer|<code>TTCPRecvBuffer = class(TSocketBuffer)</code>]]
 +
|-
 +
|}
 +
<br />
  
 
=== Public variables ===
 
=== Public variables ===
Line 414: Line 467:
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
|-
+
|-https://ultibo.org/wiki/Unit_Sockets#
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 430: Line 483:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| The complete packet including Transport header
 
| The complete packet including Transport header
 
|-
 
|-
Line 442: Line 495:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| The complete packet including Transport header
 
| The complete packet including Transport header
 
|-
 
|-
Line 450: Line 503:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function GetTCPHeaderLength(AFamily:Word; ABuffer:Pointer):Word;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function GetTCPHeaderLength(AFamily:Word; ABuffer:Pointer):Word;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' TO be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| The complete packet including Transport header
 
| The complete packet including Transport header
 
|-
 
|-
Line 466: Line 519:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| The complete packet including Transport header
 
| The complete packet including Transport header
 
|-
 
|-
Line 478: Line 531:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| The complete packet including Transport header
 
| The complete packet including Transport header
 
|-
 
|-
Line 490: Line 543:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| The complete packet including Transport header
 
| The complete packet including Transport header
 
|-
 
|-
Line 502: Line 555:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 514: Line 567:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-

Latest revision as of 01:38, 30 May 2018

Return to Unit Reference


Description


Ultibo TCP (Transmission Control Protocol) unit

Notes:

Segment handling:

Send adds new segments to the end of the list only accepts ACKs for whole segments.

Recv adds/inserts segments in correct SEQ order accepts overlapping segments only sends ACKs for whole segments.

Send will coalesce small data writes into larger segments if options allow this.

Recv will store the segments exactly as received.


TCP Send and Recv do not use a block buffer as per UDP etc. Instead the data for each Segment is stored in memory (TCP_MAX_MSS) allocated with the Segment. The Free and Used values still track the amount of data in the buffer but this method allows OOB data to be handled correctly.

TCP Sequence numbers are compared using modulo 2^32 arithmetic. The following calculations provide the necessary handling of wraparound etc.

LT = (A - B) < 0

LEQ = (A - B) <= 0

GT = (A - B) > 0

GEQ = (A - B) >= 0


See GlobalSock.pas for actual functions that implement this.

Constants



[Expand]
TCP specific constants TCP_*


[Expand]
TCP socket state TCP_STATE_*


[Expand]
TCP header option TCPOPT_*


[Expand]
TCP header flag TCP_FLAG_*


[Expand]
TCP port TCP_PORT_*


Type definitions



TCP header

[Expand]

PTCPHeader = ^TTCPHeader;

TTCPHeader = packed record

TCP segment

[Expand]

PTCPSegment = ^TTCPSegment;

TTCPSegment = record


Class definitions



TCP specific classes

TTCPProtocolTransport = class(TProtocolTransport)
TTCPProtocol = class(TNetworkProtocol)
TTCPSocket = class(TProtocolSocket)
TTCPState = class(TProtocolState)
TTCPOptions = class(TProtocolOptions)
TTCPSendBuffer = class(TSocketBuffer)
TTCPRecvBuffer = class(TSocketBuffer)


Public variables


None defined

Function declarations



Initialization functions

[Expand]
procedure TCPInit;
Description: To be documented


TCP functions

[Expand]
function CheckTCP(AFamily:Word; ABuffer:Pointer):Boolean;
Description: Verify that the packet is a valid TCP packet


[Expand]
function GetTCPHeaderOffset(AFamily:Word; ABuffer:Pointer):Word;
Description: To be documented


[Expand]
function GetTCPHeaderLength(AFamily:Word; ABuffer:Pointer):Word;
Description: To be documented


[Expand]
function GetTCPOptionsLength(AFamily:Word; ABuffer:Pointer):Word;
Description: To be documented


[Expand]
function GetTCPDataOffset(AFamily:Word; ABuffer:Pointer):Word;
Description: To be documented


[Expand]
function GetTCPDataLength(AFamily:Word; ABuffer:Pointer):Word;
Description: To be documented


[Expand]
function ChecksumTCPRecv(AFamily:Word; APseudo:PIPPseudo; ABuffer:Pointer; AOffset,ALength:Word):Word;
Description: Validate the Checksum of TCP Pseudo, Header and Data on Receive


[Expand]
function ChecksumTCPSend(AFamily:Word; APseudo:PIPPseudo; AHeader:PTCPHeader; AOptions,AData:Pointer; AOptionsLength,ADataLength:Word):Word;
Description: Checksum the TCP Pseudo, Header, Options and Data on Send


Return to Unit Reference