regarding the question about packet fragmentation (for a 2000 bytes packet) under TCP and UDP, the solutions reports fragmentation as possible only under TCP. However, I know that fragmentation can also happens at the IP layer if the segment is longer than the MTU. If this is true, B could receive only 1000 bytes also under UDP. Why this shouldn’t be the case?
Thank you.
I'm a fellow student but I think that the reassembling "under UDP" would happen at the ip layer in the receiver host, before being given to UPD layer (thus only one receive can be made). If an AE can confirm this maybe ?
Hi,
Richard is right.
When you pass 2000 bytes with a single send to a socket:
if the socket is UDP,
- the transport layer creates one unique UDP datagram containing
the 2000 bytes (in UDP, 1 send = 1 UDP datagram)
- the network layer then creates one IP packet containing the UDP
datagram. If this IP packet is longer than the MTU, then the IP packet will be split into two
(or more) IP packets, each containing part of the UDP datgram (IP
fragmentation).
- the packets travel trough the network...
- when reaching the remote end, IP packets are processed by the
recipient network layer. That layer needs to reassemble the two IP
packets into a single one before extracting the payload. Indeed,
for packet-oriented protocols (like IP), a fragment of a payload
is not a payload: a fragment of a UDP datagram is NOT a UDP
datagram. *If the IP layer fails to reassemble the two IP packets
(one of them was lost), then the IP layer cannot extract the
payload and hence does not transmit anything to the upper layer.
Hence, no part of the UDP datagram will ever reach the transport
layer of remote's end. *On the contrary, if the two packets are
reassembled, the entire payload is transmitted to the UDP layer of
the recipient, this layer may even not be aware that the IP packet
was fragmented ! It receives indeed one full UDP datagram that is
provided to the recv() call. In UDP sockets, 1 receive = 1
datagram.
if the socket is TCP,
- the transport layer may choose to create two TCP segments
containing each a part of the 2000bytes (in TCP, 1 send is not
equal to 1 TCP segment, see TCP packetization).
- the network layer then creates one IP packet per TCP segment (2
IP packets).
- packets travel
- in the remote IP layer, assume only the packet containing the first TCP segment is received. Because the payload (in this
case, a complete TCP segment) is complete, the whole is transmitted to
the transport layer. The second segment (lost) is of course not transmitted to the TCP layer.
- The transport layer hence receives only one TCP segment. For
TCP, the payload of that segment is a part of a stream ('a stream segment'). It is
hence ITSELF a payload and can be transmitted to the upper layer
(the application layer) without waiting for the rest of the
payload (the 'rest of the payload' may not even exists for an
infinite stream !). Because the socket buffer has now 1000bytes
available, a recv(buffsize) will return the whole content of the
socket buffer, with a limit at buffsize bytes. Assuming buffsize
is >1000bytes, you receive all of them.
Of course, TCP will then retransmit the lost segment and the lost
payload (the lost part of the stream) will be made available in the socket buffer later, but you
might need to issue a second recv() to get them.
Ludovic