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
This diff is collapsed.
...@@ -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