Пример #1
0
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");
}
Пример #2
0
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();
  }
}