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