// compile: gcc generate-packets-prob.c // execute: ./a.out [-h num_hops] [-n packetsize] [-p probability] [-r] [-s samples] // summary: // generates s permutations of length n for each "hop"; packets are generated based // on the sending of a single ordered packet, and are permuted based on the // sending probability p of the network; s (sample) controls how many times this // sending process is simulated; using -i initializes the packet to the proper ordering // each time. The STDOUT may be captured and measured using measure-order.c: // // ./gen-packets-prob.x -h 4 -p 0.9 | ./measure-order.x // // Output format: // // numNodes(or hops) numPackets numSuccessfulRuns(or data sets) // foreach S numSuccessfulRuns // foreach N numHodes // nodeNumber: orderPacketsReceived // #include #include #include // defaults #define _NUM_PACKETS 5 #define _PROBABILITY 0.5 #define _SAMPLES 100000 #define _USE_SRAND 0 // use current usec and srand to seed rand() #define _NUM_HOPS 1 // initialize new packet for each sample, or use last one? // so we can use cmdline flags int NUM_PACKETS=_NUM_PACKETS,SAMPLES=_SAMPLES,USE_SRAND=_USE_SRAND,NUM_HOPS=_NUM_HOPS; double PROBABILITY = _PROBABILITY; // dumps array to stdout void print_array( int* array, int size ) { int i; for (i = 0; i < size; i++) printf("%d ", array[i]); printf("\n"); } // provides high resolution time in microseconds for srand int get_usec ( void ) { struct timeval tv; struct timezone tz; struct tm *tm; gettimeofday(&tv, &tz); return tv.tv_usec; } // globals - mins are initialized using INT_MAX static int *permutation, send_attempts, hopCount; // generates permutation based on probability, given some initial sequence int messagePermutation(int *inputPermutation) { int i, *temp, tempPosition=0, numItemsInTemp=NUM_PACKETS, permPosition=0, attempts=0; double prob; temp = (int *)malloc(sizeof(int) * NUM_PACKETS); for (i=0; i