You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ma...@apache.org on 2018/09/11 03:23:16 UTC

[trafficserver] branch quic-latest updated: [draft-13] Add QUICTransportParameterId::DISABLE_MIGRATION

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

masaori 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 38a1771  [draft-13] Add QUICTransportParameterId::DISABLE_MIGRATION
38a1771 is described below

commit 38a177115e38e83b25c03274025487a2ac47dcec
Author: Masaori Koshiba <ma...@apache.org>
AuthorDate: Tue Sep 11 12:20:49 2018 +0900

    [draft-13] Add QUICTransportParameterId::DISABLE_MIGRATION
---
 iocore/net/quic/QUICDebugNames.cc                  |   2 +
 iocore/net/quic/QUICTransportParameters.cc         |  14 +++
 iocore/net/quic/QUICTransportParameters.h          |   4 +-
 .../net/quic/test/test_QUICTransportParameters.cc  | 133 +++++++++++++++++----
 4 files changed, 127 insertions(+), 26 deletions(-)

diff --git a/iocore/net/quic/QUICDebugNames.cc b/iocore/net/quic/QUICDebugNames.cc
index 44f13eb..567266b 100644
--- a/iocore/net/quic/QUICDebugNames.cc
+++ b/iocore/net/quic/QUICDebugNames.cc
@@ -191,6 +191,8 @@ QUICDebugNames::transport_parameter_id(QUICTransportParameterId id)
     return "ACK_DELAY_EXPONENT";
   case QUICTransportParameterId::INITIAL_MAX_UNI_STREAMS:
     return "INITIAL_MAX_UNI_STREAMS";
+  case QUICTransportParameterId::DISABLE_MIGRATION:
+    return "DISABLE_MIGRATION";
   default:
     return "UNKNOWN";
   }
diff --git a/iocore/net/quic/QUICTransportParameters.cc b/iocore/net/quic/QUICTransportParameters.cc
index de7382f..6797ab6 100644
--- a/iocore/net/quic/QUICTransportParameters.cc
+++ b/iocore/net/quic/QUICTransportParameters.cc
@@ -201,6 +201,12 @@ QUICTransportParameters::_validate_parameters() const
     }
   }
 
+  if ((ite = this->_parameters.find(QUICTransportParameterId::DISABLE_MIGRATION)) != this->_parameters.end()) {
+    if (ite->second->len() != 0) {
+      return -6;
+    }
+  }
+
   return 0;
 }
 
@@ -253,6 +259,14 @@ QUICTransportParameters::getAsUInt32(QUICTransportParameterId tpid) const
   }
 }
 
+bool
+QUICTransportParameters::contains(QUICTransportParameterId id) const
+{
+  // Use std::map::contains when C++20 is supported
+  auto p = this->_parameters.find(id);
+  return (p != this->_parameters.end());
+}
+
 void
 QUICTransportParameters::set(QUICTransportParameterId id, const uint8_t *value, uint16_t value_len)
 {
diff --git a/iocore/net/quic/QUICTransportParameters.h b/iocore/net/quic/QUICTransportParameters.h
index 577478e..aef3b69 100644
--- a/iocore/net/quic/QUICTransportParameters.h
+++ b/iocore/net/quic/QUICTransportParameters.h
@@ -42,7 +42,8 @@ public:
     MAX_PACKET_SIZE,
     STATELESS_RESET_TOKEN,
     ACK_DELAY_EXPONENT,
-    INITIAL_MAX_UNI_STREAMS
+    INITIAL_MAX_UNI_STREAMS,
+    DISABLE_MIGRATION,
   };
 
   explicit operator bool() const { return true; }
@@ -78,6 +79,7 @@ public:
   uint8_t getAsUInt8(QUICTransportParameterId id) const;
   uint16_t getAsUInt16(QUICTransportParameterId id) const;
   uint32_t getAsUInt32(QUICTransportParameterId id) const;
+  bool contains(QUICTransportParameterId id) const;
 
   void set(QUICTransportParameterId id, const uint8_t *value, uint16_t value_len);
   void set(QUICTransportParameterId id, uint16_t value);
diff --git a/iocore/net/quic/test/test_QUICTransportParameters.cc b/iocore/net/quic/test/test_QUICTransportParameters.cc
index 9dff13c..4053ed2 100644
--- a/iocore/net/quic/test/test_QUICTransportParameters.cc
+++ b/iocore/net/quic/test/test_QUICTransportParameters.cc
@@ -174,6 +174,49 @@ TEST_CASE("QUICTransportParametersInEncryptedExtensions_read", "[quic]")
     data = params_in_ee.getAsBytes(QUICTransportParameterId::STATELESS_RESET_TOKEN, len);
     CHECK(len == 16);
     CHECK(memcmp(data, buf + 37, 16) == 0);
+
+    CHECK(!params_in_ee.contains(QUICTransportParameterId::DISABLE_MIGRATION));
+  }
+
+  SECTION("OK case - zero length value")
+  {
+    uint8_t buf[] = {
+      0x01, 0x02, 0x03, 0x04, // negotiated version
+      0x04,                   // size of supported versions
+      0x01, 0x02, 0x03, 0x04, //
+      0x00, 0x1a,             // size of parameters
+      0x00, 0x00,             // parameter id
+      0x00, 0x04,             // length of value
+      0x11, 0x22, 0x33, 0x44, // value
+      0x00, 0x01,             // parameter id
+      0x00, 0x04,             // length of value
+      0x12, 0x34, 0x56, 0x78, // value
+      0x00, 0x03,             // parameter id
+      0x00, 0x02,             // length of value
+      0x01, 0x23,             // value
+      0x00, 0x09,             // parameter id
+      0x00, 0x00,             // length of value
+    };
+
+    QUICTransportParametersInEncryptedExtensions params_in_ee(buf, sizeof(buf));
+    CHECK(params_in_ee.is_valid());
+
+    uint16_t len        = 0;
+    const uint8_t *data = nullptr;
+
+    data = params_in_ee.getAsBytes(QUICTransportParameterId::INITIAL_MAX_STREAM_DATA, len);
+    CHECK(len == 4);
+    CHECK(memcmp(data, "\x11\x22\x33\x44", 4) == 0);
+
+    data = params_in_ee.getAsBytes(QUICTransportParameterId::INITIAL_MAX_DATA, len);
+    CHECK(len == 4);
+    CHECK(memcmp(data, "\x12\x34\x56\x78", 4) == 0);
+
+    data = params_in_ee.getAsBytes(QUICTransportParameterId::IDLE_TIMEOUT, len);
+    CHECK(len == 2);
+    CHECK(memcmp(data, "\x01\x23", 2) == 0);
+
+    CHECK(params_in_ee.contains(QUICTransportParameterId::DISABLE_MIGRATION));
   }
 
   SECTION("Duplicate parameters")
@@ -198,34 +241,74 @@ TEST_CASE("QUICTransportParametersInEncryptedExtensions_read", "[quic]")
 
 TEST_CASE("QUICTransportParametersEncryptedExtensions_write", "[quic]")
 {
-  uint8_t buf[65536];
-  uint16_t len;
+  SECTION("OK cases")
+  {
+    uint8_t buf[65536];
+    uint16_t len;
 
-  uint8_t expected[] = {
-    0x01, 0x02, 0x03, 0x04, // negotiated version
-    0x08,                   // size of supported versions
-    0x01, 0x02, 0x03, 0x04, // version 1
-    0x05, 0x06, 0x07, 0x08, // version 2
-    0x00, 0x0e,             // size of parameters
-    0x00, 0x00,             // parameter id
-    0x00, 0x04,             // length of value
-    0x11, 0x22, 0x33, 0x44, // value
-    0x00, 0x05,             // parameter id
-    0x00, 0x02,             // length of value
-    0xab, 0xcd,             // value
-  };
+    uint8_t expected[] = {
+      0x01, 0x02, 0x03, 0x04, // negotiated version
+      0x08,                   // size of supported versions
+      0x01, 0x02, 0x03, 0x04, // version 1
+      0x05, 0x06, 0x07, 0x08, // version 2
+      0x00, 0x0e,             // size of parameters
+      0x00, 0x00,             // parameter id
+      0x00, 0x04,             // length of value
+      0x11, 0x22, 0x33, 0x44, // value
+      0x00, 0x05,             // parameter id
+      0x00, 0x02,             // length of value
+      0xab, 0xcd,             // value
+    };
 
-  QUICTransportParametersInEncryptedExtensions params_in_ee(0x01020304);
+    QUICTransportParametersInEncryptedExtensions params_in_ee(0x01020304);
 
-  uint32_t max_stream_data = 0x11223344;
-  params_in_ee.set(QUICTransportParameterId::INITIAL_MAX_STREAM_DATA, max_stream_data);
+    uint32_t max_stream_data = 0x11223344;
+    params_in_ee.set(QUICTransportParameterId::INITIAL_MAX_STREAM_DATA, max_stream_data);
 
-  uint16_t max_packet_size = 0xabcd;
-  params_in_ee.set(QUICTransportParameterId::MAX_PACKET_SIZE, max_packet_size);
+    uint16_t max_packet_size = 0xabcd;
+    params_in_ee.set(QUICTransportParameterId::MAX_PACKET_SIZE, max_packet_size);
 
-  params_in_ee.add_version(0x01020304);
-  params_in_ee.add_version(0x05060708);
-  params_in_ee.store(buf, &len);
-  CHECK(len == 29);
-  CHECK(memcmp(buf, expected, len) == 0);
+    params_in_ee.add_version(0x01020304);
+    params_in_ee.add_version(0x05060708);
+    params_in_ee.store(buf, &len);
+    CHECK(len == 29);
+    CHECK(memcmp(buf, expected, len) == 0);
+  }
+
+  SECTION("OK cases - include zero length value")
+  {
+    uint8_t buf[65536];
+    uint16_t len;
+
+    uint8_t expected[] = {
+      0x01, 0x02, 0x03, 0x04, // negotiated version
+      0x08,                   // size of supported versions
+      0x01, 0x02, 0x03, 0x04, // version 1
+      0x05, 0x06, 0x07, 0x08, // version 2
+      0x00, 0x12,             // size of parameters
+      0x00, 0x00,             // parameter id
+      0x00, 0x04,             // length of value
+      0x11, 0x22, 0x33, 0x44, // value
+      0x00, 0x05,             // parameter id
+      0x00, 0x02,             // length of value
+      0xab, 0xcd,             // value
+      0x00, 0x09,             // parameter id
+      0x00, 0x00,             // length of value
+    };
+
+    QUICTransportParametersInEncryptedExtensions params_in_ee(0x01020304);
+
+    uint32_t max_stream_data = 0x11223344;
+    params_in_ee.set(QUICTransportParameterId::INITIAL_MAX_STREAM_DATA, max_stream_data);
+
+    uint16_t max_packet_size = 0xabcd;
+    params_in_ee.set(QUICTransportParameterId::MAX_PACKET_SIZE, max_packet_size);
+    params_in_ee.set(QUICTransportParameterId::DISABLE_MIGRATION, nullptr, 0);
+
+    params_in_ee.add_version(0x01020304);
+    params_in_ee.add_version(0x05060708);
+    params_in_ee.store(buf, &len);
+    CHECK(len == 33);
+    CHECK(memcmp(buf, expected, len) == 0);
+  }
 }