root / otg / trunk / src / cpp / auto / cbr_generator_helper.cpp

Revision 547, 2.0 kB (checked in by zhibinwu, 3 years ago)

Fix all warning messages, clean build

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2 * This will be automatically generated in the future
3 */
4
5#include <iostream>
6#include <sstream>
7using namespace std;
8
9#include "popt_helper.h"
10#include "cbr_generator_helper.h"
11
12 
13static void 
14callback(
15  poptContext con,
16  enum poptCallbackReason reason,
17  const struct poptOption * opt,
18  char * arg, 
19  void * data
20) {
21  // cout << "CBR Callback: " << opt->longName << " arg: " << arg <<endl;
22   
23  CBR_Generator* gen = (CBR_Generator*)data;
24
25  if (strcmp(opt->longName, "size") == 0) {
26       gen->setPktSize(atoi(arg));
27       cout << "packet size parameter is set as "<< atoi(arg) << endl;
28  } else  if (strcmp(opt->longName, "interval") == 0) {
29    double interv = double(atof(arg))/1000.0;
30    cout << "Packet inteval is set as " << interv << "second " <<endl;
31    gen->setPktInterval(interv);
32  } else if (strcmp(opt->longName, "rate") == 0) {
33    double ra = double(atof(arg))*1e3;
34    cout << "Rate is set as " << ra  << "bps" << endl;
35    gen->setRate(ra);
36  }
37  // else if (strcmp(opt->longName, "pause") == 0){
38  //      gen->pauseGenerator();
39  //} else if (strcmp(opt->longName, "resume") == 0){
40  //      gen->resumeGenerator();
41  //      }
42}
43
44const struct poptOption* 
45cbr_generator_get_options(
46  const CBR_Generator* gen,
47  const char* prefix
48) {
49  struct poptOption* opts = (struct poptOption*)calloc(5, sizeof(struct poptOption));
50  struct poptOption* p = opts;
51  popt_set(p++, NULL, NULL, '\0', POPT_ARG_CALLBACK, (void*)callback, 0, (char*)gen);
52  popt_set(p++, prefix, "size", '\0', POPT_ARG_INT, NULL, 0, "Size of packet", "bytes");
53  popt_set(p++, prefix, "interval", '\0', POPT_ARG_FLOAT, NULL, 0, 
54                          "Internval between consecutive packets", "msec");
55  popt_set(p++, prefix, "rate", '\0', POPT_ARG_FLOAT, NULL, 0, 
56                          "Data rate of the flow", "kbps");
57  // popt_set(p++, prefix, "pause",'\0',POPT_ARG_NONE, NULL, 0, "Pause the traffic generation");
58  // popt_set(p++, prefix, "resume",'\0',POPT_ARG_NONE, NULL,0,"Resume the traffic generation");
59     
60  popt_set(p);
61
62  return opts;
63}
Note: See TracBrowser for help on using the browser.