Detailed Description
To facilitate an understanding of the invention, the invention will now be described more fully with reference to the accompanying drawings. Preferred embodiments of the present invention are shown in the drawings. This invention may, however, be embodied in many different forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terminology used in the description of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used herein, the term "and/or" includes any and all combinations of one or more of the associated listed items.
At present, the transmission bandwidth which is not controlled by the protocol becomes more and more, and under the environment, according to the requirement of the high-speed development of the ethernet, the transmission bandwidth needs to be controlled to meet the requirement of rate transmission, so that the problem of network congestion and even packet loss can be avoided.
The bandwidth control method provided in the embodiment of the present invention may be applied to an application environment shown in fig. 1, where fig. 1 is an application environment diagram of an embodiment of the bandwidth control method of the present invention. Wherein the terminal 102 communicates with the server 104 via a network. The terminal 102 measures the length of the data packet, dynamically adjusts the bandwidth in real time, and transmits the data packet to the network with the preset bandwidth, so that the problem of packet loss caused by data congestion is avoided. The terminal 102 may be, but not limited to, various personal computers, notebook computers, smart phones, tablet computers, and portable wearable devices, and the server 104 may be implemented by an independent server or a server cluster formed by a plurality of servers.
Specifically, an embodiment of the present invention provides a bandwidth control method, as shown in fig. 2, where fig. 2 is a schematic diagram of a first flow of an embodiment 1 of the bandwidth control method of the present invention, and the method includes:
step S210, measuring the data packet length of the data packet to be transmitted;
specifically, length measurement is carried out on an input data packet to be transmitted, and the length of the data packet can be obtained; preferably, the data packets to be transmitted are counted by using the clock period of the working clock, and the obtained counted number can be the length of the data packets to be transmitted; further, after obtaining the length of the data packet, the length of the data packet can be recorded to a specified position;
it should be noted that the data packet to be transmitted may be a data packet to be transmitted to the ethernet;
the length of the data packet can be measured or calculated in bytes, for example, the physical characteristics of the ethernet determine that the maximum length of a link layer data frame is 1500 bytes, a longest IP packet can be 65535 bytes, and the like;
step S220, based on the length of the data packet and the preset bandwidth, generating an output ratio and idle data packets for separating the data packets to be transmitted in the transmission process; the output ratio is the data packet length ratio or the number ratio of the data packet to be transmitted and the idle data packet;
specifically, generating an idle data packet and an output ratio according to a preset bandwidth by the length of an input data packet;
it should be noted that the preset bandwidth may be used to set the bandwidth size or the rate according to the actual need, and may be obtained by the system configuration parameters; specifically, such as full speed, cutout, half speed, 1/4 rate, 1/5 rate, 1/8 rate, etc.; the embodiment of the invention achieves real-time adjustment of the parameters by dynamically adjusting the bandwidth parameters in real time without restarting the system;
the idle data packets can be idle invalid data packets or idle characters and can be used for controlling the interval of each data packet to be transmitted in the transmission process; specifically, a corresponding idle data packet can be generated according to the length of the data packet to be transmitted and a preset bandwidth, and the idle data packet can be used for separating the data packets to be transmitted in the transmission process, so that the bandwidth parameters can be dynamically adjusted in real time without restarting the system;
the output ratio can be the length or the number ratio of the data packets to be transmitted to the idle data packets, and can be used for controlling the proportion of the data packets to be transmitted to the idle data packets in the data transmission process;
specifically, the length of a data packet to be transmitted is measured to obtain the length L of the data packet; generating an idle data packet and an output ratio according to the length L of the data packet and a preset bandwidth, wherein the length of the data packet of the idle data packet is I;
if L is equal to I, the output ratio may represent the number ratio of the data packets to be transmitted to the idle data packets; when the preset bandwidth is in a full-speed mode, the output ratio can be 1/0, the number of data packets to be transmitted is 1, and the number of idle data packets is 0, that is, the input data packets are continuously sent away without increasing packet intervals; when the preset bandwidth is in a cutoff mode, the output ratio can be 0/1, the number of data packets to be transmitted is 0, the number of idle data packets is 1, no data packet is output, and idle characters are continuously sent; when the preset bandwidth is in a half-speed mode, the output ratio can be 1/1, the number of data packets to be transmitted is 1, the number of idle data packets is 1, one data packet to be transmitted is sent, one idle data packet is sent, and the output bandwidth is controlled to be reduced by half; when the preset bandwidth is in a 1/4 rate mode, the output ratio can be 1/3, the number of data packets to be transmitted is 1, the number of idle data packets is 3, a packet of data to be transmitted is sent, 3 packets of idle data packets are sent, and the output bandwidth is controlled to be 1/4; by analogy, the preset bandwidth may also be an 1/5 rate mode, a 1/8 rate mode, and the like, which is not described herein again;
if L is not equal to I, the output ratio can represent the packet length ratio of the data packet to be transmitted and the idle data packet; according to the preset bandwidth, sending a packet of data packet to be transmitted with the length of L, sending an idle data packet with the length of I, and controlling the actual transmission bandwidth to be L/(L + I);
and step S230, transmitting the data packet to be transmitted and the idle data packet to the Ethernet in a preset bandwidth according to the output ratio.
Specifically, based on the output ratio, outputting the data packet to be transmitted and the idle data packet to the next stage according to reading control, and transmitting the data packet to the Ethernet in a preset bandwidth to complete bandwidth control;
it should be noted that other processing can be performed in the process of transmitting the data packet to be transmitted and the idle data packet to the ethernet, so that the data packet to be transmitted and the idle data packet can be transmitted to the next stage with a preset bandwidth according to the output ratio, and then transmitted to the ethernet after being processed by the next stage, thereby completing bandwidth control;
optionally, in an example, the output ratio may be converted into a read-write control delay logic, and the data packet is read out and output to the next stage; specifically, in the full-speed mode, the data packet to be transmitted is directly read and output to the next stage without increasing the clock reading delay of the idle data packet; in a half-speed mode, after a data packet to be transmitted with the length of L is read, idle data is added to wait for I clock counts (the number of the clock counts of I is equal to that of the clock counts of L), then the next data packet to be transmitted is read, and the transmission interval between two data packets to be transmitted is strictly controlled to ensure that the average bandwidth is controlled at 1/2;
the embodiment of the invention measures the length of the data packet to be transmitted; generating an output ratio and an idle data packet based on the length of the data packet and a preset bandwidth; according to the output ratio, transmitting the data packet to be transmitted and the idle data packet to the Ethernet by using a preset bandwidth; the method can measure the length of the data packet and dynamically adjust the bandwidth in real time, solves the problem of uncontrolled transmission bandwidth, and is not limited by a specific transmission protocol; the idle data packet is sent to realize the control of the bandwidth, the bandwidth rate of the input data packet is not depended on, extra cost is not required to be added, the control of the transmission bandwidth according to the requirement when the Ethernet transmits data is facilitated, meanwhile, the automatic adjustment is realized by software, excessive manual intervention is not required, the software configuration is convenient, the convenience and the adaptability of the bandwidth control are improved, and the problem of packet loss caused by data congestion in an Ethernet transmission link can be avoided;
further, the embodiments of the present invention are advantageously implemented by using Programmable Logic devices such as an FPGA (Field-Programmable Gate Array), a CPLD (Complex Programmable Logic Device), an EPLD (Erasable Programmable Logic Device), an SPLD (simple Programmable Logic Device), etc., or by using an Application Specific Integrated Circuit (ASIC) chip or a Digital Signal Processing (DSP) Programmable chip.
In a specific embodiment, referring to fig. 3, fig. 3 is a second flowchart of the bandwidth control method according to the embodiment of the present invention, where the step of measuring the packet length of the data packet includes:
in step S310, the length of the data packet is measured by the working clock.
Specifically, the working clock can be used for counting the data packets to be transmitted to reach the data packet length;
it should be noted that, the length of the measurement data packet may be counted by using the clock period of the working clock; the method measures the length of the data packet by counting the working clock, can realize automatic measurement of the length of the data packet, further enhances the flexibility of the bandwidth control method, reduces manual intervention, is convenient for software configuration, and improves the convenience and adaptability of bandwidth control.
In a specific embodiment, as shown in fig. 4, fig. 4 is a third flowchart of an embodiment of the bandwidth control method of the present invention, and the step of generating an idle data packet based on the length of the data packet and a preset bandwidth includes:
step S422, generating the length of an idle data packet according to the preset bandwidth and the length of the data packet;
in step S424, an idle packet is generated based on the idle packet length.
Specifically, the idle data packet length can be calculated according to the measured data packet length of the data packet to be transmitted and the preset bandwidth; generating an idle data packet according to the length of the idle data packet;
specifically, the difference between the preset bandwidth and the data packet length of the data packet to be transmitted can be obtained to obtain the idle data packet length; based on the idle packet length, a number of idle packets may be generated.
In a specific embodiment, referring to fig. 5, fig. 5 is a fourth flowchart illustrating an embodiment of the bandwidth control method of the present invention, where the step of transmitting the data packet to be transmitted and the idle data packet to the ethernet with the preset bandwidth according to the output ratio includes:
step S532, converting to obtain a read-write control delay value according to the output ratio; the read-write control delay value comprises the output sequence and the output ratio of the data packet to be transmitted and the idle data packet;
step S534, based on the read-write control delay value, reading and outputting the data packet to be transmitted and the idle data packet.
Specifically, the data packet to be transmitted and the idle data packet can be read and output based on the read-write control delay value obtained by converting the output ratio;
it should be noted that the read-write control delay value may be obtained by converting the output ratio, and may include the output sequence and the output ratio of the data packet to be transmitted and the idle data packet; reading out the data packet according to the read-write control delay value, and outputting the data packet to the next stage; specifically, in the full-speed mode, the data packet to be transmitted is directly read and output to the next stage without increasing the clock reading delay of the idle data packet; in the half-speed mode, after a data packet to be transmitted with the length of the data packet L is read, an idle data packet with the length of the data packet I can be sent or idle data is added to wait for I clock counts (the number of the clock counts of I is equal to that of the clock counts of L), then the next data packet to be transmitted is read, and the transmission interval between the two data packets to be transmitted is strictly controlled to ensure that the average bandwidth is controlled at 1/2; optionally, the output sequence of the output ratio in the embodiment of the present invention may be that the data packet to be transmitted is read and output first, and then the idle data packet is transmitted, or the idle data packet is transmitted first and then the idle data packet is read and output, or the data packet to be transmitted is inserted into the middle of a plurality of idle data packets and transmitted;
the embodiment of the invention sequentially sends the data packet to be transmitted and the idle data packet according to the read-write control delay value to realize the control of the bandwidth, does not depend on the specific bandwidth rate of the input data packet, does not need to increase extra cost, is favorable for controlling the transmission bandwidth according to the requirement when the data is transmitted by the Ethernet, simultaneously realizes automatic adjustment by software, does not need excessive manual intervention, is convenient for software configuration, improves the convenience and the self-adaptability of the bandwidth control, and can avoid the problem of packet loss caused by data congestion in an Ethernet transmission link.
In a specific embodiment, as shown in fig. 6, fig. 6 is a schematic diagram of a fifth flow chart of an embodiment of the bandwidth control method of the present invention, and according to the output ratio, before the step of transmitting the data packet to be transmitted and the idle data packet to the ethernet with the preset bandwidth, the method further includes:
step S612, cache the data packet to be transmitted.
Specifically, after an input data packet to be transmitted is acquired, the data packet to be transmitted can be cached so as to facilitate subsequent reading and transmission; preferably, the data packet to be transmitted may be stored in an internal Memory of the programming chip, such as a First Input First Output (FIFO) Memory, a Random-Access Memory (RAM), and the like
In a specific embodiment, referring to fig. 7, fig. 7 is a sixth flowchart illustrating an embodiment of the bandwidth control method of the present invention, where the step of caching the to-be-transmitted data packet includes:
step S714, when a preset number of data packets to be transmitted are obtained within a preset time, sequentially caching the data packets according to the sequence of obtaining the data packets to be transmitted.
Specifically, when a plurality of data packets to be transmitted are acquired in a short time, the data packets can be sequentially cached according to the sequence of acquiring the data packets to be transmitted, which is beneficial to sequentially reading the data packets to be transmitted subsequently;
the preset time can be set according to actual needs, and specifically, can be 1s (second), 0.01s, 0.001s, or the like;
the preset number can be set according to actual needs, specifically, more than 2, more than 3 and the like;
when a plurality of data packets are received in a burst manner, the data packets are sequentially stored in the memory so as to be read in a correct sequence subsequently, the accuracy of reading the output data packets is ensured, and the accurate transmission of bandwidth control is guaranteed.
In a specific embodiment, as shown in fig. 8, fig. 8 is a seventh flowchart illustrating an embodiment of the bandwidth control method of the present invention, and after the step of measuring the packet length of the data packet to be transmitted, the method further includes the steps of:
in step S812, the packet length is recorded.
Specifically, after measuring the packet length of the packet to be transmitted, the packet length may be recorded and saved to a designated location for invocation of subsequent steps.
It should be understood that although the various steps in the flow charts of fig. 2-8 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least some of the steps in fig. 2-8 may include multiple sub-steps or multiple stages that are not necessarily performed at the same time, but may be performed at different times, and the order of performance of the sub-steps or stages is not necessarily sequential, but may be performed in turn or alternating with other steps or at least some of the sub-steps or stages of other steps.
On the other hand, an embodiment of the present invention further provides a bandwidth control apparatus, referring to fig. 9, where fig. 9 is a schematic structural diagram of an embodiment 1 of the bandwidth control apparatus of the present invention, including:
a packet length measuring module 910, configured to measure a packet length of a packet to be transmitted;
a bandwidth configuration module 920, configured to generate an output ratio and idle data packets for separating data packets to be transmitted in a transmission process based on the length of the data packet and a preset bandwidth; the output ratio is the data packet length ratio or the number ratio of the data packet to be transmitted and the idle data packet;
the data packet transmission module 930 is configured to transmit the data packet to be transmitted and the idle data packet to the ethernet with a preset bandwidth according to the output ratio.
Further, the embodiment of the present invention may further include: the data packet caching module is used for caching the data packet to be transmitted; the data packet length recording module is used for recording the data packet length;
the data packet length measuring module can comprise a working clock measuring unit which is used for measuring the data packet length of the data packet to be transmitted through a working clock;
the bandwidth configuration module can comprise an idle data packet length acquisition unit and an idle data packet generation unit; the idle data packet length acquisition unit is used for generating the idle data packet length according to the preset bandwidth and the data packet length; the idle data packet generating unit is used for generating an idle data packet based on the length of the idle data packet;
the data packet transmission module can comprise a read-write control delay value acquisition unit and a read output data packet unit; the read-write control delay value acquisition unit is used for converting to obtain a read-write control delay value according to the output ratio; the reading output data packet unit is used for reading and outputting a data packet to be transmitted and an idle data packet based on the read-write control delay value;
it should be noted that, for specific limitations of the bandwidth control apparatus, reference may be made to the above limitations of the bandwidth control method, which is not described herein again. The various modules in the bandwidth control apparatus described above may be implemented in whole or in part by software, hardware, and combinations thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
To facilitate understanding of a specific implementation flow of the embodiment of the present invention, a specific implementation example is set forth, as shown in fig. 10 and 11, fig. 10 is a system connection block diagram of an example of a bandwidth control method of the present invention, and fig. 11 is a data packet control bandwidth output diagram of an example of a bandwidth control method of the present invention;
acquiring a data packet 1 and a data packet 2 to be transmitted, and measuring the data packet lengths of the data packets 1 and 2 by adopting a working clock to obtain L1 and L2; writing the received data packets 1 and 2 into an internal memory such as FIFO, RAM and the like in sequence; according to the packet lengths L1 and L2 and the preset bandwidth, the packet lengths I1 and I2 of the idle packets are obtained through calculation, and output proportion including L1, L2, I1 and I2 is generated; according to the output ratio, sequentially reading data packets 1 with the length of L1 according to reading control, then sending idle packets 1 with the length of I1, then reading data packets 2 with the length of L2, then sending idle packets 2 with the length of I2, sequentially outputting the data packets to the next stage, and further transmitting the data packets to the Ethernet to finish bandwidth control; the data packet corresponds to the data packet to be transmitted, and the idle packet corresponds to the idle data packet.
The embodiment of the invention can measure the data packet length of the data packet to be transmitted; generating an output ratio and an idle data packet based on the length of the data packet and a preset bandwidth; according to the output ratio, transmitting the data packet to be transmitted and the idle data packet to the Ethernet by using a preset bandwidth; the method can measure the length of the data packet and dynamically adjust the bandwidth in real time without increasing extra cost, is beneficial to controlling the transmission bandwidth according to requirements when the data is transmitted by the Ethernet, meanwhile, realizes automatic adjustment by software, does not need excessive manual intervention, is convenient for software configuration, improves the convenience and the adaptability of bandwidth control, solves the problem of uncontrolled transmission bandwidth, is not limited by a specific transmission protocol, and can avoid the problem of packet loss caused by data congestion in an Ethernet transmission link;
furthermore, the data packet length is measured by dynamically caching the data packet and utilizing the working clock, so that the transmission bandwidth can be configured in real time, the actually output data transmission bandwidth is controlled, the flexibility of bandwidth control is enhanced, manual intervention is reduced, and the software configuration is convenient.
In one embodiment, a computer device is provided, the computer device may be a server, an internal structure diagram of the computer device may be as shown in fig. 12, and fig. 12 is an internal structure diagram of the computer device in one embodiment of the invention. The computer device includes a processor, a memory, and a network interface connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a bandwidth control method.
Those skilled in the art will appreciate that the architecture shown in fig. 12 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
When a processor of the computer device executes a program, the bandwidth control method can be realized in any one of the above embodiments, so that the bandwidth can be dynamically adjusted in real time without manual participation, the convenience and the adaptability of bandwidth control are improved, the problem of uncontrolled transmission bandwidth is solved, the computer device is not limited by a specific transmission protocol, and the problem of packet loss caused by data congestion in an Ethernet transmission link can be avoided.
In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, which computer program, when executed by a processor, implements a bandwidth control method.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM). The technical features of the embodiments described above may be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the embodiments described above are not described, but should be considered as being within the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present invention, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention. Therefore, the protection scope of the present patent shall be subject to the appended claims.