[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Segmentation and Reassembly Agent
I just started learning simulation on ns.
I would like to make an agent who can handle segmentation and
reassembly.
A model is like this:
There is a connection between Node A and Node D.
Node 0 generates IP packets.
Node 1 receives an IP packet, devides it into cells, and sends them to
Node 2
Node 2 receives cells and assembles them into an IP packet, then sends
to Node 3.
Node 3 receives IP packets.
Node 0 Node 1 Node 2
Node 3
| IP | -------------|IP | |IP
|---------------|IP |
| | |cell|------------------- |cell|
| |
I tried the code below for segmentation part, but I don't know whether
it is a right way or not.
I didn't make header definition and so far.
=======C++ code=====================
class sarAgent : public Agent {
public:
sarAgent() :Agent(PT_PING){} // do nothing for this test
int command(int argc, const char*const* argv);
void recv(Packet* pkt, Handler*);
void output_cell(Packet* c); // IP -> cells
protected:
Agent *cdst_, *pdst_; // destination Agent for cells and pakets
respectively
};
static class sarClass : public TclClass {
public:
sarClass() : TclClass("Agent/sar") {}
TclObject* create(int, const char*const*) {
return (new sarAgent());
}
} class_sar;
int sarAgent::command(int argc, const char*const* argv)
{
if(argc == 3) {
if(strcmp(argv[1], "cell-dst" )==0) { // take destination
agent
Agent* a = (Agent*)TclObject::lookup(argv[2]);
cdst_ = a;
return (TCL_OK);
}
}
return (Agent::command(argc, argv));
}
void sarAgent::output_cell(Packet* c)
{
cdst_->recv(c,0); // Is this OK???
}
void sarAgent::recv(Packet* p, Handler *)
{
Packet* cell;
int cnt = (int)ceil(p->size_/50.0);
for(int i=0; i< cnt;i++) {
cell = Agent::allocpkt();
output_cell(cell);
}
}
=====Tcl file===================
# test for segmentation part only
# n0 n1 n2
# |IP |---|IP |
# | | |cell| --- |Null|
#Create a simulator object
set ns [new Simulator]
#Open a trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
}
#Create three nodes
set n0 [$ns node] // NODE 0
set n1 [$ns node] // NODE 1
set n2 [$ns node] // NODE 2
#Connect the nodes with two links
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
#Create two ping agents and attach them to the nodes n0 and n2
set p0 [new Agent/CBR]
$ns attach-agent $n0 $p0
set p2 [new Agent/Null]
$ns attach-agent $n2 $p2
set pp [new Agent/sar]
$ns attach-agent $n1 $pp
# set destination agent
$pp cell-dst $p2
#Connect the two agents // Is this OK???
$ns connect $p0 $p2
$ns connect $p2 $pp
#Schedule events
$ns at 0.1 "$p0 start"
$ns at 1.0 "$p0 stop"
#Run the simulation
$ns run
===================================
I don't know how to devide IP packets into cells and recover IP packets.
Someone, help me!
Yukio HASHIMOTO