I’m looking for the way to read packet loss counters from WiFi network.
It should be over adb shell or Java or C (NDK) or your way
Android is not rooted.
I have an Access Point where I configured packet loss 2% with Dummynet service.
I use wget command from PC and download 50 Mb file from local server (Band Width for LAN should be `100Mb). I see that after packet loss configuration Band Width reduced from 100Mb to 3Mb, its mean that all works fine.
So far so good,
My device (Android) is connected to above mentioned AP by WiFi.
I try to download the same 50 Mb file , download rate is 3M but I don’t see any error or retransmission counters rise.
I use adb shell CLI and entered to: sys/class/net/eth0/statistics where I see:
-r--r--r-- root root 4096 2012-12-04 15:42 rx_packets
-r--r--r-- root root 4096 2012-12-04 15:42 tx_packets
-r--r--r-- root root 4096 2012-12-04 15:41 rx_bytes
-r--r--r-- root root 4096 2012-12-04 15:41 tx_bytes
-r--r--r-- root root 4096 2012-12-04 15:43 rx_errors
-r--r--r-- root root 4096 2012-12-04 15:43 tx_errors
-r--r--r-- root root 4096 2012-12-04 15:43 rx_dropped
-r--r--r-- root root 4096 2012-12-04 15:43 tx_dropped
-r--r--r-- root root 4096 2012-12-04 15:43 multicast
-r--r--r-- root root 4096 2012-12-04 15:43 collisions
-r--r--r-- root root 4096 2012-12-04 15:43 rx_length_errors
-r--r--r-- root root 4096 2012-12-04 15:43 rx_over_errors
-r--r--r-- root root 4096 2012-12-04 15:43 rx_crc_errors
-r--r--r-- root root 4096 2012-12-04 15:38 rx_frame_errors
-r--r--r-- root root 4096 2012-12-04 15:38 rx_fifo_errors
-r--r--r-- root root 4096 2012-12-04 15:38 rx_missed_errors
-r--r--r-- root root 4096 2012-12-04 15:38 tx_aborted_errors
-r--r--r-- root root 4096 2012-12-04 15:38 tx_carrier_errors
-r--r--r-- root root 4096 2012-12-04 15:38 tx_fifo_errors
-r--r--r-- root root 4096 2012-12-04 15:38 tx_heartbeat_errors
-r--r--r-- root root 4096 2012-12-04 15:38 tx_window_errors
-r--r--r-- root root 4096 2012-12-04 15:38 rx_compressed
-r--r--r-- root root 4096 2012-12-04 15:38 tx_compressed
So I run cat * and get all above mentioned files with 0 value except 4:
tx/rx_packets/bytes are active , it’s mean that I use write interface:
cat rx_packets
9106
If any know other way to detect packet loss or get it programmatically would be greatly appreciated
Unless I’m mistaken about your requirements. You could use wireshark if you are connected to the same network as your mobile device.
Or you can do a tcpdump and then analyze it through wireshark to get packet loss.
Here are a bunch of links that might help you.
http://dennismillerdev.wordpress.com/2011/02/03/debug-network-activity-in-android-using-wireshark/
http://mobile.tutsplus.com/tutorials/android/analyzing-android-network-traffic/
Capturing mobile phone traffic on wireshark
If you you are just trying to do a generic connectivity test. You could try simply sending a series of UDP packets to a server that echoes back the same packet in response. Have a separate thread running concurrently that is trying to receive these packets from the server. Record the timestamp if you want for other measurements, but if there are fewer packets returned than sent, you know how many packets were lost. If you give the packets a 1 byte payload that contains an id. (ie: send 20 packets with id’s 1-20) and then when you receive the packets from the server you can check the payload and see which packets were lost and/or out of sequence.
Other than that, you are limited without rooting your phone. You can use TrafficStats to get the number of packets sent getTotalRxPackets() or getTotalTxPackets() to get total packets sent/received. Or if you using a higher level API you can even get the number of UDP packets per application. So you could find the number of packets sent, and received but not lost.
If you know how many packets the device is sending, and on the server side detect the number of packets coming in from that device, the difference should help give you an idea of the number of lost packets too. (This method would require you to have control of the server and involve some more device-server communication)
Hopefully this helps.