LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-17-2015, 07:38 AM   #1
nadine01
Member
 
Registered: Oct 2014
Posts: 62

Rep: Reputation: Disabled
How to simulate leach???


Hello all,

Code:
# Define options
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)             10                         ;# number of mobilenodes
set val(rp)            AODV                       ;# routing protocol
set val(X)              500  			   ;# X dimension of topography
set val(Y)              500			   ;# Y dimension of topography  
set val(stop)		1000			   ;# time of simulation end
set val(energymodel)    EnergyModel		   ;#Energy set up

# Simulator Instance Creation
set ns	[new Simulator]

set tracefd     [open simple.tr w]
$ns trace-all $tracefd

set namtrace [open wireless1-out.nam w]        
$ns namtrace-all-wireless $namtrace $val(X) $val(Y)

#Fixing the co-ordinate of simulation area


# set up topography object
set topo       [new Topography]
$topo load_flatgrid $val(X) $val(Y)

# general operational descriptor- storing the hop details in the network
create-god $val(nn)



# configure the first 5 nodes with transmission range of 500m 

       $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 \
                   -energyModel $val(energymodel) \
			 -initialEnergy 10 \
                   -rxPower 0.5 \
			 -txPower 1.0 \
                   -idlePower 0.0 \
			 -sensePower 0.3 \
			 -agentTrace ON \
			 -routerTrace ON \
			 -macTrace OFF \
			 -movementTrace ON


# Node Creation Sink



set energy(0) 1000

$ns node-config -initialEnergy 1000 \
                -rxPower 0.5 \
		-txPower 1.0 \
                -idlePower 0.0 \
		-sensePower 0.3 

	set node_(0) [$ns node]
		$node_(0) set X_ [expr 10 + round (rand() *$val(X))]
   		$node_(0) set Y_ [expr 10 + round (rand() *$val(Y))]
		$node_(0) set Z_ 0.0
	#$node_(0) color black
	



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

set energy($i) 500

$ns node-config -initialEnergy $energy($i) \
                -rxPower 0.5 \
		-txPower 1.0 \
                -idlePower 0.0 \
		-sensePower 0.3 

	set node_($i) [$ns node]
	

		$node_($i) set X_ [expr 10 + round (rand() *$val(X))]
   		$node_($i) set Y_ [expr 10 + round (rand() *$val(X))]
		$node_($i) set Z_ 0.0
	#$node_($i) color black

}
 set t 1.0
 set f 25.0	
for {set i 1} {$i < $val(nn)} {incr i} {

# Defining a transport agent for sending
set udp [new Agent/UDP]

# Attaching transport agent to sender node
$ns attach-agent $node_($i) $udp

# Defining a transport agent for receiving
set null [new Agent/Null]

# Attaching transport agent to receiver node
$ns attach-agent $node_(0) $null

#Connecting sending and receiving transport agents
$ns connect $udp $null

#Defining Application instance
set cbr [new Application/Traffic/CBR]

# Attaching transport agent to application agent
$cbr attach-agent $udp
#Packet size in bytes 
$cbr set packetSize_ 512   
# data packet generation starting time
$ns at $t "$cbr start"
$ns at $f "$cbr stop"

set t [expr 22 * $i]
set f [expr 25+ $t]
}





# Define node initial position in nam
for {set i 0} {$i < $val(nn)} {incr i} {

        # 20 defines the node size in nam, must adjust it according to your
        # scenario size.
        # The function must be called after mobility model is defined
        $ns initial_node_pos $node_($i) 50
}
# Tell nodes when the simulation ends
#



for {set i 0} {$i < $val(nn) } {incr i} {
    $ns at 1000.0 "$node_($i) reset";
}
$ns at 1000.0 "stop"
$ns at 1000.01 "puts \"NS EXITING...\" ; $ns halt"
 proc stop {} {
    global ns tracefd namtrace
    $ns flush-trace
    close $tracefd
    close $namtrace
    exec nam wireless1-out.nam &
    exit 0
}

puts "Starting Simulation..."
$ns run
i have this tcl for AODV , i need to make the same parameters with leach protocol

How to do it?????

when i add leach and make ./test

i have this reseault in the end of leach.out

Code:
At 494.80000000004401:
		Total Energy = 327.82507706058254
		Total Data = 44146
		Total Alive = 4

Simulation complete.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with running leach protocol in ns2.34 leach.er Mohamed69 Linux - Software 14 04-16-2018 07:10 AM
leach.out total energy increase leach ns2.34 linuxUser123linux Linux - Software 1 07-13-2013 04:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration