An overview of the

function

The network layer, which moves packets from a sending host to a receiving host, needs to provide two functions

  • Forwarding A router local action that transfers packets from an input link interface to the appropriate output link interface
  • Routing refers to the network-wide process of determining the end-to-end path taken by a packet from source to destination.

classification

  • Virtual-Circuit (VC) a computer network that provides connectivity services only at the network layer, such as ATM networks and frame relay
  • The Datagram Network provides connectionless computer networks only at the network layer

The network layer of the Internet provides best-effort service

Other network architecture models (such as ATM (Asynchronous Transfer Mode) networks, frame relay, and so on) may provide specific services such as ensuring delivery, ensuring minimum bandwidth, and so on.

Internet Protocol (IP)

IPv4

See Wikipedia IPv4

Message format

Header Field Meaning

An IP datagram with no option header is 20 bytes long, and if it carries a TCP packet segment, each (non-fragmented) datagram carries a total of 40 bytes header (20 bytes IP header, 20 bytes TCP header).

IP datagram fragmentation

Why sharding?

The Maximum amount of data that a link layer frame can carry is called the MTU. Different link layer frames have different sizes. An Ethernet frame can carry no more than 1500 bytes of data, and a wan frame can carry no more than 576 bytes of data. When the IP datagram is larger than the MTU of the link layer protocol, fragmentation is required.

How to sharding and regrouping?

Fragmentation is supported only in IPv4, but not in IPv6. (If an IPv6 datagram is too large to be forwarded to the link, the router only needs to discard the datagram and send an ICMP error message with “Packet too large” to the sender.)

Shard can be performed in the router, and reassembly in the router will affect performance, so the reassembly is completed in the end system, and the destination host is assembled by the identity, flag and slice offset field in the header of the IP datagram.

Detailed assembly process does not need to be described, general understanding can be.

addressing

capacity

IPv4 uses 32-bit (4-byte) addresses, so there are only 4,294,967,296 (2^32) addresses in the address space. However, some addresses are reserved for special purposes, such as private networks (about 18 million addresses) and multicast addresses (about 270 million addresses), which reduce the number of addresses available on the Internet.

It is in dotted decimal notation

An IPv4 address can be written in any form representing a 32-bit integer value, but for human reading and analysis, it is usually written in dotted decimal notation, with four bytes written separately in decimal notation, separated by dots. For example, 192.0.2.235. In addition, in the dotted format, each byte can be expressed in any base. For example, 192.0×00.0002.235 is a legal (but uncommon) representation.

IPv6 address representation

In binary format, the IPv6 address consists of 128 bits. Each group consists of 16 bits, separated by colons (:), and can be divided into eight groups. Each group is represented by four hexadecimal digits. For example: 2001:0 db8:86 a3:08 d3:1319:8 a2e: 0370:7344 is a valid IPv6 address. Similar to the dotted decimal notation of IPv4, the dotted hexadecimal notation also exists. After removing the colons of eight groups of 4-digit hexadecimal addresses, each group is marked with a period (.). Grouping, for example: 2001:0 db8:85 a3:08 d3:1319:8 a2e: 0370:7344 is counted as 2.0.0.1.0 d.b. 8.8.5. A. 3.0.8. D. 3.1.3.1.9.8. A. 2. E. 0.3.7.0.7.3.4.4, In reverse order, it is used to record the mapping between IPv6 addresses and domain names.

The rule

  • The leading 0 of each digit can be omitted, and the leading 0 continues after the omission
    • 2001:DB8:2de:0:0:0:0:e13
  • A double colon “::” can be used to indicate a group of zeros or consecutive groups of zeros, butIt can only happen once
    • 2001:0DB8:0::0:1428:57ab

Classification of addressing

The network portion of the IP address is limited to 8, 16, or 24 bits in length, and the high bits of the address are redefined as the Class of the network. The system defines five categories: A, B, C, D, and E. Classes A, B, and C have different network class lengths, and the rest of the network is used to identify hosts within the network, which means that each network class has A different ability to address hosts. Class D is used for multicast addresses and class E is reserved for future use.

But class C (/24) subnets can only hold 2^ 8-2 = 254 hosts, and class B (/16) is too large to support 65534 hosts. This can lead to insufficient or wasteful address space.

Address classification

Refer to IPv4 wikipedia for the description of address classification.

Local loopback address

Wikipedia LocalHost

Localhost is a host name used to represent “this computer” in a computer network. It is used to access natively running services through the local loopback network interface and will bypass any physical network interface hardware.

Public address, private address

Zhihu – Why are IP addresses of lans generally starting with 192.168?

  • Public address
    • Most IP addresses in class A, B, and C are public and need to be registered with the Internet Information Center. However, the IPv4 address protocol reserves three IP address segments as private addresses for internal use.
  • Private address
    • Class A ADDRESSES: 10.0.0.0 to 10.255.255.255

Class B address: 172.16.0.0–172.31.255.255 Class C address: 192.168.0.0 to 192.168.255.255 – Common Lans Use class C 192.168.0.0 as the address segment due to the small capacity. Some large enterprises need to use Class B or even Class A IP addresses as the address segment of the internal network.

CIDR

Classless Interdomain Routing

a.b.c.d/x

CIDR creates a layered architecture managed by the Internet Bureau for Assigned Numbers (IANA) and Regional Internet Registries (RIR), each of which maintains a common WHOIS database to provide IP address assignment details.

DHCP

role

Dynamic Host Configuration Protocol

DHCP allows a host to automatically acquire (be assigned) an IP address and obtain other information, such as its subnet mask, the address of the first-hop router (default gateway), and the address of the local DNS server.

Network administrators can configure DHCP so that a given host gets the same IP address each time it connects to the network, or that a host will be assigned a temporary IP address.

Request process

  • During the DHCP request step, the DHCP server constructs a request message from one or more servers. The DHCP server may have multiple servers

NAT

Network Address Translation

See NAT on Wikipedia

role

A solution to IPv4 address shortage to avoid the difficulty of reserving IP addresses. A popular belief on the web is that widespread adoption of IPv6 will make NAT unnecessary, since NAT is simply a way of dealing with IPv4’s address-space inadequacy

Assume that the allocated IP addresses can only be used by 256 hosts, and assume that more hosts are connected, then without NAT, you can only apply for new IP addresses to ensure that enough hosts can be accommodated. However, if NAT is used, there is no need to maintain a NAT table for internal forwarding.

How to work

NAT Translation Table

Assume that the router address is 138.76.29.7

ICMP

Internet Control Message Protocol

Refer to Wikipedia ICMP

role

message

IPv6

See Wikipedia IPv6

Message format

Header Field Meaning

Different from IPv4

IPv4 has unicast and multicast addresses, and IPv6 has one more unicast address.

Transformation mechanism

  • Double stack
    • Dual IP stack implementation regards IPv6 as an extension of IPv4. It is relatively easy to implement network stack by sharing code. It can support both IPv4 and IPv6.
  • The tunnel
    • To connect to the IPv6 Internet, an isolated host or network needs to use the existing IPv4 infrastructure to carry IPv6 packets. This can be done by tunneling protocols that load IPv6 packets into IPv4 packets, in effect using IPv4 as the link layer for IPv6.

The router

The working principle of

  • 1. Input port

    • The physical link is connected to the router to implement physical layer functions

  • 2. Output port

  • 3. Exchange structures

    • The internal structure of the router connects the input and output ports

    • Transmemory swap
      • The simplest and earliest routers are traditional computers
    • Transbus switching
    • Through the Internet exchange
  • 4. Routing processor

    • Implements routing protocols, maintains routing tables, and maintains link state information for connections

If the router output Queue cache is congested, the strategy to manage the cache is called Active Queue Management (AQM)

The Random Early Detection (RED) algorithm is an AQM algorithm.

Routing algorithm

Classification – link state algorithm and distance vector algorithm

A classification in a broad sense

  • Global routing algorithm
    • Use the completed global network knowledge to calculate the lowest cost path from source to destination, taking connectivity and cost between all nodes as input
    • Example: Link State algorithm (LS) (Dijkstra algorithm)
  • Distributed routing algorithm
    • The lowest cost path is calculated in an iterative and distributed way. No node has complete information about the cost of all network links, while each node only has the cost information of links directly connected to it.
    • Example: Distance-vector (DV) algorithm

Another classification in a broad sense

  • Static route selection algorithm
    • Manual configuration
  • Dynamic routing algorithm
    • Change the routing path when the network load or topology changes

Link state algorithm – Dijkstra algorithm

Dijkstra algorithm

Distance vector algorithm

Each node needs to maintain a routing table, based on bellman-Ford algorithm

contrast

For details, see 4.5.2.3

Autonomous systems

The routing algorithm that operates within an Autonomous System is called the Autonomous System Internal Routing Protocol (IGP). A router in an AS that forwards packets to destinations outside the AS is called a gateway router. There is also inter-Autonomous System routing protocol (BORDER Gateway Protocol BGP).

Routing protocol

Internal gateway protocol: RIP

Routing Information Protocol, based on bellman-Ford algorithm, is a distance vector Protocol that exchanges submessages with neighboring routers every 30 seconds to dynamically create Routing tables.

Refer to Wikipedia

The internal gateway protocol is OSPF

Open Shortest Path First Refer to Wikipedia

OSPF is an implementation of link-state routing protocol and operates in an autonomous system (AS). It uses Dijkstra algorithm to calculate the shortest path tree.

Border Gateway protocol: BGP

Border Gateway Protocol

It implements the reachability between Autonomous systems (AS) by maintaining the IP routing table or “prefix” table (CDIR prefix). It is a vector routing protocol.

Refer to Wikipedia

Broadcast and multicast routing

  • unicast
    • Only two entities communicate with each other at a time, and the sender and receiver are uniquely identified.
  • radio
  • multicast
    • It transmits information simultaneously to a group of destination computers.

Broadcast routing

The network layer provides a source node to deliver groups to all other nodes in the network

N unicast

  • Uncontrolled flooding

  • A controlled flooding

    • Reverse path forwarding RPF
  • Spanning tree broadcast

Multicast routing

A single source node delivers a grouping to a subset of other nodes in the network

  • IGMP
  • DVMRP