Exemplo n.º 1
0
void PacketDumper::dumpPacket(const struct pcap_pkthdr *h, const u_char *packet,
                              dump_reason reason, int sampling_rate,
                              unsigned int max_pkts_per_file, unsigned int max_sec_per_file) {

  // ntop->getTrace()->traceEvent(TRACE_WARNING, "%s(len=%u)", __FUNCTION__, h->len);
  if(!dumper) openDump(h->ts.tv_sec, sampling_rate, max_pkts_per_file, max_sec_per_file);

  int rate_dump_ok = reason != ATTACK || num_dumped_packets % sampling_rate == 0;

  if(dumper && rate_dump_ok) {
    pcap_dump((u_char*)dumper, h, packet);
    num_dumped_packets++;
    checkClose(h->ts.tv_sec);
  }
}
Exemplo n.º 2
0
int main(int argc, char** argv)
{
   struct sched_param sp;
   pthread_t bgth;

   if ( argc != 3 && argc != 5 )
   {
      usage();
      return -1;
   }

   unsigned int coreID = 0;
   unsigned int startFreq = 0;
   unsigned int targetFreq = 0;
   
   unsigned int argcCounter = 1;
   
   // Option for core specification
   if ( strcmp(argv[1],"-c")==0 )
   {
      if ( sscanf(argv[2],"%u",&coreID) != 1 )
      {
         fprintf(stderr,"Fail to get the core ID argument\n");
         return -2;
      }
      argcCounter +=2;
      
      if ( argc != 5 )
      {
         fprintf(stderr,"Missing frequencies arguments\n");
         usage();
         return -1;
      }
   }

   if ( sscanf(argv[argcCounter],"%u",&startFreq) != 1 )
   {
      fprintf(stderr,"Fail to get the start frequency argument\n");
      return -3;
   }

   if ( sscanf(argv[argcCounter+1],"%u",&targetFreq) != 1 )
   {
      fprintf(stderr,"Fail to get the target freq argument\n");
      return -4;
   }
   
   // Additional checks
   if ( coreID >= getCoreNumber() )
   {
      fprintf(stdout,"The core ID that user gave is invalid\n");
      fprintf(stdout,"Core ID is set to 0\n");
      coreID = 0;
   }
   
   initFreqInfo();
   
   if ( isFreqAvailable(coreID,startFreq) == 0 )
   {
      fprintf(stdout,"The starting frequency that you have entered (%d) is not available for the core %d\n",startFreq,coreID);
      fprintf(stdout,"Aborting");
      cleanup();
      return -6;
   }
   
   if ( isFreqAvailable(coreID,targetFreq) == 0 )
   {
      fprintf(stdout,"The target frequency that you have entered (%d) is not available for the core %d\n",targetFreq,coreID);
      fprintf(stdout,"Aborting");
      cleanup();
      return -7;
   }
   
   initCoreRelations();
   
   
#ifdef _DUMP
   openDump("./results.dump",NB_TRY_REPET_LOOP*NB_VALIDATION_REPET);
#endif

   // stay on cpu 2
   pinCPU(coreID);

   // create a background task to keep CPU awaken
   pthread_create(&bgth, NULL, thfn, NULL);
      
   // go realtime, max prio
   sched_getparam(0, &sp);
   sp.sched_priority = sched_get_priority_max(SCHED_FIFO);
   if (sched_setscheduler(0, SCHED_FIFO, &sp))
   {
      perror("setscheduler background");
   }

   if ( setCPUGovernor("userspace") != 0 )
   {
      fprintf(stderr,"We are unable to set \"userspace\" governor. Do you have cpufreq and permissions ?\n");
      cleanup();
      return -5;
   }

   // Set the minimal frequency
   if ( openFreqSetterFiles() != 0 )
   {
      cleanup();
      return -3;
   }

   setFreqForAllRelatedCore(coreID,getMinAvailableFreq(coreID));
   runTest(startFreq, targetFreq, coreID);

   // kill bg thread
   pthread_cancel(bgth);

   cleanup();
   return 0;
}