Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

PushReceiverApp Class Reference

#include <push_receiver.hh>

Inheritance diagram for PushReceiverApp:

Inheritance graph
[legend]
Collaboration diagram for PushReceiverApp:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 PushReceiverApp (int argc, char **argv)
void recv (NRAttrVec *data, NR::handle my_handle)
void run ()

Protected Member Functions

void usage (char *s)
void parseCommandLine (int argc, char **argv)

Protected Attributes

NRdr_
u_int16_t diffusion_port_
char * config_file_

Private Member Functions

handle setupSubscription ()

Private Attributes

PushReceiverReceivemr_
handle subHandle_
int last_seq_recv_
int num_msg_recv_
int first_msg_recv_

Constructor & Destructor Documentation

PushReceiverApp::PushReceiverApp int  argc,
char **  argv
 

Definition at line 155 of file push_receiver.cc.

References NR::createNR().

00157 {
00158   last_seq_recv_ = 0;
00159   num_msg_recv_ = 0;
00160   first_msg_recv_ = -1;
00161 
00162   mr_ = new PushReceiverReceive(this);
00163 
00164 #ifndef NS_DIFFUSION
00165   parseCommandLine(argc, argv);
00166   dr_ = NR::createNR(diffusion_port_);
00167 #endif // !NS_DIFFUSION
00168 }

Here is the call graph for this function:


Member Function Documentation

void DiffApp::parseCommandLine int  argc,
char **  argv
[protected, inherited]
 

Definition at line 59 of file diffapp.cc.

References DiffApp::config_file_, DEBUG_ALWAYS, DEFAULT_DIFFUSION_PORT, DiffPrint(), DiffApp::diffusion_port_, global_debug_level, optarg, u_int16_t, and DiffApp::usage().

Referenced by GeoRoutingFilter::GeoRoutingFilter(), GradientFilter::GradientFilter(), PingSenderApp::PingSenderApp(), PushSenderApp::PushSenderApp(), and SrcRtFilter::SrcRtFilter().

00060 {
00061   u_int16_t diff_port = DEFAULT_DIFFUSION_PORT;
00062   int debug_level;
00063   int opt;
00064 
00065   config_file_ = NULL;
00066   opterr = 0;
00067 
00068   while (1){
00069     opt = getopt(argc, argv, "f:hd:p:");
00070     switch (opt){
00071 
00072     case 'p':
00073 
00074       diff_port = (u_int16_t) atoi(optarg);
00075       if ((diff_port < 1024) || (diff_port >= 65535)){
00076         DiffPrint(DEBUG_ALWAYS, "Error: Diffusion port must be between 1024 and 65535 !\n");
00077         exit(-1);
00078       }
00079 
00080       break;
00081 
00082     case 'h':
00083 
00084       usage(argv[0]);
00085 
00086       break;
00087 
00088     case 'd':
00089 
00090       debug_level = atoi(optarg);
00091 
00092       if (debug_level < 1 || debug_level > 10){
00093         DiffPrint(DEBUG_ALWAYS, "Error: Debug level outside range or missing !\n");
00094         usage(argv[0]);
00095       }
00096 
00097       global_debug_level = debug_level;
00098 
00099       break;
00100 
00101     case 'f':
00102 
00103       if (!strncasecmp(optarg, "-", 1)){
00104         DiffPrint(DEBUG_ALWAYS, "Error: Parameter missing !\n");
00105         usage(argv[0]);
00106       }
00107 
00108       config_file_ = strdup(optarg);
00109 
00110       break;
00111 
00112     case '?':
00113 
00114       DiffPrint(DEBUG_ALWAYS,
00115                 "Error: %c isn't a valid option or its parameter is missing !\n", optopt);
00116       usage(argv[0]);
00117 
00118       break;
00119 
00120     case ':':
00121 
00122       DiffPrint(DEBUG_ALWAYS, "Parameter missing !\n");
00123       usage(argv[0]);
00124 
00125       break;
00126 
00127     }
00128 
00129     if (opt == -1)
00130       break;
00131   }
00132 
00133   diffusion_port_ = diff_port;
00134 }

Here is the call graph for this function:

void PushReceiverApp::recv NRAttrVec data,
NR::handle  my_handle
 

Definition at line 51 of file push_receiver.cc.

References AppCounterAttr, DEBUG_ALWAYS, DiffPrint(), first_msg_recv_, GetTime(), NRSimpleAttribute< T >::getVal(), last_seq_recv_, num_msg_recv_, PrintAttrs(), EventTime::seconds_, TimeAttr, and EventTime::useconds_.

Referenced by PushReceiverReceive::recv().

00052 {
00053   NRSimpleAttribute<int> *counterAttr = NULL;
00054   NRSimpleAttribute<void *> *timeAttr = NULL;
00055   EventTime *probe_event;
00056   long delay_seconds;
00057   long delay_useconds;
00058   float total_delay;
00059   struct timeval tmv;
00060 
00061   GetTime(&tmv);
00062 
00063   counterAttr = AppCounterAttr.find(data);
00064   timeAttr = TimeAttr.find(data);
00065 
00066   if (!counterAttr || !timeAttr){
00067     DiffPrint(DEBUG_ALWAYS, "Received a BAD packet !\n");
00068     PrintAttrs(data);
00069     return;
00070   }
00071 
00072   // Calculate latency
00073   probe_event = (EventTime *) timeAttr->getVal();
00074   delay_seconds = tmv.tv_sec;
00075   delay_useconds = tmv.tv_usec;
00076 
00077   if ((delay_seconds < probe_event->seconds_) ||
00078       ((delay_seconds == probe_event->seconds_) &&
00079        (delay_useconds < probe_event->useconds_))){
00080     // Time's not synchronized
00081     delay_seconds = -1;
00082     delay_useconds = 0;
00083     DiffPrint(DEBUG_ALWAYS, "Error calculating delay !\n");
00084   }
00085   else{
00086     delay_seconds = delay_seconds - probe_event->seconds_;
00087     if (delay_useconds < probe_event->useconds_){
00088       delay_seconds--;
00089       delay_useconds = delay_useconds + 1000000;
00090     }
00091     delay_useconds = delay_useconds - probe_event->useconds_;
00092   }
00093   total_delay = (float) (1.0 * delay_seconds) + ((float) delay_useconds / 1000000.0);
00094 
00095   // Check if this is the first message received
00096   if (first_msg_recv_ < 0){
00097     first_msg_recv_ = counterAttr->getVal();
00098   }
00099 
00100   // Print output message
00101   if (last_seq_recv_ >= 0){
00102     if (counterAttr->getVal() < last_seq_recv_){
00103       // Multiple sources detected, disabling statistics
00104       last_seq_recv_ = -1;
00105       DiffPrint(DEBUG_ALWAYS, "Received data %d, total latency = %f!\n",
00106                 counterAttr->getVal(), total_delay);
00107     }
00108     else{
00109       last_seq_recv_ = counterAttr->getVal();
00110       num_msg_recv_++;
00111       DiffPrint(DEBUG_ALWAYS, "Received data: %d, total latency = %f, %% messages received: %f !\n",
00112                 last_seq_recv_, total_delay,
00113                 (float) ((num_msg_recv_ * 100.00) /
00114                          ((last_seq_recv_ - first_msg_recv_) + 1)));
00115     }
00116   }
00117   else{
00118     DiffPrint(DEBUG_ALWAYS, "Received data %d, total latency = %f !\n",
00119               counterAttr->getVal(), total_delay);
00120   }
00121 }

Here is the call graph for this function:

void PushReceiverApp::run  )  [virtual]
 

Implements DiffApp.

Definition at line 140 of file push_receiver.cc.

References setupSubscription(), and subHandle_.

Referenced by main().

00141 {
00142   subHandle_ = setupSubscription();
00143 
00144 #ifndef NS_DIFFUSION
00145   // Do nothing
00146   while (1){
00147     sleep(1000);
00148   }
00149 #endif // !NS_DIFFUSION
00150 }

Here is the call graph for this function:

handle PushReceiverApp::setupSubscription  )  [private]
 

Definition at line 123 of file push_receiver.cc.

References ClearAttrs(), DiffApp::dr_, NRAttribute::EQ, handle, NRAttribute::INTEREST_CLASS, NRAttribute::IS, LatitudeAttr, LongitudeAttr, mr_, NRAttribute::NODE_LOCAL_SCOPE, NRClassAttr, NRScopeAttr, NR::subscribe(), and TargetAttr.

Referenced by run().

00124 {
00125   NRAttrVec attrs;
00126 
00127   attrs.push_back(NRClassAttr.make(NRAttribute::IS, NRAttribute::INTEREST_CLASS));
00128   attrs.push_back(NRScopeAttr.make(NRAttribute::IS, NRAttribute::NODE_LOCAL_SCOPE));
00129   attrs.push_back(LatitudeAttr.make(NRAttribute::IS, 60.00));
00130   attrs.push_back(LongitudeAttr.make(NRAttribute::IS, 54.00));
00131   attrs.push_back(TargetAttr.make(NRAttribute::EQ, "F117A"));
00132 
00133   handle h = dr_->subscribe(&attrs, mr_);
00134 
00135   ClearAttrs(&attrs);
00136 
00137   return h;
00138 }

Here is the call graph for this function:

void DiffApp::usage char *  s  )  [protected, inherited]
 

Definition at line 49 of file diffapp.cc.

References DEBUG_ALWAYS, and DiffPrint().

Referenced by DiffApp::parseCommandLine().

00049                           {
00050   DiffPrint(DEBUG_ALWAYS, "Usage: %s [-d debug] [-p port] [-f file] [-h]\n\n", s);
00051   DiffPrint(DEBUG_ALWAYS, "\t-d - Sets debug level (0-10)\n");
00052   DiffPrint(DEBUG_ALWAYS, "\t-p - Uses port 'port' to talk to diffusion\n");
00053   DiffPrint(DEBUG_ALWAYS, "\t-f - Specifies a config file\n");
00054   DiffPrint(DEBUG_ALWAYS, "\t-h - Prints this information\n");
00055   DiffPrint(DEBUG_ALWAYS, "\n");
00056   exit(0);
00057 }

Here is the call graph for this function:


Member Data Documentation

char* DiffApp::config_file_ [protected, inherited]
 

Definition at line 57 of file diffapp.hh.

Referenced by DiffApp::parseCommandLine().

u_int16_t DiffApp::diffusion_port_ [protected, inherited]
 

Definition at line 56 of file diffapp.hh.

Referenced by GeoRoutingFilter::GeoRoutingFilter(), GradientFilter::GradientFilter(), DiffApp::parseCommandLine(), PingSenderApp::PingSenderApp(), PushSenderApp::PushSenderApp(), and SrcRtFilter::SrcRtFilter().

NR* DiffApp::dr_ [protected, inherited]
 

Definition at line 55 of file diffapp.hh.

Referenced by GeoRoutingFilter::beaconTimeout(), GeoRoutingFilter::broadcastHeuristicValue(), GradientFilter::forwardData(), GradientFilter::forwardExploratoryData(), GradientFilter::forwardPushExploratoryData(), GeoRoutingFilter::GeoRoutingFilter(), GeoRoutingFilter::getNodeLocation(), GradientFilter::GradientFilter(), GradientFilter::interestTimeout(), GradientFilter::messageTimeout(), GeoRoutingFilter::messageTimeout(), PingSenderApp::PingSenderApp(), GeoRoutingFilter::postProcessFilter(), GeoRoutingFilter::preProcessFilter(), SrcRtFilter::ProcessMessage(), GradientFilter::processNewMessage(), PushSenderApp::PushSenderApp(), TagFilter::recv(), SrcRtFilter::recv(), LogFilter::recv(), GradientFilter::reinforcementTimeout(), PushSenderApp::run(), PingSenderApp::run(), GeoRoutingFilter::run(), GradientFilter::sendInterest(), GeoRoutingFilter::sendNeighborRequest(), GradientFilter::sendPositiveReinforcement(), TagFilter::setupFilter(), SrcRtFilter::setupFilter(), LogFilter::setupFilter(), GradientFilter::setupFilter(), GeoRoutingFilter::setupPostFilter(), GeoRoutingFilter::setupPreFilter(), PushSenderApp::setupPublication(), PingSenderApp::setupPublication(), setupSubscription(), PingSenderApp::setupSubscription(), PingReceiverApp::setupSubscription(), and SrcRtFilter::SrcRtFilter().

int PushReceiverApp::first_msg_recv_ [private]
 

Definition at line 54 of file push_receiver.hh.

Referenced by recv().

int PushReceiverApp::last_seq_recv_ [private]
 

Definition at line 52 of file push_receiver.hh.

Referenced by recv().

PushReceiverReceive* PushReceiverApp::mr_ [private]
 

Definition at line 48 of file push_receiver.hh.

Referenced by setupSubscription().

int PushReceiverApp::num_msg_recv_ [private]
 

Definition at line 53 of file push_receiver.hh.

Referenced by recv().

handle PushReceiverApp::subHandle_ [private]
 

Definition at line 49 of file push_receiver.hh.

Referenced by run().


The documentation for this class was generated from the following files:
Generated on Tue Apr 20 13:09:48 2004 for NS2.26SourcesOriginal by doxygen 1.3.3