Commit ae4ddebe authored by Cristian Lumezanu's avatar Cristian Lumezanu Committed by Facebook GitHub Bot

Update TcpInfo namespaces

Summary: We update the TcpInfo namespace to `folly` (previosuly `folly::tcpinfo`) to avoid introducing unnecessary namespaces and to make it slightly easier to refer to. We also move the structs in the `TcpInfoTypes.h` file to the `folly::detail` namespace and move `LookupOptions` to the `TcpInfo` class, following comments in D22134355 (https://github.com/facebook/folly/commit/68a78d99d10743b54d38a550b2f0ebdc5c872f76).

Reviewed By: bschlinker

Differential Revision: D30159429

fbshipit-source-id: 7260fc80c2e76b3439c539b65cc188b2e5517b24
parent 416d85c5
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#endif #endif
namespace folly { namespace folly {
namespace tcpinfo {
namespace { namespace {
constexpr std::array< constexpr std::array<
...@@ -52,7 +51,6 @@ static_assert( ...@@ -52,7 +51,6 @@ static_assert(
using ms = std::chrono::milliseconds; using ms = std::chrono::milliseconds;
using us = std::chrono::microseconds; using us = std::chrono::microseconds;
using namespace tcpinfo;
TcpInfo::IoctlDispatcher* TcpInfo::IoctlDispatcher::getDefaultInstance() { TcpInfo::IoctlDispatcher* TcpInfo::IoctlDispatcher::getDefaultInstance() {
static TcpInfo::IoctlDispatcher dispatcher = {}; static TcpInfo::IoctlDispatcher dispatcher = {};
...@@ -69,7 +67,7 @@ int TcpInfo::IoctlDispatcher::ioctl(int fd, unsigned long request, void* argp) { ...@@ -69,7 +67,7 @@ int TcpInfo::IoctlDispatcher::ioctl(int fd, unsigned long request, void* argp) {
Expected<TcpInfo, std::errc> TcpInfo::initFromFd( Expected<TcpInfo, std::errc> TcpInfo::initFromFd(
const NetworkSocket& fd, const NetworkSocket& fd,
const LookupOptions& options, const TcpInfo::LookupOptions& options,
netops::Dispatcher& netopsDispatcher, netops::Dispatcher& netopsDispatcher,
IoctlDispatcher& ioctlDispatcher) { IoctlDispatcher& ioctlDispatcher) {
#ifndef FOLLY_HAVE_TCP_INFO #ifndef FOLLY_HAVE_TCP_INFO
...@@ -85,7 +83,7 @@ Expected<TcpInfo, std::errc> TcpInfo::initFromFd( ...@@ -85,7 +83,7 @@ Expected<TcpInfo, std::errc> TcpInfo::initFromFd(
auto ret = netopsDispatcher.getsockopt( auto ret = netopsDispatcher.getsockopt(
fd, fd,
IPPROTO_TCP, IPPROTO_TCP,
folly::tcpinfo::tcp_info_sock_opt, folly::detail::tcp_info_sock_opt,
(void*)&info.tcpInfo, (void*)&info.tcpInfo,
&len); &len);
if (ret < 0) { if (ret < 0) {
...@@ -411,8 +409,10 @@ Optional<uint64_t> TcpInfo::bbrBwBytesPerSecond() const { ...@@ -411,8 +409,10 @@ Optional<uint64_t> TcpInfo::bbrBwBytesPerSecond() const {
#ifndef FOLLY_HAVE_TCP_CC_INFO #ifndef FOLLY_HAVE_TCP_CC_INFO
return folly::none; return folly::none;
#elif defined(__linux__) #elif defined(__linux__)
auto bbrBwLoOpt = getFieldAsOptUInt64(&tcp_bbr_info::bbr_bw_lo); auto bbrBwLoOpt =
auto bbrBwHiOpt = getFieldAsOptUInt64(&tcp_bbr_info::bbr_bw_hi); getFieldAsOptUInt64(&folly::TcpInfo::tcp_bbr_info::bbr_bw_lo);
auto bbrBwHiOpt =
getFieldAsOptUInt64(&folly::TcpInfo::tcp_bbr_info::bbr_bw_hi);
if (bbrBwLoOpt && bbrBwHiOpt) { if (bbrBwLoOpt && bbrBwHiOpt) {
return ((int64_t)*bbrBwHiOpt << 32) + *bbrBwLoOpt; return ((int64_t)*bbrBwHiOpt << 32) + *bbrBwLoOpt;
} }
...@@ -428,7 +428,7 @@ Optional<std::chrono::microseconds> TcpInfo::bbrMinrtt() const { ...@@ -428,7 +428,7 @@ Optional<std::chrono::microseconds> TcpInfo::bbrMinrtt() const {
#ifndef FOLLY_HAVE_TCP_CC_INFO #ifndef FOLLY_HAVE_TCP_CC_INFO
return folly::none; return folly::none;
#elif defined(__linux__) #elif defined(__linux__)
auto opt = getFieldAsOptUInt64(&tcp_bbr_info::bbr_min_rtt); auto opt = getFieldAsOptUInt64(&folly::TcpInfo::tcp_bbr_info::bbr_min_rtt);
return (opt) ? us(*opt) : folly::Optional<us>(); return (opt) ? us(*opt) : folly::Optional<us>();
#elif defined(__APPLE__) #elif defined(__APPLE__)
return folly::none; return folly::none;
...@@ -441,7 +441,7 @@ Optional<uint64_t> TcpInfo::bbrPacingGain() const { ...@@ -441,7 +441,7 @@ Optional<uint64_t> TcpInfo::bbrPacingGain() const {
#ifndef FOLLY_HAVE_TCP_CC_INFO #ifndef FOLLY_HAVE_TCP_CC_INFO
return folly::none; return folly::none;
#elif defined(__linux__) #elif defined(__linux__)
return getFieldAsOptUInt64(&tcp_bbr_info::bbr_pacing_gain); return getFieldAsOptUInt64(&folly::TcpInfo::tcp_bbr_info::bbr_pacing_gain);
#elif defined(__APPLE__) #elif defined(__APPLE__)
return folly::none; return folly::none;
#else #else
...@@ -453,7 +453,7 @@ Optional<uint64_t> TcpInfo::bbrCwndGain() const { ...@@ -453,7 +453,7 @@ Optional<uint64_t> TcpInfo::bbrCwndGain() const {
#ifndef FOLLY_HAVE_TCP_CC_INFO #ifndef FOLLY_HAVE_TCP_CC_INFO
return folly::none; return folly::none;
#elif defined(__linux__) #elif defined(__linux__)
return getFieldAsOptUInt64(&tcp_bbr_info::bbr_cwnd_gain); return getFieldAsOptUInt64(&folly::TcpInfo::tcp_bbr_info::bbr_cwnd_gain);
#elif defined(__APPLE__) #elif defined(__APPLE__)
return folly::none; return folly::none;
#else #else
...@@ -539,8 +539,8 @@ void TcpInfo::initCcInfoFromFd( ...@@ -539,8 +539,8 @@ void TcpInfo::initCcInfoFromFd(
LOG(FATAL) << "CongestionControlName::NumCcTypes is not a valid CC type"; LOG(FATAL) << "CongestionControlName::NumCcTypes is not a valid CC type";
} }
tcpinfo::tcp_cc_info ccInfo = {}; tcp_cc_info ccInfo = {};
socklen_t len = sizeof(tcpinfo::tcp_cc_info); socklen_t len = sizeof(tcp_cc_info);
const int ret = netopsDispatcher.getsockopt( const int ret = netopsDispatcher.getsockopt(
fd, IPPROTO_TCP, TCP_CC_INFO, (void*)&ccInfo, &len); fd, IPPROTO_TCP, TCP_CC_INFO, (void*)&ccInfo, &len);
if (ret < 0) { if (ret < 0) {
...@@ -574,5 +574,4 @@ void TcpInfo::initMemInfoFromFd( ...@@ -574,5 +574,4 @@ void TcpInfo::initMemInfoFromFd(
#endif #endif
} }
} // namespace tcpinfo
} // namespace folly } // namespace folly
...@@ -27,19 +27,6 @@ ...@@ -27,19 +27,6 @@
#include <folly/net/TcpInfoTypes.h> #include <folly/net/TcpInfoTypes.h>
namespace folly { namespace folly {
namespace tcpinfo {
/**
* Structure specifying options for TcpInfo::initFromFd.
*/
struct LookupOptions {
// On supported platforms, whether to fetch the name of the congestion
// control algorithm and any information exposed via TCP_CC_INFO.
bool getCcInfo{false};
// On supported platforms, whether to fetch socket buffer utilization.
bool getMemInfo{false};
};
/** /**
* Abstraction layer for capturing current TCP and congestion control state. * Abstraction layer for capturing current TCP and congestion control state.
...@@ -112,6 +99,20 @@ struct TcpInfo { ...@@ -112,6 +99,20 @@ struct TcpInfo {
NumCcTypes, NumCcTypes,
}; };
/**
* Structure specifying options for TcpInfo::initFromFd.
*/
struct LookupOptions {
// On supported platforms, whether to fetch the name of the congestion
// control algorithm and any information exposed via TCP_CC_INFO.
bool getCcInfo{false};
// On supported platforms, whether to fetch socket buffer utilization.
bool getMemInfo{false};
LookupOptions() {}
};
/** /**
* Dispatcher that enables calls to ioctl to be intercepted for tests. * Dispatcher that enables calls to ioctl to be intercepted for tests.
* *
...@@ -139,7 +140,7 @@ struct TcpInfo { ...@@ -139,7 +140,7 @@ struct TcpInfo {
*/ */
static Expected<TcpInfo, std::errc> initFromFd( static Expected<TcpInfo, std::errc> initFromFd(
const NetworkSocket& fd, const NetworkSocket& fd,
const LookupOptions& options = LookupOptions(), const TcpInfo::LookupOptions& options = TcpInfo::LookupOptions(),
netops::Dispatcher& netopsDispatcher = netops::Dispatcher& netopsDispatcher =
*netops::Dispatcher::getDefaultInstance(), *netops::Dispatcher::getDefaultInstance(),
IoctlDispatcher& ioctlDispatcher = IoctlDispatcher& ioctlDispatcher =
...@@ -268,7 +269,7 @@ struct TcpInfo { ...@@ -268,7 +269,7 @@ struct TcpInfo {
#if defined(FOLLY_HAVE_TCP_INFO) #if defined(FOLLY_HAVE_TCP_INFO)
public: public:
using tcp_info = folly::tcpinfo::tcp_info; using tcp_info = folly::detail::tcp_info;
/** /**
* Returns pointer containing requested field from tcp_info struct. * Returns pointer containing requested field from tcp_info struct.
...@@ -311,7 +312,10 @@ struct TcpInfo { ...@@ -311,7 +312,10 @@ struct TcpInfo {
#if defined(FOLLY_HAVE_TCP_CC_INFO) #if defined(FOLLY_HAVE_TCP_CC_INFO)
public: public:
using tcp_cc_info = folly::tcpinfo::tcp_cc_info; using tcp_cc_info = folly::detail::tcp_cc_info;
using tcp_bbr_info = folly::detail::tcp_bbr_info;
using tcpvegas_info = folly::detail::tcpvegas_info;
using tcp_dctcp_info = folly::detail::tcp_dctcp_info;
// TCP_CA_NAME_MAX from <net/tcp.h> (Linux) or <netinet/tcp.h> (FreeBSD) // TCP_CA_NAME_MAX from <net/tcp.h> (Linux) or <netinet/tcp.h> (FreeBSD)
static constexpr socklen_t kLinuxTcpCaNameMax = 16; static constexpr socklen_t kLinuxTcpCaNameMax = 16;
...@@ -326,8 +330,7 @@ struct TcpInfo { ...@@ -326,8 +330,7 @@ struct TcpInfo {
* specifics, use accessors such as bbrBwBitsPerSecond(). * specifics, use accessors such as bbrBwBitsPerSecond().
*/ */
template <typename T1> template <typename T1>
folly::Optional<uint64_t> getFieldAsOptUInt64( folly::Optional<uint64_t> getFieldAsOptUInt64(T1 tcp_bbr_info::*field) const {
T1 tcpinfo::tcp_bbr_info::*field) const {
if (maybeCcInfo.has_value() && ccNameEnum() == CongestionControlName::BBR) { if (maybeCcInfo.has_value() && ccNameEnum() == CongestionControlName::BBR) {
return getFieldAsOptUInt64(maybeCcInfo.value().bbr, field); return getFieldAsOptUInt64(maybeCcInfo.value().bbr, field);
} }
...@@ -342,7 +345,7 @@ struct TcpInfo { ...@@ -342,7 +345,7 @@ struct TcpInfo {
*/ */
template <typename T1> template <typename T1>
folly::Optional<uint64_t> getFieldAsOptUInt64( folly::Optional<uint64_t> getFieldAsOptUInt64(
T1 tcpinfo::tcpvegas_info::*field) const { T1 tcpvegas_info::*field) const {
if (maybeCcInfo.hasValue() && if (maybeCcInfo.hasValue() &&
ccNameEnum() == CongestionControlName::VEGAS) { ccNameEnum() == CongestionControlName::VEGAS) {
return getFieldAsOptUInt64(maybeCcInfo.value().vegas, field); return getFieldAsOptUInt64(maybeCcInfo.value().vegas, field);
...@@ -358,7 +361,7 @@ struct TcpInfo { ...@@ -358,7 +361,7 @@ struct TcpInfo {
*/ */
template <typename T1> template <typename T1>
const folly::Optional<uint64_t> getFieldAsOptUInt64( const folly::Optional<uint64_t> getFieldAsOptUInt64(
T1 tcpinfo::tcp_dctcp_info::*field) const { T1 tcp_dctcp_info::*field) const {
if (maybeCcInfo.has_value() && if (maybeCcInfo.has_value() &&
(ccNameEnum() == CongestionControlName::DCTCP || (ccNameEnum() == CongestionControlName::DCTCP ||
ccNameEnum() == CongestionControlName::DCTCP_CUBIC || ccNameEnum() == CongestionControlName::DCTCP_CUBIC ||
...@@ -410,5 +413,4 @@ struct TcpInfo { ...@@ -410,5 +413,4 @@ struct TcpInfo {
folly::Optional<size_t> maybeRecvBufInUseBytes; folly::Optional<size_t> maybeRecvBufInUseBytes;
}; };
} // namespace tcpinfo
} // namespace folly } // namespace folly
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#endif #endif
namespace folly { namespace folly {
namespace tcpinfo { namespace detail {
/** /**
* *
...@@ -222,5 +222,5 @@ union tcp_cc_info { ...@@ -222,5 +222,5 @@ union tcp_cc_info {
}; };
#endif #endif
} // namespace tcpinfo } // namespace detail
} // namespace folly } // namespace folly
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
using namespace folly; using namespace folly;
using namespace testing; using namespace testing;
using namespace folly::tcpinfo; using namespace folly::test;
using namespace folly::tcpinfo::test;
using us = std::chrono::microseconds; using us = std::chrono::microseconds;
...@@ -49,7 +48,7 @@ class TcpInfoTest : public Test { ...@@ -49,7 +48,7 @@ class TcpInfoTest : public Test {
} }
void setupExpectCallCcInfo( void setupExpectCallCcInfo(
NetworkSocket& s, const folly::tcpinfo::tcp_cc_info& ccInfo) { NetworkSocket& s, const folly::TcpInfo::tcp_cc_info& ccInfo) {
TcpInfoTestUtil::setupExpectCallCcInfo(mockNetOpsDispatcher_, s, ccInfo); TcpInfoTestUtil::setupExpectCallCcInfo(mockNetOpsDispatcher_, s, ccInfo);
} }
...@@ -74,8 +73,8 @@ class TcpInfoTest : public Test { ...@@ -74,8 +73,8 @@ class TcpInfoTest : public Test {
}))); })));
} }
static folly::tcpinfo::tcp_info getTestLatestTcpInfo() { static folly::TcpInfo::tcp_info getTestLatestTcpInfo() {
folly::tcpinfo::tcp_info tInfo = {}; folly::TcpInfo::tcp_info tInfo = {};
tInfo.tcpi_state = 1; tInfo.tcpi_state = 1;
tInfo.tcpi_ca_state = 2; tInfo.tcpi_ca_state = 2;
tInfo.tcpi_retransmits = 3; tInfo.tcpi_retransmits = 3;
...@@ -134,8 +133,8 @@ class TcpInfoTest : public Test { ...@@ -134,8 +133,8 @@ class TcpInfoTest : public Test {
return tInfo; return tInfo;
} }
static folly::tcpinfo::tcp_info_legacy getTestLegacyTcpInfo() { static folly::detail::tcp_info_legacy getTestLegacyTcpInfo() {
folly::tcpinfo::tcp_info_legacy tInfo = {}; folly::detail::tcp_info_legacy tInfo = {};
tInfo.tcpi_state = 1; tInfo.tcpi_state = 1;
tInfo.tcpi_ca_state = 2; tInfo.tcpi_ca_state = 2;
tInfo.tcpi_retransmits = 3; tInfo.tcpi_retransmits = 3;
...@@ -171,8 +170,8 @@ class TcpInfoTest : public Test { ...@@ -171,8 +170,8 @@ class TcpInfoTest : public Test {
return tInfo; return tInfo;
} }
static folly::tcpinfo::tcp_cc_info getTestBbrInfo() { static folly::TcpInfo::tcp_cc_info getTestBbrInfo() {
folly::tcpinfo::tcp_cc_info ccInfo = {}; folly::TcpInfo::tcp_cc_info ccInfo = {};
ccInfo.bbr.bbr_bw_lo = 1; ccInfo.bbr.bbr_bw_lo = 1;
ccInfo.bbr.bbr_bw_hi = 2; ccInfo.bbr.bbr_bw_hi = 2;
ccInfo.bbr.bbr_min_rtt = 3; ccInfo.bbr.bbr_min_rtt = 3;
...@@ -181,8 +180,8 @@ class TcpInfoTest : public Test { ...@@ -181,8 +180,8 @@ class TcpInfoTest : public Test {
return ccInfo; return ccInfo;
} }
static folly::tcpinfo::tcp_cc_info getTestVegasInfo() { static folly::TcpInfo::tcp_cc_info getTestVegasInfo() {
folly::tcpinfo::tcp_cc_info ccInfo = {}; folly::TcpInfo::tcp_cc_info ccInfo = {};
ccInfo.vegas.tcpv_enabled = 6; ccInfo.vegas.tcpv_enabled = 6;
ccInfo.vegas.tcpv_rttcnt = 7; ccInfo.vegas.tcpv_rttcnt = 7;
ccInfo.vegas.tcpv_rtt = 8; ccInfo.vegas.tcpv_rtt = 8;
...@@ -190,8 +189,8 @@ class TcpInfoTest : public Test { ...@@ -190,8 +189,8 @@ class TcpInfoTest : public Test {
return ccInfo; return ccInfo;
} }
static folly::tcpinfo::tcp_cc_info getTestDctcpInfo() { static folly::TcpInfo::tcp_cc_info getTestDctcpInfo() {
folly::tcpinfo::tcp_cc_info ccInfo = {}; folly::TcpInfo::tcp_cc_info ccInfo = {};
ccInfo.dctcp.dctcp_enabled = 10; ccInfo.dctcp.dctcp_enabled = 10;
ccInfo.dctcp.dctcp_ce_state = 11; ccInfo.dctcp.dctcp_ce_state = 11;
ccInfo.dctcp.dctcp_alpha = 12; ccInfo.dctcp.dctcp_alpha = 12;
...@@ -209,11 +208,11 @@ class TcpInfoTest : public Test { ...@@ -209,11 +208,11 @@ class TcpInfoTest : public Test {
EXPECT_FALSE(wrappedTcpInfo.cwndInPackets().has_value()); EXPECT_FALSE(wrappedTcpInfo.cwndInPackets().has_value());
EXPECT_FALSE( EXPECT_FALSE(
wrappedTcpInfo wrappedTcpInfo
.getFieldAsOptUInt64(&folly::tcpinfo::tcp_info::tcpi_total_retrans) .getFieldAsOptUInt64(&folly::TcpInfo::tcp_info::tcpi_total_retrans)
.has_value()); .has_value());
EXPECT_FALSE( EXPECT_FALSE(
wrappedTcpInfo wrappedTcpInfo
.getFieldAsOptUInt64(&folly::tcpinfo::tcp_info::tcpi_snd_cwnd) .getFieldAsOptUInt64(&folly::TcpInfo::tcp_info::tcpi_snd_cwnd)
.has_value()); .has_value());
} }
...@@ -257,13 +256,13 @@ class TcpInfoTest : public Test { ...@@ -257,13 +256,13 @@ class TcpInfoTest : public Test {
EXPECT_EQ( EXPECT_EQ(
controlTcpInfo.tcpi_snd_cwnd, controlTcpInfo.tcpi_snd_cwnd,
wrappedTcpInfo.getFieldAsOptUInt64( wrappedTcpInfo.getFieldAsOptUInt64(
&folly::tcpinfo::tcp_info::tcpi_snd_cwnd)); &folly::TcpInfo::tcp_info::tcpi_snd_cwnd));
// try using getTcpInfoFieldAsOpt to get one of the newer fields // try using getTcpInfoFieldAsOpt to get one of the newer fields
// this field should _not_ be available in legacy // this field should _not_ be available in legacy
EXPECT_FALSE( EXPECT_FALSE(
wrappedTcpInfo wrappedTcpInfo
.getFieldAsOptUInt64(&folly::tcpinfo::tcp_info::tcpi_delivery_rate) .getFieldAsOptUInt64(&folly::TcpInfo::tcp_info::tcpi_delivery_rate)
.hasValue()); .hasValue());
} }
...@@ -318,7 +317,7 @@ class TcpInfoTest : public Test { ...@@ -318,7 +317,7 @@ class TcpInfoTest : public Test {
EXPECT_EQ( EXPECT_EQ(
controlTcpInfo.tcpi_delivery_rate, controlTcpInfo.tcpi_delivery_rate,
wrappedTcpInfo.getFieldAsOptUInt64( wrappedTcpInfo.getFieldAsOptUInt64(
&folly::tcpinfo::tcp_info::tcpi_delivery_rate)); &folly::TcpInfo::tcp_info::tcpi_delivery_rate));
} }
static void checkNoCcNameType(const TcpInfo& wrappedTcpInfo) { static void checkNoCcNameType(const TcpInfo& wrappedTcpInfo) {
...@@ -331,12 +330,16 @@ class TcpInfoTest : public Test { ...@@ -331,12 +330,16 @@ class TcpInfoTest : public Test {
// should get false for all three types // should get false for all three types
EXPECT_FALSE(wrappedTcpInfo.bbrCwndGain().has_value()); EXPECT_FALSE(wrappedTcpInfo.bbrCwndGain().has_value());
EXPECT_FALSE( EXPECT_FALSE(
wrappedTcpInfo.getFieldAsOptUInt64(&tcp_bbr_info::bbr_pacing_gain) wrappedTcpInfo
.getFieldAsOptUInt64(&folly::TcpInfo::tcp_bbr_info::bbr_pacing_gain)
.has_value()); .has_value());
EXPECT_FALSE(wrappedTcpInfo.getFieldAsOptUInt64(&tcpvegas_info::tcpv_rtt)
.has_value());
EXPECT_FALSE( EXPECT_FALSE(
wrappedTcpInfo.getFieldAsOptUInt64(&tcp_dctcp_info::dctcp_alpha) wrappedTcpInfo
.getFieldAsOptUInt64(&folly::TcpInfo::tcpvegas_info::tcpv_rtt)
.has_value());
EXPECT_FALSE(
wrappedTcpInfo
.getFieldAsOptUInt64(&folly::TcpInfo::tcp_dctcp_info::dctcp_alpha)
.has_value()); .has_value());
} }
...@@ -347,7 +350,8 @@ class TcpInfoTest : public Test { ...@@ -347,7 +350,8 @@ class TcpInfoTest : public Test {
const auto controlCcInfo = getTestBbrInfo().bbr; const auto controlCcInfo = getTestBbrInfo().bbr;
EXPECT_EQ( EXPECT_EQ(
controlCcInfo.bbr_pacing_gain, controlCcInfo.bbr_pacing_gain,
wrappedTcpInfo.getFieldAsOptUInt64(&tcp_bbr_info::bbr_pacing_gain)); wrappedTcpInfo.getFieldAsOptUInt64(
&folly::TcpInfo::tcp_bbr_info::bbr_pacing_gain));
const uint64_t bbrBwBytesPerSecond = const uint64_t bbrBwBytesPerSecond =
(uint64_t(controlCcInfo.bbr_bw_hi) << 32) + controlCcInfo.bbr_bw_lo; (uint64_t(controlCcInfo.bbr_bw_hi) << 32) + controlCcInfo.bbr_bw_lo;
EXPECT_EQ(bbrBwBytesPerSecond, wrappedTcpInfo.bbrBwBytesPerSecond()); EXPECT_EQ(bbrBwBytesPerSecond, wrappedTcpInfo.bbrBwBytesPerSecond());
...@@ -359,12 +363,14 @@ class TcpInfoTest : public Test { ...@@ -359,12 +363,14 @@ class TcpInfoTest : public Test {
// try using getFieldAsOptUInt64 directly to get one of the BBR fields // try using getFieldAsOptUInt64 directly to get one of the BBR fields
EXPECT_EQ( EXPECT_EQ(
controlCcInfo.bbr_pacing_gain, controlCcInfo.bbr_pacing_gain,
wrappedTcpInfo.getFieldAsOptUInt64(&tcp_bbr_info::bbr_pacing_gain)); wrappedTcpInfo.getFieldAsOptUInt64(
&folly::TcpInfo::tcp_bbr_info::bbr_pacing_gain));
// no CC info for the other types // no CC info for the other types
EXPECT_FALSE(wrappedTcpInfo.getFieldAsOptUInt64(&tcpvegas_info::tcpv_rtt)); EXPECT_FALSE(wrappedTcpInfo.getFieldAsOptUInt64(
EXPECT_FALSE( &folly::TcpInfo::tcpvegas_info::tcpv_rtt));
wrappedTcpInfo.getFieldAsOptUInt64(&tcp_dctcp_info::dctcp_alpha)); EXPECT_FALSE(wrappedTcpInfo.getFieldAsOptUInt64(
&folly::TcpInfo::tcp_dctcp_info::dctcp_alpha));
} }
static void checkCcFieldsAgainstVegas(const TcpInfo& wrappedTcpInfo) { static void checkCcFieldsAgainstVegas(const TcpInfo& wrappedTcpInfo) {
...@@ -375,15 +381,18 @@ class TcpInfoTest : public Test { ...@@ -375,15 +381,18 @@ class TcpInfoTest : public Test {
const auto controlCcInfo = getTestVegasInfo().vegas; const auto controlCcInfo = getTestVegasInfo().vegas;
EXPECT_EQ( EXPECT_EQ(
controlCcInfo.tcpv_rtt, controlCcInfo.tcpv_rtt,
wrappedTcpInfo.getFieldAsOptUInt64(&tcpvegas_info::tcpv_rtt)); wrappedTcpInfo.getFieldAsOptUInt64(
&folly::TcpInfo::tcpvegas_info::tcpv_rtt));
// no CC info for the other types // no CC info for the other types
EXPECT_FALSE(wrappedTcpInfo.bbrCwndGain().has_value()); EXPECT_FALSE(wrappedTcpInfo.bbrCwndGain().has_value());
EXPECT_FALSE( EXPECT_FALSE(
wrappedTcpInfo.getFieldAsOptUInt64(&tcp_bbr_info::bbr_pacing_gain) wrappedTcpInfo
.getFieldAsOptUInt64(&folly::TcpInfo::tcp_bbr_info::bbr_pacing_gain)
.has_value()); .has_value());
EXPECT_FALSE( EXPECT_FALSE(
wrappedTcpInfo.getFieldAsOptUInt64(&tcp_dctcp_info::dctcp_alpha) wrappedTcpInfo
.getFieldAsOptUInt64(&folly::TcpInfo::tcp_dctcp_info::dctcp_alpha)
.has_value()); .has_value());
} }
...@@ -415,18 +424,23 @@ class TcpInfoTest : public Test { ...@@ -415,18 +424,23 @@ class TcpInfoTest : public Test {
const auto controlCcInfo = getTestDctcpInfo().dctcp; const auto controlCcInfo = getTestDctcpInfo().dctcp;
EXPECT_EQ( EXPECT_EQ(
controlCcInfo.dctcp_alpha, controlCcInfo.dctcp_alpha,
wrappedTcpInfo.getFieldAsOptUInt64(&tcp_dctcp_info::dctcp_alpha)); wrappedTcpInfo.getFieldAsOptUInt64(
&folly::TcpInfo::tcp_dctcp_info::dctcp_alpha));
EXPECT_EQ( EXPECT_EQ(
controlCcInfo.dctcp_enabled, controlCcInfo.dctcp_enabled,
wrappedTcpInfo.getFieldAsOptUInt64(&tcp_dctcp_info::dctcp_enabled)); wrappedTcpInfo.getFieldAsOptUInt64(
&folly::TcpInfo::tcp_dctcp_info::dctcp_enabled));
// no CC info for the other types // no CC info for the other types
EXPECT_FALSE(wrappedTcpInfo.bbrCwndGain().has_value()); EXPECT_FALSE(wrappedTcpInfo.bbrCwndGain().has_value());
EXPECT_FALSE( EXPECT_FALSE(
wrappedTcpInfo.getFieldAsOptUInt64(&tcp_bbr_info::bbr_pacing_gain) wrappedTcpInfo
.getFieldAsOptUInt64(&folly::TcpInfo::tcp_bbr_info::bbr_pacing_gain)
.has_value());
EXPECT_FALSE(
wrappedTcpInfo
.getFieldAsOptUInt64(&folly::TcpInfo::tcpvegas_info::tcpv_rtt)
.has_value()); .has_value());
EXPECT_FALSE(wrappedTcpInfo.getFieldAsOptUInt64(&tcpvegas_info::tcpv_rtt)
.has_value());
} }
static void checkNoMemoryInfo(const TcpInfo& wrappedTcpInfo) { static void checkNoMemoryInfo(const TcpInfo& wrappedTcpInfo) {
...@@ -443,7 +457,7 @@ TEST_F(TcpInfoTest, LegacyStruct) { ...@@ -443,7 +457,7 @@ TEST_F(TcpInfoTest, LegacyStruct) {
NetworkSocket s(0); NetworkSocket s(0);
setupExpectCallTcpInfo(s, getTestLegacyTcpInfo()); setupExpectCallTcpInfo(s, getTestLegacyTcpInfo());
LookupOptions options = {}; TcpInfo::LookupOptions options = {};
options.getCcInfo = false; options.getCcInfo = false;
options.getMemInfo = false; options.getMemInfo = false;
auto wrappedTcpInfoExpect = auto wrappedTcpInfoExpect =
...@@ -463,7 +477,7 @@ TEST_F(TcpInfoTest, LatestStruct) { ...@@ -463,7 +477,7 @@ TEST_F(TcpInfoTest, LatestStruct) {
NetworkSocket s(0); NetworkSocket s(0);
setupExpectCallTcpInfo(s, getTestLatestTcpInfo()); setupExpectCallTcpInfo(s, getTestLatestTcpInfo());
LookupOptions options = {}; TcpInfo::LookupOptions options = {};
options.getCcInfo = false; options.getCcInfo = false;
options.getMemInfo = false; options.getMemInfo = false;
auto wrappedTcpInfoExpect = auto wrappedTcpInfoExpect =
...@@ -485,7 +499,7 @@ TEST_F(TcpInfoTest, LatestStructWithCcInfo) { ...@@ -485,7 +499,7 @@ TEST_F(TcpInfoTest, LatestStructWithCcInfo) {
setupExpectCallCcName(s, "bbr"); setupExpectCallCcName(s, "bbr");
setupExpectCallCcInfo(s, getTestBbrInfo()); setupExpectCallCcInfo(s, getTestBbrInfo());
LookupOptions options = {}; TcpInfo::LookupOptions options = {};
options.getCcInfo = true; options.getCcInfo = true;
options.getMemInfo = false; options.getMemInfo = false;
auto wrappedTcpInfoExpect = TcpInfo::initFromFd( auto wrappedTcpInfoExpect = TcpInfo::initFromFd(
...@@ -508,7 +522,7 @@ TEST_F(TcpInfoTest, LatestStructWithMemInfo) { ...@@ -508,7 +522,7 @@ TEST_F(TcpInfoTest, LatestStructWithMemInfo) {
ExpectCallMemInfoConfig{ ExpectCallMemInfoConfig{
.siocoutq = kTestSiocoutqVal, .siocinq = kTestSiocinqVal}); .siocoutq = kTestSiocoutqVal, .siocinq = kTestSiocinqVal});
LookupOptions options = {}; TcpInfo::LookupOptions options = {};
options.getCcInfo = false; options.getCcInfo = false;
options.getMemInfo = true; options.getMemInfo = true;
auto wrappedTcpInfoExpect = TcpInfo::initFromFd( auto wrappedTcpInfoExpect = TcpInfo::initFromFd(
...@@ -535,7 +549,7 @@ TEST_F(TcpInfoTest, LatestStructWithCcInfoAndMemInfo) { ...@@ -535,7 +549,7 @@ TEST_F(TcpInfoTest, LatestStructWithCcInfoAndMemInfo) {
ExpectCallMemInfoConfig{ ExpectCallMemInfoConfig{
.siocoutq = kTestSiocoutqVal, .siocinq = kTestSiocinqVal}); .siocoutq = kTestSiocoutqVal, .siocinq = kTestSiocinqVal});
LookupOptions options = {}; TcpInfo::LookupOptions options = {};
options.getCcInfo = true; options.getCcInfo = true;
options.getMemInfo = true; options.getMemInfo = true;
auto wrappedTcpInfoExpect = TcpInfo::initFromFd( auto wrappedTcpInfoExpect = TcpInfo::initFromFd(
...@@ -558,7 +572,7 @@ TEST_F(TcpInfoTest, LatestStructWithCcInfoAndMemInfoUnknownCc) { ...@@ -558,7 +572,7 @@ TEST_F(TcpInfoTest, LatestStructWithCcInfoAndMemInfoUnknownCc) {
ExpectCallMemInfoConfig{ ExpectCallMemInfoConfig{
.siocoutq = kTestSiocoutqVal, .siocinq = kTestSiocinqVal}); .siocoutq = kTestSiocoutqVal, .siocinq = kTestSiocinqVal});
LookupOptions options = {}; TcpInfo::LookupOptions options = {};
options.getCcInfo = true; options.getCcInfo = true;
options.getMemInfo = true; options.getMemInfo = true;
auto wrappedTcpInfoExpect = TcpInfo::initFromFd( auto wrappedTcpInfoExpect = TcpInfo::initFromFd(
...@@ -581,7 +595,7 @@ TEST_F(TcpInfoTest, LatestStructWithCcInfoAndMemInfoUnknownCc) { ...@@ -581,7 +595,7 @@ TEST_F(TcpInfoTest, LatestStructWithCcInfoAndMemInfoUnknownCc) {
TEST_F(TcpInfoTest, FailUninitializedSocket) { TEST_F(TcpInfoTest, FailUninitializedSocket) {
NetworkSocket s; NetworkSocket s;
LookupOptions options = {}; TcpInfo::LookupOptions options = {};
options.getCcInfo = true; options.getCcInfo = true;
options.getMemInfo = true; options.getMemInfo = true;
auto wrappedTcpInfoExpect = TcpInfo::initFromFd( auto wrappedTcpInfoExpect = TcpInfo::initFromFd(
...@@ -592,7 +606,7 @@ TEST_F(TcpInfoTest, FailUninitializedSocket) { ...@@ -592,7 +606,7 @@ TEST_F(TcpInfoTest, FailUninitializedSocket) {
TEST_F(TcpInfoTest, FailTcpInfo) { TEST_F(TcpInfoTest, FailTcpInfo) {
NetworkSocket s(0); NetworkSocket s(0);
LookupOptions options = {}; TcpInfo::LookupOptions options = {};
options.getCcInfo = true; options.getCcInfo = true;
options.getMemInfo = true; options.getMemInfo = true;
EXPECT_CALL(mockNetOpsDispatcher_, getsockopt(s, IPPROTO_TCP, TCP_INFO, _, _)) EXPECT_CALL(mockNetOpsDispatcher_, getsockopt(s, IPPROTO_TCP, TCP_INFO, _, _))
...@@ -622,7 +636,7 @@ TEST_F(TcpInfoTest, FailCcName) { ...@@ -622,7 +636,7 @@ TEST_F(TcpInfoTest, FailCcName) {
Pointee(Eq(TcpInfo::kLinuxTcpCaNameMax)))) Pointee(Eq(TcpInfo::kLinuxTcpCaNameMax))))
.WillOnce(Return(-1)); .WillOnce(Return(-1));
LookupOptions options = {}; TcpInfo::LookupOptions options = {};
options.getCcInfo = true; options.getCcInfo = true;
options.getMemInfo = true; options.getMemInfo = true;
auto wrappedTcpInfoExpect = TcpInfo::initFromFd( auto wrappedTcpInfoExpect = TcpInfo::initFromFd(
...@@ -660,7 +674,7 @@ TEST_F(TcpInfoTest, FailCcInfo) { ...@@ -660,7 +674,7 @@ TEST_F(TcpInfoTest, FailCcInfo) {
Pointee(Eq(sizeof(TcpInfo::tcp_cc_info))))) Pointee(Eq(sizeof(TcpInfo::tcp_cc_info)))))
.WillOnce(Return(-1)); .WillOnce(Return(-1));
LookupOptions options = {}; TcpInfo::LookupOptions options = {};
options.getCcInfo = true; options.getCcInfo = true;
options.getMemInfo = true; options.getMemInfo = true;
auto wrappedTcpInfoExpect = TcpInfo::initFromFd( auto wrappedTcpInfoExpect = TcpInfo::initFromFd(
...@@ -695,7 +709,7 @@ TEST_F(TcpInfoTest, FailSiocoutq) { ...@@ -695,7 +709,7 @@ TEST_F(TcpInfoTest, FailSiocoutq) {
return 0; return 0;
}))); })));
LookupOptions options = {}; TcpInfo::LookupOptions options = {};
options.getCcInfo = true; options.getCcInfo = true;
options.getMemInfo = true; options.getMemInfo = true;
auto wrappedTcpInfoExpect = TcpInfo::initFromFd( auto wrappedTcpInfoExpect = TcpInfo::initFromFd(
...@@ -726,7 +740,7 @@ TEST_F(TcpInfoTest, FailSiocinq) { ...@@ -726,7 +740,7 @@ TEST_F(TcpInfoTest, FailSiocinq) {
EXPECT_CALL(mockIoctlDispatcher_, ioctl(s.toFd(), SIOCINQ, testing::_)) EXPECT_CALL(mockIoctlDispatcher_, ioctl(s.toFd(), SIOCINQ, testing::_))
.WillOnce(Return(-1)); .WillOnce(Return(-1));
LookupOptions options = {}; TcpInfo::LookupOptions options = {};
options.getCcInfo = true; options.getCcInfo = true;
options.getMemInfo = true; options.getMemInfo = true;
auto wrappedTcpInfoExpect = TcpInfo::initFromFd( auto wrappedTcpInfoExpect = TcpInfo::initFromFd(
...@@ -806,7 +820,7 @@ TEST_P(TcpInfoTestCcParam, FetchAllAndCheck) { ...@@ -806,7 +820,7 @@ TEST_P(TcpInfoTestCcParam, FetchAllAndCheck) {
FAIL(); FAIL();
} }
LookupOptions options = {}; TcpInfo::LookupOptions options = {};
options.getCcInfo = true; options.getCcInfo = true;
options.getMemInfo = true; options.getMemInfo = true;
auto wrappedTcpInfoExpect = TcpInfo::initFromFd( auto wrappedTcpInfoExpect = TcpInfo::initFromFd(
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include <folly/portability/GTest.h> #include <folly/portability/GTest.h>
namespace folly { namespace folly {
namespace tcpinfo {
namespace test { namespace test {
class TcpInfoTestUtil { class TcpInfoTestUtil {
...@@ -32,7 +31,7 @@ class TcpInfoTestUtil { ...@@ -32,7 +31,7 @@ class TcpInfoTestUtil {
/** /**
* Mock to enable testing of socket buffer lookups. * Mock to enable testing of socket buffer lookups.
*/ */
class MockIoctlDispatcher : public folly::tcpinfo::TcpInfo::IoctlDispatcher { class MockIoctlDispatcher : public folly::TcpInfo::IoctlDispatcher {
public: public:
MockIoctlDispatcher() = default; MockIoctlDispatcher() = default;
virtual ~MockIoctlDispatcher() = default; virtual ~MockIoctlDispatcher() = default;
...@@ -79,8 +78,7 @@ class TcpInfoTestUtil { ...@@ -79,8 +78,7 @@ class TcpInfoTestUtil {
IPPROTO_TCP, IPPROTO_TCP,
TCP_CONGESTION, TCP_CONGESTION,
testing::NotNull(), testing::NotNull(),
testing::Pointee( testing::Pointee(testing::Eq(folly::TcpInfo::kLinuxTcpCaNameMax))))
testing::Eq(folly::tcpinfo::TcpInfo::kLinuxTcpCaNameMax))))
.WillOnce(testing::WithArgs<3, 4>( .WillOnce(testing::WithArgs<3, 4>(
testing::Invoke([ccName](void* optval, socklen_t* optlen) { testing::Invoke([ccName](void* optval, socklen_t* optlen) {
EXPECT_THAT(optlen, testing::Pointee(testing::Ge(ccName.size()))); EXPECT_THAT(optlen, testing::Pointee(testing::Ge(ccName.size())));
...@@ -89,8 +87,8 @@ class TcpInfoTestUtil { ...@@ -89,8 +87,8 @@ class TcpInfoTestUtil {
ccName.end(), ccName.end(),
((std::array< ((std::array<
char, char,
(unsigned int) (unsigned int)folly::TcpInfo::kLinuxTcpCaNameMax>*)
folly::tcpinfo::TcpInfo::kLinuxTcpCaNameMax>*)optval) optval)
->data()); ->data());
*optlen = std::min<socklen_t>(ccName.size(), *optlen); *optlen = std::min<socklen_t>(ccName.size(), *optlen);
return 0; return 0;
...@@ -100,7 +98,7 @@ class TcpInfoTestUtil { ...@@ -100,7 +98,7 @@ class TcpInfoTestUtil {
static void setupExpectCallCcInfo( static void setupExpectCallCcInfo(
folly::netops::test::MockDispatcher& mockDispatcher, folly::netops::test::MockDispatcher& mockDispatcher,
const NetworkSocket& s, const NetworkSocket& s,
const folly::tcpinfo::tcp_cc_info& ccInfo) { const folly::TcpInfo::tcp_cc_info& ccInfo) {
EXPECT_CALL( EXPECT_CALL(
mockDispatcher, mockDispatcher,
getsockopt( getsockopt(
...@@ -108,7 +106,7 @@ class TcpInfoTestUtil { ...@@ -108,7 +106,7 @@ class TcpInfoTestUtil {
IPPROTO_TCP, IPPROTO_TCP,
TCP_CC_INFO, TCP_CC_INFO,
testing::NotNull(), testing::NotNull(),
testing::Pointee(testing::Eq(sizeof(folly::tcpinfo::tcp_cc_info))))) testing::Pointee(testing::Eq(sizeof(folly::TcpInfo::tcp_cc_info)))))
.WillOnce(testing::WithArgs<3, 4>( .WillOnce(testing::WithArgs<3, 4>(
testing::Invoke([ccInfo](void* optval, socklen_t* optlen) { testing::Invoke([ccInfo](void* optval, socklen_t* optlen) {
auto copied = std::min((unsigned int)sizeof ccInfo, *optlen); auto copied = std::min((unsigned int)sizeof ccInfo, *optlen);
...@@ -120,5 +118,4 @@ class TcpInfoTestUtil { ...@@ -120,5 +118,4 @@ class TcpInfoTestUtil {
}; };
} // namespace test } // namespace test
} // namespace tcpinfo
} // namespace folly } // namespace folly
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment