upload android base code part4
This commit is contained in:
parent
b9e30e05b1
commit
78ea2404cd
23455 changed files with 5250148 additions and 0 deletions
7
android/hardware/interfaces/tetheroffload/Android.bp
Normal file
7
android/hardware/interfaces/tetheroffload/Android.bp
Normal file
|
@ -0,0 +1,7 @@
|
|||
// This is an autogenerated file, do not edit.
|
||||
subdirs = [
|
||||
"config/1.0",
|
||||
"config/1.0/vts/functional",
|
||||
"control/1.0",
|
||||
"control/1.0/vts/functional",
|
||||
]
|
|
@ -0,0 +1,62 @@
|
|||
// This file is autogenerated by hidl-gen. Do not edit manually.
|
||||
|
||||
filegroup {
|
||||
name: "android.hardware.tetheroffload.config@1.0_hal",
|
||||
srcs: [
|
||||
"IOffloadConfig.hal",
|
||||
],
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "android.hardware.tetheroffload.config@1.0_genc++",
|
||||
tools: ["hidl-gen"],
|
||||
cmd: "$(location hidl-gen) -o $(genDir) -Lc++-sources -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.tetheroffload.config@1.0",
|
||||
srcs: [
|
||||
":android.hardware.tetheroffload.config@1.0_hal",
|
||||
],
|
||||
out: [
|
||||
"android/hardware/tetheroffload/config/1.0/OffloadConfigAll.cpp",
|
||||
],
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "android.hardware.tetheroffload.config@1.0_genc++_headers",
|
||||
tools: ["hidl-gen"],
|
||||
cmd: "$(location hidl-gen) -o $(genDir) -Lc++-headers -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.tetheroffload.config@1.0",
|
||||
srcs: [
|
||||
":android.hardware.tetheroffload.config@1.0_hal",
|
||||
],
|
||||
out: [
|
||||
"android/hardware/tetheroffload/config/1.0/IOffloadConfig.h",
|
||||
"android/hardware/tetheroffload/config/1.0/IHwOffloadConfig.h",
|
||||
"android/hardware/tetheroffload/config/1.0/BnHwOffloadConfig.h",
|
||||
"android/hardware/tetheroffload/config/1.0/BpHwOffloadConfig.h",
|
||||
"android/hardware/tetheroffload/config/1.0/BsOffloadConfig.h",
|
||||
],
|
||||
}
|
||||
|
||||
cc_library {
|
||||
name: "android.hardware.tetheroffload.config@1.0",
|
||||
defaults: ["hidl-module-defaults"],
|
||||
generated_sources: ["android.hardware.tetheroffload.config@1.0_genc++"],
|
||||
generated_headers: ["android.hardware.tetheroffload.config@1.0_genc++_headers"],
|
||||
export_generated_headers: ["android.hardware.tetheroffload.config@1.0_genc++_headers"],
|
||||
vendor_available: true,
|
||||
vndk: {
|
||||
enabled: true,
|
||||
},
|
||||
shared_libs: [
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"libhwbinder",
|
||||
"liblog",
|
||||
"libutils",
|
||||
"libcutils",
|
||||
],
|
||||
export_shared_lib_headers: [
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"libhwbinder",
|
||||
"libutils",
|
||||
],
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.hardware.tetheroffload.config@1.0;
|
||||
|
||||
|
||||
/**
|
||||
* Interface used for configuring the hardware management process
|
||||
*/
|
||||
interface IOffloadConfig {
|
||||
/**
|
||||
* Provides bound netlink file descriptors for use in the management process
|
||||
*
|
||||
* @param fd1 A file descriptor bound to the following netlink groups
|
||||
* (NF_NETLINK_CONNTRACK_NEW | NF_NETLINK_CONNTRACK_DESTROY).
|
||||
* @param fd2 A file descriptor bound to the following netlink groups
|
||||
* (NF_NETLINK_CONNTRACK_UPDATE | NF_NETLINK_CONNTRACK_DESTROY).
|
||||
*
|
||||
* @return success true if successful, false otherwise
|
||||
* @return errMsg a human readable string if eror has occured.
|
||||
*/
|
||||
setHandles(handle fd1, handle fd2) generates (bool success, string errMsg);
|
||||
};
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2017 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
cc_test {
|
||||
name: "VtsHalTetheroffloadConfigV1_0TargetTest",
|
||||
defaults: ["VtsHalTargetTestDefaults"],
|
||||
srcs: ["VtsHalTetheroffloadConfigV1_0TargetTest.cpp"],
|
||||
static_libs: ["android.hardware.tetheroffload.config@1.0"],
|
||||
}
|
|
@ -0,0 +1,182 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "VtsOffloadConfigV1_0TargetTest"
|
||||
|
||||
#include <VtsHalHidlTargetTestBase.h>
|
||||
#include <android-base/stringprintf.h>
|
||||
#include <android-base/unique_fd.h>
|
||||
#include <android/hardware/tetheroffload/config/1.0/IOffloadConfig.h>
|
||||
#include <linux/netfilter/nfnetlink.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <log/log.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#include <set>
|
||||
|
||||
using android::base::StringPrintf;
|
||||
using android::base::unique_fd;
|
||||
using android::hardware::hidl_handle;
|
||||
using android::hardware::hidl_string;
|
||||
using android::hardware::Return;
|
||||
using android::hardware::tetheroffload::config::V1_0::IOffloadConfig;
|
||||
using android::hardware::Void;
|
||||
using android::sp;
|
||||
|
||||
#define ASSERT_TRUE_CALLBACK \
|
||||
[&](bool success, const hidl_string& errMsg) { ASSERT_TRUE(success) << errMsg.c_str(); }
|
||||
|
||||
#define ASSERT_FALSE_CALLBACK \
|
||||
[&](bool success, const hidl_string& errMsg) { ASSERT_FALSE(success) << errMsg.c_str(); }
|
||||
|
||||
const unsigned kFd1Groups = NF_NETLINK_CONNTRACK_NEW | NF_NETLINK_CONNTRACK_DESTROY;
|
||||
const unsigned kFd2Groups = NF_NETLINK_CONNTRACK_UPDATE | NF_NETLINK_CONNTRACK_DESTROY;
|
||||
|
||||
inline const sockaddr* asSockaddr(const sockaddr_nl* nladdr) {
|
||||
return reinterpret_cast<const sockaddr*>(nladdr);
|
||||
}
|
||||
|
||||
int netlinkSocket(int protocol, unsigned groups) {
|
||||
unique_fd s(socket(AF_NETLINK, SOCK_DGRAM, protocol));
|
||||
if (s.get() < 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
const struct sockaddr_nl bind_addr = {
|
||||
.nl_family = AF_NETLINK, .nl_pad = 0, .nl_pid = 0, .nl_groups = groups,
|
||||
};
|
||||
if (::bind(s.get(), asSockaddr(&bind_addr), sizeof(bind_addr)) != 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
const struct sockaddr_nl kernel_addr = {
|
||||
.nl_family = AF_NETLINK, .nl_pad = 0, .nl_pid = 0, .nl_groups = groups,
|
||||
};
|
||||
if (::connect(s.get(), asSockaddr(&kernel_addr), sizeof(kernel_addr)) != 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
return s.release();
|
||||
}
|
||||
|
||||
int netlinkSocket(unsigned groups) {
|
||||
return netlinkSocket(NETLINK_NETFILTER, groups);
|
||||
}
|
||||
|
||||
class OffloadConfigHidlTest : public testing::VtsHalHidlTargetTestBase {
|
||||
public:
|
||||
virtual void SetUp() override {
|
||||
config = testing::VtsHalHidlTargetTestBase::getService<IOffloadConfig>();
|
||||
ASSERT_NE(nullptr, config.get()) << "Could not get HIDL instance";
|
||||
}
|
||||
|
||||
virtual void TearDown() override {}
|
||||
|
||||
sp<IOffloadConfig> config;
|
||||
};
|
||||
|
||||
// Ensure handles can be set with correct socket options.
|
||||
TEST_F(OffloadConfigHidlTest, TestSetHandles) {
|
||||
// Try multiple times in a row to see if it provokes file descriptor leaks.
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
unique_fd fd1(netlinkSocket(kFd1Groups));
|
||||
if (fd1.get() < 0) {
|
||||
ALOGE("Unable to create conntrack handles: %d/%s", errno, strerror(errno));
|
||||
FAIL();
|
||||
}
|
||||
native_handle_t* const nativeHandle1 = native_handle_create(1, 0);
|
||||
nativeHandle1->data[0] = fd1.release();
|
||||
hidl_handle h1;
|
||||
h1.setTo(nativeHandle1, true);
|
||||
|
||||
unique_fd fd2(netlinkSocket(kFd2Groups));
|
||||
if (fd2.get() < 0) {
|
||||
ALOGE("Unable to create conntrack handles: %d/%s", errno, strerror(errno));
|
||||
FAIL();
|
||||
}
|
||||
native_handle_t* const nativeHandle2 = native_handle_create(1, 0);
|
||||
nativeHandle2->data[0] = fd2.release();
|
||||
hidl_handle h2;
|
||||
h2.setTo(nativeHandle2, true);
|
||||
|
||||
const Return<void> ret = config->setHandles(h1, h2, ASSERT_TRUE_CALLBACK);
|
||||
ASSERT_TRUE(ret.isOk());
|
||||
}
|
||||
}
|
||||
|
||||
// Passing a handle without an associated file descriptor should return an error
|
||||
// (e.g. "Failed Input Checks"). Check that this occurs when both FDs are empty.
|
||||
TEST_F(OffloadConfigHidlTest, TestSetHandleNone) {
|
||||
native_handle_t* const nativeHandle1 = native_handle_create(0, 0);
|
||||
hidl_handle h1;
|
||||
h1.setTo(nativeHandle1, true);
|
||||
native_handle_t* const nativeHandle2 = native_handle_create(0, 0);
|
||||
hidl_handle h2;
|
||||
h2.setTo(nativeHandle2, true);
|
||||
|
||||
const Return<void> ret = config->setHandles(h1, h2, ASSERT_FALSE_CALLBACK);
|
||||
ASSERT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Passing a handle without an associated file descriptor should return an error
|
||||
// (e.g. "Failed Input Checks"). Check that this occurs when FD2 is empty.
|
||||
TEST_F(OffloadConfigHidlTest, TestSetHandle1Only) {
|
||||
unique_fd fd1(netlinkSocket(kFd1Groups));
|
||||
if (fd1.get() < 0) {
|
||||
ALOGE("Unable to create conntrack handles: %d/%s", errno, strerror(errno));
|
||||
FAIL();
|
||||
}
|
||||
native_handle_t* const nativeHandle1 = native_handle_create(1, 0);
|
||||
nativeHandle1->data[0] = fd1.release();
|
||||
hidl_handle h1;
|
||||
h1.setTo(nativeHandle1, true);
|
||||
|
||||
native_handle_t* const nativeHandle2 = native_handle_create(0, 0);
|
||||
hidl_handle h2;
|
||||
h2.setTo(nativeHandle2, true);
|
||||
|
||||
const Return<void> ret = config->setHandles(h1, h2, ASSERT_FALSE_CALLBACK);
|
||||
ASSERT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Passing a handle without an associated file descriptor should return an error
|
||||
// (e.g. "Failed Input Checks"). Check that this occurs when FD1 is empty.
|
||||
TEST_F(OffloadConfigHidlTest, TestSetHandle2OnlyNotOk) {
|
||||
native_handle_t* const nativeHandle1 = native_handle_create(0, 0);
|
||||
hidl_handle h1;
|
||||
h1.setTo(nativeHandle1, true);
|
||||
|
||||
unique_fd fd2(netlinkSocket(kFd2Groups));
|
||||
if (fd2.get() < 0) {
|
||||
ALOGE("Unable to create conntrack handles: %d/%s", errno, strerror(errno));
|
||||
FAIL();
|
||||
}
|
||||
native_handle_t* const nativeHandle2 = native_handle_create(1, 0);
|
||||
nativeHandle2->data[0] = fd2.release();
|
||||
hidl_handle h2;
|
||||
h2.setTo(nativeHandle2, true);
|
||||
|
||||
const Return<void> ret = config->setHandles(h1, h2, ASSERT_FALSE_CALLBACK);
|
||||
ASSERT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
int status = RUN_ALL_TESTS();
|
||||
ALOGE("Test result with status=%d", status);
|
||||
return status;
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
// This file is autogenerated by hidl-gen. Do not edit manually.
|
||||
|
||||
filegroup {
|
||||
name: "android.hardware.tetheroffload.control@1.0_hal",
|
||||
srcs: [
|
||||
"types.hal",
|
||||
"IOffloadControl.hal",
|
||||
"ITetheringOffloadCallback.hal",
|
||||
],
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "android.hardware.tetheroffload.control@1.0_genc++",
|
||||
tools: ["hidl-gen"],
|
||||
cmd: "$(location hidl-gen) -o $(genDir) -Lc++-sources -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.tetheroffload.control@1.0",
|
||||
srcs: [
|
||||
":android.hardware.tetheroffload.control@1.0_hal",
|
||||
],
|
||||
out: [
|
||||
"android/hardware/tetheroffload/control/1.0/types.cpp",
|
||||
"android/hardware/tetheroffload/control/1.0/OffloadControlAll.cpp",
|
||||
"android/hardware/tetheroffload/control/1.0/TetheringOffloadCallbackAll.cpp",
|
||||
],
|
||||
}
|
||||
|
||||
genrule {
|
||||
name: "android.hardware.tetheroffload.control@1.0_genc++_headers",
|
||||
tools: ["hidl-gen"],
|
||||
cmd: "$(location hidl-gen) -o $(genDir) -Lc++-headers -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.tetheroffload.control@1.0",
|
||||
srcs: [
|
||||
":android.hardware.tetheroffload.control@1.0_hal",
|
||||
],
|
||||
out: [
|
||||
"android/hardware/tetheroffload/control/1.0/types.h",
|
||||
"android/hardware/tetheroffload/control/1.0/hwtypes.h",
|
||||
"android/hardware/tetheroffload/control/1.0/IOffloadControl.h",
|
||||
"android/hardware/tetheroffload/control/1.0/IHwOffloadControl.h",
|
||||
"android/hardware/tetheroffload/control/1.0/BnHwOffloadControl.h",
|
||||
"android/hardware/tetheroffload/control/1.0/BpHwOffloadControl.h",
|
||||
"android/hardware/tetheroffload/control/1.0/BsOffloadControl.h",
|
||||
"android/hardware/tetheroffload/control/1.0/ITetheringOffloadCallback.h",
|
||||
"android/hardware/tetheroffload/control/1.0/IHwTetheringOffloadCallback.h",
|
||||
"android/hardware/tetheroffload/control/1.0/BnHwTetheringOffloadCallback.h",
|
||||
"android/hardware/tetheroffload/control/1.0/BpHwTetheringOffloadCallback.h",
|
||||
"android/hardware/tetheroffload/control/1.0/BsTetheringOffloadCallback.h",
|
||||
],
|
||||
}
|
||||
|
||||
cc_library {
|
||||
name: "android.hardware.tetheroffload.control@1.0",
|
||||
defaults: ["hidl-module-defaults"],
|
||||
generated_sources: ["android.hardware.tetheroffload.control@1.0_genc++"],
|
||||
generated_headers: ["android.hardware.tetheroffload.control@1.0_genc++_headers"],
|
||||
export_generated_headers: ["android.hardware.tetheroffload.control@1.0_genc++_headers"],
|
||||
vendor_available: true,
|
||||
vndk: {
|
||||
enabled: true,
|
||||
},
|
||||
shared_libs: [
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"libhwbinder",
|
||||
"liblog",
|
||||
"libutils",
|
||||
"libcutils",
|
||||
],
|
||||
export_shared_lib_headers: [
|
||||
"libhidlbase",
|
||||
"libhidltransport",
|
||||
"libhwbinder",
|
||||
"libutils",
|
||||
],
|
||||
}
|
274
android/hardware/interfaces/tetheroffload/control/1.0/Android.mk
Normal file
274
android/hardware/interfaces/tetheroffload/control/1.0/Android.mk
Normal file
|
@ -0,0 +1,274 @@
|
|||
# This file is autogenerated by hidl-gen. Do not edit manually.
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
################################################################################
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := android.hardware.tetheroffload.control-V1.0-java
|
||||
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
|
||||
|
||||
intermediates := $(call local-generated-sources-dir, COMMON)
|
||||
|
||||
HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := \
|
||||
android.hidl.base-V1.0-java \
|
||||
|
||||
|
||||
#
|
||||
# Build types.hal (IPv4AddrPortPair)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/tetheroffload/control/V1_0/IPv4AddrPortPair.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.tetheroffload.control@1.0::types.IPv4AddrPortPair
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build types.hal (NatTimeoutUpdate)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/tetheroffload/control/V1_0/NatTimeoutUpdate.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.tetheroffload.control@1.0::types.NatTimeoutUpdate
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build types.hal (NetworkProtocol)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/tetheroffload/control/V1_0/NetworkProtocol.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.tetheroffload.control@1.0::types.NetworkProtocol
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build types.hal (OffloadCallbackEvent)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/tetheroffload/control/V1_0/OffloadCallbackEvent.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.tetheroffload.control@1.0::types.OffloadCallbackEvent
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build IOffloadControl.hal
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/tetheroffload/control/V1_0/IOffloadControl.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IOffloadControl.hal
|
||||
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/ITetheringOffloadCallback.hal
|
||||
$(GEN): $(LOCAL_PATH)/ITetheringOffloadCallback.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.tetheroffload.control@1.0::IOffloadControl
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/IOffloadControl.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build ITetheringOffloadCallback.hal
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/tetheroffload/control/V1_0/ITetheringOffloadCallback.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/ITetheringOffloadCallback.hal
|
||||
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.tetheroffload.control@1.0::ITetheringOffloadCallback
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/ITetheringOffloadCallback.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
include $(BUILD_JAVA_LIBRARY)
|
||||
|
||||
|
||||
################################################################################
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := android.hardware.tetheroffload.control-V1.0-java-static
|
||||
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
|
||||
|
||||
intermediates := $(call local-generated-sources-dir, COMMON)
|
||||
|
||||
HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
|
||||
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := \
|
||||
android.hidl.base-V1.0-java-static \
|
||||
|
||||
|
||||
#
|
||||
# Build types.hal (IPv4AddrPortPair)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/tetheroffload/control/V1_0/IPv4AddrPortPair.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.tetheroffload.control@1.0::types.IPv4AddrPortPair
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build types.hal (NatTimeoutUpdate)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/tetheroffload/control/V1_0/NatTimeoutUpdate.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.tetheroffload.control@1.0::types.NatTimeoutUpdate
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build types.hal (NetworkProtocol)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/tetheroffload/control/V1_0/NetworkProtocol.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.tetheroffload.control@1.0::types.NetworkProtocol
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build types.hal (OffloadCallbackEvent)
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/tetheroffload/control/V1_0/OffloadCallbackEvent.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.tetheroffload.control@1.0::types.OffloadCallbackEvent
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build IOffloadControl.hal
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/tetheroffload/control/V1_0/IOffloadControl.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IOffloadControl.hal
|
||||
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/ITetheringOffloadCallback.hal
|
||||
$(GEN): $(LOCAL_PATH)/ITetheringOffloadCallback.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.tetheroffload.control@1.0::IOffloadControl
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/IOffloadControl.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
|
||||
#
|
||||
# Build ITetheringOffloadCallback.hal
|
||||
#
|
||||
GEN := $(intermediates)/android/hardware/tetheroffload/control/V1_0/ITetheringOffloadCallback.java
|
||||
$(GEN): $(HIDL)
|
||||
$(GEN): PRIVATE_HIDL := $(HIDL)
|
||||
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/ITetheringOffloadCallback.hal
|
||||
$(GEN): PRIVATE_DEPS += $(LOCAL_PATH)/types.hal
|
||||
$(GEN): $(LOCAL_PATH)/types.hal
|
||||
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
|
||||
$(GEN): PRIVATE_CUSTOM_TOOL = \
|
||||
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
|
||||
-Ljava \
|
||||
-randroid.hardware:hardware/interfaces \
|
||||
-randroid.hidl:system/libhidl/transport \
|
||||
android.hardware.tetheroffload.control@1.0::ITetheringOffloadCallback
|
||||
|
||||
$(GEN): $(LOCAL_PATH)/ITetheringOffloadCallback.hal
|
||||
$(transform-generated-source)
|
||||
LOCAL_GENERATED_SOURCES += $(GEN)
|
||||
include $(BUILD_STATIC_JAVA_LIBRARY)
|
||||
|
||||
|
||||
|
||||
include $(call all-makefiles-under,$(LOCAL_PATH))
|
|
@ -0,0 +1,221 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.hardware.tetheroffload.control@1.0;
|
||||
|
||||
import ITetheringOffloadCallback;
|
||||
|
||||
|
||||
/**
|
||||
* Interface used to control the lifecycle of tethering offload
|
||||
*/
|
||||
interface IOffloadControl {
|
||||
/**
|
||||
* Indicates intent to start offload for tethering in immediate future.
|
||||
*
|
||||
* This API must be called exactly once the first time that Tethering is requested by
|
||||
* the user.
|
||||
*
|
||||
* If this API is called multiple times without first calling stopOffload, then the subsequent
|
||||
* calls must fail without changing the state of the server.
|
||||
*
|
||||
* If for some reason, the hardware is currently unable to support offload, this call must fail.
|
||||
*
|
||||
* @param cb Assuming success, this callback must provide unsolicited updates of offload status.
|
||||
* It is assumed to be valid until stopOffload is called.
|
||||
*
|
||||
* @return success true if initialization is successful, false otherwise
|
||||
* @return errMsg a human readable string if eror has occured.
|
||||
*
|
||||
* Remarks: Initializing offload does not imply that any upstreams or downstreams have yet been,
|
||||
* or even will be, chosen. This API is symmetrical with stopOffload.
|
||||
*/
|
||||
@entry
|
||||
@callflow(next={"*"})
|
||||
initOffload(ITetheringOffloadCallback cb) generates (bool success, string errMsg);
|
||||
|
||||
/**
|
||||
* Indicate desire to tear down all tethering offload.
|
||||
*
|
||||
* Called after tethering is no longer requested by the user. Any remaining offload must
|
||||
* be subsequently torn down by the management process. Upon success, the callback registered
|
||||
* in initOffload must be released, and offload must be stopped.
|
||||
*
|
||||
* @return success true if offload is stopped, false otherwise
|
||||
* @return errMsg a human readable string if eror has occured.
|
||||
*
|
||||
* Remarks: Statistics must be reset by this API.
|
||||
*/
|
||||
@exit
|
||||
stopOffload() generates (bool success, string errMsg);
|
||||
|
||||
/**
|
||||
* Instruct management process not to forward traffic destined to or from the specified prefixes.
|
||||
*
|
||||
* This API may only be called after initOffload and before stopOffload.
|
||||
*
|
||||
* @param prefixes List containing fully specified prefixes. For e.g. 192.168.1.12/24
|
||||
or 2001:4860:0684:0:0:0:0:0:1002/64
|
||||
*
|
||||
* @return success true if success, false otherwise
|
||||
* @return errMsg a human readable string if eror has occured.
|
||||
*
|
||||
* Remarks: This list overrides any previously specified list
|
||||
*/
|
||||
setLocalPrefixes(vec<string> prefixes) generates (bool success, string errMsg);
|
||||
|
||||
/**
|
||||
* Query offloaded traffic statistics forwarded to an upstream address.
|
||||
*
|
||||
* Return statistics that have transpired since the last query. This would include
|
||||
* statistics from all offloaded downstream tether interfaces that have been forwarded to this
|
||||
* upstream interface. After returning the statistics, the counters are reset to zero.
|
||||
*
|
||||
* Only offloaded statistics must be returned by this API, software stats must not be
|
||||
* returned.
|
||||
*
|
||||
* @param upstream Upstream interface on which traffic exited/entered
|
||||
*
|
||||
* @return rxBytes values depicting the received bytes
|
||||
* @return txBytes values depicting the transmitted bytes
|
||||
*/
|
||||
getForwardedStats(string upstream) generates (uint64_t rxBytes, uint64_t txBytes);
|
||||
|
||||
/**
|
||||
* Instruct hardware to stop forwarding traffic and send a callback after limit bytes have been
|
||||
* transferred in either direction on this upstream interface.
|
||||
*
|
||||
* The limit must be applied to all traffic on the given upstream interface. This
|
||||
* includes hardware forwarded traffic, software forwarded traffic, and AP-originated traffic.
|
||||
* IPv4 and IPv6 traffic both count towards the same limit. IP headers are included in the
|
||||
* byte count limit, but, link-layer headers are not.
|
||||
*
|
||||
* This API may only be called while offload is occurring on this upstream. The hardware
|
||||
* management process is not expected to cache the value and apply the quota once offload is
|
||||
* started. This cache is not expected, because the limit value would likely become stale over
|
||||
* time and would not reflect any new traffic that has occurred.
|
||||
*
|
||||
* This limit must replace any previous limit. It may be interpreted as "tell me when
|
||||
* <limit> bytes have been transferred (in either direction) on <upstream>, starting
|
||||
* now and counting from zero."
|
||||
*
|
||||
* Once the limit is reached, the callback registered in initOffload must be called to indicate
|
||||
* this event and all offload must be stopped. If offload is desired again, the hardware
|
||||
* management process must be completely reprogrammed by calling setUpstreamParameters and
|
||||
* addDownstream again. Note that it is not necessary to call initOffload again to resume offload
|
||||
* if stopOffload was not called by the client.
|
||||
*
|
||||
* @param upstream Upstream interface name that limit must apply to
|
||||
* @param limit Bytes limit that can occur before action must be taken
|
||||
*
|
||||
* @return success true if limit is applied, false otherwise
|
||||
* @return errMsg a human readable string if eror has occured.
|
||||
*/
|
||||
setDataLimit(string upstream, uint64_t limit) generates (bool success, string errMsg);
|
||||
|
||||
/**
|
||||
* Instruct hardware to start forwarding traffic to the specified upstream.
|
||||
*
|
||||
* When iface, v4Addr, and v4Gw are all non-null, the management process may begin forwarding
|
||||
* any currently configured or future configured IPv4 downstreams to this upstream interface.
|
||||
*
|
||||
* If any of the previously three mentioned parameters are null, then any current IPv4 offload
|
||||
* must be stopped.
|
||||
*
|
||||
* When iface and v6Gws are both non-null, and in the case of v6Gws, are not empty, the
|
||||
* management process may begin forwarding any currently configured or future configured IPv6
|
||||
* downstreams to this upstream interface.
|
||||
*
|
||||
* If either of the two above parameters are null, or no V6 Gateways are provided, then IPv6
|
||||
* offload must be stopped.
|
||||
*
|
||||
* This API may only be called after initOffload and before stopOffload.
|
||||
*
|
||||
* @param iface Upstream interface name. Note that only one is needed because IPv4 and IPv6
|
||||
* interfaces cannot be different (only known that this can occur during software
|
||||
* xlat, which cannot be offloaded through hardware anyways). If the iface is
|
||||
* null, offload must be stopped.
|
||||
* @param v4Addr The local IPv4 address assigned to the provided upstream interface, i.e. the
|
||||
* IPv4 address the packets are NATed to. For e.g. 192.168.1.12.
|
||||
* @param v4Gw The IPv4 address of the IPv4 gateway on the upstream interface.
|
||||
* For e.g. 192.168.1.1
|
||||
* @param v6Gws A list of IPv6 addresses (for e.g. 2001:4860:0684:0:0:0:0:0:1002) for possible
|
||||
* IPv6 gateways on the upstream interface.
|
||||
*
|
||||
* @return success true if success, false otherwise
|
||||
* @return errMsg a human readable string if eror has occured.
|
||||
*
|
||||
* Remarks: This overrides any previously configured parameters.
|
||||
*/
|
||||
setUpstreamParameters(string iface, string v4Addr, string v4Gw, vec<string> v6Gws)
|
||||
generates (bool success, string errMsg);
|
||||
|
||||
/**
|
||||
* Configure a downstream interface and prefix in the hardware management process that may be
|
||||
* forwarded.
|
||||
*
|
||||
* The prefix may be an IPv4 or an IPv6 address to signify which family can be offloaded from the
|
||||
* specified tether interface. The list of IPv4 and IPv6 downstreams that are configured may
|
||||
* differ.
|
||||
*
|
||||
* If the given protocol, as determined by the prefix, has an upstream set,
|
||||
* the hardware may begin forwarding traffic between the upstream and any devices on the
|
||||
* downstream interface that have IP addresses within the specified prefix. Traffic from the same
|
||||
* downstream interfaces is unaffected and must be forwarded if and only if it was already
|
||||
* being forwarded.
|
||||
*
|
||||
* If no upstream is currently configured, then these downstream interface and prefixes must be
|
||||
* preserved so that offload may begin in the future when an upstream is set.
|
||||
*
|
||||
* This API does not replace any previously configured downstreams and must be explictly removed
|
||||
* by calling removeDownstream.
|
||||
*
|
||||
* This API may only be called after initOffload and before stopOffload.
|
||||
*
|
||||
* @param iface Tether interface
|
||||
* @param prefix Downstream prefix depicting addresses that may be offloaded.
|
||||
* For e.g. 192.168.1.12/24 or 2001:4860:0684::/64)
|
||||
*
|
||||
* @return success true if success, false otherwise
|
||||
* @return errMsg a human readable string if eror has occured.
|
||||
*
|
||||
* Remarks: The hardware management process may fail this call in a normal situation. This can
|
||||
* happen because the hardware cannot support the current number of prefixes, the
|
||||
* hardware cannot support concurrent offload on multiple interfaces, the hardware
|
||||
* cannot currently support offload on the tether interface for some reason, or any
|
||||
* other dynamic configuration issues which may occur. In this case,
|
||||
* traffic must remain unaffected and must be forwarded if and only if it was already
|
||||
* being forwarded.
|
||||
*/
|
||||
addDownstream(string iface, string prefix) generates (bool success, string errMsg);
|
||||
|
||||
/**
|
||||
* Remove a downstream prefix that may be forwarded from the hardware management process.
|
||||
*
|
||||
* The prefix may be an IPv4 or an IPv6 address. If it was not previously configured using
|
||||
* addDownstream, then this must be a no-op.
|
||||
*
|
||||
* This API may only be called after initOffload and before stopOffload.
|
||||
*
|
||||
* @param iface Tether interface
|
||||
* @param prefix Downstream prefix depicting address that must no longer be offloaded
|
||||
* For e.g. 192.168.1.12/24 or 2001:4860:0684::/64)
|
||||
*
|
||||
* @return success true if success, false otherwise
|
||||
* @return errMsg a human readable string if eror has occured.
|
||||
*/
|
||||
removeDownstream(string iface, string prefix) generates (bool success, string errMsg);
|
||||
};
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.hardware.tetheroffload.control@1.0;
|
||||
|
||||
/**
|
||||
* Callback providing information about status of hardware management process
|
||||
* as well as providing a way to keep offloaded connections from timing out.
|
||||
*/
|
||||
interface ITetheringOffloadCallback {
|
||||
/**
|
||||
* Called when an asynchronous event is generated by the hardware management
|
||||
* process.
|
||||
*/
|
||||
oneway onEvent(OffloadCallbackEvent event);
|
||||
|
||||
/**
|
||||
* Provide a way for the management process to request that a connections
|
||||
* timeout be updated in kernel.
|
||||
*
|
||||
* This is necessary to ensure that offloaded traffic is not cleaned up
|
||||
* by the kernel connection tracking module for IPv4.
|
||||
*/
|
||||
oneway updateTimeout(NatTimeoutUpdate params);
|
||||
};
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.hardware.tetheroffload.control@1.0;
|
||||
|
||||
enum OffloadCallbackEvent : uint32_t {
|
||||
/**
|
||||
* Indicate that a working configuration has been programmed and the
|
||||
* hardware management process has begun forwarding traffic.
|
||||
*/
|
||||
OFFLOAD_STARTED = 1,
|
||||
/**
|
||||
* Indicate that an error has occurred which has disrupted hardware
|
||||
* acceleration. Software routing may still be attempted; however,
|
||||
* statistics may be temporarily unavailable. Statistics may be recovered
|
||||
* after OFFLOAD_SUPPORT_AVAILABLE event is fired.
|
||||
*/
|
||||
OFFLOAD_STOPPED_ERROR = 2,
|
||||
/**
|
||||
* Indicate that the device has moved to a RAT on which hardware
|
||||
* acceleration is not supported. Subsequent calls to setUpstreamParameters
|
||||
* and add/removeDownstream will likely fail and cannot be presumed to be
|
||||
* saved inside of the hardware management process. Upon receiving
|
||||
* OFFLOAD_SUPPORT_AVAIALBLE, the client may reprogram the hardware
|
||||
* management process to begin offload again.
|
||||
*/
|
||||
OFFLOAD_STOPPED_UNSUPPORTED = 3,
|
||||
/**
|
||||
* Indicate that the hardware management process is willing and able to
|
||||
* provide support for hardware acceleration at this time. If applicable,
|
||||
* the client may query for statistics. If offload is desired, the client
|
||||
* must reprogram the hardware management process.
|
||||
*/
|
||||
OFFLOAD_SUPPORT_AVAILABLE = 4,
|
||||
/**
|
||||
* Hardware acceleration is no longer in effect and must be reprogrammed
|
||||
* in order to resume. This event is fired when the limit, applied in
|
||||
* setDataLimit, has expired. It is recommended that the client query for
|
||||
* statistics immediately after receiving this event.
|
||||
*/
|
||||
OFFLOAD_STOPPED_LIMIT_REACHED = 5
|
||||
};
|
||||
|
||||
enum NetworkProtocol : uint32_t {
|
||||
TCP = 6,
|
||||
UDP = 17
|
||||
};
|
||||
|
||||
struct IPv4AddrPortPair {
|
||||
/** IPv4 Address and Port */
|
||||
string addr; // for e.g. 192.168.1.12
|
||||
uint16_t port; // for e.g. 8080
|
||||
};
|
||||
|
||||
struct NatTimeoutUpdate {
|
||||
IPv4AddrPortPair src;
|
||||
IPv4AddrPortPair dst;
|
||||
NetworkProtocol proto;
|
||||
};
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2017 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
cc_test {
|
||||
name: "VtsHalTetheroffloadControlV1_0TargetTest",
|
||||
defaults: ["VtsHalTargetTestDefaults"],
|
||||
srcs: ["VtsHalTetheroffloadControlV1_0TargetTest.cpp"],
|
||||
static_libs: [
|
||||
"android.hardware.tetheroffload.config@1.0",
|
||||
"android.hardware.tetheroffload.control@1.0",
|
||||
],
|
||||
}
|
|
@ -0,0 +1,685 @@
|
|||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "VtsOffloadControlV1_0TargetTest"
|
||||
|
||||
#include <VtsHalHidlTargetCallbackBase.h>
|
||||
#include <VtsHalHidlTargetTestBase.h>
|
||||
#include <android-base/stringprintf.h>
|
||||
#include <android-base/unique_fd.h>
|
||||
#include <android/hardware/tetheroffload/config/1.0/IOffloadConfig.h>
|
||||
#include <android/hardware/tetheroffload/control/1.0/IOffloadControl.h>
|
||||
#include <android/hardware/tetheroffload/control/1.0/types.h>
|
||||
#include <linux/netfilter/nfnetlink.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <log/log.h>
|
||||
#include <net/if.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#include <set>
|
||||
|
||||
using android::base::StringPrintf;
|
||||
using android::base::unique_fd;
|
||||
using android::hardware::hidl_handle;
|
||||
using android::hardware::hidl_string;
|
||||
using android::hardware::hidl_vec;
|
||||
using android::hardware::Return;
|
||||
using android::hardware::tetheroffload::config::V1_0::IOffloadConfig;
|
||||
using android::hardware::tetheroffload::control::V1_0::IOffloadControl;
|
||||
using android::hardware::tetheroffload::control::V1_0::IPv4AddrPortPair;
|
||||
using android::hardware::tetheroffload::control::V1_0::ITetheringOffloadCallback;
|
||||
using android::hardware::tetheroffload::control::V1_0::OffloadCallbackEvent;
|
||||
using android::hardware::tetheroffload::control::V1_0::NatTimeoutUpdate;
|
||||
using android::hardware::tetheroffload::control::V1_0::NetworkProtocol;
|
||||
using android::hardware::Void;
|
||||
using android::sp;
|
||||
|
||||
enum class ExpectBoolean {
|
||||
Ignored = -1,
|
||||
False = 0,
|
||||
True = 1,
|
||||
};
|
||||
|
||||
constexpr const char* TEST_IFACE = "rmnet_data0";
|
||||
|
||||
// We use #defines here so as to get local lamba captures and error message line numbers
|
||||
#define ASSERT_TRUE_CALLBACK \
|
||||
[&](bool success, std::string errMsg) { \
|
||||
if (!success) { \
|
||||
ALOGI("Error message: %s", errMsg.c_str()); \
|
||||
} \
|
||||
ASSERT_TRUE(success); \
|
||||
}
|
||||
|
||||
#define ASSERT_FALSE_CALLBACK \
|
||||
[&](bool success, std::string errMsg) { \
|
||||
if (!success) { \
|
||||
ALOGI("Error message: %s", errMsg.c_str()); \
|
||||
} \
|
||||
ASSERT_FALSE(success); \
|
||||
}
|
||||
|
||||
#define ASSERT_ZERO_BYTES_CALLBACK \
|
||||
[&](uint64_t rxBytes, uint64_t txBytes) { \
|
||||
EXPECT_EQ(0ULL, rxBytes); \
|
||||
EXPECT_EQ(0ULL, txBytes); \
|
||||
}
|
||||
|
||||
inline const sockaddr* asSockaddr(const sockaddr_nl* nladdr) {
|
||||
return reinterpret_cast<const sockaddr*>(nladdr);
|
||||
}
|
||||
|
||||
int conntrackSocket(unsigned groups) {
|
||||
unique_fd s(socket(AF_NETLINK, SOCK_DGRAM, NETLINK_NETFILTER));
|
||||
if (s.get() < 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
const struct sockaddr_nl bind_addr = {
|
||||
.nl_family = AF_NETLINK, .nl_pad = 0, .nl_pid = 0, .nl_groups = groups,
|
||||
};
|
||||
if (::bind(s.get(), asSockaddr(&bind_addr), sizeof(bind_addr)) < 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
const struct sockaddr_nl kernel_addr = {
|
||||
.nl_family = AF_NETLINK, .nl_pad = 0, .nl_pid = 0, .nl_groups = groups,
|
||||
};
|
||||
if (connect(s.get(), asSockaddr(&kernel_addr), sizeof(kernel_addr)) != 0) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
return s.release();
|
||||
}
|
||||
|
||||
constexpr char kCallbackOnEvent[] = "onEvent";
|
||||
constexpr char kCallbackUpdateTimeout[] = "updateTimeout";
|
||||
|
||||
class TetheringOffloadCallbackArgs {
|
||||
public:
|
||||
OffloadCallbackEvent last_event;
|
||||
NatTimeoutUpdate last_params;
|
||||
};
|
||||
|
||||
class OffloadControlHidlTestBase : public testing::VtsHalHidlTargetTestBase {
|
||||
public:
|
||||
virtual void SetUp() override {
|
||||
setupConfigHal();
|
||||
prepareControlHal();
|
||||
}
|
||||
|
||||
virtual void TearDown() override {
|
||||
// For good measure, we should try stopOffload() once more. Since we
|
||||
// don't know where we are in HAL call test cycle we don't know what
|
||||
// return code to actually expect, so we just ignore it.
|
||||
stopOffload(ExpectBoolean::Ignored);
|
||||
}
|
||||
|
||||
// The IOffloadConfig HAL is tested more thoroughly elsewhere. He we just
|
||||
// setup everything correctly and verify basic readiness.
|
||||
void setupConfigHal() {
|
||||
config = testing::VtsHalHidlTargetTestBase::getService<IOffloadConfig>();
|
||||
ASSERT_NE(nullptr, config.get()) << "Could not get HIDL instance";
|
||||
|
||||
unique_fd fd1(conntrackSocket(NF_NETLINK_CONNTRACK_NEW | NF_NETLINK_CONNTRACK_DESTROY));
|
||||
if (fd1.get() < 0) {
|
||||
ALOGE("Unable to create conntrack handles: %d/%s", errno, strerror(errno));
|
||||
FAIL();
|
||||
}
|
||||
native_handle_t* const nativeHandle1 = native_handle_create(1, 0);
|
||||
nativeHandle1->data[0] = fd1.release();
|
||||
hidl_handle h1;
|
||||
h1.setTo(nativeHandle1, true);
|
||||
|
||||
unique_fd fd2(conntrackSocket(NF_NETLINK_CONNTRACK_UPDATE | NF_NETLINK_CONNTRACK_DESTROY));
|
||||
if (fd2.get() < 0) {
|
||||
ALOGE("Unable to create conntrack handles: %d/%s", errno, strerror(errno));
|
||||
FAIL();
|
||||
}
|
||||
native_handle_t* const nativeHandle2 = native_handle_create(1, 0);
|
||||
nativeHandle2->data[0] = fd2.release();
|
||||
hidl_handle h2;
|
||||
h2.setTo(nativeHandle2, true);
|
||||
|
||||
const Return<void> ret = config->setHandles(h1, h2, ASSERT_TRUE_CALLBACK);
|
||||
ASSERT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
void prepareControlHal() {
|
||||
control = testing::VtsHalHidlTargetTestBase::getService<IOffloadControl>();
|
||||
ASSERT_NE(nullptr, control.get()) << "Could not get HIDL instance";
|
||||
|
||||
control_cb = new TetheringOffloadCallback();
|
||||
ASSERT_NE(nullptr, control_cb.get()) << "Could not get get offload callback";
|
||||
}
|
||||
|
||||
void initOffload(const bool expected_result) {
|
||||
auto init_cb = [&](bool success, std::string errMsg) {
|
||||
if (!success) {
|
||||
ALOGI("Error message: %s", errMsg.c_str());
|
||||
}
|
||||
ASSERT_EQ(expected_result, success);
|
||||
};
|
||||
const Return<void> ret = control->initOffload(control_cb, init_cb);
|
||||
ASSERT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
void setupControlHal() {
|
||||
prepareControlHal();
|
||||
initOffload(true);
|
||||
}
|
||||
|
||||
void stopOffload(const ExpectBoolean value) {
|
||||
auto cb = [&](bool success, const hidl_string& errMsg) {
|
||||
if (!success) {
|
||||
ALOGI("Error message: %s", errMsg.c_str());
|
||||
}
|
||||
switch (value) {
|
||||
case ExpectBoolean::False:
|
||||
ASSERT_EQ(false, success);
|
||||
break;
|
||||
case ExpectBoolean::True:
|
||||
ASSERT_EQ(true, success);
|
||||
break;
|
||||
case ExpectBoolean::Ignored:
|
||||
break;
|
||||
}
|
||||
};
|
||||
const Return<void> ret = control->stopOffload(cb);
|
||||
ASSERT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Callback class for both events and NAT timeout updates.
|
||||
class TetheringOffloadCallback
|
||||
: public testing::VtsHalHidlTargetCallbackBase<TetheringOffloadCallbackArgs>,
|
||||
public ITetheringOffloadCallback {
|
||||
public:
|
||||
TetheringOffloadCallback() = default;
|
||||
virtual ~TetheringOffloadCallback() = default;
|
||||
|
||||
Return<void> onEvent(OffloadCallbackEvent event) override {
|
||||
const TetheringOffloadCallbackArgs args{.last_event = event};
|
||||
NotifyFromCallback(kCallbackOnEvent, args);
|
||||
return Void();
|
||||
};
|
||||
|
||||
Return<void> updateTimeout(const NatTimeoutUpdate& params) override {
|
||||
const TetheringOffloadCallbackArgs args{.last_params = params};
|
||||
NotifyFromCallback(kCallbackUpdateTimeout, args);
|
||||
return Void();
|
||||
};
|
||||
};
|
||||
|
||||
sp<IOffloadConfig> config;
|
||||
sp<IOffloadControl> control;
|
||||
sp<TetheringOffloadCallback> control_cb;
|
||||
};
|
||||
|
||||
// Call initOffload() multiple times. Check that non-first initOffload() calls return false.
|
||||
TEST_F(OffloadControlHidlTestBase, AdditionalInitsWithoutStopReturnFalse) {
|
||||
initOffload(true);
|
||||
initOffload(false);
|
||||
initOffload(false);
|
||||
initOffload(false);
|
||||
}
|
||||
|
||||
// Check that calling stopOffload() without first having called initOffload() returns false.
|
||||
TEST_F(OffloadControlHidlTestBase, MultipleStopsWithoutInitReturnFalse) {
|
||||
stopOffload(ExpectBoolean::False);
|
||||
stopOffload(ExpectBoolean::False);
|
||||
stopOffload(ExpectBoolean::False);
|
||||
}
|
||||
|
||||
// Check whether the specified interface is up.
|
||||
bool interfaceIsUp(const char* name) {
|
||||
if (name == nullptr) return false;
|
||||
struct ifreq ifr = {};
|
||||
strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
int sock = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
if (sock == -1) return false;
|
||||
int ret = ioctl(sock, SIOCGIFFLAGS, &ifr, sizeof(ifr));
|
||||
close(sock);
|
||||
return (ret == 0) && (ifr.ifr_flags & IFF_UP);
|
||||
}
|
||||
|
||||
// Check that calling stopOffload() after a complete init/stop cycle returns false.
|
||||
TEST_F(OffloadControlHidlTestBase, AdditionalStopsWithInitReturnFalse) {
|
||||
initOffload(true);
|
||||
// Call setUpstreamParameters() so that "offload" can be reasonably said
|
||||
// to be both requested and operational.
|
||||
const hidl_string v4Addr("192.0.0.2");
|
||||
const hidl_string v4Gw("192.0.0.1");
|
||||
const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")};
|
||||
const Return<void> upstream =
|
||||
control->setUpstreamParameters(TEST_IFACE, v4Addr, v4Gw, v6Gws, ASSERT_TRUE_CALLBACK);
|
||||
EXPECT_TRUE(upstream.isOk());
|
||||
if (!interfaceIsUp(TEST_IFACE)) {
|
||||
return;
|
||||
}
|
||||
stopOffload(ExpectBoolean::True); // balance out initOffload(true)
|
||||
stopOffload(ExpectBoolean::False);
|
||||
stopOffload(ExpectBoolean::False);
|
||||
}
|
||||
|
||||
// Check that calling setLocalPrefixes() without first having called initOffload() returns false.
|
||||
TEST_F(OffloadControlHidlTestBase, SetLocalPrefixesWithoutInitReturnsFalse) {
|
||||
const vector<hidl_string> prefixes{hidl_string("2001:db8::/64")};
|
||||
const Return<void> ret = control->setLocalPrefixes(prefixes, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Check that calling getForwardedStats() without first having called initOffload()
|
||||
// returns zero bytes statistics.
|
||||
TEST_F(OffloadControlHidlTestBase, GetForwardedStatsWithoutInitReturnsZeroValues) {
|
||||
const hidl_string upstream(TEST_IFACE);
|
||||
const Return<void> ret = control->getForwardedStats(upstream, ASSERT_ZERO_BYTES_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Check that calling setDataLimit() without first having called initOffload() returns false.
|
||||
TEST_F(OffloadControlHidlTestBase, SetDataLimitWithoutInitReturnsFalse) {
|
||||
const hidl_string upstream(TEST_IFACE);
|
||||
const uint64_t limit = 5000ULL;
|
||||
const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Check that calling setUpstreamParameters() without first having called initOffload()
|
||||
// returns false.
|
||||
TEST_F(OffloadControlHidlTestBase, SetUpstreamParametersWithoutInitReturnsFalse) {
|
||||
const hidl_string iface(TEST_IFACE);
|
||||
const hidl_string v4Addr("192.0.2.0/24");
|
||||
const hidl_string v4Gw("192.0.2.1");
|
||||
const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
|
||||
const Return<void> ret =
|
||||
control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Check that calling addDownstream() with an IPv4 prefix without first having called
|
||||
// initOffload() returns false.
|
||||
TEST_F(OffloadControlHidlTestBase, AddIPv4DownstreamWithoutInitReturnsFalse) {
|
||||
const hidl_string iface(TEST_IFACE);
|
||||
const hidl_string prefix("192.0.2.0/24");
|
||||
const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Check that calling addDownstream() with an IPv6 prefix without first having called
|
||||
// initOffload() returns false.
|
||||
TEST_F(OffloadControlHidlTestBase, AddIPv6DownstreamWithoutInitReturnsFalse) {
|
||||
const hidl_string iface(TEST_IFACE);
|
||||
const hidl_string prefix("2001:db8::/64");
|
||||
const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Check that calling removeDownstream() with an IPv4 prefix without first having called
|
||||
// initOffload() returns false.
|
||||
TEST_F(OffloadControlHidlTestBase, RemoveIPv4DownstreamWithoutInitReturnsFalse) {
|
||||
const hidl_string iface(TEST_IFACE);
|
||||
const hidl_string prefix("192.0.2.0/24");
|
||||
const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Check that calling removeDownstream() with an IPv6 prefix without first having called
|
||||
// initOffload() returns false.
|
||||
TEST_F(OffloadControlHidlTestBase, RemoveIPv6DownstreamWithoutInitReturnsFalse) {
|
||||
const hidl_string iface(TEST_IFACE);
|
||||
const hidl_string prefix("2001:db8::/64");
|
||||
const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
class OffloadControlHidlTest : public OffloadControlHidlTestBase {
|
||||
public:
|
||||
virtual void SetUp() override {
|
||||
setupConfigHal();
|
||||
setupControlHal();
|
||||
}
|
||||
|
||||
virtual void TearDown() override {
|
||||
// For good measure, we should try stopOffload() once more. Since we
|
||||
// don't know where we are in HAL call test cycle we don't know what
|
||||
// return code to actually expect, so we just ignore it.
|
||||
stopOffload(ExpectBoolean::Ignored);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Tests for IOffloadControl::setLocalPrefixes().
|
||||
*/
|
||||
|
||||
// Test setLocalPrefixes() accepts an IPv4 address.
|
||||
TEST_F(OffloadControlHidlTest, SetLocalPrefixesIPv4AddressOk) {
|
||||
const vector<hidl_string> prefixes{hidl_string("192.0.2.1")};
|
||||
const Return<void> ret = control->setLocalPrefixes(prefixes, ASSERT_TRUE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Test setLocalPrefixes() accepts an IPv6 address.
|
||||
TEST_F(OffloadControlHidlTest, SetLocalPrefixesIPv6AddressOk) {
|
||||
const vector<hidl_string> prefixes{hidl_string("fe80::1")};
|
||||
const Return<void> ret = control->setLocalPrefixes(prefixes, ASSERT_TRUE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Test setLocalPrefixes() accepts both IPv4 and IPv6 prefixes.
|
||||
TEST_F(OffloadControlHidlTest, SetLocalPrefixesIPv4v6PrefixesOk) {
|
||||
const vector<hidl_string> prefixes{hidl_string("192.0.2.0/24"), hidl_string("fe80::/64")};
|
||||
const Return<void> ret = control->setLocalPrefixes(prefixes, ASSERT_TRUE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Test that setLocalPrefixes() fails given empty input. There is always
|
||||
// a non-empty set of local prefixes; when all networking interfaces are down
|
||||
// we still apply {127.0.0.0/8, ::1/128, fe80::/64} here.
|
||||
TEST_F(OffloadControlHidlTest, SetLocalPrefixesEmptyFails) {
|
||||
const vector<hidl_string> prefixes{};
|
||||
const Return<void> ret = control->setLocalPrefixes(prefixes, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Test setLocalPrefixes() fails on incorrectly formed input strings.
|
||||
TEST_F(OffloadControlHidlTest, SetLocalPrefixesInvalidFails) {
|
||||
const vector<hidl_string> prefixes{hidl_string("192.0.2.0/24"), hidl_string("invalid")};
|
||||
const Return<void> ret = control->setLocalPrefixes(prefixes, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests for IOffloadControl::getForwardedStats().
|
||||
*/
|
||||
|
||||
// Test that getForwardedStats() for a non-existent upstream yields zero bytes statistics.
|
||||
TEST_F(OffloadControlHidlTest, GetForwardedStatsInvalidUpstreamIface) {
|
||||
const hidl_string upstream("invalid");
|
||||
const Return<void> ret = control->getForwardedStats(upstream, ASSERT_ZERO_BYTES_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// TEST_IFACE is presumed to exist on the device and be up. No packets
|
||||
// are ever actually caused to be forwarded.
|
||||
TEST_F(OffloadControlHidlTest, GetForwardedStatsDummyIface) {
|
||||
const hidl_string upstream(TEST_IFACE);
|
||||
const Return<void> ret = control->getForwardedStats(upstream, ASSERT_ZERO_BYTES_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests for IOffloadControl::setDataLimit().
|
||||
*/
|
||||
|
||||
// Test that setDataLimit() for an empty interface name fails.
|
||||
TEST_F(OffloadControlHidlTest, SetDataLimitEmptyUpstreamIfaceFails) {
|
||||
const hidl_string upstream("");
|
||||
const uint64_t limit = 5000ULL;
|
||||
const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// TEST_IFACE is presumed to exist on the device and be up. No packets
|
||||
// are ever actually caused to be forwarded.
|
||||
TEST_F(OffloadControlHidlTest, SetDataLimitNonZeroOk) {
|
||||
const hidl_string upstream(TEST_IFACE);
|
||||
const uint64_t limit = 5000ULL;
|
||||
const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_TRUE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// TEST_IFACE is presumed to exist on the device and be up. No packets
|
||||
// are ever actually caused to be forwarded.
|
||||
TEST_F(OffloadControlHidlTest, SetDataLimitZeroOk) {
|
||||
const hidl_string upstream(TEST_IFACE);
|
||||
const uint64_t limit = 0ULL;
|
||||
const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_TRUE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests for IOffloadControl::setUpstreamParameters().
|
||||
*/
|
||||
|
||||
// TEST_IFACE is presumed to exist on the device and be up. No packets
|
||||
// are ever actually caused to be forwarded.
|
||||
TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv6OnlyOk) {
|
||||
const hidl_string iface(TEST_IFACE);
|
||||
const hidl_string v4Addr("");
|
||||
const hidl_string v4Gw("");
|
||||
const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")};
|
||||
const Return<void> ret =
|
||||
control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_TRUE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// TEST_IFACE is presumed to exist on the device and be up. No packets
|
||||
// are ever actually caused to be forwarded.
|
||||
TEST_F(OffloadControlHidlTest, SetUpstreamParametersAlternateIPv6OnlyOk) {
|
||||
const hidl_string iface(TEST_IFACE);
|
||||
const hidl_string v4Addr;
|
||||
const hidl_string v4Gw;
|
||||
const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:3")};
|
||||
const Return<void> ret =
|
||||
control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_TRUE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// TEST_IFACE is presumed to exist on the device and be up. No packets
|
||||
// are ever actually caused to be forwarded.
|
||||
TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv4OnlyOk) {
|
||||
const hidl_string iface(TEST_IFACE);
|
||||
const hidl_string v4Addr("192.0.2.2");
|
||||
const hidl_string v4Gw("192.0.2.1");
|
||||
const vector<hidl_string> v6Gws{};
|
||||
const Return<void> ret =
|
||||
control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_TRUE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// TEST_IFACE is presumed to exist on the device and be up. No packets
|
||||
// are ever actually caused to be forwarded.
|
||||
TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv4v6Ok) {
|
||||
const hidl_string iface(TEST_IFACE);
|
||||
const hidl_string v4Addr("192.0.2.2");
|
||||
const hidl_string v4Gw("192.0.2.1");
|
||||
const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")};
|
||||
const Return<void> ret =
|
||||
control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_TRUE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Test that setUpstreamParameters() fails when all parameters are empty.
|
||||
TEST_F(OffloadControlHidlTest, SetUpstreamParametersEmptyFails) {
|
||||
const hidl_string iface("");
|
||||
const hidl_string v4Addr("");
|
||||
const hidl_string v4Gw("");
|
||||
const vector<hidl_string> v6Gws{};
|
||||
const Return<void> ret =
|
||||
control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Test that setUpstreamParameters() fails when given empty or non-existent interface names.
|
||||
TEST_F(OffloadControlHidlTest, SetUpstreamParametersBogusIfaceFails) {
|
||||
const hidl_string v4Addr("192.0.2.2");
|
||||
const hidl_string v4Gw("192.0.2.1");
|
||||
const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
|
||||
for (const auto& bogus : {"", "invalid"}) {
|
||||
SCOPED_TRACE(StringPrintf("iface='%s'", bogus));
|
||||
const hidl_string iface(bogus);
|
||||
const Return<void> ret =
|
||||
control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
}
|
||||
|
||||
// Test that setUpstreamParameters() fails when given unparseable IPv4 addresses.
|
||||
TEST_F(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4AddrFails) {
|
||||
const hidl_string iface(TEST_IFACE);
|
||||
const hidl_string v4Gw("192.0.2.1");
|
||||
const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
|
||||
for (const auto& bogus : {"invalid", "192.0.2"}) {
|
||||
SCOPED_TRACE(StringPrintf("v4addr='%s'", bogus));
|
||||
const hidl_string v4Addr(bogus);
|
||||
const Return<void> ret =
|
||||
control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
}
|
||||
|
||||
// Test that setUpstreamParameters() fails when given unparseable IPv4 gateways.
|
||||
TEST_F(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4GatewayFails) {
|
||||
const hidl_string iface(TEST_IFACE);
|
||||
const hidl_string v4Addr("192.0.2.2");
|
||||
const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
|
||||
for (const auto& bogus : {"invalid", "192.0.2"}) {
|
||||
SCOPED_TRACE(StringPrintf("v4gateway='%s'", bogus));
|
||||
const hidl_string v4Gw(bogus);
|
||||
const Return<void> ret =
|
||||
control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
}
|
||||
|
||||
// Test that setUpstreamParameters() fails when given unparseable IPv6 gateways.
|
||||
TEST_F(OffloadControlHidlTest, SetUpstreamParametersBadIPv6GatewaysFail) {
|
||||
const hidl_string iface(TEST_IFACE);
|
||||
const hidl_string v4Addr("192.0.2.2");
|
||||
const hidl_string v4Gw("192.0.2.1");
|
||||
for (const auto& bogus : {"", "invalid", "fe80::bogus", "192.0.2.66"}) {
|
||||
SCOPED_TRACE(StringPrintf("v6gateway='%s'", bogus));
|
||||
const vector<hidl_string> v6Gws{hidl_string("fe80::1"), hidl_string(bogus)};
|
||||
const Return<void> ret =
|
||||
control->setUpstreamParameters(iface, v4Addr, v4Gw, v6Gws, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests for IOffloadControl::addDownstream().
|
||||
*/
|
||||
|
||||
// Test addDownstream() works given an IPv4 prefix.
|
||||
TEST_F(OffloadControlHidlTest, AddDownstreamIPv4) {
|
||||
const hidl_string iface("dummy0");
|
||||
const hidl_string prefix("192.0.2.0/24");
|
||||
const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_TRUE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Test addDownstream() works given an IPv6 prefix.
|
||||
TEST_F(OffloadControlHidlTest, AddDownstreamIPv6) {
|
||||
const hidl_string iface("dummy0");
|
||||
const hidl_string prefix("2001:db8::/64");
|
||||
const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_TRUE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Test addDownstream() fails given all empty parameters.
|
||||
TEST_F(OffloadControlHidlTest, AddDownstreamEmptyFails) {
|
||||
const hidl_string iface("");
|
||||
const hidl_string prefix("");
|
||||
const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Test addDownstream() fails given empty or non-existent interface names.
|
||||
TEST_F(OffloadControlHidlTest, AddDownstreamInvalidIfaceFails) {
|
||||
const hidl_string prefix("192.0.2.0/24");
|
||||
for (const auto& bogus : {"", "invalid"}) {
|
||||
SCOPED_TRACE(StringPrintf("iface='%s'", bogus));
|
||||
const hidl_string iface(bogus);
|
||||
const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
}
|
||||
|
||||
// Test addDownstream() fails given unparseable prefix arguments.
|
||||
TEST_F(OffloadControlHidlTest, AddDownstreamBogusPrefixFails) {
|
||||
const hidl_string iface("dummy0");
|
||||
for (const auto& bogus : {"", "192.0.2/24", "2001:db8/64"}) {
|
||||
SCOPED_TRACE(StringPrintf("prefix='%s'", bogus));
|
||||
const hidl_string prefix(bogus);
|
||||
const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests for IOffloadControl::removeDownstream().
|
||||
*/
|
||||
|
||||
// Test removeDownstream() works given an IPv4 prefix.
|
||||
TEST_F(OffloadControlHidlTest, RemoveDownstreamIPv4) {
|
||||
const hidl_string iface("dummy0");
|
||||
const hidl_string prefix("192.0.2.0/24");
|
||||
// First add the downstream, otherwise removeDownstream logic can reasonably
|
||||
// return false for downstreams not previously added.
|
||||
const Return<void> add = control->addDownstream(iface, prefix, ASSERT_TRUE_CALLBACK);
|
||||
EXPECT_TRUE(add.isOk());
|
||||
const Return<void> del = control->removeDownstream(iface, prefix, ASSERT_TRUE_CALLBACK);
|
||||
EXPECT_TRUE(del.isOk());
|
||||
}
|
||||
|
||||
// Test removeDownstream() works given an IPv6 prefix.
|
||||
TEST_F(OffloadControlHidlTest, RemoveDownstreamIPv6) {
|
||||
const hidl_string iface("dummy0");
|
||||
const hidl_string prefix("2001:db8::/64");
|
||||
// First add the downstream, otherwise removeDownstream logic can reasonably
|
||||
// return false for downstreams not previously added.
|
||||
const Return<void> add = control->addDownstream(iface, prefix, ASSERT_TRUE_CALLBACK);
|
||||
EXPECT_TRUE(add.isOk());
|
||||
const Return<void> del = control->removeDownstream(iface, prefix, ASSERT_TRUE_CALLBACK);
|
||||
EXPECT_TRUE(del.isOk());
|
||||
}
|
||||
|
||||
// Test removeDownstream() fails given all empty parameters.
|
||||
TEST_F(OffloadControlHidlTest, RemoveDownstreamEmptyFails) {
|
||||
const hidl_string iface("");
|
||||
const hidl_string prefix("");
|
||||
const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
// Test removeDownstream() fails given empty or non-existent interface names.
|
||||
TEST_F(OffloadControlHidlTest, RemoveDownstreamBogusIfaceFails) {
|
||||
const hidl_string prefix("192.0.2.0/24");
|
||||
for (const auto& bogus : {"", "invalid"}) {
|
||||
SCOPED_TRACE(StringPrintf("iface='%s'", bogus));
|
||||
const hidl_string iface(bogus);
|
||||
const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
}
|
||||
|
||||
// Test removeDownstream() fails given unparseable prefix arguments.
|
||||
TEST_F(OffloadControlHidlTest, RemoveDownstreamBogusPrefixFails) {
|
||||
const hidl_string iface("dummy0");
|
||||
for (const auto& bogus : {"", "192.0.2/24", "2001:db8/64"}) {
|
||||
SCOPED_TRACE(StringPrintf("prefix='%s'", bogus));
|
||||
const hidl_string prefix(bogus);
|
||||
const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
int status = RUN_ALL_TESTS();
|
||||
ALOGE("Test result with status=%d", status);
|
||||
return status;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue