Dear All,
  I created a .cc file which actually has to broadcast the no of neighbors. For 
checking the c++ Otcl linkage i have just set the no of neighbors to be 10. I 
successfully created the .o file after doing make. I tried printing the no of 
neighbors using recv() in tcl but it dint print anything. When i ran the tcl 
script the packet is named as undefined and it is being sent at the specified 
time. I can understand that somewhere i made a logical mistake and since this 
is my first try i dont know where the actual error is.
  This is my .cc file:
  int hdr_broad::offset_broad_;
  static class BroadHeaderClass : public PacketHeaderClass {
  BroadHeaderClass() : PacketHeaderClass("PacketHeader/Broad", 
  sizeof(hdr_broad)) {
  } class_broadhdr;
  static class AntClass : public TclClass {
  AntClass() : TclClass("Agent/Ant") {}
  TclObject* create(int, const char*const*) {
  return (new AntAgent());
  } class_ant;
  AntAgent::AntAgent() : Agent(PT_ANT)
  int AntAgent::command(int argc, const char*const* argv)
  if (argc == 2) {
  if (strcmp(argv[1], "broadcast") == 0) { 
  return (TCL_OK);
  return (Agent::command(argc, argv));
  void AntAgent::recv(Packet* pkt, Handler*)
  hdr_broad* hdrb = HDR_BROAD(pkt);
  char out[100];
  sprintf(out, "%s no of neighbors is %d",hdrb->src,hdrb->no_of_neigh);
  Tcl& tcl = Tcl::instance();
  void AntAgent::broadcast_neigh()
  Packet* pkt = allocpkt();
  hdr_broad* hdrb = HDR_BROAD(pkt);
  hdrb->no_of_neigh = 10; 
  send(pkt, 0);
  The hdr_broad contains two elements: no of neighbors and the address(nsaddr_t)
  This is part of my tcl script:
  for {set i 0} {$i < $num_nodes} {incr i} {
  set a($i) [new Agent/Ant] 
  $n($i) attach $a($i) 
  Agent/Ant instproc recv {from neigh} {
  $self instvar node_
  puts "Node [$node_ id] received broadcast from $from with no of neighbors 
  $ns at 1.0 "$a(0) broadcast"
  $ns at 2.0 "$a(2) broadcast"
  $ns at 5.0 "finish"
  $ns run
  Please bear with my silly errors. Only with your guidance i can proceed with 
my project. Please tell me where i have made a mistake. Why the no of nighbors 
is not getting printed?
  Thanks in Advance

Yahoo! Messenger with Voice. PC-to-Phone calls for ridiculously low rates.

Reply via email to