Transport Layer
2024-01-19
A small selection of well-known port numbers:
Port number | Service | Description |
---|---|---|
21 | FTP | File transfer |
22 | SSH | Encrypted terminal emulation (secure shell) |
23 | Telnet | Terminal emulation for remote control of computers |
25 | SMTP | E-mail transfer |
53 | DNS | Resolution of domain names into IP addresses |
67 | DHCP | Assignment of the network configuration to clients |
80 | HTTP | Webserver |
110 | POP3 | Client access to E-mail server |
143 | IMAP | Client access to E-mail server |
443 | HTTPS | Webserver (encrypted) |
993 | IMAPS | Client access to E-mail server (encrypted) |
995 | POP3S | Client access to E-mail server (encrypted) |
Well-known ports and registered ports are assigned by the IANA
In Linux/UNIX systems: /etc/services
In Windows systems: %WINDIR%\system32\drivers\etc\services
Tools to monitor the open ports and sockets with…
ss
, netstat
, lsof
and nmap
netstat
TCP specification: RFC 793 from 1981
http://tools.ietf.org/rfc/rfc793.txt
MTU vs. MSS
Maximum Transfer Unit (MTU): Maximum size of the IP packets
MTU of Ethernet = 1,500 bytes, MTU of PPPoE (e.g., DSL) = 1,492 bytes
Maximum Segement Size (MSS): Maximum segment size
MSS = MTU - 40 bytes for IPv4 header and TCP header
A TCP segment can contain a maximum of 64 kB payload (data of the Application Layer)
Overhead
\(\Longrightarrow\) The overhead, caused by the TCP and IP headers, is small for an IP packet with a size of several kB
000000
Remember NAT from slide set 8… If a NAT device (router) is used, this routing device also needs to recalculate the checksums in TCP segments when doing IP address translations
You already know…
SYN=1
as a request to synchronize the sequence numbersACK=1
and requests with SYN=1
to synchronize the sequence numbers, tooACK=1
that the connection is establishedTo demonstrate a data transmission, Seq number (sequence number of the current segment) and ACK number (sequence number of the expected next segment) need particular values
x
=100 and the server’s sequence number is y
=500x
=101 and y
=501ACK=1
the received payload and requests with the ACK number 1101
the next segment. In the same segment, the server transfers 400 bytes of payload901
the next segmentACK=1
the received payload and requests with the ACK number 2101
the next segmentIn the example, the server does not increment its Seq number because it does not transmit payload to the client
SYN
bit set, the FIN
bit is used to close the connection, i.e., indicate that the sender will not transmit any more payloadFIN=1
ACK=1
FIN=1
ACK=1
CLOSED
: Default state. Still no connectionLISTEN
: Waiting for a SYN messageSYN-SENT
: SYN is sent. Waiting for SYN and ACKSYN-RECEIVED
: Replied with SYN and ACK to SYN. Waiting for ACKESTABLISHED
: The TCP connection is established and payload can be exchangedCLOSE-WAIT
: FIN is received. Local application needs to reply with ACKLAST-ACK
: ACK has already been sent. Now FIN is sentFIN-WAIT-1
: FIN is sent. Waiting for ACKFIN-WAIT-2
: ACK is sent. Waiting for FINCLOSING
: FIN is received and ACK is sent backTIME-WAIT
: Connection is terminatedSource: http://www.tcpipguide.com/free/t_TCPOperationalOverviewandtheTCPFiniteStateMachineF-2.htm
The Trivial File Transfer Protocol (RFC 783) operates according to the Stop-and-Wait principle
Signs of congestion of the network
The minimum of both windows is the maximum number of bytes, the sender can transmit
Example:
You already know…
Robustness Principle TCP implementations will follow a general principle of robustness: be conservative in what you do, be liberal in what you accept from others.
Jon Postel, RFC 793, page 13
TCP has no version number
Continuous enhancements and extensions were necessary over time, in order to …
The main challenge is to stay compatible
socket
)connect
)send
) and receive data (recv
)close
)socket
)bind
)listen
)
accept
)send
) and receive data (recv
)close
)#!/usr/bin/env python
# Echo Server via TCP
import socket # Import module socket
HOST = '' # '' = all interfaces
PORT = 50007 # Port number of server
# Create socket and return socket descriptor
sd = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind socket to port
sd.bind((HOST, PORT))
# Make socket ready to receive
# Max. number of connections = 1
sd.listen(1)
# Socket accepts connections
conn, addr = sd.accept()
print('Connected by', addr)
while 1: # Infinite loop
data = conn.recv(1024) # Receive data
if not data: break # Break infinite loop
conn.send(data) # Send back received data
sd.close() # Close socket
$ python tcp_server.py
#!/usr/bin/env python
# Echo Client via TCP
import socket # Import module socket
HOST = 'localhost' # Hostname of Server
PORT = 50007 # Port number of server
# Create socket and return socket descriptor
sd = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect with server socket
sd.connect((HOST, PORT))
sd.send('Hello, world') # Send data
data = sd.recv(1024) # Receive data
sd.close() # Close socket
# Print out received data
print('Received:', repr(data))
$ python tcp_client.py
Received: 'Hello, world'
$ python tcp_server.py
Connected by ('127.0.0.1', 49898)
Target: Making services or servers inaccessible
A client sends multiple connection requests (SYN), but does not respond to the acknowledgments (SYN ACK) of the server via ACK
The server waits some time for the acknowledgment of the client
The confirmation delay could be caused by a network issue
During this period, the address of the client and the status of incomplete connection are stored in the memory of the network stack
By flooding the server with connection requests, the table, which stores the TCP connections in the network stack is completely filled
\(\Longrightarrow\) the server gets unable to establish new connections
The memory consumption at the server may become this large that the main memory gets completely filled and the server becomes unresponsive
Countermeasure: Real-time analysis of the network by intelligent firewalls
UDP standard: RFC 768 from 1980
0
), if no response is requiredRemember NAT from slide set 8…
If a NAT device (Router) is used, this routing device also needs to recalculate the checksums in UDP datagrams when doing IP address translations
socket
)sendto
) and receive data (recvfrom
)close
)socket
)bind
)sendto
) and receive data (recvfrom
)close
)#!/usr/bin/env python
# Server: Receives a message via UDP
import socket # Import module socket
# For all interfaces of the host
HOST = '' # '' = all interfaces
PORT = 50000 # Port number of server
# Create socket and return socket descriptor
sd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
sd.bind((HOST, PORT)) # Bind socket to port
while True:
# Receive data
data = sd.recvfrom(1024)
# Print out received data
print('Received:', repr(data))
finally:
sd.close() # Close socket
$ python udp_server.py
#!/usr/bin/env python
# Client: Sends a message via UDP
import socket # Import module socket
HOST = 'localhost' # Hostname of Server
PORT = 50000 # Port number of Server
MESSAGE = 'Hello World' # Message
# Create socket and return socket descriptor
sd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Send message to socket
sd.sendto(MESSAGE, (HOST, PORT))
sd.close() # Close socket
$ python udp_client.py
$ python udp_server.py
Received: ('Hello World', ('127.0.0.1', 39834))
Source: KSkun’s blog, https://ksmeow.moe/quic/
You should now be able to answer the following questions:
Computer Networks - Transport Layer - WS 23/24