Software implementation of PPP protocol link operations

Source: Internet
Author: User

1. Introduction to the PPP protocol
PPP (Point-to-Point Protocol) is a link layer Protocol designed for the transmission of data packets between equal units. This link provides full duplex operations and transmits data packets in sequence. The purpose of the design is to establish a point-to-point connection to send data through a dial-up or leased line, making it a common solution for simple connections between hosts, bridges, and routers.

The PPP protocol consists of three parts:
1) one method of encapsulating IP datagram into a serial link.
PPP encapsulation provides different network layer protocols and enables them to maintain compatibility with commonly used Supported Hardware through the multi-channel technology of unified links.
2) LCPLink ControlProtocol used to establish, configure, and test data link connections ). Both parties can negotiate some options through the LCP package.
3) A set of Network control protocols (Network ControlProtocol ). NCP is a family of Protocols responsible for solving the network protocols running on physical connections and the problems arising from upper-layer network protocols. It supports different network layer protocols, such as IP, OSI network layer, DECCnet, and AppleTalk.
The PPP frame Encapsulation Format is as follows:

A ppp frame starts and ends with a flag character of 01111110. The address field is 1 B in length, the content is standard broadcast address 11111111, and the control field is 00000011. The protocol field length is 2 B, and its value indicates the network layer protocol to which the subsequent data field belongs. The data field contains the Protocol datagram specified in the Protocol field. The length is 0 ~ 1 500 B. The CRC field is the cyclic redundancy check code of the entire frame. It is used to detect possible data errors during transmission.
According to the three parts of the PPP protocol, the encapsulation of PPP data frames is also divided into IP datagram encapsulation, LCP Control Data encapsulation, and NCP Control Data encapsulation. When the Protocol field of the PPP frame is 0x0021, the information field is the IP datagram; when the protocol field is 0xC021, the information field is the LCP control data; when the protocol field is 0x8021, the information field is the NCP control data.

2. Link creation and state machine
2.1 Overview of PPP link establishment
A complete PPP session consists of four phases: the link establishment phase, the authentication phase, the Network Layer Control Protocol phase, and the link termination phase. This article discusses and implements the link establishment phase.
The link creation process is as follows: one end of the request to establish a connection uses the LCP configuration information package Configure packets) to establish a connection. After the peer receives the configuration information package, if the configuration request and negotiation options are accepted, the Configure-Ack packet is sent ), when a configuration is successfully sent and received, the link is established. After the LCP is established, if the LCP Configure-Request link receives the LCP configuration Request packet, it will be returned from the network layer protocol phase or authentication phase to the link establishment phase.
Generally, the two ends of the line need to negotiate the following content, which is included in the LCP configuration request package:
(1) Maximum-Receive-Unit Maximum-receiving-Unit)
(2) Authentication-Protocol (Authentication-Protocol)
(3) Quality-Protocol (Quality-Protocol)
(4) Magic-Number
(5) Protocol-Field-Compression (Protocol-Domain-Compression)
(6) Address-and-Control-Field-Compression Address-and-Control domain-Compression)

2.2 Finite State Machine Model
The connection and negotiation process at the LCP layer of the PPP protocol is complicated. Generally, the state machine model is used to explain the detailed changes of the PPP status.
A state machine is a device that records the state at a given time point and changes the state or initiates an action for each given change based on input. Finite State Automation is defined by event, action, and state transition. The state machine can be used to explain in detail the state transition process established by the LCP link in the PPP protocol. The state machine for LCP operations can be divided into the following elements:
The current state and the next state) and state transition are the basic concepts of the state machine. He specifies what the state machine is doing at the current time and what the situation is. In the LCP link connection state machine, there are 10 statuses: Initial, Starting, Closed, Stopped, Closing, Stopping, Rdq-Sent, Ack-terminated ed, Ack-Sent, and Opened.
The state transition in event automation is caused by events. During link connection negotiation, the local end sends the LCP package from the peer end of the line and its own status to determine the event to occur, the next status of the system is determined based on the current status. There are many types of events during the establishment of LCP links, which can be divided into the following categories:
① Network status events indicate the status changes of LCP or NCP, including Up, Down, Open, and Close.
② Timeout timer event, which is related TO the timeout timer, including TO + and -.
③ S/T packet events, including RCR +, RCR-, RCA, RCN, and RTR. RTA, RUC, RXJ +, RXJ-, RXR. Actions in the Action automation are caused by events. Therefore
All events correspond to corresponding actions. For example, some actions indicate the transmission of different types of LCP packets or the start and stop of Restart timer.
The status jump table is in the PPP link operation. After a specific event, each status changes to a new State and there may be corresponding events. These relationships are complex and can be expressed in the status jump table [1.

3 software implementation
3.1 software principles
The establishment, negotiation, and handshake of a PPP link must be completed by both parties. Each party makes corresponding judgment and response based on the type of the LCP package sent by the peer end. The principle of the software is to use software to simulate one end of the PPP link and fully implement the Protocol Stack function. More importantly, the implementation methods discussed in this article can achieve the purpose of detection and diagnosis, which is not possible for general software.
In the implementation process, the software receives the LCP package of the Peer end, and then jumps to the table based on the LCP status to determine its next state, and generates corresponding events and actions, send the response package to the peer through the software to achieve the link connection of the software.
The software displays the status of The Link activity, the received and sent packets, and the current status of the link one by one. You can learn more about the network activity and status through the software.

3.2 Implementation Method
The software development tool is Borland C ++ Builder visual development environment, and the running environment is Windows 98 in simplified Chinese. The software has an information display interface for user testing and analysis. The following describes the software implementation methods in detail.

3.2.1 overall process
The implementation part of the software uses two subthreads, which are responsible for receiving and processing data respectively and operating the data buffer zone. The overall process 1 is shown.

3.2.2 thread structure
The software is implemented by multithreading technology. Apart from the main thread, there are two subthreads used for Link Operations: one as the data packet receiving thread and the other as the data packet processing thread.
When the program starts, the main thread initializes, sets its status to Initial, and starts the data receiving thread. At this time, the two sides of the PPP connection start to connect and negotiate, so they will receive the LCP package from the peer device, receive the LCP package from the receiving thread, and hand it over to the processing thread for processing. The processing thread unpacks the received data, solves the content of the LCP package, obtains the generated event based on the current situation, and jumps to the table based on the current status and status, determines the next state to be simulated. If necessary, send the corresponding response to the peer.

The processing thread is the focus of the entire program, as shown in process 2 of this thread.

You can perform the following steps:
1) obtain the peer data packet from the receiving thread.
2) analyze the content in the data packet and locate the status jump table based on the data packet type and current local status to determine the next status of the local data packet.
3) The local end executes the corresponding event through status-event correspondence.
4) display the generated events and system information on the interface.
5) determine whether to send the LCP package to the Peer based on the Status jump table. If needed, data is encapsulated and sent according to the LCP package standard.

3.2.3 Data Structure
In terms of data structure, the program uses a buffer zone with a total of 10 elements. Each element has a size of about 500 B, which is used to store the data sent each time for analysis. The two threads read and write the buffer respectively. There is a header pointer and a tail pointer to avoid access conflicts. The receiving thread reads data from the underlying layer, makes a simple judgment, stores the data in the buffer element pointed to by the header pointer, and sets its unused flag, add 1 to the header pointer; the processing thread reads data from the buffer element pointed by the tail pointer, then processes the data, sets the used flag, and Adds 1 to the tail pointer. The specific data structure is as follows:

3.2.4 display of Link Status
The process of link status and status transition can be completed through the LCP package processing sub-thread. Each time the sub-thread processes an LCP packet sent from the peer end, the status changes and link conditions are displayed on the interface, and events such as timeout exceptions and timer restart can also be displayed. Users can monitor the connection status in real time, which plays an important role in analyzing the line.

3.3 Application Prospects of software implementation
Software Implementation for ppp lcp operations is of great practical significance. You can determine the line conditions and locate the fault location by displaying the software interface. Some manufacturers have made products based on the principles and implementation methods described in this article, and are now promoting the application.

Related Articles]

  • PPP user authentication and IP Address Allocation
  • Application of PPPoE protocol in Broadband Access Network
  • Wan protocol interpretation unveil the secrets of PPP

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.