NS2.33基础上修改
/NS-2.33
./aodv
./aodv.cc
./aodv.h
./aodv_packet.h
./aodv_packet.cc
./aodv_rtable.h
./aodv_rtable.cc
./common
./moblienode.cc
./moblienode.h
./mac
./channel.cc
./tcl
./lib
更新上述文件。make clean->make
测试脚本TCL
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
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(rp) AODV ;# routing protocol
set val(x) 782 ;# X dimension of topography
set val(y) 545 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end
set val(ni) 3 ;#number of interface
set val(nn) 3 ;# number of mobilenodes
for {set i 0} {$i < $val(ni)} {incr i} {
set chan_($i) [new $val(chan)]
}
create-god [expr $val(nn)*$val(ni)]
#Create a ns simulator
set ns_ [new Simulator]
#Setup topography object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
#create-god $val(nn)
#Open the NS trace file
set tracefd [open multi-interface.tr w]
#$ns_ use-newtrace
$ns_ trace-all $tracefd
#Open the NAM trace file
set namfile [open multi-interface.nam w]
$ns_ namtrace-all $namfile
$ns_ namtrace-all-wireless $namfile $val(x) $val(y)
#===================================
# Mobile node parameter setup
#===================================
$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_(0) /
-topoInstance $topo /
-agentTrace ON /
-routerTrace ON /
-macTrace OFF /
-movementTrace OFF /
-ifNum $val(ni)
#===================================
# Nodes Definition
#===================================
#Create 3 nodes
$ns_ change-numifs 1
$ns_ add-channel 0 $chan_(0)
set n0 [$ns_ node]
$n0 set X_ 150
$n0 set Y_ 445
$n0 set Z_ 0.0
$ns_ initial_node_pos $n0 20
$ns_ change-numifs 2
$ns_ add-channel 0 $chan_(0)
$ns_ add-channel 1 $chan_(2)
set n1 [$ns_ node]
$n1 set X_ 382
$n1 set Y_ 443
$n1 set Z_ 0.0
$ns_ initial_node_pos $n1 20
$ns_ change-numifs 1
$ns_ add-channel 0 $chan_(2)
set n2 [$ns_ node]
$n2 set X_ 500
$n2 set Y_ 447
$n2 set Z_ 0.0
$ns_ initial_node_pos $n2 20
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns_ attach-agent $n0 $tcp0
set sink0 [new Agent/TCPSink]
$ns_ attach-agent $n2 $sink0
$ns_ connect $tcp0 $sink0
$tcp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp0
$ns_ at 1.0 "$ftp1 start"
$ns_ at 10.0 "$ftp1 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns_ tracefd namfile
$ns_ flush-trace
close $tracefd
close $namfile
exit 0
}
for {set i 0} {$i < $val(nn) } { incr i } {
$ns_ at $val(stop) "/$n$i reset"
}
$ns_ at $val(stop) "$ns_ nam-end-wireless $val(stop)"
$ns_ at $val(stop) "finish"
$ns_ at $val(stop) "puts /"done/" ; $ns_ halt"
$ns_ run