[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ns] problem with LinkDelay::recv
Hi,
I had posted this question yesterday, but with a in appropriate subject
field. Hence re-posting my question.
Thanks and regards,
Sudhin.
Hi,
I have written a agent which binds to port 255 on a node, takes a
destination address as paramater, populates the ih->daddr() with the value
sent. And calls Agent::send(p,0).
What is happening is that the
classifier::recv calls connector::recv which calls connector::send which
after passing through the Trace - Queue - DequeTrace - reaches the
LinkDelay::recv. The LinkDelay::recv calculates the txtime and calls
Scheduler::schedule(this, p, txt+delay_) (which implies
^^^^
LinkDelay::dynamic_ is set) which calls CalendarScheduler::insert.
Then this event is never dispatched. Why can this be occuring?
I traced a similar path for the Ping agent, the schedule call in the
LinkDelay::recv here is
Scheduler::schedule(target_, p, txt+delay_) (which implies
^^^^^^^
LinkDelay::dynamic_ is 0).
Can you tell me where can I be going wrong. I have attached both the agent
code (simpleagent.cc) and the tcl script (testsim.tcl)
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
#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 == 3 && strcasecmp(argv[1], "broadcast") == 0)
{
nsaddr_t dst = (nsaddr_t)atoi(argv[2]);
printf("In SimpleAgent::command:broadcast\n");
return broadcastpkt(dst);
}
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);
}
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("My addr: %d, port: %d\n", here_.addr_, here_.port_);
printf("With TTL: %d\n", ih->ttl());
}
int
SimpleAgent::broadcastpkt(nsaddr_t dst)
{
Packet *p = allocpkt();
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;
cm->size() = sizeof(hdr_ip) + sizeof(hdr_simple);
ih->daddr() = dst; // IP_BROADCAST; forget about doing the limited broadcast
// missing
ih->dport() = 255;
ih->sport() = 255;
ih->saddr() = myId;
ih->ttl() = 1;
printf("Sending a broadcast packet\n");
// target_->recv(p, (Handler*) 0);
send(p,0);
return(TCL_OK);
}
# debug 1
set ns [new Simulator]
# Simulator set node_factory_ Node/Broadcast
$ns color 0 blue
$ns color 1 red
$ns color 2 green
$ns color 3 white
# debug 1
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]]
$n0 attach $sim0 255
#
set sim1 [new Agent/Simple [$n1 id]]
$n1 attach $sim1 255
set sim2 [new Agent/Simple [$n2 id]]
$n2 attach $sim2 255
set sim3 [new Agent/Simple [$n3 id]]
$n3 attach $sim3 255
Agent/Simple instproc broadcast {} {
$self instvar node_
puts "agent is attached to [$node_ id]"
set nblist [$node_ neighbors]
foreach node $nblist {
puts "sending packet to [$node id]"
$self cmd broadcast [$node id]
}
}
$ns at 0.5 "$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