Blame netem/paretonormal.c

Packit d3f73b
/*
Packit d3f73b
 * Paretoormal distribution table generator
Packit d3f73b
 *
Packit d3f73b
 * This distribution is simply .25*normal + .75*pareto; a combination
Packit d3f73b
 * which seems to match experimentally observed distributions reasonably
Packit d3f73b
 *  well, but is computationally easy to handle.
Packit d3f73b
 * The entries represent a scaled inverse of the cumulative distribution
Packit d3f73b
 * function.
Packit d3f73b
 *
Packit d3f73b
 * Taken from the uncopyrighted NISTnet code.
Packit d3f73b
 */
Packit d3f73b
#include <stdio.h>
Packit d3f73b
#include <stdlib.h>
Packit d3f73b
#include <string.h>
Packit d3f73b
#include <math.h>
Packit d3f73b
#include <limits.h>
Packit d3f73b
#include <malloc.h>
Packit d3f73b
Packit d3f73b
#include <linux/types.h>
Packit d3f73b
#include <linux/pkt_sched.h>
Packit d3f73b
Packit d3f73b
#define TABLESIZE	16384
Packit d3f73b
#define TABLEFACTOR	NETEM_DIST_SCALE
Packit d3f73b
Packit d3f73b
static double
Packit d3f73b
normal(double x, double mu, double sigma)
Packit d3f73b
{
Packit d3f73b
	return .5 + .5*erf((x-mu)/(sqrt(2.0)*sigma));
Packit d3f73b
}
Packit d3f73b
Packit d3f73b
static const double a=3.0;
Packit d3f73b
Packit d3f73b
static int
Packit d3f73b
paretovalue(int i)
Packit d3f73b
{
Packit d3f73b
	double dvalue;
Packit d3f73b
Packit d3f73b
	i = 65536-4*i;
Packit d3f73b
	dvalue = (double)i/(double)65536;
Packit d3f73b
	dvalue = 1.0/pow(dvalue, 1.0/a);
Packit d3f73b
	dvalue -= 1.5;
Packit d3f73b
	dvalue *= (4.0/3.0)*(double)TABLEFACTOR;
Packit d3f73b
	if (dvalue > 32767)
Packit d3f73b
		dvalue = 32767;
Packit d3f73b
	return (int)rint(dvalue);
Packit d3f73b
}
Packit d3f73b
Packit d3f73b
int
Packit d3f73b
main(int argc, char **argv)
Packit d3f73b
{
Packit d3f73b
	int i,n;
Packit d3f73b
	double x;
Packit d3f73b
	double table[TABLESIZE+1];
Packit d3f73b
Packit d3f73b
	for (x = -10.0; x < 10.05; x += .00005) {
Packit d3f73b
		i = rint(TABLESIZE*normal(x, 0.0, 1.0));
Packit d3f73b
		table[i] = x;
Packit d3f73b
	}
Packit d3f73b
	printf(
Packit d3f73b
"# This is the distribution table for the paretonormal distribution.\n"
Packit d3f73b
	);
Packit d3f73b
Packit d3f73b
	for (i = n = 0; i < TABLESIZE; i += 4) {
Packit d3f73b
		int normvalue, parvalue, value;
Packit d3f73b
Packit d3f73b
		normvalue = (int) rint(table[i]*TABLEFACTOR);
Packit d3f73b
		parvalue = paretovalue(i);
Packit d3f73b
Packit d3f73b
		value = (normvalue+3*parvalue)/4;
Packit d3f73b
		if (value < SHRT_MIN) value = SHRT_MIN;
Packit d3f73b
		if (value > SHRT_MAX) value = SHRT_MAX;
Packit d3f73b
Packit d3f73b
		printf(" %d", value);
Packit d3f73b
		if (++n == 8) {
Packit d3f73b
			putchar('\n');
Packit d3f73b
			n = 0;
Packit d3f73b
		}
Packit d3f73b
	}
Packit d3f73b
Packit d3f73b
	return 0;
Packit d3f73b
}