Summary of the invention
The objective of the invention is provides a kind of method that the crumb data bag is spliced into the designated length packet in order to reduce the influence of crumb data bag to network transmission efficiency.
To achieve these goals, the invention provides a kind of wireless network node buffering data package processing method, be used for the input packet of different length is spliced into the dateout bag of unique length, comprising:
1) length value L that, each input bag in the input bag set is done descending according to data length, and the value of initialization waterline t, the value of waterline is decided to be output packet;
2), judge whether the set of input bag is empty, if sky end operation then otherwise is carried out next step;
3), judge whether current input bag has one or more input bag in gathering, and the data length sums that make these inputs wrap equal the value of waterline t; If there is such input bag, then execution in step 4), otherwise execution in step 5);
4), will import the bag dateout bag that to be spliced into a length be L, if the value of t is less than L, then the insufficient section in the dateout bag is filled 0, after splicing successfully, the output packet that the storage splicing obtains, and the input packet that will splice deletion from input packet set, and execution in step 2 again);
5), with the value of the waterline t unit that descends, forward step 2 then to) re-execute.
The present invention also provides a kind of wireless network node buffering data package processing method, is used for the input packet of different length is spliced into the dateout bag of multiple different length, comprising:
A), each input bag in the set of input bag is done descending by length;
B), according to the species number of different length output packet in the output packet set, the number of designated water level line,, the output packet of the corresponding a kind of length of waterline, the value of each bar waterline of initialization and the value of overall lower limit then, when initialization, the value of waterline is identical with the length of its corresponding output packet, and the value of overall lower limit is 100%; Choose a waterline and corresponding output packet thereof at last;
C), judge whether the set of input bag is empty, if empty, end operation, otherwise, carry out next step;
D), judge whether current input bag has one or more input bag in gathering, and the data length sums that make these inputs wrap equal the value of current waterline; If have such input bag, then execution in step e), otherwise execution in step f);
E), will import packet and be spliced into an output packet corresponding with current waterline, if the value of waterline is less than the length of output packet, then the insufficient section in the output packet is filled 0, after splicing successfully, the output packet that the storage splicing obtains, and the input packet that will splice deletion from the set of input packet, re-execute step c) then;
F), judge the output packet that whether has other length in the output packet set, make the ratio of the value of the pairing waterline of this output packet and this output packet length be higher than the value of overall lower limit, if exist, then the waterline with this output packet correspondence replaces current waterline, and forward step c) to, if there is not execution in step g);
G), reduce the value of current waterline, and the value of the waterline after will the reducing output packet length corresponding with this waterline is made comparisons, if their ratio is greater than or equal to the value of overall lower limit, then jump to step c), otherwise, overall lower limit is updated to this ratio, jumps to then and continue in the step c) to carry out.
All increase under the situation of an extra packet joint in the saturated output packet of described input, described wireless network node buffering data package processing method is applicable to that output packet and input bag have the situation in extra packet header.
The invention has the advantages that:
1, the code space of wireless network node buffering data package processing method of the present invention is little, and it is fast to find the solution speed, is highly suitable for wireless network node and implements.
2, many waterlines heuristic search method of wireless network node buffering data package processing method employing of the present invention has been done global optimization to transmission course, and the utilance of splicing is higher.
3, wireless network node buffering data package processing method of the present invention splices processing to packet, can sacrifice computational resource, response time etc., but exchanged the reduction of transport overhead and routing cost for, be applicable to that comparatively some emphasizes that network saves the transmission power consumption and real-time is required lower environment.
Embodiment
Below in conjunction with the drawings and specific embodiments, method of the present invention is further described.
Wireless network node buffering data package processing method of the present invention is the packet that has different length in a large number to be spliced into the optimization aim data package length.When the splicing of doing packet, the plurality of data bag that certain node compiles, be called the input bag, the bag the splicing back produces is called output packet.Wherein, the length of input bag depends on the image data length of node, and the bag quantity of every kind of length is not limit, and the length of output packet is value in limited several regular lengths, and the bag quantity of every kind of length is not limit.If input bag splicing back then needs to add 0 less than output packet length, send receiving course to simplify.Input bag is spliced into output packet and has the extra packet header overhead, is used to arrive the bag decapsulation after the destination node.
Below in conjunction with embodiment, method of the present invention is elaborated.
Embodiment 1: the joining method that output packet length is fixing.
When output packet length fixedly the time, realize that the splicing of packet will be found the solution exactly with n input bag, all being spliced into length is the optimum splicing scheme of the output packet of L.In the method for the invention, adopt the judgment criteria of utilance as the data splicing effect.Described utilance is the ratio between the total length of the total length of input bag data and output packet data, and utilance is high more, and the effect of obviously splicing scheme is good more.
Splicing problem for this packet, can adopt general greedy algorithm to find the solution, promptly each input bag with current maximum splices into output packet, when this output packet can not be held again, then the new output packet of another one is gone in splicing, disposes up to all input bags.Though this method is simple, may be owing to having selected local optimum, and miss optimal solution, the data total length increases too much, causes bandwidth waste.
In order to improve splicing efficient, in the present embodiment, can adopt single waterline method.Described waterline is illustrated in the scanning position that splices when attempting.Represent waterline with t, the definition waterline is the integer from output packet length L to 0, and waterline t begins to successively decrease from L and scans.Concrete implementation step is as follows:
Step 11, each input bag in the input bag set is done descending according to data length, and the value of initialization waterline t, the value of waterline is decided to be the length value L of output packet;
Step 12, judge whether the set of input bag is empty, if sky end operation then, otherwise carry out next step;
Step 13, judge in the set of current input bag whether one or more input bag is arranged, make data length sums of these input bags equal the value of waterline t just; If there is such input bag, then execution in step 14, otherwise execution in step 15;
Step 14, with these input packets dateout bags that to be spliced into a length be L, if the value of t is less than L, then the insufficient section in the dateout bag is filled 0, after splicing successfully, the output packet that the storage splicing obtains, and the input packet that will splice deletion from input packet set, and execution in step 12 again;
Step 15, waterline t must be worth the unit that descends, forward step 12 then to and re-execute.
The algorithm of said method is achieved as follows:
Represent the input bag with PDisc, the structure of bag is as follows:
struct?PDisc?{
Int len: the length of bag
Int count: the bag quantity of this length
PDisc * next: following a kind of bag is described
}
If P represents the input bag of all kinds of length for being the chained list of element with PDisc, bag is done descending.R is that PDisc is the chained list of element, represents a splicing scheme.Begin to find the solution from first element p of P tabulation.T is a waterline, and cn is the number of times that the input bag of current trial uses, and is initially 0.The function of finding the solution a perfect splicing scheme be Perfect (p, t), method is as follows:
1, attempts earlier a p class bag is spliced into t;
If 2 p->len just equals t, then find a perfect splicing, generate a R list element, r->len=t, r->count=1 returns;
If 3 t are less than p->len, the p bag can not be spliced into t, and (p->next t), returns then to find the solution Perfect;
If 4 p->c-cn=1, p class bag uses up just, and then cn puts 0, and a p class bag is spliced into t, find the solution Perfect (p->next, L-t);
If 5 p->count-cn>1, then cn adds 1, find the solution Perfect (p, L-t);
If the scheme in 65 comprises p class bag, judge then whether the inferior of its use exceeds quantity available, as exceed that then the access times with p class bag in the scheme add 1, return; If surpass, then abandon this scheme, return;
If 7 P tabulation non-NULL or do not find scheme R, p=p->next forwards 1 to;
If 8 find a scheme, a p class bag then is described, and the bag in the bag splicing scheme of t-p->len length can be spliced into t just, add p class bag to scheme tabulation R head.
Below in conjunction with example said method is described.
Suppose to have an input bag set by descending 8,7,6,5,4,3,2,1,1}, the data length of each input bag of the numeral in this set, and the regular length of output packet is 10.When utilizing single waterline method that packet is processed, according to step 10, at first the length with waterline is decided to be 10, whether have one or more length of data package equal 10, obvious if checking then in the set of input bag, the input packet length is to be 10 after two bags addition of 3 and 7, the splicing of these two input bags is obtained new output packet, can count a, then with these two input bag deletions from set, the input bag set that obtains is for { 1,1,5,6,8,4,2}.Then the residue input bag in the set of input bag is conducted a survey, see that whether also having the length of input bag is 10.Same, can obtain length and be two input bags of 8 and 2, and length is two input bags of 6 and 4.Two output packets that obtain after these packets are spliced respectively are designated as b and c respectively, last remaining input bag set for 1,1,5}.Utilizing length is that 10 waterline can not splice remaining input bag, need do to successively decrease to the length of waterline.The length of waterline is reduced by a unit, become 9, still can not splice residue input bag, therefore, continue to successively decrease, become 7 up to the length of waterline, at this moment, can be that three input bags of 1,1 and 5 are made the d that splicing obtains output packet with length in the input bag set, in this output packet, insufficient section adds 0.At last, { 1,1,3,5,6,8,4,7,9 input bags among the 2} obtain 4 output packets to the set of input bag, and its overall utilization is 92.5%.
Embodiment 2: the joining method with multiple output packet length.
The input bag is spliced in the method for output packet, and output packet length may not be unique, but the output packet length of plurality of optional is arranged.When having multiple output packet length and can select, need take all factors into consideration the input bag is spliced to may make up in the output packet of different length, therefore also just there is a plurality of search branch.The mode of search has two kinds: depth-first traversal and breadth First traversal.Depth-first is at the complete end of scan of a kind of output packet of length, just forwards to down a kind of.Breadth First then is the wheel scan flow that walks abreast on the output packet of all lengths according to certain switching law.The present invention adopts many waterlines heuristic search algorithm, and as shown in Figure 3, many waterlines heuristic search algorithm is a kind of breadth First mode.This method is provided with an overall lower limit, represents with the splicing utilance of output packet, and described splicing utilance is with the total length of input bag and the ratio of spliced output packet length.Waterline initially is decided to be the length of first output packet, all writes down a waterline corresponding to each output packet.Judge whether current waterline can hold some input bag just, if exist then output; If there is no then continue search.Waterline scans on corresponding output packet, and each search back waterline subtracts 1, and recomputates utilance, when utilance is lower than overall lower limit, then forwards on the next output packet to scan, and current waterline changes to the waterline of new output packet.Like this, roll off the production line as the foundation of waterline variation control, make the waterline of each output packet all change, have overall uniformity, more can find globally optimal solution according to same ratio by the overall situation.The specific implementation step is as follows:
Step 21, each input bag in the input bag set is done descending by length;
Step 22, according to the species number of different length output packet in the output packet set, the number of designated water level line,, the output packet of the corresponding a kind of length of waterline, the value of each bar waterline of initialization and the value of overall lower limit then, when initialization, the value of waterline is decided to be the length of the output packet corresponding with it, the value of overall lower limit is decided to be 100%; And choose a waterline and corresponding output packet thereof;
Whether step 23, the set of judgement input bag are empty, if sky, end operation, otherwise, carry out next step;
Step 24, judge in the set of current input bag whether one or more input bag is arranged, make data length sums of these input bags equal the value of this waterline just; If there is such input bag, then execution in step 25, otherwise execution in step 26;
Step 25, with these the input packets be spliced into an output packet corresponding with current waterline, if the value of waterline is less than the length of output packet, then the insufficient section in the output packet is filled 0, after splicing successfully, the output packet that the storage splicing obtains, and the input packet that will splice deletion from input packet set, and execution in step 23 again;
Step 26, judge the output packet that whether has other length in the output packet set, make the ratio of the value of the pairing waterline of this output packet and this output packet length be higher than the value of overall lower limit, if exist, then the waterline with this output packet correspondence replaces current waterline, and forward step 23 to, if there is not execution in step 27;
The value of step 27, the current waterline of reduction, and the value of the waterline after will the reducing output packet length corresponding with this waterline is made comparisons, if their ratio is greater than or equal to the value of overall lower limit, then jump to step 23, otherwise, overall lower limit is updated to this ratio, jumps to then and continue in the step 23 to carry out.
The arthmetic statement of the above-mentioned joining method with multiple output packet length is as follows:
Set input the package list P, output packet tabulation Q, two tabulations all are to be the chained list of element with PDisc, the element in the chained list is according to the descending of packet length.
Initialization: current sweep object is first output packet element q of tabulation Q, and current waterline t is first kind of output packet length q->len.Be limited to current utilance under the overall situation: current waterline/current output packet length=100%.
1, when P tabulation for empty, then withdraw from, otherwise the current output packet of q scanned, t be to waterline value that should the output packet preservation, find the solution Perfect (p, t);
If 2 scheme non-NULLs, the output packet that then the input bag of correspondence to be spliced into a length be q->len is removed corresponding input bag from P;
If 3 scheme skies, and t is less than maximum bag and minimum packet length sum in input the package list, and t is maximum in all waterlines, then is the bag selection the shortest a kind of output packet of this maximum length, finishes encapsulation;
4, the current waterline t unit that successively decreases preserves the waterline of this object.
If 5 t/q->len is higher than or equals overall lower limit, then forward 1 to;
If be lower than overall lower limit, then recomputate current utilance, upgrade overall lower limit, change sweep object, make q=q->next, forward 1 to;
In conjunction with example, foregoing description is described.
{ 18,16,16,9,9,7,6,5,5,4,3,3,2,1} suppose to have the output packet of two kinds of length in output packet is gathered, be respectively 10 and 20 to suppose to have an input bag set by descending.Because output is surrounded by two kinds of different length, therefore, two waterlines is arranged, and is designated as t1 and t2 respectively, wherein, the corresponding length of t1 is 10 output packet, and the corresponding length of t2 is 20 output packet.When initial, be limited to 100% under the overall situation.
The length of at first choosing waterline t2 and correspondence thereof is 20 output packet, by searching, in the set of input bag length being arranged as can be known is 18 and 2,16 and 4,16,3 and 1,9,6 and 5 input bag can be spliced into output packet, obtains output packet A, B, C, D, will import bag deletion from the set of input bag accordingly, remaining input bag set is for { 7,3,9,5}.Because the current water level line can't find new splicing scheme again, change the current water level line, the length of choosing waterline t1 and correspondence thereof is 10 output packet.Length in input bag set is that 7 and 3 input bag can be spliced into output packet, obtains output packet E, remaining input bag set for 9,5}.Reduce the value to 9 of waterline t1,9/10=90%, the overall lower limit less than current is reduced to 90% with overall lower limit.And then the value to 9 of reduction waterline t1, can be at this moment that 9 input bag is delivered in the output packet with length, remaining input bag set is { 5}.Reduce overall lower limit once more up to 50%, and reduce the value to 5 of waterline t1, it is sent in the output packet.All input bag splicings in the set of input bag finish, and then the processing procedure of whole buffered data also finishes, and overall utilization is 94.55%.
In above-mentioned example, only selected the situation that two kinds of output packet length are arranged for use, for the situation with two or more output packet length, method of the present invention is suitable for too.Describe at the situation that four kinds of output packet length are arranged below.
Suppose to have an input packet set by descending 19,16,15,13,12,10,9,8,6,5,4,2,2,1}, the length of supposing output packet is 20,15,10,5.Because the length of output packet has four kinds, therefore four different waterlines are arranged, be labeled as t3 respectively, t4, t5, t6.When initial, be limited to 100% under the overall situation.At first choose t3, the length of its pairing output packet is 20.By searching, 19 and 1,16 and 4,15 and 5,12 and 8,10,6,2 and 2 to be spliced into length be 20 input bag as can be known, remaining input bag set for 13,9}.Choose t4 then, the length of its pairing output packet is 15, does not have sliceable input bag.Choose t5 again, the length of its pairing output packet is 10, does not have sliceable input bag equally.Choose t6 at last, its pairing output packet length is 5, does not also have sliceable input bag.At this moment, the set of input bag still is not empty, needs to reduce the length of waterline, when reducing waterline, needs to check overall lower limit.The length of t5 is dropped at 9 o'clock, and the input bag is sliceable in output packet, and the overall lower limit of this moment is 90%.When the length value of t4 was 13, length was that 13 input bag is sliceable in output packet, and the overall lower limit of this moment is 86.7%.
In the description in front, extra computing cost of not considering in the data splicing to be produced and extra packet header are added the processing of extra packet header and can be made algorithm can become complicated, can adopt a kind ofly to wrap the long method of revising and solve.The length of input bag and output packet is all increased an extra packet length of said joint, the situation equivalence of considering extra packet header can be converted into the situation of not considering extra packet header.
Proof:
Criterion 1: when considering extra packet header, length is c, is K1 for a length, and if the packet sequence of K2...Kn is (K1+c)+(K2+c) ...+(Kn-1+c)+and Kn=K, then claim this packet sequence when considering extra packet header, can be spliced in the bag of K length.
Criterion 2: when not considering extra packet header, be K1 for a length, the packet sequence of K2...Kn is if K1+K2......+Kn-1+Kn=K then claims this packet sequence can be spliced in the bag of K length when not considering extra packet header.
When considering extra packet header, be respectively L1 for the input packet length, the packet sequence of L2...Ln judges whether to be spliced into the output packet that length is L, needs to use criterion 1.By the packet length adjustment: will import bag and be adjusted into L1+c, L2+c...Ln-1+c, Ln+c, output length adjustment is L+c, note is done respectively: A1, A2...An, and export length A.When not considering extra packet header, above-mentioned adjusted length is used criterion 2, if satisfy, then A1+A2...+An=A, i.e. (L1+c)+(L2+c) ... (Ln-1+c)+Ln+c=L+c, i.e. (L1+c)+(L2+c) ... (Ln-1+c)+Ln=L, L1 is described, L2...Ln also satisfies criterion 1.And this process is reversible.Therefore have:
Criterion 3:
For a length is K1, and if the packet sequence of K2...Kn and output packet length K when carrying out after packet length adjusts, do not satisfy criterion 2 when not considering extra packet header, is equivalent to satisfy criterion 1 when considering extra packet header.Vice versa.Therefore, by the adjustment of packet length, the algorithm operation result when not considering extra packet header is equivalent to the algorithm operation result when considering extra packet header.Therefore according to above-mentioned adjusted packet length, the method for the present invention when not considering extra packet header is applicable to the situation of considering extra packet header too.