The communication of learning experience (TCP/IP protocol stack)

Source: Internet
Author: User

The protocol addressing mechanism mentioned above is simple, the transmission speed is slow, it is not suitable for the data transmission of large range and large flow, therefore, it is applied to the interior of the equipment (such as IC, between circuit board and Circuit board). The TCP/IP protocol stack physical layer uses the fiber/coaxial cable for the transmission medium, fast transmission rate, (up to 100Mbit), routing, gateway, debugging error detection function is very powerful, very good to achieve multi-user communication, so much is used for equipment outside the large data flow communication between devices. such as between pc/mobile and access to the server, is achieved through TCP/IP.

The TCP/IP protocol does not fully cover the Iso/os international I standard seven-layer network protocol, which only applies to four layers: network interface layer (physical layer/Data link layer), Network layer, Transport layer, application layer.

1. Network interface layer.

is actually the physical layer and the data link layer of the seven-layer protocol. The physical layer realizes some physical and electrical characteristics of PHY, such as interface type rmii/mii, level characteristic, and data link layer, mainly has MAC (Media Intervention control Layer) protocol, ARP (address Resolution) protocol, RARP (reverse Address Resolution) protocol.

Mac Header composition: (Mac frame is the data frame format that is actually transmitted in physical media)

1. Preamble: For data Synchronization (the contiguous 01 sequence occupies a total of seven bytes of space, that is, 55-55-55-55-55-55-55)

2. The bounding symbol sfd,0xd5 the beginning of a frame; (SOF)

3.DA destination MAC address, consisting of a total of 6 bytes, separated by colons between bytes, expressed in hexadecimal;

4.SA Source MAC address, ditto;

5. Type (ip/arp/rarp)/length, a total of two bytes, when greater than 0x0600 when the expression type, less than 0x0600 length (valid frame data field length is 46~1500 bytes);

6. Data domain (the IP layer packet is inserted in this domain, and the TCP layer packet is inserted in the IP packet's data field)

7.FSC End (frame check sequence is from the destination MAC address-"data field")

0xd5 starts receiving data when the MAC layer detects the start character. First received is the purpose of the MAC address, the Mac can set the filtering mechanism, the local MAC address to the corresponding registers, in the communication through the receiver of the target MAC address compared to the inconsistent and not broadcast or multicast data filter out, In addition to meet the purpose of the MAC address, then to judge the length/type, the length of too long or too short data also filtered out, the next check value, that is, the MAC layer itself calculated checksum value compared with FSC, not filtered out, Only a complete set of data in accordance with the conditions will be DMA into the FIFO, when the beginning of transmission data, DMA will judge the state of the MAC data register, so that control the MAC receive data register value into the FIFO, FIFO settings have thresholds, When the threshold is reached or the data contained is a full frame, DMA will also control the FIFO data into the corresponding data registers, or in memory, transmission direction, source and destination address and transmit full frame byte number, all in the DMA initialization, when the delivery, will trigger the corresponding interruption, The MAC receives less data than the FIFO capacity, so the Mac inserts a bit of frame spacing in the data frame.

The composition of the ARP header: (ARP function: The transmission of ARP data frames for broadcast to obtain the physical address of the target IP, or the own MAC address to respond to the requesting party; Get the IP address in the packet from the IP layer corresponding to the MAC address to facilitate the MAC layer to form a complete data frame)

1. Destination MAC Address (if broadcast mode is FF-FF-FF-FF-FF-FF)

2. Source MAC Address

3. Frame type (if the ARP frame is 0x0806)

The first three parts are the MAC header, which is joined by the MAC layer when ARP passes through the MAC layer.

The following is the header of ARP: Because ARP belongs to the network interface layer and is higher than the Mac, it is inserted into the Mac's data domain.

4. Hardware type (Hardware address type if 1 means Ethernet)

5. Protocol type (if the upper level protocol is IP layer 0x8000)

7. Hardware address Length (6Byte)

8. Protocol address Length (4Byte)

9. Operation field OP (four types of operation: ARP request 1; ARP reply 2;rarp request 3;rarp answer 4, request and answer only this bit to differentiate

6. Send-side Ethernet Address

7. IP address of sending end

8. Destination Ethernet Address (when the request, there is no fill, there is no padding, when the response to this frame, the target host will be sent to the address to send the address, the Action field to 2)

9. Destination IP Address

The following is the Network layer protocol: (different from the MAC layer only physical layer data transfer, if you need to address the target machine to traverse all clients, network layer implementation will classify the network, through the IP address network number to distinguish between different networks, when the need to access the target machine, the first to determine what kind of network, And then by the way to assign a path to address, greatly improve the efficiency of communications, because it can not guarantee that the data issued will be safe to arrive, so this layer protocol is unreliable protocol, but because of the ICMP and other as auxiliary, so with a certain error-checking function.

IP Header composition: (IP layer is the upper level protocol of MAC, TCP lower protocol)

1. Version (IP protocol version, now mainly have IPV4 and IPV6 two kinds)

2. Header length: The length of the entire IP header, expressed in 4Byte, such as 0001 for 4 bytes, 1111 for the largest 60 bytes, when not more than 4 of the multiple, filled with the Fill field.

3. Service types, according to the requirements of IP data transfer are divided into: the first three-bit priority, the latter four-bit to represent the type D (lower delay) T (greater throughput) R (higher reliability) C (lower routing) The last one was unused.

4. Total length: The header of this packet data plus the total length of the data (1Byte, the maximum can represent 65,535 bytes of data)

The next three fields are some of the settings for IP fragmentation, when the packet required to form a data frame is greater than the MTU (that is, 1500Byte), IP fragmentation is performed, and the fragment is based on the position in the original packet, the token segment is biased, according to the different packets, the label packet identifier, The receiver is then reorganized according to the packet ID and the fragment offset.

5. Identification (in order to identify different packets, the different data segments of the same package packet occupy an identity)

6. The logo (MF (more fragment) =0 indicates that the data segment is the last paragraph in the packet data, and df=0 (Donn ' t fragment) allows the packet to be segmented;)

7. Segment offset, which represents the segment offset in the full packet, facilitates the reorganization of the segmented data by Segment offset value. The unit is in 8Byte.

8. Life (TTL) that this piece of data exists time, each through a route, TTL minus one, until the 1 o'clock, the data is discarded, thus preventing data from passing through the channel for a long time, causing obstruction.

9. Protocol, that is, the protocol type at the top of the IP layer (TCP/UDP/ICMP, etc.)

10. The first inspection and (each through a node to recalculate the entire header test and, excluding the data section, this part can choose to be calculated by the hardware itself, can also be calculated by the software to join, initialization when the definition)

11. Destination IP Address

12. Source IP address (for the IP layer and its upper level protocol, MAC address is not visible, mainly through IP address to communicate, IP address by the network number and host number composed of 32 bits, Between four bytes. Connection, expressed in decimal, according to its network number and host number of the number of allocations can be divided into three categories: Class A 0+7bit the network number, followed by the 24bit host number; Class B: 10+14bit represents the network number, after 16bit to indicate the host number; Class C: 110+ 21bit indicates the network number, and the following 8bit indicates the host number; Subnet mask: That is, with n one to represent n-bit network number, such as the IP address of Class B subnet mask is 255.255.0.0, the same network network number must be consistent, with the network Bridge and LAN switch can achieve the same network segment of the host connected, Routing enables you to associate different segments of the network, there is a routing table in the route that corresponds the internal LAN gateway to the extranet IP address, and lists all the internal IP addresses and external IP addresses associated with it, using the NAT protocol, and the IP of any different domain must be routed through the connection first. The route also corresponds to the IP address, which is called a gateway, when an IP to access the extranet, first of all to the gateway as the target IP communication, and then the gateway address into the external network address (through the NAT protocol, the role is to reduce the cost of the IP segment), the replacement of its source IP address packet. )

13. Optional fields

ICMP header: (as the IP protocol is located in the network layer, mainly through it to obtain some of the state of network communications, because the IP layer does not guarantee that the data must not be lost, but there will be some quality assurance functions, ICMP Implementation report data communication errors or anomalies), just as the ARP protocol, The data field to be inserted into the Mac when sent, ICMP as a network layer and ip-based so to be inserted into the IP data domain to send. )

1.ICMP Type:

0//echo Response

3///Destination Station unreachable

4//Source station suppression

5//Change Routing

8//echo Request

11//Datagram time is over

12//Datagram has a problem with the parameter

13//Timestamp request (current time parameter date)

14//Time stamp Answer

17//Address Mask Request

18//Address mask Answer

2. Code type (further distinguishing between different cases of the above type)

3. Inspection and (ICMP header and, excluding data fields)

4. Indefinite fields (related to ICMP type, total divided into two categories: Error category/Inquiry Class)

Next is the transport layer, visible TCP/IP is not just TCP and ip-based protocol but a protocol group, but because the two-tier protocol is the focus, the protocol is relatively large, just so called, now talk about the TCP protocol:

TCP is a link-oriented protocol, that is, to establish a link before data transmission, transmission completion and the removal of links. This link-building process is achieved through a well-known "three-time handshake". In addition, TCP is another feature of the byte stream transmission, segmented transmission, that is, in the need to transmit a serial number of bytes, When the packet to be transferred is greater than the MSS, the transmitted data needs to be segmented by the allowed size (MSS) and marked with the segment number (that is, the sequence number of the first byte of the beginning of a data segment). Because the MSS is less than the IP layer's MTU, the data segment does not need IP fragmentation when it is uploaded to the IP layer. Instead, only the identification number is updated (that is, the first few data segments sent since the link was established), and the segment offset is zero.

Now the first TCP is introduced as follows:

1. Source port; (application's port number)

2. Destination port;

3. Serial number (first byte number of data segment)

4. Confirmation Number (Reply data section number)

5.TCP Offset

6. Reservations

7. Logo (Syn,ack,psh,rst,urg,fin)

8. Window (Specify instructions for sending the next paragraph size)

9. Checksum (including header and data)

10. Emergency

11. Option number

UDP is a non-linked protocol, that is, the transfer of data does not need to establish a connection, reduce a large number of system overhead, so the transmission speed, but because the reliability is not high, can not guarantee that data can be reached, can not be grouped, when the packet length is greater than the MSS, passed to the IP layer, IP layer for IP It does not guarantee that all IP fragments can reach the destination, and if one of the fragments is lost, it cannot be corrected, and TCP will retransmit the whole packet if one of the packets is lost.

The UDP protocol header is described below:

1. Source port;

2. Destination port;

3. Datagram Length (total length of header and data part)

4. Calibration and verification;

The above section has already covered most of the TCP/IP protocol stack, to enable users to use, but also must have some application layer protocol, such as HTTP/FTP/SNMP and so on a more extensive use of the agreement,

HTTP protocol (Hypertext Transfer Protocol): Enables users to view files on the server through a browser,

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.