how to add wormhole node LAR ns2?

214 views
Skip to first unread message

Hasan sabiq

unread,
Feb 18, 2022, 10:05:23 PM2/18/22
to Network Simulator 2 (NS2)


#set n0 [$ns node]
#$ns initial_node_pos $n0 30




set val(chan)   Channel/WirelessChannel    ;# channel type
set val(prop)   Propagation/TwoRayGround   ;# radio-propagation model
set val(netif)  Phy/WirelessPhy            ;# network interface type
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)     20                        ;# number of mobilenodes
set val(rp)     AODV                       ;# routing protocol
set val(x)      1000                      ;# X dimension of topography
set val(y)      1000                      ;# Y dimension of topography
set val(seed)       1.0                       ;
set val(dataStart)  0.0                       ;
set val(dataStop)   998                    ;
set val(signalStop) 999                     ;
set val(minSpeed) 0.5                      ;# movement minimum speed [m/s]
set val(maxSpeed) 1.5                      ;# movement maximum speed [m/s]
set val(minPause) 0.0                      ;# movement minimum pause time [s]
set val(maxPause) 0.0                      ;# movement maximum pause time [s]
set val(mobility) Static           ;# mobility model
set val(stop)     1000                      ;
#set val(wormholes) 1;

Queue/DropTail/PriQueue set Prefer_Routing_Protocols 1
# =====================================================================
# Other default settings
puts "setting other default settings..."
LL set mindelay_ 50us
LL set delay_ 25us
LL set bandwidth_ 0 ;

Agent/Null set sport_ 0
Agent/Null set dport_ 0
Agent/CBR set sport_ 0
Agent/CBR set dport_ 0
Agent/TCPSink set sport_ 0
Agent/TCPSink set dport_ 0
Agent/TCP set sport_ 0
Agent/TCP set dport_ 0
Agent/TCP set packetSize_ 512
# unity gain, omni-directional antennas
# set up the antennas to be centered in the node and 1.5 meters above it
Antenna/OmniAntenna set X_ 0
Antenna/OmniAntenna set Y_ 0
Antenna/OmniAntenna set Z_ 0.25
Antenna/OmniAntenna set Gt_ 1
Antenna/OmniAntenna set Gr_ 1


# Initialize the SharedMedia interface with parameters to make
# it work like the 914MHz Lucent WaveLAN DSSS radio interface
Phy/WirelessPhy set CPThresh_ 10.0
Phy/WirelessPhy set CSThresh_ 9.21756e-11
Phy/WirelessPhy set RXThresh_ 4.4613e-10
Phy/WirelessPhy set Rb_ 2*1e6
#this was the default
#Phy/WirelessPhy set Pt_ 0.2818
# This is for 100m
Phy/WirelessPhy set Pt_ 8000.2818
# This is for 40m
#Phy/WirelessPhy set Pt_ 8.5872e-4
# This is for 250m
#Phy/WirelessPhy set Pt_ 0.2818
Phy/WirelessPhy set freq_ 2.4e+9
Phy/WirelessPhy set L_ 1.0

# =====================================================================
# This puts in only the headers that we need.
# =====================================================================
puts "removing unecessary packet headers..."
remove-all-packet-headers
add-packet-header IP
add-packet-header Common
add-packet-header LAR
add-packet-header LL
add-packet-header Mac
add-packet-header ARP
add-packet-header Flags
add-packet-header TCP
add-packet-header AODV
add-packet-header Message
add-packet-header RTP
add-packet-header LOCS
add-packet-header SR
add-packet-header RTP
add-packet-header Ping
add-packet-header HLS

# seeding RNG
ns-random $val(seed)
#===================================
#        Initialization        
#===================================
#Create a ns simulator
set ns_ [new Simulator]

#nametrace
set nf [open 1.nam w]
$ns_ namtrace-all-wireless $nf $val(x) $val(y)

#Open a trace file
set nt [open 1.tr w]
$ns_ trace-all $nt

#setupTopography
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)

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

set chan [new $val(chan)];

ns-random $val(seed)

#global node setting
puts "setting global node values..."
$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) \
                 -channel $chan \
                 -topoInstance $topo \
                 -agentTrace ON \
                 -routerTrace ON \
                 -macTrace OFF \
               
               
# Pseudo-random sequence generator
# General pseudo-random sequence generator
set genSeed [new RNG]
$genSeed seed $val(seed)
set randomSeed [new RandomVariable/Uniform]
$randomSeed use-rng $genSeed
$randomSeed set min_ 2.0
$randomSeed set max_ 100.0

# Mobility model: x node position [m]
set genNodeX [new RNG]
$genNodeX seed [expr [$randomSeed value]]
set randomNodeX [new RandomVariable/Uniform]
$randomNodeX use-rng $genNodeX
$randomNodeX set min_ 1.0
$randomNodeX set max_ [expr $val(x) - 1.0]

# Mobility model: y node position [m]
set posNodeY [new RNG]
$posNodeY seed [expr [$randomSeed value]]
set randomNodeY [new RandomVariable/Uniform]
$randomNodeY use-rng $posNodeY
$randomNodeY set min_ 1.0
$randomNodeY set max_ [expr $val(y) - 1.0]

# Mobility model: node speed [m/s]
set genNodeSpeed [new RNG]
$genNodeSpeed seed [expr [$randomSeed value]]
set randomNodeSpeed [new RandomVariable/Uniform]
$randomNodeSpeed use-rng $genNodeSpeed
$randomNodeSpeed set min_ $val(minSpeed)
$randomNodeSpeed set max_ $val(maxSpeed)

# Mobility model: node movement pause [s]
set genNodePause [new RNG]
$genNodePause seed [expr [$randomSeed value]]
set randomNodePause [new RandomVariable/Uniform]
$randomNodePause use-rng $genNodePause
$randomNodePause set min_ $val(minPause)
$randomNodePause set max_ $val(maxPause)

# Data pattern: node
set genNode [new RNG]
$genNode seed [expr [$randomSeed value]]
set randomNode [new RandomVariable/Uniform]
$randomNode use-rng $genNode
$randomNode set min_ 0
$randomNode set max_ [expr $val(nn) - 1]

# ------------------------------------------------------------------------------
# Nodes definition
# ------------------------------------------------------------------------------
#  Create the specified number of nodes [$val(nn)] and "attach" them to the channel.
for {set i 0} {$i < $val(nn) } {incr i} {
  set node_($i) [$ns_ node]
  $node_($i) random-motion 0        ;# disable random motion
}

# ------------------------------------------------------------------------------
# Nodes mobility
# ------------------------------------------------------------------------------
if {$val(mobility) == "Static"} {
  for {set i 0} {$i < $val(nn)} {incr i} {
    set X [expr [$randomNodeX value] ]
    $node_($i) set X_ $X
    set Y [expr [$randomNodeY value] ]
    $node_($i) set Y_ $Y
    $node_($i) set Z_ 0.0
    $ns_ initial_node_pos $node_($i) 20
    #puts $scenarioTrc "\$node_($i) set X_ $X"
    #puts $scenarioTrc "\$node_($i) set Y_ $Y"
    #puts $scenarioTrc "\$node_($i) set Z_ 0.0"
  }
}

for {set i 0} {$i < $val(nn)} {incr i} {
    set xx_ [$randomNodeX value]
    set yy_ [$randomNodeY value]
    set spd_ [$randomNodeSpeed value]
#    set rng_time [expr rand()*$val(stop)]
    $ns_ at 0 "$node_($i) setdest $xx_ $yy_ $spd_"   ;# random movements
}

# configure Wormholes

        #puts "Making first wormhole"
        set n14 [$ns node]
        $n14 set X_ 300.0
        $n14 set Y_ 500.0
        $n14 set Z_ 0.0
        $ns initial_node_pos $n14 20    
        $ns at 0.01 "$n14 label \"wormhole1\""

        set n15 [$ns node]
        $n15 set X_ 900.0
        $n15 set Y_ 300.0
        $n15 set Z_ 0.0
        $ns initial_node_pos $n15 20
        $ns at 0.01 "$n15 label \"wormhole2\""
                 
 
[$n14 set ll_(0)] wormhole-peer [$n15 set ll_(0)]
#[$n15 set ll_(0)] wormhole-peer [$n14 set ll_(0)]

#Create lar agents and attach them to the nodes
puts "creating lar agents and attaching them to nodes..."
for {set i 0} {$i < $val(nn)} {incr i} {
  set g($i) [new Agent/LAR]
  $node_($i) attach $g($i) 254

  # need to tell the lar agents about their link layers
  set ll($i) [$node_($i) set ll_(0)]
  $ns_ at 0.0 "$g($i) set-ll $ll($i)"

  # need to tell the lar agents which nodes they're on also
  $ns_ at 0.0 "$g($i) set-node $node_($i)"
}

puts "Scheduling the send events"
for {set k $val(dataStart)} {$k < $val(dataStop)} {set k [expr $k + 0.25] } \
{
  $ns_ at $k "$g(0) sendData 49 64 S"
  $ns_ at [expr $k + .0001] "$g(1) sendData 48 64 S"
  $ns_ at [expr $k + .0002] "$g(2) sendData 47 64 S"
  $ns_ at [expr $k + .0003] "$g(3) sendData 46 64 S"
  $ns_ at [expr $k + .0004] "$g(4) sendData 45 64 S"
  $ns_ at [expr $k + .0005] "$g(5) sendData 44 64 S"
  $ns_ at [expr $k + .0006] "$g(6) sendData 43 64 S"
  $ns_ at [expr $k + .0007] "$g(7) sendData 42 64 S"
  $ns_ at [expr $k + .0008] "$g(8) sendData 41 64 S"
  $ns_ at [expr $k + .0009] "$g(9) sendData 40 64 S"
  $ns_ at [expr $k + .0010] "$g(10) sendData 39 64 S"
  $ns_ at [expr $k + .0011] "$g(11) sendData 38 64 S"
  $ns_ at [expr $k + .0012] "$g(12) sendData 37 64 S"
  $ns_ at [expr $k + .0013] "$g(13) sendData 36 64 S"
  $ns_ at [expr $k + .0014] "$g(14) sendData 35 64 S"
  $ns_ at [expr $k + .0015] "$g(15) sendData 34 64 S"
  $ns_ at [expr $k + .0016] "$g(16) sendData 33 64 S"
  $ns_ at [expr $k + .0017] "$g(17) sendData 32 64 S"
  $ns_ at [expr $k + .0018] "$g(18) sendData 31 64 S"
  $ns_ at [expr $k + .0019] "$g(19) sendData 30 64 S"
}


#Setup a UDP connection
set udp1 [new Agent/UDP]
$ns_ attach-agent $node_(0) $udp1
set null1 [new Agent/Null]
$ns_ attach-agent $node_(40) $null1
$ns_ connect $udp1 $null1
$udp1 set packetSize_ 512
 

#Setup a CBR Application over UDP connection
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$cbr1 set type_ CBR
$cbr1 set packetSize_ 512
$cbr1 set rate_ 512kb
$cbr1 set interval_ 0.25
$cbr1 set random_ false

$ns_ at 0.0 "$cbr1 start"
 

# this is done to make the simulator continue running and "settle" things out
for {set i 0} {$i < $val(nn)} {incr i} {
  $ns_ at $val(signalStop) "$g($i) larDone"
}

$ns_ at $val(stop) "stop"
$ns_ at [expr $val(stop) + 0.1] "puts \"NS Exiting...\" ; $ns_ halt"

for {set i 0} {$i < 100} {incr i} {
    $ns_ at [expr $i * $val(stop) / 100] "puts \" ... $i % into sim ....\""
}
 

proc stop {} {
        global ns_ nt nf
        $ns_ flush-trace
        close $nt
        close $nf
}
$ns_ run

knudfl

unread,
Feb 19, 2022, 6:06:12 PM2/19/22
to Network Simulator 2 (NS2)
Typos in your file : ns can be defined as either ns_ or ns, not both.
The file "Static" is missing. A copy of 'mob.2' was used for testing.
Editing your code: Settings, definitions from box-Helen.tcl were used
https://drive.google.com/file/d/1rhwBqs-_s6eZF4bqQR-c5x7Ut89i0NXd/view?usp=sharing

Creating an executable ns+LAR can be created with an old OS.
Example OS : CentOS 6.10, Ubuntu 10.10 .

Wormhole code can be added with `wormhole_ns235.patch´
https://drive.google.com/file/d/1YErI9TdsZjjgIRDjoRgZMLi0u-zM1WWy/view?usp=sharing
$ cd ns-allinone-2.35/ && patch -p0 < wormhole_ns235.patch && ./install

The LAR code I am using for ns-2.35 is `LAR-dream__ns235.patch`
https://drive.google.com/file/d/0B7S255p3kFXNdVlhckRMMTcxalk/view?usp=sharing
Patches are available for ns-2.32, -2.33, -2.34 too.
See ns2-patches https://drive.google.com/drive/folders/0B7S255p3kFXNZ2lWZDBRSW40Q00?resourcekey=0-eBw6mJFKhSVGultqaD2rDA&usp=sharing
--------------

Examples of your edited file ....
Plain LAR : h-lar2022-edit-3.tcl
LAR + wormhole : h-lar2022-edit-5worm.tcl    (dataStart)  1000.0
LAR + wormhole : h-lar2022-edit-6-worm.tcl   (dataStart)  1.0

-

knudfl

unread,
Feb 21, 2022, 8:18:51 AM2/21/22
to Network Simulator 2 (NS2)
New LAR "overview" :   _LAR-simulations.txt ,  lar+dream-examples-02.22.tar.xz

Hasan sabiq

unread,
Feb 23, 2022, 12:49:03 AM2/23/22
to Network Simulator 2 (NS2)
Sorry sir, I just try the coding that you suggest to me now.
from the results of the tcl test, the program can run perfectly. but there is something I want to ask, after running the tcl program that you gave. Wormhole nodes in the network do not move at all. is it like that or is there a code error in it?
I have attached the screen shot as follows:
WhatsApp Image 2022-02-23 at 12.28.46.jpeg
this is the result of NAM from the TCL program that you gave, and the wormhole node didn't move.
and then i just try to modify your TCL program that initiation the wormhole node:
WhatsApp Image 2022-02-23 at 12.30.54.jpeg
from this
to this
WhatsApp Image 2022-02-23 at 12.30.42.jpeg
i think if i delet the $n15 set X and Y. the wormhole node will be moving like other node move. 
but iam wrong, the NAM result show that worm hole node 1 and wormhole node 2 is be in the same position.
like this:
WhatsApp Image 2022-02-23 at 12.30.26.jpeg
can you help me sir? 

Hasan sabiq

unread,
Feb 23, 2022, 12:53:01 AM2/23/22
to Network Simulator 2 (NS2)
First of all, I would like to thank you for replying to my question regarding the addition of the previous wormhole node.

Hasan sabiq

unread,
Feb 28, 2022, 10:14:15 AM2/28/22
to Network Simulator 2 (NS2)
Sorry sir, I just try the coding that you suggest to me now.
from the results of the tcl test, the program can run perfectly. but there is something I want to ask, after running the tcl program that you gave. Wormhole nodes in the network do not move at all. is it like that or is there a code error in it?
I have attached the screen shot as follows:

this is the result of NAM from the TCL program that you gave, and the wormhole node didn't move.
and then i just try to modify your TCL program that initiation the wormhole node:

from this
to this

i think if i delet the $n15 set X and Y. the wormhole node will be moving like other node move. 
but iam wrong, the NAM result show that worm hole node 1 and wormhole node 2 is be in the same position.
like this:

can you help me sir? 

Hasan sabiq

unread,
Mar 15, 2022, 5:47:08 AM3/15/22
to Network Simulator 2 (NS2)
Pada Senin, 21 Februari 2022 pukul 20.18.51 UTC+7 knudfl menulis:
Reply all
Reply to author
Forward
0 new messages