Computer network reading Notes-----Web layer

Source: Internet
Author: User

    • Two services provided by the network layer

The network layer is located above the data link layer, under the application layer, provides two services: datagram and virtual circuit, the former is a non-connected network service, the latter is a connection-oriented network service. This is somewhat similar to TCP and UDP.

Datagram Service: The network at any time can accept the host sent packet (datagram), the network for each packet independent selection of routes, to do their best to deliver the packet to the destination host, so the datagram service is not reliable, can not guarantee the quality of service.

Virtual Circuit Services: A to communicate with B, first A to B to send a specific message, the request for communication, B received after the return response, the virtual circuit is established, and then the data can be transferred, so the quality of service has a better guarantee.

Project Virtual Circuit Services Data Reporting Services
Ideas Reliable communication should be ensured by the network Reliable communication should be guaranteed by the user host
Establishment of a connection Must have No
Destination Station Address Used only during the connection establishment phase, each grouping uses a short virtual circuit number Each group has a destination station's full address
Forwarding of packets Packets belonging to the same virtual circuit are forwarded according to the same route Each packet independently selects the route for forwarding
When the node is out of order All virtual circuits that pass through failed nodes do not work Failed nodes may lose grouping, some routes may change
Order of grouping Always arrive at destination station in send order Does not necessarily follow the order of delivery when arriving at destination station
End-to-end error handling and flow control Can be owned by a packet switching network or by a user host Is the responsibility of the user host
    • The advent of IP networks

If a network of large and small networks across the world is interconnected and communicated through routers, there are many problems to be solved: different addressing schemes, different maximum packet lengths, different timeout controls, different routing techniques, and so on.
Because the needs of users are diverse, there is no single network with all the needs of users.

Connecting the network requires some intermediary devices:
1, the physical layer of intermediate equipment called forwarders
2. Intermediate devices used in the data link layer called bridges or bridges
3, the network layer uses the intermediary device called the router
4, the network layer above the use of intermediary devices called gateways, usually with a gateway to connect two networks using different protocols.

In general, the network interconnection refers to the use of routers for network interconnection and routing. The router can be viewed as a dedicated computer, but it is responsible for routing in the Internet.

TCP/IP system in Network interconnection is the practice of using a standardized protocol in the network layer, the network through the interconnection of routers using the same IP network protocol, so you can connect the formation of the network as a virtual interconnection network, so-called virtual interconnection is logical interconnection.
In this way, the various physical networks that we interconnect are heterogeneous, but they look like a unified network on the network layer, and the virtual interconnection network using IP protocols is also known as the IP network.
The benefits of IP networking: hiding the underlying specific heterogeneous details of various interconnected networks, when the host on the IP network communicates, as if it were communicating on a single network.

    • IP protocol

IP protocol is the most core protocol in TCP/IP system. TCP, UDP, ICMP, and IGMP all transmit data in the form of an IP datagram.
The IP protocol provides non-connected unreliable services.
Unreliable: There is no guarantee that IP datagrams will arrive at the destination successfully. Just do your best to transfer.
No connection: Indicates that each IP datagram processing is independent of each other, that is, the IP datagram can not be received in order.

There are also 4 protocols that are used in support of:
ARP: Address Resolution Protocol
RARP: Anti-Address Resolution Protocol
ICMP: Internet Control Message Protocol
IGMP: Internet Group Management Protocol

The latter two need to use the IP protocol, so above, while the IP protocol needs to use the first two frequently, thus below.

    • IP Address

The internet as a single, abstract network, IP address is to each access to the Internet host assigned to a world-wide unique identifier of 32bit. Such IP addresses make it convenient to address on the Internet.

IP address addressing has undergone three stages:
1. Classified IP Address
2, Sub-network division
3, constitute the super net

    • Category IP Address

The IP address is divided into several fixed classes, each of which consists of a network number and a host number. A host number is unique within the network range specified by the preceding network number, so this IP address can be recorded as
IP Address:{< Network number >,< host number;}
  

The first 1~4 bit of the network number field in the figure represents the category bit, which distinguishes these types of addresses.
The A, B, and C addresses belong to the unicast address (one to the other), the D is multicast (pair-to-multi communication), and E is reserved for later use.

As mentioned earlier, the IP address is 32bit binary code, in order to improve readability, will be expressed in equivalent decimal:

The most commonly used IP addresses are a, B, and C addresses.
IP address space Total 2^32 address, Class A address space has 2^31 address, accounting for total address space of 50%
Class B address space has a total of 2^30 address, the total address of the 25%,c class address about 2^29 address, accounting for the entire IP 12.5%
So the range of IP:

Generally not used IP address:

features of IP:
1, the IP address is a hierarchical address structure, the advantage: IP address Management agencies only need to assign network number (first level), the host number (the second level) by the use of the network number of units assigned by their own, convenient management; Routers only forward packets based on the network number that the destination host is connected to, regardless of the host number. This simplifies the routing table and the time it takes to find the routing table.
2, a host connected to two networks, you must have two corresponding IP address, so because a router should be connected to at least two networks, at least one router should have at least two different IP addresses
3, LAN has the same network number
4. All networks assigned to network numbers are equal.

    • IP address and hardware address

物理地址是指数据链路层和物理层使用的地址而IP地址是网络层及以上各层使用的地址,是一种逻辑地址

IP address in the IP datagram header, and the hardware address in the Mac frame header, IP datagram into the data link layer of Mac frame, the entire IP datagram becomes MAC frame data, so at the data link layer is not invisible datagram IP address, The network layer can only find the source IP address and destination IP address in the header of the IP datagram if the Mac frame is handed over to the network layer at the first and the end of the stripped Mac frame.

Instance:

Now H1 to communicate with H2,h1-> R1 forwarding, R2 forwarding->h2
Represents the source address and IP address of different levels, different intervals

We can see that although the IP datagram is forwarded two times by the router, the source address and destination address at its header are always the IP address of H1 and the IP address of H2, and the address of the two routers will not appear in the header of the IP datagram. Routers only route their routes based on the network number of the IP address of the destination station

When a Mac frame is transferred between different networks, its source address and destination address are changed, and we can see his changes from the table. But this change in Mac frames is invisible on the IP layer.

We can see that although the hardware addresses vary between different networks, the IP address cleverly masks these complex details.

    • Address Resolution Protocol and anti-Address Resolution Protocol

      地址解析协议(ARP):将IP地址转换为物理地址反地址解析协议(RARP):将物理地址转换为IP地址

RARP:
Anti-Address Resolution Protocol has played an important role, but now DHCP already contains rarp function, so no one to use the RARP protocol alone, just know that the hardware address of their host can be RARP protocol to obtain its IP address.

ARP:
Although the network layer uses an IP address, we must use the hardware address of the network when we transfer the data frame on the actual link.
However, there is no simple mapping between the IP address and the hardware address, and ARP solves this problem by storing a mapping table from the IP address to the hardware address in the host's ARP cache, and the mapping table is dynamically updated.

Each host has an ARP cache, which has the IP address of each host and router of the local area network to the Hardware Address mapping table, then how does the host know these addresses?

Example:
When host A to a host of local area network to send IP packets, the ARP cache is now looking for a host IP address, if any, in the ARP cache to identify its corresponding hardware address, and then write this hardware address to Mac frame, and then the Mac frame through the LAN to send this hardware address.
If Host B just enters the network or host a just power up (the cache is empty), it will not find the IP address of Host B.
At this point, host A will automatically run ARP, follow the steps below to find the hardware address of Host B:

1、ARP进程在本局域网上广播发送一个ARP请求分组,请求分组的内容是:自己(主机A)的IP地址和硬件地址以及主机B的IP地址。2、在本局域网上的所有主机运行的ARP进程都会收到这个请求分组。3、主机B在ARP请求分组中见到自己的IP地址,就向主机A发送ARP响应分组,并写入自己的硬件地址。其余的主机都不会理会这个ARP的请求分组。(ARP请求分组是广播发送,但是响应分组是普通的单播,从某一个源地址发送到一个目的地址)4、主机A收到主机B的ARP响应分组,就在其ARP高速缓存中写入主机B的IP地址到硬件地址的映射。

In the future, Host B may communicate to host A, so it has to be reversed once, in order to reduce traffic on the network, host a sends a request packet that includes its own IP address to the hardware address of the map written to the ARP Request packet. When Host B receives a packet of ARP requests from host A, the address mapping of host A is written to Host B's own ARP cache, which can then be found directly in the cache.
diagram:

In front of the ARP represents the dynamic update, when a and B communication, just start good, the network adapter behind B changed, B immediately replaced a piece, so B's hardware address changed, but A and B communication, because the IP address is still there, but the previous hardware address has been invalidated, So a cannot find the hardware address of B.
Each item in the ARP is set by the time to live, and items that exceed their lifetime are removed from the cache. So the above scenario, a cannot find Host B, but after the time of survival, A's ARP cache has deleted the original hardware address of B, so a at this time re-broadcast send ARP request group, find B.

If the two hosts that communicate are no longer in the same LAN, then the IP address and hardware address of the router need to be recorded.

This IP address to the hardware address is automatic, the host users of this address resolution process is not known, as long as the host or router and the network on a known IP address of the host or router to communicate, ARP will automatically convert this IP to a hardware address.

why not communicate directly with the hardware address, instead of invoking ARP to find the appropriate hardware?
This is a bit like the beginning of the emergence of IP network, there are various networks around the world, there are a variety of hardware addresses, to communicate with a very complex conversion, almost impossible. So abstract a unified IP address, the host connected to the Internet as long as the use of a unified IP address, their communication is like connecting on the same network so simple and convenient. And ARP is automatic, it is not visible to the user, so it is very convenient.
This IP address is a bit like abstract class, there are a variety of subclasses, but these subclasses and another area of the subclass to communicate, then need to write a lot of code, so abstract out the base class, two base classes to communicate with each other, convenient and simple.

    • IP datagram

version:
4 bits refers to the version of the IP protocol. The IP protocol versions used by both sides of the communication are consistent
The first ministerial degree --4 digits, the maximum number that can be represented
is 15 units (one unit is 4 bytes)
The maximum value of the first ministerial degree of the IP is therefore 60 bytes.
Total Length:
Refers to the length of the sum of the header and data, in bytes. The total Length field is 16, so the maximum datagram length is 2^6-1 (65535) and the total length must not exceed the maximum transfer unit MTU
Survival Time:
8-bit, indicating the lifespan of the datagram in the network, the index is reported to be up to the number of routers in the Internet, the maximum value is obviously 255
Protocol
Indicates what protocol is used for the data that this datagram carries, so that the IP layer of the destination host knows which process to give the data part to

Protocol ICMP IGMP TCP EGP IGP UDP IPV6 OSPF
Protocol Field Name 1 2 6 8 9 17 41 89

Header Checksum
Ideas:

首先将IP首部即40位16进制的字符串转化为二进制字符串,然后以每16位为一个字段,分为10个二进制字段。存放在IP1~IP10字符串中; 然后求出每个字段的反码,根据IP数据报格式,可以知道IP6存放的就是校验和,将校验和IP6置位全0; 利用求反码和,求出10个字段反码相加后的值sum,然后对字符串sum取反,得到发送时所用的校验码。 假设接收端的IP首部与发送的是相同的,那么其10个字段的利用反码和算法求出的值应为0

Graphic:

(Image address: http://wenku.baidu.com/link?url=em2I8OC8FEg-zHslpMcF5r_m2eYFbzXyYkZ0ChdXdWH9CnRs6htX_6IhVosmecTxOWrF_ VCQVII1JM2MYIOGI9KOMC1B8BWSCCU3VB-UB4W)

    • The process of forwarding packets in IP layer

As mentioned earlier, if you make the routing table by the destination host number, the final routing table will be too large
So in order to simplify the routing table, we use the host's network address to make the routing table, as shown in:

So in the routing table, the main information for each route is the following:
(Destination network address, next hop address)

So we use the destination network to determine the next-hop router, which explains:

IP datagrams will eventually be able to find routers on the destination network where the destination host is located
IP datagram attempts to direct delivery to the host only when it reaches the last router

At the same time, routers can use default routing to simplify routing tables and reduce the time it takes to search the routing table. As shown: When the destination network is not N1 and N2, the default route is selected, the datagram is delivered to the router R1, the R1 is forwarded to the next router and forwarded to the router on the destination network.

only the source IP address and destination IP address in the IP datagram, how does the datagram find the next hop router?
Is through ARP, first in the routing table to get the next hop of the router's IP address, and then the address through the ARP converted to a hardware address, and then sent to the next hop router, and then repeatedly

Packet forwarding algorithm:

(1)从数据报的首部提取目的主机的 IP 地址 D,得出目的网络地址为 N。(2)若网络 N 与此路由器直接相连,则把数据报直接交付目的主机 D;否则是间接交付,执行(3)。(3) 若路由表中有目的地址为 D 的特定主机路由,则把数据报传送给路由表中所指明的下一跳路由器;否则,执行(4)。(特殊情况)(4)  若路由表中有到达网络 N 的路由,则把数据报传送给路由表指明的下一跳路由器;否则,执行(5)。(5) 若路由表中有一个默认路由,则把数据报传送给路由表中所指明的默认路由器;否则,执行(6)。(6)  

Excerpt from: Computer network-fifth edition. Shehiren
Reference: TCP/IP detailed. Volume One

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Computer network reading Notes-----Web layer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.