Quantcast
Channel: Network – Benjr.tw
Viewing all articles
Browse latest Browse all 56

Pktgen – netfilter

$
0
0

前面有介紹過 Pktgen 簡介 ,這次採用的方式是同一個系統自己跟自己的網路埠互相對打,架構圖如下:
pktgen02

不過這一次採用另外一個版本的 pktgen ,是由 IT水電工-哆啦胖虎 建議使用的 netfilter – https://people.kth.se/~danieltt/pktgen/

IT水電工-哆啦胖虎:
谷哥大神查到的文章均為 TX 的部分,至於 RX 的部分比較少,按照 https://people.kth.se/~danieltt/pktgen/ 裡有提到需要額外在指定 Kernel 版本下重新編譯 pktgen 的 Module,才有辦法生出 /proc/net/pktgen/pgrx 的 file,或是直接使用 Bifrost/Linux 這支 Distribution,進而從 RX Side 觀察 TX Packet Loss 的情況.

不是系統預設的 pktgen 版本所以必須手動更新.並手動編輯,我的作業系統環境是 Ubuntu14.04

root@ubuntu:~# wget https://github.com/danieltt/pktgen/archive/3.11.0-netfilter.tar.gz
root@ubuntu:~# cd pktgen-3.11.0-netfilter/
root@ubuntu:~/pktgen-3.11.0-netfilter# make
make -C /lib/modules/3.13.0-43-generic/build M=/root/pktgen-3.11.0-netfilter modules 
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-43-generic'
  Building modules, stage 2.
  MODPOST 1 modules
  LD [M]  /root/pktgen-3.11.0-netfilter/pktgen.ko
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-43-generic'
root@ubuntu:~# insert pktgen.ko

這個版本會多出一個 Pktgen receiver 的檔案 /proc/net/pktgen/pgrx ,可用的控制指令如下:

  • rx [device]: to enable the receiver part for a specific device. If it is wrong, all the devices are used. (all versions)
  • rx_reset: to reset the counters
  • rx_disable: to disable the receiver
  • display [human or script]
  • statistics [counter, basic, basic6 or time]

In the transmission the config parameter is added in the config version <- 不確定使用時機

  • config [0 or 1]: Enables or disables the configuration packet, which reset the statistics and allows to calculate the losses.
root@ubuntu:/proc/net/pktgen# ll /proc/net/pktgen/
total 0
dr-xr-xr-x 2 root root 0 Dec 26 01:19 ./
dr-xr-xr-x 6 root root 0 Dec 26 01:19 ../
-rw------- 1 root root 0 Dec 26 01:19 eth1
-rw------- 1 root root 0 Dec 26 01:19 kpktgend_0
-rw------- 1 root root 0 Dec 26 01:19 kpktgend_1
-rw------- 1 root root 0 Dec 26 01:19 pgctrl
-rw------- 1 root root 0 Dec 26 01:19 pgrx

好了直接看使用方式會比較了解這些參數的使用方式,同一系統從 eth0 (00:0C:29:8F:8A:2B) -> eth1 (00:0C:29:8F:8A:35)

root@ubuntu:/proc/net/pktgen# echo "add_device eth0" > /proc/net/pktgen/kpktgend_0
root@ubuntu:/proc/net/pktgen# echo "count 0" >  /proc/net/pktgen/eth0
root@ubuntu:/proc/net/pktgen# echo "min_pkt_size 46" >  /proc/net/pktgen/eth0
root@ubuntu:/proc/net/pktgen# echo "max_pkt_size 1500" >  /proc/net/pktgen/eth0
root@ubuntu:/proc/net/pktgen# echo "dst_mac 00:0C:29:8F:8A:35" >  /proc/net/pktgen/eth0
root@ubuntu:/proc/net/pktgen# echo "rx eth0" > /proc/net/pktgen/pgrx
  • echo “add_device eth0″ > kpktgend_0
    你可能會看到多個 kpktgend ,kpktgend_0, kpktgend_1, kpktgend_2, kpktgend_3 …. ,這跟你的 CPU 的核心數量會一致,在使用 pktgen 的時候可以設定哪一個網路埠使用哪一個 CPU 核心來處理資料,kpktgend_0 就對應到 CPU 0 這個核心,以此類推 kpktgend_1 對應到 CPU 1 , kpktgend_2 對應到 CPU 2, kpktgend_3 對應到 CPU 3 …
  • echo “count 0″ > /proc/net/pktgen/eth0
    傳送封包次數,0 為無限
  • echo “min_pkt_size 46″ > /proc/net/pktgen/eth0
    最小封包
  • echo “max_pkt_size 1500″ > /proc/net/pktgen/eth0
    最大封包
  • echo “dst_mac 00:0C:29:8F:8A:35″ > /proc/net/pktgen/eth0
    指定對方的 MAC Address
  • echo “rx eth0″ > /proc/net/pktgen/pgrx
    這個版本的特色是可以透過 /proc/net/pktgen/pgrx 檢視 RX 的狀況.

好檢查一下設定值吧!

root@ubuntu:/proc/net/pktgen# cat /proc/net/pktgen/eth0
Params: count 0  min_pkt_size: 46  max_pkt_size: 1500
     frags: 0  delay: 0  clone_skb: 0  ifname: eth0
     flows: 0 flowlen: 0
     queue_map_min: 0  queue_map_max: 0
     dst_min:   dst_max: 
        src_min:   src_max: 
     src_mac: 00:0c:29:8f:8a:2b dst_mac: 00:0c:29:8f:8a:35
     udp_src_min: 9  udp_src_max: 9  udp_dst_min: 9  udp_dst_max: 9
     src_mac_count: 0  dst_mac_count: 0
     Flags: 
Current:
     pkts-sofar: 0  errors: 0
     started: 0us  stopped: 0us idle: 0us
     seq_num: 0  cur_dst_mac_offset: 0  cur_src_mac_offset: 0
     cur_saddr: 0.0.0.0  cur_daddr: 0.0.0.0
     cur_udp_dst: 0  cur_udp_src: 0
     cur_queue_map: 0
     flows: 0
Result: OK: dstmac 00:0c:29:8f:8a:35

開始進行測試

root@ubuntu:/proc/net/pktgen# echo "start" > /proc/net/pktgen/pgctrl
^C

在測試階段你可以看一下封包傳送狀況.

root@ubuntu:/proc/net/pktgen# sar -n DEV 1 1000
08:28:45 PM     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil
08:28:46 PM      eth0      0.00  23392.86      0.00  17786.92      0.00      0.00      0.00     14.57
08:28:46 PM      eth1  23392.86      0.00  17786.92      0.00      0.00      0.00      0.00     14.57
08:28:46 PM        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00

Average:        IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s   %ifutil
Average:         eth0      1.38  15296.88      0.59  11546.07      0.00      0.00      0.00      9.46
Average:         eth1  15295.93     12.92  11545.90      0.76      0.00      0.00      0.00      9.46
Average:           lo      0.33      0.33      0.04      0.04      0.00      0.00      0.00      0.00

透過 /proc/net/pktgen/pgrx 就可以看到 RX 的狀況,不過看起來怪怪的 CPP 1 <- eth1 ,剛剛我設的是 eth0 ???

root@ubuntu:/proc/net/pktgen# cat /proc/net/pktgen/pgrx
		RECEPTION STATISTICS
	PER-CPU Stats
CPU 0:	Rx packets: 0	 Rx bytes: 0
CPU 1:	Rx packets: 1044159	 Rx bytes: 806946501
	Work time 29683915 us
	Rate:  35175pps 217Mb/sec (217477108bps)

	Global Statistics
Packets Rx: 1044159	 Bytes Rx: 806946501
	Work time 29683915 us
	Rate:  35175pps 217Mb/sec (217477108bps)

原先的 /proc/net/pktgen/eth0 還是可以看到資料.

root@ubuntu:/proc/net/pktgen# cat /proc/net/pktgen/eth0
Params: count 0  min_pkt_size: 46  max_pkt_size: 1500
     frags: 0  delay: 0  clone_skb: 0  ifname: eth0
     flows: 0 flowlen: 0
     queue_map_min: 0  queue_map_max: 0
     dst_min:   dst_max: 
        src_min:   src_max: 
     src_mac: 00:0c:29:8f:8a:2b dst_mac: 00:0c:29:8f:8a:35
     udp_src_min: 9  udp_src_max: 9  udp_dst_min: 9  udp_dst_max: 9
     src_mac_count: 0  dst_mac_count: 0
     Flags: 
Current:
     pkts-sofar: 1044159  errors: 0
     started: 943556474us  stopped: 973240569us idle: 134691us
     seq_num: 1044160  cur_dst_mac_offset: 0  cur_src_mac_offset: 0
     cur_saddr: 172.16.175.145  cur_daddr: 0.0.0.0
     cur_udp_dst: 9  cur_udp_src: 9
     cur_queue_map: 0
     flows: 0
Result: OK: 29684095(c29549403+d134691) usec, 1044159 (970byte,0frags)
  35175pps 272Mb/sec (272958000bps) errors: 0

剛剛有提到幾個參數 statistics [counter, basic, basic6 or time],可以看到多了一些封包的統計資料.

root@ubuntu:/proc/net/pktgen# echo "statistics time" > pgrx
root@ubuntu:/proc/net/pktgen# echo "start" > /proc/net/pktgen/pgctrl
^C
root@ubuntu:/proc/net/pktgen# cat pgrx
		RECEPTION STATISTICS
	PER-CPU Stats
CPU 0:	Rx packets: 0	 Rx bytes: 0
CPU 1:	Rx packets: 594077	 Rx bytes: 458822018
	Work time 2189540586 us
	Rate:  271pps 1Mb/sec (1676413bps)
	Inter-arrival
		Average: 35619 ns Variance 2350806601 ns2
		Max: 3119519 ns Min:: 344 ns
		Samples: 43496
	Jitter
		Average: 3976 ns Variance 830305713 ns2
		Max: 2977052 ns Min:: 0 ns
		Samples: 43497
	Latency
		Average: 75564 ns Variance 9736075659 ns2
		Max: 3115268 ns Min:: 53277 ns
		Samples: 43497

	Global Statistics
Packets Rx: 594077	 Bytes Rx: 458822018
	Work time 2189540586 us
	Rate:  271pps 1Mb/sec (1676413bps)

Viewing all articles
Browse latest Browse all 56

Trending Articles


Vimeo 10.7.1 by Vimeo.com, Inc.


UPDATE SC IDOL: TWO BECOME ONE


KASAMBAHAY BILL IN THE HOUSE


Girasoles para colorear


Presence Quotes – Positive Quotes


EASY COME, EASY GO


Love with Heart Breaking Quotes


Re:Mutton Pies (lleechef)


Ka longiing longsem kaba skhem bad kaba khlain ka pynlong kein ia ka...


Vimeo 10.7.0 by Vimeo.com, Inc.


FORECLOSURE OF REAL ESTATE MORTGAGE


FORTUITOUS EVENT


Pokemon para colorear


Sapos para colorear


Smile Quotes


Letting Go Quotes


Love Song lyrics that marks your Heart


RE: Mutton Pies (frankie241)


Hato lada ym dei namar ka jingpyrshah jong U JJM Nichols Roy (Bah Joy) ngin...


Long Distance Relationship Tagalog Love Quotes