int main() { Tossim *t = new Tossim(NULL); Radio *r = t->radio(); Mote *m = t->getNode(11); m->bootAtTime(878010); r->add(11, 12, -90.71); for (int j = 0; j < 500; j++) m->addNoiseTraceReading(-97); m->createNoiseModel(); m = t->getNode(12); m->bootAtTime(371173); r->add(12, 11, -90.71); for (int j = 0; j < 500; j++) m->addNoiseTraceReading(-97); m->createNoiseModel(); t->addChannel("app", stdout); // t->addChannel("TL", stdout); while(1) t->runNextEvent(); }
int main() { srand(time(NULL)); Tossim* t = new Tossim(NULL); Radio* r = t->radio(); t->addChannel("TestBVR", stdout); // t->addChannel("BVR-debug", stdout); // t->addChannel("S4-debug", stdout); // t->addChannel("BVR", stdout); // t->addChannel("S4UserRouter", stdout); t->addChannel("S4Router", stdout); // t->addChannel("S4-beacon", stdout); // t->addChannel("S4-state-func", stdout); fstream filestr; char nextLine[1024]; std::vector<int> v; fstream filestr_noise; filestr_noise.open("meyer-heavy.txt", fstream::in); while (!filestr_noise.eof()) { filestr_noise.getline(nextLine, 1024); v.push_back(atoi(nextLine)); } filestr_noise.close(); fstream filestr2; filestr2.open ("grid-topology.txt", fstream::in ); while (!filestr2.eof()) { filestr2.getline(nextLine, 1024); char* s0 = strtok(nextLine, "\t"); char* s1 = strtok( NULL, "\t"); char* s2 = strtok( NULL, "\t"); char* s3 = strtok( NULL, "\t"); if (s0 == NULL) break; if (!strncmp(s0, "gain", strlen(s0))) { if ( atof(s3) > -104.0){ r->add(atoi(s1), atoi(s2), atof(s3)); std::cout << "Adding connection: "<< s1<< " "<< s2<< " "<< s3<<std::endl; } } else if (! strncmp(s0 , "noise", strlen(s0))){ t->getNode(atoi(s1))->bootAtTime(rand() % 1234567890); std::cout << "Adding node: "<< s1<< " "<< s2<< " "<< s3<<std::endl; Mote* m = t->getNode(atoi(s1)); for (int j = 0; j < v.size(); j++) { int noiseReading = v[j]; m->addNoiseTraceReading(noiseReading); } m->createNoiseModel(); } } std::cout << "Starting the simulation\n"; int i = 0; while (t->time()/ t->ticksPerSecond() < 1500) { t->runNextEvent(); //std::cout << t->time()/ t->ticksPerSecond() << std::endl; } printf("Ended\n"); }
int main(int argc, char **argv) { Tossim* t = new Tossim(NULL); SerialForwarder *sf = new SerialForwarder(9001); map<int, int> motes; map<int, int>::const_iterator iter; Throttle *throttle = new Throttle(t, 1); t->init(); FILE *tables = fopen("table.txt", "w"); FILE *flows = fopen("flows.txt", "w"); //FILE *am = fopen("am.txt", "w"); //t->addChannel("Scheduler", fdopen(1, "w")); //t->addChannel("TossimPacketModelC", fdopen(1, "w")); //t->addChannel("LedsC", fdopen(1, "w")); //t->addChannel("AM", am); /* t->addChannel("Acks", stdout); */ //t->addChannel("Boot", stdout); /* t->addChannel("base", stdout); */ /* t->addChannel("printf", stdout); */ /* t->addChannel("Debug", stdout); */ /* t->addChannel("Unique", stdout); */ /* t->addChannel("SNRLoss", stdout); */ //t->addChannel("CpmModelC", stdout); //t->addChannel("PacketLink", stdout); //t->addChannel("Lqi", stdout); /* t->addChannel("Footer", stdout); */ t->addChannel("Drops", stdout); t->addChannel("Evictions", stdout); t->addChannel("Install", stdout); t->addChannel("Table", tables); t->addChannel("Flows", flows); t->addChannel("Test", stdout); /* t->addChannel("Status", stdout); */ Radio* r = t->radio(); FILE *fp = fopen(argv[1], "r"); int from, to, noise; float gain; int maxNode; while (fscanf(fp, "gain\t%i\t%i\t%f\n", &from, &to, &gain) != EOF) { r->add(from, to, gain); motes[from] = 1; motes[to] = 1; } fclose(fp); throttle->initialize(); // fp = fopen("casino-lab.txt", "r"); fp = fopen("meyer-heavy.txt", "r"); int i = 0; while(fscanf(fp,"%i\n", &noise) != EOF && i++ < 1000) { for (iter = motes.begin(); iter != motes.end(); ++iter ) { t->getNode(iter->first)->addNoiseTraceReading(noise); } } fclose(fp); for (iter = motes.begin(); iter != motes.end(); ++iter ) { printf("creating noise model for %i\n", iter->first); t->getNode(iter->first)->createNoiseModel(); } for (iter = motes.begin(); iter != motes.end(); ++iter ) { printf("booting mote %i\n", iter->first); t->getNode(iter->first)->bootAtTime((31 + t->ticksPerSecond() / 10) * iter->first + 1); } sf->process(); for (;;) { //throttle->checkThrottle(); t->runNextEvent(); sf->process(); } }
int main() { Tossim* t = new Tossim(NULL); Radio* r = t->radio(); int i, x, y, nodeId; double gain, mean, std, noise; char filename[] = "2by1_linkgain_1hop.txt"; int event_run_cnts = 5000; int nodeNum = 2; t->addChannel("TestSMC", stdout); FILE *file = fopen(filename, "r"); if (file != NULL) { //printf("file %s opened \n", filename); char str[MAX_LINE_LEN]; /* or other suitable maximum line size */ char *token; while (fgets(str, sizeof(str), file) != NULL) /* read a line */ { //split the line token = strtok(str," \t"); //printf("0 token %s \n", token); if (strcmp(token, "gain") == 0) { token = strtok(NULL," \t"); x = atoi(token); //printf("1 token %s \n", token); token = strtok(NULL," \t"); y = atoi(token); //printf("2 token %s \n", token); token = strtok(NULL," \t"); //printf("3 token %s \n", token); gain = atof(token); //printf("link (%d, %d, %f) added \n", x, y, gain); r->add(x, y, gain); } if (strcmp(token, "noise") == 0) { token = strtok(NULL," \t"); nodeId = atoi(token); token = strtok(NULL," \t"); mean = atof(token); token = strtok(NULL," \t"); std = atof(token); Mote* m = t->getNode(nodeId); //printf("noise for node %d added, mean = %f, std = %f \n", nodeId, mean, std); for (i = 0; i < NOISE_RANDOM_NUM; i++) { noise = mean + (drand48() - 0.5) * std * 2; m->addNoiseTraceReading((char)noise); } } } fclose (file); } else { perror(filename); /* why didn't the file open? */ return 1; } //r->add(0, 1, -54.0); for (i = 0; i < nodeNum; i++) { Mote* m = t->getNode(i); //global sync //m->bootAtTime(0); m->bootAtTime(5003 * i + 1); m->createNoiseModel(); } for (i = 0; i < event_run_cnts; i++) { t->runNextEvent(); } }