The basic theory of network model

Source: Internet
Author: User

Basic concepts

LAN: Coverage is small, cable length is generally within 100 meters. Fixed bandwidth. Link yourself to buy equipment maintenance.

Wide Area network: Distance is far away. Pay to rent bandwidth. The chain routes other people to manage.

ISP: telecom operator.

Router: Similar to a network card, requires an IP to connect to other network segments of the device.

Gateway: A machine connection within a LAN in order to connect the IP of a device specified by another network segment.

MAC Address: Physical address.

OSI Reference Model

Layering is a common idea in the field of software. The well-known OSI layered model, the upper layer relies on the lower layer, the lower level services. The application layer serves the user.

Name Description
Application Layer The program that can generate network traffic.
Presentation Layer Pre-transfer encryption processing, or compression processing.
Session Layer Can be understood as a TCP connection.
Transport Layer Provides reliable transmission or unreliable transmission, providing flow control.
Network layer Responsible for selecting the best path and planning the IP address.
Data Link Layer Define the start and end of the frame, transparent transmission, error checking, but not correcting.
Physical Layer The physical layer provides a path for data-terminal devices to transmit data. The interface standard, electrical standard and line rate of network equipment are defined.

TCP/IP protocol and OSI Reference Model

The TCP/IP protocol refers to a set of protocols in fact.

Data Encapsulation (encapsulation)

When data is sent, the ISO seven layer model or the TCP/IP four layer model, the data from the upper layer down, the data is packaged layer by row.

    • Four layers, the protocol layer transmits the data message, is mainly the protocol format.
    • Layer three, the network layer is the transmission of packets, including data packets, and increase the transmission of the IP address and other three layers of information.
    • The second layer, the Data link layer transmits the data frame, contains the packet, and adds the corresponding MAC address and two layers of information.

When data is received, the lower layer is encapsulated in the upper layer. The package and unpacking process is very similar to the real-life mailing. Mail items need to be packaged and written on the sender and addressee.

PDU (Protocol Data Unit)

The Protocol Data unit PDU (Protocol Data Unit) refers to the unit of data passed between peer levels.

    • The PDU at the application level is a message (message)
    • The PDU of the transport layer is the data segment (Segment)
    • The PDU on the network layer is a packet (Packet)
    • The PDU at the data link layer is a data frame (frame)
    • The PDU at the physical layer is the data bit (bit)

Message (message)

A block of data to be sent by the site. The message contains the complete data information to be sent, the length of which is inconsistent, unlimited and variable.

Data segment (Segment)

In the transport layer, the message data is segmented, and each piece of data is added to the TCP header (containing the source port, destination port, sequence number, etc.) to form the data segment.

Reasons for Fragmentation:

(A) data can be sent from multiple applications simultaneously.

(B) When the packet is too large to produce an error, it also needs to be re-transmitted, that is, the take-up and time, small packets on the data flow is much less impact.

(C) A variety of network transmission media has its largest transmission unit limit, does not allow the presence of large packets on the network.

Datagram (Datagram)

For non-connected data transfer, the working process is similar to message exchange. When transmitting in a datagram mode, the packet being transmitted is called a datagram.

The basic unit of data transmitted over a network consists of a header (header) and the data itself, where the header describes the destination of the data and the relationship to other data. Can be understood as a grouping of transferred data. The basic unit of data that we transmit over the network is called a datagram.

Data packet (Packet)

In the network layer, the data segment is added to the IP header (containing the source IP address, the destination IP address) to form the packet.

Data frame (frame)

In the data link layer, the data Mac header (including the source MAC address and destination MAC address) is added to the packet header of the packet, and a frame check bit (debug: Frame check Sequence, FCS) is added to the packet end of the packet to form a data frame.

Switch processing of data frames

After the switch receives the data stream, it looks for the destination host based on the MAC address of the data frame sent over. If found, send data to the destination host. The forwarding process does not change the data frame structure.

The destination host receives the operation of the data frame

When the destination host receives a data frame to compare the purpose of the Mac, if sent to its own, then remove the data frame head, sent to the network layer, the network layer compared to the destination IP, such as the same packet is sent to the transport layer, the transport layer is then compared to the destination port, the same is removed data segment to the application process data assembly

TCP Segmentation and IP sharding

TCP segments and IP shards work in different tiers.

Difference:

    • The reason for IP fragmentation is that the MTU;TCP segment of the network layer is due to MSS.
    • IP shards are completed by the network layer, and are reorganized at the network layer, and TCP segmentation is done at the transport layer and reassembled at the transport layer.
    • For Ethernet, MSS is 1460 bytes, and Mut is often larger than MSS.

Therefore, the use of TCP protocol for data transmission, is not caused by IP shards. If the data is too large, the data will only be segmented at the transport layer, and the IP layer will not be fragmented. IP shards are usually caused by the UDP transport protocol because the UDP transport protocol does not limit the size of the transmitted datagram.

PDU Message Header Format

UDP header

 /*   UDP header definition, total 8 bytes  */ typedef  struct   _udp_header{unsigned  short  m_ussourport; //         source port number 16bit  unsigned short  m_usdestport; //            unsigned short  m_uslength; //       unsigned short  m_uschecksum; //  checksum 16bit } __ATTRIBUTE__ ((Packed)) Udp_header, *pudp_header; 

TCP Header

/*TCP header definition, a total of 20 bytes*/typedefstruct_tcp_header{ ShortM_ssourport;//Source port number 16bit     ShortM_sdestport;//Destination port number 16bitUnsignedintM_uisequnum;//Serial number 32bitUnsignedintM_uiacknowledgenum;//Confirmation Number 32bit     ShortM_sheaderlenandflag;//Top 4 bits: TCP header length, medium 6 bit: reserved, last 6 bits: Flag bit     ShortM_swindowsize;//Window Size 16bit     ShortM_schecksum;//Inspection and 16bit     ShortM_surgentpointer;//Emergency data offset 16bit}__ATTRIBUTE__ ((Packed)) Tcp_header, *Ptcp_header;/*the option definition in the TCP header. Kind (8bit) +length (8bit, length of the entire option, contains the first two parts) + content (if any) kind = 1 means no operation NOP, no back Part 2 means that the length after maximum segment is Max The length of the imum segment option (in bytes, 1+1+ content part length) 3 means that length after Windows scale is the size of the Windows Scale option (in bytes, 1+1+ content part length degrees) 4 means SACK permitted length is 2, no content Part 5 indicates that this is a SACK packet length of 2, no content Part 8 represents a timestamp, lengt H is 10, with a timestamp of 8 bytes*/typedefstruct_tcp_options{CharM_ckind; Charm_clength; Charm_ccontext[ +];} __ATTRIBUTE__ ((Packed)) Tcp_options,*ptcp_options;

IP header

/*IP Header definition, a total of 20 bytes*/typedefstruct_ip_header{CharM_cversionandheaderlen;//version information (first 4 bits), head length (last 4 bits)    CharM_ctypeofservice;//Service type 8-bit     ShortM_stotallenofpacket;//Packet length     ShortM_spacketid;//Packet identification     ShortM_ssliceinfo;//Shard Usage    CharM_cttl;//Survival Time    CharM_ctypeofprotocol;//protocol Type     ShortM_schecksum;//ChecksumUnsignedintM_uisourip;//Source IPUnsignedintM_uidestip;//Destination IP} __attribute__ ((packed)) Ip_header, *pip_header;

Mac Header

/*data frame definition, first 14 bytes, tail 4 bytes*/typedefstruct_mac_frame_header{Charm_cdstmacaddress[6];//Destination MAC address    Charm_csrcmacaddress[6];//Source MAC address     ShortM_ctype;//The previous layer protocol type, such as 0x0800 represents the previous layer is the IP protocol, 0x0806 is ARP}__ATTRIBUTE__ ((packed)) mac_frame_header,*Pmac_frame_header;typedefstruct_mac_frame_tail{unsignedintM_schecksum;//Data frame tail check and}__ATTRIBUTE__ ((Packed)) Mac_frame_tail, *pmac_frame_tail;

TCP three-time handshake and four-time handshake establish TCP connection--three handshake

The so-called three-time handshake (three-way handshake) means that when a TCP connection is established, the client and server are required to send a total of 3 packets.

Establish a TCP connection and synchronize the serial number and confirmation number of both parties and Exchange TCP window size information. In socket programming, the client executes connect (). Will trigger a three-time handshake.

First handshake: The client sends a TCP SYN flag where 1 of the packet indicates the port of the server to which the client intends to connect, and the initial sequence number x, which is stored in the header sequence number (Sequence) field.

Second handshake: The server sends back a confirmation packet (ACK) reply. That is, the SYN flag bit and the ACK flag bit are both 1, and the confirmation ordinal (acknowledgement number) is set to the customer's I S n plus 1 to. that is x+1.

Third handshake: The client sends a confirmation packet again (ACK) to the SYN flag bit for the 0,ACK flag bit of 1. and send the server an ACK to the ordinal field +1, placed in the OK field sent to the other party. Also in the data segment write +1 of the isn.

Releasing a TCP connection--four waves

The removal of TCP connections requires sending four packets, so called four waves (Four-way handshake). Either the client or the server can initiate a wave gesture, and in socket programming, any party performs a close () operation to generate a wave.

Basic theory of the network model

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.