# ====================================================================== # Define options # ====================================================================== set val(chan) Channel/WirelessChannel ; # channel type set val(prop) Propagation/TwoRayGround ; #radio-propagationmodel set val(netif) Phy/WirelessPhy ; # networkinterfacetype 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 #Energy Model set opt(energymodel) EnergyModel; set opt(rxPower) 0.3; #recieve Energy, in W set opt(txPower) 0.5; #send Energy, in W set opt(initialenergy) 0.015; # Initial energy in Joules # Create channel #1 and #2 (explained in tcl/ex/wireless-mitf.tcl) set chan_1_ [new $val(chan)] set chan_2_ [new $val(chan)] #====================================================================== # #Main Program #====================================================================== # #Initialize Global Variables set ns [new Simulator] set tracefd [open p2p.tr w] ;# for wireless traces $ns trace-all $tracefd set namtrace [open p2p.nam w] ;# for nam tracing $ns namtrace-all-wireless $namtrace 500 500 set topo [new Topography] $topo load_flatgrid 500 500 #God object: is the object that is used to store global #information about the state of the environment, network or nodes that an #omniscent observer would have, but that should not be made known to any #participant in the simulation create-god $val(nn) #procedure that closes the trace file and starts nam proc finish {} { global ns tracefd $ns flush-trace close $tracefd # exec nam p2p.nam & exit 0 } #The configuration API for creating mobilenodes looks as follows: # Configure nodes $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) \ -topoInstance $topo \ -channel $chan_1_ \ -agentTrace ON \ -routerTrace ON \ -macTrace OFF \ -movementTrace OFF\ -energyModel $opt(energymodel) \ -rxPower opt(rxPower) \ -txPower opt(txPower) \ -initialEnergy $opt(initialenergy) #create the 2 mobilenodes as follows: set node_0 [$ns node] $ns node-config -channel $chan_2_ set node_1 [$ns node] $node_0 random-motion 0 ; #disable random motion $node_1 random-motion 0 ; #In ns, data is always being sent from one 'agent' to another. #Create a UDP agent and attach it to node n0 set udp0 [new Agent/UDP] ns attach-agent $node_0 $udp0 #Create a CBR traffic source and attach it to udp0 #CBR = Constant Bit Rate set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 $cbr0 attach-agent $udp0 #The next lines create a Null agent which acts as traffic sink and attach it #to node n1. set null0 [new Agent/Null] $ns attach-agent $node_1 $null0 #Now the two agents have to be connected with each other. $ns connect $udp0 $null0 #$ns at 0.5 "$cbr0 start" #$ns at 49.5 "$cbr0 stop" $ns at 50.0 "finish" $ns run