The packet size distribution enhancement of the Linux Kernel Packet Generator: ---------------------------------------------------------- Table of Contents: I. How it works II. How to use the new enhancements III. How to install this module IV. What i have change in the code First of all I want to mention that this patch was only tested on a x86 PC with a v2.6.8 Linux Kernel. But please report problems to me: fabian_at_net.in.tum.de (substitute "_at_" with "@") I. How it works: ----------------- When a new packet shall be generated, a new packet size has to be determined. Therefore we randomly choose an entry of the (so called) outliers array. This array contains packet size values of those packet sizes which appear very often in the distribution which shall be represented. If we read a -1 in this array, none of these packet sizes is choosen, therefore we need to choose randomly again. But this time we use another array---the so called histos array. In this array the entrys are the lowest packet size of the bin which it is representing. For this reason we need to add random jitter of maximal the width of such a bin (called hist_width below) to this obtained packet size. II. How to use the new enhancements: ------------------------------------ 1. Read the original pktgen.txt 2. The following three new commands for the /proc interface were added: dist: pgset "dist 1000 20 1500 33 75" This is used to set up the Linux Kernel Packet Generator for excepting the distributions entered by the "outl" and "hist" commands. The syntax is: dist <#outliers> <#histos> With the size of the array used for generating the different packet sizes is set. This is directly influencing how high the resolution of the different entrys is. The sets the width of a bin. The sets the maximum packet size. The <#outliers> and <#histos> define how many lines of "oult" and "hist" have to follow until the input distribution is complete. outl: pgset "outl 40 179" Syntax: outl <#cells> This instructs the Generator to fill <#cells> of the outliers array with the packet size hist: pgset "hist 40 91" Syntax: hist <#cells> This instructs the Generator to fill <#cells> of the histos array with the packet size , to which jitter will be added. 3. To activate the distribution you have to switch the PKTSIZE_REAL flag pgset "flag PKTSIZE_REAL". This will only succeed if the distribution is complete and correct, indicated with the DIST_READY flag. III. How to install this module: -------------------------------- 1. Download the source code: http://www.net.in.tum.de/~schneifa/sources/pktgen-lkpg-dist-0.1.tar.gz 2. unpack the tar archive: tar -xvzf pktgen-lkpg-dist-0.1.tar.gz 3. Copy the new pktgen.c over the old: cp pktgen-lkpg-dist-0.1/pktgen.c /usr/src/linux/net/core/pktgen.c 4. Compile the new pktgen.c: cd /usr/src/linux/net/core make -C /usr/src/linux SUBDIRS=$PWD modules 5. Install the new module: cd /usr/src/linux make modules_install 6. use it! Happy generating IV. What i have change in the code: ----------------------------------- To use the packet size distributions it was necessary to change the source code of the Linux Kernel Packet Generator module. Please refer to the original source code, to comprehend the following changes: * I added a new struct for input array entries, consisting of two integers for packet size and amount of cells in the arrays used for generation. * I added a general struct for controlling the distribution and its state. The precision, the size of the bins, the maximum packet size, the number of outliers, the number of bins as well as indexes to the arrays and the two input arrays themself are saved in this struct. * I added two new flags: one to indicate that the entered distribution is ready, and one to activate the usage of the packet size distribution. * I added the two generation arrays and a byte counter to the existent control struct of the packet generator. * I wrote the new function mod_cur_pktsize() which is modifying the actual packet size according to the principle describe in I. utilising the net_random() function of the kernel. * I adjoined a check for each packet to calculate a new packet size if both new flags are set (in function fill_packet()). * I added byte counting after the generation of the packet. This is necessary because you can not calculated the the data rate by multiplying the amount of generated packets with the preset packet size any longer since the packet size changes per packet now. * I changed the accounting processing at the end of packet generation to get the right results (this was somewhat screwing up my brain, because of wild bit shifts to preseve reasonable accuracy for the output). * I wrote the function calculate_ra_arrays() which fills the arrays used for packet size inquiry. If done successfully the flag which indicates that the distribution is ready is set. * I wrote the function check_dist_complete() which checks if the entered distribution is complete, and if so calls calculate_ra_arrays(). * I added the whole input stuff for the distributions to proc_write(). * I added the initialisation to init() as well as the clearance to cleanup(). Please comments in the source code in addition. 02.10.2005, Fabian Schneider