ns2 simulation

155 views
Skip to first unread message

sadjida lebid

unread,
Aug 11, 2020, 10:21:03 AM8/11/20
to ns-u...@googlegroups.com
hello guys, i need to excute this code, please help mee

#=== Input parameters =====================================

set val(nd) [lindex $argv 0]; #distance between nodes

set val(retx) [lindex $argv 1]; #retransmission attempt for repeater

set val(filename) [lindex $argv 2]; #for different output file name

set val(cwmin) [lindex $argv 3]; #Contention Window (mininum)

set val(cwmax) [lindex $argv 4]; #Contention Window (maximum)

set val(num) [lindex $argv 5]; #number of nodes

set val(random) [lindex $argv 6]; #random number for seed

set nodedist $val(nd);

set retransmission $val(retx);

set fn $val(filename);

set cwmin $val(cwmin);

set cwmax $val(cwmax);

set random $val(random);

$defaultRNG seed $random;#deterministic into Random

#=== 802.11p default parameters ===========================

#~/ns-allinone-2.35/ns-2.35/tcl/ex/802.11/IEEE802-11p.tcl

Phy/WirelessPhyExt set CSThresh_ 3.162e-12 ;#-85 dBm Wireless interface sensitivity (sensitivity defined in the standard)

Phy/WirelessPhyExt set Pt_ 0.0003108 ;#0.00000051 for distCST_ 80.0 mts range

Phy/WirelessPhyExt set freq_ 5.9e+9

Phy/WirelessPhyExt set noise_floor_ 1.26e-13 ;#-99 dBm for 10MHz band-width

Phy/WirelessPhyExt set L_ 1.0 ;#default radio circuit gain/loss

Phy/WirelessPhyExt set PowerMonitorThresh_ 6.310e-14 ;#-102dBm power moni-tor sensitivity

Phy/WirelessPhyExt set HeaderDuration_ 0.000040 ;#40 us

Phy/WirelessPhyExt set BasicModulationScheme_ 0

Phy/WirelessPhyExt set PreambleCaptureSwitch_ 1

Phy/WirelessPhyExt set DataCaptureSwitch_ 0

Phy/WirelessPhyExt set SINR_PreambleCapture_ 2.5118; ;# 4 dB

Phy/WirelessPhyExt set SINR_DataCapture_ 100.0; ;# 10 dB

Phy/WirelessPhyExt set trace_dist_ 1e6 ;# PHY trace until distance of 1 Mio. km ("infinty")

 

Phy/WirelessPhyExt set PHY_DBG_ 0

Mac/802_11Ext set CWMin_ $cwmin

Mac/802_11Ext set CWMax_ $cwmax

Mac/802_11Ext set SlotTime_ 0.000013

Mac/802_11Ext set SIFS_ 0.000032

Mac/802_11Ext set ShortRetryLimit_ 7

Mac/802_11Ext set LongRetryLimit_ 4

Mac/802_11Ext set HeaderDuration_ 0.000040

Mac/802_11Ext set SymbolDuration_ 0.000008

Mac/802_11Ext set BasicModulationScheme_ 0

Mac/802_11Ext set use_802_11a_flag_ true

Mac/802_11Ext set RTSThreshold_ 2346

Mac/802_11Ext set MAC_DBG 0

#=== Configure RF model parameters ========================

Antenna/OmniAntenna set Gt_ 1.0

Antenna/OmniAntenna set Gr_ 1.0

#=== Node configuration options ===========================

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

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

set val(netif) Phy/WirelessPhyExt;# network interface type

set val(mac) Mac/802_11Ext;# 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) 20;# max packet in ifq

set val(nn) $val(num);# number of mobilenodes

set val(x) 2000;# X dimension of topography

set val(y) 200;# Y dimension of topography

set val(stop) 100;# time of simulation end

set val(rtg) DumbAgent;# routing protocol

#=== Create a ns simulator ================================

set ns_ [new Simulator]

#=== Setup topography object ==============================

set topo [new Topography]

$topo load_flatgrid $val(x) $val(y)

set god_ [create-god $val(nn)]

$god_ off

#=== Open the NS trace file ===============================

set tracefile [open out_$fn.tr w]

$ns_ use-newtrace

$ns_ trace-all $tracefile

#=== Open the NAM trace file ==============================

set namfile [open out_$fn.nam w]

$ns_ namtrace-all-wireless $namfile $val(x) $val(y)

#=== Configure the Nodes ==================================

set chan [new $val(chan)]

$ns_ node-config -adhocRouting $val(rtg) \

-llType $val(ll) \

-macType $val(mac) \

-ifqType $val(ifq) \

-ifqLen $val(ifqlen) \

-antType $val(ant) \

-propType $val(prop) \

-phyType $val(netif) \

-channel $chan \

-topoInstance $topo \

-agentTrace ON \

-routerTrace OFF \

-macTrace OFF\

-phyTrace OFF

 

set node_(0) [$ns_ node]

 

 

#=== Creating node objects ================================

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

set ID_($i) $i

set node_($i) [$ns_ node]

$node_($i) set id_ $ID_($i)

$node_($i) set address_ $ID_($i)

$node_($i) set X_ [expr $i * $nodedist]

$node_($i) set Y_ 50

$node_($i) set Z_ 0.0

$node_($i) random-motion 0;# disable random motion

}

#=== PBC Agents Definition ================================

for {set i 0} {$i < 1 } { incr i } {

set agent_($i) [new Agent/PBC]

$ns_ attach-agent $node_($i) $agent_($i)

$agent_($i) set payloadSize 500

$agent_($i) set periodicBroadcastInterval 0.01

$agent_($i) set periodicBroadcastVariance 0.01

$agent_($i) set modulationScheme 1

$agent_($i) singleBroadcast

#packetType (0 = safety, 1 = service)

#Safety Type packet, set the channel number to -99

$agent_($i) set channel_ -99

$agent_($i) set type_dsrc_ 0

}

for {set i 1} {$i < $val(nn)} { incr i } {

set agent_($i) [new Agent/PBC]

$ns_ attach-agent $node_($i) $agent_($i)

$agent_($i) set payloadSize 500

$agent_($i) set periodicBroadcastInterval 0.5

$agent_($i) set periodicBroadcastVariance 0.05

#$agent_($i) set modulationScheme 1

$agent_($i) Repeater ON $retransmission

#packetType (0 = safety, 1 = service)

#Safety Type packet, set the channel number to -99

$agent_($i) set channel_ -99

$agent_($i) set type_dsrc_ 0

}

#=== Define node initial position in nam ==================

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

$ns_ initial_node_pos $node_($i) 0

}

#=== Define a 'finish' procedure ==========================

proc finish {} {

global ns_ tracefile namfile

$ns_ flush-trace

close $tracefile

close $namfile

#exec nam scenario1.nam &

}

#=== Tell node to stop ====================================

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

$ns_ at $val(stop).0 "$node_($i) reset";

}

$ns_ at $val(stop) "$ns_ nam-end-wireless $val(stop)"

$ns_ at $val(stop) "finish"

$ns_ at $val(stop).0002 "puts \"End Simulation\" ; $ns_ halt"

puts "Starting Simulation..."

$ns_ run 
--
                     Lebid Sadjida 
Etudiante en Master 2 Réseaux et Télécommunications. 
Département de Télécommunication.
Faculté de Génie Electrique.
Université Djilali Liabes de Sidi Bel Abbes.

knudfl

unread,
Aug 11, 2020, 12:45:53 PM8/11/20
to Network Simulator 2 (NS2)
Hi.

Please edit section "$ns_ node-config", lines 155 .. 168.
A backslash means "this sentence will continue in the next line"
.... which will fail when the following line is empty.
(This error is well known. Happens e.g. when copying text from a HTML site / a file.html ).

Edited to ....
$ns_ node-config -adhocRouting $val(rtg) \
    -llType $val(ll) \
    -macType $val(mac) \
    -ifqType $val(ifq) \
    -ifqLen $val(ifqlen) \
    -antType $val(ant) \
    -propType $val(prop) \
    -phyType $val(netif) \
    -channel $chan \
    -topoInstance $topo \
    -agentTrace ON \
    -routerTrace OFF \
    -macTrace OFF \
    -phyTrace OFF




sadjida lebid

unread,
Aug 11, 2020, 1:03:52 PM8/11/20
to ns-u...@googlegroups.com
I didn't understand sir,
that section is correct as you have written it.
Would you please explain to me. 
thank you

--
You received this message because you are subscribed to the Google Groups "Network Simulator 2 (NS2)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-users+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-users/cfed40b5-8406-4489-b473-ccee7937d0b5n%40googlegroups.com.

sadjida lebid

unread,
Aug 11, 2020, 1:29:10 PM8/11/20
to ns-u...@googlegroups.com
these are the errors :

image.png
 

knudfl

unread,
Aug 11, 2020, 1:34:41 PM8/11/20
to Network Simulator 2 (NS2)
Lines 155 .. 168 :  No spacing between the lines is allowed. Your copy in the first posting has double "line feeds".

Correct is .....
$ns_ node-config -adhocRouting $val(rtg) \
    -llType $val(ll) \
    -macType $val(mac) \
    -ifqType $val(ifq) \
    -ifqLen $val(ifqlen) \
    -antType $val(ant) \
    -propType $val(prop) \
    -phyType $val(netif) \
    -channel $chan \
    -topoInstance $topo \
    -agentTrace ON \
    -routerTrace OFF \
    -macTrace OFF\
    -phyTrace OFF

sadjida lebid

unread,
Aug 11, 2020, 3:59:08 PM8/11/20
to ns-u...@googlegroups.com
Hello, ah okay understood,
Now the error shown :   
              node 0 is not defined...missing required flag -x in w -t 100
                    missing required flag -y in w -t 100  
                    parsing error in event
                    node 0 is not defined...
What should i do now sir ??


knudfl

unread,
Aug 11, 2020, 6:44:04 PM8/11/20
to Network Simulator 2 (NS2)
Hi.

May have something to do with with some missing arguments. There are theoretically seven :
[lindex $argv 0]  ....  ....  [lindex $argv 6]
.... see the first lines in your file.

Not unusual in an ns2 command. Can be like : $ ns file.tcl 1 2 2 4
... I did try out some various commands : $ ns usman.tcl 30 2 0 5 10 10 0.1    etc. etc. but they all failed.

sadjida lebid

unread,
Aug 12, 2020, 2:49:14 PM8/12/20
to ns-u...@googlegroups.com
hello sir, 
when i tried what you said, this is what happened :
image.png

knudfl

unread,
Aug 12, 2020, 10:56:33 PM8/12/20
to Network Simulator 2 (NS2)
Hi.

First :  Images with text are not at all appreciated
"You should avoid posting pictures of text. Pictures can be hard to read. Text is easier to read in different screen formats, can be copied and pasted, as well as is search engine addressable, making it easier for people to reach this post who may have a similar issue."
My comments : I guess you know how to copy-paste a text.

About "$ ns usman.tcl 30 2 0 5 10 10 0.1" : 
I didn't suggest this. I specifically mentioned that  none of the arguments I tried out were working.

sadjida lebid

unread,
Aug 13, 2020, 5:38:19 AM8/13/20
to ns-u...@googlegroups.com
Hello,

Sorry about that sir, I know it's not recommended but I have a problem when I copy paste from virtual machine/windows to windows/virtual machine (m using Fedora virtual machine with virtual box)it didn't work even the clipboard is bidirectional so that's why I posted an image.

I know it didn't work for you, I just wanted to show you what it showed me cuz I'm struggling with this code, I couldn't execute it, I'm stuck in this step.
Thank you.

Reply all
Reply to author
Forward
0 new messages