Study Notes on network layer and transport layer of computer network (Xie xiiren)

Source: Internet
Author: User
Note: This note is written from the programming perspective, that is, the content is something I think is helpful for programming, rather than from the perspective of a network professional knowledge.
The Comparison of Different Computer Architectures: OSI Layer-7 protocol architecture, TCP/IP architecture, and five-layer protocol architecture:

It indicates the changes in the data transmitted by the application process at each layer.

It indicates the method distance of the TCP/IP protocol. Note that when forwarding packets, the router only uses the network layer, while the wood has the transport layer and the application layer.

It shows that the two server processes on host C provide services to the Customer Service processes of A and B respectively.

The rules, standards, or conventions established for data exchange in the network are called network protocols. network protocols are mainly composed of the following three elements: ①. The syntax is the structure or format of data and control information.
2. Semantics refers to the control information to be sent, the action to be done, and the response to be made.
③ Synchronization is a detailed description of the event Implementation sequence. PS: synchronization here is in a broad sense, that is, what should happen under certain conditions, So synchronization contains the meaning of time series. currently, the most common method is to use network adapters to implement hardware and software for communication protocols. generally, the adapter includes the data link layer and the physical layer. only data flows at the data link layer are considered.

In the Internet, the network layer protocol data unit is an IP datagram or packet. each link layer specifies the maximum length of the Data part of the frame, that is, the maximum transmission unit MTU group exchange. The main features are as follows: group exchange uses the storage and forwarding technology. Generally, we call the entire block of data to be sent as a packet. before sending a data packet, divide the data packet into smaller and longer data segments. after some necessary control information is added before each data segment to form a group, it is also called "package ". A group is a data unit transmitted over the Internet. it shows the concept of dividing a packet into several groups.

IP datagram format

The services provided by Ethernet are unreliable delivery, that is, the best effort to deliver. the upper layer determines whether a frame with errors is retransmitted. there are also four protocols used in concert with the IP protocol: Address Resolution Protocol ARP (Address Resolution Protocol) and Reverse Address Resolution Protocol RARP (Reverse Address Resolution Protocol) internet Control Message Protocol (ICMP) and Internet Group Management Protocol (IGMP)
The intermediate device used by the physical layer is called a forwarder; the intermediate device used by the data link layer is called a bridge or bridge; the intermediate device used by the network layer is called a router; the intermediate device used above the network layer is called a gateway. PS: to connect two incompatible systems with a gateway, you need to switch the protocol at the high level. sometimes we call the vro used at the network layer as a gateway. to extend Ethernet over the data link layer, you must use a bridge. the bridge works on the data link layer. It forwards and filters received Frames Based on the target address of the MAC frame. shows the Source and Destination addresses of different levels and ranges.

Several local networks connected by a forwarder or bridge are still one network because these networks have the same host number. a lan with different network numbers must use routers for interconnection. the router selects routes only based on the network number of the IP address of the destination site. A vro always has two or more IP addresses, that is, each interface of the vro has an IP address with different network numbers. after receiving the IP datagram, the router finds the destination subnet according to the destination network number and subnet number, and delivers the IP datagram to the destination host. the network layer corresponds to the IP address; the transport layer corresponds to TCP. the network number field and host number field in the IP address are displayed.

IP address addressing has gone through three historical stages: IP address classification, subnet division, and definition of two levels of IP addresses.

The definition of the third-level IP address.

The specified IP address range.

The physical address is the address used by the data link layer and the physical layer, while the IP address is the address used by the network layer and its above layers. It is a logical address. the IP address is a logical address because it is implemented by software.
Differences between IP addresses and hardware addresses

Only IP datagram can be seen on the abstract Internet at the IP layer. only Mac frames can be seen at the LAN link layer. mac frames are transmitted on different networks. as shown in the figure, the MAC frame format segment offset of Ethernet V2 indicates that a part is located in the original group after it is divided into multiple parts. that is to say, the starting point of the table relative to the user data field. the Slice offset is measured in eight bytes.
Although all group forwarding on the internet is based on the network of the target host, in most cases, this exception is allowed, that is, specifying a route for a specific target host. this route is called a specific host route.
Address Resolution Protocol ARP stores a ing list of IP addresses to hardware addresses in the host ARP cache, And the ing list is updated frequently. each host has an ARP high-speed cache, which contains a ing table between the IP addresses of each host and the router of the local area network and the hardware addresses. when switching information between a vro and an adjacent vro, The subnet mask of your network must be added to the adjacent vro. the following figure shows the working principle of Address Resolution Protocol arp. The default subnet mask of Class A addresses is 255.0.0.0. The default subnet mask of Class B addresses is 255.255.0.0. The default subnet mask of class C addresses is 255.255.255.0. the default subnet mask of Class A, Class B, and class C IP addresses.

End-to-End communication is the communication between application processes. the network layer provides logical communication for hosts, while the transport layer provides end-to-end logical communication between application processes. the transport layer provides logical communication for the application processes that communicate with each other.

Shows the main differences between transport layer protocol and Network Layer Protocol

According to OSI, the data units transmitted by two peer transport entities during communication are called transport protocol data units tpdu. however, in TCP/IP, the protocol used is TCP or UDP, which is called the TCP packet segment or UDP User Datagram respectively. shows the UDP user datagram header and pseudo header.

The port number is spliced to the IP address to form a socket. the endpoint of the TCP connection is the socket. TCP uses the connection as the most basic abstraction. each TCP connection is uniquely identified by the two ends of the communication, namely the socket.

Some common port numbers are shown.

The Header Format of the TCP packet segment.

As shown in, use three-way handshakes to establish a TCP connection.

Shows the TCP connection release process.

According to the Internet, a network refers to a set of hosts with the same network number. therefore, several local networks connected by a forwarder or bridge are still one network, that is, only one network number is allowed. we know that the IP address is used at the network layer, but the hardware address of the network must be used for transmitting data frames on the link of the actual network.
The following describes four typical scenarios of ARP:
① The sender is a host, and the IP datagram should be sent to another host on the network. This is the hardware address of the host found using ARP.
② The sender is a host, and the IP datagram should be sent to a host on another network. at this time, ARP finds the hardware address of a vro on the current network. the router is responsible for the remaining work.
③ The sender is a vro and forwards the IP datagram to a host on the local network. This is the hardware address of a host on the local network.
4. the sender is a vro and the IP address needs to be datagram to a host on another network. then, use ARP to find the hardware address of a vro on the network. the router is responsible for the remaining work.
When the router receives a data packet to be forwarded and obtains the IP address of the next hop router from the route table, it does not fill in the IP data packet but sends it to the lower-layer network interface software. the network interface software is responsible for converting the IP address of the next hop router into a hardware address, placing the hardware address at the first MAC frame of the link layer, and then finding the next hop router based on the hardware address.
Dividing subnets only divides the host number of the IP address, without changing the original network number of the IP address. the same IP address and different subnet masks can be used to obtain the same network location. however, different masks have different effects.
Classless addressing (CIDR): using a variable-length subnet mask vlsm can further improve the utilization of IP Address resources. based on vlsm, the classless addressing method is further studied. Its formal name is classless Inter-Domain Routing (CIDR. major features of CIDR: CIDR eliminates the traditional concepts of Class A, Class B, and class C addresses, as well as subnet division, so it can effectively allocate IPv4 address space, in addition, the Internet scale can continue to grow before the new IPv6 is used. although CIDR does not use subnets, some networks still use subnet division and subnet mask. Therefore, the address mask used by CIDR can also be referred to as subnet mask.
There are five types of ICMP Error Report packets: 1. inaccessibility to the end point 2. Source point suppression 3. Time-out 4. Parameter Problem 5. Change the routing. The format of the ICMP message shown in

Shows several common ICMP packet types

The data field content of the ICMP error message.

From the perspective of the transport layer, the real endpoint of the communication is not the host but the process in the host. that is to say, end-to-end communication is the communication network layer between application processes. The host provides logical communication, while the transport layer provides end-to-end logical communication for application processes.
UDP supports one-to-one, one-to-many, one-to-one, and many-to-many communication. main features of UDP: connectionless, near-maximum delivery effort, packet-oriented. the packet sent by the sender's UDP to the application is sent to the IP layer after the header is added. UDP does not merge or split the packets, but retains the boundary of the packets.
At the network layer, the test field in the IP datagram only checks whether the header is on a business trip or not, and does not check the data section. The transport layer also checks the received packets for errors.
Main features of TCP: connection-oriented transport layer protocol, point-to-point, reliable delivery service, full-duplex communication, transport layer protocol for byte streams, as shown in the TCP/IP System

The "stream" in TCP refers to the byte sequence that flows into or out of the process. the meaning of "byte stream oriented" is: although the application and TCP delivery are a data block of different sizes at a time, however, TCP only regards the data handed over by the application as a series of unstructured byte streams. TCP does not know the meaning of the byte stream. the TCP byte stream-oriented concept shown in "stop waiting" means to stop sending after a group is not sent, and wait for the recipient to confirm sending. send the message to the next group after receiving the confirmation. note the following three points:

1. After sending a group, a must temporarily retain the copy of the sent group. Only after receiving the confirmation can a temporary copy of the Group be cleared.
2. Group and validation groups must be numbered.
3. The retransmission time set by the timeout timer should be longer than the average round-trip time for data transmission in the group.
Through the validation and retransmission mechanism, we can achieve reliable communication on the unreliable transmission network, as shown in the following two possible scenarios:

Confirm the loss and be late.

In the IP address range, some non-route addresses are reserved by IANA, which is the IANA reserved address. These addresses are mainly used for special purposes. The reserved addresses are mainly in the following three categories:
Class A: 10.0.0.0-10.255.255.255 (equivalent to one class a ip address) Class B: 172.16.0.0-172.31.255.255 (equivalent to 16 consecutive Class B IP addresses) Class C: 192.168.0.0-192.168.255.255 (equivalent to 256 consecutive Class c ip addresses)
These addresses are not allocated by the Internet, so they are never routed over the Internet. although they cannot be directly connected to the internet, they can still be used to communicate with the Internet. People can select an appropriate address class as needed, use these addresses as public IP addresses in an internal LAN. on the Internet, devices that do not need to communicate with the Internet, such as printers and manageable hubs, can also use these addresses to save IP Address resources. private address: 10. x. x. the addresses X, 172.16.x.x-172.31.x.x, and 192.168.x.x are widely used in internal enterprise networks. some broadband routers often use 192.168.1.1 as the default address. the private network may use random IP addresses because it is not interconnected with external networks. this address is reserved for use to avoid address confusion when accessing the public network in the future. when a private network using a private address accesses the internet, you must use address translation (NAT) to translate the private address into a public legal address. such addresses cannot appear on the Internet. all routers on the Internet do not forward data packets whose destination address is a private address.
The common 192.168.1.2-192.168.1.99 is a manual IP segment, from 192.168.1.100 ~ 192.168.1.254 is the IP address segment of the dynamic DHCP address. When the DHCP server in the network is faulty or the IP address is allocated, or the DHCP client cannot contact the DHCP server, DHCP Client automatically uses an address configured from 169.254.0.1-169.254.255.254 to the NIC. Such addresses are called Microsoft automatic private addresses because address resources are exhausted, it is impossible to force the IP address type to be assigned by DHCP. the IP address is generally not used.

The difference between a vswitch and a vro: a traditional vswitch developed from a bridge and belongs to the OSI Layer 2, that is, the data link layer device. it is addressing according to the MAC address. A router is a layer-3 network-layer device of OSI. It is addressing based on IP addresses and is generated through the route table routing protocol.

It is a group of TCP protocol and UDP protocol that I use the packet capture tool to capture respectively. This article is updated at the end of this article and at on January 1, January 1, 2013 (will be updated later) I solemnly declare the following: I, write a good blog good time, hope you a lot of support, thank you. This article address http://t.cn/zjQjulJ II. This statement shall not be removed when all individuals or websites repost this article. 3. You are not allowed to modify the article unless explicitly stated. You are also welcome to comment, repost, and share the article. 4. the blogger is a programmer and also a micro-controller. You are welcome to pay attention to my Sina Weibo account. Http://t.cn/zjYnpEa

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.