1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-08-06 22:22:38 +03:00

Revert PMTU and size-enforced packet builder

Differential Revision: D23283619

fbshipit-source-id: b7fe31871dad5711016234a2d10ae84edc4fd24c
This commit is contained in:
Luca Niccolini
2020-08-22 16:54:27 -07:00
committed by Facebook GitHub Bot
parent 918cc5786d
commit c47c3cf5c6
23 changed files with 47 additions and 328 deletions

View File

@@ -38,8 +38,8 @@ constexpr uint16_t kDefaultMaxUDPPayload = 1452;
// maximum QUIC packet size. // maximum QUIC packet size.
constexpr uint16_t kMinMaxUDPPayload = 1200; constexpr uint16_t kMinMaxUDPPayload = 1200;
// How many bytes to reduce from udpSendPacketLen when socket write leads // How many bytes to reduce from udpSendPacketLen when socket write leads to
// to EMSGSIZE. // EMSGSIZE.
constexpr uint16_t kDefaultMsgSizeBackOffSize = 50; constexpr uint16_t kDefaultMsgSizeBackOffSize = 50;
// Size of read buffer we provide to AsyncUDPSocket. The packet size cannot be // Size of read buffer we provide to AsyncUDPSocket. The packet size cannot be

View File

@@ -590,7 +590,7 @@ TEST_P(QuicBatchWriterTest, InplaceWriterBufResidueCheck) {
auto bufAccessor = auto bufAccessor =
std::make_unique<SimpleBufAccessor>(conn_.udpSendPacketLen * batchSize); std::make_unique<SimpleBufAccessor>(conn_.udpSendPacketLen * batchSize);
conn_.bufAccessor = bufAccessor.get(); conn_.bufAccessor = bufAccessor.get();
updateUdpSendPacketLen(conn_, 1000); conn_.udpSendPacketLen = 1000;
auto batchWriter = quic::BatchWriterFactory::makeBatchWriter( auto batchWriter = quic::BatchWriterFactory::makeBatchWriter(
sock, sock,
quic::QuicBatchingMode::BATCHING_MODE_GSO, quic::QuicBatchingMode::BATCHING_MODE_GSO,

View File

@@ -862,7 +862,7 @@ TEST_F(QuicPacketSchedulerTest, CloningSchedulerWithInplaceBuilderFullPacket) {
TEST_F(QuicPacketSchedulerTest, CloneLargerThanOriginalPacket) { TEST_F(QuicPacketSchedulerTest, CloneLargerThanOriginalPacket) {
QuicClientConnectionState conn( QuicClientConnectionState conn(
FizzClientQuicHandshakeContext::Builder().build()); FizzClientQuicHandshakeContext::Builder().build());
updateUdpSendPacketLen(conn, 1000); conn.udpSendPacketLen = 1000;
conn.streamManager->setMaxLocalBidirectionalStreams(10); conn.streamManager->setMaxLocalBidirectionalStreams(10);
conn.flowControlState.peerAdvertisedMaxOffset = 100000; conn.flowControlState.peerAdvertisedMaxOffset = 100000;
conn.flowControlState.peerAdvertisedInitialMaxStreamOffsetBidiRemote = 100000; conn.flowControlState.peerAdvertisedInitialMaxStreamOffsetBidiRemote = 100000;

View File

@@ -1087,7 +1087,7 @@ TEST_F(QuicTransportFunctionsTest, TestUpdateConnectionConnWindowUpdate) {
TEST_F(QuicTransportFunctionsTest, WriteQuicDataToSocketWithCC) { TEST_F(QuicTransportFunctionsTest, WriteQuicDataToSocketWithCC) {
auto conn = createConn(); auto conn = createConn();
updateUdpSendPacketLen(*conn, 30); conn->udpSendPacketLen = 30;
auto mockCongestionController = auto mockCongestionController =
std::make_unique<NiceMock<MockCongestionController>>(); std::make_unique<NiceMock<MockCongestionController>>();
auto rawCongestionController = mockCongestionController.get(); auto rawCongestionController = mockCongestionController.get();
@@ -1162,7 +1162,7 @@ TEST_F(QuicTransportFunctionsTest, WriteQuicDataToSocketLimitTest) {
std::make_unique<NiceMock<MockCongestionController>>(); std::make_unique<NiceMock<MockCongestionController>>();
auto rawCongestionController = mockCongestionController.get(); auto rawCongestionController = mockCongestionController.get();
conn->congestionController = std::move(mockCongestionController); conn->congestionController = std::move(mockCongestionController);
updateUdpSendPacketLen(*conn, aead->getCipherOverhead() + 50); conn->udpSendPacketLen = aead->getCipherOverhead() + 50;
EventBase evb; EventBase evb;
auto socket = auto socket =
@@ -2124,7 +2124,7 @@ TEST_F(QuicTransportFunctionsTest, WriteLimitBytRttFraction) {
TEST_F(QuicTransportFunctionsTest, CongestionControlWritableBytesRoundUp) { TEST_F(QuicTransportFunctionsTest, CongestionControlWritableBytesRoundUp) {
auto conn = createConn(); auto conn = createConn();
updateUdpSendPacketLen(*conn, 2000); conn->udpSendPacketLen = 2000;
auto mockCongestionController = auto mockCongestionController =
std::make_unique<NiceMock<MockCongestionController>>(); std::make_unique<NiceMock<MockCongestionController>>();
auto rawCongestionController = mockCongestionController.get(); auto rawCongestionController = mockCongestionController.get();
@@ -2217,7 +2217,7 @@ TEST_F(QuicTransportFunctionsTest, HandshakeConfirmedDropCipher) {
TEST_F(QuicTransportFunctionsTest, ProbeWriteNewFunctionalFrames) { TEST_F(QuicTransportFunctionsTest, ProbeWriteNewFunctionalFrames) {
auto conn = createConn(); auto conn = createConn();
updateUdpSendPacketLen(*conn, 1200); conn->udpSendPacketLen = 1200;
EventBase evb; EventBase evb;
auto sock = std::make_unique<NiceMock<folly::test::MockAsyncUDPSocket>>(&evb); auto sock = std::make_unique<NiceMock<folly::test::MockAsyncUDPSocket>>(&evb);
auto rawSocket = sock.get(); auto rawSocket = sock.get();

View File

@@ -3034,7 +3034,7 @@ TEST_F(QuicTransportTest, PacingWillBurstFirst) {
TEST_F(QuicTransportTest, AlreadyScheduledPacingNoWrite) { TEST_F(QuicTransportTest, AlreadyScheduledPacingNoWrite) {
transport_->setPacingTimer(TimerHighRes::newTimer(&evb_, 1ms)); transport_->setPacingTimer(TimerHighRes::newTimer(&evb_, 1ms));
auto& conn = transport_->getConnectionState(); auto& conn = transport_->getConnectionState();
updateUdpSendPacketLen(conn, 100); conn.udpSendPacketLen = 100;
auto mockCongestionController = auto mockCongestionController =
std::make_unique<NiceMock<MockCongestionController>>(); std::make_unique<NiceMock<MockCongestionController>>();
auto rawCongestionController = mockCongestionController.get(); auto rawCongestionController = mockCongestionController.get();

View File

@@ -1423,21 +1423,17 @@ void QuicClientTransport::addNewPeerAddress(folly::SocketAddress peerAddress) {
CHECK(peerAddress.isInitialized()); CHECK(peerAddress.isInitialized());
if (happyEyeballsEnabled_) { if (happyEyeballsEnabled_) {
updateUdpSendPacketLen( conn_->udpSendPacketLen = std::min(
*conn_,
std::min(
conn_->udpSendPacketLen, conn_->udpSendPacketLen,
(peerAddress.getFamily() == AF_INET6 (peerAddress.getFamily() == AF_INET6 ? kDefaultV6UDPSendPacketLen
? kDefaultV6UDPSendPacketLen : kDefaultV4UDPSendPacketLen));
: kDefaultV4UDPSendPacketLen)));
happyEyeballsAddPeerAddress(*conn_, peerAddress); happyEyeballsAddPeerAddress(*conn_, peerAddress);
return; return;
} }
updateUdpSendPacketLen( conn_->udpSendPacketLen = peerAddress.getFamily() == AF_INET6
*conn_, ? kDefaultV6UDPSendPacketLen
peerAddress.getFamily() == AF_INET6 ? kDefaultV6UDPSendPacketLen : kDefaultV4UDPSendPacketLen;
: kDefaultV4UDPSendPacketLen);
conn_->originalPeerAddress = peerAddress; conn_->originalPeerAddress = peerAddress;
conn_->peerAddress = std::move(peerAddress); conn_->peerAddress = std::move(peerAddress);
} }

View File

@@ -43,8 +43,6 @@ std::unique_ptr<QuicClientConnectionState> undoAllClientStateForRetry(
newConn->originalPeerAddress = conn->originalPeerAddress; newConn->originalPeerAddress = conn->originalPeerAddress;
newConn->peerAddress = conn->peerAddress; newConn->peerAddress = conn->peerAddress;
newConn->udpSendPacketLen = conn->udpSendPacketLen; newConn->udpSendPacketLen = conn->udpSendPacketLen;
newConn->peerMaxPacketSize = conn->peerMaxPacketSize;
newConn->currentPMTU = conn->currentPMTU;
newConn->supportedVersions = conn->supportedVersions; newConn->supportedVersions = conn->supportedVersions;
newConn->transportSettings = conn->transportSettings; newConn->transportSettings = conn->transportSettings;
newConn->initialWriteCipher = std::move(conn->initialWriteCipher); newConn->initialWriteCipher = std::move(conn->initialWriteCipher);
@@ -153,13 +151,12 @@ void processServerInitialParams(
} }
conn.peerAckDelayExponent = conn.peerAckDelayExponent =
ackDelayExponent.value_or(kDefaultAckDelayExponent); ackDelayExponent.value_or(kDefaultAckDelayExponent);
// TODO: udpSendPacketLen should also be limited by PMTU // TODO: udpSendPacketLen should also be limited by PMTU
if (conn.transportSettings.canIgnorePathMTU) { if (conn.transportSettings.canIgnorePathMTU) {
if (*packetSize > kDefaultMaxUDPPayload) { if (*packetSize > kDefaultMaxUDPPayload) {
*packetSize = kDefaultUDPSendPacketLen; *packetSize = kDefaultUDPSendPacketLen;
} }
updateUdpSendPacketLen(conn, *packetSize); conn.udpSendPacketLen = *packetSize;
} }
// Currently no-op for a client; it doesn't issue connection ids // Currently no-op for a client; it doesn't issue connection ids
@@ -238,7 +235,7 @@ void updateTransportParamsFromCachedEarlyParams(
const CachedServerTransportParameters& transportParams) { const CachedServerTransportParameters& transportParams) {
conn.peerIdleTimeout = std::chrono::milliseconds(transportParams.idleTimeout); conn.peerIdleTimeout = std::chrono::milliseconds(transportParams.idleTimeout);
if (conn.transportSettings.canIgnorePathMTU) { if (conn.transportSettings.canIgnorePathMTU) {
updateUdpSendPacketLen(conn, transportParams.maxRecvPacketSize); conn.udpSendPacketLen = transportParams.maxRecvPacketSize;
} }
conn.flowControlState.peerAdvertisedMaxOffset = conn.flowControlState.peerAdvertisedMaxOffset =
transportParams.initialMaxData; transportParams.initialMaxData;

View File

@@ -286,94 +286,6 @@ Buf StatelessResetPacketBuilder::buildPacket() && {
return std::move(data_); return std::move(data_);
} }
RegularSizeEnforcedPacketBuilder::RegularSizeEnforcedPacketBuilder(
Packet packet,
uint64_t enforcedSize,
uint32_t cipherOverhead)
: packet_(std::move(packet.packet)),
header_(std::move(packet.header)),
body_(std::move(packet.body)),
bodyAppender_(body_.get(), kAppenderGrowthSize),
enforcedSize_(enforcedSize),
cipherOverhead_(cipherOverhead) {}
bool RegularSizeEnforcedPacketBuilder::canBuildPacket() const noexcept {
// We only force size of packets with short header, because d6d probes always
// have short headers and there's no other situations for this type of builder
const ShortHeader* shortHeader = packet_.header.asShort();
// We also don't want to send packets longer than kDefaultMaxUDPPayload
return shortHeader && enforcedSize_ <= kDefaultMaxUDPPayload &&
(body_->computeChainDataLength() + header_->computeChainDataLength() +
cipherOverhead_ <
enforcedSize_);
}
PacketBuilderInterface::Packet
RegularSizeEnforcedPacketBuilder::buildPacket() && {
// Store counters on the stack to overhead from function calls
size_t extraDataWritten = 0;
size_t bodyLength = body_->computeChainDataLength();
size_t headerLength = header_->computeChainDataLength();
while (extraDataWritten + bodyLength + headerLength + cipherOverhead_ <
enforcedSize_) {
QuicInteger paddingType(static_cast<uint8_t>(FrameType::PADDING));
paddingType.encode([&](auto val) { bodyAppender_.writeBE(val); });
extraDataWritten++;
}
return Packet(std::move(packet_), std::move(header_), std::move(body_));
}
InplaceSizeEnforcedPacketBuilder::InplaceSizeEnforcedPacketBuilder(
BufAccessor& bufAccessor,
Packet packet,
uint64_t enforcedSize,
uint32_t cipherOverhead)
: bufAccessor_(bufAccessor),
iobuf_(bufAccessor_.obtain()),
packet_(std::move(packet.packet)),
header_(std::move(packet.header)),
body_(std::move(packet.body)),
enforcedSize_(enforcedSize),
cipherOverhead_(cipherOverhead) {}
bool InplaceSizeEnforcedPacketBuilder::canBuildPacket() const noexcept {
const ShortHeader* shortHeader = packet_.header.asShort();
size_t encryptedPacketSize =
header_->length() + body_->length() + cipherOverhead_;
size_t delta = enforcedSize_ - encryptedPacketSize;
return shortHeader && enforcedSize_ <= kDefaultMaxUDPPayload &&
encryptedPacketSize < enforcedSize_ && iobuf_->tailroom() >= delta;
}
PacketBuilderInterface::Packet
InplaceSizeEnforcedPacketBuilder::buildPacket() && {
// Create bodyWriter
size_t encryptedPacketSize =
header_->length() + body_->length() + cipherOverhead_;
size_t paddingSize = enforcedSize_ - encryptedPacketSize;
BufWriter bodyWriter(*iobuf_, paddingSize);
// Store counters on the stack to overhead from function calls
size_t extraDataWritten = 0;
size_t bodyLength = body_->computeChainDataLength();
size_t headerLength = header_->computeChainDataLength();
while (extraDataWritten + bodyLength + headerLength + cipherOverhead_ <
enforcedSize_) {
QuicInteger paddingType(static_cast<uint8_t>(FrameType::PADDING));
paddingType.encode([&](auto val) { bodyWriter.writeBE(val); });
extraDataWritten++;
}
PacketBuilderInterface::Packet builtPacket(
std::move(packet_),
std::move(header_),
folly::IOBuf::wrapBuffer(body_->data(), iobuf_->tail() - body_->data()));
// Release internal iobuf
bufAccessor_.release(std::move(iobuf_));
return builtPacket;
}
VersionNegotiationPacketBuilder::VersionNegotiationPacketBuilder( VersionNegotiationPacketBuilder::VersionNegotiationPacketBuilder(
ConnectionId sourceConnectionId, ConnectionId sourceConnectionId,
ConnectionId destinationConnectionId, ConnectionId destinationConnectionId,

View File

@@ -255,88 +255,6 @@ class RegularQuicPacketBuilder final : public PacketBuilderInterface {
folly::Optional<PacketNumEncodingResult> packetNumberEncoding_; folly::Optional<PacketNumEncodingResult> packetNumberEncoding_;
}; };
/**
* A less involving interface for packet builder, this enables polymorphism
* for wrapper-like packet builders (e.g. RegularSizeEnforcedPacketBuilder).
*/
class WrapperPacketBuilderInterface {
public:
using Packet = PacketBuilderInterface::Packet;
virtual ~WrapperPacketBuilderInterface() = default;
FOLLY_NODISCARD virtual bool canBuildPacket() const noexcept = 0;
virtual Packet buildPacket() && = 0;
};
/**
* This builder will enforce the packet size by appending padding frames for
* chained memory. This means appending IOBuf at the end of the chain. The
* caller should ensure canBuildPacket() returns true before constructing the
* builder.
*/
class RegularSizeEnforcedPacketBuilder : public WrapperPacketBuilderInterface {
public:
using Packet = PacketBuilderInterface::Packet;
explicit RegularSizeEnforcedPacketBuilder(
Packet packet,
uint64_t enforcedSize,
uint32_t cipherOverhead);
/**
* Returns true when packet has short header, and that enforced size >
* current packet size + cipher overhead, otherwise false
*/
FOLLY_NODISCARD bool canBuildPacket() const noexcept override;
Packet buildPacket() && override;
private:
RegularQuicWritePacket packet_;
Buf header_;
Buf body_;
BufAppender bodyAppender_;
uint64_t enforcedSize_;
uint32_t cipherOverhead_;
};
/**
* This builder will enforce the packet size by appending padding frames for
* continuous memory. This means pushing padding frame directly to the current
* tail offset. The caller should ensure canBuildPacket() returns true before
* constructing the builder.
*/
class InplaceSizeEnforcedPacketBuilder : public WrapperPacketBuilderInterface {
public:
using Packet = PacketBuilderInterface::Packet;
explicit InplaceSizeEnforcedPacketBuilder(
BufAccessor& bufAccessor,
Packet packet,
uint64_t enforcedSize,
uint32_t cipherOverhead);
/**
* Returns true when packet has short header, and that enforced size> current
* packet size + cipher oveahead and that iobuf has enough tailroom,
* otherwise false
*/
FOLLY_NODISCARD bool canBuildPacket() const noexcept override;
Packet buildPacket() && override;
private:
BufAccessor& bufAccessor_;
Buf iobuf_;
RegularQuicWritePacket packet_;
Buf header_;
Buf body_;
uint64_t enforcedSize_;
uint32_t cipherOverhead_;
};
class VersionNegotiationPacketBuilder { class VersionNegotiationPacketBuilder {
public: public:
explicit VersionNegotiationPacketBuilder( explicit VersionNegotiationPacketBuilder(

View File

@@ -109,7 +109,7 @@ class QuicPacketBuilderTest : public TestWithParam<TestFlavor> {
folly::assume_unreachable(); folly::assume_unreachable();
} }
protected: private:
std::unique_ptr<BufAccessor> simpleBufAccessor_; std::unique_ptr<BufAccessor> simpleBufAccessor_;
}; };
@@ -277,67 +277,6 @@ TEST_P(QuicPacketBuilderTest, ShortHeaderRegularPacket) {
EXPECT_EQ(pktNum, decodedHeader.getPacketSequenceNum()); EXPECT_EQ(pktNum, decodedHeader.getPacketSequenceNum());
} }
TEST_P(QuicPacketBuilderTest, EnforcePacketSizeWithCipherOverhead) {
auto connId = getTestConnectionId();
PacketNum pktNum = 222;
PacketNum largestAckedPacketNum = 0;
size_t cipherOverhead = 2;
uint64_t enforcedSize = 1400;
auto aead = std::make_unique<NiceMock<MockAead>>();
auto aead_ = aead.get();
EXPECT_CALL(*aead_, _inplaceEncrypt(_, _, _))
.WillRepeatedly(Invoke([&](auto& buf, auto, auto) {
auto overhead = folly::IOBuf::create(1000);
overhead->append(cipherOverhead);
auto clone = buf->clone();
clone->prependChain(std::move(overhead));
return std::move(clone);
}));
auto builder = testBuilderProvider(
GetParam(),
kDefaultUDPSendPacketLen,
ShortHeader(ProtectionType::KeyPhaseZero, connId, pktNum),
largestAckedPacketNum,
2000);
builder->accountForCipherOverhead(cipherOverhead);
builder->encodePacketHeader();
// write out at least one frame
writeFrame(PaddingFrame(), *builder);
EXPECT_TRUE(builder->canBuildPacket());
auto builtOut = std::move(*builder).buildPacket();
auto param = GetParam();
if (param == TestFlavor::Regular) {
EXPECT_EQ(builtOut.body->isManagedOne(), true);
RegularSizeEnforcedPacketBuilder sizeEnforcedBuilder(
std::move(builtOut), enforcedSize, cipherOverhead);
EXPECT_TRUE(sizeEnforcedBuilder.canBuildPacket());
auto out = std::move(sizeEnforcedBuilder).buildPacket();
EXPECT_EQ(
out.header->computeChainDataLength() +
out.body->computeChainDataLength(),
enforcedSize - cipherOverhead);
auto buf = packetToBuf(out, aead_);
EXPECT_EQ(buf->computeChainDataLength(), enforcedSize);
} else {
EXPECT_EQ(builtOut.body->isManagedOne(), false);
InplaceSizeEnforcedPacketBuilder sizeEnforcedBuilder(
*simpleBufAccessor_, std::move(builtOut), enforcedSize, cipherOverhead);
EXPECT_TRUE(sizeEnforcedBuilder.canBuildPacket());
auto out = std::move(sizeEnforcedBuilder).buildPacket();
EXPECT_EQ(
out.header->computeChainDataLength() +
out.body->computeChainDataLength(),
enforcedSize - cipherOverhead);
auto buf = packetToBuf(out, aead_);
EXPECT_EQ(buf->computeChainDataLength(), enforcedSize);
}
}
TEST_P(QuicPacketBuilderTest, ShortHeaderWithNoFrames) { TEST_P(QuicPacketBuilderTest, ShortHeaderWithNoFrames) {
auto connId = getTestConnectionId(); auto connId = getTestConnectionId();
PacketNum pktNum = 222; PacketNum pktNum = 222;

View File

@@ -25,7 +25,7 @@ class BbrTest : public Test {};
TEST_F(BbrTest, InitStates) { TEST_F(BbrTest, InitStates) {
QuicConnectionStateBase conn(QuicNodeType::Client); QuicConnectionStateBase conn(QuicNodeType::Client);
updateUdpSendPacketLen(conn, 1000); conn.udpSendPacketLen = 1000;
BbrCongestionController bbr(conn); BbrCongestionController bbr(conn);
EXPECT_EQ(CongestionControlType::BBR, bbr.type()); EXPECT_EQ(CongestionControlType::BBR, bbr.type());
EXPECT_FALSE(bbr.inRecovery()); EXPECT_FALSE(bbr.inRecovery());
@@ -39,7 +39,7 @@ TEST_F(BbrTest, Recovery) {
QuicConnectionStateBase conn(QuicNodeType::Client); QuicConnectionStateBase conn(QuicNodeType::Client);
auto qLogger = std::make_shared<FileQLogger>(VantagePoint::Client); auto qLogger = std::make_shared<FileQLogger>(VantagePoint::Client);
conn.qLogger = qLogger; conn.qLogger = qLogger;
updateUdpSendPacketLen(conn, 1000); conn.udpSendPacketLen = 1000;
conn.transportSettings.initCwndInMss = 500; // Make a really large initCwnd conn.transportSettings.initCwndInMss = 500; // Make a really large initCwnd
BbrCongestionController bbr(conn); BbrCongestionController bbr(conn);
// Make a huge inflight so we don't underflow anything // Make a huge inflight so we don't underflow anything
@@ -121,7 +121,7 @@ TEST_F(BbrTest, Recovery) {
TEST_F(BbrTest, StartupCwnd) { TEST_F(BbrTest, StartupCwnd) {
QuicConnectionStateBase conn(QuicNodeType::Client); QuicConnectionStateBase conn(QuicNodeType::Client);
updateUdpSendPacketLen(conn, 1000); conn.udpSendPacketLen = 1000;
BbrCongestionController bbr(conn); BbrCongestionController bbr(conn);
auto mockRttSampler = std::make_unique<MockMinRttSampler>(); auto mockRttSampler = std::make_unique<MockMinRttSampler>();
auto mockBandwidthSampler = std::make_unique<MockBandwidthSampler>(); auto mockBandwidthSampler = std::make_unique<MockBandwidthSampler>();
@@ -147,7 +147,7 @@ TEST_F(BbrTest, StartupCwnd) {
TEST_F(BbrTest, LeaveStartup) { TEST_F(BbrTest, LeaveStartup) {
QuicConnectionStateBase conn(QuicNodeType::Client); QuicConnectionStateBase conn(QuicNodeType::Client);
updateUdpSendPacketLen(conn, 1000); conn.udpSendPacketLen = 1000;
BbrCongestionController bbr(conn); BbrCongestionController bbr(conn);
auto mockBandwidthSampler = std::make_unique<MockBandwidthSampler>(); auto mockBandwidthSampler = std::make_unique<MockBandwidthSampler>();
auto rawBandwidthSampler = mockBandwidthSampler.get(); auto rawBandwidthSampler = mockBandwidthSampler.get();
@@ -203,7 +203,7 @@ TEST_F(BbrTest, LeaveStartup) {
TEST_F(BbrTest, RemoveInflightBytes) { TEST_F(BbrTest, RemoveInflightBytes) {
QuicConnectionStateBase conn(QuicNodeType::Client); QuicConnectionStateBase conn(QuicNodeType::Client);
updateUdpSendPacketLen(conn, 1000); conn.udpSendPacketLen = 1000;
BbrCongestionController bbr(conn); BbrCongestionController bbr(conn);
auto writableBytesAfterInit = bbr.getWritableBytes(); auto writableBytesAfterInit = bbr.getWritableBytes();
bbr.onPacketSent(makeTestingWritePacket(0, 1000, 1000)); bbr.onPacketSent(makeTestingWritePacket(0, 1000, 1000));
@@ -214,7 +214,7 @@ TEST_F(BbrTest, RemoveInflightBytes) {
TEST_F(BbrTest, ProbeRtt) { TEST_F(BbrTest, ProbeRtt) {
QuicConnectionStateBase conn(QuicNodeType::Client); QuicConnectionStateBase conn(QuicNodeType::Client);
updateUdpSendPacketLen(conn, 1000); conn.udpSendPacketLen = 1000;
BbrCongestionController bbr(conn); BbrCongestionController bbr(conn);
auto mockBandwidthSampler = std::make_unique<MockBandwidthSampler>(); auto mockBandwidthSampler = std::make_unique<MockBandwidthSampler>();
auto rawBandwidthSampler = mockBandwidthSampler.get(); auto rawBandwidthSampler = mockBandwidthSampler.get();
@@ -376,7 +376,7 @@ TEST_F(BbrTest, AckAggregation) {
QuicConnectionStateBase conn(QuicNodeType::Client); QuicConnectionStateBase conn(QuicNodeType::Client);
auto qLogger = std::make_shared<FileQLogger>(VantagePoint::Client); auto qLogger = std::make_shared<FileQLogger>(VantagePoint::Client);
conn.qLogger = qLogger; conn.qLogger = qLogger;
updateUdpSendPacketLen(conn, 1000); conn.udpSendPacketLen = 1000;
BbrCongestionController bbr(conn); BbrCongestionController bbr(conn);
auto mockBandwidthSampler = std::make_unique<MockBandwidthSampler>(); auto mockBandwidthSampler = std::make_unique<MockBandwidthSampler>();
auto mockRttSampler = std::make_unique<MockMinRttSampler>(); auto mockRttSampler = std::make_unique<MockMinRttSampler>();

View File

@@ -10,7 +10,6 @@
#include <folly/portability/GTest.h> #include <folly/portability/GTest.h>
#include <quic/QuicConstants.h> #include <quic/QuicConstants.h>
#include <quic/state/QuicStateFunctions.h>
#include <quic/state/StateData.h> #include <quic/state/StateData.h>
using namespace testing; using namespace testing;
@@ -22,7 +21,7 @@ class CongestionControlFunctionsTest : public Test {};
TEST_F(CongestionControlFunctionsTest, CalculatePacingRate) { TEST_F(CongestionControlFunctionsTest, CalculatePacingRate) {
QuicConnectionStateBase conn(QuicNodeType::Client); QuicConnectionStateBase conn(QuicNodeType::Client);
updateUdpSendPacketLen(conn, 1); conn.udpSendPacketLen = 1;
conn.transportSettings.minBurstPackets = 1; conn.transportSettings.minBurstPackets = 1;
conn.transportSettings.pacingTimerTickInterval = 10ms; conn.transportSettings.pacingTimerTickInterval = 10ms;
std::chrono::microseconds rtt(1000 * 100); std::chrono::microseconds rtt(1000 * 100);
@@ -40,7 +39,7 @@ TEST_F(CongestionControlFunctionsTest, CalculatePacingRate) {
TEST_F(CongestionControlFunctionsTest, MinPacingRate) { TEST_F(CongestionControlFunctionsTest, MinPacingRate) {
QuicConnectionStateBase conn(QuicNodeType::Client); QuicConnectionStateBase conn(QuicNodeType::Client);
updateUdpSendPacketLen(conn, 1); conn.udpSendPacketLen = 1;
conn.transportSettings.pacingTimerTickInterval = 1ms; conn.transportSettings.pacingTimerTickInterval = 1ms;
auto result = calculatePacingRate( auto result = calculatePacingRate(
conn, 100, conn.transportSettings.minCwndInMss, 100ms); conn, 100, conn.transportSettings.minCwndInMss, 100ms);
@@ -52,7 +51,7 @@ TEST_F(CongestionControlFunctionsTest, MinPacingRate) {
TEST_F(CongestionControlFunctionsTest, SmallCwnd) { TEST_F(CongestionControlFunctionsTest, SmallCwnd) {
QuicConnectionStateBase conn(QuicNodeType::Client); QuicConnectionStateBase conn(QuicNodeType::Client);
updateUdpSendPacketLen(conn, 1); conn.udpSendPacketLen = 1;
conn.transportSettings.minBurstPackets = 1; conn.transportSettings.minBurstPackets = 1;
conn.transportSettings.pacingTimerTickInterval = 1ms; conn.transportSettings.pacingTimerTickInterval = 1ms;
auto result = calculatePacingRate( auto result = calculatePacingRate(
@@ -63,7 +62,7 @@ TEST_F(CongestionControlFunctionsTest, SmallCwnd) {
TEST_F(CongestionControlFunctionsTest, RttSmallerThanInterval) { TEST_F(CongestionControlFunctionsTest, RttSmallerThanInterval) {
QuicConnectionStateBase conn(QuicNodeType::Client); QuicConnectionStateBase conn(QuicNodeType::Client);
updateUdpSendPacketLen(conn, 1); conn.udpSendPacketLen = 1;
conn.transportSettings.minBurstPackets = 1; conn.transportSettings.minBurstPackets = 1;
conn.transportSettings.pacingTimerTickInterval = 10ms; conn.transportSettings.pacingTimerTickInterval = 10ms;
auto result = auto result =

View File

@@ -19,7 +19,7 @@ class CubicHystartTest : public Test {};
TEST_F(CubicHystartTest, SendAndAck) { TEST_F(CubicHystartTest, SendAndAck) {
QuicConnectionStateBase conn(QuicNodeType::Client); QuicConnectionStateBase conn(QuicNodeType::Client);
updateUdpSendPacketLen(conn, 100); conn.udpSendPacketLen = 100;
Cubic cubic(conn); Cubic cubic(conn);
auto initCwnd = cubic.getWritableBytes(); auto initCwnd = cubic.getWritableBytes();
// Packet 0 is sent: // Packet 0 is sent:
@@ -54,7 +54,7 @@ TEST_F(CubicHystartTest, CwndLargerThanSSThresh) {
TEST_F(CubicHystartTest, NoDelayIncrease) { TEST_F(CubicHystartTest, NoDelayIncrease) {
QuicConnectionStateBase conn(QuicNodeType::Client); QuicConnectionStateBase conn(QuicNodeType::Client);
updateUdpSendPacketLen(conn, 100); conn.udpSendPacketLen = 100;
Cubic cubic(conn); Cubic cubic(conn);
auto initCwnd = cubic.getWritableBytes(); auto initCwnd = cubic.getWritableBytes();
// Packet 0 is sent: // Packet 0 is sent:

View File

@@ -20,7 +20,7 @@ TEST_F(CubicSteadyTest, CubicReduction) {
QuicConnectionStateBase conn(QuicNodeType::Client); QuicConnectionStateBase conn(QuicNodeType::Client);
// initCwnd > initSsthresh: an ack will immediately make the state machine // initCwnd > initSsthresh: an ack will immediately make the state machine
// transit to Steady state: // transit to Steady state:
updateUdpSendPacketLen(conn, 200); // initCwnd = 2000, minCwnd = 400 conn.udpSendPacketLen = 200; // initCwnd = 2000, minCwnd = 400
Cubic cubic(conn, 1000); Cubic cubic(conn, 1000);
// Send one and get acked, this moves the state machine to steady. Cwnd will // Send one and get acked, this moves the state machine to steady. Cwnd will

View File

@@ -115,7 +115,7 @@ TEST_F(CubicTest, CwndIncreaseAfterReduction) {
QuicConnectionStateBase conn(QuicNodeType::Client); QuicConnectionStateBase conn(QuicNodeType::Client);
auto qLogger = std::make_shared<FileQLogger>(VantagePoint::Client); auto qLogger = std::make_shared<FileQLogger>(VantagePoint::Client);
conn.qLogger = qLogger; conn.qLogger = qLogger;
updateUdpSendPacketLen(conn, 200); conn.udpSendPacketLen = 200;
// initCwnd > initSsthresh: an ack will immediately make the state machine // initCwnd > initSsthresh: an ack will immediately make the state machine
// transit to Steady state: // transit to Steady state:
Cubic cubic(conn, 1000); Cubic cubic(conn, 1000);
@@ -178,7 +178,7 @@ TEST_F(CubicTest, AppIdle) {
QuicConnectionStateBase conn(QuicNodeType::Client); QuicConnectionStateBase conn(QuicNodeType::Client);
auto qLogger = std::make_shared<FileQLogger>(VantagePoint::Client); auto qLogger = std::make_shared<FileQLogger>(VantagePoint::Client);
conn.qLogger = qLogger; conn.qLogger = qLogger;
updateUdpSendPacketLen(conn, 1500); conn.udpSendPacketLen = 1500;
TestingCubic cubic(conn); TestingCubic cubic(conn);
cubic.setStateForTest(CubicStates::Steady); cubic.setStateForTest(CubicStates::Steady);
@@ -244,7 +244,7 @@ TEST_F(CubicTest, PacingGain) {
conn.pacer = std::move(mockPacer); conn.pacer = std::move(mockPacer);
auto qLogger = std::make_shared<FileQLogger>(VantagePoint::Client); auto qLogger = std::make_shared<FileQLogger>(VantagePoint::Client);
conn.qLogger = qLogger; conn.qLogger = qLogger;
updateUdpSendPacketLen(conn, 1500); conn.udpSendPacketLen = 1500;
Cubic cubic(conn); Cubic cubic(conn);
conn.lossState.srtt = 3000us; conn.lossState.srtt = 3000us;

View File

@@ -1811,12 +1811,12 @@ TEST_F(QuicClientTransportTest, AddNewPeerAddressSetsPacketSize) {
folly::SocketAddress v4Address("0.0.0.0", 0); folly::SocketAddress v4Address("0.0.0.0", 0);
ASSERT_TRUE(v4Address.getFamily() == AF_INET); ASSERT_TRUE(v4Address.getFamily() == AF_INET);
client->addNewPeerAddress(v4Address); client->addNewPeerAddress(v4Address);
EXPECT_EQ(kDefaultV4UDPSendPacketLen, client->getConn().currentPMTU); EXPECT_EQ(kDefaultV4UDPSendPacketLen, client->getConn().udpSendPacketLen);
folly::SocketAddress v6Address("::", 0); folly::SocketAddress v6Address("::", 0);
ASSERT_TRUE(v6Address.getFamily() == AF_INET6); ASSERT_TRUE(v6Address.getFamily() == AF_INET6);
client->addNewPeerAddress(v6Address); client->addNewPeerAddress(v6Address);
EXPECT_EQ(kDefaultV6UDPSendPacketLen, client->getConn().currentPMTU); EXPECT_EQ(kDefaultV6UDPSendPacketLen, client->getConn().udpSendPacketLen);
client->closeNow(folly::none); client->closeNow(folly::none);
} }

View File

@@ -61,10 +61,9 @@ void QuicServerTransport::setRoutingCallback(
void QuicServerTransport::setOriginalPeerAddress( void QuicServerTransport::setOriginalPeerAddress(
const folly::SocketAddress& addr) { const folly::SocketAddress& addr) {
conn_->originalPeerAddress = addr; conn_->originalPeerAddress = addr;
updateUdpSendPacketLen( conn_->udpSendPacketLen = addr.getFamily() == AF_INET6
*conn_, ? kDefaultV6UDPSendPacketLen
addr.getFamily() == AF_INET6 ? kDefaultV6UDPSendPacketLen : kDefaultV4UDPSendPacketLen;
: kDefaultV4UDPSendPacketLen);
} }
void QuicServerTransport::setServerConnectionIdParams( void QuicServerTransport::setServerConnectionIdParams(

View File

@@ -181,7 +181,7 @@ void processClientInitialParams(
if (*packetSize > kDefaultMaxUDPPayload) { if (*packetSize > kDefaultMaxUDPPayload) {
*packetSize = kDefaultUDPSendPacketLen; *packetSize = kDefaultUDPSendPacketLen;
} }
updateUdpSendPacketLen(conn, *packetSize); conn.udpSendPacketLen = *packetSize;
} }
conn.peerActiveConnectionIdLimit = conn.peerActiveConnectionIdLimit =

View File

@@ -3783,11 +3783,11 @@ TEST_F(
TEST_F(QuicUnencryptedServerTransportTest, MaxReceivePacketSizeTooLarge) { TEST_F(QuicUnencryptedServerTransportTest, MaxReceivePacketSizeTooLarge) {
getFakeHandshakeLayer()->allowZeroRttKeys(); getFakeHandshakeLayer()->allowZeroRttKeys();
auto originalPeerMaxPacketSize = server->getConn().udpSendPacketLen; auto originalUdpSize = server->getConn().udpSendPacketLen;
fakeHandshake->maxRecvPacketSize = 4096; fakeHandshake->maxRecvPacketSize = 4096;
setupClientReadCodec(); setupClientReadCodec();
recvClientHello(); recvClientHello();
EXPECT_NE(originalPeerMaxPacketSize, server->getConn().udpSendPacketLen); EXPECT_NE(originalUdpSize, server->getConn().udpSendPacketLen);
EXPECT_EQ(server->getConn().udpSendPacketLen, kDefaultUDPSendPacketLen); EXPECT_EQ(server->getConn().udpSendPacketLen, kDefaultUDPSendPacketLen);
} }

View File

@@ -208,22 +208,6 @@ void increaseNextPacketNum(
} }
} }
void updatePeerMaxPacketSize(QuicConnectionStateBase& conn, uint64_t size) {
conn.peerMaxPacketSize = size;
conn.udpSendPacketLen = std::min(conn.peerMaxPacketSize, conn.currentPMTU);
}
void updateCurrentPMTU(QuicConnectionStateBase& conn, uint64_t size) {
conn.currentPMTU = size;
conn.udpSendPacketLen = std::min(conn.peerMaxPacketSize, conn.currentPMTU);
}
void updateUdpSendPacketLen(QuicConnectionStateBase& conn, uint64_t size) {
conn.peerMaxPacketSize = size;
conn.currentPMTU = size;
conn.udpSendPacketLen = size;
}
std::deque<OutstandingPacket>::iterator getFirstOutstandingPacket( std::deque<OutstandingPacket>::iterator getFirstOutstandingPacket(
QuicConnectionStateBase& conn, QuicConnectionStateBase& conn,
PacketNumberSpace packetNumberSpace) { PacketNumberSpace packetNumberSpace) {

View File

@@ -55,24 +55,6 @@ void increaseNextPacketNum(
QuicConnectionStateBase& conn, QuicConnectionStateBase& conn,
PacketNumberSpace pnSpace) noexcept; PacketNumberSpace pnSpace) noexcept;
/**
* Update peerMaxPacketSize, will re-calculate udpSendPacketLen
*/
void updatePeerMaxPacketSize(QuicConnectionStateBase& conn, uint64_t size);
/**
* Update currPMTU, will re-calculate udpSendPacketLen
*/
void updateCurrentPMTU(QuicConnectionStateBase& conn, uint64_t size);
/**
* Update the actual maximum udp packet length, this will set both
* peerMaxPacketSize and PMTU to the same value.
* This is useful for initialization when setting peer socket address and
* testing.
*/
void updateUdpSendPacketLen(QuicConnectionStateBase& conn, uint64_t size);
/** /**
* Update largestReceivedPacketNum in ackState with packetNum. Return if the * Update largestReceivedPacketNum in ackState with packetNum. Return if the
* current packetNum is received out of order. * current packetNum is received out of order.

View File

@@ -728,15 +728,8 @@ struct QuicConnectionStateBase : public folly::DelayedDestruction {
// until the handshake sets the timeout. // until the handshake sets the timeout.
std::chrono::milliseconds peerIdleTimeout{kMaxIdleTimeout}; std::chrono::milliseconds peerIdleTimeout{kMaxIdleTimeout};
// The max_packet_size Transport Parameters // The max UDP packet size we will be sending, limited by both the received
uint64_t peerMaxPacketSize{kDefaultUDPSendPacketLen}; // max_packet_size in Transport Parameters and PMTU
// Current PMTU, which may change as d6d discovers new PMTU on the path
uint64_t currentPMTU{kDefaultUDPSendPacketLen};
// The effective max UDP packet size we will be sending, limited by both the
// received max_packet_size in Transport Parameters and PMTU. Should not be
// set directly, use setUDPSendPacketLen()
uint64_t udpSendPacketLen{kDefaultUDPSendPacketLen}; uint64_t udpSendPacketLen{kDefaultUDPSendPacketLen};
struct PacketSchedulingState { struct PacketSchedulingState {

View File

@@ -87,7 +87,7 @@ TEST_F(PendingPathRateLimiterTest, TestSetInitialCredit) {
EXPECT_EQ( EXPECT_EQ(
limiter_.currentCredit(now, std::chrono::microseconds{kRtt}), limiter_.currentCredit(now, std::chrono::microseconds{kRtt}),
maxWindowBytes); maxWindowBytes);
updateUdpSendPacketLen(conn_, 2000); conn_.udpSendPacketLen = 2000;
PendingPathRateLimiter limiter2{conn_.udpSendPacketLen}; PendingPathRateLimiter limiter2{conn_.udpSendPacketLen};
EXPECT_EQ( EXPECT_EQ(
limiter2.currentCredit(now, std::chrono::microseconds{kRtt}), limiter2.currentCredit(now, std::chrono::microseconds{kRtt}),