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