]> git.proxmox.com Git - mirror_iproute2.git/blame - netem/paretonormal.c
devlink: Add devlink trap set and show commands
[mirror_iproute2.git] / netem / paretonormal.c
CommitLineData
c2fdec53
SH
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>
c2fdec53
SH
14#include <string.h>
15#include <math.h>
16#include <limits.h>
17#include <malloc.h>
18
19#include <linux/types.h>
20#include <linux/pkt_sched.h>
21
22#define TABLESIZE 16384
23#define TABLEFACTOR NETEM_DIST_SCALE
24
25static double
26normal(double x, double mu, double sigma)
27{
28 return .5 + .5*erf((x-mu)/(sqrt(2.0)*sigma));
29}
30
c2fdec53
SH
31static const double a=3.0;
32
33static int
34paretovalue(int i)
35{
36 double dvalue;
37
38 i = 65536-4*i;
39 dvalue = (double)i/(double)65536;
40 dvalue = 1.0/pow(dvalue, 1.0/a);
41 dvalue -= 1.5;
42 dvalue *= (4.0/3.0)*(double)TABLEFACTOR;
43 if (dvalue > 32767)
44 dvalue = 32767;
45 return (int)rint(dvalue);
e9e9365b 46}
c2fdec53
SH
47
48int
49main(int argc, char **argv)
50{
c2fdec53 51 int i,n;
f8f9de56 52 double x;
6864c1e7 53 double table[TABLESIZE+1];
c2fdec53
SH
54
55 for (x = -10.0; x < 10.05; x += .00005) {
f8f9de56 56 i = rint(TABLESIZE*normal(x, 0.0, 1.0));
c2fdec53
SH
57 table[i] = x;
58 }
59 printf(
60"# This is the distribution table for the paretonormal distribution.\n"
61 );
62
63 for (i = n = 0; i < TABLESIZE; i += 4) {
64 int normvalue, parvalue, value;
65
66 normvalue = (int) rint(table[i]*TABLEFACTOR);
67 parvalue = paretovalue(i);
68
69 value = (normvalue+3*parvalue)/4;
70 if (value < SHRT_MIN) value = SHRT_MIN;
71 if (value > SHRT_MAX) value = SHRT_MAX;
72
73 printf(" %d", value);
74 if (++n == 8) {
75 putchar('\n');
76 n = 0;
77 }
78 }
c2fdec53
SH
79
80 return 0;
81}