[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ns] weird interactions




I am seeing some behavior for which i have no explaination for. I would
appreciate if someone can help.

I write a new queue and a new agent (also changed the makefile). And after
instantiating the agent, i pass that as parameter to the queue which
stores a pointer to it. All is fine till here. When a packet comes to this
queue, I do an upcall to the agent. In this upcall i try to access a
member variable of the agent, at which point the code seg faults.

I have appended both the .cc and .tcl file i am wrote. They are rather
small and simple (i tore them down to the minumum before posting). Again,
any help or directions appreciated.

thanks,
-ratul

-----------------------

trial.cc
========

#include "agent.h"
#include "queue.h"

class PushbackAgent : public Agent {

 public:
  PushbackAgent();
  int last_index_;
  
  void upcall() {
    printf("In Agent upcall\n");
    printf("Last Index = %d\n", last_index_);
  }
  
};

static class PushbackClass : public TclClass {
public:
  PushbackClass() : TclClass("Agent/Pushback") {}
  TclObject* create(int, const char*const*) {
    return (new PushbackAgent());
  }
} class_Pushback;

PushbackAgent::PushbackAgent() : Agent(PT_PING), last_index_(0) {
  bind("last_index_", &last_index_);
}


//##################### PushbackQueue #####################

class PushbackQueue: public Queue {
 public:
  PushbackQueue( const char* const);

  void enque(Packet *p);
  Packet * deque() {return NULL;}

  PushbackAgent * pushback_; 
};

static class PushbackQueueClass : public TclClass {
public:
  PushbackQueueClass() : TclClass("Queue/Pushback") {}
  TclObject * create(int argc, const char*const* argv) {
    if (argc==4) {
      printf("Missing Argument for Pushback Queue Constructor\n");
      exit(-1);
    }
    return (new PushbackQueue(argv[4]));
  }

} class_pushback_queue;

PushbackQueue::PushbackQueue(const char* const pba) {
  
  PushbackAgent * pushback_ = (PushbackAgent *)TclObject::lookup(pba);
  if (pushback_ == NULL) {
    printf("Wrong Argument for Pushback Queue Constructor\n");
    exit(-1);
  }
  printf("pushback queue instantiated %d\n",pushback_->last_index_);
}

void 
PushbackQueue::enque(Packet *p) {

  printf("In queue enque\n");
  pushback_->upcall();
}


--------------------------------------------------------

first.tcl
========

set ns [new Simulator]

set n0 [$ns node]
set n1 [$ns node]

set pushback0 [new Agent/Pushback]
$ns attach-agent $n0 $pushback0

$ns simplex-link $n0 $n1 0.5Mb 10ms Pushback $pushback0
$ns simplex-link $n1 $n0 0.5Mb 10ms DropTail

set src1 [$ns create-connection TCP $n0 TCPSink $n1 0]
set ftp1 [$src1 attach-app FTP]

$ns at 1.0 "$ftp1 start"
$ns at 20.0 "$ns halt; exit 0"
$ns run


-----------------------------------------------
output
-----

warning: no class variable Agent/Pushback::last_index_

        see tcl-object.tcl in tclcl for info about this warning.

pushback queue instantiated 0
In queue enque
In Agent upcall
Segmentation fault (core dumped)


-> so it fails at the point i try to access "last_index_".
any clues?