Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions envoy/network/udp_packet_writer_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ class UdpPacketWriterFactory {
* @param socket UDP socket used to send packets.
* @return the UdpPacketWriter created.
*/
virtual UdpPacketWriterPtr createUdpPacketWriter(Network::IoHandle& io_handle,
Stats::Scope& scope) PURE;
virtual UdpPacketWriterPtr
createUdpPacketWriter(Network::IoHandle& io_handle, Stats::Scope& scope,
Envoy::Event::Dispatcher& dispatcher,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comments for the new parameters (dispacter is pretty obvious, but on_can_write_cb is less so)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added comments for new params and updated existing comments because the "socket" param is outdated

absl::AnyInvocable<void() &&> on_can_write_cb) PURE;
};

using UdpPacketWriterFactoryPtr = std::unique_ptr<UdpPacketWriterFactory>;
Expand Down
5 changes: 3 additions & 2 deletions source/common/network/udp_packet_writer_handler_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ class UdpDefaultWriter : public UdpPacketWriter {

class UdpDefaultWriterFactory : public Network::UdpPacketWriterFactory {
public:
Network::UdpPacketWriterPtr createUdpPacketWriter(Network::IoHandle& io_handle,
Stats::Scope&) override {
Network::UdpPacketWriterPtr createUdpPacketWriter(Network::IoHandle& io_handle, Stats::Scope&,
Envoy::Event::Dispatcher&,
absl::AnyInvocable<void() &&>) override {
return std::make_unique<UdpDefaultWriter>(io_handle);
}
};
Expand Down
5 changes: 4 additions & 1 deletion source/common/quic/active_quic_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,13 @@ ActiveQuicListener::ActiveQuicListener(
per_worker_stats_, dispatcher, listen_socket_, quic_stat_names, crypto_server_stream_factory_,
*connection_id_generator_, debug_visitor_factory);

absl::AnyInvocable<void() &&> on_can_write_cb = [&]() { quic_dispatcher_->OnCanWrite(); };

// Create udp_packet_writer
Network::UdpPacketWriterPtr udp_packet_writer =
listener_config.udpListenerConfig()->packetWriterFactory().createUdpPacketWriter(
listen_socket_.ioHandle(), listener_config.listenerScope());
listen_socket_.ioHandle(), listener_config.listenerScope(), dispatcher,
std::move(on_can_write_cb));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have missed it, but do we have a unit test which ensures that this CB is sent correctly to the writer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't have a unit test for the cb because this change is interface only, the concrete implementation using the cb will come in followup cl.

udp_packet_writer_ = udp_packet_writer.get();

// Some packet writers (like `UdpGsoBatchWriter`) already directly implement
Expand Down
4 changes: 3 additions & 1 deletion source/common/quic/udp_gso_batch_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ UdpGsoBatchWriterStats UdpGsoBatchWriter::generateStats(Stats::Scope& scope) {
}

Network::UdpPacketWriterPtr
UdpGsoBatchWriterFactory::createUdpPacketWriter(Network::IoHandle& io_handle, Stats::Scope& scope) {
UdpGsoBatchWriterFactory::createUdpPacketWriter(Network::IoHandle& io_handle, Stats::Scope& scope,
Envoy::Event::Dispatcher&,
absl::AnyInvocable<void() &&>) {
return std::make_unique<UdpGsoBatchWriter>(io_handle, scope);
}

Expand Down
6 changes: 4 additions & 2 deletions source/common/quic/udp_gso_batch_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ class UdpGsoBatchWriter : public quic::QuicGsoBatchWriter, public Network::UdpPa

class UdpGsoBatchWriterFactory : public Network::UdpPacketWriterFactory {
public:
Network::UdpPacketWriterPtr createUdpPacketWriter(Network::IoHandle& io_handle,
Stats::Scope& scope) override;
Network::UdpPacketWriterPtr
createUdpPacketWriter(Network::IoHandle& io_handle, Stats::Scope& scope,
Envoy::Event::Dispatcher& dispatcher,
absl::AnyInvocable<void() &&> on_can_write_cb) override;

private:
envoy::config::core::v3::RuntimeFeatureFlag enabled_;
Expand Down
3 changes: 2 additions & 1 deletion source/server/active_udp_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ ActiveRawUdpListener::ActiveRawUdpListener(uint32_t worker_index, uint32_t concu

// Create udp_packet_writer
udp_packet_writer_ = config_->udpListenerConfig()->packetWriterFactory().createUdpPacketWriter(
listen_socket_.ioHandle(), config.listenerScope());
listen_socket_.ioHandle(), config.listenerScope(), /*dispatcher=*/udp_listener_->dispatcher(),
/*on_can_write_cb=*/[]() {});
}

void ActiveRawUdpListener::onDataWorker(Network::UdpRecvData&& data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ TEST_P(ListenerManagerImplQuicOnlyTest, QuicListenerFactoryAndSslContext) {
.udpListenerConfig()
->packetWriterFactory()
.createUdpPacketWriter(listen_socket->ioHandle(),
manager_->listeners()[0].get().listenerScope());
manager_->listeners()[0].get().listenerScope(),
server_.dispatcher_, []() {});
EXPECT_EQ(udp_packet_writer->isBatchMode(), Api::OsSysCallsSingleton::get().supportsUdpGso());

// No filter chain found with non-matching transport protocol.
Expand Down Expand Up @@ -267,7 +268,8 @@ TEST_P(ListenerManagerImplQuicOnlyTest, QuicWriterFromConfig) {
Network::UdpPacketWriterFactory& udp_packet_writer_factory =
manager_->listeners().front().get().udpListenerConfig()->packetWriterFactory();
Network::UdpPacketWriterPtr udp_packet_writer = udp_packet_writer_factory.createUdpPacketWriter(
listen_socket->ioHandle(), manager_->listeners()[0].get().listenerScope());
listen_socket->ioHandle(), manager_->listeners()[0].get().listenerScope(),
server_.dispatcher_, []() {});
// Even though GSO is enabled, the default writer should be used.
EXPECT_EQ(false, udp_packet_writer->isBatchMode());
}
Expand Down
3 changes: 2 additions & 1 deletion test/common/listener_manager/listener_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8237,7 +8237,8 @@ TEST_P(ListenerManagerImplTest, UdpDefaultWriterConfig) {
.udpListenerConfig()
->packetWriterFactory()
.createUdpPacketWriter(listen_socket->ioHandle(),
manager_->listeners()[0].get().listenerScope());
manager_->listeners()[0].get().listenerScope(),
server_.dispatcher_, []() {});
EXPECT_FALSE(udp_packet_writer->isBatchMode());
}

Expand Down
7 changes: 4 additions & 3 deletions test/common/quic/active_quic_listener_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ class ActiveQuicListenerTest : public testing::TestWithParam<Network::Address::I
.WillByDefault(Return(Network::UdpListenerConfigOptRef(udp_listener_config_)));
ON_CALL(udp_listener_config_, packetWriterFactory())
.WillByDefault(ReturnRef(udp_packet_writer_factory_));
ON_CALL(udp_packet_writer_factory_, createUdpPacketWriter(_, _))
.WillByDefault(Invoke(
[&](Network::IoHandle& io_handle, Stats::Scope& scope) -> Network::UdpPacketWriterPtr {
ON_CALL(udp_packet_writer_factory_, createUdpPacketWriter(_, _, _, _))
.WillByDefault(
Invoke([&](Network::IoHandle& io_handle, Stats::Scope& scope, Envoy::Event::Dispatcher&,
absl::AnyInvocable<void()&&>) -> Network::UdpPacketWriterPtr {
#if UDP_GSO_BATCH_WRITER_COMPILETIME_SUPPORT
return std::make_unique<Quic::UdpGsoBatchWriter>(io_handle, scope);
#else
Expand Down
4 changes: 3 additions & 1 deletion test/mocks/network/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,9 @@ class MockUdpPacketWriterFactory : public UdpPacketWriterFactory {
MockUdpPacketWriterFactory() = default;

MOCK_METHOD(Network::UdpPacketWriterPtr, createUdpPacketWriter,
(Network::IoHandle&, Stats::Scope&), ());
(Network::IoHandle&, Stats::Scope&, Envoy::Event::Dispatcher&,
absl::AnyInvocable<void() &&>),
());
};

class MockUdpListenerConfig : public UdpListenerConfig {
Expand Down
7 changes: 4 additions & 3 deletions test/server/active_udp_listener_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ class ActiveUdpListenerTest : public testing::TestWithParam<Network::Address::Ip
EXPECT_CALL(listener_config_, filterChainFactory());
ON_CALL(*udp_listener_config_, packetWriterFactory())
.WillByDefault(ReturnRef(udp_packet_writer_factory_));
ON_CALL(udp_packet_writer_factory_, createUdpPacketWriter(_, _))
.WillByDefault(Invoke(
[&](Network::IoHandle& io_handle, Stats::Scope& scope) -> Network::UdpPacketWriterPtr {
ON_CALL(udp_packet_writer_factory_, createUdpPacketWriter(_, _, _, _))
.WillByDefault(
Invoke([&](Network::IoHandle& io_handle, Stats::Scope& scope, Envoy::Event::Dispatcher&,
absl::AnyInvocable<void()&&>) -> Network::UdpPacketWriterPtr {
#if UDP_GSO_BATCH_WRITER_COMPILETIME_SUPPORT
return std::make_unique<Quic::UdpGsoBatchWriter>(io_handle, scope);
#else
Expand Down
Loading