lost and found ( for me ? )

Showing posts with label traffic control. Show all posts
Showing posts with label traffic control. Show all posts

回線エミュレータ WANem ( Wide Area EMulator )

[ WANem とは ? ]

http://wanem.sourceforge.net/

WAN回線のエミュレーションが可能
bandwitdh , パケットロス , jitter , latency の設定が可能。
ブラウザ(GUI)で設定可能。

マニュアルのアーキテクチャの説明をみると、netem , htb , tc , netfilter などを使用しているので、仕組みは CentOSやUbuntuなどの tc と同じ。

マニュアル
http://jaist.dl.sourceforge.net/project/wanem/wanem/WANem%20v2.0/wanemulator_all_about_v2.0.pdf

WANem だと:

・GUIで bandwidth , packet loss などの設定、設定の保存、リストアができる

・WANalyzer
指定したリモートサイトのネットワークの状態(帯域、latency , loss , jitter ) を計測できる。
その結果を tc コマンドでどうやるか表示してくれる

・tc がよくわかなくても設定できる

GUIで bandwidth など設定できるので tc を知らなくても設定可能。
また、設定した内容を表示できるので、tc でどうやったらできるのか確認できる。

・Live CD なので、ハードディスクにインストール不要

tcに精通している人は特にこれを使わずに、WANem使う必要性はないかも。CLI で tcコマンドをたたけば。。

[ どうやって動かす? ]

Live CD 、または VMware Player/Server のイメージが提供されているので、Live CD を起動、またはVMで動かす。

[ ためしに KVM上のVMとしてWANemを起動 ]

KVMマシンスペック

root@hat1:~# cat /etc/lsb-release | tail -1
DISTRIB_DESCRIPTION="Ubuntu 10.04.1 LTS"
root@hat1:~# uname -r
2.6.32-25-server

KVMのイメージはないので、iso (WANemv2.2.iso.bz2)を  http://wanem.sourceforge.net/ からダウンロード

root@hat1:~# bunzip2 WANemv2.2.iso.bz2
root@hat1:~# ls WAN*
WANemv2.2.iso

iso をマウントして中身をチェック

root@hat1:~# mount -o loop -t iso9660 WANemv2.2.iso tmp

knoppix 5.3.1 だ。

root@hat1:~/tmp# cat version.txt
knx5.3.1CD Wed May 21 14:40:52 JST 2008

カーネル 2.6.24.4 みたい。結構新しい。

root@hat1:~/tmp/boot/isolinux# file linux
linux: Linux kernel x86 boot executable bzImage, version 2.6.24.4 (root@Knoppix) #2 SMP , RO-rootFS, root_dev 0x103, swap_dev 0x2, Video mode 791

インストール

NICを2つアサイン。
Live CD なので、local HDDにインストールできるか ? だけど、とりあえず ディスクも追加 ( 3GB )
メモリは 512MB

OS type Linux , カーネルは 2.6.x kernel を指定。


IPの設定 ( DHCPも可 )


user : perc のパスワードを設定。ユーザ perc は勝手につくられている。


起動した。
コンソール、ssh 、ブラウザで操作可能。

コンソール、ssh は WANem のシステム設定 ( IPアドレス、ルーティング設定など )
ブラウザは bandwidth などの設定。

最初 DHCP で アドレスをもらえる設定で起動したら、IPはもらえているのに外部と通信できなかった。
NICの削除・追加をしたら直った。リブートでもいいかも。

[ 管理操作 ]

root@hat1:~# ssh 192.168.11.18 -l perc
Password:
Welcome to Knoppix!
WANemControl@PERC>

- ネットワークアドレスの確認 + ping

WANemControl@PERC>status

IP Settings
=========================================================================
eth0      Link encap:Ethernet  HWaddr 52:54:00:2d:25:0c
         inet addr:192.168.11.18  Bcast:192.168.11.255  Mask:255.255.255.0
         inet6 addr: fe80::5054:ff:fe2d:250c/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:307 errors:0 dropped:0 overruns:0 frame:0
         TX packets:254 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:30601 (29.8 KiB)  TX bytes:28385 (27.7 KiB)
         Interrupt:10 Base address:0x8000

lo        Link encap:Local Loopback
         inet addr:127.0.0.1  Mask:255.0.0.0
         inet6 addr: ::1/128 Scope:Host
         UP LOOPBACK RUNNING  MTU:16436  Metric:1
         RX packets:2 errors:0 dropped:0 overruns:0 frame:0
         TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0
         RX bytes:100 (100.0 B)  TX bytes:100 (100.0 B)

=========================================================================
Route Settings
=========================================================================
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.11.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
0.0.0.0         192.168.11.1    0.0.0.0         UG    0      0        0 eth0
=========================================================================
Apache ..... running
SSH Server ..... up
Enter IP Address to test reachability(q to skip):192.168.11.1
ping: icmp open socket: Operation not permitted
Wrong IPAddress....
WANemControl@PERC>

他使えるコマンドは、assgin ( IPアドレス設定 ) , shutdown , reset ( 設定のクリア ) など。詳細はマニュアルを。

exit2shell とすると shell モードになり、linuxのコマンドがつかえる。

rootでsshにログインできるように、まず、コンソールから root のパスワードを設定する。
root 以外で ssh でアクセスすると、shell モードになれない。

コンソールで root のパスワードを設定


root で ssh ログイン ( 一般ユーザ perc で sshログインすると exit2hell が使えない )

root@hat1:~# ssh 192.168.11.18
Password:
Welcome to Knoppix!
WANemControl@PERC>exit2shell
Type 'wanem' to return to WANem console
root@Knoppix:~# uname -a
Linux Knoppix 2.6.24.4 #2 SMP PREEMPT Tue Mar 25 21:35:28 CET 2008 i686 GNU/Linux

[ WANエミュレーション設定 ]

ブラウザで http://WANemのIP/WANem  にアクセス。


・WANalyzer

リモートサイトのIP を指定すると bandwitdh , latency などを計測してくれる。
ためしに、デフォルトゲートウェイ ( 192.168.11.1 ) でテスト。

測定はping でやっている。
小さいデータから徐々にデータを大きくしているみたい。

   Fragment offset: 1480
   Time to live: 64
   Protocol: ICMP (0x01)
   Header checksum: 0x5e6e [correct]
       [Good: True]
       [Bad : False]
   Source: 192.168.11.1 (192.168.11.1) <- WANem
   Destination: 192.168.11.18 (192.168.11.18) <- remote host
Data (1480 bytes)


start wan emulation を実行すると tc コマンドが実行された。
実行されたコマンドは下記のおしり3行。


これであってるのかは、、??

root@Knoppix:~# tc -s qdisc show dev eth0
qdisc netem 1: root limit 1000
Sent 10317 bytes 76 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
qdisc netem 10: parent 1:1 limit 1000
Sent 10317 bytes 76 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
qdisc htb 20: parent 10:1 r2q 10 default 1 direct_packets_stat 0
Sent 10317 bytes 76 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0

・Basic Mode

bandwidth の設定

bandwidth を 9600kbps に設定



CLIで設定をチェック。

root@Knoppix:~# tc qdisc show dev eth0
qdisc netem 1: root limit 1000
qdisc htb 10: parent 1:1 r2q 1 default 1 direct_packets_stat 0

root@Knoppix:~# tc -s qdisc show dev eth0
qdisc netem 1: root limit 1000
Sent 31430 bytes 133 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
qdisc htb 10: parent 1:1 r2q 1 default 1 direct_packets_stat 0
Sent 31430 bytes 133 pkt (dropped 0, overlimits 42 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0

tc きいていることはきいている。のろい。。( start 07:42:39 , finish 07:43:27 )

root@Knoppix:~# wget 192.168.11.14/1M
--07:42:39--  http://192.168.11.14/1M
          => `1M'
Connecting to 192.168.11.14:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1,048,576 (1.0M) [text/plain]

100%[==============================================>] 1,048,576     25.35K/s    ETA 00:00

07:43:27 (21.71 KB/s) - `1M' saved [1048576/1048576]

qdisc 10: にはいってる。

root@Knoppix:~# tc -s qdisc show dev eth0
qdisc netem 1: root limit 1000
Sent 128816 bytes 1207 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
qdisc htb 10: parent 1:1 r2q 1 default 1 direct_packets_stat 0
Sent 128816 bytes 1207 pkt (dropped 0, overlimits 801 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0

参考: tc がかかっていないときの結果。 ( start 07:47:05 , finish : 07:47:05 )

root@Knoppix:~# wget 192.168.11.14/1M
--07:47:05--  http://192.168.11.14/1M
          => `1M.1'
Connecting to 192.168.11.14:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1,048,576 (1.0M) [text/plain]

100%[==============================================>] 1,048,576     --.--K/s

07:47:05 (10.31 MB/s) - `1M.1' saved [1048576/1048576]

・Advanced mode

細かい設定 ( bandwidth , packet loss duplication reordering corruption , src ip , dst ip , dst port etc ) ができる。
tc でどうのように書くか確認できるのがよい。


設定の保存、リストアも可能

Linux: traffic control

netem ( tcコマンド ) の基本的な使い方。

tc コマンドで、遅延、パケットロス、パケットの重複、パケットの到着順を変える、など模擬することができる。
遅延させ、WAN を模擬し、その時の、ネットワーク機器(フローテーブルをためたときの挙動)や、SLA(遅延が xx秒だとユーザ逃げちゃうだろうな)などのテストができそう。
あと、パケットの到着順をかえたときに、ロードバランサやFirewall が、処理できるか確認してみるとか。

・delay : outgoing に対して delay を設定  ( WANエミュレーション )

100ms の delay をかける。

[root@hat1-vm ~]# tc qdisc add dev eth0 root netem delay 100ms

[root@hat1-vm ~]# tc qdisc show dev eth0
qdisc netem 8001: limit 1000 delay 100.0ms

[root@hat1-vm ~]# ping 192.168.11.15
PING 192.168.11.15 (192.168.11.15) 56(84) bytes of data.
64 bytes from 192.168.11.15: icmp_seq=1 ttl=64 time=100 ms

削除

[root@hat1-vm ~]# tc qdisc del dev eth0 root netem delay 100ms

[root@hat1-vm ~]# tc qdisc show dev eth0
qdisc pfifo_fast 0: bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1

100ms ± 20ms といった設定も可能

[root@hat1-vm ~]# tc qdisc add dev eth0 root netem delay 100ms 20ms

[root@hat1-vm ~]# tc qdisc show dev eth0
qdisc netem 8001: limit 1000 delay 100.0ms  20.0ms

[root@hat1-vm ~]# ping 192.168.11.15
PING 192.168.11.15 (192.168.11.15) 56(84) bytes of data.
64 bytes from 192.168.11.15: icmp_seq=1 ttl=64 time=110 ms
64 bytes from 192.168.11.15: icmp_seq=2 ttl=64 time=83.7 ms

遅延 100ms ± 20ms に加え、ばらつき ( 正規分布 : normal distribution ) を設定。

# tc qdisc change dev eth0 root netem delay 100ms 20ms distribution normal

[root@hat1-vm ~]# ping 192.168.11.15
PING 192.168.11.15 (192.168.11.15) 56(84) bytes of data.
64 bytes from 192.168.11.15: icmp_seq=1 ttl=64 time=161 ms
64 bytes from 192.168.11.15: icmp_seq=2 ttl=64 time=103 ms

・パケットロス

10%のパケットロス。(パケット 100 個中 10 個パケットロス)

[root@hat1-vm ~]# tc qdisc change dev eth0 root netem loss 10%

[root@hat1-vm ~]# tc qdisc show dev eth0
qdisc netem 8001: limit 1000 loss 10%

ping 100 回うったら、13個パケットロス

[root@hat1-vm ~]# ping 192.168.11.15 -c 100
100 packets transmitted, 87 received, 13% packet loss, time 99480ms
rtt min/avg/max/mdev = 0.761/0.859/1.089/0.067 ms

受信側でも一応確認。87パケット、キャプチャしている。13個パケットロス

[root@hat2-vm ~]# egrep -i request aa.txt | wc -l
87

・重複パケット

[root@hat1-vm ~]# tc qdisc change dev eth0 root netem duplicate 10%

[root@hat1-vm ~]# tc qdisc show dev eth0
qdisc netem 8001: limit 1000 duplicate 10%

DUP! なんて表示されるんだ。。

[root@hat1-vm ~]# ping 192.168.11.15
64 bytes from 192.168.11.15: icmp_seq=21 ttl=64 time=4.20 ms (DUP!)
64 bytes from 192.168.11.15: icmp_seq=22 ttl=64 time=4.55 ms
64 bytes from 192.168.11.15: icmp_seq=22 ttl=64 time=4.56 ms (DUP!)

reply が 2つきている。重複している。

[root@hat1-vm ~]# tshark -i eth0 icmp
 9.390787 192.168.11.14 -> 192.168.11.15 ICMP Echo (ping) request
 9.392571 192.168.11.15 -> 192.168.11.14 ICMP Echo (ping) reply
 9.392585 192.168.11.15 -> 192.168.11.14 ICMP Echo (ping) reply

・パケット破損 ( カーネル 2.6.16 以降から可能 )

[root@hat1-vm ~]# uname -r
2.6.18-194.17.1.el5

[root@hat1-vm ~]# tc qdisc change dev eth0 root netem corrupt 10%

[root@hat1-vm ~]# tc qdisc show dev eth0
qdisc netem 8001: limit 1000 corrupt 10%

キャプチャしてみたがパケット壊れていないような。。
確認できず。。

・パケットの到着順変更 ( re-ordering )

[root@hat1-vm ~]# tc qdisc add dev eth0 root netem delay 10ms reorder 25% 50%

[root@hat1-vm ~]# tc qdisc show dev eth0
qdisc netem 8002: limit 1000 delay 10.0ms reorder 25% 50% gap 1

25%のパケットはすぐ送信。残りは delay 10ms 。
すぐ送信されるパケットと、そうでないパケットがあるので到着順が変わる。
50% は correlation of 50% ,, correlation 相関、、50%の相関 ?? 。理解できず。

到着順がかわってる。

tc machine ( 192.168.11.14 ) から ssh で 192.168.11.100 に ssh したときのキャプチャデータより。

src 11.14 -> dst 11.100 宛てのパケット

seq # より到着順がかわっていることが読み取れる。

No.10

   Source: 192.168.11.14 (192.168.11.14)
   Destination: 192.168.11.100 (192.168.11.100)
257, Ack: 145, Len: 64
   Source port: ssh (22)
   Destination port: 53077 (53077)
   Sequence number: 257    (relative sequence number)

No.12

   Source: 192.168.11.14 (192.168.11.14)
   Destination: 192.168.11.100 (192.168.11.100)
145, Ack: 145, Len: 112
   Source port: ssh (22)
   Destination port: 53077 (53077)
   Sequence number: 145    (relative sequence number)

・incoming に対して delay

[root@hat1-vm ~]# modprobe ifb
[root@hat1-vm ~]# lsmod | grep ifb
ifb                     8901  0
[root@hat1-vm ~]# ip link set dev ifb0 up

[root@hat1-vm ~]# ifconfig ifb0
ifb0      Link encap:Ethernet  HWaddr A6:77:C4:D8:7A:C8
         inet6 addr: fe80::a477:c4ff:fed8:7ac8/64 Scope:Link
         UP BROADCAST RUNNING NOARP  MTU:1500  Metric:1
         RX packets:0 errors:0 dropped:0 overruns:0 frame:0
         TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:32
         RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

[root@hat1-vm ~]# tc qdisc add dev eth0 ingress
[root@hat1-vm ~]#  tc filter add dev eth0 parent ffff: protocol ip u32 match u32 0 0 flowid 1:1 action mirred egress redirect dev ifb0
[root@hat1-vm ~]#  tc qdisc add dev ifb0 root netem delay 500ms

[root@hat1-vm ~]# tc -s qdisc show dev eth0
qdisc pfifo_fast 0: bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
qdisc ingress ffff: ----------------
Sent 276 bytes 6 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0

500msの遅延

[root@hat1-vm ~]# ping 192.168.11.15
PING 192.168.11.15 (192.168.11.15) 56(84) bytes of data.
64 bytes from 192.168.11.15: icmp_seq=1 ttl=64 time=500 ms
64 bytes from 192.168.11.15: icmp_seq=2 ttl=64 time=500 ms
64 bytes from 192.168.11.15: icmp_seq=3 ttl=64 time=500 ms

ping 先 ( 192.168.11.15 ) でキャプチャ
対抗先で delay がないので、受信後に遅延が発生している(incomingでdelay)と読み取れる。

[root@hat2-vm html]# tshark -i eth0 icmp
Running as user "root" and group "root". This could be dangerous.
Capturing on eth0
eth0: Promiscuous mode enabled.
 0.000000 192.168.11.14 -> 192.168.11.15 ICMP Echo (ping) request
 0.000013 192.168.11.15 -> 192.168.11.14 ICMP Echo (ping) reply
 1.003810 192.168.11.14 -> 192.168.11.15 ICMP Echo (ping) request
 1.003835 192.168.11.15 -> 192.168.11.14 ICMP Echo (ping) reply
 2.006794 192.168.11.14 -> 192.168.11.15 ICMP Echo (ping) request
 2.006820 192.168.11.15 -> 192.168.11.14 ICMP Echo (ping) reply