00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "push_sender.hh"
00044 #include <unistd.h>
00045
00046 #ifdef NS_DIFFUSION
00047 static class PushSenderAppClass : public TclClass {
00048 public:
00049 PushSenderAppClass() : TclClass("Application/DiffApp/PushSender") {}
00050 TclObject* create(int , const char*const*) {
00051 return(new PushSenderApp());
00052 }
00053 } class_ping_sender;
00054
00055 void PushSendDataTimer::expire(Event *e) {
00056 a_->send();
00057 }
00058
00059 void PushSenderApp::send()
00060 {
00061 struct timeval tmv;
00062 int retval;
00063
00064
00065 GetTime(&tmv);
00066 lastEventTime_->seconds_ = tmv.tv_sec;
00067 lastEventTime_->useconds_ = tmv.tv_usec;
00068
00069
00070 DiffPrint(DEBUG_ALWAYS, "Node%d: Sending Data %d\n", ((DiffusionRouting *)dr_)->getNodeId(), last_seq_sent_);
00071 retval = dr_->send(pubHandle_, &data_attr_);
00072
00073
00074 last_seq_sent_++;
00075 counterAttr_->setVal(last_seq_sent_);
00076
00077
00078 sdt_.resched(SEND_DATA_INTERVAL);
00079 }
00080
00081 int PushSenderApp::command(int argc, const char*const* argv) {
00082 if (argc == 2) {
00083 if (strcmp(argv[1], "publish") == 0) {
00084 run();
00085 return TCL_OK;
00086 }
00087 }
00088 return DiffApp::command(argc, argv);
00089 }
00090 #endif // NS_DIFFUSION
00091
00092 handle PushSenderApp::setupPublication()
00093 {
00094 NRAttrVec attrs;
00095
00096 attrs.push_back(NRClassAttr.make(NRAttribute::IS, NRAttribute::DATA_CLASS));
00097 attrs.push_back(NRScopeAttr.make(NRAttribute::IS, NRAttribute::GLOBAL_SCOPE));
00098 attrs.push_back(LatitudeAttr.make(NRAttribute::LE, 70.00));
00099 attrs.push_back(LatitudeAttr.make(NRAttribute::GT, 50.00));
00100 attrs.push_back(LongitudeAttr.make(NRAttribute::LE, 85.00));
00101 attrs.push_back(LongitudeAttr.make(NRAttribute::GT, 50.00));
00102 attrs.push_back(TargetAttr.make(NRAttribute::IS, "F117A"));
00103
00104 handle h = dr_->publish(&attrs);
00105
00106 ClearAttrs(&attrs);
00107
00108 return h;
00109 }
00110
00111 void PushSenderApp::run()
00112 {
00113 struct timeval tmv;
00114 #ifndef NS_DIFFUSION
00115 int retval;
00116 #endif // !NS_DIFFUSION
00117
00118 #ifdef INTERACTIVE
00119 char input;
00120 fd_set FDS;
00121 #endif // INTERATIVE
00122
00123
00124 pubHandle_ = setupPublication();
00125
00126
00127 GetTime(&tmv);
00128 lastEventTime_ = new EventTime;
00129 lastEventTime_->seconds_ = tmv.tv_sec;
00130 lastEventTime_->useconds_ = tmv.tv_usec;
00131 timeAttr_ = TimeAttr.make(NRAttribute::IS, (void *) &lastEventTime_,
00132 sizeof(EventTime));
00133 data_attr_.push_back(timeAttr_);
00134
00135
00136 delete lastEventTime_;
00137 lastEventTime_ = (EventTime *) timeAttr_->getVal();
00138
00139
00140 counterAttr_ = AppCounterAttr.make(NRAttribute::IS, last_seq_sent_);
00141 data_attr_.push_back(counterAttr_);
00142
00143 #ifndef NS_DIFFUSION
00144
00145 while(1){
00146 #ifdef INTERACTIVE
00147 FD_SET(0, &FDS);
00148 fprintf(stdout, "Press <Enter> to send a ping probe...");
00149 fflush(NULL);
00150 select(1, &FDS, NULL, NULL, NULL);
00151 input = getc(stdin);
00152 #else
00153 sleep(5);
00154 #endif // INTERACTIVE
00155
00156
00157 GetTime(&tmv);
00158 lastEventTime_->seconds_ = tmv.tv_sec;
00159 lastEventTime_->useconds_ = tmv.tv_usec;
00160
00161
00162 DiffPrint(DEBUG_ALWAYS, "Sending Data %d\n", last_seq_sent_);
00163 retval = dr_->send(pubHandle_, &data_attr_);
00164
00165
00166 last_seq_sent_++;
00167 counterAttr_->setVal(last_seq_sent_);
00168 }
00169 #else
00170 send();
00171 #endif // NS_DIFFUSION
00172 }
00173
00174 #ifdef NS_DIFFUSION
00175 PushSenderApp::PushSenderApp() : sdt_(this)
00176 #else
00177 PushSenderApp::PushSenderApp(int argc, char **argv)
00178 #endif
00179 {
00180 last_seq_sent_ = 0;
00181
00182 #ifndef NS_DIFFUSION
00183 parseCommandLine(argc, argv);
00184 dr_ = NR::createNR(diffusion_port_);
00185 #endif // NS_DIFFUSION
00186 }
00187
00188 #ifndef NS_DIFFUSION
00189 int main(int argc, char **argv)
00190 {
00191 PushSenderApp *app;
00192
00193 app = new PushSenderApp(argc, argv);
00194 app->run();
00195
00196 return 0;
00197 }
00198 #endif // NS_DIFFUSION