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

[ns] IP_BROADCAST error: no target for slot -1



Hi,

I want to do neighbour discovery, the way I want to do it is sending a
packet to IP_BROADCAST address with ttl = 1(the way it is done in AODV). 

Here is a snippet of my tcl script

set sim0 [new Agent/Simple [$n0 id]]
$ns attach-agent $n0 $sim0

.. other nodes with the similar agent attached

$ns at 0.2 "$sim0 broadcast"

When the command function in C++ class, executes the following code
...
    cm->ptype() = PT_SIMPLE;
    ih->daddr() = IP_BROADCAST;
    ih->saddr() = myId;

    ih->ttl() = 1;
 
target_->recv(p, (Handler*) 0);
...

I get the following error message and 'ns' aborts

_o11: no target for slot -1

**
How do I specify that these packets should come to my agent.
**
A related question that I have is if I bind my agent on a particular port,
will all the instances of my agent attached to other nodes inherit that
port nr.
**
Can youi pls give me some pointers to gain better knowledge about agents
binding to port. 

I have attached my C++ and tcl script just in case you require to know
what exactly I am doing.

Thanks in anticipation.

Regards,
Sudhin.

****************** Sudhindra Suresh Bengeri *******************
School:                       | Home:                         |
Dept. of Computer Science     | 2502, Avent Ferry Rd          |
NCSU, Raleigh, NC.            | Apt #206, Raleigh, NC - 27606 |
Ph. 919 515 7135(TA room)     | Ph. 919 838 8746              |     
web page: http://www4.ncsu.edu/~ssbenger
#ifndef _SIMPLEAGENT_
#define _SIMPLEAGENT_

#include "agent.h"
#include "tclcl.h"
#include "packet.h"
#include "address.h"
#include "ip.h"

#define HDR_SIMPLE(p) ((struct hdr_simple*)(p)->access(off_simple_))

struct hdr_simple {
  char ret;
};


class SimpleAgent : public Agent {
 public:
  SimpleAgent(nsaddr_t id);
  void recv(Packet *p, Handler *);
 protected:
  int command(int argc, const char*const* argv);
  int broadcastpkt();
  void recvSimplePkt(Packet *);

  nsaddr_t myId;
  int off_simple_;
};


#endif
#include <stdlib.h>
#include <assert.h>
#include <errno.h>

#include "simpleagent.h"

static class SimpleAgentClass : public TclClass {
public:
        SimpleAgentClass() : TclClass("Agent/Simple") {}
        TclObject* create(int, const char*const* argv) {
	    printf("Agent/Simple being created \n");
	    assert(argc == 5);
	    printf("argv[0] = %s, [1] = %s, [2] = %s, [3] = %s, [4] = %s\n",
		    argv[0], argv[1], argv[2], argv[3], argv[4]);
            return (new SimpleAgent((nsaddr_t)atoi(argv[4])));
        }
} class_simpleagent;

static class SimpleHeaderClass : public PacketHeaderClass {
public:
        SimpleHeaderClass() : PacketHeaderClass("PacketHeader/Simple",
                                             sizeof(hdr_simple)) 
        { printf("SimpleHeader::Constructor\n"); }
						 
} class_simplehdr;


SimpleAgent::SimpleAgent(nsaddr_t id) : Agent(PT_SIMPLE) 
{
    printf("SimpleAgent::Constructor\n");
    bind("off_simple_", &off_simple_);
    myId = id;
}

int
SimpleAgent::command(int argc, const char*const* argv)
{

    if (argc == 2 && strcasecmp(argv[1], "hi") == 0)
    {
        printf("In SimpleAgent::command exec hi\n");
        Tcl::instance().result("Hi boss, this message is from C++\n");
        return TCL_OK;
    }
  
    if(argc == 2 && strcasecmp(argv[1], "broadcast") == 0)
    {
        printf("In SimpleAgent::command:broadcast\n");
        return broadcastpkt();
    }

    return Agent::command(argc, argv);
}

void 
SimpleAgent::recv(Packet *p, Handler *)
{
    struct hdr_cmn *cm = HDR_CMN(p);
    struct hdr_ip  *ih = HDR_IP(p);

    if(cm->ptype() == PT_SIMPLE)
    {
	recvSimplePkt(p);
	return;
    }
    else
    {
	printf("Packet of type = %d, ignoring..\n", cm->ptype());
	free(p);
    }
}

void
SimpleAgent::recvSimplePkt(Packet *p)
{
    struct hdr_cmn *cm = HDR_CMN(p);
    struct hdr_ip  *ih = HDR_IP(p);
    struct hdr_simple *sh = HDR_SIMPLE(p);
    
    printf("Pkt recd from: %d, port: %d\n", ih->saddr(), ih->sport());
    printf("Pkt recd to:   %d, port: %d\n", ih->daddr(), ih->dport());
    printf("With TTL:\n", ih->ttl());
}

int
SimpleAgent::broadcastpkt()
{
    Packet *p = Packet::alloc();
    struct hdr_cmn *cm = HDR_CMN(p);
    struct hdr_ip  *ih = HDR_IP(p);
    struct hdr_simple *sh = HDR_SIMPLE(p);

    cm->ptype() = PT_SIMPLE;
    ih->daddr() = IP_BROADCAST;
    ih->saddr() = myId;

    ih->ttl() = 1;

    printf("Sending a broadcast packet\n");
    target_->recv(p, (Handler*) 0);
}

set ns [new Simulator]

$ns color 0 blue
$ns color 1 red
$ns color 2 green
$ns color 3 white

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

set f [open out.tr w]
$ns trace-all $f
set nf [open out.nam w]
$ns namtrace-all $nf

$ns duplex-link $n1 $n0 750Kb 100ms DropTail
$ns duplex-link $n2 $n0 1.5Mb 50ms DropTail
$ns duplex-link $n3 $n2 750Kb 100ms DropTail

$ns duplex-link-op $n1 $n0 orient right-up
$ns duplex-link-op $n2 $n0 orient right-up
$ns duplex-link-op $n3 $n2 orient right-down


set sim0 [new Agent/Simple [$n0 id]]
$ns attach-agent $n0 $sim0

set sim1 [new Agent/Simple [$n1 id]]
$ns attach-agent $n1 $sim1

set sim2 [new Agent/Simple [$n2 id]]
$ns attach-agent $n2 $sim2

set sim3 [new Agent/Simple [$n3 id]]
$ns attach-agent $n3 $sim3

$ns at 0.2 "$sim0 broadcast"
$ns at 0.4 "$sim1 broadcast"
$ns at 0.6 "$sim2 broadcast"
$ns at 0.8 "$sim3 broadcast"

$ns at 1.0 "finish"

proc finish {} {
	global ns f nf
	$ns flush-trace
	close $f
	close $nf

	puts "running nam..."
	exec nam out.nam &
	exit 0
}

$ns run