Add binder call tetherOffloadGetStats
This binder call is separated from the existing call tetherGetStats
and used for for BPF tether stats.
Note that the default value of ifIndex of TetherStatsParcel.aidl is
applied for backward compatibility because it is added from this
commit.
Make netd modules to use netd_aidl_interface-unstable-cpp.
Both netd and libnetd_server use unstable aidl for new api
tetherOffload* and modified parcel TetherStatsParcel.
Generated with:
m netd_aidl_interface-update-api
Bug: 150736748
Test: atest
Original-Change: https://android-review.googlesource.com/1256108
Merged-In: Ie03834bc40992a4abdc8ef70150569982092b386
Change-Id: Ie03834bc40992a4abdc8ef70150569982092b386
diff --git a/server/TetherControllerTest.cpp b/server/TetherControllerTest.cpp
index fd6e43a..d2ff4a7 100644
--- a/server/TetherControllerTest.cpp
+++ b/server/TetherControllerTest.cpp
@@ -43,17 +43,20 @@
using ::testing::Contains;
using TetherStats = android::net::TetherController::TetherStats;
using TetherStatsList = android::net::TetherController::TetherStatsList;
+using TetherOffloadStats = android::net::TetherController::TetherOffloadStats;
+using TetherOffloadStatsList = android::net::TetherController::TetherOffloadStatsList;
namespace android {
namespace net {
constexpr int TEST_MAP_SIZE = 10;
-// Comparison for TetherStats. Need to override operator== because class TetherStats doesn't have.
-// TODO: once C++20 is used, use default operator== in TetherStats and remove the overriding here.
-bool operator==(const TetherStats& lhs, const TetherStats& rhs) {
- return lhs.intIface == rhs.intIface && lhs.extIface == rhs.extIface &&
- lhs.rxBytes == rhs.rxBytes && lhs.txBytes == rhs.txBytes &&
+// Comparison for TetherOffloadStats. Need to override operator== because class TetherOffloadStats
+// doesn't have one.
+// TODO: once C++20 is used, use default operator== in TetherOffloadStats and remove the overriding
+// here.
+bool operator==(const TetherOffloadStats& lhs, const TetherOffloadStats& rhs) {
+ return lhs.ifIndex == rhs.ifIndex && lhs.rxBytes == rhs.rxBytes && lhs.txBytes == rhs.txBytes &&
lhs.rxPackets == rhs.rxPackets && lhs.txPackets == rhs.txPackets;
}
@@ -65,41 +68,33 @@
protected:
TetherController mTetherCtrl;
- BpfMap<uint32_t, IfaceValue> mFakeIfaceIndexNameMap{BPF_MAP_TYPE_HASH, TEST_MAP_SIZE};
BpfMap<uint32_t, TetherStatsValue> mFakeTetherStatsMap{BPF_MAP_TYPE_HASH, TEST_MAP_SIZE};
BpfMap<uint32_t, uint64_t> mFakeTetherLimitMap{BPF_MAP_TYPE_HASH, TEST_MAP_SIZE};
void SetUp() {
SKIP_IF_BPF_NOT_SUPPORTED;
- ASSERT_TRUE(mFakeIfaceIndexNameMap.isValid());
ASSERT_TRUE(mFakeTetherStatsMap.isValid());
ASSERT_TRUE(mFakeTetherLimitMap.isValid());
- mTetherCtrl.mIfaceIndexNameMap = mFakeIfaceIndexNameMap;
- ASSERT_TRUE(mTetherCtrl.mIfaceIndexNameMap.isValid());
mTetherCtrl.mBpfStatsMap = mFakeTetherStatsMap;
ASSERT_TRUE(mTetherCtrl.mBpfStatsMap.isValid());
mTetherCtrl.mBpfLimitMap = mFakeTetherLimitMap;
ASSERT_TRUE(mTetherCtrl.mBpfLimitMap.isValid());
}
- std::string toString(const TetherStatsList& statsList) {
+ std::string toString(const TetherOffloadStatsList& statsList) {
std::string result;
for (const auto& stats : statsList) {
- result += StringPrintf("%s, %s, %" PRId64 ", %" PRId64 ", %" PRId64 ", %" PRId64 "\n",
- stats.intIface.c_str(), stats.extIface.c_str(), stats.rxBytes,
- stats.rxPackets, stats.txBytes, stats.txPackets);
+ result += StringPrintf("%d, %" PRId64 ", %" PRId64 ", %" PRId64 ", %" PRId64 "\n",
+ stats.ifIndex, stats.rxBytes, stats.rxPackets, stats.txBytes,
+ stats.txPackets);
}
return result;
}
- void updateMaps(uint32_t ifaceIndex, const char* ifaceName, uint64_t rxBytes,
- uint64_t rxPackets, uint64_t txBytes, uint64_t txPackets) {
- IfaceValue iface{};
- strlcpy(iface.name, ifaceName, sizeof(iface.name));
- ASSERT_RESULT_OK(mFakeIfaceIndexNameMap.writeValue(ifaceIndex, iface, BPF_ANY));
-
+ void updateMaps(uint32_t ifaceIndex, uint64_t rxBytes, uint64_t rxPackets, uint64_t txBytes,
+ uint64_t txPackets) {
// {rx, tx}Errors in |tetherStats| are set zero because getTetherStats doesn't use them.
const TetherStatsValue tetherStats = {rxPackets, rxBytes, 0 /*unused*/,
txPackets, txBytes, 0 /*unused*/};
@@ -490,31 +485,20 @@
EXPECT_TRUE(std::equal(expectedError.rbegin(), expectedError.rend(), err.rbegin()));
}
-TEST_F(TetherControllerTest, TestGetTetherStatsWithBpfTetherStatsMap) {
+TEST_F(TetherControllerTest, TestTetherOffloadGetStats) {
SKIP_IF_BPF_NOT_SUPPORTED;
- // Setup BPF tether stats maps. The tether stats of interface rmnet0 comes from two tether
- // stats map items with different interface index. Therefore, need to sum up both of them
- // for the tether stats of interface rmnet0.
- updateMaps(101, "wlan0", 100, 10, 200, 20);
- updateMaps(102, "rmnet0", 300, 30, 400, 40);
- updateMaps(103, "rmnet0", 500, 50, 600, 60);
- const TetherStats expected0("BPFOffloadInterface", "wlan0", 100, 10, 200, 20);
- const TetherStats expected1("BPFOffloadInterface", "rmnet0", 800, 80, 1000, 100);
+ updateMaps(101, 100, 10, 200, 20);
+ updateMaps(102, 300, 30, 400, 40);
+ const TetherOffloadStats expected0{101, 100, 10, 200, 20};
+ const TetherOffloadStats expected1{102, 300, 30, 400, 40};
- // Setup iptables tether counters. IPv4 and IPv6 counters are added together.
- addIptablesRestoreOutput(kIPv4TetherCounters, kIPv6TetherCounters);
- const TetherStats expected2("wlan0", "rmnet0", 20002002, 20027, 10002373, 10026);
- const TetherStats expected3("bt-pan", "rmnet0", 1708806, 1450, 107471, 1040);
-
- const StatusOr<TetherStatsList> result = mTetherCtrl.getTetherStats();
+ const StatusOr<TetherOffloadStatsList> result = mTetherCtrl.getTetherOffloadStats();
ASSERT_OK(result);
- const TetherStatsList& actual = result.value();
- ASSERT_EQ(4U, actual.size());
+ const TetherOffloadStatsList& actual = result.value();
+ ASSERT_EQ(2U, actual.size());
EXPECT_THAT(actual, Contains(expected0)) << toString(actual);
EXPECT_THAT(actual, Contains(expected1)) << toString(actual);
- EXPECT_THAT(actual, Contains(expected2)) << toString(actual);
- EXPECT_THAT(actual, Contains(expected3)) << toString(actual);
clearIptablesRestoreOutput();
}