trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mas...@apache.org
Subject [trafficserver] branch quic-latest updated: Use shortest stream id length
Date Wed, 13 Sep 2017 02:14:53 GMT
This is an automated email from the ASF dual-hosted git repository.

maskit 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 581151a  Use shortest stream id length
581151a is described below

commit 581151aaf5c55e9c47fcfc3f99ed0cd9b458aa84
Author: Masakazu Kitajo <maskit@apache.org>
AuthorDate: Wed Sep 13 11:12:25 2017 +0900

    Use shortest stream id length
---
 iocore/net/quic/QUICFrame.cc           | 15 ++++++++---
 iocore/net/quic/test/test_QUICFrame.cc | 49 ++++++++++++++++++++++++++++++----
 2 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/iocore/net/quic/QUICFrame.cc b/iocore/net/quic/QUICFrame.cc
index 6a07641..4baa551 100644
--- a/iocore/net/quic/QUICFrame.cc
+++ b/iocore/net/quic/QUICFrame.cc
@@ -116,9 +116,18 @@ QUICStreamFrame::store(uint8_t *buf, size_t *len, bool include_length_field)
con
   }
 
   // "SS" of "11FSSOOD"
-  // use 32 bit length for now
-  buf[0] += (0x03 << 3);
-  QUICTypeUtil::write_QUICStreamId(this->stream_id(), 4, buf + *len, &n);
+  uint8_t stream_id_width = 0;
+  if (this->_stream_id > 0xFFFFFF) {
+    stream_id_width = 4;
+  } else if (this->_stream_id > 0xFFFF) {
+    stream_id_width = 3;
+  } else if (this->_stream_id > 0xFF) {
+    stream_id_width = 2;
+  } else {
+    stream_id_width = 1;
+  }
+  buf[0] += ((stream_id_width - 1) << 3);
+  QUICTypeUtil::write_QUICStreamId(this->stream_id(), stream_id_width, buf + *len, &n);
   *len += n;
 
   // "OO" of "11FSSOOD"
diff --git a/iocore/net/quic/test/test_QUICFrame.cc b/iocore/net/quic/test/test_QUICFrame.cc
index 207664d..c630007 100644
--- a/iocore/net/quic/test/test_QUICFrame.cc
+++ b/iocore/net/quic/test/test_QUICFrame.cc
@@ -110,18 +110,57 @@ TEST_CASE("Store STREAM Frame", "[quic]")
   uint8_t buf[65535];
   size_t len;
 
+  // 8bit stream id, 64bit offset
+  uint8_t expected1[] = {
+    0xC7,                                           // 11FSSOOD
+    0x01,                                           // Stream ID
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Offset
+    0x00, 0x05,                                     // Data Length
+    0x01, 0x02, 0x03, 0x04, 0x05,                   // Stream Data
+  };
+  QUICStreamFrame streamFrame1(reinterpret_cast<const uint8_t *>("\x01\x02\x03\x04\x05"),
5, 0x01, 0x00);
+  streamFrame1.store(buf, &len);
+  CHECK(len == 17);
+  CHECK(memcmp(buf, expected1, len) == 0);
+
+  // 16bit stream id, 64bit offset
+  uint8_t expected2[] = {
+    0xCF,                                           // 11FSSOOD
+    0x01, 0x00,                                     // Stream ID
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Offset
+    0x00, 0x05,                                     // Data Length
+    0x01, 0x02, 0x03, 0x04, 0x05,                   // Stream Data
+  };
+  QUICStreamFrame streamFrame2(reinterpret_cast<const uint8_t *>("\x01\x02\x03\x04\x05"),
5, 0x0100, 0x00);
+  streamFrame2.store(buf, &len);
+  CHECK(len == 18);
+  CHECK(memcmp(buf, expected2, len) == 0);
+
+  // 24bit stream id, 64bit offset
+  uint8_t expected3[] = {
+    0xD7,                                           // 11FSSOOD
+    0x01, 0x00, 0x00,                               // Stream ID
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Offset
+    0x00, 0x05,                                     // Data Length
+    0x01, 0x02, 0x03, 0x04, 0x05,                   // Stream Data
+  };
+  QUICStreamFrame streamFrame3(reinterpret_cast<const uint8_t *>("\x01\x02\x03\x04\x05"),
5, 0x010000, 0x00);
+  streamFrame3.store(buf, &len);
+  CHECK(len == 19);
+  CHECK(memcmp(buf, expected3, len) == 0);
+
   // 32bit stream id, 64bit offset
-  uint8_t expected[] = {
+  uint8_t expected4[] = {
     0xDF,                                           // 11FSSOOD
-    0x00, 0x00, 0x00, 0x01,                         // Stream ID
+    0x01, 0x00, 0x00, 0x00,                         // Stream ID
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Offset
     0x00, 0x05,                                     // Data Length
     0x01, 0x02, 0x03, 0x04, 0x05,                   // Stream Data
   };
-  QUICStreamFrame streamFrame(reinterpret_cast<const uint8_t *>("\x01\x02\x03\x04\x05"),
5, 0x01, 0x00);
-  streamFrame.store(buf, &len);
+  QUICStreamFrame streamFrame4(reinterpret_cast<const uint8_t *>("\x01\x02\x03\x04\x05"),
5, 0x01000000, 0x00);
+  streamFrame4.store(buf, &len);
   CHECK(len == 20);
-  CHECK(memcmp(buf, expected, len) == 0);
+  CHECK(memcmp(buf, expected4, len) == 0);
 }
 
 TEST_CASE("Load Ack Frame 1", "[quic]")

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>'].

Mime
View raw message