takeaway
Objective: To establish a holistic understanding of the fundamentals of computer networks
Estimated reading time: 15 minutes
Applicable groups:
- Wan, LAN, bridge, gateway, switch, subnet mask and other nouns confused by the meng new;
- Chew “TCP/IP detailed explanation” and other textbooks chew to cry helpless pain engineer;
- A candidate who is preparing for an interview. Note 1
First edition: Computer Network Basics (0 threshold)
Before We Start
Let’s forget all the bits and pieces of knowledge in your head and start with the simplest.
Logistics? The data flow?
The package goes like this:
The data frame goes like this:
Express is the basic unit of express transportation, residents in the area can directly send express to each other; Each area has a receiving and receiving point. External express delivery is uniformly delivered by the receiving and receiving point, and external express delivery is uniformly forwarded to the superior distribution station by the receiving and receiving point. Each terminal is responsible for multiple zones, forwarding express delivery between terminals, and distributing express delivery within its own zone to corresponding receiving and receiving points.
Data frame is the basic unit of network transmission. Hosts in network segment can communicate with each other directly. Each network segment has one switch. The switch broadcasts external data frames to all hosts and forwards the outgoing data frames to the upper-layer router. Each router is responsible for multiple network segments. It forwards data frames between routers and distributes the data frames in its own network segment to the corresponding switch.
knowThe express packageData frame
A complete package contains at least: the recipient’s address, the recipient’s mobile phone, the sender’s address, the recipient’s mobile phone, and the items to be sent.
Data frames are really similar to express 🐶 🐶…
-
Destination MAC => Recipient mobile phone number
-
Source MAC => Sender’s mobile phone
-
Destination IP Address => Recipient IP address
-
Source IP address => Sender IP address
-
Data => The object to be sent
A complete data frame looks like this:
Here’s a little basics:
- According to the Ethernet protocol, all devices that access the network must be installed with network adapters, that is, network adapters.
- Data frames must be sent from one network card to another. The network card (MAC) address is the send and receive address of the data frame.
- The Media Access Control (MAC) address is the unique identifier of each NETWORK adapter. The MAC address consists of six hexadecimal bytes. The first three bytes are the manufacturer number and the last three bytes are the SERIAL number of the network adapter.
In addition, the data frame has a frame check sequence, which allows the network adapter or interface that receives the data frame to determine whether an error occurred in the data frame. Note 2.
From this point of view, data frame is more reliable than express delivery. Every time there is a problem with the express package, they have to take the initiative to ask me where the express is. 😓
Data frame transfer
The sender wants to send an object, see the recipient first with whether he is in the same community, if so, give him directly; No, then give it to the dot.
To send a data frame, the host first checks whether the target host is on the same network segment as the host. Yes, throw the frame directly to each other; If not, send it to the switch.
Jargon: The host first checks whether the local IP address and destination IP address reside on the same network segment. If the host on the same network segment has no ARP entry corresponding to the destination host, the sending host broadcasts an ARP request based on the IP address of the destination host to obtain the MAC address. After receiving the ARP request, the destination host loads its MAC address and IP address into the ARP reply and sends them back to the sending host. After receiving the ARP reply, the sending host extracts the MAC address of the destination host. In the ARP table, the device establishes an entry (the mapping between IP addresses and MAC addresses) corresponding to the destination host. Then the device sends data to the destination host, encapsulates the data into frames, and forwards the data to the destination host in the network segment. The communication is complete. If they are on different network segments, the packets are sent to the switch for forwarding. Note 4
Transmission should be reliable. Kill and bury
This describes how data frames are transferred from one host to another, but there are many programs on the host.
Put a port in front of the data. Whichever program uses the port, throw the data to the person.
This is UDP. Through UDP, we realize the data transfer between applications.
But there is a problem, express will lose pieces, data frame to smooth transmission is not so easy…
On the way, you may be blocked by the firewall; Maybe the router is jammed; Maybe the other party dropped the line; The Wolf probably got away with it…
How to ensure that the data frame is delivered? Which brings us to TCP.
To ensure reliable transmission communication, at least three problems need to be solved:
- How do I establish and disconnect a connection?
- I sent a data frame, how to confirm that the other party has successfully received?
- What if one party dropped the line?
1. Establish/disconnect the connection
A three-way handshake is used to establish a connection. A four-way handshake is used to disconnect a connection.
Q: Why do you need three handshakes?
A: Because two times is unreliable, and four times is pants farting. (Rough words, but not rough)
(The picture is from the network, if infringement, please contact the author to delete.)
Q: Why do you need to wave four times?
A: Because TCP communication is two-way. I have nothing to pass (1 time), you confirm (2 times); You don’t have anything (3 times), I also confirm (4 times). At this point, the connection can be completely disconnected.
(The picture is from the network, if infringement, please contact the author to delete.)
2. “Receipt” mechanism
TCP agreement:
After the sender sends a packet, it starts a timer and waits for the “receipt” from the destination. If the “receipt” is not received in time, the package will be reissued.
When the destination receives a packet, it sends a “receipt” telling the sender I received it.
The receipt is also a data frame, a “receipt” specifically sent once, is not a bit of a waste ah…
TCP is a bad idea. It assumes that the receiver will not send a “receipt” immediately, but will wait (usually around 200ms) to see if the sender has requested the data. If so, put the “receipt” inserted into the data the other party needs, send back together; If not, send a special “return receipt”.
3. Reset the mechanism
TCP designed a reset mechanism to deal with broken lines, data frame errors and other problems.
If the recipient is disconnected, you can repeat the message no matter how many times you send it. Therefore, if TCP fails to retransmit five times by default (the number of times can be set by yourself), the connection is reset.
If a party feels that the other party or the data sent by the other party has problems, it can also proactively trigger connection reset at any time to ensure stable and correct communication.
Q: Why is TCP expensive?
A: Never mind that it takes three handshakes and four waves to establish A disconnect; In order to confirm the correct arrival of a packet, we need to return receipt, repeat the packet, and consider whether the other party dropped the line… ; There are many, many things not covered in this article: slow start, congestion control, sliding window mechanisms… Worry so much, can cost little. 😂
Q: TCP is awesome. Why do you need UDP?
A: Because UDP is fast. If you don’t care so much about stability (like watching a movie, it doesn’t matter if you lose one or two frames), doesn’t it smell good to transmit faster? Well, there’s always something to it. PS:HTTP3 is based on UDP rather than TCP, interested in search to read.
Put the data to work
Thanks to TCP, thanks to IP, thanks to MAC, finally the data is passed safely from one program to another!!
But how does this piece of data work? Is he a picture? Video? The text? Easter eggs? Or what?? 😕
TCP does not interpret the content of the byte stream. TCP does not know whether it transmits binary data, ASCII characters, EBCDIC characters, or other types of data.
Obviously, this requires both ends of the program to agree on what protocol to use, what to pass, what to do… And so on.
How to do? This is what HTTP, POP3, SMTP and other protocols do.
Finally, let’s look at the wrapping process from data to a complete data frame:
At the end
Wait, hey, all this protocol talk and not even the OSI seven layer model?
Not only that, wan, bridge, gateway, ARP, DARP, IP protocol, routing protocol, etc., are not introduced, if not necessary, do not add concepts. Note 5
The resources
What’s going on with the TCP/IP family
What are routers and switches if you know about express delivery
TCP/IP, rounding
History of Ethernet
Why use MAC addresses when you have IP addresses? Hello, the world’s answer – Zhihu
Subnet, LAN, and network segment
- The author is currently working in Shence Data · Marketing Cloud. If you want to push, please send your resume to [email protected]. ↩
- Check the principle of reference: CRC calculation and principle, non-network engineers do not need to explore. ↩
- If the two IP addresses are consistent with the local subnet mask, they are on the same network segment. Otherwise, the two IP addresses are on different network segments. ↩
- If the jargon looks too tiring, skip it. ↩
- Steal from “Don’t add substance if you don’t need it.” The author believes that learning should first focus on the essence of the problem and the core solution, and gradually understand the concept and details in the process of learning the solution and its evolution. ↩