set ;# max packet in ifqset val(nn) 11 ;#

set val(chan)           Channel/WirelessChannel    ;# Channel Typeset val(prop)           Propagation/TwoRayGround ;#Nakagamiset val(netif)          Phy/WirelessPhyset val(mac)            Mac/802_11set val(ifq)             Queue/DropTail/PriQueue ;# ; CMUPriQueue ;# #;set val(ll)             LL                         ;# link layer typeset val(ant)            Antenna/OmniAntenna        ;# antenna modelset val(ifqlen)         50                         ;# max packet in ifqset val(nn)            11                    ;# number of mobilenodesset val(rp)             ;# routing protocolset val(x) 1400set val(y) 1400#set val(nam) out.nam#set val(traffic) ftp                        ;# cbr/poisson/ftp#============================================================================ Mac/802_15_4 wpanCmd verbose on Mac/802_15_4 wpanNam namStatus on#===========================================================================#Creating simulator object        set ns new Simulator;       #To open the Simulator        set nf open out.nam w        set tr open out.tr w set ns_ $ns $ns_ namtrace-all-wireless $nf $val(x) $val(y) $ns_ trace-all $tr#============================================================================= source trace.tcl $ns color 1 blue source ammnet.tcl set NoRT 3 set Sim new Sim set topo       new Topography $topo load_flatgrid $val(x) $val(y) set god_ create-god $val(nn) set nam_write new Agent/NAM_ $nam_write namattach $nfMac/802_11 set basicRate_ 11e06Phy/WirelessPhy set freq_  2.4e09Phy/WirelessPhy set CSThresh_ 1.40074e-9Phy/WirelessPhy set RXThresh_ 1.40074e-9Phy/WirelessPhy set Pt_ 0.1402#Phy/WirelessPhy set CPThresh_ .1$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)         -channelType  $val(chan) -topoInstance $topo -agentTrace ON -routerTrace ON -macTrace ON -movementTrace ON set rtr_list listfor {set i 0} {$i<$NoRT} {incr i} {   Phy/WirelessPhy set id $i       lappend  rtr_list  $i          set n($i) $ns node         $n($i) color black          set node_($i) $n($i) $node_($i) set ragent_ nam_write $nam_write         $node_($i) set netif_(0) set Pt_ Phy/WirelessPhy set Pt_ $node_($i) set ragent_ wiphy $node_($i) set netif_(0) 0.1402 #$node_($i) set ragent_ wiphy $node_($i) set netif_(0) 0.5         $node_($i) set ragent_ opt_ 3  set nd_($i) $Sim Create_RTR         $ns_ at $ns_ now "$n($i) add-mark m1 purple hexagon"         $ns at 0.1 "adv $i"         $ns at 0 "free_route $i"         $n($i) set X_ 0         $n($i) set Y_ 0}$ns_ at 25 "$nd_(0) fail"$ns at 0 "Inter_route 0"$ns at 0 "fixed_route expr $NoRT-2"$nd_(expr $NoRT-1) set fixed 1#Phy/WirelessPhy set CPThresh_ 10.0Phy/WirelessPhy set CSThresh_ 1.40074e-9Phy/WirelessPhy set RXThresh_ 1.40074e-9Phy/WirelessPhy set Pt_ 0.0277#Phy/WirelessPhy set Pt_ 0.03$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)         -channelType  $val(chan) -topoInstance $topo -agentTrace ON -routerTrace ON -macTrace ON -movementTrace ON for {set i $NoRT} {$i<$val(nn)} {incr i} {         Phy/WirelessPhy set id $i              set n($i)     $ns node         set node_($i) $n($i)         $node_($i) set ragent_ nam_write $nam_write    $node_($i) set ragent_ wiphy $node_($i) set netif_(0) 0.0277         $node_($i) set ragent_ opt_ 3 $n($i) color black set nd_($i)   $Sim Create_Client         $n($i) set X_ 0         $n($i) set Y_ 0}Phy/WirelessPhy set Pt_ 0.1402         set n(11)     $ns nodeset node_(11) $n(11) $ns_ color 1 red $ns_ color 2 purple $ns_ color 3 blue $ns_ color 4 yellow  set ln list  #Create a duplex link between the nodes  for {set i 0} {$i<$NoRT} {incr i} {  $ns duplex-link $n($i) $n(11) 10Mb 10ms DropTail  $ns duplex-link-op $n($i) $n(11) color #E5E5E5      for {set j 0} {$j<$NoRT} {incr j} {           if {$i!=$j && lsearch $ln "$i $j"==-1} {                 set lk_($i,$j) 1 set lk_($j,$i) 1                lappend ln "$i $j"                lappend ln "$j $i"                $ns duplex-link $n($i) $n($j) 10Mb 10ms DropTail                #$ns duplex-link-op $n($i) $n($j) color #E5E5E5             }         }       }#        $ns duplex-link-op $n0 $n1 color #E5E5E5          set x new Agent/UDP     ; #TCP           $ns attach-agent $n(5) $x           set app new Application/Traffic/CBR ;#Traffic/CBR           $app attach-agent $x        #Create a dest.. and attach it to node n0           set sink new Agent/Null   ;#TCPSink           $ns attach-agent $n(10) $sink           $ns connect $x $sink             $ns at 0 "$app start"           $ns at 50 "$app stop"        set RN new RNG        for {set nm  $NoRT} {$nm <$val(nn)} {incr nm} {             $ns at 1 "$n($nm) setdest $RN uniform 1 80 $RN uniform 5 250 $RN uniform 5 15"        } $ns at 22 "$n(4) setdest 67 270 15" $ns at 22 "$n(6) setdest 70 250 15" $ns at 22 "$n(9) setdest 50 240 15" $ns at 29 "$n(7) setdest 23 255 15" proc free_route {id} {        global node_ nd_         $node_($id) color red         $nd_($id) set  RTR_type 0     }     proc fixed_route {id} {        global node_ nd_         $node_($id) color #E5E5E5         $nd_($id) set  RTR_type -1     }     proc Inter_route {id} {        global node_ nd_         $node_($id) color black         $nd_($id) set  RTR_type 1          #$node_($id) setdest $node_($id) set X_ $node_($id) set Y_ 0     }      proc Intra_route {id} {        global node_ nd_         $node_($id) color green         $nd_($id) set  RTR_type 2     }proc link {} {   global n ns lk_ nd_  NoRT exchl rtr_list   set lst list   set cll lsearch $rtr_list $exchl if { $cll != -1} {  set rtr_list lreplace $rtr_list $cll $cll 11 }   for {set iop 0} {$iop < $NoRT} {incr iop} { set nm lindex $rtr_list $iop         for {set poi 0} {$poi < $NoRT} {incr poi} { set mn lindex $rtr_list $poi            if {$nm != $mn && lsearch $lst "$mn $nm" ==-1} {              $n($nm) update-pos              $n($mn) update-pos              lappend lst "$nm $mn"              lappend lst "$mn $nm"              set dist expr sqrt(pow($n($nm) set X_-$n($mn) set X_,2)+pow($n($nm) set Y_-$n($mn) set Y_,2))              if {info exist lk_($nm,$mn) == 0} {               # $ns duplex-link $n($nm) $n($mn) 10Mb 10ms DropTail #$ns at expr $ns now+0.001 "$ns duplex-link-op $n($nm) $n($mn) color #E5E5E5" set lk_($nm,$mn) 0       }              if {($dist>150 || $nd_($mn) set work == 0 || $nd_($nm) set work == 0) && $lk_($nm,$mn)==1 } {                 $ns duplex-link-op $n($nm) $n($mn) color yellow                 $ns at expr $ns now+0.005 “$ns duplex-link-op $n($nm) $n($mn) color red”                 $ns at expr $ns now+0.01 “$ns duplex-link-op $n($nm) $n($mn) color #E5E5E5 ”                 set lk_($nm,$mn) 0 set lk_($mn,$nm) 0                $nd_($nm) Delete_RTR $mn                $nd_($mn) Delete_RTR $nm              } elseif {$dist<= 150 && $lk_($nm,$mn) ==0} {                 set lk_($nm,$mn) 1 set lk_($mn,$nm) 1                 $ns duplex-link-op $n($nm) $n($mn) color yellow                 $ns at expr $ns now+0.005 "$ns duplex-link-op $n($nm) $n($mn) color green"                 $ns at expr $ns now+0.01 "$ns duplex-link-op $n($nm) $n($mn) color black"              }              if {$dist>=140 && $lk_($nm,$mn) ==1} {                  $nd_($mn) set-follower $nm   $nd_($nm) set-follower $mn               }            }         }   }   $ns at expr $ns now+1 “link”}$ns at 1 “link”proc adv {i} {  global ns n nd_  if {$nd_($i) set  RTR_type>0 && $nd_($i) set work == 1} {      $ns advertise_ $i Scan 100 3  }  $ns at expr $ns now+0.01 “adv $i”}for {set i 0} {$i < 12} {incr i} {$ns_ initial_node_pos $n($i) 10#$ns_ initial_node_pos $node_(0) 10}proc finish {} {           global ns nf           $ns flush-trace    #Close the trace file           close $nf    #Execute nam on the trace file        exec nam out.nam                exec awk -f pdf.awk out.tr > pdr &        exec awk -f OH.awk out.tr > oh &        exec awk -f drop.awk out.tr > drop & exec awk -f totalcalc.awk out.tr > analysis &  exec xgraph exist/pdr proposed/pdr &         exec xgraph exist/oh proposed/oh &        exec xgraph exist/drop proposed/drop &     exec xgraph exist/pdr_bar proposed/pdr_bar -bar -brw 1 -nl &         exec xgraph exist/oh_bar proposed/oh_bar -bar -brw 1 -nl &        exec xgraph exist/drop_bar proposed/drop_bar -bar -brw 1 -nl &            exit }     #Call the finish procedure after 5 seconds of simulation time          $ns at 30.0 “finish”    #Run the simulation           $ns run

x

Hi!
I'm Jamie!

Would you like to get a custom essay? How about receiving a customized one?

Check it out