set opt(chan)		Channel/UnderwaterChannel
set opt(prop)		Propagation/UnderwaterPropagation
set opt(netif)		Phy/UnderwaterPhy
set opt(mac)		Mac/UnderwaterMac/BroadcastMac
set opt(ifq)		Queue/DropTail
set opt(ll)		LL
set opt(energy)         EnergyModel
set opt(txpower)        1
set opt(rxpower)        1
set opt(initialenergy)  10000
set opt(idlepower)      0
set opt(ant)            Antenna/OmniAntenna  
set opt(filters)        GradientFilter    ;# options can be one or more of 
                                ;# TPP/OPP/Gear/Rmst/SourceRoute/Log/TagFilter

set opt(ifqlen)		50	;# max packet in ifq
set opt(nn)		6	;# number of nodes in each layer
set opt(x)		100	;# X dimension of the topography
set opt(y)	        100  ;# Y dimension of the topography
set opt(z)              100
set opt(datarate)       0.1
set opt(seed)		0        ;# random seed
set opt(stop)		600	;# simulation time
set opt(tr)		"MyVBFScenario.tr"	;# trace file
set opt(nam)            "MyVBFScenario.nam"  ;# nam file
set opt(datafile)	 "MyVBFScenario.data";# data file
set opt(adhocRouting)   Vectorbasedforward
set opt(width)          100

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

LL set mindelay_		50us
LL set delay_			25us


# 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.05
Antenna/OmniAntenna set Gt_ 1.0
Antenna/OmniAntenna set Gr_ 1.0

Mac/UnderwaterMac set bit_rate_  1.0e4
Mac/UnderwaterMac set encoding_efficiency_  1
Mac/UnderwaterMac/BroadcastMac set packet_size_  568

# Initialize the SharedMedia interface with parameters to make
# it work like the 914MHz Lucent WaveLAN DSSS radio interface
Phy/UnderwaterPhy set CPThresh_ 100  ;#10.0
Phy/UnderwaterPhy set CSThresh_ 0  ;#1.559e-11
Phy/UnderwaterPhy set RXThresh_ 0   ;#3.652e-10
Phy/UnderwaterPhy set Pt_ 0.2818
Phy/UnderwaterPhy set freq_ 25  ;#frequency range in khz 
Phy/UnderwaterPhy set K_ 2.0   ;#spherical spreading

Agent/Vectorbasedforward set hop_by_hop_ 1

# ==================================================================
# Main Program
# =================================================================

#
# Initialize Global Variables
# 
#set sink_ 1


remove-all-packet-headers 
#remove-packet-header AODV ARP TORA  IMEP TFRC
add-packet-header IP Mac LL  ARP  UWVB RMAC

set ns_ [new Simulator]
set topo  [new Topography]

$topo load_cubicgrid $opt(x) $opt(y) $opt(z)
set tracefd	[open $opt(tr) w]
$ns_ trace-all $tracefd

set nf [open $opt(nam) w]
$ns_ namtrace-all-wireless $nf $opt(x) $opt(y)

set data [open $opt(datafile) a]

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

set chan_1_ [new $opt(chan)]

$ns_ at 0.0 "$god_  set_filename $opt(datafile)"


global defaultRNG
$defaultRNG seed $opt(seed)

$ns_ node-config -adhocRouting $opt(adhocRouting) \
		 -llType $opt(ll) \
		 -macType $opt(mac) \
		 -ifqType $opt(ifq) \
		 -ifqLen $opt(ifqlen) \
		 -antType $opt(ant) \
		 -propType $opt(prop) \
		 -phyType $opt(netif) \
		 -agentTrace ON \
                 -routerTrace ON \
                 -macTrace ON\
                 -topoInstance $topo\
                 -energyModel $opt(energy)\
                 -txpower $opt(txpower)\
                 -rxpower $opt(rxpower)\
                 -initialEnergy $opt(initialenergy)\
                 -idlePower $opt(idlepower)\
                 -channel $chan_1_


set node_(0) [$ns_  node 0]
$node_(0) set sinkStatus_ 1
$god_ new_node $node_(0)
$node_(0) set X_  0
$node_(0) set Y_  0
$node_(0) set Z_   0.0
$node_(0) set passive 1
set a_(0) [new Agent/UWSink]
$ns_ attach-agent $node_(0) $a_(0)
$a_(0) attach-vectorbasedforward $opt(width)
$a_(0) cmd set-range 20
$a_(0) cmd set-target-x -2
$a_(0) cmd set-target-y -1
$a_(0) cmd set-target-z -2
$a_(0) cmd set-filename $opt(datafile)



set node_(1) [$ns_  node 1]
$node_(1) set sinkStatus_ 1
$god_ new_node $node_(1)
$node_(1) set X_  0
$node_(1) set Y_  70
$node_(1) set Z_   0
$node_(1) set-cx  0
$node_(1) set-cy  70
$node_(1) set-cz  0
set a_(1) [new Agent/UWSink]
$ns_ attach-agent $node_(1) $a_(1)
$a_(1) attach-vectorbasedforward $opt(width)
 $a_(1) cmd set-range 20
 $a_(1) cmd set-target-x   0
 $a_(1) cmd set-target-y   0
 $a_(1) cmd set-target-z   0
 $a_(1) set data_rate_ 0.05
$a_(1) cmd set-filename $opt(datafile)


set node_(2) [$ns_  node 2]
$node_(2) set sinkStatus_ 1
$god_ new_node $node_(2)
$node_(2) set X_  0
$node_(2) set Y_  140
$node_(2) set Z_   0
$node_(2) set-cx  0
$node_(2) set-cy  140
$node_(2) set-cz  0
set a_(2) [new Agent/UWSink]
$ns_ attach-agent $node_(2) $a_(2)
$a_(2) attach-vectorbasedforward $opt(width)
 $a_(2) cmd set-range 20
 $a_(2) cmd set-target-x   0
 $a_(2) cmd set-target-y   0
 $a_(2) cmd set-target-z   0
 $a_(2) set data_rate_ 0.05
$a_(2) cmd set-filename $opt(datafile)


set node_(3) [$ns_  node 3]
$node_(3) set sinkStatus_ 1
$god_ new_node $node_(3)
$node_(3) set X_  0
$node_(3) set Y_  180
$node_(3) set Z_   0
$node_(3) set-cx  0
$node_(3) set-cy  0
$node_(3) set-cz  0
set a_(3) [new Agent/UWSink]
$ns_ attach-agent $node_(3) $a_(3)
$a_(3) attach-vectorbasedforward $opt(width)
 $a_(3) cmd set-range 30
 $a_(3) cmd set-target-x   0
 $a_(3) cmd set-target-y   0
 $a_(3) cmd set-target-z   0
 $a_(3) set data_rate_ 0.05
$a_(3) cmd set-filename $opt(datafile)


set node_(4) [$ns_  node 4]
$node_(4) set sinkStatus_ 1
$god_ new_node $node_(4)
$node_(4) set X_  50
$node_(4) set Y_  210
$node_(4) set Z_   0
$node_(4) set-cx  50
$node_(4) set-cy  210
$node_(4) set-cz  0
set a_(4) [new Agent/UWSink]
$ns_ attach-agent $node_(4) $a_(4)
$a_(4) attach-vectorbasedforward $opt(width)
 $a_(4) cmd set-range 20
 $a_(4) cmd set-target-x   0
 $a_(4) cmd set-target-y   0
 $a_(4) cmd set-target-z   0
 $a_(4) set data_rate_ 0.05
$a_(4) cmd set-filename $opt(datafile)




set node_(5) [$ns_  node 5]
$node_(5) set sinkStatus_ 1
$god_ new_node $node_(5)
$node_(5) set X_  -50
$node_(5) set Y_  210
$node_(5) set Z_   0
$node_(5) set-cx  -50
$node_(5) set-cy  210
$node_(5) set-cz  0
set a_(5) [new Agent/UWSink]
$ns_ attach-agent $node_(5) $a_(5)
$a_(5) attach-vectorbasedforward $opt(width)
 $a_(5) cmd set-range 20
 $a_(5) cmd set-target-x   0
 $a_(5) cmd set-target-y   0
 $a_(5) cmd set-target-z   0
 $a_(5) set data_rate_ 0.05
$a_(5) cmd set-filename $opt(datafile)



$ns_ at 3 "$a_(5) exp-start"

set node_size 10
for {set k 0} { $k<$opt(nn) } { incr k } {
	$ns_ initial_node_pos $node_($k) $node_size
}

puts "+++++++AFTER ANNOUNCE++++++++++++++"

$ns_ at $opt(stop).001 "$a_(0) terminate"
$ns_ at $opt(stop).002 "$a_(1) terminate"
$ns_ at $opt(stop).002 "$a_(2) terminate"
$ns_ at $opt(stop).002 "$a_(3) terminate"
$ns_ at $opt(stop).002 "$a_(4) terminate"
$ns_ at $opt(stop).002 "$a_(5) terminate"

$ns_ at $opt(stop).003  "$god_ compute_energy"
$ns_ at $opt(stop).004  "$ns_ nam-end-wireless $opt(stop)"
$ns_ at $opt(stop).005 "puts \"NS EXISTING...\"; $ns_ halt"

 puts $tracefd "vectorbased"
 puts $tracefd "M 0.0 nn $opt(nn) x $opt(x) y $opt(y) z $opt(z)"
 puts $tracefd "M 0.0 prop $opt(prop) ant $opt(ant)"
 puts "starting Simulation..."
 $ns_ run

