Two services provided by the network layer
Virtual Circuit Services: When two computers to communicate, first establish a connection to ensure that the two sides to communicate all the network resources required.
Datagram Services: The network layer only provides a simple, flexible, non-connected, and best-effort delivery of datagram services. The network does not establish a connection when sending packets, and each packet is sent independently, regardless of its grouping, and does not provide a quality of service commitment.
IP protocol
The IP protocol also includes ARP (Address Resolution Protocol), RARP (Inverse Address Resolution Protocol), ICMP (Internet Control Message Protocol), and IGMP (Internetwork Group Management Protocol).
Virtual Interconnect Network
The network interconnect needs to pass through some intermediary devices: The forwarder physical layer (), bridge or bridge (data link layer), Router (network layer), and gateway (above the network layer). When the intermediary device is a repeater or a bridge, it simply expands a network, which is not generally referred to as network interconnection.
Virtual Private network: logical Internet. This means that the heterogeneity of the various physical networks interconnected is objective, but the use of IP protocols can make these different performance networks appear to be a unified network at the network level.
IP address of the classification
An IP address is an identifier that assigns a unique 32 to each port on each host (or router) on the Internet. The method of compiling IP addresses has undergone three stages:
- IP address of the classification
- Sub-Network Division
- form an ultra-net
The IP address is divided into several fixed classes, each of which has two fixed-length fields, where the first field is the network number and the second field is the host number.
Class A address: network Address (1Byte) + host address (3Byte), and the first network address must be 0, the network address of the value range is 0~127, the network number is 0 address is reserved address, and 127 is a reserved address, and is used for testing loopback. So the range of Class A addresses is actually from 1-126. There are 126 available Class A networks, each of which can hold more than 100 million hosts (2 of the 24-minus 2 hosts). Subnet mask: 255.0.0.0. Class A IP range: the first is 0;1.0.0.1~~126.255.255.254; host number 24 bit
Class B Address: network Address (2Byte) + host address (2Byte), and the network address of the first two bits is 10, the network address of the value range is 128~~191, the available Class B network has 2 14-square minus 1, each network can accommodate more than 60,000 hosts ( 2 of the 16 parties minus 0 and broadcast addresses). Subnet mask: 255.255.0.0. Class B IP range: The first two bits are 10; 128.1.0.1~~191.255.255.254; host number 16 bit
Class C Address: network Address (3Byte) + host address (1Byte), and the network address of the first three bits is 110, the network address of the value range is 192.0.1~~223, the available C-class network has 2 of 21 square minus 1, up to 2.09 million, Each network can hold 254 hosts. Subnet mask: 255.255.255.0.
Class C IP range: The first three bits are 110;192.0.0.1~~223.255.255.254; Host number 8 bit
Class D Address: This type of address is called a multicast address, also known as the multicast address, the first four bits must be 1110; The range of network addresses is the 224~~239,d class IP range: The first four bits are 1110;224.0.0.1~~239.255.255.254
Class E Address: This type of address is reserved for future use, the first five digits must be 11110; The range of network addresses is 240~~254,e class IP range: The first five bits are 11110;240.0.0.1~~254.255.255.254
Features of IP address:
- Each IP address has a network number + host number is composed of two parts. In this sense, an IP address is a hierarchical address structure. The benefits of grading: A, IP address management agency when assigning IP address, only assign network number, and the remaining host number is assigned by the unit that obtains the network number. This facilitates management; B, routers only forward packets based on the network number that the destination host is connected to (no host number is considered), so that the number of items in the routing table can be reduced significantly, reducing the memory used by the routing table, and checking the time it takes to find the route.
- An IP address is actually used to flag a host (or router) and an interface for a link. When a host is connected to two networks at the same time (for example, a proxy server in the lab). The host must have two corresponding IP addresses. This is where hosts become multi-homed hosts
- A switch is a device on the data link layer, and the host that is connected to it still belongs to the same network. The hosts of different LANs must be connected by routers because of different network numbers.
- All network numbers are equivalent.
IP address and hardware address
The physical address is the address used by the data link layer and the physical layer, and the IP address is the address used by the network layer and the above layers, which is a logical address (the IP address is implemented by software).
When data is sent, the data is transferred from the top to the bottom, and then to the communication link. IP datagrams that use IP addresses are encapsulated as Mac frames once they are delivered to the data link layer. The source and destination addresses used by Mac frames at the time of transmission are hardware addresses, both of which are written in the header of the Mac frame. The device (host or router) connected to the communication link is based on the hardware address in the Mac frame header when it receives the MAC frame. In the data link layer, the IP address hidden in the data of the Mac frame is not visible. The network layer can only find the source IP address and destination IP address in the header of the IP datagram when the MAC layer data is handed over to the network layer after stripping the header and tail of the Mac frame. In short, the IP address is placed at the header of the IP datagram, and the hardware address is placed at the header of the Mac frame. The IP address is used above the network layer and the network layer, and the data link layer and the following use the hardware address. In the know, when the IP datagram is placed in the Mac frame of the data link layer, the entire IP datagram becomes the data of the Mac frame, thus the IP address of the datagram is not visible at the data link layer. Example: A is a picture of three LAN with two routers R1 and R2 interconnect together. Now the host H1 to communicate with the host H2. The IP addresses of the two hosts are IP1 and IP2, respectively, and their hardware addresses are HA1 and HA2 (HA represents hardware address). The communication path is:h1-> through R1 forwarding, and then through R2 forwarding->h2. Router R1 is connected to two LAN at the same time, so it consists of two hardware addresses, namely HA3 and HA4. Similarly, router R2 also has two hardware addresses HA5 and HA6. Note here: 1: IP datagrams can only be seen on the IP layer abstract Internet. Although the IP datagram is forwarded two times by router R1 and R2, the source and destination addresses in its header are always IP1 and IP2 respectively. The data in the graph, written from IP1 to IP2, indicates that the former is the source address and then the destination address. The IP address of the two routers that pass through the datagram does not appear in the header of the IP datagram. 2: Although the IP datagram header has the source IP address, but the router only according to the destination station's IP address network number for routing. 3: At the link layer of the LAN, only Mac frames are visible. The IP datagram is encapsulated in a Mac frame. When Mac frames are transmitted over different networks, the source and destination addresses of their Mac frame headers change. 4: Although the interconnection of the network's hardware address system is different, but the IP layer abstraction of the internet has shielded the lower layers of these very complex details. As long as we discuss the problem at the network level, we can use a unified, abstract IP address to study the host and the host or router directly through theLetter. Address Resolution Protocol
The network layer uses an IP address, but when the data frame is transferred over the link of the actual network, the hardware address of the network must eventually be used. However, there is no simple mapping between the IP address and the hardware address of the following network (the IP address has 32 bits and the LAN hardware address is 48 bits) because of the different format. In addition, new hosts may often be added to a network, or some hosts will be withdrawn. Replacing the network adapter also causes the host's hardware address to change. Address Resolution Protocol ARP solves this problem by storing a mapping table from an IP address to a hardware address in the host ARP cache, and this mapping table is also frequently updated dynamically (new or time-out deletions).
Each host has an ARP cache, which has the IP address of each host and router on the local area network to the hardware address of the mapping table, these are the host now know some of the address. So how does the host know these addresses? when host a sends an IP datagram to a host B on the local area network, it first looks at the IP address of Host B in its ARP cache. If so, the corresponding hardware address is detected in the ARP cache, then the hardware address is written to the Mac frame, and the Mac frame is sent to this hardware address through the LAN. It is also possible to find the Host B's IP address of the project, which may be host B before the network, it may be host a just boot, its cache or empty. In this case, host A will automatically run ARP, and then follow the steps below to find the hardware address of Host B. The 1:ARP process broadcasts a packet of ARP requests on the local area network. The main content of the ARP request grouping is that my IP address is 209.0.0.5 and the hardware address is 00-00-c0-15-ad-18. I want to know the hardware address of the host with IP address 209.0.0.6. 2: The ARP process that is running on all hosts on this local area network receives this ARP request grouping. 3: Host B sees its own IP address in the ARP Request packet, sends an ARP response packet to host A and writes its own hardware address. All the other hosts ignore this ARP request grouping. The main content of the ARP response grouping: My IP address is 209.0.0.6, my hardware address is 08-00-2b-00-ee-0a. Note that although the ARP request grouping is broadcast-sent, the ARP response grouping is normal unicast, which is sent from a source address to a destination address. 4: When host a receives a packet of ARP responses from Host B, it writes the IP address of Host B to the mapping of the hardware address in its ARP cache. The visible ARP cache is useful. If the ARP cache is not applicable, then any host will have to broadcast the ARP Request packet on the network as long as the communication is made, which makes the traffic on the network greatly increased. ARP stores the obtained address mappings in the cache, so that the next time the host communicates with a host with the same destination address, it can find the required hardware address directly from the cache without having to broadcast the ARP Request packet. ARP is a mapping problem that resolves the IP address and hardware address of a host or router on the same LAN. 4 Scenarios for using ARP are summarized:1: The sender is the host, to send the IP datagram to another host on the network. The hardware address of the destination host is found with ARP. 2: The sender is the host, to send the IP datagram to a host on another network. The hardware address of a router on this network is found with ARP. The rest of the work is given to this router to complete. 3: The sender is the router, to forward the IP datagram to a host on the network. At this point the hardware address of the destination host is found with ARP. 4: The sender is the router that wants to forward the IP datagram to a host on another network. The hardware address of a router on this network is found with ARP. The rest of the work is given to this router to complete. IP datagram Format
in the TCP/IP standard, various data formats are often described in 32-bit units. An IP datagram consists of a header and a data component. The first part of the header is a fixed yield, a total of 20 bytes, which all IP datagrams must have. The fixed part of the header is followed by some optional fields whose length is variable.
- Version: 4 bits, which is the version of the IP protocol. The version of the IP protocol used by both sides of the communication must be consistent. The current widely used IP protocol version number is 4 (that is, IPv4). You should use IPV6 later.
- Header length: 4 bits, the maximum decimal value that can be represented is 15. Note that the unit of the number represented in this field is a 32-bit word (a 32-bit word is 4 bytes), so the header maximum length is 60 bytes. When the header length of an IP packet is not an integer multiple of 4 bytes, it must be populated with the Fill field after the group.
- Differentiated Services: 8-bit for better service.
- Total Length: The total length refers to the length of the header and the sum of the data, in bytes. The total Length field is 16 bits, so the maximum length of the datagram is 2^16-1=65535 bytes. Although the use of the longest possible datagram will improve the efficiency of transmission, but due to the widespread use of Ethernet, so the actual datagram length is rarely more than 1500 bytes. When the datagram length exceeds the maximum transmission unit MTU allowed by the network, it is necessary to fragment too long packets to be sent over the network.
- Identification: 16 bits. The IP software maintains a counter in memory, each generating a datagram, the counter is + 1, and assigns this value to the identity field. However, this identifier is not an ordinal, because IP is a no-connect service, and the datagram does not have an ordered receive problem. When a packet must be fragmented because it is longer than the MTU of the network, the value of the identity field is copied to the identity field of all the datagrams. The value of the same identity field causes the number of fragments after the fragment to be correctly re-installed to the original datagram.
- flag: 3-bit, at present only 2 bits make sense. the lowest bit in the Flag field is recorded as MF (more fragment). Mf=1 is a datagram that identifies a fragment behind it. Mf=0 identification This is already the last of several datagrams. The middle of the flag field is recorded as DF (don ' t fragment), meaning it cannot be fragmented. Shards are allowed only when df=0.
- Chip offset: 13 bits. The slice offset indicates the relative position of a piece in the original group after a long grouping in the Shard. That is, where the slice starts relative to the starting point of the user data field. The slice offset is offset in 8 bytes. This means that the length of each shard must be an integer multiple of 8 bytes.
Example:The total length of a datagram is 3820 bytes, and its data portion is 3800 bytes (using a fixed header), requiring fragmentation to be a datagram with a length of not more than 1420 bytes. Because the fixed header length is 20 bytes, the data portion of each datagram cannot exceed 1400 bytes in length. It is divided into 3 data sheets, with data part lengths of 1400,1400 and 1000 bytes respectively. The original datagram header is copied to the header of each datagram, but the value of the field must be modified.
-
- protocol: 8 Bits, the Protocol field indicates what protocol is used for data carried by the datagram, So that the IP layer of the destination host knows which process should be handed over to the data part.
- first Test and accounted for 16 bits. This field only examines the header of the datagram, excluding the data section. This is because the router has to recalculate the first check and (some fields, such as time to live, flag, slice offset, and so on) each router. Do not test the data section to reduce the amount of computational effort.
-
- Destination Address: 32-bit
the variable part of the IP datagram header is an option field. To support the troubleshooting, measurement of the level of security and other measures, the content is very rich. This segment is variable in length, ranging from 1 bytes to 40 bytes, depending on the item selected. The variable portion of the header is added to increase the functionality of the IP datagram, but it also makes the header length of the IP datagram variable. This increases the overhead of each router handling datagrams. In fact, these options are rarely reserved. The new IPV6 version makes the header length of the IP datagram fixed. The process of IP layer packet forwarding
- The IP address d of the destination host is extracted from the header of the datagram, and the network address n of the destination host is computed. (The IP address of the destination host in the IP datagram and the subnet mask on the routing table are &, you can derive the network address n)
- If n is the network address of a network directly connected to this router. It is delivered directly to the destination host without having to go through another router, but directly to the IP datagram. (note that when delivered directly, the router needs to convert the destination host address D to a specific hardware address, encapsulating the datagram in a Mac frame, sending this frame.) if n is not a network directly connected to this router, it is delivered indirectly. Execution 3.
- If the routing table has a specific host route with Destination D, the datagram is routed to the next-hop router indicated in the routing table; otherwise, 4 is executed.
- If there is a route in the routing table that reaches network n, the datagram is routed to the next-hop router indicated in the routing table; otherwise, 5 is executed.
- If both 3 and 4 are not able to forward the IP datagram, if there is a default route in the routing table, the datagram is routed to the default indicated in the routing table, otherwise 6 is executed.
- Error reporting forward grouping.
Network layer----1