NS-3 Simulator Basics
NS-3 Simulator Basics
NS-3 Simulator Basics
Bindings in Pthon
,ive visuali-er
date-driven schedules
http3&&www+nsnam+org&docs&release&3+01&tutorial&n
s-3-tutorial+pdf
$nstallation
Node
(pplication
Net device
Channel
Corresponding to these a!stractions there are
modules ).here are other modules for other
functionalities*
%odules
Different entities are implemented in different
modules+ /ach modules has C(ttri!utesC+
#unctionalities of modules are provided !
different C++ mem!er functions+ .here is helper
(P$ availa!le with each module+ .hese helper
methods makes programming easier+ ,ow level
(P$ can still !e used+
Create nodes
Setup routing
Setup tracing
@un simulation
Net Devices
(lohaNoackNetDevice
Point.oPoint
Bridge
Csma
7ifi
7i%a"
BaseStationNetDevice
Su!scri!erStation
'pen#lowSwitch
,oopBack
Simple
Net Devices
#d )#ile descriptor*
.ap
#ake
NonCommunicating
/rror
(pplications
!ulk-send )sends data as fast as possi!le*
on-off )'n 'ff pattern*
packet-sink
udp-server )@eceives =DP packets*
udp-client )=DP packet with se? no and time stamp*
udp-echo-server
udp-echo-client
v2ping )sends one $C%P /CG' re?uest4 reports the @..*
ping:
radv)@outer advertisement daemon*
@outing protocols
I#v(Static*outing
/"ample 2
0<+0+0+<
n< -------------- n0 n2 n3 n2
point-to-point T T T T
RRRRRRRRRRRRRRRR
,(N 0<+0+2+<
int main )int argc4 char KargvLM* N
!ool ver!ose R trueJ
uint32Pt nCsma R 3J
Command,ine cmdJ
cmd+(ddQalue )InCsmaI4 INum!er of I4 nCsma*J
cmd+(ddQalue )Iver!oseI4 I,og if trueI4 ver!ose*J
cmd+Parse )argc4argv*J
nCsma R nCsma RR < U 0 3 nCsmaJ
&& +&waf --run Isecond --nCsmaR3I
NodeContainer p2pNodesJ
p2pNodes+Create )2*J
NodeContainer csmaNodesJ
csmaNodes+(dd )p2pNodes+Oet )0**J
csmaNodes+Create )nCsma*J
Point.oPointGelper point.oPointJ
point.oPoint+SetDevice(ttri!ute
)IData@ateI4 StringQalue )I;%!psI**J
point.oPoint+SetChannel(ttri!ute
)IDelaI4 StringQalue )I2msI**J
NetDeviceContainer p2pDevicesJ
p2pDevices R point.oPoint+$nstall )p2pNodes*J
CsmaGelper csmaJ
csma+SetChannel(ttri!ute
)IData@ateI4 StringQalue )I0<<%!psI**J
csma+SetChannel(ttri!ute
)IDelaI4 .imeQalue )NanoSeconds ):;:<***J
NetDeviceContainer csmaDevicesJ
csmaDevices R csma+$nstall )csmaNodes*J
$nternetStackGelper stackJ
stack+$nstall )p2pNodes+Oet )<**J
stack+$nstall )csmaNodes*J
$pv2(ddressGelper addressJ
address+SetBase )I0<+0+0+<I4 I2;;+2;;+2;;+<I*J
$pv2$nterfaceContainer p2p$nterfacesJ
p2p$nterfaces R address+(ssign )p2pDevices*J
address+SetBase )I0<+0+2+<I4 I2;;+2;;+2;;+<I*J
$pv2$nterfaceContainer csma$nterfacesJ
csma$nterfaces R address+(ssign)csmaDevices*J
=dp/choServerGelper echoServer )D*J
(pplicationContainer server(pps R
echoServer+$nstall )csmaNodes+Oet )nCsma**J
server(pps+Start )Seconds )0+<**J
server(pps+Stop )Seconds )0<+<**J
=dp/choClientGelper echoClient
)csma$nterfaces+Oet(ddress )nCsma*4 D*J
echoClient+Set(ttri!ute
)I%a"PacketsI4 =integerQalue )0**J
echoClient+Set(ttri!ute
)I$ntervalI4 .imeQalue )Seconds )0+<***J
echoClient+Set(ttri!ute
)IPacketSi-eI4 =integerQalue )0<22**J
(pplicationContainer client(pps R
echoClient+$nstall )p2pNodes+Oet )<**J
client(pps+Start )Seconds )2+<**J
client(pps+Stop )Seconds )0<+<**J
$pv2Olo!al@outingGelper33
Populate@outing.a!les )*J
point.oPoint+/na!lePcap(ll )IsecondI*J
csma+/na!lePcap
)IsecondI4 csmaDevices+Oet )0*4 true*J
Simulator33@un )*J
Simulator33Destro )*J
return <J
S
/"ample 3
7ifi 0<+0+3+<
(P
K K K K
T T T T 0<+0+0+<
n; n: nE n< -------------- n0 n2 n3 n2
point-to-point T T T T
RRRRRRRRRRRRRRRR
,(N 0<+0+2+<
NodeContainer p2pNodesJ
p2pNodes+Create )2*J
Point.oPointGelper point.oPointJ
point.oPoint+SetDevice(ttri!ute )IData@ateI4
StringQalue )I;%!psI**J
point.oPoint+SetChannel(ttri!ute )IDelaI4
StringQalue )I2msI**J
NetDeviceContainer p2pDevicesJ
p2pDevices R point.oPoint+$nstall )p2pNodes*J
NodeContainer csmaNodesJ
csmaNodes+(dd )p2pNodes+Oet )0**J
csmaNodes+Create )nCsma*J
CsmaGelper csmaJ
csma+SetChannel(ttri!ute
)IData@ateI4 StringQalue )I0<<%!psI**J
csma+SetChannel(ttri!ute
)IDelaI4 .imeQalue )NanoSeconds ):;:<***J
NetDeviceContainer csmaDevicesJ
csmaDevices R csma+$nstall )csmaNodes*J
NodeContainer wifiStaNodesJ
wifiStaNodes+Create )n7ifi*J
NodeContainer wifi(pNode R p2pNodes+Oet )<*J
>ans7ifiChannelGelper channel R
>ans7ifiChannelGelper33Default )*J
>ans7ifiPhGelper ph R >ans7ifiPhGelper33Default )*J
ph+SetChannel )channel+Create )**J
7ifiGelper wifi R 7ifiGelper33Default )*J
wifi+Set@emoteStation%anager )Ins333(arf7ifi%anagerI*J
N?os7ifi%acGelper mac R N?os7ifi%acGelper33Default )*J
Ssid ssid R Ssid )Ins-3-ssidI*J
mac+Set.pe )Ins333Sta7ifi%acI4
ISsidI4 SsidQalue )ssid*4
I(ctivePro!ingI4 BooleanQalue )false**J
NetDeviceContainer staDevicesJ
staDevices R wifi+$nstall )ph4 mac4 wifiStaNodes*J
mac+Set.pe )Ins333(p7ifi%acI4
ISsidI4 SsidQalue )ssid**J
NetDeviceContainer apDevicesJ
apDevices R wifi+$nstall )ph4 mac4 wifi(pNode*J
%o!ilitGelper mo!ilitJ
mo!ilit+SetPosition(llocator )Ins333OridPosition(llocatorI4
I%inVI4 Dou!leQalue )<+<*4
I%in>I4 Dou!leQalue )<+<*4
IDeltaVI4 Dou!leQalue );+<*4
IDelta>I4 Dou!leQalue )0<+<*4
IOrid7idthI4 =integerQalue )3*4
I,aout.peI4 StringQalue )I@ow#irstI**J
mo!ilit+Set%o!ilit%odel )Ins333@andom7alk2d%o!ilit%odelI4
IBoundsI4 @ectangleQalue )@ectangle )-;<4 ;<4 -;<4 ;<***J
mo!ilit+$nstall )wifiStaNodes*J
mo!ilit+Set%o!ilit%odel )Ins333ConstantPosition%o!ilit%odelI*J
mo!ilit+$nstall )wifi(pNode*J
$nternetStackGelper stackJ
stack+$nstall )csmaNodes*J stack+$nstall )wifi(pNode*J
stack+$nstall )wifiStaNodes*J
$pv2(ddressGelper addressJ
address+SetBase )I0<+0+0+<I4 I2;;+2;;+2;;+<I*J
$pv2$nterfaceContainer p2p$nterfacesJ
p2p$nterfaces R address+(ssign )p2pDevices*J
address+SetBase )I0<+0+2+<I4 I2;;+2;;+2;;+<I*J
$pv2$nterfaceContainer csma$nterfacesJ
csma$nterfaces R address+(ssign )csmaDevices*J
address+SetBase )I0<+0+3+<I4 I2;;+2;;+2;;+<I*J
address+(ssign )staDevices*J address+(ssign )apDevices*J
=dp/choServerGelper echoServer )D*J
(pplicationContainer server(pps R
echoServer+$nstall )csmaNodes+Oet )nCsma**J
server(pps+Start )Seconds )0+<**J
server(pps+Stop )Seconds )0<+<**J
=dp/choClientGelper echoClient
)csma$nterfaces+Oet(ddress )nCsma*4 D*J
echoClient+Set(ttri!ute )I%a"PacketsI4 =integerQalue )0**J
echoClient+Set(ttri!ute )I$ntervalI4 .imeQalue )Seconds )0+<***J
echoClient+Set(ttri!ute )IPacketSi-eI4 =integerQalue )0<22**J
(pplicationContainer client(pps R
echoClient+$nstall )wifiStaNodes+Oet )n7ifi - 0**J
client(pps+Start )Seconds )2+<**J client(pps+Stop )Seconds )0<+<**J
$pv2Olo!al@outingGelper33Populate@outing.a!les )*J
Simulator33Stop )Seconds )0<+<**J
point.oPoint+/na!lePcap(ll )IthirdI*J
ph+/na!lePcap )IthirdI4 apDevices+Oet )<**J
csma+/na!lePcap )IthirdI4 csmaDevices+Oet )<*4 true*J
Simulator33@un )*J
Simulator33Destro )*J
return <J
Thanks
(If you are still listning)
It's Demo Time