Skip to content

PktCounter

Ondrej Lichtner edited this page Nov 4, 2016 · 3 revisions

1. Basic description

This test uses iptables to count incoming packets on a specified interface, port and protocol. The test can be used to get diagnostic information about specific types of traffic on slave machines.

2. Options

This test module accepts the following options. They will be used to create a rule for iptables which will count the packets for us.

input_netdev_name specifies the name of the device on which we will be listening, represents the option -i for iptables.
dport specifies the port on which we will be listening, represents the option --dport for iptables.
proto specifies the protocol we are looking for, represents the option -p for iptables.
ipv6 makes PktCounter use ip6tables instead of iptables.

3. Usage Example

This test module serves for gathering diagnostic information, therefore it must be run on the background. Other than that usage is very basic, as can be seen in the following recipe snippet. I am also using the IcmpPing test module to create some artificial traffic that our PktCounter can detect.

<run module="PktCounter" host="testmachine2" bg_id="test">
    <options>
        <option name="input_netdev_name" value="{devname(testmachine2, testifc2)}"/>
        <option name="proto" value="icmp"/>
    </options>
</run>
<run module="IcmpPing" host="testmachine1">
    <options>
        <option name="addr" value="{ip(testmachine2, testifc2)}"/>
        <option name="count" value="20"/>
        <option name="interval" value="0"/>
    </options>
</run>
<intr host="testmachine2" bg_id="test"/>

4. Results

Unless there was an error during execution of some shell commands, the test will always result with a PASS returning the diagnostic information about the count of the specified packets.

The results of commands in the previous sections will look something like this:

25/01 12:55:18|       (127.0.0.1) INFO: Executing command: [type (test), machine_id (testmachine2), value (PktCounter), bg_id (test)]
25/01 12:55:17|  (192.168.122.30) DEBUG: Running in background with id "test", pid "3167"
25/01 12:55:18|       (127.0.0.1) DEBUG: Result: {'passed': True}
25/01 12:55:19|       (127.0.0.1) INFO: Executing command: [type (test), machine_id (testmachine1), value (IcmpPing)]
25/01 12:55:17| (192.168.122.109) DEBUG: Executing: "ping 192.168.100.2 -c 20 -i 0"
25/01 12:55:17| (192.168.122.109) DEBUG: 
    Stdout:
    ----------------------------
    PING 192.168.100.2 (192.168.100.2) 56(84) bytes of data.
    64 bytes from 192.168.100.2: icmp_seq=1 ttl=64 time=2.67 ms
    64 bytes from 192.168.100.2: icmp_seq=2 ttl=64 time=0.327 ms
    64 bytes from 192.168.100.2: icmp_seq=3 ttl=64 time=0.230 ms
    64 bytes from 192.168.100.2: icmp_seq=4 ttl=64 time=0.428 ms
    64 bytes from 192.168.100.2: icmp_seq=5 ttl=64 time=0.423 ms
    64 bytes from 192.168.100.2: icmp_seq=6 ttl=64 time=0.479 ms
    64 bytes from 192.168.100.2: icmp_seq=7 ttl=64 time=0.402 ms
    64 bytes from 192.168.100.2: icmp_seq=8 ttl=64 time=0.447 ms
    64 bytes from 192.168.100.2: icmp_seq=9 ttl=64 time=0.398 ms
    64 bytes from 192.168.100.2: icmp_seq=10 ttl=64 time=0.428 ms
    64 bytes from 192.168.100.2: icmp_seq=11 ttl=64 time=0.396 ms
    64 bytes from 192.168.100.2: icmp_seq=12 ttl=64 time=0.246 ms
    64 bytes from 192.168.100.2: icmp_seq=13 ttl=64 time=0.233 ms
    64 bytes from 192.168.100.2: icmp_seq=14 ttl=64 time=0.231 ms
    64 bytes from 192.168.100.2: icmp_seq=15 ttl=64 time=0.246 ms
    64 bytes from 192.168.100.2: icmp_seq=16 ttl=64 time=0.238 ms
    64 bytes from 192.168.100.2: icmp_seq=17 ttl=64 time=0.207 ms
    64 bytes from 192.168.100.2: icmp_seq=18 ttl=64 time=0.212 ms
    64 bytes from 192.168.100.2: icmp_seq=19 ttl=64 time=0.208 ms
    64 bytes from 192.168.100.2: icmp_seq=20 ttl=64 time=0.209 ms
    
    --- 192.168.100.2 ping statistics ---
    20 packets transmitted, 20 received, 0% packet loss, time 10ms
    rtt min/avg/max/mdev = 0.207/0.433/2.677/0.523 ms, ipg/ewma 0.572/0.456 ms
    ----------------------------
25/01 12:55:17| (192.168.122.109) DEBUG: Transmitted "20", received "20", rate "100%", limit_rate "80%"
25/01 12:55:17| (192.168.122.109) DEBUG: rtt min "0.207", avg "0.433", max "2.677", mdev "0.523"
25/01 12:55:17| (192.168.122.109) DEBUG: PASSED
25/01 12:55:19|       (127.0.0.1) DEBUG: Result: {'res_data': {'rate': 100}, 'passed': True}
25/01 12:55:19|       (127.0.0.1) INFO: Result data: {'rate': 100}
25/01 12:55:19|       (127.0.0.1) INFO: Executing command: [type (intr), machine_id (testmachine2), value (test)]
25/01 12:55:18|  (192.168.122.30) DEBUG: Interrupting background command with id "test", pid "3167"
25/01 12:55:17|  (192.168.122.30) DEBUG: Executing: "iptables -L -v -x -n"
25/01 12:55:17|  (192.168.122.30) DEBUG: 
    Stdout:
    ----------------------------
    Chain INPUT (policy ACCEPT 579 packets, 54408 bytes)
        pkts      bytes target     prot opt in     out     source               destination         
    
    Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
        pkts      bytes target     prot opt in     out     source               destination         
    
    Chain OUTPUT (policy ACCEPT 565 packets, 75540 bytes)
        pkts      bytes target     prot opt in     out     source               destination         
    ----------------------------
25/01 12:55:17|  (192.168.122.30) DEBUG: Executing: "iptables -I INPUT -i eth1 -p icmp"
25/01 12:55:18|  (192.168.122.30) DEBUG: Executing: "iptables -L -v -x -n"
25/01 12:55:18|  (192.168.122.30) DEBUG: 
    Stdout:
    ----------------------------
    Chain INPUT (policy ACCEPT 24 packets, 2463 bytes)
        pkts      bytes target     prot opt in     out     source               destination         
          20     1680            icmp --  eth1   *       0.0.0.0/0            0.0.0.0/0           
    
    Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
        pkts      bytes target     prot opt in     out     source               destination         
    
    Chain OUTPUT (policy ACCEPT 23 packets, 2100 bytes)
        pkts      bytes target     prot opt in     out     source               destination         
    ----------------------------
25/01 12:55:18|  (192.168.122.30) DEBUG: Executing: "iptables -D INPUT -i eth1 -p icmp"
25/01 12:55:18|  (192.168.122.30) DEBUG: PASSED
25/01 12:55:19|       (127.0.0.1) DEBUG: Result: {'res_data': {'pkt_count': '20'}, 'passed': True}
25/01 12:55:19|       (127.0.0.1) INFO: Result data: {'pkt_count': '20'}

Clone this wiki locally