4

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

Maxim Shoustin
  • 76,444
  • 28
  • 192
  • 219
  • Have you compared what happens to these counters on an ordinary linux client subjected to the same test? – Chris Stratton Dec 07 '12 at 14:03
  • I had on linux 'netstat -s | grep retransmited` but on Android netstat shows nothing interesting. Because of PL (packet loss) my download rate decrease to 3M. I use NDK (C code). BTW, I activated PL for TCP only. – Maxim Shoustin Dec 07 '12 at 14:17
  • But what do you see in the comparable /sys/class/net statistics on a normal linux? Also, are you sure you are looking at the interface in use? – Chris Stratton Dec 07 '12 at 14:32
  • If you are cleanly dropping packets at a software level of the stack on the router, I'm not sure you should expect to see errors in the network interface statistics. These would not be dropped as far as the interface on the device is concerned (that counter would more likely show if the device itself had dropped any packets). To see the effect of packets simply dropped at the remote end, you'd probably need to look at retry counts at the TCP level, or even within an application where UDP is concerned. – Chris Stratton Dec 07 '12 at 14:41
  • @ChrisStratton no, but this is a most appropriate place because I see Tx/Rx byts/frames there. The question is if I can extract PL through Java or C or other way – Maxim Shoustin Dec 07 '12 at 15:14
  • I use HTTP for download. The Dummynet service drops X% of frames therefore i must see retransmission attempts. – Maxim Shoustin Dec 07 '12 at 15:16
  • Not from here, as packets cleanly dropped by the router are not fault conditions as far as the network interface is concerned. If you want to see retries in an HTTP interchange you will need to look at TCP level statistics, not interface level ones. – Chris Stratton Dec 07 '12 at 15:17
  • @ChrisStratton agree, so where I can see that? Android is not rooted – Maxim Shoustin Dec 07 '12 at 15:19
  • You might see it in /proc/net/tcp or /proc/net/tcp6, though I'm not being able to get that counter to increment in a simple test with the device inside a metal filing cabinet and an ssh session running 'yes'. – Chris Stratton Dec 07 '12 at 15:41
  • @ChrisStratton thanks, ill try to verify it today (tcp/tcp6) – Maxim Shoustin Dec 09 '12 at 06:13
  • Probably because you're not actually using `eth0` and should use either `wlan0` or `rmnet` in **/sys/class/net/`eth0`/statistics.** – not2qubit Dec 27 '17 at 21:37

2 Answers2

3

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.

Community
  • 1
  • 1
Dave
  • 3,118
  • 4
  • 25
  • 44
  • Thank you for response. I use `TrafficStats` through NDK (C code) since I do it faster than Java implementation. I know 100%, that Access Point has packet loss 2%. The aim is to read packet loss counters from Android without do any activity like send UDP with payload ..... – Maxim Shoustin Dec 13 '12 at 07:28
2

I think, the counters you need are in the /proc/net/netstat file.

ljudoed
  • 21
  • 3