#include <gear_sender.hh>
Inheritance diagram for GearSenderApp:


Definition at line 67 of file gear_sender.hh.
Public Member Functions | |
| GearSenderApp (int argc, char **argv) | |
| void | recv (NRAttrVec *data, NR::handle my_handle) |
| void | run () |
| virtual | ~GearSenderApp () |
Protected Attributes | |
| char * | config_file_ |
| u_int16_t | diffusion_port_ |
| NR * | dr_ |
Private Member Functions | |
| void | parseCommandLine (int argc, char **argv) |
| void | readGeographicCoordinates () |
| handle | setupPublication () |
| handle | setupSubscription () |
| void | usage (char *s) |
Private Attributes | |
| NRSimpleAttribute< int > * | counterAttr_ |
| NRAttrVec | data_attr_ |
| int | last_seq_sent_ |
| EventTime * | lastEventTime_ |
| float | lat_max_ |
| float | lat_min_ |
| float | lat_pt_ |
| float | long_max_ |
| float | long_min_ |
| float | long_pt_ |
| GearSenderReceive * | mr_ |
| int | num_subscriptions_ |
| handle | pubHandle_ |
| handle | subHandle_ |
| NRSimpleAttribute< void * > * | timeAttr_ |
| bool | using_points_ |
| bool | using_push_ |
|
||||||||||||
|
NS_DIFFUSION Definition at line 444 of file gear_sender.cc. References NR::createNR(). 00446 { 00447 last_seq_sent_ = 0; 00448 num_subscriptions_ = 0; 00449 00450 mr_ = new GearSenderReceive(this); 00451 00452 #ifndef NS_DIFFUSION 00453 parseCommandLine(argc, argv); 00454 readGeographicCoordinates(); 00455 dr_ = NR::createNR(diffusion_port_); 00456 #endif 00457 }
Here is the call graph for this function: ![]() |
|
|
Definition at line 77 of file gear_sender.hh.
|
|
||||||||||||
|
Reimplemented from DiffApp. Definition at line 305 of file gear_sender.cc. References DiffApp::config_file_, DEBUG_ALWAYS, DEFAULT_DIFFUSION_PORT, DiffPrint(), DiffApp::diffusion_port_, global_debug_level, optarg, usage(), using_points_, and using_push_. 00306 { 00307 u_int16_t diff_port = DEFAULT_DIFFUSION_PORT; 00308 int debug_level; 00309 int opt; 00310 00311 config_file_ = NULL; 00312 using_points_ = true; 00313 using_push_ = false; 00314 opterr = 0; 00315 00316 while (1){ 00317 opt = getopt(argc, argv, "srhd:p:"); 00318 switch (opt){ 00319 00320 case 'p': 00321 00322 diff_port = (u_int16_t) atoi(optarg); 00323 if ((diff_port < 1024) || (diff_port >= 65535)){ 00324 DiffPrint(DEBUG_ALWAYS, "Error: Diffusion port must be between 1024 and 65535 !\n"); 00325 exit(-1); 00326 } 00327 00328 break; 00329 00330 case 'h': 00331 00332 usage(argv[0]); 00333 00334 break; 00335 00336 case 'd': 00337 00338 debug_level = atoi(optarg); 00339 00340 if (debug_level < 1 || debug_level > 10){ 00341 DiffPrint(DEBUG_ALWAYS, "Error: Debug level outside range or missing !\n"); 00342 usage(argv[0]); 00343 } 00344 00345 global_debug_level = debug_level; 00346 00347 break; 00348 00349 case 's': 00350 00351 using_push_ = true; 00352 00353 break; 00354 00355 case 'r': 00356 00357 using_points_ = false; 00358 00359 break; 00360 00361 case '?': 00362 00363 DiffPrint(DEBUG_ALWAYS, 00364 "Error: %c isn't a valid option or its parameter is missing !\n", optopt); 00365 usage(argv[0]); 00366 00367 break; 00368 00369 case ':': 00370 00371 DiffPrint(DEBUG_ALWAYS, "Parameter missing !\n"); 00372 usage(argv[0]); 00373 00374 break; 00375 00376 } 00377 00378 if (opt == -1) 00379 break; 00380 } 00381 00382 diffusion_port_ = diff_port; 00383 }
Here is the call graph for this function: ![]() |
|
|
Definition at line 385 of file gear_sender.cc. References DEBUG_ALWAYS, DiffPrint(), lat_max_, lat_min_, lat_pt_, long_max_, long_min_, long_pt_, using_points_, and using_push_. 00386 { 00387 char *gear_coord_env; 00388 00389 if (using_points_ || !using_push_){ 00390 // Read latitude coordinate 00391 gear_coord_env = getenv("lat_pt"); 00392 if (!gear_coord_env){ 00393 DiffPrint(DEBUG_ALWAYS, "Cannot read lat_pt !\n"); 00394 exit(-1); 00395 } 00396 lat_pt_ = atoi(gear_coord_env); 00397 00398 // Read longitude coordinate 00399 gear_coord_env = getenv("long_pt"); 00400 if (!gear_coord_env){ 00401 DiffPrint(DEBUG_ALWAYS, "Cannot read long_pt !\n"); 00402 exit(-1); 00403 } 00404 long_pt_ = atoi(gear_coord_env); 00405 } 00406 else{ 00407 // Read latitude_min value 00408 gear_coord_env = getenv("lat_min"); 00409 if (!gear_coord_env){ 00410 DiffPrint(DEBUG_ALWAYS, "Cannot read lat_min !\n"); 00411 exit(-1); 00412 } 00413 lat_min_ = atoi(gear_coord_env); 00414 00415 // Read latitude_max value 00416 gear_coord_env = getenv("lat_max"); 00417 if (!gear_coord_env){ 00418 DiffPrint(DEBUG_ALWAYS, "Cannot read lat_max !\n"); 00419 exit(-1); 00420 } 00421 lat_max_ = atoi(gear_coord_env); 00422 00423 // Read longitude_min value 00424 gear_coord_env = getenv("long_min"); 00425 if (!gear_coord_env){ 00426 DiffPrint(DEBUG_ALWAYS, "Cannot read long_min !\n"); 00427 exit(-1); 00428 } 00429 long_min_ = atoi(gear_coord_env); 00430 00431 // Read longitude_max value 00432 gear_coord_env = getenv("long_max"); 00433 if (!gear_coord_env){ 00434 DiffPrint(DEBUG_ALWAYS, "Cannot read long_max !\n"); 00435 exit(-1); 00436 } 00437 long_max_ = atoi(gear_coord_env); 00438 } 00439 }
Here is the call graph for this function: ![]() |
|
||||||||||||
|
Definition at line 133 of file gear_sender.cc. References DEBUG_ALWAYS, DiffPrint(), NRAttribute::DISINTEREST_CLASS, NRSimpleAttribute< T >::getVal(), NRAttribute::INTEREST_CLASS, NRClassAttr, and num_subscriptions_. Referenced by GearSenderReceive::recv(). 00134 { 00135 NRSimpleAttribute<int> *nrclass = NULL; 00136 00137 nrclass = NRClassAttr.find(data); 00138 00139 if (!nrclass){ 00140 DiffPrint(DEBUG_ALWAYS, "Received a BAD packet !\n"); 00141 return; 00142 } 00143 00144 switch (nrclass->getVal()){ 00145 00146 case NRAttribute::INTEREST_CLASS: 00147 00148 DiffPrint(DEBUG_ALWAYS, "Received an Interest message !\n"); 00149 num_subscriptions_++; 00150 break; 00151 00152 case NRAttribute::DISINTEREST_CLASS: 00153 00154 DiffPrint(DEBUG_ALWAYS, "Received a Disinterest message !\n"); 00155 num_subscriptions_--; 00156 break; 00157 00158 default: 00159 00160 DiffPrint(DEBUG_ALWAYS, "Received an unknown message (%d)!\n", nrclass->getVal()); 00161 break; 00162 00163 } 00164 }
Here is the call graph for this function: ![]() |
|
|
Implements DiffApp. Definition at line 226 of file gear_sender.cc. References counterAttr_, data_attr_, DEBUG_ALWAYS, DiffPrint(), DiffApp::dr_, GearCounterAttr, GearTimeAttr, GetTime(), NRSimpleAttribute< void * >::getVal(), NRAttribute::IS, last_seq_sent_, lastEventTime_, num_subscriptions_, pubHandle_, EventTime::seconds_, NR::send(), SEND_DATA_INTERVAL, setupPublication(), setupSubscription(), NRSimpleAttribute< T >::setVal(), subHandle_, timeAttr_, EventTime::useconds_, and using_push_. Referenced by main(). 00227 { 00228 struct timeval tmv; 00229 #ifndef NS_DIFFUSION 00230 int retval; 00231 #endif // !NS_DIFFUSION 00232 00233 #ifdef INTERACTIVE 00234 char input; 00235 fd_set FDS; 00236 #endif // INTERATIVE 00237 00238 // Setup publication and subscription 00239 if (!using_push_) 00240 subHandle_ = setupSubscription(); 00241 pubHandle_ = setupPublication(); 00242 00243 // Create time attribute 00244 GetTime(&tmv); 00245 lastEventTime_ = new EventTime; 00246 lastEventTime_->seconds_ = tmv.tv_sec; 00247 lastEventTime_->useconds_ = tmv.tv_usec; 00248 timeAttr_ = GearTimeAttr.make(NRAttribute::IS, (void *) &lastEventTime_, 00249 sizeof(EventTime)); 00250 data_attr_.push_back(timeAttr_); 00251 00252 // Change pointer to point to attribute's payload 00253 delete lastEventTime_; 00254 lastEventTime_ = (EventTime *) timeAttr_->getVal(); 00255 00256 // Create counter attribute 00257 counterAttr_ = GearCounterAttr.make(NRAttribute::IS, last_seq_sent_); 00258 data_attr_.push_back(counterAttr_); 00259 00260 #ifndef NS_DIFFUSION 00261 // Main thread will send ping probes 00262 while(1){ 00263 #ifdef INTERACTIVE 00264 FD_SET(0, &FDS); 00265 fprintf(stdout, "Press <Enter> to send a ping probe..."); 00266 fflush(NULL); 00267 select(1, &FDS, NULL, NULL, NULL); 00268 input = getc(stdin); 00269 #else 00270 sleep(SEND_DATA_INTERVAL); 00271 #endif // INTERACTIVE 00272 00273 // Send data packet if we have active subscriptions 00274 if ((num_subscriptions_ > 0) || using_push_){ 00275 // Update time in the packet 00276 GetTime(&tmv); 00277 lastEventTime_->seconds_ = tmv.tv_sec; 00278 lastEventTime_->useconds_ = tmv.tv_usec; 00279 00280 // Send data probe 00281 DiffPrint(DEBUG_ALWAYS, "Node%d: Sending Data %d\n", ((DiffusionRouting *)dr_)->getNodeId(), last_seq_sent_); 00282 retval = dr_->send(pubHandle_, &data_attr_); 00283 00284 // Update counter 00285 last_seq_sent_++; 00286 counterAttr_->setVal(last_seq_sent_); 00287 } 00288 } 00289 #else 00290 send(); 00291 #endif // !NS_DIFFUSION 00292 }
Here is the call graph for this function: ![]() |
|
|
Definition at line 185 of file gear_sender.cc. References ClearAttrs(), NRAttribute::DATA_CLASS, DiffApp::dr_, NRAttribute::EQ, NRAttribute::GE, GearTargetAttr, NRAttribute::GLOBAL_SCOPE, NRAttribute::IS, lat_max_, lat_min_, lat_pt_, LatitudeAttr, NRAttribute::LE, long_max_, long_min_, long_pt_, LongitudeAttr, NRAttribute::NODE_LOCAL_SCOPE, NRClassAttr, NRScopeAttr, NR::publish(), using_points_, and using_push_. Referenced by run(). 00186 { 00187 NRAttrVec attrs; 00188 00189 attrs.push_back(NRClassAttr.make(NRAttribute::IS, 00190 NRAttribute::DATA_CLASS)); 00191 // Use push or pull semantics 00192 if (using_push_){ 00193 attrs.push_back(NRScopeAttr.make(NRAttribute::IS, 00194 NRAttribute::GLOBAL_SCOPE)); 00195 00196 // Insert point or region coordinates 00197 if (using_points_){ 00198 attrs.push_back(LatitudeAttr.make(NRAttribute::EQ, lat_pt_)); 00199 attrs.push_back(LongitudeAttr.make(NRAttribute::EQ, long_pt_)); 00200 } 00201 else{ 00202 attrs.push_back(LatitudeAttr.make(NRAttribute::GE, lat_min_)); 00203 attrs.push_back(LatitudeAttr.make(NRAttribute::LE, lat_max_)); 00204 attrs.push_back(LongitudeAttr.make(NRAttribute::GE, long_min_)); 00205 attrs.push_back(LongitudeAttr.make(NRAttribute::LE, long_max_)); 00206 } 00207 } 00208 else{ 00209 attrs.push_back(NRScopeAttr.make(NRAttribute::IS, 00210 NRAttribute::NODE_LOCAL_SCOPE)); 00211 00212 // Insert point coordinates 00213 attrs.push_back(LatitudeAttr.make(NRAttribute::IS, lat_pt_)); 00214 attrs.push_back(LongitudeAttr.make(NRAttribute::IS, long_pt_)); 00215 } 00216 00217 attrs.push_back(GearTargetAttr.make(NRAttribute::IS, "F117A")); 00218 00219 handle h = dr_->publish(&attrs); 00220 00221 ClearAttrs(&attrs); 00222 00223 return h; 00224 }
Here is the call graph for this function: ![]() |
|
|
Definition at line 166 of file gear_sender.cc. References ClearAttrs(), NRAttribute::DATA_CLASS, DiffApp::dr_, NRAttribute::EQ, GearTargetAttr, NRAttribute::IS, lat_pt_, LatitudeAttr, long_pt_, LongitudeAttr, mr_, NRAttribute::NE, NRAttribute::NODE_LOCAL_SCOPE, NRClassAttr, NRScopeAttr, and NR::subscribe(). Referenced by run(). 00167 { 00168 NRAttrVec attrs; 00169 00170 attrs.push_back(NRClassAttr.make(NRAttribute::NE, 00171 NRAttribute::DATA_CLASS)); 00172 attrs.push_back(NRScopeAttr.make(NRAttribute::IS, 00173 NRAttribute::NODE_LOCAL_SCOPE)); 00174 attrs.push_back(GearTargetAttr.make(NRAttribute::EQ, "F117A")); 00175 attrs.push_back(LatitudeAttr.make(NRAttribute::IS, lat_pt_)); 00176 attrs.push_back(LongitudeAttr.make(NRAttribute::IS, long_pt_)); 00177 00178 handle h = dr_->subscribe(&attrs, mr_); 00179 00180 ClearAttrs(&attrs); 00181 00182 return h; 00183 }
Here is the call graph for this function: ![]() |
|
|
Reimplemented from DiffApp. Definition at line 294 of file gear_sender.cc. References DEBUG_ALWAYS, and DiffPrint(). Referenced by parseCommandLine(). 00294 { 00295 DiffPrint(DEBUG_ALWAYS, "Usage: %s [-d debug] [-p port] [-s] [-r] [-h]\n\n", s); 00296 DiffPrint(DEBUG_ALWAYS, "\t-d - Sets debug level (0-10)\n"); 00297 DiffPrint(DEBUG_ALWAYS, "\t-p - Uses port 'port' to talk to diffusion\n"); 00298 DiffPrint(DEBUG_ALWAYS, "\t-s - Uses push semantics (default: pull)\n"); 00299 DiffPrint(DEBUG_ALWAYS, "\t-r - Uses regions (default: points)\n"); 00300 DiffPrint(DEBUG_ALWAYS, "\t-h - Prints this information\n"); 00301 DiffPrint(DEBUG_ALWAYS, "\n"); 00302 exit(0); 00303 }
Here is the call graph for this function: ![]() |
|
|
Definition at line 79 of file diffapp.hh. Referenced by parseCommandLine(), GearReceiverApp::parseCommandLine(), and DiffApp::parseCommandLine(). |
|
|
Definition at line 104 of file gear_sender.hh. Referenced by run(). |
|
|
Definition at line 102 of file gear_sender.hh. Referenced by run(). |
|
|
|
|
Definition at line 95 of file gear_sender.hh. Referenced by run(). |
|
|
Definition at line 105 of file gear_sender.hh. Referenced by run(). |
|
|
Definition at line 97 of file gear_sender.hh. Referenced by readGeographicCoordinates(), and setupPublication(). |
|
|
Definition at line 96 of file gear_sender.hh. Referenced by readGeographicCoordinates(), and setupPublication(). |
|
|
Definition at line 100 of file gear_sender.hh. Referenced by readGeographicCoordinates(), setupPublication(), and setupSubscription(). |
|
|
Definition at line 99 of file gear_sender.hh. Referenced by readGeographicCoordinates(), and setupPublication(). |
|
|
Definition at line 98 of file gear_sender.hh. Referenced by readGeographicCoordinates(), and setupPublication(). |
|
|
Definition at line 101 of file gear_sender.hh. Referenced by readGeographicCoordinates(), setupPublication(), and setupSubscription(). |
|
|
Definition at line 87 of file gear_sender.hh. Referenced by setupSubscription(). |
|
|
Definition at line 94 of file gear_sender.hh. |
|
|
Definition at line 89 of file gear_sender.hh. Referenced by run(). |
|
|
Definition at line 88 of file gear_sender.hh. Referenced by run(). |
|
|
Definition at line 103 of file gear_sender.hh. Referenced by run(). |
|
|
Definition at line 92 of file gear_sender.hh. Referenced by parseCommandLine(), readGeographicCoordinates(), and setupPublication(). |
|
|
Definition at line 93 of file gear_sender.hh. Referenced by parseCommandLine(), readGeographicCoordinates(), run(), and setupPublication(). |
1.4.6