You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by sc...@apache.org on 2018/04/12 12:43:31 UTC

[trafficserver] branch quic-latest updated: QUIC: make ack creator derive from QUICFrameGenerator

This is an automated email from the ASF dual-hosted git repository.

scw00 pushed a commit to branch quic-latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/quic-latest by this push:
     new 13fd149  QUIC: make ack creator derive from QUICFrameGenerator
13fd149 is described below

commit 13fd1491205d3d3f00f59c59feab7e593dfccee6
Author: scw00 <sc...@apache.org>
AuthorDate: Thu Apr 12 19:17:07 2018 +0800

    QUIC: make ack creator derive from QUICFrameGenerator
---
 iocore/net/QUICNetVConnection.cc                 |  8 +++---
 iocore/net/quic/QUICAckFrameCreator.cc           | 31 +++++++++++++-----------
 iocore/net/quic/QUICAckFrameCreator.h            | 22 ++++++++++-------
 iocore/net/quic/test/test_QUICAckFrameCreator.cc | 29 +++++++++++++---------
 4 files changed, 53 insertions(+), 37 deletions(-)

diff --git a/iocore/net/QUICNetVConnection.cc b/iocore/net/QUICNetVConnection.cc
index 91f579c..0f33a84 100644
--- a/iocore/net/QUICNetVConnection.cc
+++ b/iocore/net/QUICNetVConnection.cc
@@ -1148,9 +1148,11 @@ QUICNetVConnection::_packetize_frames()
 
   // ACK
   if (will_be_ack_only) {
-    frame = this->_ack_frame_creator.create_if_needed();
+    if (this->_ack_frame_creator.will_generate_frame()) {
+      frame = this->_ack_frame_creator.generate_frame(UINT16_MAX, this->_maximum_stream_frame_data_size());
+    }
   } else {
-    frame = this->_ack_frame_creator.create();
+    frame = this->_ack_frame_creator.generate_frame(UINT16_MAX, this->_maximum_stream_frame_data_size());
   }
   if (frame != nullptr) {
     ++frame_count;
@@ -1240,7 +1242,7 @@ QUICNetVConnection::_packetize_closing_frame()
     return;
   }
 
-  QUICFrameUPtr frame = QUICFrameFactory::create_null_ack_frame();
+  QUICFrameUPtr frame = QUICFrameFactory::create_null_frame();
   if (this->_connection_error->cls == QUICErrorClass::APPLICATION) {
     frame = QUICFrameFactory::create_application_close_frame(std::move(this->_connection_error));
   } else {
diff --git a/iocore/net/quic/QUICAckFrameCreator.cc b/iocore/net/quic/QUICAckFrameCreator.cc
index ab9de24..45792eb 100644
--- a/iocore/net/quic/QUICAckFrameCreator.cc
+++ b/iocore/net/quic/QUICAckFrameCreator.cc
@@ -48,10 +48,10 @@ QUICAckFrameCreator::update(QUICPacketNumber packet_number, bool protection, boo
   return 0;
 }
 
-std::unique_ptr<QUICAckFrame, QUICFrameDeleterFunc>
-QUICAckFrameCreator::create()
+QUICFrameUPtr
+QUICAckFrameCreator::_create_frame()
 {
-  std::unique_ptr<QUICAckFrame, QUICFrameDeleterFunc> ack_frame = QUICFrameFactory::create_null_ack_frame();
+  QUICFrameUPtr ack_frame = QUICFrameFactory::create_null_frame();
   if (this->_can_send) {
     ack_frame           = this->_create_ack_frame();
     this->_can_send     = false;
@@ -63,23 +63,13 @@ QUICAckFrameCreator::create()
   return ack_frame;
 }
 
-std::unique_ptr<QUICAckFrame, QUICFrameDeleterFunc>
-QUICAckFrameCreator::create_if_needed()
-{
-  std::unique_ptr<QUICAckFrame, QUICFrameDeleterFunc> ack_frame = QUICFrameFactory::create_null_ack_frame();
-  if (this->_should_send) {
-    ack_frame = this->create();
-  }
-  return ack_frame;
-}
-
 void
 QUICAckFrameCreator::_sort_packet_numbers()
 {
   // TODO Find more smart way
 }
 
-std::unique_ptr<QUICAckFrame, QUICFrameDeleterFunc>
+QUICFrameUPtr
 QUICAckFrameCreator::_create_ack_frame()
 {
   std::unique_ptr<QUICAckFrame, QUICFrameDeleterFunc> ack_frame = QUICFrameFactory::create_null_ack_frame();
@@ -126,6 +116,19 @@ QUICAckFrameCreator::_create_ack_frame()
   return ack_frame;
 }
 
+bool
+QUICAckFrameCreator::will_generate_frame()
+{
+  return this->_should_send;
+}
+
+QUICFrameUPtr
+QUICAckFrameCreator::generate_frame(uint16_t connection_credit, uint16_t maximum_frame_size)
+{
+  // FIXME fix size
+  return this->_create_frame();
+}
+
 uint64_t
 QUICAckFrameCreator::_calculate_delay()
 {
diff --git a/iocore/net/quic/QUICAckFrameCreator.h b/iocore/net/quic/QUICAckFrameCreator.h
index 088d574..d474aad 100644
--- a/iocore/net/quic/QUICAckFrameCreator.h
+++ b/iocore/net/quic/QUICAckFrameCreator.h
@@ -24,6 +24,7 @@
 #pragma once
 
 #include "ts/ink_hrtime.h"
+#include "QUICFrameGenerator.h"
 #include "QUICTypes.h"
 #include "QUICFrame.h"
 #include <vector>
@@ -51,7 +52,7 @@ private:
   std::vector<QUICPacketNumber> _packet_numbers;
 };
 
-class QUICAckFrameCreator
+class QUICAckFrameCreator : public QUICFrameGenerator
 {
 public:
   static constexpr int MAXIMUM_PACKET_COUNT = 256;
@@ -64,19 +65,22 @@ public:
   int update(QUICPacketNumber packet_number, bool protection, bool should_send);
 
   /*
-   * Returns QUICAckFrame only if ACK frame is able to be sent.
-   * Caller must send the ACK frame to the peer if it was returned.
+   * Returns true only if should send ack.
    */
-  std::unique_ptr<QUICAckFrame, QUICFrameDeleterFunc> create();
+  bool will_generate_frame() override;
 
   /*
-   * Returns QUICAckFrame only if ACK frame need to be sent,
-   * because sending an ACK only packet against an ACK only packet is prohibited.
-   * Caller must send the ACK frame to the peer if it was returned.
+   * Calls create directly.
    */
-  std::unique_ptr<QUICAckFrame, QUICFrameDeleterFunc> create_if_needed();
+  QUICFrameUPtr generate_frame(uint16_t connection_credit, uint16_t maximum_frame_size) override;
 
 private:
+  /*
+   * Returns QUICAckFrame only if ACK frame is able to be sent.
+   * Caller must send the ACK frame to the peer if it was returned.
+   */
+  QUICFrameUPtr _create_frame();
+
   bool _can_send    = false;
   bool _should_send = false;
 
@@ -85,6 +89,6 @@ private:
   std::set<QUICPacketNumber> _unprotected_packets;
 
   void _sort_packet_numbers();
-  std::unique_ptr<QUICAckFrame, QUICFrameDeleterFunc> _create_ack_frame();
+  QUICFrameUPtr _create_ack_frame();
   uint64_t _calculate_delay();
 };
diff --git a/iocore/net/quic/test/test_QUICAckFrameCreator.cc b/iocore/net/quic/test/test_QUICAckFrameCreator.cc
index a19851e..b044c5a 100644
--- a/iocore/net/quic/test/test_QUICAckFrameCreator.cc
+++ b/iocore/net/quic/test/test_QUICAckFrameCreator.cc
@@ -29,21 +29,23 @@
 TEST_CASE("QUICAckFrameCreator", "[quic]")
 {
   QUICAckFrameCreator creator;
-  std::unique_ptr<QUICAckFrame, QUICFrameDeleterFunc> frame = {nullptr, nullptr};
 
   // Initial state
-  frame = creator.create();
+  std::shared_ptr<QUICFrame> ack_frame = creator.generate_frame(UINT16_MAX, UINT16_MAX);
+  std::shared_ptr<QUICAckFrame> frame  = std::static_pointer_cast<QUICAckFrame>(ack_frame);
   CHECK(frame == nullptr);
 
   // One packet
   creator.update(1, false, true);
-  frame = creator.create();
+  ack_frame = creator.generate_frame(UINT16_MAX, UINT16_MAX);
+  frame     = std::static_pointer_cast<QUICAckFrame>(ack_frame);
   CHECK(frame != nullptr);
   CHECK(frame->ack_block_count() == 0);
   CHECK(frame->largest_acknowledged() == 1);
   CHECK(frame->ack_block_section()->first_ack_block() == 0);
 
-  frame = creator.create();
+  ack_frame = creator.generate_frame(UINT16_MAX, UINT16_MAX);
+  frame     = std::static_pointer_cast<QUICAckFrame>(ack_frame);
   CHECK(frame == nullptr);
 
   // Not sequential
@@ -51,7 +53,8 @@ TEST_CASE("QUICAckFrameCreator", "[quic]")
   creator.update(5, false, true);
   creator.update(3, false, true);
   creator.update(4, false, true);
-  frame = creator.create();
+  ack_frame = creator.generate_frame(UINT16_MAX, UINT16_MAX);
+  frame     = std::static_pointer_cast<QUICAckFrame>(ack_frame);
   CHECK(frame != nullptr);
   CHECK(frame->ack_block_count() == 0);
   CHECK(frame->largest_acknowledged() == 5);
@@ -61,7 +64,8 @@ TEST_CASE("QUICAckFrameCreator", "[quic]")
   creator.update(6, false, true);
   creator.update(7, false, true);
   creator.update(10, false, true);
-  frame = creator.create();
+  ack_frame = creator.generate_frame(UINT16_MAX, UINT16_MAX);
+  frame     = std::static_pointer_cast<QUICAckFrame>(ack_frame);
   CHECK(frame != nullptr);
   CHECK(frame->ack_block_count() == 1);
   CHECK(frame->largest_acknowledged() == 10);
@@ -72,10 +76,10 @@ TEST_CASE("QUICAckFrameCreator", "[quic]")
 TEST_CASE("QUICAckFrameCreator_loss_recover", "[quic]")
 {
   QUICAckFrameCreator creator;
-  std::unique_ptr<QUICAckFrame, QUICFrameDeleterFunc> frame = {nullptr, nullptr};
 
   // Initial state
-  frame = creator.create();
+  std::shared_ptr<QUICFrame> ack_frame = creator.generate_frame(UINT16_MAX, UINT16_MAX);
+  std::shared_ptr<QUICAckFrame> frame  = std::static_pointer_cast<QUICAckFrame>(ack_frame);
   CHECK(frame == nullptr);
 
   creator.update(2, false, true);
@@ -84,19 +88,22 @@ TEST_CASE("QUICAckFrameCreator_loss_recover", "[quic]")
   creator.update(8, false, true);
   creator.update(9, false, true);
 
-  frame = creator.create();
+  ack_frame = creator.generate_frame(UINT16_MAX, UINT16_MAX);
+  frame     = std::static_pointer_cast<QUICAckFrame>(ack_frame);
   CHECK(frame != nullptr);
   CHECK(frame->ack_block_count() == 2);
   CHECK(frame->largest_acknowledged() == 9);
   CHECK(frame->ack_block_section()->first_ack_block() == 1);
   CHECK(frame->ack_block_section()->begin()->gap() == 0);
 
-  frame = creator.create();
+  ack_frame = creator.generate_frame(UINT16_MAX, UINT16_MAX);
+  frame     = std::static_pointer_cast<QUICAckFrame>(ack_frame);
   CHECK(frame == nullptr);
 
   creator.update(7, false, true);
   creator.update(4, false, true);
-  frame = creator.create();
+  ack_frame = creator.generate_frame(UINT16_MAX, UINT16_MAX);
+  frame     = std::static_pointer_cast<QUICAckFrame>(ack_frame);
   CHECK(frame != nullptr);
   CHECK(frame->ack_block_count() == 1);
   CHECK(frame->largest_acknowledged() == 7);

-- 
To stop receiving notification emails like this one, please contact
scw00@apache.org.