Packet capture methods, devices, electronic equipment, and storage media based on nodes in VPP.
By extending the packet capture switch field and command-line control in the VPP node data structure, flexible packet capture of specified nodes is achieved, solving the problem that packet capture schemes cannot be flexibly specified in existing technologies, and improving processing performance and fault location efficiency.
Patent Information
- Application Number
- CN202411802829.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-12-02
- Estimated Expiration
- 2044-12-09
AI Technical Summary
Existing packet capture solutions cannot flexibly specify packet capture nodes in VPP, which increases the number of memory copies and affects program processing performance.
By extending the packet capture switch field in the node data structure and combining command line and node packet capture functions, flexible packet capture of specified nodes can be achieved, avoiding packet capture operations on all nodes.
It enables flexible packet capture of specified nodes, reduces the number of memory copies, improves program processing performance, and enhances fault location efficiency.
Smart Images

Figure CN119814377B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of network technology and security, and in particular to a packet capture method, apparatus, electronic device and storage medium based on nodes in VPP. Background Technology
[0002] When developing data plane programs for gateway devices based on VPP (Vector Packet Processing), sometimes the target packets are not forwarded along the expected path, resulting in service disruptions. Therefore, it is necessary to troubleshoot and locate the cause of the problem. Packet capture can be used to analyze and locate the reason for the forwarding failure.
[0003] However, existing packet capture solutions can only capture packets from the two ends of the forwarding path, and cannot flexibly specify other nodes for packet capture; or although they can specify the name of the input node, starting packet capture across the entire process results in multiple copies of a single target packet (data), leading to a significant increase in memory copying and impacting the overall processing performance of the program. Therefore, how to achieve flexible packet capture of specific nodes is a technical problem that urgently needs to be solved. Summary of the Invention
[0004] In view of the above problems, embodiments of this application provide a packet capture method, apparatus, electronic device and storage medium based on nodes in VPP, so as to overcome the above problems or at least partially solve the above problems.
[0005] A first aspect of this application discloses a packet capture method based on nodes in a Virtual Portal Provider Interface (VPP), the method comprising:
[0006] The packet capture parameters are set based on the command line, and the node packet capture function is called according to the packet capture parameters. The packet capture parameters include at least the name of the packet capture node, the maximum number of packets to capture, and the target cache. The packet capture node is a node in the VPP forwarding node path.
[0007] The packet capture switch status of the packet capture node is determined by the target code block in the packet capture function. The packet capture switch is characterized by a field in the node data structure.
[0008] When the packet capture switch is in the on state, the packet data of the packet capture node is placed into the target buffer for node packet capture. The packet data is the packet data transmitted to the packet capture node.
[0009] Optionally, the method further includes:
[0010] Based on the command line, the packet capture switch of the packet capture node is set to the on state through the global data structure field, so as to start packet capture on the packet capture node.
[0011] Optionally, when the packet capture switch is in the on state, the packet data of the packet capture node is placed into the target cache for node packet capture, including:
[0012] Monitor the transmitted packet data of the packet capture node;
[0013] If packet data is detected being transmitted to the packet capture node, the packet data is placed into the target cache as the packet data of the packet capture node.
[0014] Optionally, the method further includes:
[0015] Count the number of packet data in the target cache and determine whether the number of packet data is equal to the maximum number of packets captured;
[0016] When the number of packet data is equal to the maximum number of packet captures, stop capturing packets at the packet capture node and obtain the packet capture data.
[0017] Optionally, stop capturing packets at the packet capture node and obtain packet capture data, including:
[0018] Based on the command line, the packet capture switch of the packet capture node is set to the off state through the global data structure field, so as to disable packet capture of the packet capture node;
[0019] The packet data in the target cache is written to a specified file to obtain packet capture data.
[0020] Optionally, the method further includes:
[0021] Export the captured packet data to a target format file, and open the target format file using analysis software to view the field content of each packet in the captured packet data;
[0022] Based on the field content of each packet in the captured data, the field where the error occurred after passing through the fault node is determined in order to locate the fault problem.
[0023] Optionally, the method further includes:
[0024] The packet capture progress status of the packet capture node can be viewed using the command line. The packet capture progress status represents the number of packet data captured by the packet capture node.
[0025] A second aspect of this application discloses a packet capture device based on nodes in a VPP, the device comprising:
[0026] The configuration module is used to set packet capture parameters based on the command line and call the node packet capture function according to the packet capture parameters. The packet capture parameters include at least the name of the packet capture node, the maximum number of packets to capture, and the target cache. The packet capture node is a node in the VPP forwarding node path.
[0027] The judgment module is used to determine the packet capture switch status of the packet capture node through the target code block in the packet capture function of the node. The packet capture switch is characterized by a field in the node data structure.
[0028] The module is used to put the packet data of the packet capture node into the target cache for node packet capture when the packet capture switch is on. The packet data is the packet data transmitted to the packet capture node.
[0029] A third aspect of this application discloses an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of the packet capture method based on nodes in VPP described in the first aspect of this application.
[0030] A fourth aspect of this application discloses a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the packet capture method based on nodes in VPP described in the first aspect of this application.
[0031] A fifth aspect of this application discloses a computer program product, including a computer program that, when executed by a processor, implements the steps of the packet capture method based on nodes in VPP described in the first aspect of this application.
[0032] The embodiments of this application have the following advantages:
[0033] In this embodiment, packet capture parameters are set via command line, and a node packet capture function is called according to these parameters. The packet capture parameters include at least the name of the packet capture node, the maximum number of packets to capture, and the target buffer. The packet capture node is a node in the VPP forwarding node path. The packet capture switch status of the packet capture node is determined by the target code block in the node packet capture function. The packet capture switch is represented by a field in the node data structure. When the packet capture switch status is on, the packet data of the packet capture node is placed in the target buffer for node packet capture. The packet data is the packet data transmitted to the packet capture node. Thus, the node can be flexibly specified for packet capture via command line, and the field in the node data structure can be used as the packet capture switch to flexibly control the packet capture switch of a single packet capture node. Furthermore, determining the packet capture switch status based on the target code block in the node packet capture function avoids capturing packet data (messages) from all service nodes (forwarding node paths), which would affect the overall processing performance of the program, thereby achieving flexible packet capture of a specified node.
[0034] The above description is only an overview of the technical solution of this application. In order to better understand the technical means of this application and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this application more obvious and understandable, the following are specific embodiments of this application. Attached Figure Description
[0035] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0036] Figure 1 This is a flowchart illustrating the steps of a packet capture method based on nodes in a VPP, as provided in an embodiment of this application.
[0037] Figure 2 This is a flowchart of another packet capture method based on nodes in VPP provided in this application embodiment;
[0038] Figure 3 This is a schematic diagram of a forwarding node path provided in an embodiment of this application;
[0039] Figure 4 This is a schematic diagram of a packet capture device based on nodes in VPP provided in an embodiment of this application;
[0040] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0041] To make the above-mentioned objectives, features, and advantages of this application more apparent and understandable, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0042] To better understand the technical solution of this application, the technical concepts involved in this application will be explained.
[0043] VPP: Vector Packet Processing.
[0044] Node: A forwarding node in VPP, a program structure that processes data packets.
[0045] Wireshark: A network packet analyzer that can capture various network packets and display the most detailed network packet information possible.
[0046] pcap: is a commonly used data storage format, which can be understood as a file format. This format is mainly used to store data packets in network communication for subsequent analysis and processing.
[0047] In related technologies, VPP supports two methods for packet capture. One method uses the `pcap trace` command to capture rx (receive), tx (send), and drop (drop) packets during the forwarding process, and supports packet capture based on filtering conditions configured in the `classify` configuration. The other method uses the `pcap dispatch trace` command to capture data packets and their forwarding node path information. Using the latest version of Wireshark, the `vlib_buff_t` structure data and trace node graph data can be displayed.
[0048] Specifically, the `pcap trace rx` command, when capturing received packets, checks the packet capture switch and status data in the "ethernet-input" node before deciding whether to buffer the current packet for later dumping. The `pcap trace tx` command, when capturing sent packets, checks the packet capture switch and status data in the "interface-output" node before deciding whether to buffer the current packet for later dumping. The `pcap dispatch trace` command, within the `dispatch_node` function running in the main loop, switches the function pointer of the node processing function to a custom-encapsulated function pointer, capturing packets at each node upon arrival and recording the node name, original packet data, and private field data.
[0049] When developing data plane programs for gateway devices based on VPP, sometimes target packets are not forwarded along the expected path, resulting in service disruptions. This necessitates troubleshooting and locating the cause of the problem. Packet capture can be used to analyze and pinpoint the reason for forwarding failure. Generally, the `trace` command series can be used to analyze and locate the cause of forwarding failure. In some cases, the `pcap` command is required. After exporting the captured packets, the `pcap` file can be opened with Wireshark to analyze more fields of the target packet data.
[0050] However, the pcap trace command is limited to capturing packets only at the two ends of the forwarding path (nodes that have just received packets and are about to send / drop them), and cannot flexibly specify other nodes for packet capture. While the pcap dispatch trace command has a node name parameter, it is limited to specifying the name of the input node; the name of its command parameter is... <input-node-name>Therefore, the pcap dispatch trace command actually starts packet capture as a whole. A single packet will be captured and stored multiple times. For example, if a packet passes through 17 nodes on its forwarding path, the packet capture may store up to 17 copies of the packet, which will lead to a significant increase in the number of memory copies and affect the overall processing performance of the program.
[0051] To overcome the limitations of related technologies, this application provides a packet capture method based on nodes in VPP. This node-based packet capture method is applied in VPP and is implemented as follows: An additional field is added to the node data structure to characterize the packet capture switch of the node; a global data structure field is used to maintain the packet capture status data of the node (e.g., global switch, pcap_main_t); the packet capture processing logic is implemented by calling the node packet capture function. A target code block is added to the node packet capture function to determine the packet capture switch status in the node's runtime data. Only when the packet capture switch status is on will packet capture be performed on the node. In this way, flexible packet capture of a specified node is achieved.
[0052] The packet capture method based on nodes in VPP provided in this application will be described in detail below with reference to the accompanying drawings.
[0053] Reference Figure 1 As shown, Figure 1 This is a flowchart illustrating the steps of a packet capture method based on nodes in a VPP, as provided in an embodiment of this application. Figure 1 As shown, a packet capture method based on nodes in a VPP provided in this application embodiment may include steps S110 to S130:
[0054] Step S110: Set packet capture parameters based on the command line, and call the node packet capture function according to the packet capture parameters. The packet capture parameters include at least the name of the packet capture node, the maximum number of packets to capture, and the target cache. The packet capture node is a node in the VPP forwarding node path.
[0055] Step S120: Determine the packet capture switch status of the packet capture node through the target code block in the node packet capture function. The packet capture switch is characterized by a field in the node data structure.
[0056] Step S130: When the packet capture switch is in the on state, the packet data of the packet capture node is put into the target buffer for node packet capture. The packet data is the packet data transmitted to the packet capture node.
[0057] In this embodiment, the command line is used to set packet capture parameters and call node packet capture functions. For packet capture nodes in the VPP forwarding node path that need to be captured, the name of the packet capture node is set in the command line to specify that packet capture should be performed on that node. For example, for the forwarding node path A→B→C→D→F, if packet capture is required on nodes B and C, the names of nodes B and C can be set in the command line to specify that packet capture should be performed on nodes B and C.
[0058] Furthermore, the maximum number of packets to be captured can be set for each packet capture node via command line. This specifies the number of packets to be captured for that node. The maximum number of packets to be captured can be the same or different for different nodes. For example, the maximum number of packets to be captured for node 1 can be set to 100, for node 2 to 150, and for node 3 to 100, etc.
[0059] The target cache can be configured via command line. This target cache stores captured packet data. When capturing packets at a capture node, the acquired packet data is placed in this target cache. In some embodiments, the data state of the node's captured packets is maintained through global data structure fields, including the `pcap_main_t` field. The target cache can be a cache set via the `pcap_main_t` field. Furthermore, the `pcap_main_t` field can also specify the capture interface and the filename used to store the captured packet data.
[0060] A node packet capture function is a function that captures packets from a specified node based on packet capture parameters. After setting the packet capture parameters via the command line, the node packet capture function is called according to the parameters to initiate the packet capture process for the node. Specifically, the node packet capture function includes a packet processing function that places the packet data of the captured node into a target cache for node packet capture. This includes: calling pcap basic functions through the packet processing function to implement the node packet capture processing logic, thereby placing the packet data of the captured node into the target cache to achieve node packet capture.
[0061] In this embodiment, a field is added to the node data structure as a packet capture switch. The state of the packet capture switch determines whether to capture packets from the node. The packet capture switch state includes an on state and an off state. A target code block is set in the node packet capture function. When the node packet capture function is executed, the packet capture switch state of the node is determined based on the target code block. In some embodiments, the node packet capture function includes a `dispatch_node` function running in the main loop, where a target code block is added to determine the packet capture switch state of the node.
[0062] The processing logic for the packet capture node is only activated when the packet capture switch is in the "on" state, which involves placing the packet data (capture data) of the packet capture node into the target cache. The target cache is flexibly configured via command line in step S110.
[0063] By adopting the technical solution of this application embodiment, nodes can be flexibly specified for packet capture via command line. Fields in the node data structure can be used as packet capture switches, allowing flexible control of the packet capture switch of a single packet capture node. Furthermore, the packet capture switch status is determined based on the target code block in the node packet capture function, avoiding packet capture of packet data (messages) in all business nodes (forwarding node paths), which would affect the overall processing performance of the program. Thus, flexible packet capture of specified nodes is achieved.
[0064] In conjunction with the above embodiments, in one implementation, this application also provides a node-based packet capture method. This method, in addition to the steps described above, further includes the following steps:
[0065] Based on the command line, the packet capture switch of the packet capture node is set to the on state through the global data structure field, so as to start packet capture on the packet capture node.
[0066] In this embodiment of the application, a global data structure field is set to maintain the data status of the node packet capture. The global data structure field includes a global switch field, which is used to set the packet capture switch of the packet capture node. For example, when it is necessary to capture packets from a certain node, the packet capture switch of that node is set to the on state through the global switch field.
[0067] Specifically, setting the packet capture switch of the packet capture node to the on state needs to be done before executing step S120. After the packet capture switch setting is completed, in step S120, the packet capture switch state of the packet capture node can be determined by the target code block in the node packet capture function, so as to realize packet capture on the node whose packet capture switch state is on.
[0068] By adopting the technical solution of this application embodiment, the packet capture switch of a single specified packet capture node can be precisely and flexibly controlled through the global data structure field. Thus, the packet capture switch status is determined based on the target code block in the node packet capture function, avoiding packet capture of node data in all business nodes (i.e., forwarding node paths), which would affect the overall processing performance of the program.
[0069] In conjunction with the above embodiments, in one embodiment, this application also provides a node-based packet capture method. In this method, step S130, "when the packet capture switch is in the 'on' state, the packet data of the packet capture node is placed in the target cache for node packet capture," specifically includes the following steps S130-1 to S130-2:
[0070] Step S130-1: Monitor the transmission packet data of the packet capture node.
[0071] Step S130-2: When packet data is detected to be transmitted to the packet capture node, the packet data is placed into the target cache as the packet data of the packet capture node.
[0072] In this embodiment, the packet capture node is a data forwarding node in the forwarding node path. The packet capture node receives packet data transmitted from the previous hop node. Fault location needs to be performed based on the packet data transmitted to the packet capture node. Therefore, the packet data transmitted by the packet capture node is monitored. When packet data is detected to be transmitted to the packet capture node, the packet data is written to the target cache to achieve packet capture.
[0073] In conjunction with the above embodiments, in one implementation, this application also provides a node-based packet capture method. In addition to the steps described above, this method further includes steps A1 to A2:
[0074] Step A1: Count the number of packet data in the target cache and determine whether the number of packet data is equal to the maximum number of packets captured.
[0075] Step A2: When the number of packet data is equal to the maximum number of packets to be captured, stop capturing packets at the packet capture node and obtain the packet capture data.
[0076] In this embodiment of the application, the number of packet data in the target cache is the number of packet data captured by the packet capture node. The relationship between the number of packet data in the target cache and the maximum number of packet captures can be used to determine whether to stop capturing packets for the packet capture node.
[0077] For example, if the maximum number of packets to be captured is set to 100, when the number of packets in the target cache is less than 100, packet capture will continue to be performed on the capture node until the number of packets in the target cache equals 100, at which point packet capture will stop to obtain the captured data.
[0078] Understandably, when capturing packets from multiple nodes in a forwarding path, the number of packets transmitted by each node may differ, and the maximum number of packets captured for each node may also differ. Therefore, whether to stop capturing packets from each node depends on the number of packets captured from that node and the maximum number of packets captured for that node. For example, if the maximum number of packets captured for node 1 is 100 and the maximum number of packets captured for node 2 is 200, and the number of packets captured from both node 1 and node 2 is 100, then capturing packets from node 1 will stop, while capturing packets from node 2 will continue until the number of packets captured from node 2 reaches 200, at which point capturing packets from node 2 will cease.
[0079] In this way, the packet capture process between each packet capture node is independently controlled, allowing for flexible control of each packet capture node's packet capture. Furthermore, packet capture automatically stops when the number of packet data equals the maximum number of packets to capture, eliminating the need for manual control of stopping the packet capture process and simplifying the packet capture operation.
[0080] Furthermore, step A2 above, "stop capturing packets at the packet capture node and obtain packet capture data," specifically includes steps A2-1 to A2-2:
[0081] Step A2-1: Based on the command line, set the packet capture switch of the packet capture node to the off state through the global data structure field to disable packet capture of the packet capture node.
[0082] Step A2-2: Write the packet data in the target cache to the specified file to obtain the packet capture data.
[0083] In this embodiment, when it is necessary to stop packet capture on the captured node, a command is sent via command line to stop and close packet capture on the node. Specifically, the packet capture switch in the node's data structure is turned off by the command. When the target code block in the node's packet capture function detects that the packet capture switch is in a closed state, it will not continue to perform packet capture operations on the node.
[0084] After closing packet capture on the aforementioned capture node, the packet data in the target cache can be written to a specified file to obtain the final packet capture data. The packet capture data can be represented by different file formats; for example, it can be a pcap file (pcap is a commonly used data storage format).
[0085] By adopting the technical solution of this application embodiment, the start and stop of the packet capture process for each packet capture node can be independently controlled, so as to realize flexible packet capture of the specified node, thereby ensuring that the packet capture process will not affect the overall performance of the application.
[0086] In conjunction with the above embodiments, in one implementation, this application also provides a node-based packet capture method. This method, in addition to the steps described above, further includes the following steps:
[0087] The packet capture progress status of the packet capture node can be viewed using the command line. The packet capture progress status represents the number of packet data captured by the packet capture node.
[0088] In this embodiment of the application, the packet capture progress status of the capture node can also be viewed via command line. Specifically, when it is necessary to view the packet capture progress status of a certain capture node, a command to view the packet capture progress status of that capture node can be sent via command line. In this way, the packet capture progress can be monitored during the packet capture process of the node.
[0089] In conjunction with the above embodiments, in one implementation, this application also provides a node-based packet capture method. In addition to the steps described above, this method further includes steps B1 to B2:
[0090] Step B1: Export the target format file of the captured packet data, and open the target format file using analysis software to view the field content of each packet in the captured packet data.
[0091] Step B2: Based on the field content of each packet in the captured data, determine the field where the error occurred after passing through the fault node, in order to locate the fault problem.
[0092] In this embodiment, the captured packet data is exported according to a target format file and viewed using analysis software. The captured packet data can be exported in different file formats, and different file formats require different analysis software. This embodiment does not specifically limit the file format of the captured packet data or the type of specific analysis software.
[0093] For example, if the packet capture data is exported as a pcap file, it can be opened with Wireshark software to view the field content of each node in the packet capture data.
[0094] After examining the field content of each node in the packet capture data, we can analyze which specific fields were erroneous after passing through the faulty node, further narrowing down the scope of the problematic code, and finally locating the fault based on the erroneous fields.
[0095] By adopting the technical solution of this application embodiment, packet capture can be performed on a specific node to obtain packet capture data of the specific node, and then fault location can be performed based on the packet capture data of the specific node, without needing to perform fault location based on the packet capture data of all nodes in the forwarding node path, thus improving the efficiency of fault location.
[0096] The following describes the node-based packet capture method provided in this application with reference to a specific embodiment.
[0097] Reference Figure 2 As shown, Figure 2 This is a flowchart illustrating another packet capture method based on nodes in a VPP, provided in an embodiment of this application. The method includes the following steps S210 to S260:
[0098] Step S210: Set packet capture parameters based on the command line, and call the node packet capture function according to the packet capture parameters. The packet capture parameters include at least the name of the packet capture node, the maximum number of packets to capture, and the target cache. The packet capture node is a node in the VPP forwarding node path.
[0099] Step S220: Based on the command line, set the packet capture switch of the packet capture node to the on state through the global data structure field.
[0100] Specifically, a global data structure field is set to maintain the data status of the node packet capture. The global data structure field includes a global switch field, which is used to set the packet capture switch of the packet capture node. For example, when it is necessary to capture packets from a certain node, the packet capture switch of that node is set to the on state through the global switch field.
[0101] Step S230: Determine the packet capture switch status of the packet capture node through the target code block in the node packet capture function. The packet capture switch is represented by a field in the node data structure.
[0102] The node packet capture function is a function that captures packets from a specified node based on packet capture parameters. After setting the packet capture parameters via the command line, the node packet capture function is called according to the parameters to initiate the packet capture process for the node. Specifically, the node packet capture function includes a packet processing function that places the packet data of the captured node into a target cache for node packet capture. This includes: calling pcap basic functions through the packet processing function to implement the node packet capture processing logic, thereby placing the packet data of the captured node into the target cache to achieve node packet capture.
[0103] Step S240: Monitor the transmission packet data of the packet capture node; if packet data is detected to be transmitted to the packet capture node, put the packet data into the target cache as the packet data of the packet capture node.
[0104] Specifically, a packet capture node is a data forwarding node in the forwarding node path. The packet capture node receives packet data transmitted from the previous hop node. Fault location needs to be performed based on the packet data transmitted to the packet capture node. Therefore, the packet data transmitted by the packet capture node is monitored. When packet data is detected to be transmitted to the packet capture node, the packet data is written to the target buffer to achieve packet capture.
[0105] Step S250: Count the number of packet data in the target cache and determine whether the number of packet data is equal to the maximum number of packet captures; if the number of packet data is equal to the maximum number of packet captures, set the packet capture switch of the packet capture node to the off state based on the command line through the global data structure field, so as to turn off packet capture of the packet capture node; write the packet data in the target cache to the specified file to obtain the packet capture data.
[0106] Step S260: Export the target format file of the packet capture data, and open the target format file using analysis software to view the field content of each packet data in the packet capture data; based on the field content of each packet data in the packet capture data, determine the field where the error occurred after passing the fault node, so as to locate the fault problem.
[0107] In this embodiment, the captured packet data can be exported according to a target format file and viewed using analysis software. For example, if the captured packet data is exported as a pcap file, it can be opened using Wireshark software to view the field content of each node in the captured packet data. After viewing the field content of each node in the captured packet data, it is possible to analyze which specific fields of data were erroneous after passing through the faulty node, further narrowing down the scope of the problematic code, and finally locating the fault problem based on the erroneous fields.
[0108] Furthermore, during the packet capture process of the packet capture node, the packet capture progress status of the packet capture node can be viewed based on the command line. The packet capture progress status represents the amount of node data captured for the packet capture node.
[0109] Through the above process, packets can be captured from specific nodes via command line. Fields in the node's data structure can be used as capture switches, allowing flexible control over the capture status of individual nodes. Furthermore, the capture switch status is determined based on the target code block within the node's capture function, avoiding the capture of packets from all business nodes and thus preventing disruption to the overall program's processing performance. This enables flexible packet capture from specific nodes. Moreover, the method allows for the acquisition of packet capture data from a specific node, enabling fault location based on that data, rather than relying on packet capture data from all nodes in the forwarding path, thereby improving the efficiency of fault location.
[0110] The following describes the node-based packet capture method of this embodiment using a specific packet capture process along a forwarding node path. Figure 3 As shown, Figure 3 This is a schematic diagram of a forwarding node path provided in an embodiment of this application. For ease of explanation, the names of the nodes in the VPP are represented by A, B, C, etc. Assume that the expected VPP forwarding node path for service message 1 is "A→B→C→D→F". Due to coding issues in node C or hidden bugs in other modules, the message data is incorrectly processed in node C, resulting in an incorrect forwarding node path, such as "A→B→C→E→G". In this case, the aforementioned node-based packet capture method can be used to capture packets at node E to obtain the captured data. This captured data can be exported as a pcap file and opened with Wireshark software to view the content of each field in the data packet. This allows analysis of which specific fields of the data were erroneous after the message was processed by node C, further narrowing down the problematic code and locating the root cause.
[0111] Thus, by extending a field in the node data structure of the VPP node for node packet capture on / off, packet capture on / off in a single specified forwarding node can be flexibly controlled via command. Furthermore, a target code block is added to the dispatch_node function running in the main loop to determine the packet capture on / off in the node runtime data, avoiding the situation where commands like pcap dispatch trace capture packets from all running business nodes after being enabled, which would severely impact program processing performance.
[0112] Based on the same inventive concept, this application also provides a packet capture device based on nodes in VPP, referring to... Figure 4 As shown, Figure 4 This is a schematic diagram of a packet capture device based on nodes in VPP provided in an embodiment of this application. The device includes:
[0113] The setting module 410 is used to set packet capture parameters based on the command line and call the node packet capture function according to the packet capture parameters. The packet capture parameters include at least the name of the packet capture node, the maximum number of packets to capture, and the target cache. The packet capture node is a node in the VPP forwarding node path.
[0114] The judgment module 420 is used to determine the packet capture switch status of the packet capture node through the target code block in the packet capture function of the node. The packet capture switch is characterized by a field in the node data structure.
[0115] The module 430 is used to put the packet data of the packet capture node into the target buffer for node packet capture when the packet capture switch is in the on state. The packet data is the packet data transmitted to the packet capture node.
[0116] The apparatus using the embodiments of this application can flexibly specify nodes for packet capture via command line, and use fields in the node data structure as packet capture switches to flexibly control the packet capture switch of a single packet capture node; furthermore, the packet capture switch status is determined based on the target code block in the node packet capture function, avoiding packet capture processing of packet data (messages) in all business nodes, which would seriously affect the program processing performance, thus realizing flexible packet capture of specified nodes.
[0117] In an optional embodiment, the device further includes:
[0118] The first setting module is used to set the packet capture switch of the packet capture node to the on state based on the command line through a global data structure field, so as to enable packet capture of the packet capture node.
[0119] In one alternative embodiment, the insertion module includes:
[0120] The monitoring module is used to monitor the transmitted packet data of the packet capture node;
[0121] A submodule is used to store the packet data as packet data of the packet capture node when it is detected that packet data is being transmitted to the packet capture node.
[0122] In an optional embodiment, the device further includes:
[0123] The statistics module is used to count the number of packet data in the target cache and determine whether the number of packet data is equal to the maximum number of packets captured.
[0124] The stop module is used to stop capturing packets from the packet capture node and obtain the captured data when the number of packet data is equal to the maximum number of packets to be captured.
[0125] In one optional embodiment, the stop module includes:
[0126] The second setting module is used to set the packet capture switch of the packet capture node to the off state based on the command line through a global data structure field, so as to disable packet capture of the packet capture node;
[0127] The writing module is used to write the packet data in the target cache to a specified file to obtain packet capture data.
[0128] In an optional embodiment, the device further includes:
[0129] The field viewing module is used to export the target format file of the packet capture data and open the target format file based on the analysis software to view the field content of each packet data in the packet capture data;
[0130] The location module is used to determine the fields where errors occurred after passing through the fault node based on the field content of each packet data in the packet capture data, so as to locate the fault problem.
[0131] In an optional embodiment, the device further includes:
[0132] The progress viewing module is used to view the packet capture progress status of the packet capture node based on the command line. The packet capture progress status represents the amount of packet data captured by the packet capture node.
[0133] The packet capture device based on nodes in VPP provided in this application embodiment can realize all the processes implemented in the packet capture method embodiment based on nodes in VPP and achieve the same technical effect. To avoid repetition, it will not be described again here.
[0134] This application also provides an electronic device, see embodiments thereof. Figure 5 , Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. For example... Figure 5 As shown, the electronic device 500 includes a memory 510 and a processor 520. The memory 510 and the processor 520 are connected via a bus for communication. The memory 510 stores a computer program that can run on the processor 520 to implement the steps of the packet capture method based on nodes in VPP described in the embodiments of this application.
[0135] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the packet capture method based on nodes in VPP described in this application.
[0136] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the packet capture method based on nodes in VPP described in this application.
[0137] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0138] This application describes embodiments of methods and apparatus according to flowchart illustrations and / or block diagrams. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0139] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0140] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0141] Although preferred embodiments of the present application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present application.
[0142] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.
[0143] The foregoing has provided a detailed description of a packet capture method, apparatus, electronic device, and storage medium based on nodes in VPP provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A packet capture method based on nodes in VPP, characterized in that, The method includes: The packet capture parameters are set based on the command line, and the node packet capture function is called according to the packet capture parameters. The packet capture parameters include at least the name of the packet capture node, the maximum number of packets to capture, and the target cache. The packet capture node is a node in the VPP forwarding node path. The packet capture switch status of the packet capture node is determined by the target code block in the packet capture function. The packet capture switch is represented by a field in the node data structure. When the packet capture switch is in the on state, the packet data of the packet capture node is placed into the target buffer for node packet capture. The packet data is the packet data transmitted to the packet capture node.
2. The method according to claim 1, characterized in that, The method further includes: Based on the command line, the packet capture switch of the packet capture node is set to the on state through the global data structure field, so as to start packet capture on the packet capture node.
3. The method according to claim 1, characterized in that, When the packet capture switch is in the "on" state, the packet data of the packet capture node is placed into the target cache for node packet capture, including: Monitor the transmitted packet data of the packet capture node; If packet data is detected being transmitted to the packet capture node, the packet data is placed into the target cache as the packet data of the packet capture node.
4. The method according to claim 1, characterized in that, The method further includes: Count the number of packet data in the target cache and determine whether the number of packet data is equal to the maximum number of packets captured; When the number of packet data is equal to the maximum number of packet captures, stop capturing packets at the packet capture node and obtain the packet capture data.
5. The method according to claim 4, characterized in that, Stop capturing packets at the captured node and obtain the captured packet data, including: Based on the command line, the packet capture switch of the packet capture node is set to the off state through the global data structure field, so as to disable packet capture of the packet capture node; The packet data in the target cache is written to a specified file to obtain packet capture data.
6. The method according to claim 4, characterized in that, The method further includes: Export the captured packet data to a target format file, and open the target format file using analysis software to view the field content of each packet in the captured packet data; Based on the field content of each packet in the captured data, the field where the error occurred after passing through the fault node is determined in order to locate the fault problem.
7. The method according to any one of claims 1-6, characterized in that, The method further includes: The packet capture progress status of the packet capture node can be viewed using the command line. The packet capture progress status represents the number of packet data captured by the packet capture node.
8. A packet capture device based on nodes in VPP, characterized in that, The device includes: The configuration module is used to set packet capture parameters based on the command line and call the node packet capture function according to the packet capture parameters. The packet capture parameters include: the name of the packet capture node, the maximum number of packets to capture, and the target cache. The packet capture node is a node in the VPP forwarding node path. The judgment module is used to determine the packet capture switch status of the packet capture node through the target code block in the packet capture function of the node. The packet capture switch is characterized by a field in the node data structure. The module is used to put the packet data of the packet capture node into the target cache for node packet capture when the packet capture switch is on. The packet data is the packet data transmitted to the packet capture node.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the packet capture method based on nodes in VPP as described in any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the steps of the packet capture method based on nodes in VPP as described in any one of claims 1-7.
Citation Information
Patent Citations
Method and device for realizing two-layer network package capture of firewall
CN106549945A
Packet capture processing method and device based on DPDK
CN114070900A