Web Server Example
(Obsolete: work with ns-2.1b4a)
Web Server模拟脚本和网络拓扑。 脚本文件"ex-web.tcl"和"dumbbell.tcl" (This example is from the 5th VINT/NS Simulator Tutorial/Workshop). Note that you should change the path for "http-mod.tcl" at the begining of the script to an appropriate one to make it run on your machine.

Figure 34. Web server simulation network topology
ex-web.tcl
# Initial setup
source ~/ns-allinone-2.1b4a/ns-2/tcl/http/http-mod.tcl
source dumbbell.tcl
global num_node n
set ns [new Simulator]
$ns set-address 7 24 ;# set-address <bits for node address> <bits for port>
# set up colors for nam
for {set i 1} {$i <= 30} {incr i} {
set color [expr $i % 6]
if {$color == 0} {
$ns color $i blue
} elseif {$color == 1} {
$ns color $i red
} elseif {$color == 2} {
$ns color $i green
} elseif {$color == 3} {
$ns color $i yellow
} elseif {$color == 4} {
$ns color $i brown
} elseif {$color == 5} {
$ns color $i black
}
}
# Create nam trace and generic packet trace
$ns namtrace-all [open out.nam w]
# trace-all is the generic trace we've been using
$ns trace-all [open out.tr w]
create_topology
########################### Modify From Here #####################
## Number of Pages per Session
set numPage 10
set httpSession1 [new HttpSession $ns $numPage [$ns picksrc]]
set httpSession2 [new HttpSession $ns $numPage [$ns picksrc]]
## Inter-Page Interval
## Number of Objects per Page
## Inter-Object Interval
## Number of Packets per Object
## have to set page specific attributes before createPage
## have to set object specific attributes after createPage
$httpSession1 setDistribution interPage_ Exponential 1 ;#in sec
$httpSession1 setDistribution pageSize_ Constant 1 ;# number of objects/page
$httpSession1 createPage
$httpSession1 setDistribution interObject_ Exponential 0.01 ;# in sec
$httpSession1 setDistribution objectSize_ ParetoII 10 1.2 ;# number of packets
# uses default
$httpSession2 createPage
$ns at 0.1 "$httpSession1 start" ;# in sec as well
$ns at 0.2 "$httpSession2 start"
$ns at 30.0 "finish"
proc finish {} {
global ns
$ns flush-trace
puts "running nam..."
# exec to run unix command
exec nam out.nam &
exit 0
}
# Start the simualtion
$ns run
dumbbell.tcl
# Created by Polly Huang
# Simple 4-node star topology
# 8 7 2 3
# \ | | /
# 9 -- 1 ----- 0 -- 4
# / | | \
# 10 11 6 5
proc create_topology {} {
global ns n num_node
set num_node 12
for {set i 0} {$i < $num_node} {incr i} {
set n($i) [$ns node]
}
$ns set src_ [list 2 3 4 5 6]
$ns set dst_ [list 7 8 9 10 11]
# EDGES (from-node to-node length a b):
$ns duplex-link $n(0) $n(1) 1.5Mb 40ms DropTail
$ns duplex-link $n(0) $n(2) 10Mb 20ms DropTail
$ns duplex-link $n(0) $n(3) 10Mb 20ms DropTail
$ns duplex-link $n(0) $n(4) 10Mb 20ms DropTail
$ns duplex-link $n(0) $n(5) 10Mb 20ms DropTail
$ns duplex-link $n(0) $n(6) 10Mb 20ms DropTail
$ns duplex-link $n(1) $n(7) 10Mb 20ms DropTail
$ns duplex-link $n(1) $n(8) 10Mb 20ms DropTail
$ns duplex-link $n(1) $n(9) 10Mb 20ms DropTail
$ns duplex-link $n(1) $n(10) 10Mb 20ms DropTail
$ns duplex-link $n(1) $n(11) 10Mb 20ms DropTail
$ns duplex-link-op $n(0) $n(1) orient left
$ns duplex-link-op $n(0) $n(2) orient up
$ns duplex-link-op $n(0) $n(3) orient right-up
$ns duplex-link-op $n(0) $n(4) orient right
$ns duplex-link-op $n(0) $n(5) orient right-down
$ns duplex-link-op $n(0) $n(6) orient down
$ns duplex-link-op $n(1) $n(7) orient up
$ns duplex-link-op $n(1) $n(8) orient left-up
$ns duplex-link-op $n(1) $n(9) orient left
$ns duplex-link-op $n(1) $n(10) orient left-down
$ns duplex-link-op $n(1) $n(11) orient down
}
# end of create_topology
NS-2网络模拟示例
本文介绍了一个使用NS-2进行网络模拟的示例,包括Web服务器模拟脚本及网络拓扑设置。该示例涉及HTTP会话的创建、页面请求间隔、对象大小分布等配置,并提供了一个简单的哑铃型网络拓扑。
134

被折叠的 条评论
为什么被折叠?



