DGrR/DGrR.o \ common/ns-process.o \ satellite/satgeometry.o satellite/sathandoff.o \
Agent/OLSR set mid_ival_ 5
# DGrR Agent/DGrR set packetSize_ 64
# Application-Layer Protocols: Message # a protocol to carry text messages Ping # Ping DGrR # DGrR
DGrR PT_DGrR,
insert new packet types here PT_NTYPE // This MUST be the LAST one
DGrR name_[PT_DGrR] = "DGrR";
name_[PT_NTYPE]= "undefined"; }
Full explanation are available at http://www.isi.edu/nsnam/ns/tutorial/nsnew.html#third
cd $nsfolder makewhere $nsfolder should look like #/ns-2/ns-2.31
# ====================================================================== # Define 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(nn) 4 ;# number of mobilenodes set opt(adhocRouting) AODV ;# routing protocol set opt(cp) ""; #"~/bin/ns-2/ns-2.31/tcl/mobility/scene/cbr-3-test" ; # connection pattern file set opt(sc) "~/bin/ns-2/ns-2.31/tcl/mobility/scene/scen-3-test" ; # node movement file.
set opt(x) 400 ;# x coordinate of topology set opt(y) 600 ;# y coordinate of topology set opt(seed) 0.0 ;# seed for random number gen. set opt(stop) 8000 ;# time to stop simulation
# ============================================================================
#
# check for random seed
#
if {$opt(seed) > 0} {
puts "Seeding Random number generator with $opt(seed)\n"
ns-random $opt(seed)
}
# # create simulator instance # set ns_ [new Simulator]
#$ns_ set-address-format expanded
# # control OLSR behaviour from this script - # commented lines are not needed because # those are default values # Agent/OLSR set use_mac_ true Agent/OLSR set debug_ false Agent/OLSR set willingness 3 Agent/OLSR set hello_ival_ 2 Agent/OLSR set tc_ival_ 5
# # control reputation mechanism #
# synchronisation interval set DGrR(reptimer_ival_) 50 set DGrR(groupSize) 4
# % of malicious nodes at most ! set DGrR(tau_) 10 set DGrR(NRmax_) 10
# bindings # Agent/DGrR set reptimer_ival_ $DGrR(reptimer_ival_) Agent/DGrR set tau_ $DGrR(tau_) Agent/DGrR set NRmax_ $DGrR(NRmax_)
# # open traces # set tracefd [open olsr_example.tr w] set namtrace [open olsr_example.nam w]
set DGrRtrace [open olsr_example.rep w]
$ns_ trace-all $tracefd $ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)
# # create topography object # set topo [new Topography]
# # define topology # $topo load_flatgrid $opt(x) $opt(y)
# # create God # create-god $opt(nn)
set chan_1_ [new $opt(chan)]
#
# configure mobile nodes
#
$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) \
-topoInstance $topo \
-wiredRouting OFF \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-channel $chan_1_
#-channelType $opt(chan) \
create nodes & start
for {set i 0} {$i < $opt(nn)} {incr i} {
set node_($i) [$ns_ node]
$ns_ at 0.1 "$node_($i) start"
}
#
define group node (attach-agent)
#
for {set i 0} {$i < $DGrR(groupSize)} {incr i} {
set olsrRAgent($i) [new Agent/DGrR]
$node_($i) random-motion 0 ;# disable random motion
$ns_ attach-agent $node_($i) $olsrRAgent($i)
}
# # init group nodes #
#
# Note : these operations are done only because the group mechanism
# is not implemented in NS-2
# Thus, we emulate two cases :
# - node inside the group : "initGroupEntry"
# - node outside the group and who whish enter the group (here : Universe \ group) : "initEntry"
#
for {set i 0} {$i < $DGrR(groupSize)} {incr i} {
# send first messages (tables creations)
# wait for network stability
$ns_ at 100.0 "$olsrRAgent($i) start"
$ns_ at 100.0 "$olsrRAgent($i) initbroadcast"
for {set j 0} {$j < $DGrR(groupSize)} {incr j} {
set id [$node_($j) node-addr]
$ns_ at 1.0 "$olsrRAgent($i) initGroupEntry $id"
}
for {set j $DGrR(groupSize)} {$j < $opt(nn) } {incr j} {
set id [$node_($j) node-addr]
$ns_ at 1.0 "$olsrRAgent($i) initentry $id"
}
}
for {set i 0} {$i < $DGrR(groupSize)} {incr i} {
$ns_ at $opt(stop).0001 "$olsrRAgent($i) finaldisplay"
}
#
# source connection-pattern and node-movement scripts
#
if { $opt(cp) == "" } {
puts "*** NOTE: no connection pattern specified."
set opt(cp) "none"
} else {
puts "Loading connection pattern..."
source $opt(cp)
}
if { $opt(sc) == "" } {
puts "*** NOTE: no scenario file specified."
set opt(sc) "none"
} else {
puts "Loading scenario file..."
source $opt(sc)
puts "Load complete..."
}
#
# define initial node position in nam
#
for {set i 0} {$i < $opt(nn)} {incr i} {
$ns_ initial_node_pos $node_($i) 20
}
#
# tell all nodes when the simulation ends
#
for {set i 0} {$i < $opt(nn) } {incr i} {
$ns_ at $opt(stop).0 "$node_($i) reset"; }
$ns_ at $opt(stop).0002 "puts \"NS EXITING...\" ; $ns_ halt" $ns_ at $opt(stop).0001 "stop"
proc stop {} {
global ns_ tracefd namtrace
$ns_ flush-trace
close $tracefd
close $namtrace
# exec nam out.nam &
exit 0
}
# # begin simulation # puts "Starting Simulation..."
$ns_ run
full examples and explanation are available at TODO
1.4.6