Network Layer
Internet Protocol
An IP datagram consists of a header part and a text part.
IPv4
- IPv4 Header
- The header has a 20-byte fixed part and a variable length optional part.
- Fixed Part include:
- Version
- IHL
- TOS
- Total Length
- Identification
- DF and MF
- Fragment offset
- TTL
- Protocol
- Header checksum
- Source address and destination address
- Fixed Part include:
- The header has a 20-byte fixed part and a variable length optional part.
IPv4 Header Part
Version
Version: to keep track of which version of the protocol the datagram belongs to. 4 bit
IHL
IHL: to provide the length of the header, in 32-bit words. 4 bit
- When the value is 5, which applies no options are present.
TOS
TOS: (Type of service) to distinguish between different classes of services. 8 bit
- Three-bit precedence field and three flags, D, T, and R {Delay, Throughput and Reliability}. 3 bit
- 三位优先字段(precedence field)和三标志位(D、T、R)用于指示数据报的服务质量需求和优先级。这些字段通常位于IPv4首部的服务类型(Type of Service, TOS)字段中。
TOS Bits | Description |
---|---|
0000 | Normal (default) |
0001 | Minimize cost |
0010 | Maximize reliability |
0100 | Maximize throughput |
1000 | Minimize delay |
这个表格展示了服务类型字段的不同比特组合及其对应的描述。每种组合表示数据报在传输过程中不同的服务质量要求,例如默认服务、最小化成本、最大化可靠性、最大化吞吐量和最小化延迟。
Total Length
Total Length: to provide the length of the datagram (including header and data). 16 bit
Identification
- Identification: to identify each datagram.
16 bit
Fragment and Fragment offset
- DF and MF: don’t fragment, and more fragments.
3 bit
- Fragment offset: To tell where in the current datagram this fragment belongs.
13 bit
TTL
- Time to live: a counter used to limit packet lifetimes.
8 bit
Protocol and Header Checksum
- Protocol: to tell which protocol process to give it to (e.g., TCP or UDP).
8 bit
- Header checksum: to detect errors in the datagram.
16 bit
Source address and Destination address
Source address and destination address
32 bit
Unique: no two machines on the Internet have the same IP address.
32-bit long.
IPV4 Summary
字段 | 比特数 | 功能描述 |
---|---|---|
版本 (Version) | 4 | 标识IP协议的版本,IPv4的版本字段值为4 |
首部长度 (IHL) | 4 | 指示IP数据报首部的长度,以32位(4字节)为单位 |
服务类型 (TOS) | 8 | 指定数据报的优先级和服务质量 |
总长度 | 16 | 指示整个IP数据报的总长度,包括首部和数据部分,以字节为单位 |
标识 (Identification) | 16 | 唯一标识数据报,以便在需要时进行分片和重组 |
标志 (Flags) | 3 | 控制和识别数据报的分片,包括不分片位(DF)和更多分片位(MF) |
片偏移 (Fragment Offset) | 13 | 指示数据报片在原始数据报中的相对位置,以8字节为单位 |
生存时间 (TTL) | 8 | 限制数据报在网络中的生存时间,防止无限循环 |
协议 (Protocol) | 8 | 指示数据报携带的数据所使用的协议,如TCP、UDP等 |
首部校验和 (Header Checksum) | 16 | 验证IP首部的完整性 |
源地址 (Source Address) | 32 | 表示数据报发送方的IP地址 |
目的地址 (Destination Address) | 32 | 表示数据报接收方的IP地址 |
选项 (Options) | 可变 | 支持其他的控制功能和服务,长度可变,最多可达40字节 |
总结:IPv4首部的基本部分是20字节(160位),但如果包含选项字段,长度可能会超过20字节。选项字段的长度是可变的,最大可达40字节,因此整个IPv4首部的最大长度是60字节。
IPv6
Transition from IPv4 to IPv6
- Three transition strategies
Dual stack
Tunneling
Header translation
Dual Stack
Tunneling
Header Translation
Network Routing
Delivery
- The network layer supervises the handling of the packets by the underlying physical networks.
- We define this handling as the delivery of a packet.
- Direct and indirect delivery
Forwarding
- Forwarding means to place the packet in its route to its destination.
转发
- Forwarding requires a host or a router to have a routing table.
- When a host has a packet to send or when a router has received a packet to be forwarded, it looks at this table to find the route to the final destination.
Routing Algorithms
Shortest Path Routing
- To study the routing algorithms, a graph is commonly used to represent a subnet.
- Each node of the graph represents a router and each arc of the graph represents a communication line.
- The path length can be measured in terms of the number of hops, the geographic distance, etc.
Dijkstra Algorithm
[!abstract]+ Dijkstra Algorithm
- Set the value of the initial node to zero and set all other nodes to infinity.
- Mark all nodes unvisited. Set the initial node as starting point.
- For the current node, consider all of its unvisited neighbors and calculate their tentative distances.
- Mark the current node as visited and remove it from the unvisited set. A visited node will never be checked again.
- If the destination node has been marked visited or if the smallest tentative distance among the nodes in the unvisited set is infinity, then stop. The algorithm has finished.
- Set the unvisited node marked with the smallest tentative distance as the next current node and go back to step 3.
Flooding Algorithm
- Every incoming packet is sent out on every outgoing line except the one it arrived on.
- To solve the vast numbers of duplicate packets, a hop counter is introduced.
- The hop counter is contained in the header of each packet.
- It decremented at each hop. The packet will be discarded when the counter reached zero.
Distance Vector Routing
- It is a dynamic routing algorithm.
- Each router maintains a table giving the best known distance to each destination and which line to use to get there.
- These tables are updated by exchanging information with their neighbors.
- An entry of routing tables contains two parts: the preferred outgoing line to be used for the destination, and an estimate of the distance to that destination.