1 <html devsite> 2 <head> 3 <title>Network Interface Statistics Overview</title> 4 <meta name="project_path" value="/_project.yaml" /> 5 <meta name="book_path" value="/_book.yaml" /> 6 </head> 7 <body> 8 <!-- 9 Copyright 2017 The Android Open Source Project 10 11 Licensed under the Apache License, Version 2.0 (the "License"); 12 you may not use this file except in compliance with the License. 13 You may obtain a copy of the License at 14 15 http://www.apache.org/licenses/LICENSE-2.0 16 17 Unless required by applicable law or agreed to in writing, software 18 distributed under the License is distributed on an "AS IS" BASIS, 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 See the License for the specific language governing permissions and 21 limitations under the License. 22 --> 23 24 25 <p>In Android 4.0, statistics reported by Linux network interfaces are 26 recorded over time, and are used to enforce network quota limits, 27 render user-visible charts, and more.</p> 28 <p>Each network device driver (Wi-Fi included) must follow the standard 29 kernel device lifecycle, and return correct statistics through 30 <code>dev_get_stats()</code>. In particular, statistics returned must remain 31 strictly monotonic while the interface is active. Drivers may reset 32 statistics only after successfully completing an <code>unregister_netdev()</code> 33 or the equivalent that generates a <code>NETDEV_UNREGISTER</code> event for 34 callbacks registered with <code>register_netdevice_notifier()</code> / 35 <code>register_inetaddr_notifier()</code> / <code>register_inet6addr_notifier()</code>.</p> 36 <p>Mobile operators typically measure data usage at the Internet layer 37 (IP). To match this approach in Android 4.0, we rely on the fact that 38 for the kernel devices we care about the <code>rx_bytes</code> and <code>tx_bytes</code> 39 values returned by <code>dev_get_stats()</code> return exactly the Internet layer 40 (<code>IP</code>) bytes transferred. But we understand that for other devices it 41 might not be the case. For now, the feature relies on this 42 peculiarity. New drivers should have that property also, and the 43 <code>dev_get_stats()</code> values must not include any encapsulation overhead 44 of lower network layers (such as Ethernet headers), and should 45 preferably not include other traffic (such as ARP) unless it is 46 negligible.</p> 47 <p>The Android framework only collects statistics from network interfaces 48 associated with a <code>NetworkStateTracker</code> in <code>ConnectivityService</code>. This 49 enables the framework to concretely identify each network interface, 50 including its type (such as <code>TYPE_MOBILE</code> or <code>TYPE_WIFI</code>) and 51 subscriber identity (such as IMSI). All network interfaces used to 52 route data should be represented by a <code>NetworkStateTracker</code> so that 53 statistics can be accounted correctly.</p> 54 55 </body> 56 </html> 57