Merge "Begin collecting xtables iface counters." into jb-dev

This commit is contained in:
Jeff Sharkey
2012-05-04 12:53:02 -07:00
committed by Android (Google) Code Review
4 changed files with 29 additions and 60 deletions

View File

@@ -31,18 +31,20 @@ public class NetworkState implements Parcelable {
public final LinkCapabilities linkCapabilities; public final LinkCapabilities linkCapabilities;
/** Currently only used by testing. */ /** Currently only used by testing. */
public final String subscriberId; public final String subscriberId;
public final String networkId;
public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties, public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties,
LinkCapabilities linkCapabilities) { LinkCapabilities linkCapabilities) {
this(networkInfo, linkProperties, linkCapabilities, null); this(networkInfo, linkProperties, linkCapabilities, null, null);
} }
public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties, public NetworkState(NetworkInfo networkInfo, LinkProperties linkProperties,
LinkCapabilities linkCapabilities, String subscriberId) { LinkCapabilities linkCapabilities, String subscriberId, String networkId) {
this.networkInfo = networkInfo; this.networkInfo = networkInfo;
this.linkProperties = linkProperties; this.linkProperties = linkProperties;
this.linkCapabilities = linkCapabilities; this.linkCapabilities = linkCapabilities;
this.subscriberId = subscriberId; this.subscriberId = subscriberId;
this.networkId = networkId;
} }
public NetworkState(Parcel in) { public NetworkState(Parcel in) {
@@ -50,6 +52,7 @@ public class NetworkState implements Parcelable {
linkProperties = in.readParcelable(null); linkProperties = in.readParcelable(null);
linkCapabilities = in.readParcelable(null); linkCapabilities = in.readParcelable(null);
subscriberId = in.readString(); subscriberId = in.readString();
networkId = in.readString();
} }
@Override @Override
@@ -63,6 +66,7 @@ public class NetworkState implements Parcelable {
out.writeParcelable(linkProperties, flags); out.writeParcelable(linkProperties, flags);
out.writeParcelable(linkCapabilities, flags); out.writeParcelable(linkCapabilities, flags);
out.writeString(subscriberId); out.writeString(subscriberId);
out.writeString(networkId);
} }
public static final Creator<NetworkState> CREATOR = new Creator<NetworkState>() { public static final Creator<NetworkState> CREATOR = new Creator<NetworkState>() {

View File

@@ -0,0 +1,4 @@
ifname total_skb_rx_bytes total_skb_rx_packets total_skb_tx_bytes total_skb_tx_packets
rmnet2 4968 35 3081 39
rmnet1 11153922 8051 190226 2468
rmnet0 6824 16 5692 10

View File

@@ -81,58 +81,6 @@ public class NetworkStatsFactoryTest extends AndroidTestCase {
assertStatsEntry(stats, "rmnet2", 10001, SET_DEFAULT, 0x0, 1125899906842624L, 984L); assertStatsEntry(stats, "rmnet2", 10001, SET_DEFAULT, 0x0, 1125899906842624L, 984L);
} }
public void testNetworkStatsSummary() throws Exception {
stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev"));
final NetworkStats stats = mFactory.readNetworkStatsSummary();
assertEquals(6, stats.size());
assertStatsEntry(stats, "lo", UID_ALL, SET_ALL, TAG_NONE, 8308L, 8308L);
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_ALL, TAG_NONE, 1507570L, 489339L);
assertStatsEntry(stats, "ifb0", UID_ALL, SET_ALL, TAG_NONE, 52454L, 0L);
assertStatsEntry(stats, "ifb1", UID_ALL, SET_ALL, TAG_NONE, 52454L, 0L);
assertStatsEntry(stats, "sit0", UID_ALL, SET_ALL, TAG_NONE, 0L, 0L);
assertStatsEntry(stats, "ip6tnl0", UID_ALL, SET_ALL, TAG_NONE, 0L, 0L);
}
public void testNetworkStatsSummaryDown() throws Exception {
stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev"));
stageLong(1L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/active"));
stageLong(1024L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/rx_bytes"));
stageLong(128L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/rx_packets"));
stageLong(2048L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/tx_bytes"));
stageLong(256L, new File(mTestProc, "net/xt_qtaguid/iface_stat/wlan0/tx_packets"));
final NetworkStats stats = mFactory.readNetworkStatsSummary();
assertEquals(7, stats.size());
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_ALL, TAG_NONE, 1507570L, 489339L);
assertStatsEntry(stats, "wlan0", UID_ALL, SET_ALL, TAG_NONE, 1024L, 2048L);
}
public void testNetworkStatsCombined() throws Exception {
stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev"));
stageLong(1L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/active"));
stageLong(10L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_bytes"));
stageLong(20L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_packets"));
stageLong(30L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_bytes"));
stageLong(40L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_packets"));
final NetworkStats stats = mFactory.readNetworkStatsSummary();
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_ALL, TAG_NONE, 1507570L + 10L,
2205L + 20L, 489339L + 30L, 2237L + 40L);
}
public void testNetworkStatsCombinedInactive() throws Exception {
stageFile(R.raw.net_dev_typical, new File(mTestProc, "net/dev"));
stageLong(0L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/active"));
stageLong(10L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_bytes"));
stageLong(20L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/rx_packets"));
stageLong(30L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_bytes"));
stageLong(40L, new File(mTestProc, "net/xt_qtaguid/iface_stat/rmnet0/tx_packets"));
final NetworkStats stats = mFactory.readNetworkStatsSummary();
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_ALL, TAG_NONE, 10L, 20L, 30L, 40L);
}
public void testKernelTags() throws Exception { public void testKernelTags() throws Exception {
assertEquals(0, kernelToTag("0x0000000000000000")); assertEquals(0, kernelToTag("0x0000000000000000"));
assertEquals(0x32, kernelToTag("0x0000003200000000")); assertEquals(0x32, kernelToTag("0x0000003200000000"));
@@ -159,13 +107,24 @@ public class NetworkStatsFactoryTest extends AndroidTestCase {
public void testNetworkStatsSingle() throws Exception { public void testNetworkStatsSingle() throws Exception {
stageFile(R.raw.xt_qtaguid_iface_typical, new File(mTestProc, "net/xt_qtaguid/iface_stat_all")); stageFile(R.raw.xt_qtaguid_iface_typical, new File(mTestProc, "net/xt_qtaguid/iface_stat_all"));
final NetworkStats stats = mFactory.readNetworkStatsSummary(); final NetworkStats stats = mFactory.readNetworkStatsSummaryDev();
assertEquals(6, stats.size()); assertEquals(6, stats.size());
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_ALL, TAG_NONE, 2112L, 24L, 700L, 10L); assertStatsEntry(stats, "rmnet0", UID_ALL, SET_ALL, TAG_NONE, 2112L, 24L, 700L, 10L);
assertStatsEntry(stats, "test1", UID_ALL, SET_ALL, TAG_NONE, 6L, 8L, 10L, 12L); assertStatsEntry(stats, "test1", UID_ALL, SET_ALL, TAG_NONE, 6L, 8L, 10L, 12L);
assertStatsEntry(stats, "test2", UID_ALL, SET_ALL, TAG_NONE, 1L, 2L, 3L, 4L); assertStatsEntry(stats, "test2", UID_ALL, SET_ALL, TAG_NONE, 1L, 2L, 3L, 4L);
} }
public void testNetworkStatsXt() throws Exception {
stageFile(R.raw.xt_qtaguid_iface_fmt_typical,
new File(mTestProc, "net/xt_qtaguid/iface_stat_fmt"));
final NetworkStats stats = mFactory.readNetworkStatsSummaryXt();
assertEquals(3, stats.size());
assertStatsEntry(stats, "rmnet0", UID_ALL, SET_ALL, TAG_NONE, 6824L, 16L, 5692L, 10L);
assertStatsEntry(stats, "rmnet1", UID_ALL, SET_ALL, TAG_NONE, 11153922L, 8051L, 190226L, 2468L);
assertStatsEntry(stats, "rmnet2", UID_ALL, SET_ALL, TAG_NONE, 4968L, 35L, 3081L, 39L);
}
/** /**
* Copy a {@link Resources#openRawResource(int)} into {@link File} for * Copy a {@link Resources#openRawResource(int)} into {@link File} for
* testing purposes. * testing purposes.

View File

@@ -30,7 +30,7 @@ import static android.net.NetworkStats.TAG_NONE;
import static android.net.NetworkStats.UID_ALL; import static android.net.NetworkStats.UID_ALL;
import static android.net.NetworkStatsHistory.FIELD_ALL; import static android.net.NetworkStatsHistory.FIELD_ALL;
import static android.net.NetworkTemplate.buildTemplateMobileAll; import static android.net.NetworkTemplate.buildTemplateMobileAll;
import static android.net.NetworkTemplate.buildTemplateWifi; import static android.net.NetworkTemplate.buildTemplateWifiWildcard;
import static android.net.TrafficStats.MB_IN_BYTES; import static android.net.TrafficStats.MB_IN_BYTES;
import static android.net.TrafficStats.UID_REMOVED; import static android.net.TrafficStats.UID_REMOVED;
import static android.net.TrafficStats.UID_TETHERING; import static android.net.TrafficStats.UID_TETHERING;
@@ -94,7 +94,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
private static final String IMSI_1 = "310004"; private static final String IMSI_1 = "310004";
private static final String IMSI_2 = "310260"; private static final String IMSI_2 = "310260";
private static NetworkTemplate sTemplateWifi = buildTemplateWifi(); private static NetworkTemplate sTemplateWifi = buildTemplateWifiWildcard();
private static NetworkTemplate sTemplateImsi1 = buildTemplateMobileAll(IMSI_1); private static NetworkTemplate sTemplateImsi1 = buildTemplateMobileAll(IMSI_1);
private static NetworkTemplate sTemplateImsi2 = buildTemplateMobileAll(IMSI_2); private static NetworkTemplate sTemplateImsi2 = buildTemplateMobileAll(IMSI_2);
@@ -136,7 +136,6 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
mService = new NetworkStatsService( mService = new NetworkStatsService(
mServiceContext, mNetManager, mAlarmManager, mTime, mStatsDir, mSettings); mServiceContext, mNetManager, mAlarmManager, mTime, mStatsDir, mSettings);
mService.bindConnectivityManager(mConnManager); mService.bindConnectivityManager(mConnManager);
mSession = mService.openSession();
mElapsedRealtime = 0L; mElapsedRealtime = 0L;
@@ -154,6 +153,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
replay(); replay();
mService.systemReady(); mService.systemReady();
mSession = mService.openSession();
verifyAndReset(); verifyAndReset();
mNetworkObserver = networkObserver.getValue(); mNetworkObserver = networkObserver.getValue();
@@ -820,7 +820,8 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
} }
private void expectNetworkStatsSummary(NetworkStats summary) throws Exception { private void expectNetworkStatsSummary(NetworkStats summary) throws Exception {
expect(mNetManager.getNetworkStatsSummary()).andReturn(summary).atLeastOnce(); expect(mNetManager.getNetworkStatsSummaryDev()).andReturn(summary).atLeastOnce();
expect(mNetManager.getNetworkStatsSummaryXt()).andReturn(summary).atLeastOnce();
} }
private void expectNetworkStatsUidDetail(NetworkStats detail) throws Exception { private void expectNetworkStatsUidDetail(NetworkStats detail) throws Exception {
@@ -851,6 +852,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
final Config config = new Config(bucketDuration, persistBytes, deleteAge, deleteAge); final Config config = new Config(bucketDuration, persistBytes, deleteAge, deleteAge);
expect(mSettings.getDevConfig()).andReturn(config).anyTimes(); expect(mSettings.getDevConfig()).andReturn(config).anyTimes();
expect(mSettings.getXtConfig()).andReturn(config).anyTimes();
expect(mSettings.getUidConfig()).andReturn(config).anyTimes(); expect(mSettings.getUidConfig()).andReturn(config).anyTimes();
expect(mSettings.getUidTagConfig()).andReturn(config).anyTimes(); expect(mSettings.getUidTagConfig()).andReturn(config).anyTimes();
} }
@@ -912,7 +914,7 @@ public class NetworkStatsServiceTest extends AndroidTestCase {
info.setDetailedState(DetailedState.CONNECTED, null, null); info.setDetailedState(DetailedState.CONNECTED, null, null);
final LinkProperties prop = new LinkProperties(); final LinkProperties prop = new LinkProperties();
prop.setInterfaceName(TEST_IFACE); prop.setInterfaceName(TEST_IFACE);
return new NetworkState(info, prop, null, subscriberId); return new NetworkState(info, prop, null, subscriberId, null);
} }
private static NetworkState buildMobile4gState(String iface) { private static NetworkState buildMobile4gState(String iface) {