Let’s say I want to write an online music player.
Okay, so I write the code for someone to press play on a website and the song plays.
Do I now need to code up the protocol that streams the music?
Fine, I write some UDP code.
Now, do I need to go install the cables in your house?
Sure, I jump in my van and spend a few weeks running cable to your house and make sure the packets can get over too.
This sounds absurd.
As a web developer, I don’t want to worry about anything other than making my music player easy to use and fast.
I don’t want to worry about UDP and I don’t want to worry about ethernet or cables.
It’s already done, I can assume it’s taken care of.
And it is.
Internet protocols exist in layers.
We have four such layers in the computer science internet model.
The top two levels were discussed before in detail, the bottom two we won’t focus on.
The first layer is the Application layer, followed by the Transport, Internet and Link layers.
At each layer, data is made up of the previous layers’ whole unit of data, and then headers are added and passed down.
At the bottom layer, the Link layer, a footer is added also.
Below is an example of what a UDP packet looks like when it’s packaged up for transport.
Headers and footers
Footers and Headers are basically packet meta-data.
Information about the information.
Like a letterhead or a footnote, they’re not part of the content, but they are on the page.
Headers and Footers exist on packets to store data.
Headers come before the data and footers afterwards.
You can think of these protocols as a game of pass the parcel.
When a message is sent in HTTP, it is wrapped in a TCP header, which is then wrapped in an IPv6 header, which is then wrapped in a Ethernet header and footer and sent over ethernet.
At the other end, it’s unwrapped again from an ethernet frame, back to a IP packet, a TCP segment, to a HTTP request.
What is a packet?
The name packet is a generic term for a unit of data.
In the application layer units of data are called data or requests, in the transport layer, datagram or segments, in the Network/IP layer, packet and in the physical layer, a frame.
Each level has its own name for a unit of data (segment, packet, frame, request etc), however the more generic "packet" is often used instead, regardless of layer.
This system is neat because each layer can assume that the layers above and below have guaranteed something about the information, and each layer (and protocol in use at that layer) has a stand-alone role.
So if you’re making a website you just have to program website code, and not worry about code to make the site work over wifi as well as ethernet.
A similar system is in the postal system, you don’t put the courier’s truck number on the front of the envelope!
That’s taken care of by the post company, which then uses a system to sort the mail and assign it to drivers, and then drivers to trucks, and then drivers to routes… none of which you need to worry about when you send or receive a letter or use a courier.
The OSI model vs the TCP/IP model
The OSI model of the internet is different from the TCP/IP model that Computer Scientists use to approach protocol design.
OSI is considered and probably mentioned in the networking standards but this guide will use the computer science approach because it is simple.
The main idea of layers of abstraction is more important.
You can read more about the differences here.
So what does a TCP segment look like?
ACK number (if ack)
A packet is divided into four main parts:
Two 16 bit addresses (source, destination)
Two 32 bit numbers (sequence number, ACK number if it’s an acknowledgement)
Between 64 and 384 bits worth of flags and options
And the actual data
At each level, the data is the entirety of the previous level segment, which includes its own header and data.
TCP and UDP packets have a number saying how big they are.
This number means that the packet can actually be as big as you like.
Can you think of any advantages of having small packets.
How about big ones.
Think about the ratio of data to information (such as those in the header and footer).