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 6

Program 6
Implement and study the performance of CDMA on NS2/NS3 (Using stack called Call net) or equivalent environment.




Advertisement


6.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
set val(chan) Channel/WirelessChannel
set val(type) GSM
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
set val(y)     1500
set val(ifqlen) 1000
set val(adhocRouting) AODV
set val(nn) 10
set val(stop) 5.0
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
for {set i 0} {$i < $val(nn) } {incr i} {
	set node_($i) [$ns_ node]
}
set X1(0) 1035.201
set Y1(0) 444.699
set X1(1) 244.365
set Y1(1) 521.418
set X1(2) -18.1268
set Y1(2) 300.612
set X1(3) 723.89
set Y1(3) 343.533
set X1(4) 122.34
set Y1(4) 311.755
set X1(5) 373.498
set Y1(5) 472.206
set X1(6) 548.549
set Y1(6) 361.062
set X1(7) 389.995
set Y1(7) 381.178
set X1(8) 494.798
set Y1(8) 477.771
set X1(9) 275.01
set Y1(9) 381.99
for {set i 0} {$i < $val(nn) } {incr i} {
	$node_($i) set X_ $X1($i)
	$node_($i) set Y_ $Y1($i)
	$node_($i) set Z_ 0.0
}
puts "---------------------------------------"
set m 0
puts "----------------------------------------"
puts "| Node | One hop neighbour |"
puts "----------------------------------------"
for {set i 0} {$i < $val(nn) } {incr i} {
	set k 0
	for {set j 0} {$j < $val(nn) } {incr j} {
		set a [ expr $X1($j)-$X1($i)]
		set b [ expr $a*$a]
		set c [ expr $Y1($j)-$Y1($i)]
		set d [ expr $c*$c]
		set e [ expr $b+$d]
		set f 0.5
		set g [expr pow($e,$f)]
		#puts "Distance from node($i) --to--node($j)----------->$g"
		if {$g <= 200 && $i != $j} {
			puts "| node($i) | node($j) |"
			set nei($m) $j
			set k [expr $k+1]
			set m [ expr $m+1]
		}
	}
	puts "----------------------------------------"
}
puts "Loading connection pattern..."
puts "Loading scenario file..."
for {set i 0} {$i < $val(nn) } {incr i} {
	$ns_ initial_node_pos $node_($i) 45
}
for {set i 0} {$i < $val(nn) } {incr i} {
	$ns_ at $val(stop).0 "$node_($i) reset";
}
set udp_(0) [new Agent/UDP]
$ns_ attach-agent $node_(2) $udp_(0)
set sink [new Agent/LossMonitor]
$ns_ attach-agent $node_(3) $sink
set cbr1_(0) [new Application/Traffic/CBR]
$cbr1_(0) set packetSize_ 1000
$cbr1_(0) set interval_ 0.1
$cbr1_(0) set maxpkts_ 1000
$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
}
# Start Recording at Time 0
$ns_ at 0.0 "record"
source link1.tcl
proc stop {} {
	global ns_tracefd f0 f1 f2
	# Close Trace Files
	close $f0
	close $f1
	close $f2
	exec nam out.nam
	# Plot Recorded Statistics
	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


link1.tcl

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
$ns_ at 0.1 "$node_(0) setdest 786 813 20"
$ns_ at 0.1 "$node_(1) setdest 895 890 20"
$ns_ at 0.1 "$node_(2) setdest 633 669 20"
$ns_ at 0.1 "$node_(3) setdest 1375 712 20"
$ns_ at 0.1 "$node_(4) setdest 773 680 20"
$ns_ at 0.1 "$node_(5) setdest 1024 841 20"
$ns_ at 0.1 "$node_(6) setdest 1199 730 20"
$ns_ at 0.1 "$node_(7) setdest 1041 750 20"
$ns_ at 0.1 "$node_(8) setdest 1146 846 20"
$ns_ at 0.1 "$node_(9) setdest 926 751 20"
$ns_ at 0.5 "$node_(2) add-mark m blue square"
$ns_ at 0.5 "$node_(3) add-mark m blue square"
$ns_ at 0.5 "$node_(2) label source"
$ns_ at 0.5 "$node_(3) label Destination"



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 6.tcl
Step 5: Note both 6.tcl & link1.tcl file is required

output
Fig 6.1: Output

output
Fig 6.2: Output

output
Fig 6.3: Output

output
Fig 6.4: Output

output
Fig 6.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