Upload
walter-johnston
View
220
Download
0
Embed Size (px)
Citation preview
نمایید .1 نصب را زیر های فایل .ابتدا sudo apt-get install build-essential
autoconf automake libxmu-dev gcc-4.3فایل. 2 در را زیر تغییرات شدید، مواجه خطا با اگر
ns-allinone-2.34/otcl-1.13/Makefile.in اعمالکنید.
CC = @CC@ بدهید تغییر زیر حالت :بهCC = gcc-4.3
1
در ns-allinone-2.34.tar.gzفایل. 3 کپی home/userراحالت Terminalکنید. از را فایل زیر دستور با و کنید باز را
. نمایید خارج زیپtar xvfz ./ns-allinone-2.34.tar.gz
دستور. 4 از استفاده :cdبا بروید فایل محل به $cd ns-allinone-2.34
( منبع از را نیاز مورد های پکیج و ها دانلود( repositoryفایل. کنید نصب و
$sudo apt-get install build-essential autoconf automake libxmu-dev
2
:NS2نصب. 5 دستور از استفاده $ با/.install
6: دستور. از استفاده با نیاز مورد مسیرهای بعضی ویرایش
$gedit ~/.bashrc . جای به شما البته کنید اضافه شده باز فایل انتهای به را زیر home/heidari /خطوط
. بگدارید را خود فایل مسیر # LD_LIBRARY_PATH
OTCL_LIB=/home/heidari/ns-allinone-2.34/otcl-1.13NS2_LIB=/home/heidari/ns-allinone-2.34/libX11_LIB=/usr/X11R6/libUSR_LOCAL_LIB=/usr/local/libexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB
# TCL_LIBRARY
TCL_LIB=/home/heidari/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB
# PATHXGRAPH=/home/heidari/ns-allinone-2.34/bin:/home/ram/ns-allinone-2.34/tcl8.4.18/unix:/home/heidari/ns-allinone-2.34/tk8.4.18/unix:/home/heidari/ns-allinone-2.34/xgraph-12.1/NS=/home/heidari/ns-allinone-2.34/ns-2.34/NAM=/home/heidari/ns-allinone-2.34/nam-1.13/export PATH=$PATH:$XGRAPH:$NS:$NAM
دستور از استفقاده .source ~/.bashrc$ با نمایید ذخیره را تغییرات 3
و. 7 :validationتایید نصب $ cd ns-2.34 $ ./validate
. کشد می طول ای دقیقه چند و است زمانبر مرحله این کهپایان از باید nsدستور validationبعد و کنید تایپ را
. عالمت % دستور خروج برای ببینید .exitرا کنید اجرا را $ns
% $ $exit
4
NS2معرفی
5
Most UNIX and UNIX-like systems FreeBSD Linux Solaris
Windows 98/2000/2003/XPCygwin required Some work , some doesnt
6
NS – SimulatorNAM – Network AniMator
visual demonstration of NS outputPreprocessing
Handwritten TCL orTopology generator
Post analysisTrace analysis using Perl/TCL/AWK/MATLAB
7
From the user’s perspective, NS−2 is an OTcl interpreter that takes an OTcl script as input and produces a trace file as output.
8
ns-2 is an discrete event driven simulation Physical activities are translated to events Events are queued and processed in the order of their
scheduled occurrences Time progresses as the events are processed
1 2
Time: 1.5 sec Time: 1.7 sec
Time: 1.8 secTime: 2.0 sec
9
Discrete Event Scheduler
time_, uid_, next_, handler_
head_ ->
handler_ -> handle)(
time_, uid_, next_, handler_insert
head_ ->
Event Scheduler
10
Non-Real time schedulersImplementations : List , Heap , Calender Calender is default
Real time schedulersUsed for emulation for direct interaction with
real NT. Basic use of an event scheduler:
schedule simulation events, such as when to start an FTP application, when to finish a simulation, or for simulation scenario generation prior to a simulation run.
11
Simulation Scenario
Tcl Script
C++ Implementation
1 2
set ns_ [new Simulator]
set node_(0) [$ns_ node]
set node_(1) [$ns_ node]
class MobileNode : public Node {
friend class PositionHandler;public: MobileNode();
••
}
12
otcl: Object-oriented supporttclcl: C++ and otcl linkageDiscrete event schedulerData network (the Internet) components
tcl8.4
otcl
tclcl
ns-2EventScheduler
Netw
orkC
omponent
13
A ddr
R ep lica to r
M C a s t
M P a th
H a sh
C la ss ife r
D e la y
A ge nt
A p p lica tion
Q ueue
T ra ce
C on ne c to r
NSO je ct
T c lO b je ct
14
UDP
RBP
R eno
RB P
V eg as
S a ck1
N ewR eno
Tap
S in k
Fu llTC P
A dap tive
S RM
TCP DSDV AO DV TO RA DSR
A ge nt
Te ln e t
E xpo n en tia l
P are to
CBR
T ra ce
T ra ff ic
FTP
A pp lica tion
D ro p ta il
R E D
FQ
S FQ
DR R
CBQ
Q ueue
E nq
D eq
D ro p
T ra ce
15
NS-2 Directory Structure
sim
tk8.4 otcl Tcltcl8.4 ns-2 nam-1
tcl
ex test lib
...
...
tcl code
example
validation test
C++ code
tcl code core
16
Cla
ssifier
Cla
ssifier
Agent
Link
Agent
Agent
Node
Addr
Port
Node entry point
Local
Link Link
Agents are either protocol endpoints or related objects that generate/fill-in
packet fields.
Classifiers: packet demultiplexers.
17
18
Packets (events)packet
Size determined at compile
time
cmn header
Size determined at compile
time
tcp header
Size determined at compile
time
ip header
Size determined at compile
time
trace header
bits( )
accessdata( )
next_Size
determined at
simulation config
time
- packet size
- timestamp
- type
- UID
- interface label
19
Links
Enq Trace Deq Trace Rcv Trace
Drp Trace
Delay TTL
Drop head
QueueLink entry point
Links: keeps track of “from” and “to” node objects.blocked
20
Link
Link
Application
N1 N2
Classifier
Classifier
Agent
Node
Addr
Port
LocalC
lassifier
Classifier
Agent
Node
Addr
Port
Local
Enq Trace Deq Trace Rcv Trace
Drp Trace
Delay TTL
Drop head
Queue
Application
21
C++ is used for the creation of objects because of speed and efficiency.
NS-2 Code contains two sets of languages, namely C++ and OTcl.
OTcl is used as a front-end to setup the simulator, configure objects and schedule events because of its ease of use.
22
Why two languages? (Tcl & C++) C++: Detailed protocol simulations
require systems programming language byte manipulation, packet processing,
algorithm implementation Run time speed is important Turn around time (run simulation, find bug,
fix bug, recompile, re-run) is slower Tcl: Simulation of slightly varying
parameters or configurations quickly exploring a number of scenarios iteration time (change the model and re-
run) is more important23
Tcl or C++? Tcl
Simple Configuration, Setup, Scenario
If it’s something that can be done without modifying existing Tcl module.
C++Anything that requires processing
each packetNeeds to change behavior of existing
module 24
Shadowing
TclObject
Agent
Agent/DSDV
Agent/DSDV OTcl shadow object
Agent/DSDV C++ object
TclObject()
Agent()
DSDVAgent()
OTcl classhierarchy
C++ classhierarchy
25
Agent/DSDVConstructor
AgentConstructor
Invoke parent
TclObjectConstructor
Invoke parent
AgentDSDV()Constructor
Create C++
Agent()Constructor
Invoke parent
TCL
C++TclObject()
ConstructorInvoke parent
Do nothing,
returnbind and return
bind and return
OTcl shadow
init complete
init complete
26
NS-2 Directory Structure
sim
tk8.0 otcl Tcltcl8.0 ns-2 nam-1
tcl
ex test lib
...
...
tcl code
example
validation test
C++ code
tcl code core
27
مسیر 1. در و کنیم می دانلود یا نوشته را -ns/پروتکلalllinone-2.34/ns-2.34 قرار ها پروتکل سایر موازات به
. دهیم میبدهیم تغییر را زیر های فایل باید پروتکل کردن اضافه .برای
$NS_ROOT/Makefile $NS_ROOT/queue/priqueue.cc $NS_ROOT/common/packet.h $NS_ROOT/trace/cmu-trace.h $NS_ROOT/trace/cmu-trace.cc $NS_ROOT/tcl/lib/ns-packet.tcl $NS_ROOT/tcl/lib/ns-lib.tcl $NS_ROOT/tcl/lib/ns-agent.tcl $NS_ROOT/tcl/lib/ns-mobilenode.tcl
28
3 دهیم می تغییر را زیر فایل ابتدا /~ns-allinone-2.34/ns-2.34/Makefile
خط . 269در نمایید اضافه را زیر کدblackholeaodv/blackholeaodv.o\
فایل. 4 به را زیر خطوط/~ns-allinone-2.34/ns-2.34/queue/priqueue.cc
خط .93از نمایید اضافه// blackholeAODV patchcase PT_blackholeAODV:
29
فایل. 5 اصالح/~ns-allinone-2.34/ns-2.34/common/packet.h file.اضافه PT_NTYPE to 63 باید را خودمون پروتکل و دهیم قرار
را آن و کنیم .PT_blackholeAODV = 62می دهیم می قرارخط از فایل همین .85در باشد شکل این به باید تغییرات
// blackholeAODV packetstatic const packet_t PT_blackholeAODV = 62;// insert new packet types herestatic packet_t PT_NTYPE = 63; // This MUST be the
LAST one
30
فایل. 6 به را زیر تغییرات/~ns-allinone-2.34/ns-2.34/common/packet.h
. کنیم می اعمالtype == PT_AODV ||type == PT_blackholeAODV)
خط .390در نمایید اعمال را زیر تغییرات فایل همین// blackholeAODV patchname_[PT_blackholeAODV] =
"blackholeAODV";
31
های. 7 فایل باید مرحله این . TcLدر فایل شروع برای کنیم ویرایش -ns ~/راallinone-2.34/ns-2.34/tcl/lib/ns-packet.tcl خط را 633در زیر های کد
. نمایید اضافه blackholeAODV { set ragent [$self create-blackholeaodv-agent $node] }
خط نمایید 860در اضافه را زیر کدهای باید فایل همین . Simulator instproc create-blackholeaodv-agent { node } { # Create blackholeAODV routing agent set ragent [new Agent/blackholeAODV [$node node-addr]] $self at 0.0 "$ragent start" $node set ragent_ $ragent return $ragent }
32
8. Now we will set port numbers of routing agent. sport is source port, dport is destination port.
-ns-allinone-2.34/ns-2.34/tcl/lib/ns~/فایل 202خط agent.tcl. میدهیم تغییر زیر صورت به را
Agent/blackholeAODV instproc init args {$self next $args}Agent/blackholeAODV set sport_ 0Agent/blackholeAODV set dport_ 0
33
خط. 8 -ns-allinone-2.34/ns-2.34/tcl/lib/ns~/فایل 202ازmobilenode.tcl. نمایید اضافه را زیر کدهای
# Special processing for blackholeAODVset blackholeaodvonly [string first
"blackholeAODV" [$agent info class]]if {$blackholeaodvonly != -1 } {$agent if-queue [$self set ifq_(0)] ;# ifq between LL
and MAC}
مسیر. 9 به نهایت در می /ns-allinone-2.34/ns-2.34~/و. میکنیم اجرا را زیر دستورات و رویم
make cleanmake
34
Creating a Simulator Objectset ns [new Simulator]
Setting up files for trace & NAMset trace_nam [open out.nam w]set trace_all [open all.tr w]
Tracing files using their commands$ns namtrace-all $trace_nam$ns trace-all $trace_all
35
Closing trace file and starting NAMproc finish { } {
global ns trace_nam trace_all $ns flush-traceclose $trace_namclose $trace_allexec nam out.nam &exit 0}
36
Creating LINK & NODE topologyCreating NODES
set n1 [$ns node]set n2 [$ns node]set n3 [$ns node]set n4 [$ns node]set r1 [$ns node]set r2 [$ns node]
37
Creating LINKS$ns duplex-link $N1 $R1 2Mb 5ms DropTailset DuplexLink0 [$ns link $N1 $R1]$ns duplex-link $N2 $R1 2Mb 5ms DropTailset DuplexLink1 [$ns link $N2 $R1]$ns duplex-link $R1 $R2 1Mb 10ms DropTailset DuplexLink2 [$ns link $R1 $R2]$ns duplex-link $R2 $N3 2Mb 5ms DropTailset DuplexLink3 [$ns link $R2 $N3]$ns duplex-link $R2 $N4 2Mb 5ms DropTailset DuplexLink4 [$ns link $R2 $N4]
38
Orientation of links$ns duplex-link-op $N1 $R1 orient right-
down$ns duplex-link-op $N2 $R1 orient right-
up$ns duplex-link-op $R1 $R2 orient right$ns duplex-link-op $R2 $N3 orient right-
up$ns duplex-link-op $R2 $N4 orient right-
down
39
40
41
Attaching AGENT TCP to NODE 1set TCP1 [new Agent/TCP]$ns attach-agent $N1 $TCP1
Attaching AGENT TCP to NODE 2set TCP2 [new Agent/TCP]$ns attach-agent $N2 $TCP2
Attaching AGENT TCP to NODE 3set TCP3 [new Agent/TCPSink]$ns attach-agent $N2 $TCP3
Attaching AGENT TCP to NODE 4set TCP4 [new Agent/TCPSink]$ns attach-agent $N2 $TCP4
42
Attaching Application (FTP)set FTP0 [new Application/FTP]set FTP1 [new Application/FTP]$FTP0 attach-agent $TCP0$FTP1 attach-agent $TCP1
43
$ns at 0.5 "$FTP0 start"$ns at 0.5 "$FTP1 start"$ns at 10.0 "$FTP0 stop"$ns at 10.0 "$FTP1 stop“$ns at 10.0 “finish”Making NS run
$ns run
44
45