~ubuntu-branches/ubuntu/hardy/iproute/hardy-proposed

« back to all changes in this revision

Viewing changes to netem/paretonormal.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2006-07-06 10:23:46 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060706102346-tyd1mfjvay0nmz90
Tags: 20051007-4ubuntu1
* Merge from debian unstable, remaining changes:
  - versioned dependency on linux-kernel-headers,
  - MAX_ROUNDS patch to ip/ipaddress.c

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Paretoormal distribution table generator
 
3
 *
 
4
 * This distribution is simply .25*normal + .75*pareto; a combination
 
5
 * which seems to match experimentally observed distributions reasonably
 
6
 *  well, but is computationally easy to handle.
 
7
 * The entries represent a scaled inverse of the cumulative distribution
 
8
 * function.
 
9
 *
 
10
 * Taken from the uncopyrighted NISTnet code.
 
11
 */
 
12
#include <stdio.h>
 
13
#include <stdlib.h>
 
14
#include <stdlib.h>
 
15
#include <string.h>
 
16
#include <math.h>
 
17
#include <limits.h>
 
18
#include <malloc.h>
 
19
 
 
20
#include <linux/types.h>
 
21
#include <linux/pkt_sched.h>
 
22
 
 
23
#define TABLESIZE       16384
 
24
#define TABLEFACTOR     NETEM_DIST_SCALE
 
25
 
 
26
static double
 
27
normal(double x, double mu, double sigma)
 
28
{
 
29
        return .5 + .5*erf((x-mu)/(sqrt(2.0)*sigma));
 
30
}
 
31
 
 
32
static const double a=3.0;
 
33
 
 
34
static int
 
35
paretovalue(int i)
 
36
{
 
37
        double dvalue;
 
38
 
 
39
        i = 65536-4*i;
 
40
        dvalue = (double)i/(double)65536;
 
41
        dvalue = 1.0/pow(dvalue, 1.0/a);
 
42
        dvalue -= 1.5;
 
43
        dvalue *= (4.0/3.0)*(double)TABLEFACTOR;
 
44
        if (dvalue > 32767)
 
45
                dvalue = 32767;
 
46
        return (int)rint(dvalue);
 
47
}       
 
48
 
 
49
int
 
50
main(int argc, char **argv)
 
51
{
 
52
        int i,n;
 
53
        double x;
 
54
        double table[TABLESIZE+1];
 
55
 
 
56
        for (x = -10.0; x < 10.05; x += .00005) {
 
57
                i = rint(TABLESIZE*normal(x, 0.0, 1.0));
 
58
                table[i] = x;
 
59
        }
 
60
        printf(
 
61
"# This is the distribution table for the paretonormal distribution.\n"
 
62
        );
 
63
 
 
64
        for (i = n = 0; i < TABLESIZE; i += 4) {
 
65
                int normvalue, parvalue, value;
 
66
 
 
67
                normvalue = (int) rint(table[i]*TABLEFACTOR);
 
68
                parvalue = paretovalue(i);
 
69
 
 
70
                value = (normvalue+3*parvalue)/4;
 
71
                if (value < SHRT_MIN) value = SHRT_MIN;
 
72
                if (value > SHRT_MAX) value = SHRT_MAX;
 
73
 
 
74
                printf(" %d", value);
 
75
                if (++n == 8) {
 
76
                        putchar('\n');
 
77
                        n = 0;
 
78
                }
 
79
        }
 
80
 
 
81
        return 0;
 
82
}