Professional Documents
Culture Documents
Rajesh MC
Rajesh MC
PRACTICAL FILE
3 Implement and study the performance of GSM on NS2/NS3 using MAC layer.
4
Implement and study the performance of GPRS on
NS2/NS3 using MAC layer
5
Implement an Infrastructure-less wireless network comprising of 'N' nodes in
an area of 500m x 600m and
set multiple traffic nodes
# AQM parameters
set minth 30 ; set
maxth 0 ;
set adaptive 1 ;# 1 for Adaptive RED, 0 for plain RED
#Create topology
switch $type {
gsm - gprs -
umts {cell_topo}
}
set_link_para $type
$ns insert-delayer $nodes(ms) $nodes(bs1) [new Delayer]
$ns insert-delayer $nodes(ms) $nodes(bs2) [new Delayer]
X Graph:-
Trace File:-
PRACTICAL-4
Implement GPRS on NS2 using Mac Layer
# 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/Gprs;#
MAC type
set opt(ifq) Queue/DropTail/PriQueue ;# interface queue type
set opt(ll) LL ;# Link layer type set opt(rl) RLC
set opt(ant) Antenna/OmniAntenna ;# antenna model
set opt(ifqlen) 5000 ;# max paket in ifq set opt(adhoc)
NOAH ;# routing protool set opt(x) 70 ;# xoordinate
of topology set opt(y) 70 ;# yoordinate of topology
set opt(seed) 0.0 ;# seed for random num gen.
set opt(tr) "/tmp/riha/sim1.tr" set
opt(start) 0.0
set opt(stop) 80 ;# time to stop simulation set
num_bs_nodes 1
set opt(nn) 5 ;# number of mobilenodes set
opt(rate) 15k
Mac/Gprs set gprs_slots_per_frame_ 7
Mac/Gprs set slot_packet_len_ 53
Mac/Gprs set max_num_ms_ 15
Mac/Gprs set max_num_freq_ 2
Mac/Gprs set gprs_ 1
Mac/Gprs set rlc_error_ 0
Mac/Gprs set error_rate_ 1000
Mac/Gprs set verbose_ 0
LL set acked_ 0
LL set llfraged_ 1
LL set llfragsz_ 1520
LL set llverbose_ 0
RLC set acked_ 0
RLC set rlcfraged_ 1
RLC set rlcfragsz_ 50
RLC set rlcverbose_ 0
#remove unneessary paket headers, else eah pkt takes 2kb!
remove-packet-header LDP MPLS Snoop remove-
packet-header Ping TFRC TFRC_ACK remove-
packet-header Diffusion RAP IMEP remove-
packet-header AODV SR TORA IPinIP remove-
packet-header MIP HttpInval remove-packet-
header MFTP SRMEXT SRM aSRM remove-
packet-header mcastCtrl CtrMcast IVS remove-
paket-header Resv UMP Flags #Create simulator
instane set ns_ [new Simulator]
# set up for hierarchical routing
$ns_ node-config -addressType hierarchical
AddrParams set domain_num_ 1 ;# number of domains
lappend cluster_num 1 ;# number ofclusters in each domain
AddrParams set cluster_num_ $cluster_num lappend
eilastlevel 6 ;# number of nodes in eachcluster AddrParams
set nodes_num_ $eilastlevel ;# of each domain set tracefd
[open $opt(tr) w] $ns_ trace-all $tracefd # Create
topography object set topo [new Topography]
# define topology
$topo load_flatgrid $opt(x) $opt(y)
#create God create-god
$opt(nn) set chan1 [new
$opt(chan)]
#configure for base-station node
$ns_ node-config -adhocRouting $opt(adhocRouting) \
-llType $opt(ll) \
-rlcType $opt(rlc) \
-macType $opt(mac) \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propType $opt(prop) \
-phyType $opt(netif)\
-topoInstance $topo \
-wiredRouting ON \
-agentTrace ON \
-routerTrace OFF \
-macTrace OFF \
-movementTrace OFF \
-channel $chan1 #create
base-station node
set temp {1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 }
# hier address to be used for wireless domain set BS(0)
[$ns_ node [lindex $temp 0]]
$BS(0) random-motion 0 ;# disable random motion
#provide some co-ord (fixed) to base station node
$BS(0) set X_ 1.0 $BS(0)
set Y_ 2.0 $BS(0) set Z_
0.0
#configure for mobilenodes
$ns_ node-config -wiredRouting OFF
#create mobilenodes in the same domain as BS(0) for
{set j 0} {$j < $opt(nn)} {incr j} {
set node_($j) [ $ns_ node [lindex $temp [expr $j+1]]]
$node_($j) base-station [AddrParams addr2id [$BS(0) node-addr]]
}
for {set j 0} {$j < $opt(nn)} {incr j} { set
s($j) [new Agent/TCP]
$ns_ attach-agent $node_($j) $s($j)
$s($j) set packetSize_ 1500 set
null($j) [new Agent/TCPSink] $ns_
attach-agent $BS(0) $null($j)
PRACTICAL-5
Implement an Infrastructure-less wireless network comprising of 'N' nodes in an
area of 500m x 600m and set multiple traffic nodes. After simulation plot graphs
showing the performance of the network in terms of the End-to-End delay,
Throughput and packet delivery ratio for varying for Number of nodes with
different source/destination pair in NS2/NS3.
#Creating nodes
PRACTICAL-6
Implement an Infrastructure-less wireless network comprising of 'N' MOBILE
nodes.
Perform the simulations with varying speed of the nodes.
Plot and compare the performance of different MAC layer protocols using
NS2/NS3 simulator in terms of
(1) Number of collisions,
(2) Number of Control packets
#add manually
for {set i 0} {$i < $val(nn) } {incr i} { set
node_($i) [$ns_ node]
$node_($i) set X_ [expr rand() * 500] $node_($i)
set Y_ [expr rand() * 500]
$node_($i) set Z_ 0.000000000000;
}
for {set i 0} {$i < $val(nn) } {incr i} {
set xx [expr rand() * 1500] set yy
[expr rand() * 1000]
$ns_ at 0.1 "$node_($i) setdest $xx 4yy 5"
}
puts "Loading connection pattern..."
puts "Loading scenario file..." for
{set i 0} {$i < $val(nn) } {incr i} {
$ns_ initial_node_pos $node_($i) 55
}
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at $val(stop).0 "$node_($i) reset";
}
puts "Enter source node" set source [gets
stdin] puts "Enter destination node" set
dest [gets stdin] set udp_(0) [new
Agent/UDP] $ns_ attach-agent
$node_($source) $udp_(0) set sink [new
Agent/LossMonitor] $ns_ attach-agent
$node_($dest) $sink set cbr1_(0) [new
Application/Traffic/CBR]
$cbr1_(0) set packetSize_ 1000
$cbr1_(0) set interval_ 0.1
#end
# Start Recording at Time 0
$ns_ at 0.0 "record" source
link.tcl proc stop {} { global
ns_ tracefd f0 f1 f2
# Close Trace Files
close $f0 close $f1
close $f2 exec
nam out.nam
exec xgraph out02.tr -geometry -x TIME -y thr -t Throughput 800x400 & exec
xgraph lost02.tr -geometry -x TIME -y loss -t Packet_loss 800x400 & exec xgraph
delay02.tr -geometry -x TIME -y delay -t End-to-End-Delay 800x400 & $ns_ flush-
trace
}
$ns_ at $val(stop) "stop"
$ns_ at $val(stop).0002 "puts \"NS EXITING...\" ; $ns_ halt"
puts $tracefd "M 0.0 nn $val(nn) x $val(x) y $val(y) rp "
puts $tracefd "M 0.0 prop $val(prop) ant $val(ant)" puts
"Starting Simulation..."
$ns_ run
PRACTICAL-7
Implement an Infrastructure-less wireless network comprising of 'N' nodes in an
area of 1000 x 1000 square metres.
At routing layer use AODV and DSR protocols.
Perform the simulations with varying number of nodes.
Plot and compare the performance of AODV and DSR in terms of the End-to-End
delay, Throughput, packet delivery ratio using NS2/NS3 simulator.
#add manually
Mac/802_11 set cdma_code_bw_start_ 0;# cdma code for bw request (start)
Mac/802_11 set cdma_code_bw_stop_ 63;# cdma code for bw request (stop)
Mac/802_11 set cdma_code_init_start_ 64;# cdma code for initial request (start)
Mac/802_11 set cdma_code_init_stop_ 127;# cdma code for initial request (stop)
Mac/802_11 set cdma_code_cqich_start_ 128 ;# cdma code for cqich request (start)
Mac/802_11 set cdma_code_cqich_stop_ 195;# cdma code for cqich request (stop)
Mac/802_11 set cdma_code_handover_start_ 196 ;# cdma code for handover request
(start)
#add manually
for {set i 0} {$i < $val(nn) } {incr i} { set
node_($i) [$ns_ node]
$node_($i) set X_ [expr rand() * 500] $node_($i)
set Y_ [expr rand() * 500]
$node_($i) set Z_ 0.000000000000;
}
for {set i 0} {$i < $val(nn) } {incr i} {
set xx [expr rand() * 1500] set yy
[expr rand() * 1000]
$ns_ at 0.1 "$node_($i) setdest $xx 4yy 5"
}
puts "Loading connection pattern..."
puts "Loading scenario file..." for
{set i 0} {$i < $val(nn) } {incr i} {
$ns_ initial_node_pos $node_($i) 55
}
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at $val(stop).0 "$node_($i) reset";
}
puts "Enter source node" set source [gets
stdin] puts "Enter destination node" set
dest [gets stdin] set udp_(0) [new
Agent/UDP] $ns_ attach-agent
$node_($source) $udp_(0) set sink [new
Agent/LossMonitor] $ns_ attach-agent
$node_($dest) $sink set cbr1_(0) [new
Application/Traffic/CBR]
$cbr1_(0) set packetSize_ 1000
$cbr1_(0) set interval_ 0.1
#end
# Start Recording at Time 0
$ns_ at 0.0 "record" source
link.tcl proc stop {} { global
ns_ tracefd f0 f1 f2 # Close
Trace Files close $f0 close
$f1 close $f2 exec nam
out.nam
exec xgraph out02.tr -geometry -x TIME -y thr -t Throughput 800x400 & exec
xgraph lost02.tr -geometry -x TIME -y loss -t Packet_loss 800x400 & exec xgraph
delay02.tr -geometry -x TIME -y delay -t End-to-End-Delay 800x400 & $ns_ flush-
trace
}
$ns_ at $val(stop) "stop"
$ns_ at $val(stop).0002 "puts \"NS EXITING...\" ; $ns_ halt"
puts $tracefd "M 0.0 nn $val(nn) x $val(x) y $val(y) rp "
puts $tracefd "M 0.0 prop $val(prop) ant $val(ant)" puts
"Starting Simulation..."
$ns_ run