Stanford University CS144 study Notes
文章目录
- 1. The 4-layer Internet model
- 2. The IP Service
- 3. Life of a Packet
- 4. Principle
- 5. Memory, Byte Order, and Packet Formats
- 6. Names and Addresses: IPv4
- 7. Address Resolution Protocol (ARP)
1. The 4-layer Internet model
The 4-layer Model
Application: Bi-directional reliable byte stream between two applications using application-specific semantics (e.g. HTTP, SSH, FTP…)
Transport: Guarantees correct, in-order delivery of data end-to-end. Controls congestion (e.g. TCP, UDP).
*Network (the most important): Delivers datagrams end-to-end. Best-effort delivery - no guarantees. Must use the Internet protocol (only IP)
Link: Delivers data over a single link between an end host and router or between routers. (e.g. Ethernet, WiFi, DSL, 5G…)
The 7-layer OSI Model
2. The IP Service
The Internet Protocol
The Network Layer is the most important layer of the Internet. The Internet Protocol (IP) is the implement of the Network Layer.
The properties of IP
-
Datagram
IP is a datagram service. When we ask IP to send some data for us, it creates a datagram and puts our data inside.
The datagram is a packet that is routed individually through the network based on the information in its header. -
Unreliable
IP makes no promise that packets will be delivered to the destination. -
Best effort:
IP does make the promise to only drop datagrams if necessary. -
Connectionless
IPv4 Datagram
-
version: IPv4 or IPv6
-
Header Length: The length of the header.
-
Type of Service: The Importance of Packets.
-
Total Packet Length: Contains the header and all data.
-
Packet ID, Flags, Fragment Offset: Segmented datagram.
-
Time to Live “TTL”: Remaining survival time. After one forwarding minus one, 0 is recognized as entering an endless cycle, and then discarded.
-
Protocol ID: TCP、UDP etc.
-
Checksum: The calculated checksum of the header.
3. Life of a Packet
TCP Byte Stream
The three way handshake
-
The client sends a “synchronize” message to the server, often called a SYN.
-
The server responds with a “synchronize” message that also acknowledges the clients “synchronize”, or a “synchronize and acknowledge message”, often called a SYN-ACK.
-
The client responds by acknowledging the server’s synchronize, often called an ACK.
So the three way handshake is described as “synchronize, synchronize and acknowledge, acknowledge”, or “SYN, SYN-ACK, ACK”.
Inside the Stream
IP packets between the client and server take many “hops” , where a hop is a link connecting two routers.
Inside Each Hop
The router use a forwarding table to make a decision to the next router in the IP.
When a packet arrives, the router checks which forwarding table entry’s pattern best matches the packet. It forwards the packet along that entry’s link. Generally, “best” means [the longest prefix match](###Longest Prefix Match).
Longest Prefix Match
Inside Each Hop (for real)
For example
4. Principle
Packet Switching
Packet & Packet switching
Packet: A self-contained unit of data that carries information necessary for it to reach its destination.
In packet switching, there is no dedicated circuit to carry our data. Instead, we send a block of data by adding a header to it, and call it a packet. The header contains the address of where the packet is going.
Packet switching: Independently for each arriving packet, pick its outgoing link. If the link is free, send it. Else hold the packet for later.
Two consequences
1. Simple packet forwarding
No per-flow state required.
Flow: a collection of datagrams belonging to the same end-to-end communication e.g. a TCP connection.
Packet switches don’t need state for each flow — each packet is self-contained.
-
No per-flow state to be added/removed.
-
No per-flow state to be stored.
-
No per-flow state to be changed upon failure.
Packet switches are simple: they forward packets independently and don’t need to know about flows.
2. Efficient sharing of links
Data traffic is bursty
- Packet switching allows flows to use all available link capacity.
- Packet switching allows flows to share link capacity.
Packet switching is efficient: It lets us efficiently share the capacity among many flows sharing a link.
Layering
Reasons for layering
-
Modularity
It breaks down the system into smaller, more manageable modules.
-
Well defined service
Each layer provides a well defined service to the layer above.
-
Reuse
A layer above can rely on all the hard work put in by others to implement the layers blow.
-
Separation of concerns
Each layer can focus on its own job, without having to worry about how other layers do theirs. The only communication is up-down the layers.
-
Continuous improvement
It allows continuous improvement of each function.
-
Peer-to-Peer communications
Encapsulation
Two ways to draw packets
There are two ways to draw packets.
The difference comes from background and what part of the system you work on.
How layering manifests in data representation
Let’s say that you’re browsing the web using a computer connected through WiFi, wireless Ethernet.
- Your web browser generates an HTTP GET request.
- The HTTP GET request is the payload of a TCP segment.
- The TCP segment is the payload of an IP packet, which encapsulating the HTTP GET.
- The IP packet, encapsulating the TCP segment and the HTTP GET, is the payload of a WiFi frame.
Encapsulation Flexibility
- Encapsulation allows you to layer recursively.
- Example: Virtual Private Network (v*n):
The consequence of encapsulated payloads
- Help separation of concerns
- Help enforce boundaries/layering
- Simplify layer implementations
5. Memory, Byte Order, and Packet Formats
Computer Memory
Endianness (Byte Order)
Little endian
least significant byte is at lowest address.
Makes most sense from an addressing/computational standpoint.
Big endian
most significant byte is at lowest address.
Makes most sense to a human reader.
Packet Formats
6. Names and Addresses: IPv4
Goal of Internet Protocol Addresses
- Stitch many different networks together
- Need network-independent, unique address
Internet Protocol, Version 4 (IPv4)
An IPv4 address identifies a device on the Internet
- Layer 3 (network) address
32 bits long (4 octets): a.b.c.d
- Example: 171.64.64.64
- Example: 128.30.76.82
- Example: 12.22.58.30
Netmask: apply this mask, if it matches, in the same network
- Netmask of 255.255.255.0 means if the first 24 bits match
- Netmask of 255.255.252.0 means if the first 22 bits match
- Netmask of 255.128.0.0 means if the first 9 bits match
- Smaller netmask (fewer 1s) means larger network
- We just need to caculate “IP BITAND netmask”, see if they’re the same.
Address Structure
Address Structure (historical)
-
Originally hierarchical: network + host
-
Originally 3 classes of addresses: class A, class B, class C
Address Structure Today
-
Class A, B, C is too coarse grained (e.g., MIT dorms!)
-
Classless Inter-Domain Routing (CIDR)
- Address block is a pair: address/count
- Counts are powers of 2, specify netmask length
- 171.64.0.0/16 means any address in the range 171.64.0.0 to 171.64.255.255
- A /24 describes 256 () addresses, a /20 describes 4,096 () addresses
7. Address Resolution Protocol (ARP)
“I have an IP packet whose next hop is this address – what link address should I send it to?”
ARP Packet Format
Address Resolution Protocol
Take host A (192.168.38.10) sending data to Host B (192.168.38.11) as an example.
- When sending data, host A looks for the target IP address in its own ARP cache table. If you find it, you will know that the target MAC address is (00-BB-00-62-C2-02). The target MAC address directly write into the frame and send it.
- If an IP address is not found in the ARP cache table, host A sends an ARP request over the network, the target MAC address is “FF.FF.FF.FF.FF.FF”,This means making such a query to all hosts within the same network segment: “What is the MAC address of 192.168.38.11?”
- Other hosts on the network do not respond to ARP query. Only when host B receives this frame, will it give such A response (ARP Response) to Host A: “The MAC address of 192.168.38.11 is 00-BB-00-62-C2-02”, this response is unicast. In this way, host A knows the MAC address of host B, and it can send information to host B. It also updates its ARP Cache so that the next time it sends a message to host B, it can look it up directly from the ARP cache table.