You are on page 1of 7

#############################################################################

# Define simulation options

#############################################################################

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

set opt(prop) Propagation/TwoRayGround ;# radio-propagation model

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

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

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

set opt(ll) LL ;# link layer type

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

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

set opt(row) 3;

set opt(col) 3;

set opt(nn) [expr $opt(row)*$opt(col)] ;# number of mobilenodes

set opt(dist) 100; #distance between nodes

set opt(flow) [lindex $argv 2] ;# number of flows

set opt(sd) [lindex $argv 1] ;# number of shutdowns

set opt(offtime) 4.0 ;# shutdown time

set opt(rp) AODV ;# routing protocol

set opt(MaxX) 300; # X dimension of topography

set opt(MaxY) 400 ;# Y dimension of topography

set opt(stop) 150.0 ;# time of simulation end

set opt(energy) EnergyModel;

set opt(initialenergy) 11000;

set opt(txPower) 0.660;

set opt(rxPower) 0.395;


set opt(idlePower) 0.035;

Mac/802_11 set dataRate_ 2Mb;

Mac/802_11 set basicRate_ 1Mb;

Phy/WirelessPhy set CPThresh_ 10.0;

Phy/WirelessPhy set CSThresh_ 1.559e-11;

Phy/WirelessPhy set bandwidth_ 2e6;

Phy/WirelessPhy set Pt_ 0.2818;

Phy/WirelessPhy set freq_ 914e+6;

Mac/802_11 set dataRate_ 2.0e6;

#############################################################################

# Initialization and configuration

#############################################################################

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

# ns simulator

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

set ns_ [new Simulator]

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

# NAM

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

set nf [open TP2.nam w]

$ns_ namtrace-all $nf


$ns_ namtrace-all-wireless $nf $opt(MaxX) $opt(MaxY)

#set chan_1_ [new $opt(chan)]

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

# Trace File

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

set tracefile [open TP2.tr w]

$ns_ trace-all $tracefile

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

# Topologie

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

set topo [new Topography]

$topo load_flatgrid $opt(MaxX) $opt(MaxY)

set god [create-god $opt(nn)]

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

# color

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

$ns_ color 1 Blue

$ns_ color 2 Red


$ns_ color 3 Green

$ns_ color 4 Yellow

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

# nodes configuration

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

$ns_ node-config -adhocRouting $opt(rp) \

-llType $opt(ll) \

-macType $opt(mac) \

-ifqType $opt(ifq) \

-ifqLen $opt(ifqlen) \

-antType $opt(ant) \

-propType $opt(prop) \

-phyType $opt(netif) \

-channelType $opt(chan) \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace ON \

-movementTrace ON \

-energyModel $opt(energy) \

-initialEnergy $opt(initialenergy) \

-txPower $opt(txPower) \

-rxPower $opt(rxPower) \

-idlePower $opt(idlePower)
#===================================

# nodes initial positions

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

# Define node initial position in nam

for {set i 0} {$i < $opt(row) } { incr i } {

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

set nodenum [expr ($i*$opt(col))+($j)]

set node_($nodenum) [$ns_ node $nodenum]

set xpos [expr ($i+1)*$opt(dist)]

set ypos [expr ($j+1)*$opt(dist)]

$node_($nodenum) set X_ $xpos

$node_($nodenum) set Y_ $ypos

$node_($nodenum) set Z_ 0.0

$node_($nodenum) random-motion 0

$ns_ initial_node_pos $node_($nodenum) 20

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

# Nodes Color

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

$node_(0) color red

$node_(0) shape circle


$node_([expr $opt(nn)-1]) color green

$ns_ at 0.0 "$node_(0) color red"

$ns_ at 0.0 "$node_(0) label Emetteur"

$ns_ at 0.0 "$node_([expr $opt(nn)-1]) color blue"

$ns_ at 0.0 "$node_([expr $opt(nn)-1]) label Recepteur"

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

# Communication Set up

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

set tcp [new Agent/TCP]

set sink [new Agent/TCPSink]

$ns_ attach-agent $node_(0) $tcp

$ns_ attach-agent $node_([expr $opt(nn)-1]) $sink

$ns_ connect $tcp $sink

set ftp [new Application/FTP]

$ftp attach-agent $tcp

$ns_ at 0.01 "$ftp start"

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

# Termination

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

proc finish {} {

global ns_ tracefile

$ns_ flush-trace

close $tracefile

puts "simulation completed"


exit 0

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

$ns_ at $opt(stop) "\$node_($i) reset"

$ns_ at $opt(stop) "finish"

$ns_ at $opt(stop) "puts \"done\" ; $ns_ halt"

$ns_ run

You might also like