Escolar Documentos
Profissional Documentos
Cultura Documentos
Appendix
Network Lab.
In this talk
n n
Network Lab.
NS-2 Tutorial
Wireless simulation (Ad hoc)
Network Lab.
Network Lab.
% cat wireless.tcl
n n
set ns [new Simulator] set tracefd [open trace.tr w] $ns trace-all $tracefd
o Running
Trace-all is required
n
without trace file % ns wireless.tcl Warning: You have not defined you tracefile yet!
Network Lab.
Nam trace
n
Network Lab.
Topography
n
track of movements of nodes o Last two parameters are the topological boundary
Network Lab.
create-god 2 o General Operations Director o Store the total number of nodes and a table of shortest number of hops required to reach from one to another set chan_ [new Channel/WirelessChannel]
Create channel
n
Network Lab.
Node configuration
n
$ns node-config -adhocRouting DSDV -llType LL -macType Mac/802_11 -ifqType Queue/DropTail/PriQueue -ifqLen 50 -antType Antenna/OmniAntenna -propType Propagation/TwoRayGround -channel $chan_ -topoInstance $topo -agentTrace ON -routerTrace OFF -macTrace ON -movementTrace OFF
9
Network Lab.
Mobile node
Node
port classifier
routing agent
Node Entry
LL
ARP
LL: Link layer object IFQ: Interface queue MAC: Mac object PHY: Net interface
From Polly Hwangs Presentation
IFQ
MobileNode
CHANNEL
Network Lab.
10
Create nodes
n
Create nodes
n
set node_(0) [$ns node] $node_(0) random-motion 0 set node_(1) [$ns node] $node_(1) random-motion 0
o Random-motion
Network Lab.
11
Set positions
n
(X,Y,Z)
n
$node_(0) set X_ 150.0 $node_(0) set Y_ 250.0 $node_(0) set Z_ 0.0 $node_(1) set X_ 350.0 $node_(1) set Y_ 250.0 $node_(1) set Z_ 0.0
o Z-axis
Network Lab.
12
$ns initial_node_pos $node_(0) 50 $ns initial_node_pos $node_(0) 50 Not initial position, but node size in NAM o Nodes are shown in NAM, but packets are not at this time
o
Network Lab.
13
Remainder
n
Initiate agents and attach them to nodes Initiate application and attach it to node Define self-calling procedure for periodic polling Run the simulation
Network Lab.
14
Running example
n
% ns wireless.tcl
n
num_nodes is set 2 INITIALIZE THE LIST xListHead Starting Simulation channel.cc:sendUp Calc highestAntennaZ_... highestAntennaZ_ = 1.5, distCST_ = 550.0 SORTING LISTS DONE! NS EXITING
Network Lab.
15
Results
% xgraph throu.tr
n n
% head trace.tr s 0.029365548 _1_ MAC --- 0 message 84 [0 ffffffff 1 800] ------- [1:255 -1:255 32 0]
Network Lab.
16
Network Lab.
17
NS-2 Tutorial
802.11 MAC in brief
Network Lab.
18
RTS-CTS-DATA-ACK Exchange
n
802.11 in NS-2
n
Defined in $ns/mac/mac-802_11.{h,cc}
n n
class Mac802_11 inherits class Mac defined in $ns/mac/mac{h.cc} Timers are defined in $ns/mac/mac-timers.{h.cc}
Network Lab.
21
Caution
n n
Network Lab.
States
n
RxState
n n n
TxState
n n n n n
Network Lab.
RxState
(recv_timer) rx_resume MAC_IDLE recv MAC_RECV
recv recv
Network Lab.
24
RxTimer
n n
Function recv is called when the first bit of a packet is received recv schedules recv_timer
n
mhRecv_.start(txtime(p)); o txtime returns transmission time of packet p RxTimer expires calling recvHandler o mac-timer.cc recvHandler calls recv_timer
Network Lab.
25
Function recv_timer()
n
Check for collision and error Set NAV Address filtering Calls functions based on types o recvRTS o recvCTS o recvACK o recvDATA Call rx_resume
Network Lab.
26
TxState
check_pktCTRL MAC_ACK
Network Lab.
check_pktTx MAC_SEND
27
Function transmit()
n
Called for the first bit of the transmitting packet to place on the medium
n n n n n
tx_active = 1 If rx_state is not MAC_IDLE, set error of the receiving packet send the transmitting packet set TxTimer set IFTimer
Network Lab.
28
TxTimer
n n
mhSend_.start(timeout); o timeout includes transmission time of this and its response (CTS or ACK), and their maximum propagation delay TxTimer expires calling sendHandler o mac-timer.cc sendHandler calls send_timer
Network Lab.
29
IFTimer
n n
Network Lab.
30
RTS/DATA procedure
n
n n
recv is called by both upper and lower layer Packets are ready before backoff o sendDATA, sendRTS Start backoff timer (mhBackoff) When expires, calls backoffHandler If it has RTS, calls check_pktRTS If it has data packet, calls check_pktTx
Function backoffHandler()
n n
Network Lab.
31
CTS/ACK procedure
n n
Prepare CTS and ACK Calls tx_resume When expires calls deferHandler If it has CTS or ACK, calls check_pktCTRL
n n
Function deferHandler()
n
Network Lab.
32
Timers
n n n n n
RxTimer
n
To get when it receives the last bit of the packet For packet retransmission Implement 802.11 backoff It can pause and resume
n n
TxTimer
n
BeaconTimer IFTimer
n
BackoffTimer
n n
NavTimer
n
Network Lab.
33
IFQ, but When? Set to IFQ by send() tx_resume calls callback_->handle() when there is nothing to send tx_resume is called by recvRTS, recvCTS, recvDATA, recvACK and by send_timer callback_->handle calls resume of IFQ
callback_
n n n n
Network Lab.
34