P4 hardware-based message mirroring method and device
By switching mirroring rules and trimming packets on the P4 hardware according to the operating status of network devices, the problems of network performance degradation and resource consumption caused by traditional packet mirroring are solved. This achieves efficient mirroring processing when network conditions are poor, balancing network smoothness and mirroring effect.
Patent Information
- Application Number
- CN202511239538.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-01
- Publication Date
- 2025-11-11
AI Technical Summary
Traditional packet mirroring methods lead to decreased network performance, increased resource consumption, and network congestion in network devices, affecting the stability of user services and the observation effect of mirrored packets.
The packet mirroring method based on P4 hardware switches mirroring rules according to the operating status of network devices, adopts rules for mirroring complete packets or partial packets, and combines packet trimming mode to locate and copy the necessary parts of the packet, thereby achieving packet mirroring.
When network conditions are poor, unnecessary packet segments can be trimmed to improve network smoothness while ensuring effective observation of mirrored packets, thus saving bandwidth and storage resources.
Smart Images

Figure CN120935198A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of network technology, and in particular to a packet mirroring method and apparatus based on P4 hardware. Background Technology
[0002] Many network devices now support packet mirroring, with traditional methods including port mirroring and flow mirroring. Port mirroring copies all packets flowing through a given port and sends them out through that port. Flow mirroring, based on user configuration, copies packets that meet specific rules and sends them to a designated port. Packet mirroring has important applications in network monitoring, troubleshooting, and security analysis, but in practice, it can also introduce a series of side effects or potential problems. These side effects may affect network performance, resource utilization, and the stability of network device services. Specifically, these include: Performance degradation occurs because mirrored packets consume a certain amount of network bandwidth, reducing the effective bandwidth used by user services and thus causing a decline in service performance. Increased packet latency and the transmission of mirrored packets in the network will further affect the processing and forwarding of other service packets, which will have a certain impact on services with high requirements. Storage / processing resource consumption: Because there is message replication, a certain amount of storage / processing resources are required. Network congestion can occur when network packets are copied, which can lead to network congestion in certain situations and, in severe cases, interruption of normal business operations. In summary, a conflict arises between users' need for data packet monitoring and the need to ensure that users' business is not affected. Related technologies have proposed methods such as discarding mirrored packets or sampling mirrored traffic to alleviate network congestion caused by packet mirroring, but this will also affect the user's ability to observe mirrored packets. Summary of the Invention
[0003] In view of this, the purpose of the present invention is to provide a packet mirroring method and apparatus based on P4 hardware, which can better balance network smoothness and the observation effect of mirrored packets.
[0004] In a first aspect, the present invention provides a packet mirroring method based on P4 hardware, the method being applied to P4 hardware, the method comprising: The target packet mirroring rule is switched according to the current operating status of the network device. The target packet mirroring rule can be either a complete packet mirroring rule or a partial packet mirroring rule. The partial packet mirroring rule is configured with a packet trimming mode. Based on the rules for mirroring complete packets, or the rules for mirroring partial packets and the packet trimming mode configured therein, the packets flowing through the network device are mirrored to obtain mirrored packet data, which is then sent using a specified port.
[0005] In one implementation, switching the target packet mirroring rule based on the current operating state of the network device includes: Monitor network devices for any abnormal events within a preset time period; If so, determine that the current operating status of the network device is abnormal, and switch to the mirrored packet rules; If not, then confirm that the network device is currently operating normally and switch to the mirrored full packet rule.
[0006] In one implementation, according to the mirroring complete packet rules, packets flowing through the network device are mirrored to obtain mirrored packet data, including: The packets flowing through the network device are copied to obtain mirror packet data.
[0007] In one implementation, according to the mirroring portion of the packet rules and the packet pruning mode configured therein, the packets flowing through the network device are mirrored to obtain mirrored packet data, including: Based on the packet trimming mode, the segment to be trimmed in the packet flowing through the network device is located, and the segment to be trimmed is copied to obtain mirror packet data; the packet trimming mode includes fixed trimming mode and custom trimming mode.
[0008] In one implementation, locating the segment to be clipped in a packet flowing through the network device according to the packet clipping mode includes: When the packet trimming mode is fixed trimming mode, determine whether the length of the packet flowing through the network device exceeds the preset length threshold. If so, starting from the first byte, locate the segment to be clipped in the packet flowing through the network device according to the preset length threshold. The length of the segment to be clipped is consistent with the preset length threshold. If not, then the packets flowing through the network device are copied to obtain mirror packet data.
[0009] In one implementation, locating the segment to be clipped in a packet flowing through the network device according to the packet clipping mode further includes: When the packet trimming mode is set to custom trimming mode, the trimming range in the packet flowing through the network device is located according to the custom trimming parameters built into the custom trimming mode; wherein, the value of the custom trimming parameter is within a preset range.
[0010] In one implementation, the method of locating the segment to be clipped in a packet flowing through a network device based on the custom clipping parameters built into the custom clipping mode includes: When the value of the custom pruning parameter is the minimum value of the preset range, the header parsing part of the packet flowing through the network device is taken as the pruning interval; When the value of the custom trimming parameter is the maximum value of the preset range, the payload parsing part of the packet flowing through the network device is taken as the trimming interval; If the value of the custom pruning parameter is any other value within a preset range, the packets flowing through the network device are divided into multiple sub-intervals by percentage, and the sub-intervals corresponding to the custom pruning parameters are taken as the pruning intervals.
[0011] Secondly, the present invention also provides a packet mirroring device based on P4 hardware. The device is applied to P4 hardware and includes: The rule switching module is used to switch the target packet mirroring rule according to the current operating status of the network device. The target packet mirroring rule can be either a complete packet mirroring rule or a partial packet mirroring rule. The partial packet mirroring rule is configured with a packet trimming mode. The packet mirroring module is used to mirror packets flowing through network devices according to the rules for mirroring complete packets or partial packets and the packet trimming mode configured therein, to obtain mirrored packet data, and then send the mirrored packet data through a specified port.
[0012] Thirdly, the present invention also provides an electronic device including a processor and a memory, the memory storing computer-executable instructions executable by the processor, the processor executing the computer-executable instructions to implement any of the methods provided in the first aspect.
[0013] Fourthly, the present invention also provides a computer-readable storage medium storing computer-executable instructions, which, when invoked and executed by a processor, cause the processor to implement any of the methods provided in the first aspect.
[0014] This invention provides a packet mirroring method and apparatus based on P4 hardware. The method switches target packet mirroring rules according to the current operating state of the network device. The target packet mirroring rules can be either complete packet mirroring rules or partial packet mirroring rules, with the partial packet mirroring rules configured with packet pruning modes. Based on the complete packet mirroring rule or the partial packet mirroring rule and its configured packet pruning modes, packets flowing through the network device are mirrored to obtain mirrored packet data, which is then sent using a designated port. This invention leverages the programmability of P4 to provide a novel packet mirroring method. Based on the current operating state of the network device, it performs complete or partial mirroring of packets flowing through the network device according to corresponding rules. This allows for packet truncation and discarding of unnecessary parts when network conditions are poor, thus better balancing network smoothness and the observation effect of the mirrored packets.
[0015] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention are realized and obtained in accordance with the structures particularly pointed out in the description, claims and drawings.
[0016] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0017] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0018] Figure 1 This invention provides a typical network port mirroring topology diagram. Figure 2 This invention provides a typical flow mirror topology diagram. Figure 3 This is another typical flow mirror topology provided in an embodiment of the present invention; Figure 4 A flowchart illustrating a packet mirroring method based on P4 hardware provided in an embodiment of the present invention; Figure 5 A technical framework diagram of a packet mirroring method based on P4 hardware provided for an embodiment of the present invention; Figure 6A schematic diagram of a packet mirroring device based on P4 hardware provided in an embodiment of the present invention; Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0019] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below in conjunction with the embodiments. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0020] Currently, when users need to mirror packets in network devices, they typically use the following methods: (a) Port mirroring, which is further divided into ingress port mirroring and egress port mirroring. Ingress port mirroring: After the user specifies a port, all packets arriving at that port are copied. Egress port mirroring: After the user specifies a port, all packets leaving that port are copied. Bidirectional mirroring: After the user specifies a port, all packets arriving at and leaving through that port are copied. For an example, see [link to example]. Figure 1 The diagram shows a typical network port mirroring topology. Packets coming from port vf2 and packets going out from port vf1 are copied and sent to port vf0. Users can receive mirrored packets on terminal devices connected to port vf0.
[0021] (ii) Stream mirroring: Based on user-configured mirroring rules, once a packet matches a user-configured mirroring rule, that packet will be mirrored to the user-specified port. For example... Figure 2 The diagram shows a typical flow mirroring topology. Traffic from vf2 to vf1 is not all mirrored to vf0. Only packets that meet the rules configured by the user are copied to vf0.
[0022] After receiving mirrored packets, users utilize them for traffic statistics and analysis, network monitoring, troubleshooting and diagnosis, or security monitoring and intrusion detection. Since vf0 carries both service packets from mac0 and mirrored packets from other ports, this can rapidly increase the network load on vf0, especially when packet traffic on each line is excessive. The added burden of packet mirroring can severely strain the network system, potentially causing packet loss and disrupting normal user services. See also... Figure 3The diagram shows another typical flow mirroring topology. When both mirrored packets and service packets are sent to vf0, it increases the load on the network line where vf0 is located. Severe network congestion can lead to various packet reception delays, and even random dropping of service packets and mirrored packets. This is clearly not what users want.
[0023] To address the issues caused by message mirroring, the industry has proposed the following solutions: 1. When network congestion is detected, prioritize dropping mirrored packets: Modify the priority value of dscp or vlan in the mirrored packet to prioritize dropping packets with lower priority in the packet dropping policy; Attach a flow label to the mirrored packet to mark it as a mirrored packet, so that such packets will be dropped first when packet dropping is required; Set a special flag in another field of the packet, and drop packets marked with this flag by detecting this flag.
[0024] Second: Supports sampling of mirrored traffic: random sampling, randomly copying packets according to a certain ratio; time sampling, mirroring packets once every certain period of time or after a certain number of packets; traffic type sampling, mirroring only packets of a certain type according to the traffic type.
[0025] Both of the above solutions can alleviate network congestion caused by packet mirroring, but they also affect the user's ability to observe mirrored packets. For the first solution, although all packets are mirrored, mirrored packets are prioritized for dropping during network congestion, potentially causing users to miss packets they want to observe, thus affecting their viewing experience. For the second solution, a sampling parameter is provided, reducing the number of packets sampled from the source. However, for the same reason, the desired packet might not be sampled.
[0026] Based on this, the present invention provides a packet mirroring method and apparatus based on P4 hardware, which can better balance network smoothness and the observation effect of mirrored packets.
[0027] To facilitate understanding of this embodiment, a packet mirroring method based on P4 hardware disclosed in this embodiment will first be described in detail. This method is applied to P4 hardware. See [link to relevant documentation]. Figure 4 The diagram shows a message mirroring method based on P4 hardware. The method mainly includes the following steps S402 to S404: Step S402: Switch the target packet mirroring rule according to the current operating status of the network device.
[0028] The current operating status describes whether abnormal events have occurred in the network device, such as network congestion or packet loss. The target packet mirroring rule can be either a complete packet mirroring rule or a partial packet mirroring rule. A complete packet mirroring rule copies the entire packet, while a partial packet mirroring rule copies the portion of the packet to be trimmed. The partial packet mirroring rule is configured with a packet trimming mode, which is used to preset or customize the portion to be trimmed. Specifically, it includes a fixed trimming mode and a custom trimming mode.
[0029] In one example, this embodiment of the invention provides a packet mirroring rule based on P4 hardware, based on the programmability of P4, and adaptively switches the packet mirroring rule of the network device according to the current operating state of the network device, such as switching to a partial packet mirroring rule when the current operating state is abnormal, and switching to a complete packet mirroring rule when the current operating state is normal.
[0030] Step S404: Based on the rules for mirroring complete packets or the rules for mirroring partial packets and the packet trimming mode configured therein, perform mirroring processing on the packets flowing through the network device to obtain mirrored packet data, and send the mirrored packet data using the specified port.
[0031] In one example, packets flowing through network devices can be directly copied according to the rules for mirroring complete packets; in another example, the packet trimming mode built into the rules for mirroring partial packets can be used to locate the trimming section within the packets flowing through network devices, and the trimming section can be copied to obtain mirrored packet data.
[0032] This invention provides a new packet mirroring method that leverages the programmability of P4. Based on the current operating state of the network device, it performs complete or partial mirroring of packets flowing through the network device according to corresponding rules. This can be done when the network conditions are poor, by truncating packets and discarding unnecessary parts of the packets, thereby better balancing network smoothness and the observation effect of the mirrored packets.
[0033] To balance the conflict between user demand for mirrored packets and network bandwidth and storage resource limitations, and leveraging the flexible configurable rules of P4, this invention provides a specific implementation of a packet mirroring method based on P4 hardware. See [link to relevant documentation]. Figure 5The diagram illustrates a technical framework for a packet mirroring method based on P4 hardware. It determines whether to copy the entire packet. If yes, P4 copies the entire packet to the mirroring port; otherwise, it determines whether it is in fixed mode. In fixed mode (also known as fixed trimming mode), if the packet is larger than 256 bytes, only the first 256 bytes are copied to the mirroring port; if the packet is smaller than 256 bytes, the entire packet is copied to the mirroring port. In non-fixed mode (also known as custom trimming mode), the user-configured truncation parameter (also known as trimming parameter) is between 0 and 100. If it is 0, only the header parsed by P4 is copied; if it is 100, the remaining unparsed portion of the packet is copied or not copied at all; if it is any other value, a percentage of the packet bytes are truncated. In this embodiment of the invention, combined with the programmability of P4, users can flexibly set different mirroring rules. Different mirroring rules can be set according to different packet types and user needs to meet user requirements. Users can also flexibly set interception parameters. Users can adjust the interception coefficient according to network conditions to achieve an optimal effect in terms of user needs and network resource utilization.
[0034] For ease of understanding, the specific implementation process is as follows: (i) The network control agent monitors whether any abnormal events occur on the network device within a preset time period. For example, if the network device experiences abnormal events such as network congestion or packet loss within the preset time period, it is determined that the current operating status is abnormal; if no abnormal events such as network congestion or packet loss occur, it is determined that the current operating status is normal.
[0035] In another implementation, to meet different user mirroring needs, the P4 rules can be configured to allow users to choose between mirroring complete packet rules or mirroring partial packet rules.
[0036] (ii) If not, then the current operating status of the network device is confirmed to be normal, and the system switches to the mirrored complete packet rule to copy the packets flowing through it to obtain mirrored packet data. Specifically, for mirrored complete packets, when a packet flowing through the system matches the mirrored complete packet rule, P4 will copy a complete packet before sending the packet out, and send this copied complete packet out from the user-specified port.
[0037] (iii) If so, the current operating status of the network device is determined to be abnormal, and the system switches to the mirrored packet rules. Based on the packet trimming mode, the system locates the segment to be trimmed in the packets flowing through it, and copies the segment to be trimmed to obtain mirrored packet data. Specifically, for a certain part of the mirrored packet, when a flowing packet matches a rule for a part of the mirrored packet, P4 will determine how to mirror that part of the packet based on further user configuration.
[0038] To meet bandwidth and storage resource requirements, sometimes users need mirrored packets. Not all bytes of the packet are valid for the user. In this case, the user can decide how P4 should trim the mirrored packet according to their needs.
[0039] Method 1: When the packet trimming mode is fixed trimming mode, determine whether the length of the packet flowing through the network device exceeds the preset length threshold; if so, starting from the first byte, locate the trimming interval in the packet flowing through the network device according to the preset length threshold, and the length of the trimming interval is consistent with the preset length threshold; if not, copy the packet flowing through the network device to obtain mirror packet data.
[0040] For example, by trimming mirrored packets in a fixed-byte manner, after setting a trimming mode 0, P4 will execute the following trimming strategy based on the user's configuration: When the packet size is less than or equal to 192 bytes, the packet will not be trimmed, and P4 will copy the entire packet and send it to the user-specified mirror port; when the packet size is greater than or equal to 192 bytes, P4 will only copy the first 192 bytes of the packet, and the remaining part of the packet, usually the payload, will not be copied. Under this strategy, as long as the packet length exceeds 192 bytes, only the first 192 bytes of the packet will be sent to the user-specified mirror port, which preserves the useful information of the packet while potentially saving bandwidth resources.
[0041] Method 2: When the packet trimming mode is set to custom trimming mode, the trimming interval in the packet flowing through the network device is located according to the custom trimming parameters built into the custom trimming mode; the value of the custom trimming parameter is within a preset range. Specifically, when the custom trimming parameter is at the minimum value of the preset range, the header parsing part of the packet flowing through the network device is taken as the trimming interval; when the custom trimming parameter is at the maximum value of the preset range, the payload parsing part of the packet flowing through the network device is taken as the trimming interval; when the custom trimming parameter is at other values within the preset range, the packet flowing through the network device is divided into multiple sub-intervals by percentage, and the sub-intervals corresponding to the custom trimming parameters are taken as the trimming intervals.
[0042] For example, in a user-configurable manner, after setting a trimming mode 1, P4 will trim according to the user's configuration. The user provides a truncation parameter, the value of which is in the range of 0~100. To accommodate two special cases of message headers and message payloads, this embodiment of the invention specifies: When the truncation parameter is 0, only the header parsed by the parser is mirrored. However, it should be noted that in not all cases, the header parsed by the parser is exactly the same as the actual protocol header of the message.
[0043] When the parameter is set to 100, only the payload portion of the packet will be mirrored. After the P4 parser parses a portion of the packet, the remaining parsed portion is called the payload. The meaning of this payload is not always equal to the payload of the packet's protocol layer. When the user selects the 100 parameter, only the payload portion will be sent to the user-specified mirroring port. When the packet has no payload, the packet will not be mirrored.
[0044] When the truncation parameter is 0 or other values of 100, P4 truncates the packet according to the percentage of the truncation parameter provided by the user, and sends the truncated portion to the mirror port specified by the user.
[0045] In summary, leveraging the programmability of the P4, this invention provides a novel mirroring mode. While still sampling 100% of packets, the sampled packets are truncated, discarding unnecessary payloads, and the entire mirrored packet is not sent. This strategy mirrors all packets while discarding some useless packet payloads, minimizing network congestion. Experimental test data shows that when the average packet length transmitted in the network is 576 bytes, this strategy provides approximately 50% bandwidth savings compared to a full mirroring strategy without truncation.
[0046] Based on the foregoing embodiments, this invention provides a packet mirroring device based on P4 hardware, see [link to previous embodiment]. Figure 6 The schematic diagram shown illustrates the structure of a packet mirroring device based on P4 hardware, including: The rule switching module 602 is used to switch the target packet mirroring rule according to the current operating status of the network device. The target packet mirroring rule is either a complete packet mirroring rule or a partial packet mirroring rule. The partial packet mirroring rule is configured with a packet trimming mode. The packet mirroring module 604 is used to mirror packets flowing through network devices according to the rules for mirroring complete packets or partial packets and the packet trimming mode configured therein, to obtain mirrored packet data, and to send the mirrored packet data through a specified port.
[0047] This invention provides a new packet mirroring method that leverages the programmability of P4. Based on the current operating state of the network device, it performs complete or partial mirroring of packets flowing through the network device according to corresponding rules. This can be done when the network conditions are poor, by truncating packets and discarding unnecessary parts of the packets, thereby better balancing network smoothness and the observation effect of the mirrored packets.
[0048] The device provided in this embodiment of the invention has the same implementation principle and technical effect as the aforementioned method embodiment. For the sake of brevity, any parts not mentioned in the device embodiment can be referred to the corresponding content in the aforementioned method embodiment.
[0049] This invention provides an electronic device, specifically, the electronic device includes a processor and a storage device; the storage device stores a computer program, and the computer program, when run by the processor, executes the method described in any of the above embodiments.
[0050] Figure 7 The present invention provides a schematic diagram of the structure of an electronic device 100, which includes a processor 70, a memory 71, a bus 72 and a communication interface 73. The processor 70, the communication interface 73 and the memory 71 are connected through the bus 72. The processor 70 is used to execute executable modules, such as computer programs, stored in the memory 71.
[0051] The memory 71 may include high-speed random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 73 (which can be wired or wireless), such as the Internet, wide area network, local area network, metropolitan area network, etc.
[0052] Bus 72 can be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 7 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0053] The memory 71 is used to store programs. After receiving an execution instruction, the processor 70 executes the programs. The method executed by the device for defining the flow process disclosed in any of the foregoing embodiments of the present invention can be applied to the processor 70 or implemented by the processor 70.
[0054] The processor 70 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of the processor 70 or by instructions in software form. The processor 70 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this invention can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software modules may reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. The storage medium is located in memory 71. Processor 70 reads the information in memory 71 and, in conjunction with its hardware, completes the steps of the above method.
[0055] The computer program product of the readable storage medium provided in the embodiments of the present invention includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the foregoing method embodiments. For specific implementation, please refer to the foregoing method embodiments, which will not be repeated here.
[0056] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0057] Finally, it should be noted that the above-described embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A packet mirroring method based on P4 hardware, characterized in that, The method is applied to P4 hardware, and the method includes: The target packet mirroring rule is switched according to the current operating status of the network device. The target packet mirroring rule is either a complete packet mirroring rule or a partial packet mirroring rule. The partial packet mirroring rule is configured with a packet trimming mode. According to the complete message mirroring rules, or the partial message mirroring rules and the message trimming modes configured therein, the messages flowing through the network device are mirrored to obtain mirrored message data, and the mirrored message data is sent using a designated port.
2. The packet mirroring method based on P4 hardware according to claim 1, characterized in that, The target packet mirroring rules are switched according to the current operating status of the network device, including: Monitor whether any abnormal events occur on the network device within a preset time period; If so, determine that the current operating state of the network device is abnormal, and switch to the image packet rules; If not, then determine that the current operating status of the network device is normal, and switch to the mirrored complete packet rule.
3. The packet mirroring method based on P4 hardware according to claim 1, characterized in that, According to the aforementioned complete message mirroring rules, messages flowing through the network device are mirrored to obtain mirrored message data, including: The packets flowing through the network device are copied to obtain mirror packet data.
4. The packet mirroring method based on P4 hardware according to claim 1, characterized in that, Based on the aforementioned mirrored packet rules and the packet trimming mode configured within them, the packets flowing through the network device are mirrored to obtain mirrored packet data, including: According to the packet trimming mode, the segment to be trimmed in the packet flowing through the network device is located, and the segment to be trimmed is copied to obtain mirror packet data; wherein, the packet trimming mode includes a fixed trimming mode and a custom trimming mode.
5. The packet mirroring method based on P4 hardware according to claim 4, characterized in that, According to the packet trimming mode, the region to be trimmed in the packet flowing through the network device is located, including: When the packet pruning mode is the fixed pruning mode, it is determined whether the length of the packet flowing through the network device exceeds a preset length threshold. If so, starting from the first byte, locate the segment to be clipped in the packet flowing through the network device according to the preset length threshold, where the length of the segment to be clipped is consistent with the preset length threshold. If not, then the packets flowing through the network device are copied to obtain mirror packet data.
6. The packet mirroring method based on P4 hardware according to claim 4, characterized in that, According to the packet trimming mode, locating the trimming section in the packet flowing through the network device further includes: When the packet trimming mode is the custom trimming mode, the trimming interval in the packet flowing through the network device is located according to the custom trimming parameters built into the custom trimming mode; wherein, the value of the custom trimming parameter is within a preset range.
7. The packet mirroring method based on P4 hardware according to claim 6, characterized in that, Based on the custom pruning parameters built into the custom pruning mode, locate the pruning region in the packets flowing through the network device, including: When the value of the custom pruning parameter is the minimum value of the preset range, the header parsing part of the packet flowing through the network device is taken as the pruning interval; When the value of the custom pruning parameter is the maximum value of the preset range, the payload parsing part of the packet flowing through the network device is taken as the pruning interval; When the value of the custom pruning parameter is any other value within the preset range, the packets flowing through the network device are divided into multiple sub-intervals by percentage, and the sub-intervals corresponding to the custom pruning parameter are taken as the pruning intervals.
8. A message mirroring device based on P4 hardware, characterized in that, The device is applied to P4 hardware, and the device includes: The rule switching module is used to switch the target packet mirroring rule according to the current operating status of the network device. The target packet mirroring rule is either a complete packet mirroring rule or a partial packet mirroring rule. The partial packet mirroring rule is configured with a packet trimming mode. The packet mirroring module is used to mirror packets flowing through the network device according to the complete packet mirroring rules or the partial packet mirroring rules and the packet trimming mode configured therein, to obtain mirrored packet data, and to send the mirrored packet data through a designated port.
9. An electronic device, characterized in that, The method includes a processor and a memory, the memory storing computer-executable instructions executable by the processor, the processor executing the computer-executable instructions to implement the method of any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions that, when invoked and executed by a processor, cause the processor to perform the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Remote mirror image system and method based on p4 programmable chip
CN116074333A
Virtual network flow mirroring method and system
CN117857575A
Message mirroring method and network equipment with message mirroring function
CN1744534A
A device and related method for dynamic traffic mirroring policy
US20140280887A1
Network monitoring using selective mirroring
US20180091387A1