I have to simulate a network with N 802.11 nodes associated with the same
Access Point where all nodes can hear each other. Every node has a CBR
source over UDP, except the node 1 with a CBR source over TCP, towards the
AP, while on the access point there are N sources CBR over UDP for each node
in the network.
I try to do my best, but it's my first script, and it doesn't work.
here's the code

#
# ======================================================================
# Define options
# ======================================================================
#
  set opt(chan)       Channel/WirelessChannel
  set opt(netif)      Phy/WirelessPhy
  set opt(mac)        Mac/802_11
  set opt(ifq)        Queue/DropTail/PriQueue
  set opt(prop)       Propagation/Shadowing
  set opt(ll)         LL
  set opt(ant)        Antenna/OmniAntenna
  set opt(x)          100       ;# X dimension of the topography
  set opt(y)          100       ;# Y dimension of the topography
  set opt(ifqlen)     50        ;# max packet in ifq
  set opt(seed)       0.0       ;# seed for ns-2 rand()
  set opt(nn)         10        ;# how many wireless nodes are simulated
  set opt(rp)         DumbAgent ;# No Routing protocol
  set opt(stop)       150       ;# simulation time

# UDP Agent
Agent/UDP set packetSize_         2000     ;# now the default maximum
segment size is 2000 bytes
                                           ;# so the 1500 byte packet is not
fragmented
Mac/802_11 set RTSThreshold_      3000     ;# disable RTS/CTS
Mac/802_11 set ShortRetryLimit_   4
Mac/802_11 set CWMin_             31
Mac/802_11 set CWMax_             1023

# FHSS (IEEE 802.11)
Mac/802_11 set SlotTime_       0.000020
Mac/802_11 set SIFS_           0.000010
Mac/802_11 set PreambleLength_       64
Mac/802_11 set PLCPHeaderLength_    128
Mac/802_11 set PLCPDataRate_      1.0e6
Mac/802_11 set dataRate_          11.0e6
Mac/802_11 set basicRate_         2.0e6

# Physical layer
Phy/WirelessPhy set CPThresh_ 9999 ;# I put a high value so as if 2 stations
transmit simultaneously towards the AP a collision would definitely occur
Phy/WirelessPhy set CSThresh_ 9.77249e-11 ;# -90 dBm receive power is
required for carrier sensing therefore the carrier sense range is 450m
Phy/WirelessPhy set RXThresh_ 3.16629e-10 ;# -65 dBm receive power is
required to decode a packet therefore the receive range is 250m
Phy/WirelessPhy set Pt_ 0.2818
Phy/WirelessPhy set freq_ 2.4e+9



#
# ======================================================================
# Main Program
# ======================================================================
#
  set ns_                       [new Simulator]
  set god_                      [create-god [expr $opt(nn)+1]]
  
  set tracefd                   [open out.tr w]
  
  $ns_ trace-all $tracefd
  
  set tracenam                   [open out.nam w]
  $ns_ namtrace-all-wireless $tracenam $opt(x) $opt(y)
  
  set simDataRate [Mac/802_11 set dataRate_]
#
#-----------------------------------------------------------------------
#
  set topo [new Topography]
  $topo load_flatgrid $opt(x) $opt(y)
 
  set chan_ [new $opt(chan)]

set namtrace      [open out.nam w]    

$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace 100 100

  
  $ns_ node-config -adhocRouting $opt(rp) \
                   -llType $opt(ll) \
                   -macType $opt(mac) \
                   -ifqType $opt(ifq) \
                   -ifqLen $opt(ifqlen) \
                   -propType $opt(prop) \
                   -antType $opt(ant) \
                   -phyType $opt(netif) \
                   -topoInstance $topo \
                   -wiredRouting ON \
                   -agentTrace ON \
                   -routerTrace OFF \
                   -macTrace ON \
                   -movementTrace ON \
                   -channel $chan_ \
                 
#
#------------------------------------------------------------------------
#
  set degrees [expr 360/$opt(nn)]
  set rad [expr $degrees*3.1415927/180]

  $ns_ node-config   -wiredRouting OFF 

#create a node by specifying the address as a parameter after the method
node
  set Access_Point [$ns_ node 0]

  $Access_Point random-motion 0

  $Access_Point set X_ 30.0
  $Access_Point set Y_ 30.0
  $Access_Point set Z_ 0.0
  $ns_ at 0 "$Access_Point setdest 30. 30. 1000"
  
  puts "Access Point coord. X=[$Access_Point set X_] Y=X=[$Access_Point set
Y_]"      

  for {set j 0} {$j < $opt(nn)} {incr j} {

#create a node by specifying the address 0.0.x that we have memorized in the
addr_domain vector
      set node_($j) [$ns_ node [expr $j+1]]
      $node_($j) random-motion 0
      $node_($j) set X_ 30
      $node_($j) set Y_ 30
  }

#Mobile nodes are placed in a circle around the access point
  for {set j 0} {$j < $opt(nn)} {incr j} {
      set coseno [expr cos([expr $j * $rad])]
      set seno [expr sin([expr $j * $rad])]
      $ns_ at 0 "$node_($j) setdest [expr 30 + 20 * $coseno] [expr 30 + 20 *
$seno] 1000."
      puts "placing node $j: X=[format %.2f [expr 30+20*$coseno]] Y=[format
%.2f [expr 30+20*$seno] ]"
  }
#
#-------------------------------------------------------------------------
# TRAFFIC
#-------------------------------------------------------------------------
#
  proc attach-cbr-traffic { node sink size rate } {
        global ns_
        set udp [new Agent/UDP]
        $ns_ attach-agent $node $udp
        set traffic [new Application/Traffic/CBR]
        $traffic set packetSize_ $size
        $traffic set rate_ $rate
        $traffic attach-agent $udp
        $ns_ connect $udp $sink
        return $traffic
  }

  proc attach-cbr-traffic-S1 { node sink size rate } {
        global ns_
        set tcp [new Agent/TCP]
        $ns_ attach-agent $node $tcp
        set traffic [new Application/Traffic/CBR]
        $traffic set packetSize_ $size
        $traffic set rate_ $rate
        $traffic attach-agent $tcp
        $ns_ connect $tcp $sink
        return $traffic
 }

#
#--------------------------------------------------------------------------
#
# Access Point -> Receiver, Mobile Nodes --> Transmitters

 set src_rate 2.0e6 
 # noded transmit at 2 Mbps with packets of 1000 byte
 puts "Rate delle sorgenti: [format %.2f $src_rate]"

 for {set j 1} {$j < $opt(nn)} {incr j} {
   set sink_($j) [new Agent/LossMonitor]
   $ns_ attach-agent $Access_Point $sink_($j)
   set src($j) [attach-cbr-traffic $node_($j) $sink_($j) 1000 $src_rate]
   $ns_ at 1.0 "$src($j) start"
   $ns_ at $opt(stop) "$src($j) stop"
 }

# node 1 has the only TCP source
 set sink_(0) [new Agent/LossMonitor]
 $ns_ attach-agent $Access_Point $sink_(0)
 set node_(0) [$ns_ node 1]
 set src(0) [attach-cbr-traffic-S1 $node_(0) $sink_(0) 1000 $src_rate]
 $ns_ at 1.0 "$src(0) start"
 $ns_ at $opt(stop) "$src(0) stop"

# Mobile nodes -> Receivers, Access Point -> Transmitter
 set AP_rate 2.0e6
 puts "Rate dell'Access Point: [format %.2f $AP_rate]"

 for {set j 0} {$j < $opt(nn)} {incr j} {
   set sink_($j) [new Agent/LossMonitor]
   $ns_ attach-agent $node_($j) $sink_($j)
   set src($j) [attach-cbr-traffic $Access_Point $sink_($j) 500 $AP_rate]
   $ns_ at 0.5 "$src($j) start"
   $ns_ at $opt(stop) "$src($j) stop"
 }


#
#Tracing... 
 for {set j 0} {$j < $opt(nn)} {incr j} {
   set trace_file_($j) [open bw_node_$j.tr w]
   set bytes_file_($j) [open bytes_rx_$j.tr w]
  }

set total_byte 0

  proc record {node sink sink_f sink_trace_f} {

        global  ns_
        global total_byte
        set time 1.
        set bw_($node) [$sink set bytes_]
        set now [$ns_ now]
        puts $sink_trace_f "[format %.2f $now ] [expr
double($bw_($node)*8.)/$time/1000] Kbps"
        incr total_byte $bw_($node)
        $sink set bytes_ 0
        $ns_ at [expr $now+$time] "record {$node} {$sink} {$sink_f}
{$sink_trace_f}"
  }


#
#Finishing...
  proc finish {trace_file bytes_file} {
        global ns_ tracefd total_byte opt
        $ns_ flush-trace
        close $trace_file
        close $bytes_file
        close $tracefd
        puts "Total throughput [format %.2f [expr
$total_byte*8./($opt(stop)-1)/1000000.]] Mbps"
        exit 0
  }

   for {set j 0} {$j < $opt(nn)} {incr j} {
        $ns_ at 0.100 "record {$j} {$sink_($j)} {$bytes_file_($j)}
{$trace_file_($j)}"
        $ns_ at $opt(stop) " finish {$trace_file_($j)} {$bytes_file_($j)}"
}
#
#------------------------------------------------------------------------------
# Tell nodes when the simulation ends
#------------------------------------------------------------------------------
#
  for {set i 0} {$i < $opt(nn) } {incr i} {
      $ns_ at $opt(stop).001 "$node_($i) reset";
  }
  $ns_ at  $opt(stop).0002 "puts \"NS EXITING!\" ; $ns_ halt"
  


$ns_ run

Please help me

-- 
View this message in context: 
http://old.nabble.com/802.11-simulation-tp29846504p29846504.html
Sent from the ns-users mailing list archive at Nabble.com.

Reply via email to