I have developed a new wireless application on directed diffusion and have
followed the necessary steps to integrate it into the ns code.but on
executing the command make ,it gives the following error:
Makefile:195:*** command commences before first target.Stop.
below i am attaching the files i have created for my application.
 
#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
 
#ifndef _PACKET1_RECEIVER_HH_
#define _PACKET1_RECEIVER_HH_

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H

#include "ping.hh"

class Packet1ReceiverReceive;

class Packet1ReceiverApp : public DiffApp {
public:
#ifdef NS_DIFFUSION
  Packet1ReceiverApp();
  int command(int argc, const char*const* argv);
#else
  Packet1ReceiverApp(int argc, char **argv);
#endif // NS_DIFFUSION

  void recv(NRAttrVec *data, NR::handle my_handle);
  void run();

private:
  // NR Specific variables
  Packet1ReceiverReceive *mr_;
  handle subHandle_;

  // Packet1 App variables
  int last_seq_recv_;
  int num_msg_recv_;
  int first_msg_recv_;
  bool path_; //0 if query;1 if answer
  bool co; //Continuous query type
  bool ag; //Aggregate query type
  bool cp; //Complex query type
  bool rp; //Replicated query type
  handle setupSubscription();
};

class Packet1ReceiverReceive : public NR::Callback {
public:
  Packet1ReceiverReceive(Packet1ReceiverApp *app) : app_(app) {};
  void recv(NRAttrVec *data, NR::handle my_handle);

  Packet1ReceiverApp *app_;
};

#endif // !_PACKET1_RECEIVER_HH_
 
#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
 
#ifndef _PACKET1_SENDER_HH_
#define _PACKET1_SENDER_HH_

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H

#include "ping.hh"

class Packet1SenderReceive;
class Packet1SenderApp;

#define SEND_DATA_INTERVAL 5

#ifdef NS_DIFFUSION
class Packet1SendDataTimer : public TimerHandler {
  public:
  Packet1SendDataTimer(Packet1SenderApp *a) : TimerHandler() { a_ = a; }
  void expire(Event *e);
protected:
  Packet1SenderApp *a_;
};
#endif //NS_DIFFUSION

class Packet1SenderApp : public DiffApp {
public:
#ifdef NS_DIFFUSION
  Packet1SenderApp();
  int command(int argc, const char*const* argv);
  void send();
#else
  Packet1SenderApp(int argc, char **argv);
#endif // NS_DIFFUSION

  virtual ~Packet1SenderApp()
  {
    // Nothing to do
  };

  void run();
  void recv(NRAttrVec *data, NR::handle my_handle);

private:
  // NR Specific variables
  Packet1SenderReceive *mr_;
  handle subHandle_;
  handle pubHandle_;

  // Packet1 App variables
  int num_subscriptions_;
  int last_seq_sent_;
  bool path_; //0 if query;1 if answer
  bool co; //Continuous query type
  bool ag; //Aggregate query type
  bool cp; //Complex query type
  bool rp; //Replicated query type
  NRAttrVec data_attr_;
  NRSimpleAttribute<void *> *timeAttr_;
  NRSimpleAttribute<int> *counterAttr_;
  EventTime *lastEventTime_;

  handle setupSubscription();
  handle setupPublication();
#ifdef NS_DIFFUSION
  Packet1SendDataTimer sdt_;
#endif // NS_DIFFUSION
};

class Packet1SenderReceive : public NR::Callback {
public:
  Packet1SenderReceive(PingSenderApp *app) : app_(app) {};
  void recv(NRAttrVec *data, NR::handle my_handle);

  Packet1SenderApp *app_;
};

#endif // !_PACKET1_SENDER_HH_

Reply via email to