Tuesday, March 6, 2007

ns2

NS Simulator Course for Beginners
http://tagus.inesc-id.pt/~pestrela/ns2/
Trace graph
http://www.tracegraph.com/download.html

NS by Example

http://nile.wpi.edu/NS/

Ke Liu's NS2 Code

http://www.cs.binghamton.edu/~kliu/research/ns2code/index.html

NS-2 Trace Formats


http://nsnam.isi.edu/nsnam/index.php/NS-2_Trace_Formats
Marc Greis
http://www.isi.edu/nsnam/ns/tutorial/

Pedro Vale Estrela - NS2 Page

http://tagus.inesc-id.pt/~pestrela/ns2/
http://140.116.72.80/~smallko/ns2/802_11b_example.htm
802.11b ad-hoc
http://www.tracegraph.com/download.html

Ke Liu's NS2 Code (Copyright reserved) and Q & A

http://www.cs.binghamton.edu/~kliu/research/ns2code/index.html
  • How to interprete the NS2 tracefile for wireless simulation?

    To find the interpretation of all possible trace format when you do the wireless simulation, you'd better read the code of ns2 in file ns2home/trace/cmu-trace{.h, .cc} Mostly, the format would be as
    ACTION: [s|r|D]: s -- sent, r -- received, D -- dropped
    WHEN: the time when the action happened
    WHERE: the node where the action happened
    LAYER: AGT -- application,
    RTR -- routing,
    LL -- link layer (ARP is done here)
    IFQ -- outgoing packet queue (between link and mac layer)
    MAC -- mac,
    PHY -- physical
    flags:
    SEQNO: the sequence number of the packet
    TYPE: the packet type
    cbr -- CBR data stream packet
    DSR -- DSR routing packet (control packet generated by routing)
    RTS -- RTS packet generated by MAC 802.11
    ARP -- link layer ARP packet
    SIZE: the size of packet at current layer, when packet goes down, size increases, goes up size decreases
    [a b c d]: a -- the packet duration in mac layer header
    b -- the mac address of destination
    c -- the mac address of source
    d -- the mac type of the packet body
    flags:
    [......]: [
    source node ip : port_number
    destination node ip (-1 means broadcast) : port_number
    ip header ttl
    ip of next hop (0 means node 0 or broadcast)
    ]

    So we can interpret the below trace
    s 76.000000000 _98_ AGT  --- 1812 cbr 32 [0 0 0 0] ------- [98:0 0:0 32 0]
    as Application 0 (port number) on node 98 sent a CBR packet whose ID is 1812 and size is 32 bytes, at time 76.0 second, to application 0 on node 0 with TTL is 32 hops. The next hop is not decided yet.

    And we can also interpret the below trace
    r 0.010176954 _9_ RTR  --- 1 gpsr 29 [0 ffffffff 8 800] ------- [8:255 -1:255 32 0]
    in the same way, as The routing agent on node 9 received a GPSR broadcast (mac address 0xff, and ip address is -1, either of them means broadcast) routing packet whose ID is 1 and size is 19 bytes, at time 0.010176954 second, from node 8 (both mac and ip addresses are 8), port 255 (routing agent).

# A simple example for wireless simulation

#======================================================================

# Define options

#======================================================================

set val(chan) Channel/WirelessChannel ;# channel type

set val(prop) Propagation/TwoRayGround ;# radio-propagationmodel

set val(netif) Phy/WirelessPhy ;# network interface type

set val(mac) Mac/802_11 ;# MAC type

set val(ifq) Queue/DropTail/PriQueue ;# interface queue type

set val(ll) LL ;# link layer type

set val(ant) Antenna/OmniAntenna ;# antenna model

set val(ifqlen) 50 ;# max packet in ifq

set val(nn) 2 ;# number of mobilenodes

set val(rp) DSDV ;# routing protocol



# =====================================================================

# Main Program (主程式)

# =====================================================================



# 產生一個模擬的物件

set ns_ [new Simulator]
#set tracefd [open adhoc.tr w]
set tracefd [open simple.tr w]
$ns_ use-newtrace
$ns_ trace-all $tracefd
#開啟一個NAM trace file

#set nf [open out.nam w]

#$ns_ namtrace-all-wireless $nf 500 500



# set up topography object

#建立一個拓樸物件

set topo [new Topography]



# 拓樸的範圍為 500m x 500m

$topo load_flatgrid 500 500



#

# Create God

#

create-god $val(nn)



set chan_1_ [new $val(chan)]



#

# Create the specified number of mobilenodes [$val(nn)] and "attach" them

# to the channel.

# Here two nodes are created : node(0) and node(1)



# configure node

# 設置節點參數

$ns_ node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan_1_ \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace OFF



#802.11b的參數設定

#Configuration for Orinoco 802.11b 11Mbps PC card with ->22.5m range

Phy/WirelessPhy set Pt_ 0.031622777

Phy/WirelessPhy set bandwidth_ 11Mb

Mac/802_11 set dataRate_ 11Mb

Mac/802_11 set basicRate_ 1Mb

# for broadcast packets

Phy/WirelessPhy set freq_ 2.472e9

# channel-13.2.472GHz

Phy/WirelessPhy set CPThresh_ 10.0

Phy/WirelessPhy set CSThresh_ 5.011872e-12

Phy/WirelessPhy set L_ 1.0

Phy/WirelessPhy set RXThresh_ 5.82587e-09



for {set i 0} {$i < $val(nn) } {incr i} { set node_($i) [$ns_ node] $node_($i) random-motion 0 ;# disable random motion } # # Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes # # 設定節點0的位置在(10.0, 20.0, 0.0) $node_(0) set X_ 10.0 $node_(0) set Y_ 20.0 $node_(0) set Z_ 0.0 # 設定節點1的位置在(10.0, 40.0, 0.0) $node_(1) set X_ 10.0 $node_(1) set Y_ 40.0 $node_(1) set Z_ 0.0 $ns_ initial_node_pos $node_(0) 10 $ns_ initial_node_pos $node_(1) 10 # Setup traffic flow between nodes #在節點0到節點1之間建立一條FTP連線 set tcp [new Agent/TCP/Sack1] $tcp set class_ 2 set sink [new Agent/TCPSink/Sack1] $ns_ attach-agent $node_(0) $tcp $ns_ attach-agent $node_(1) $sink $ns_ connect $tcp $sink set ftp [new Application/FTP] $ftp attach-agent $tcp #在1.0秒時,開始傳送資料 $ns_ at 1.0 "$ftp start" # Tell nodes when the simulation ends for {set i 0} {$i < $val(nn) } {incr i} { $ns_ at 40.0 "$node_($i) reset"; } #在40.0秒時,結束傳送資料 $ns_ at 40.0 "stop" $ns_ at 40.01 "puts \"NS EXITING...\" ; $ns_ halt" proc stop {} { global ns_ tracefd $ns_ flush-trace close $tracefd } puts "Starting Simulation..." $ns_ run http://140.116.72.80/~smallko/ns2/802_11b_example.htm

1 comment:

Kiran Santhosh said...

Can you please tell me how to change the size of ifqLen in NS2. From tcl file I am not able to do it.

Thanks
Kiran