Chinaunix首页 | 论坛 | 博客
  • 博客访问: 181965
  • 博文数量: 56
  • 博客积分: 2305
  • 博客等级: 大尉
  • 技术积分: 591
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-13 10:42
文章分类

全部博文(56)

文章存档

2012年(3)

2011年(17)

2010年(36)

我的朋友

分类: LINUX

2010-06-24 14:36:29

【背景】
因为项目需要,搭建一个可以自由调整ping 延时的linux服务器用于模拟特定的网络延迟。
实际上后来发现nistnet功能很强大,可以模拟丢包,带宽限制等,所以应该说Nistnet是一个open source的比较好的网络仿真软件。
 
【设备】
Linux CentOS4.4 32bit 2.6.9-42ELsmp
Nistnet nistnet.2.0.12c.tar.gz (for kernel 2.6+)
 
【安装】
除了gcc和kernel source包的依赖外,nistnet还依赖以下rpm包
xlibs-dev, libxaw-headers, libxaw7-dev, xaw3dg-dev, qt3-doc, qt3-dev-tools, qt3-apps-dev, lsb-cxx
 
解决dependency后
tar xzf nistnet.2.0.12c.tar.gz
cd nistnet-3.0a
./configure
两次默认yes,一次默认使用experimental
make
make install
 
【调试】
./Load.Nistnet
报错:Fatal error, cannot load module nistnet
解决:vi /lib/modules/2.6.9-42ELsmp/modules.dep
     add "/lib/modules/2.6.9-42.ELsmp/extra/nistnet.ko:" at the end of the file
再次运行
./Load.Nistnet
 
[root@nist-01 2.6.9-42.ELsmp]# cnistnet
Usage: cnistnet - must be root to run it.
     -u                      up (on)
     -d                      down (off)
     -a src[:port[.protocol]] dest[:port[.prot]] [cos] add new
             [--delay delay [delsigma[/delcorr]]]
             [--drop  drop_percentage[/drop_correlation]]
             [--dup  dup_percentage[/dup_correlation]]
             [--bandwidth bandwidth]
             [--drd drdmin drdmax [drdcongest]]
     -r src[:port[.prot]] dest[:port[.prot]] [cos]          remove
     -s src[:port[.prot]] dest[:port[.prot]] [cos]          see stats
     -S src[:port[.prot]] dest[:port[.prot]] [cos]          see stats continuously
     [-n] -R                 read table (-n numerical format)
     -D value                debug on (value=1 minimal, 9 maximal)
     -U                      debug off
     -G                      global stats
     -K                      kickstart the clock
     -F                      flush the queues
     -h                      this help message
[root@nist-01 2.6.9-42.ELsmp]# cnistnet -G
global stats: No such file or directory
以及
util_binaddnistnet: No such file or directory

解决:运行以下命令:
mknod /dev/hitbox c 62 0
mknod /dev/nistnet c 62 1
chown root /dev/hitbox
chown root /dev/nistnet
mknod /dev/mungebox c 63 0
chown root /dev/mungebox
mknod /dev/spybox c 64 0
chown root /dev/spybox
modprobe nistnet
 
来源参考:http://www.how2blog.de/?p=9
 
可以将这个放到/etc/rc.local中,以便重启后继续可以使用
例如:
[root@nist-01 ~]# more /etc/rc.local 
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/etc/init.d/Load.Nistnet
mknod /dev/hitbox c 62 0
mknod /dev/nistnet c 62 1
chown root /dev/hitbox
chown root /dev/nistnet
mknod /dev/mungebox c 63 0
chown root /dev/mungebox
mknod /dev/spybox c 64 0
chown root /dev/spybox
modprobe nistnet
 
【使用】
延迟命令使用:
[root@nist-01 2.6.9-42.ELsmp]# cnistnet -G
Emulator is: Off
Average processed packet overhead 0 usec
Average unprocessed packet overhead 0 usec
Average hash tries 0
[root@nist-01 2.6.9-42.ELsmp]# cnistnet -a 0.0.0.0 0.0.0.0 --delay 80 0
addnistnet: 0.0.0.0:0 to 0.0.0.0:0 (prot 0 cos 0),
                        delay 80.000000 (sigma 0.000000 corr 0.000000),
                        bandwidth 0, drop 0.000000 (corr 0.000000),
                        dup 0.000000 (corr 0.000000),
                        drdmin 0, drdmax 0, drdcongest 0
[root@nist-01 2.6.9-42.ELsmp]# cnistnet -u
[root@nist-01 2.6.9-42.ELsmp]# cnistnet -G
Emulator is: On
Average processed packet overhead 3 usec
Average unprocessed packet overhead 0 usec
Average hash tries 0
 
说明,参数80表示延迟80ms,0表示浮动区间
 
加入想实现网段-网段的延迟,可以将一端改为特定的网段(默认以0为mask),比如目的是192.168.1.0/24网段的包全部延迟 30ms
cnistnet -u -a 0.0.0.0 192.168.1.0 --delay 30 0
 
注意,这里如果源也要固定到一个网段,比如想要192.168.2.0/24到192.168.1.0/24, 这样子的话就没法做了
cnistnet -u -a 192.168.2.0 192.168.1.0 --delay 30 0
这样是不起作用的,只有在一端是0.0.0.0的时候,nistnet才会认为是在处理网段。 
 
【效果】
 
阅读(4941) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~