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 @@
#endif
namespace folly {
namespace tcpinfo {
namespace {
constexpr std::array<
......@@ -52,7 +51,6 @@ static_assert(
using ms = std::chrono::milliseconds;
using us = std::chrono::microseconds;
using namespace tcpinfo;
TcpInfo::IoctlDispatcher* TcpInfo::IoctlDispatcher::getDefaultInstance() {
static TcpInfo::IoctlDispatcher dispatcher = {};
......@@ -69,7 +67,7 @@ int TcpInfo::IoctlDispatcher::ioctl(int fd, unsigned long request, void* argp) {
Expected<TcpInfo, std::errc> TcpInfo::initFromFd(
const NetworkSocket& fd,
const LookupOptions& options,
const TcpInfo::LookupOptions& options,
netops::Dispatcher& netopsDispatcher,
IoctlDispatcher& ioctlDispatcher) {
#ifndef FOLLY_HAVE_TCP_INFO
......@@ -85,7 +83,7 @@ Expected<TcpInfo, std::errc> TcpInfo::initFromFd(
auto ret = netopsDispatcher.getsockopt(
fd,
IPPROTO_TCP,
folly::tcpinfo::tcp_info_sock_opt,
folly::detail::tcp_info_sock_opt,
(void*)&info.tcpInfo,
&len);
if (ret < 0) {
......@@ -411,8 +409,10 @@ Optional<uint64_t> TcpInfo::bbrBwBytesPerSecond() const {
#ifndef FOLLY_HAVE_TCP_CC_INFO
return folly::none;
#elif defined(__linux__)
auto bbrBwLoOpt = getFieldAsOptUInt64(&tcp_bbr_info::bbr_bw_lo);
auto bbrBwHiOpt = getFieldAsOptUInt64(&tcp_bbr_info::bbr_bw_hi);
auto bbrBwLoOpt =
getFieldAsOptUInt64(&folly::TcpInfo::tcp_bbr_info::bbr_bw_lo);
auto bbrBwHiOpt =
getFieldAsOptUInt64(&folly::TcpInfo::tcp_bbr_info::bbr_bw_hi);
if (bbrBwLoOpt && bbrBwHiOpt) {
return ((int64_t)*bbrBwHiOpt << 32) + *bbrBwLoOpt;
}
......@@ -428,7 +428,7 @@ Optional<std::chrono::microseconds> TcpInfo::bbrMinrtt() const {
#ifndef FOLLY_HAVE_TCP_CC_INFO
return folly::none;
#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>();
#elif defined(__APPLE__)
return folly::none;
......@@ -441,7 +441,7 @@ Optional<uint64_t> TcpInfo::bbrPacingGain() const {
#ifndef FOLLY_HAVE_TCP_CC_INFO
return folly::none;
#elif defined(__linux__)
return getFieldAsOptUInt64(&tcp_bbr_info::bbr_pacing_gain);
return getFieldAsOptUInt64(&folly::TcpInfo::tcp_bbr_info::bbr_pacing_gain);
#elif defined(__APPLE__)
return folly::none;
#else
......@@ -453,7 +453,7 @@ Optional<uint64_t> TcpInfo::bbrCwndGain() const {
#ifndef FOLLY_HAVE_TCP_CC_INFO
return folly::none;
#elif defined(__linux__)
return getFieldAsOptUInt64(&tcp_bbr_info::bbr_cwnd_gain);
return getFieldAsOptUInt64(&folly::TcpInfo::tcp_bbr_info::bbr_cwnd_gain);
#elif defined(__APPLE__)
return folly::none;
#else
......@@ -539,8 +539,8 @@ void TcpInfo::initCcInfoFromFd(
LOG(FATAL) << "CongestionControlName::NumCcTypes is not a valid CC type";
}
tcpinfo::tcp_cc_info ccInfo = {};
socklen_t len = sizeof(tcpinfo::tcp_cc_info);
tcp_cc_info ccInfo = {};
socklen_t len = sizeof(tcp_cc_info);
const int ret = netopsDispatcher.getsockopt(
fd, IPPROTO_TCP, TCP_CC_INFO, (void*)&ccInfo, &len);
if (ret < 0) {
......@@ -574,5 +574,4 @@ void TcpInfo::initMemInfoFromFd(
#endif
}
} // namespace tcpinfo
} // namespace folly
......@@ -27,19 +27,6 @@
#include <folly/net/TcpInfoTypes.h>
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.
......@@ -112,6 +99,20 @@ struct TcpInfo {
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.
*
......@@ -139,7 +140,7 @@ struct TcpInfo {
*/
static Expected<TcpInfo, std::errc> initFromFd(
const NetworkSocket& fd,
const LookupOptions& options = LookupOptions(),
const TcpInfo::LookupOptions& options = TcpInfo::LookupOptions(),
netops::Dispatcher& netopsDispatcher =
*netops::Dispatcher::getDefaultInstance(),
IoctlDispatcher& ioctlDispatcher =
......@@ -268,7 +269,7 @@ struct TcpInfo {
#if defined(FOLLY_HAVE_TCP_INFO)
public:
using tcp_info = folly::tcpinfo::tcp_info;
using tcp_info = folly::detail::tcp_info;
/**
* Returns pointer containing requested field from tcp_info struct.
......@@ -311,7 +312,10 @@ struct TcpInfo {
#if defined(FOLLY_HAVE_TCP_CC_INFO)
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)
static constexpr socklen_t kLinuxTcpCaNameMax = 16;
......@@ -326,8 +330,7 @@ struct TcpInfo {
* specifics, use accessors such as bbrBwBitsPerSecond().
*/
template <typename T1>
folly::Optional<uint64_t> getFieldAsOptUInt64(
T1 tcpinfo::tcp_bbr_info::*field) const {
folly::Optional<uint64_t> getFieldAsOptUInt64(T1 tcp_bbr_info::*field) const {
if (maybeCcInfo.has_value() && ccNameEnum() == CongestionControlName::BBR) {
return getFieldAsOptUInt64(maybeCcInfo.value().bbr, field);
}
......@@ -342,7 +345,7 @@ struct TcpInfo {
*/
template <typename T1>
folly::Optional<uint64_t> getFieldAsOptUInt64(
T1 tcpinfo::tcpvegas_info::*field) const {
T1 tcpvegas_info::*field) const {
if (maybeCcInfo.hasValue() &&
ccNameEnum() == CongestionControlName::VEGAS) {
return getFieldAsOptUInt64(maybeCcInfo.value().vegas, field);
......@@ -358,7 +361,7 @@ struct TcpInfo {
*/
template <typename T1>
const folly::Optional<uint64_t> getFieldAsOptUInt64(
T1 tcpinfo::tcp_dctcp_info::*field) const {
T1 tcp_dctcp_info::*field) const {
if (maybeCcInfo.has_value() &&
(ccNameEnum() == CongestionControlName::DCTCP ||
ccNameEnum() == CongestionControlName::DCTCP_CUBIC ||
......@@ -410,5 +413,4 @@ struct TcpInfo {
folly::Optional<size_t> maybeRecvBufInUseBytes;
};
} // namespace tcpinfo
} // namespace folly
......@@ -27,7 +27,7 @@
#endif
namespace folly {
namespace tcpinfo {
namespace detail {
/**
*
......@@ -222,5 +222,5 @@ union tcp_cc_info {
};
#endif
} // namespace tcpinfo
} // namespace detail
} // namespace folly
This diff is collapsed.
......@@ -24,7 +24,6 @@
#include <folly/portability/GTest.h>
namespace folly {
namespace tcpinfo {
namespace test {
class TcpInfoTestUtil {
......@@ -32,7 +31,7 @@ class TcpInfoTestUtil {
/**
* Mock to enable testing of socket buffer lookups.
*/
class MockIoctlDispatcher : public folly::tcpinfo::TcpInfo::IoctlDispatcher {
class MockIoctlDispatcher : public folly::TcpInfo::IoctlDispatcher {
public:
MockIoctlDispatcher() = default;
virtual ~MockIoctlDispatcher() = default;
......@@ -79,8 +78,7 @@ class TcpInfoTestUtil {
IPPROTO_TCP,
TCP_CONGESTION,
testing::NotNull(),
testing::Pointee(
testing::Eq(folly::tcpinfo::TcpInfo::kLinuxTcpCaNameMax))))
testing::Pointee(testing::Eq(folly::TcpInfo::kLinuxTcpCaNameMax))))
.WillOnce(testing::WithArgs<3, 4>(
testing::Invoke([ccName](void* optval, socklen_t* optlen) {
EXPECT_THAT(optlen, testing::Pointee(testing::Ge(ccName.size())));
......@@ -89,8 +87,8 @@ class TcpInfoTestUtil {
ccName.end(),
((std::array<
char,
(unsigned int)
folly::tcpinfo::TcpInfo::kLinuxTcpCaNameMax>*)optval)
(unsigned int)folly::TcpInfo::kLinuxTcpCaNameMax>*)
optval)
->data());
*optlen = std::min<socklen_t>(ccName.size(), *optlen);
return 0;
......@@ -100,7 +98,7 @@ class TcpInfoTestUtil {
static void setupExpectCallCcInfo(
folly::netops::test::MockDispatcher& mockDispatcher,
const NetworkSocket& s,
const folly::tcpinfo::tcp_cc_info& ccInfo) {
const folly::TcpInfo::tcp_cc_info& ccInfo) {
EXPECT_CALL(
mockDispatcher,
getsockopt(
......@@ -108,7 +106,7 @@ class TcpInfoTestUtil {
IPPROTO_TCP,
TCP_CC_INFO,
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>(
testing::Invoke([ccInfo](void* optval, socklen_t* optlen) {
auto copied = std::min((unsigned int)sizeof ccInfo, *optlen);
......@@ -120,5 +118,4 @@ class TcpInfoTestUtil {
};
} // namespace test
} // namespace tcpinfo
} // 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