#include #include int align_to_cell(int packet_size, int cell_size, int cell_payload) { int needed_cells; needed_cells = packet_size / cell_payload; if((packet_size % cell_payload) > 0) needed_cells++; return needed_cells * cell_size; } int main(int argc, char** argv) { if(argc < 4) { printf("usage: %s <0|1 for show rate table>\n", argv[0]); return 1; } int bps = atoi(argv[1]); int mtu = atoi(argv[2]); int mpu = atoi(argv[3]); int overhead = atoi(argv[4]); int show_rates=0; if(argc > 5) show_rates = atoi(argv[5]); if(mtu == 0 ) { printf("mtu == 0\n"); return 1; } int cell_log = 0; int i; while ((mtu>>cell_log) > 255) cell_log++; unsigned int rate_table_static[256]; unsigned int rate_table_dynamic[256]; printf("cell_log = %d\n", cell_log); for (i=0; i<256; i++) { unsigned sz1 = ((i+1)< static overhead calculation\n"); printf("rate2 -> dynamic overhead calcuation\n"); printf("rate3 -> realtime calculation. this is the reference value\n"); int rate1_err=0; int rate2_err=0; for(k=40; k < mtu;k++) { //bytes to send at ip-layer (at least 40) int ps = k; //static overhead calculated already in rate table unsigned int rate1 = rate_table_static[ps >> cell_log]; //dynamic overhead calculated in kernel L2T unsigned int rate2 = rate_table_dynamic[(ps-1 + overhead) >> cell_log]; //realtime calculated int sz3 = ps + overhead; if(sz3 < mpu) sz3 = mpu; sz3 = align_to_cell(sz3, 53, 48); unsigned int rate3 = (1000000*sz3) /bps; if(rate1 != rate3) { printf("rate1 is wrong: Bytes at IP-Layer = %d rate1=%d rate3 = %d\n", ps, rate1, rate3); rate1_err++; } if(rate2 != rate3) { printf("rate2 is wrong: Bytes at IP-Layer = %d rate2=%d rate3 = %d\n", ps, rate2, rate3); rate2_err++; } } printf("Rate1 Error: %d Rate2 Error: %d\n", rate1_err, rate2_err); return 0; }