// compile: gcc generate-packets-all.c // execute: ./a.out [-n packetsize] // summary: // generates all permutations of length n; taken to be received by a single // node or via a single "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-all.x -n | ./measure-order.x // // Output format: // // numNodes(or hops) numPackets numSuccessfulRuns(or data sets) // foreach S numSuccessfulRuns // foreach N numHodes // nodeNumber: orderPacketsReceived // #include #include #define MARKED -1 #define _SINGLE_NODE 0 #define _NUM_PACKETS 5 // so we can use cmdline flags int NUM_PACKETS=_NUM_PACKETS,SINGLE_NODE=_SINGLE_NODE; // prints array void print_array( int* array, int size ) { int i; for (i = 0; i < size; i++) printf("%d ", array[i]); printf("\n"); } // recursively creates permutation ina systematic way - when the // permutation is created, the function evaluates the it void makePermutation ( int* permutation, int curr_size, int* choices ) { int i; if ( NUM_PACKETS > curr_size ) { for (i=0; i < NUM_PACKETS; i++) { if ( MARKED != choices[i] ) { permutation[curr_size++] = i; choices[i] = MARKED; makePermutation(permutation, curr_size, choices); choices[i] = i; curr_size--;} } } else { printf("%d: ",SINGLE_NODE); print_array(permutation,NUM_PACKETS); } } // takes argument processing out of main void processArgs( int argc, char** argv ) { int i; extern char *optarg; extern int optind, optopt; /* command line flag stuff */ while ((i = getopt(argc, argv, "n:")) != -1) { switch(i) {case 'n': NUM_PACKETS = atoi(optarg); break; case ':': /* n, p, or s without operand */ exit (EXIT_FAILURE); break; case '?': exit (EXIT_FAILURE); break; } } } int main( int argc, char** argv ) { int i, *inputPermutation, *permutation, total_permutations=1; processArgs(argc,argv); //output first line of output for (i=1;i<=NUM_PACKETS;i++) total_permutations *= i; printf("%d %d %d // numNodes(or hops) numPackets numSuccessfulRuns(or data sets)\n",1,NUM_PACKETS,total_permutations); inputPermutation = (int*)malloc(sizeof(int)*NUM_PACKETS); permutation = (int*)malloc(sizeof(int)*NUM_PACKETS); /* init */ for (i=0;i