TCP/IP packets and datagrams
Asked Answered
F

4

9

Is it true that upon receiving a segment from Transport Layer(TCP) towards Network Layer(IP) the resulting data unit will be a packet. Whereas when receiving a user datagram from Transport Layer(UDP) the resulting data unit will be a datagram?

Floozy answered 25/12, 2012 at 0:54 Comment(0)
F
20

You are getting caught up in the details ... packet and datagram are not exactly well defined terms. I also think that you are also looking at things backwards. In a conventional network:

  1. the link layer (e.g., 802.3 "Ethernet" or 802.11 "Wi-Fi") presents frames to the network layer (e.g., IP, ICMP)
  2. The network layer assembles the frames into packets which are passed on to the next layer in the stack - the transport layer
  3. The transport layer, in turn, passes the bytes on to the application layer. The application layer API is really what distinguishes between data streams in TCP and datagrams in UDP

The OSI stack isn't really used in practice any longer. In most cases, it has been replaced by the Internet Protocol Suite. The easiest way to understand how network stacks work is to buy a copy of "TCP/IP Illustrated: Volume 1", download a nice network capture utility, and watch some Internet traffic. You can see how the packets are assembled from the physical layer upward.

Fourpence answered 25/12, 2012 at 1:16 Comment(4)
To say "The OSI stack isn't really used any longer" is just flat-out wrong. The OSI 7-layer stack is a reference model. The X.500 protocol implementation (like contemporaries DecNET and LanTastic) - ancient history. The OSI reference model: is - and continues to be - a valuable conceptual model. IMHO... PS: "frames" (Layer 2), "packets" (Layer 3) and "datagrams" (TCP/IP, Layer 4) are all examples of "PDUs" (Protocol Data Units) and are all very well defined!Piscatory
@Piscatory - what I mean is that the OSI model as defined, most notably layers 5 and 6, are all but forgotten. Everything above the transport layer has merged into the application layer which is precisely what the IETF model is. I do agree that OSI is well-defined to a fault where the IETF model is, at best, loosely defined.Fourpence
@Piscatory The OSI reference model applies to the ODI protocol stack. TCP/IP has its own reference model, and it has 4 layers, not 7. The 7 layer OSI reference model is as obsolete as the protocol stack it refers to.Purism
@D.Shawley: +1 - good explanation. In particular, thank you for distinguishing "frames", "packets" and "datagrams". And noting that TCP "byte streams" and UDP "datagrams" are what's passed to the "Application Layer" (layer 7: the level at which your program is actually reading and writing network data).Piscatory
B
5

The term datagram is often considered synonymous to packet but there are some nuances. The term datagram is generally reserved for packets of an unreliable service, which cannot notify the sender if delivery fails, while the term packet applies to any packet, reliable or not. Datagrams are the IP packets that provide a quick and unreliable service like UDP, and all IP packets are datagrams;[4] however, at the TCP layer, what is termed a TCP segment is the sometimes necessary IP fragmentation of a datagram,[5] but those are referred to as "packets".[6]

[Emphasys added]

Wiki source

Berezniki answered 21/2, 2018 at 14:20 Comment(0)
P
0

You absolutely need to familiarize yourself with the "7 layer network stack".

It doesn't perfectly apply to TCP/IP, but it's an excellent basis for understanding any "networking" protocol - including TCP/IP:

Short answer:

  • "packets" are something that are sent over the network.

  • For TCP/IP, the receiving hosts assembles the packets into a "stream".

  • For UDP, on the other hand, the receiving host assembles the same packet (or, actually packet(s)) into a "datagram".

"Packets" are a level 3 ("network layer") thing.

"Streams" and "datagrams" are a level 4 ("transport layer" thing).

In the case of TCP/IP, both "streams" and "datagrams" are accessed directly by Layer 7 (the "application layer": which includes HTTP/web, SMTP/e-mail, FTP/file transfer, etc etc).

Piscatory answered 25/12, 2012 at 0:56 Comment(2)
He may need to familiarise with the 4 layer TCP/IP model. There is absolutely no need to familiarise with the obsolete and inapplicable 7 layer OSI network model.Purism
It is certainly not an ignorant statement, and your comment is borderline offensive. All the standard authors on TCP/IP that I have ever read, including the RFCs themselves, agree that the OSI model doesn't apply to it, and there are whole layers of OSI that don't apply to anything in particular at all: not even to the OSI protocol stack with any great precision actually. As a pedagogical tool it is obsolete by about 20 years. What is important is the concept of protocol layers, and the fairly universal agreement on what is in layers 2 and 3.Purism
P
-1

Is it true that upon receiving a segment from Transport Layer(TCP) towards Network Layer(IP) the resulting data unit will be a packet.

No.

The only unit of reception in TCP that the client can see is a byte. TCP segments consist of one or more IP packets but all the application can see is a byte stream. Any and all segment and packet boundaries are lost before the application ever gets to see any data. You send some bytes, you receive some bytes, and there is no necessarily strong correlation between how many were sent and received respectively, except that they all add up to the same stream.

In UDP by contrast the unit of both sending and receiving is the datagram. You send a datagram, and if it arrives intact you receive the same datagram containing the same bytes and the same number of bytes.

Purism answered 26/12, 2012 at 8:40 Comment(3)
Close, but still not quite correct. The network layer deals with packets: true. It's the Application layer (Layer 7) that deals with either 1) a stream of bytes, or 2) a UDP datagram. Not the network layer :) Interestingly, the datagram may or may not be the size of your layer 3 packet: cboard.cprogramming.com/networking-device-communication/…Piscatory
@Piscatory Come to think of it I'm not even sure what 'receiving a segment from Transport Layer ... towards Network Layer even means. TCP doesn't send segments to IP at all, they are a figment of its own imagination, not part of the interface.Purism
@paulsm Late, but I haven't stated anything whatsoever about the network layer, let alone what you have attributed to me here. Talking about layer 7 in the context of TCP/IP is meaningless. The TCP/IP reference model doesn't have 7 layers, and the 7-layer OSI model doesn't apply to TCP/IP, or to anything else that I am aware of. I don't see what your link has to do with my answer.Purism

© 2022 - 2024 — McMap. All rights reserved.