Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Jianming Wu
Outline
Introduction Fundamental Skills - Tcl and OTcl Network Simulator - ns-2 Study Project - Mobile IP Reference
Introduction
NS2 history
Modified from REAL network simulator Developed through VINT project at UC-Berkeley NS1 vs. NS2
R1
R2
Fundamental Skills
NS2 is written in C++ and OTcl
OTcl = Tcl + OO C++ implements the code that executed frequently OTcl configures the system
set ns [new Simulator] set n1 [new Node] set n2 [new Node] $ns duplex-link $n1 $n2 5Mb 2ms DropTail
n1
n2
add2 55 57
linsert
lreplace
TcpClass() : TclClass("Agent/TCP") {}
TclObject* create(int, const char*const*) { return (new TcpAgent);} } class_tcp;
init
init
OTcl
TclObject (C++)
constructor
C++ parent
constructor
TcpAgent
constructor
C++
int Agent::command(int argc, const char*const* argv) { if (argc == 3) { if (strcmp(argv[1], advance") == 0) { int newswq = atoi(argv[2]); return (TCL_OK); } } return (Agent::command(argc, argv); }
Otcl
$tcp set window_ 200
Buffer
Simple.tcl
OFFMN
Motion
# Create HA and FA set HA [$ns_ node 1.0.0] set FA [$ns_ node 2.0.0] $HA random-motion 0 $FA random-motion 0
# create a mobilenode $ns_ node-config -wiredRouting OFF set MH [$ns_ node 1.0.1] set node_(0) $MH set HAaddress [AddrParams addr2id [$HA node-addr]] [$MH set regagent_] set home_agent_ $HAaddress # movement of the MH $MH set Z_ 0.000000000000 $MH set Y_ 2.000000000000 $MH set X_ 2.000000000000 # MH starts to move towards FA $ns_ at 100.00 "$MH setdest 640.0 610.0 20.0" # goes back to HA speed $ns_ at 200.00 "$MH setdest 2.0 2.0 20.0"
# Position for base-station nodes (HA & FA). $HA set X_ 1.000000000000 $HA set Y_ 2.000000000000 $HA set Z_ 0.000000000000
destination
Initial position
Mobile Node
0 1
Agent Agent
Node
Base-Station
Packet header
offset_
struct hdr_ip { .
Data-structure
public:
MIPHeaderClass() : struct hdr_mip { PacketHeaderClass("PacketHeader/MIP", sizeof(hdr_mip)) { int haddr_; int ha_; bind_offset(&hdr_mip::offset_);} int coa_; } class_miphdr; MipRegType type_; //MIPT_REG_REQUEST, MIPT_REG_REPLY, MIPT_ADS, MIPT_SOL double lifetime_; int seqno_; Setting: static int offset_; inline static hdr_mip* access(const Packet* p) { ~ns/comm/packet.h and return (hdr_mip*) p->access(offset_); ~ns/tcl/lib/ns-packet.tcl } };
Access:
New Agent
New Agent for sending registration packet periodically class SimpleTimer : public TimerHandler { Data-structure
class MIPMHAgent : public Agent { public: MIPMHAgent(); void recv(Packet *, Handler *); void timeout(int); protected: void reg(); int ha_; /* home agent address */ int coa_; /* care-of-address */ double reg_rtx_; /* retransmitting time */ SimpleTimer rtx_timer_; RegTimer reg_timer_; double reglftm_; /* registration lifetime */ double adlftm_; /* current ads lifetime */ };
public: SimpleTimer(Agent *a) : TimerHandler() { a_ = a; } protected: inline void expire(Event*){ a_>timeout(MIP_TIMER_SIMPLE); } Agent *a_; }; class RegTimer : public TimerHandler { public:
Receiving reply
void MIPMHAgent::recv(Packet* p, Handler *){ Tcl& tcl = Tcl::instance(); hdr_mip *miph = hdr_mip::access(p); switch (miph->type_) { case MIPT_REG_REPLY: tcl.evalf("%s update-reg %d", name_, coa_); if (rtx_timer_.status() == TIMER_PENDING) rtx_timer_.cancel(); reg_timer_.resched(miph->lifetime_-0.5); break; case MIPT_ADS: reg(); break; default: Packet::free(p); break; } }
~ns/tcl/lib/ns-default.tcl
Processing handoff
$ns_ node-config -propType Propagation/TwoRayGround \ -phyType Phy/WirelessPhy \ -channelType Channel/WirelessChannel \
RXThresh_
References
Tcl/Tk http://www.tcl.tk/software/tcltk/ Nsnam web pages http://www.isi.edu/nsnam/ NS by example http://nile.wpi.edu/NS/ Tutorial Marc Greis's tutorial Discrete-event simulation software
http://www.topology.org/soft/sim.html