使用 ns-2 模拟实时网络
我是 NS2(甚至 Linux)的完全初学者。我的任务是演示一个非常基本的仿真示例,只是为了表明可以使用 ns2 进行仿真。我去过 在过去的几周里试图让任何简单的模拟脚本都能工作,但是 已经失败了。我确信专家只需要几分钟就可以 编写几行代码来执行此操作。我读过的大多数解释 类似的问题对于我的理解来说甚至太高级了 NS2 或 Linux。如果有人可以在学生层面上帮助我,那就是
非常感谢。
我使用的是 Linux 机器,到目前为止我已经下载并安装了 蒜酮 ns-2.34。我还用谷歌搜索了一些简单的模拟示例 脚本。
例如,我找到了这个:
# Create Simulator
设置 ns [新模拟器]
$ns use-scheduler RealTime
# 模拟器地址
设置我[exec主机名]
#数据包输入
设置 bpf0 [新网络/Pcap/Live]
$bpf0 设置 promisc_ true
设置 nd0 [$bpf0 打开只读 fxp0]
设置过滤器“(不是 ip 主机 $me)”
$bpf0 过滤器 $filt
# 数据包输出
设置 ipnet [新网络/IP]
$ipnet open writeonly
# 输入代理
设置 pfa [新代理/Tap]
$pfa 网络 $bpf0
# 输出代理
设置 ipa [新代理/Tap]
$ipa 网络 $ipnet
# ICMP ECHO 代理
设置 echoagent [新代理/PingResponder]
设置 n0 [$ns 节点]
设置 n1 [$ns 节点]
设置 n2 [$ns 节点]
$ns 单工链接 $n0 $n2 100Mb 1000ms DropTail
$ns 单工链接 $n2 $n1 100Mb 1000ms DropTail
$ns 附加代理 $n0 $pfa
$ns 附加代理 $n1 $ipa
$ns 附加代理 $n2 $echoagent
$ns simplex-connect $pfa $echoagent
$ns simplex-connect $ipa $echoagent
# 等待 ping 到来...
$ns run
当我尝试运行此脚本时,我收到一条消息:
无效的命令名称“Network/Pcap/Live” 执行时 “网络/Pcap/Live创建o_11” 从内部调用 “捕获“$className 创建$o $args”消息” (程序“新”第 3 行) 内调用 “新网络/Pcap/直播” 从内部调用 “设置 bpf0 [新网络/Pcap/Live]” (文件“./vince/emu1.tcl”第12行)
有人可以帮我解决这个问题吗?因为我还不是ns2 专家,我不太清楚该代码是如何工作的。我相信这是一个 ping 应答者。我所需要的只是一个非常简单的仿真示例来表明它 有效,所以任何其他建议或示例脚本都会很棒!
谢谢
I am a complete beginner to NS2 (and even Linux).my task is to demonstrate a very basic emulation example just to show that it is possible to use ns2 to emulate. I've been
trying to get any simple emulation script to work for the past few weeks but
have failed. I'm sure it would take an expert just a few minutes to
write a couple lines of code to do this. Most explanations I have read to
similar problems are even too advanced for my understanding either in terms of
NS2 or Linux. If someone could please help me on a student level that would be
greatly appreciated.
I am using a Linux machine and so far I have downloaded and installed the
allinone ns-2.34. I have also googled for some simple example emulation
scripts.
For example, I found this one:
# Create simulator
set ns [new Simulator]
$ns use-scheduler RealTime
# Emulator address
set me [exec hostname]
# Packet input
set bpf0 [new Network/Pcap/Live]
$bpf0 set promisc_ true
set nd0 [$bpf0 open readonly fxp0]
set filt "(not ip host $me)"
$bpf0 filter $filt
# Packet output
set ipnet [new Network/IP]
$ipnet open writeonly
# Input agent
set pfa [new Agent/Tap]
$pfa network $bpf0
# Output agent
set ipa [new Agent/Tap]
$ipa network $ipnet
# ICMP ECHO agent
set echoagent [new Agent/PingResponder]
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
$ns simplex-link $n0 $n2 100Mb 1000ms DropTail
$ns simplex-link $n2 $n1 100Mb 1000ms DropTail
$ns attach-agent $n0 $pfa
$ns attach-agent $n1 $ipa
$ns attach-agent $n2 $echoagent
$ns simplex-connect $pfa $echoagent
$ns simplex-connect $ipa $echoagent
# Wait for ping to come in...
$ns run
When I try running this script I get a message that says:
invalid command name "Network/Pcap/Live"
while executing
"Network/Pcap/Live create o_11 "
invoked from within
"catch "$className create $o $args" msg"
(procedure "new" line 3)
invoked within
"new Network/Pcap/Live"
invoked from within
"set bpf0 [new Network/Pcap/Live]"
(file "./vince/emu1.tcl" line 12)
Can anyone help me with this problem please? Since I am not yet an ns2
expert, I don't know all too well how that code works. I believe it is a ping
responder. All I need is a very simple emulation example to show that it
works so any other suggestions or example scripts would be great!
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你需要进入ns目录并编译模拟器。
您也可以在模拟目录中看到文件
README_TCP_EMULATE
如果
make nse
不起作用,当您运行模拟器时,您需要从根目录运行:
./nse
you need to go to the directory of ns and compile the emulator.
you can see in emulate directory the file
README_TCP_EMULATE
also if the
make nse
doesn't work:and when you run the emulator you need to run from the root:
./nse