Alex Bikfalvi
SimStream Documentation
SimulatorNetUcast.cpp
00001 #include "Headers.h" 00002 #include "SimulatorNetUcast.h" 00003 #include "TopoBrite.h" 00004 #include "Rand.h" 00005 00006 #pragma warning(disable : 4996) 00007 00008 void CSimulatorNetUcast::Run(char* simName, int argc, char* argv[]) 00009 { 00010 printf("\n\nSimulator: NETWORK UNICAST (v. %s %s) (%s)\n", __DATE__, __TIME__, simName); 00011 00012 if(argc != 7) 00013 { 00014 printf("\nSyntax is:\ 00015 \n\t1 - Topology name\ 00016 \n\t2 - Output file\ 00017 \n\t3 - Count sources\ 00018 \n\t4 - Count destinations\ 00019 \n\t5 - Min topology\ 00020 \n\t6 - Max topology\ 00021 \n"); 00022 return; 00023 } 00024 00025 // Input parameters 00026 char* name = argv[1]; 00027 char* outName = argv[2]; 00028 __uint32 numSrc = atoi(argv[3]); 00029 __uint32 numDst = atoi(argv[4]); 00030 __uint32 minTopo = atoi(argv[5]); 00031 __uint32 maxTopo = atoi(argv[6]); 00032 00033 printf("\nInput parameters are:\ 00034 \n\t 1 - Topology name = %s\ 00035 \n\t 2 - Output file = %s\ 00036 \n\t 3 - Count sources = %u\ 00037 \n\t 4 - Count destinations = %u\ 00038 \n\t 5 - Min topology = %u\ 00039 \n\t 6 - Max topology = %u\ 00040 \n\n", 00041 name, 00042 outName, 00043 numSrc, 00044 numDst, 00045 minTopo, 00046 maxTopo); 00047 00048 double ucastLengthSum = 0; 00049 __uint32 ucastLengthNum = 0; 00050 char topoFile[1024]; 00051 00052 FILE* out = fopen(outName, "w"); 00053 if(NULL == out) printf("\n\nCannot open file %s.", outName); 00054 00055 for(__uint32 topo = minTopo; topo <= maxTopo; topo++) 00056 { 00057 // Generate topology file 00058 sprintf(topoFile, "%s-%02u.brite", name, topo); 00059 00060 CTopo* topology = new CTopoBrite( 00061 topoFile 00062 ); 00063 00064 for(__uint32 indexSrc = 0; indexSrc < numSrc; indexSrc++) 00065 { 00066 __uint32 src = CRand::Generate(topology->Nodes()-1); 00067 00068 for(__uint32 indexDst = 0; indexDst < numDst; indexDst++) 00069 { 00070 __uint32 dst = CRand::Generate(topology->Nodes()-1); 00071 00072 fprintf(out, "%u ", topology->Route()->Distance(src, dst)); 00073 00074 ucastLengthSum += topology->Route()->Distance(src, dst); 00075 ucastLengthNum ++; 00076 } 00077 } 00078 00079 delete topology; 00080 } 00081 00082 fclose(out); 00083 printf("\nAverage unicast path length: %.2lf", ucastLengthSum / ucastLengthNum); 00084 } 00085
Last updated: February 8, 2011