DOC PREVIEW
UW-Madison CS 740 - NS2 Tutorial

This preview shows page 1-2-15-16-31-32 out of 32 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32NS2 TutorialAga ZhangDependable Computing LabOutline•Introduction•Fundamental Skills - Tcl and OTcl•Network Simulator - ns-2•Study Project - Mobile IP•ConclusionsIntroduction•NS2 history–Modified from REAL network simulator–Developed through VINT project at UCB–NS1 vs. NS2•NS version2 is a discrete-event driven and object-oriented network simulator–Type of simulation: continuous, discrete event, and combined•Events  Packet and TimerR1 R2AckTCP PacketRetransmit timer startRetransmitFundamental Skills (I)•Scripting language is used to describe a high-level programming language with relatively transparent syntax button .b text Hello! –command {puts hello} ---- tcl command•Scripting language—Unix shells(sh, csh, …), Tcl, Perl,VB, and JavaScript•All major computing platforms provide both system programming languages such as C or Java and scripting languages such as TclFundamental Skills (II) •NS2 is written in C++ and OTcl–OTcl = Tcl + OO–C++ implements the code that executed frequently–OTcl configures the systemset ns [new Simulator]set n1 [new Node] set n2 [new Node] $ns duplex-link $n1 $n2 5Mb 2ms DropTailn1 n2Tcl – Tool Command Language•Start: Typing “tclsh” in Unix shell•Instructions using in ns2:proc add2 {a} {set b [expr $a+1]incr bputs “a+2=$b” }add2 55  57 set ll [list a b c]lappend $ll d  a b c dlindex $ll 0  allength $ll  4lsearchlinsertlreplacesplit a.b . a bsource file includeforeachinfo exists varNaminfo tclversionOTcl – MIT Object TclClass fatherfather instproc init {args} {$self set var_ 0puts “**var_=$var_”eval $self next $args}father ff  **var_=0ff info vars  var_ff set var_  0ff info class  fatherfather info instances  ffClass son –superclass fatherson instproc init {args} {puts “no var_” }son ss  no var_Class son2 –superclass fatherson instproc init {args} {puts “no var_”$self next $args }son2 ss  no var_ **var_=0OTcl Linkageset tcp [new Agent/TCP]initAgent/TCPinit AgentCreate Otcl shadow objectTclObjectCreate C++ objectconstructorTclObject (C++)constructorparentconstructorTcpAgentOTclC++static class TcpClass : public TclClass {public:TcpClass() : TclClass("Agent/TCP") {} TclObject* create(int, const char*const*) {return (new TcpAgent);}} class_tcp;OTcl Linkage (II)Command()•Otcl$tcp advance 10•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 Linkage (III)bind(): link C++ member variables to Otcl object variables•C++TcpAgent::TcpAgent() {bind(“window_”, &wnd_);} // bind_time(), bind_bool(), bind_bw()•Otcl$tcp set window_ 200 You must setting the initial values of variants in ~ns/tcl/lib/ns-default.tclOTcl Linkage (IV)•Invoking Otcl procedure and obtaining its resultsTcl::instance().evalf("%s Lookup_CIP_RT %d", name(), iph->dst().addr_);nextHop = Tcl::instance().result();Classifier/Addr/Cip instproc Lookup_CIP_RT { m_addr } { return … }•Passing a results string to OtclTcl::instance().result(“………”)BufferNetwork Simulator - ns-2•After installing: Add the path of ns2 to your profile, and validate your ns2•Modifying *.cc or *.tcl fileif add new oneadding its path to makefile(.cc) or ~ns/tcl/lib/ns-lib.tcl(.tcl)Type: make depend makeOr make clean configure –enable--debug makeThe directory of ns2Simple code (I)Simple.tclRun your program  % ns Simple.tclSimple code (II)Simple code (III)Simple code (IV)Simple code (V)Study Project - Mobile IP•Configuring mobile node, HA, and FA•New packet header•Setting timer for advertisement and registration•Processing handoffConfigure mobile node, HA, and FA•Wired node– set node(0) [$ns_ node] •Wireless&wired noderoutingAgent_OFFMNMotion# Create HA and FAset HA [$ns_ node 1.0.0]set FA [$ns_ node 2.0.0]$HA random-motion 0$FA random-motion 0# Position for base-station nodes (HA & FA).$HA set X_ 1.000000000000$HA set Y_ 2.000000000000$HA set Z_ 0.000000000000$FA set X_ 650.000000000000$FA set Y_ 600.000000000000$FA set Z_ 0.000000000000# create a mobilenode $ns_ node-config -wiredRouting OFFset MH [$ns_ node 1.0.1]set node_(0) $MHset 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$ns_ at 200.00 "$MH setdest 2.0 2.0 20.0"Initial positionClose random motiondestinationspeedMobile Node Agent0Agent1NodeBase-StationPacket header•Access packet header:hdr_ip *iph = hdr_ip::access(p);hdr_cmn *ch = hdr_cmn::access(p);……………………iph->dst() = iph->src();struct hdr_ip {………………….static int offset_; // required by PacketHeaderManagerinline static hdr_ip* access(Packet* p) {return (hdr_ip*) p->access(offset_);}offset_New MIP packet header•Data-structurestruct hdr_mip {int haddr_;int ha_;int coa_;MipRegType type_; //MIPT_REG_REQUEST, MIPT_REG_REPLY, MIPT_ADS, MIPT_SOLdouble lifetime_;int seqno_;static int offset_; inline static hdr_mip* access(const Packet* p) {return (hdr_mip*) p->access(offset_);}};•Setting:~ns/comm/packet.h and ~ns/tcl/lib/ns-packet.tcl•Access:hdr_mip *miph = hdr_mip::access(p)static class MIPHeaderClass : public PacketHeaderClass {public:MIPHeaderClass() : PacketHeaderClass("PacketHeader/MIP", sizeof(hdr_mip)) {bind_offset(&hdr_mip::offset_);}} class_miphdr;New Agent•New Agent for sending registration packet periodically•Data-structureclass 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 */};class SimpleTimer : public TimerHandler {public: SimpleTimer(Agent *a) : TimerHandler() { a_ = a; }protected: inline void expire(Event*){ a_>timeout(MIP_TIMER_SIMPLE); } Agent


View Full Document

UW-Madison CS 740 - NS2 Tutorial

Documents in this Course
Load more
Download NS2 Tutorial
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view NS2 Tutorial and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view NS2 Tutorial 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?