Hi all, .i have created two new applications named packet1_sender.cc & packet1_receiver.cc after creating the requisite header files.but when used in a tcl program,the following error occurs:
invalid command name "Application/DiffApp/Packet1Sender" while executing "Application/DiffApp/Packet1Sender create _o86 " invoked from within "catch "$className create $o $args" msg" (procedure "new" line 3) invoked from within "new Application/DiffApp/Packet1Sender" invoked from within "set src_(0) [new Application/DiffApp/Packet1Sender]" (file "simplediffusion2.tcl" line 190) please help.i am attaching the packet1 files.please have a look.thanks in advance. -aritra.
#include "packet1_receiver.hh" #ifdef NS_DIFFUSION static class Packet1ReceiverAppClass : public TclClass { public: Packet1ReceiverAppClass() : TclClass("Application/DiffApp/Packet1Receiver") {} TclObject* create(int , const char*const* ) { return(new Packet1ReceiverApp()); } } class_packet1_receiver; int Packet1ReceiverApp::command(int argc, const char*const* argv) { if (argc == 2) { if (strcmp(argv[1], "subscribe") == 0) { run(); return TCL_OK; } } return DiffApp::command(argc, argv); } #endif // NS_DIFFUSION void Packet1ReceiverReceive::recv(NRAttrVec *data, NR::handle my_handle) { app_->recv(data, my_handle); } void Packet1ReceiverApp::recv(NRAttrVec *data, NR::handle my_handle) { NRSimpleAttribute<int> *counterAttr = NULL; NRSimpleAttribute<void *> *timeAttr = NULL; EventTime *probe_event; long delay_seconds; long delay_useconds; float total_delay; struct timeval tmv; GetTime(&tmv); counterAttr = AppCounterAttr.find(data); timeAttr = TimeAttr.find(data); if (!counterAttr || !timeAttr){ DiffPrint(DEBUG_ALWAYS, "Received a BAD packet !\n"); PrintAttrs(data); return; } // Calculate latency probe_event = (EventTime *) timeAttr->getVal(); delay_seconds = tmv.tv_sec; delay_useconds = tmv.tv_usec; if ((delay_seconds < probe_event->seconds_) || ((delay_seconds == probe_event->seconds_) && (delay_useconds < probe_event->useconds_))){ // Time's not synchronized delay_seconds = -1; delay_useconds = 0; DiffPrint(DEBUG_ALWAYS, "Error calculating delay !\n"); } else{ delay_seconds = delay_seconds - probe_event->seconds_; if (delay_useconds < probe_event->useconds_){ delay_seconds--; delay_useconds = delay_useconds + 1000000; } delay_useconds = delay_useconds - probe_event->useconds_; } total_delay = (float) (1.0 * delay_seconds) + ((float) delay_useconds / 1000000.0); // Check if this is the first message received if (first_msg_recv_ < 0){ first_msg_recv_ = counterAttr->getVal(); } // Print output message if (last_seq_recv_ >= 0){ if (counterAttr->getVal() < last_seq_recv_){ // Multiple sources detected, disabling statistics rp = 1; last_seq_recv_ = -1; DiffPrint(DEBUG_ALWAYS, "Received data %d, total latency = %f!\n", counterAttr->getVal(), total_delay); } else{ last_seq_recv_ = counterAttr->getVal(); num_msg_recv_++; DiffPrint(DEBUG_ALWAYS, "Received data: %d, total latency = %f, %% messages received: %f !\n", last_seq_recv_, total_delay, (float) ((num_msg_recv_ * 100.00) / ((last_seq_recv_ - first_msg_recv_) + 1))); } } else{ DiffPrint(DEBUG_ALWAYS, "Received data %d, total latency = %f !\n", counterAttr->getVal(), total_delay); } } handle Packet1ReceiverApp::setupSubscription() { NRAttrVec attrs; path_ = 0; attrs.push_back(NRClassAttr.make(NRAttribute::IS, NRAttribute::INTEREST_CLASS)); attrs.push_back(LatitudeAttr.make(NRAttribute::GT, 54.78)); attrs.push_back(LongitudeAttr.make(NRAttribute::LE, 87.32)); attrs.push_back(TargetAttr.make(NRAttribute::IS, "F117A")); handle h = dr_->subscribe(&attrs, mr_); ClearAttrs(&attrs); return h; } void Packet1ReceiverApp::run() { subHandle_ = setupSubscription(); #ifndef NS_DIFFUSION // Do nothing while (1){ sleep(1000); } #endif // !NS_DIFFUSION } #ifdef NS_DIFFUSION Packet1ReceiverApp::Packet1ReceiverApp() #else Packet1ReceiverApp::Packet1ReceiverApp(int argc, char **argv) #endif // NS_DIFFUSION { last_seq_recv_ = 0; num_msg_recv_ = 0; first_msg_recv_ = -1; mr_ = new Packet1ReceiverReceive(this); #ifndef NS_DIFFUSION parseCommandLine(argc, argv); dr_ = NR::createNR(diffusion_port_); #endif // !NS_DIFFUSION } #ifndef NS_DIFFUSION int main(int argc, char **argv) { Packet1ReceiverApp *app; app = new Packet1ReceiverApp(argc, argv); app->run(); return 0; } #endif // !NS_DIFFUSION
#include "packet1_sender.hh" #include <unistd.h> #ifdef NS_DIFFUSION static class Packet1SenderAppClass : public TclClass { public: Packet1SenderAppClass() : TclClass("Application/DiffApp/Packet1Sender") {} TclObject* create(int , const char*const*) { return(new Packet1SenderApp()); } } class_packet1_sender; void Packet1SendDataTimer::expire(Event *e) { a_->send(); } void Packet1SenderApp::send() { struct timeval tmv; int retval; // Send data if we have active subscriptions if (num_subscriptions_ > 0){ // Update time in the packet GetTime(&tmv); lastEventTime_->seconds_ = tmv.tv_sec; lastEventTime_->useconds_ = tmv.tv_usec; // Send data probe DiffPrint(DEBUG_ALWAYS, "Sending Data %d\n", ((DiffusionRouting *)dr_)->getNodeId(), last_seq_sent_); retval = dr_->send(pubHandle_, &data_attr_); // Update counter last_seq_sent_++; counterAttr_->setVal(last_seq_sent_); } // re-schedule the timer sdt_.resched(SEND_DATA_INTERVAL); } int Packet1SenderApp::command(int argc, const char*const* argv) { if (argc == 2) { if (strcmp(argv[1], "publish") == 0) { run(); return TCL_OK; } } return DiffApp::command(argc, argv); } #endif // NS_DIFFUSION void Packet1SenderReceive::recv(NRAttrVec *data, NR::handle my_handle) { app_->recv(data, my_handle); } void Packet1SenderApp::recv(NRAttrVec *data, NR::handle my_handle) { NRSimpleAttribute<int> *nrclass = NULL; nrclass = NRClassAttr.find(data); if (!nrclass){ DiffPrint(DEBUG_ALWAYS, "Received a BAD packet !\n"); return; } switch (nrclass->getVal()){ case NRAttribute::INTEREST_CLASS: DiffPrint(DEBUG_ALWAYS, "Received an Interest message !\n"); num_subscriptions_++; break; case NRAttribute::DISINTEREST_CLASS: DiffPrint(DEBUG_ALWAYS, "Received a Disinterest message !\n"); num_subscriptions_--; break; default: DiffPrint(DEBUG_ALWAYS, "Received an unknown message (%d)!\n", nrclass->getVal()); break; } } handle Packet1SenderApp::setupSubscription() { NRAttrVec attrs; path_ = 0; attrs.push_back(NRClassAttr.make(NRAttribute::NE, NRAttribute::DATA_CLASS)); attrs.push_back(NRScopeAttr.make(NRAttribute::IS, NRAttribute::NODE_LOCAL_SCOPE)); attrs.push_back(TargetAttr.make(NRAttribute::EQ, "F117A")); attrs.push_back(LatitudeAttr.make(NRAttribute::IS, 60.00)); attrs.push_back(LongitudeAttr.make(NRAttribute::IS, 54.00)); handle h = dr_->subscribe(&attrs, mr_); ClearAttrs(&attrs); return h; } handle Packet1SenderApp::setupPublication() { NRAttrVec attrs; path_ = 1; attrs.push_back(NRClassAttr.make(NRAttribute::IS, NRAttribute::DATA_CLASS)); attrs.push_back(LatitudeAttr.make(NRAttribute::IS, 60.00)); attrs.push_back(LongitudeAttr.make(NRAttribute::IS, 54.00)); attrs.push_back(TargetAttr.make(NRAttribute::IS, "F117A")); handle h = dr_->publish(&attrs); ClearAttrs(&attrs); return h; } void Packet1SenderApp::run() { struct timeval tmv; #ifndef NS_DIFFUSION int retval; #endif // !NS_DIFFUSION #ifdef INTERACTIVE char input; fd_set FDS; #endif // INTERATIVE // Setup publication and subscription subHandle_ = setupSubscription(); pubHandle_ = setupPublication(); // Create time attribute GetTime(&tmv); lastEventTime_ = new EventTime; lastEventTime_->seconds_ = tmv.tv_sec; lastEventTime_->useconds_ = tmv.tv_usec; timeAttr_ = TimeAttr.make(NRAttribute::IS, (void *) &lastEventTime_, sizeof(EventTime)); data_attr_.push_back(timeAttr_); // Change pointer to point to attribute's payload delete lastEventTime_; lastEventTime_ = (EventTime *) timeAttr_->getVal(); // Create counter attribute counterAttr_ = AppCounterAttr.make(NRAttribute::IS, last_seq_sent_); data_attr_.push_back(counterAttr_); #ifndef NS_DIFFUSION // Main thread will send ping probes while(1){ #ifdef INTERACTIVE FD_SET(0, &FDS); fprintf(stdout, "Press <Enter> to send a ping probe..."); fflush(NULL); select(1, &FDS, NULL, NULL, NULL); input = getc(stdin); #else sleep(SEND_DATA_INTERVAL); #endif // INTERACTIVE // Send data packet if we have active subscriptions if (num_subscriptions_ > 0){ // Update time in the packet GetTime(&tmv); lastEventTime_->seconds_ = tmv.tv_sec; lastEventTime_->useconds_ = tmv.tv_usec; // Send data probe DiffPrint(DEBUG_ALWAYS, "Sending Data %d\n", ((DiffusionRouting *)dr_)->getNodeId(), last_seq_sent_); retval = dr_->send(pubHandle_, &data_attr_); // Update counter last_seq_sent_++; counterAttr_->setVal(last_seq_sent_); } } #else send(); #endif // !NS_DIFFUSION } #ifdef NS_DIFFUSION Packet1SenderApp::Packet1SenderApp() : sdt_(this) #else Packet1SenderApp::Packet1SenderApp(int argc, char **argv) #endif // NS_DIFFUSION { last_seq_sent_ = 0; num_subscriptions_ = 0; mr_ = new Packet1SenderReceive(this); #ifndef NS_DIFFUSION parseCommandLine(argc, argv); dr_ = NR::createNR(diffusion_port_); #endif // NS_DIFFUSION } #ifndef NS_DIFFUSION int main(int argc, char **argv) { Packet1SenderApp *app; app = new Packet1SenderApp(argc, argv); app->run(); return 0; } #endif // NS_DIFFUSION