Future Vision BIE Future Vision BIE


ONE STOP FOR ALL STUDY MATERIALS & LAB PROGRAMS


E MENU Whatsapp Share Join Telegram, to get Instant Updates
× NOTE! Click on MENU to Browse between Subjects...

Advertisement

17CSL57
COMPUTER NETWORK LABORATORY
[As per Choice Based Credit System (CBCS) scheme]
(Effective from the academic year 2017-2018)
SEMESTER - V



This Page Provides Program & Output.
Program 5

Program 5
Implement and study the performance of GSM on NS2/NS3 (Using MAC layer) or equivalent environment.




Advertisement


5.tcl

 1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
puts "Enter number of nodes"
set tnn [gets stdin]
set val(chan) 	Channel/WirelessChannel
set val(prop) 	Propagation/TwoRayGround
set val(netif) 	Phy/WirelessPhy
set val(mac) 	Mac/802_11
set val(ifq) 	Queue/DropTail/PriQueue
set val(ll) 	LL
set val(ant)  	Antenna/OmniAntenna
set val(x)	       1500;#add manually
set val(y)	       1500;#add manually
set val(ifqlen)        1000;#add manually
set val(adhocRouting) AODV;#add manually
set val(nn)  $tnn
set val(stop) 10.0
#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)
Mac/802_11 set cdma_code_handover_stop_  255;# cdma code for handover request (stop)
#end
set f0 [open out02.tr w]
set f1 [open lost02.tr w]
set f2 [open delay02.tr w]
set ns_ [new Simulator]
set topo [new Topography]
set tracefd [open out.tr w]
set namtrace [open out.nam w]

$ns_ trace-all $tracefd
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
$topo load_flatgrid $val(x) $val(y)
set god_ [create-god $val(nn)]               
$ns_ color 0 red
$ns_ node-config -adhocRouting AODV \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-energyModel EnergyModel \
-initialEnergy 100 \
-rxPower 0.3 \
-txPower 0.6 \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF
#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
$cbr1_(0) set maxpkts_ 10000
$cbr1_(0) attach-agent $udp_(0)
$ns_ connect $udp_(0) $sink
$ns_ at 1.00 "$cbr1_(0) start"
set holdtime 0
set holdseq 0
set holdrate1 0
proc record {} {
global sink f0 f1 f2 holdtime holdseq holdrate1
set ns [Simulator instance]
set time 0.9 ;#Set Sampling Time to 0.9 Sec
set bw0 [$sink set bytes_]
set bw1 [$sink set nlost_]
set bw2 [$sink set lastPktTime_]
set bw3 [$sink set npkts_]
set now [$ns now]
# Record Bit Rate in Trace Files
puts $f0 "$now [expr (($bw0+$holdrate1)*8)/(2*$time*1000000)]"
# Record Packet Loss Rate in File
puts $f1 "$now [expr $bw1/$time]"
if { $bw3 > $holdseq } {
puts $f2 "$now [expr ($bw2 - $holdtime)/($bw3 - $holdseq)]"
} else {
puts $f2 "$now [expr ($bw3 - $holdseq)]"
}
$sink set bytes_ 0
$sink set nlost_ 0
set holdtime $bw2
set holdseq $bw3
set holdrate1 $bw0
$ns at [expr $now+$time] "record" ;# Schedule Record after $time interval sec}
#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


link.tcl

 1
2
3
4
5
$ns_ at 0.5 "$node_($source) add-mark m blue square" 
$ns_ at 0.5 "$node_($dest) add-mark m magenta square"
$ns_ at 0.5 "$node_($source) label SENDER" 
$ns_ at 0.5 "$node_($dest) label RECEIVER"
$ns_ at 0.01 "$ns_ trace-annotate \"Network Deployment\""



Process to Execute the Program

Step 1: We need to have ns2 pre installed
Step 2: Head to Cmd
Step 3: Navigate to file saved using cd & ls command
Step 4: ns 5.tcl
Step 5: Note both 5.tcl & link.tcl file is required

output
Fig 5.1: Output

output
Fig 5.2: Output

output
Fig 5.3: Output

output
Fig 5.4: Output

output
Fig 5.5: Output

Step 6: Check the output.

× Note Please Share the website link with Your Friends and known Students...

-ADMIN

× Note Page Number is specified to navigate between Pages...
T = Text book
QB = Question Bank
AS = Answer Script

-ADMIN