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 2017/12/18 02:45:35 UTC
[trafficserver] branch quic-latest updated: Add tests for
retransmission and fix QUIC*Frame::store()
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 af623f8 Add tests for retransmission and fix QUIC*Frame::store()
af623f8 is described below
commit af623f8864a7567fe0cbb4dfb8ac65b5663e35ce
Author: Masaori Koshiba <ma...@apache.org>
AuthorDate: Mon Dec 18 11:43:09 2017 +0900
Add tests for retransmission and fix QUIC*Frame::store()
---
iocore/net/quic/QUICFrame.cc | 270 ++++++++++++++++++++-------------
iocore/net/quic/test/test_QUICFrame.cc | 243 +++++++++++++++++++++++++++++
2 files changed, 408 insertions(+), 105 deletions(-)
diff --git a/iocore/net/quic/QUICFrame.cc b/iocore/net/quic/QUICFrame.cc
index 682d5b0..6160b26 100644
--- a/iocore/net/quic/QUICFrame.cc
+++ b/iocore/net/quic/QUICFrame.cc
@@ -696,18 +696,23 @@ QUICRstStreamFrame::size() const
void
QUICRstStreamFrame::store(uint8_t *buf, size_t *len) const
{
- size_t n;
- uint8_t *p = buf;
- *p = static_cast<uint8_t>(QUICFrameType::RST_STREAM);
- ++p;
- QUICTypeUtil::write_QUICStreamId(this->_stream_id, p, &n);
- p += n;
- QUICTypeUtil::write_QUICAppErrorCode(this->_error_code, p, &n);
- p += n;
- QUICTypeUtil::write_QUICOffset(this->_final_offset, p, &n);
- p += n;
+ if (this->_buf) {
+ *len = this->size();
+ memcpy(buf, this->_buf, *len);
+ } else {
+ size_t n;
+ uint8_t *p = buf;
+ *p = static_cast<uint8_t>(QUICFrameType::RST_STREAM);
+ ++p;
+ QUICTypeUtil::write_QUICStreamId(this->_stream_id, p, &n);
+ p += n;
+ QUICTypeUtil::write_QUICAppErrorCode(this->_error_code, p, &n);
+ p += n;
+ QUICTypeUtil::write_QUICOffset(this->_final_offset, p, &n);
+ p += n;
- *len = p - buf;
+ *len = p - buf;
+ }
}
QUICStreamId
@@ -796,8 +801,13 @@ QUICPingFrame::size() const
void
QUICPingFrame::store(uint8_t *buf, size_t *len) const
{
- buf[0] = static_cast<uint8_t>(QUICFrameType::PING);
- *len = 1;
+ if (this->_buf) {
+ *len = this->size();
+ memcpy(buf, this->_buf, *len);
+ } else {
+ buf[0] = static_cast<uint8_t>(QUICFrameType::PING);
+ *len = 1;
+ }
}
//
@@ -849,20 +859,25 @@ QUICConnectionCloseFrame::size() const
void
QUICConnectionCloseFrame::store(uint8_t *buf, size_t *len) const
{
- size_t n;
- uint8_t *p = buf;
- *p = static_cast<uint8_t>(QUICFrameType::CONNECTION_CLOSE);
- ++p;
- QUICTypeUtil::write_QUICTransErrorCode(this->_error_code, p, &n);
- p += n;
- QUICTypeUtil::write_QUICVariableInt(this->_reason_phrase_length, p, &n);
- p += n;
- if (this->_reason_phrase_length > 0) {
- memcpy(p, this->_reason_phrase, this->_reason_phrase_length);
- p += this->_reason_phrase_length;
- }
+ if (this->_buf) {
+ *len = this->size();
+ memcpy(buf, this->_buf, *len);
+ } else {
+ size_t n;
+ uint8_t *p = buf;
+ *p = static_cast<uint8_t>(QUICFrameType::CONNECTION_CLOSE);
+ ++p;
+ QUICTypeUtil::write_QUICTransErrorCode(this->_error_code, p, &n);
+ p += n;
+ QUICTypeUtil::write_QUICVariableInt(this->_reason_phrase_length, p, &n);
+ p += n;
+ if (this->_reason_phrase_length > 0) {
+ memcpy(p, this->_reason_phrase, this->_reason_phrase_length);
+ p += this->_reason_phrase_length;
+ }
- *len = p - buf;
+ *len = p - buf;
+ }
}
QUICTransErrorCode
@@ -944,20 +959,25 @@ QUICApplicationCloseFrame::size() const
void
QUICApplicationCloseFrame::store(uint8_t *buf, size_t *len) const
{
- size_t n;
- uint8_t *p = buf;
- *p = static_cast<uint8_t>(QUICFrameType::APPLICATION_CLOSE);
- ++p;
- QUICTypeUtil::write_QUICAppErrorCode(this->_error_code, p, &n);
- p += n;
- QUICTypeUtil::write_QUICVariableInt(this->_reason_phrase_length, p, &n);
- p += n;
- if (this->_reason_phrase_length > 0) {
- memcpy(p, this->_reason_phrase, this->_reason_phrase_length);
- p += this->_reason_phrase_length;
- }
+ if (this->_buf) {
+ *len = this->size();
+ memcpy(buf, this->_buf, *len);
+ } else {
+ size_t n;
+ uint8_t *p = buf;
+ *p = static_cast<uint8_t>(QUICFrameType::APPLICATION_CLOSE);
+ ++p;
+ QUICTypeUtil::write_QUICAppErrorCode(this->_error_code, p, &n);
+ p += n;
+ QUICTypeUtil::write_QUICVariableInt(this->_reason_phrase_length, p, &n);
+ p += n;
+ if (this->_reason_phrase_length > 0) {
+ memcpy(p, this->_reason_phrase, this->_reason_phrase_length);
+ p += this->_reason_phrase_length;
+ }
- *len = p - buf;
+ *len = p - buf;
+ }
}
QUICAppErrorCode
@@ -1035,14 +1055,19 @@ QUICMaxDataFrame::size() const
void
QUICMaxDataFrame::store(uint8_t *buf, size_t *len) const
{
- size_t n;
- uint8_t *p = buf;
- *p = static_cast<uint8_t>(QUICFrameType::MAX_DATA);
- ++p;
- QUICTypeUtil::write_QUICMaxData(this->_maximum_data, p, &n);
- p += n;
+ if (this->_buf) {
+ *len = this->size();
+ memcpy(buf, this->_buf, *len);
+ } else {
+ size_t n;
+ uint8_t *p = buf;
+ *p = static_cast<uint8_t>(QUICFrameType::MAX_DATA);
+ ++p;
+ QUICTypeUtil::write_QUICMaxData(this->_maximum_data, p, &n);
+ p += n;
- *len = p - buf;
+ *len = p - buf;
+ }
}
uint64_t
@@ -1089,16 +1114,21 @@ QUICMaxStreamDataFrame::size() const
void
QUICMaxStreamDataFrame::store(uint8_t *buf, size_t *len) const
{
- size_t n;
- uint8_t *p = buf;
- *p = static_cast<uint8_t>(QUICFrameType::MAX_STREAM_DATA);
- ++p;
- QUICTypeUtil::write_QUICStreamId(this->_stream_id, p, &n);
- p += n;
- QUICTypeUtil::write_QUICMaxData(this->_maximum_stream_data, p, &n);
- p += n;
+ if (this->_buf) {
+ *len = this->size();
+ memcpy(buf, this->_buf, *len);
+ } else {
+ size_t n;
+ uint8_t *p = buf;
+ *p = static_cast<uint8_t>(QUICFrameType::MAX_STREAM_DATA);
+ ++p;
+ QUICTypeUtil::write_QUICStreamId(this->_stream_id, p, &n);
+ p += n;
+ QUICTypeUtil::write_QUICMaxData(this->_maximum_stream_data, p, &n);
+ p += n;
- *len = p - buf;
+ *len = p - buf;
+ }
}
QUICStreamId
@@ -1176,14 +1206,19 @@ QUICMaxStreamIdFrame::size() const
void
QUICMaxStreamIdFrame::store(uint8_t *buf, size_t *len) const
{
- size_t n;
- uint8_t *p = buf;
- *p = static_cast<uint8_t>(QUICFrameType::MAX_STREAM_ID);
- ++p;
- QUICTypeUtil::write_QUICStreamId(this->_maximum_stream_id, p, &n);
- p += n;
+ if (this->_buf) {
+ *len = this->size();
+ memcpy(buf, this->_buf, *len);
+ } else {
+ size_t n;
+ uint8_t *p = buf;
+ *p = static_cast<uint8_t>(QUICFrameType::MAX_STREAM_ID);
+ ++p;
+ QUICTypeUtil::write_QUICStreamId(this->_maximum_stream_id, p, &n);
+ p += n;
- *len = p - buf;
+ *len = p - buf;
+ }
}
QUICStreamId
@@ -1224,15 +1259,20 @@ QUICBlockedFrame::size() const
void
QUICBlockedFrame::store(uint8_t *buf, size_t *len) const
{
- size_t n;
- uint8_t *p = buf;
+ if (this->_buf) {
+ *len = this->size();
+ memcpy(buf, this->_buf, *len);
+ } else {
+ size_t n;
+ uint8_t *p = buf;
- *p = static_cast<uint8_t>(QUICFrameType::BLOCKED);
- ++p;
- QUICTypeUtil::write_QUICOffset(this->_offset, p, &n);
- p += n;
+ *p = static_cast<uint8_t>(QUICFrameType::BLOCKED);
+ ++p;
+ QUICTypeUtil::write_QUICOffset(this->_offset, p, &n);
+ p += n;
- *len = p - buf;
+ *len = p - buf;
+ }
}
QUICOffset
@@ -1273,16 +1313,21 @@ QUICStreamBlockedFrame::size() const
void
QUICStreamBlockedFrame::store(uint8_t *buf, size_t *len) const
{
- size_t n;
- uint8_t *p = buf;
- *p = static_cast<uint8_t>(QUICFrameType::STREAM_BLOCKED);
- ++p;
- QUICTypeUtil::write_QUICStreamId(this->_stream_id, p, &n);
- p += n;
- QUICTypeUtil::write_QUICOffset(this->_offset, p, &n);
- p += n;
+ if (this->_buf) {
+ *len = this->size();
+ memcpy(buf, this->_buf, *len);
+ } else {
+ size_t n;
+ uint8_t *p = buf;
+ *p = static_cast<uint8_t>(QUICFrameType::STREAM_BLOCKED);
+ ++p;
+ QUICTypeUtil::write_QUICStreamId(this->_stream_id, p, &n);
+ p += n;
+ QUICTypeUtil::write_QUICOffset(this->_offset, p, &n);
+ p += n;
- *len = p - buf;
+ *len = p - buf;
+ }
}
QUICStreamId
@@ -1349,15 +1394,20 @@ QUICStreamIdBlockedFrame::size() const
void
QUICStreamIdBlockedFrame::store(uint8_t *buf, size_t *len) const
{
- size_t n;
- uint8_t *p = buf;
+ if (this->_buf) {
+ *len = this->size();
+ memcpy(buf, this->_buf, *len);
+ } else {
+ size_t n;
+ uint8_t *p = buf;
- *p = static_cast<uint8_t>(QUICFrameType::STREAM_ID_BLOCKED);
- ++p;
- QUICTypeUtil::write_QUICStreamId(this->_stream_id, p, &n);
- p += n;
+ *p = static_cast<uint8_t>(QUICFrameType::STREAM_ID_BLOCKED);
+ ++p;
+ QUICTypeUtil::write_QUICStreamId(this->_stream_id, p, &n);
+ p += n;
- *len = p - buf;
+ *len = p - buf;
+ }
}
QUICStreamId
@@ -1399,18 +1449,23 @@ QUICNewConnectionIdFrame::size() const
void
QUICNewConnectionIdFrame::store(uint8_t *buf, size_t *len) const
{
- size_t n;
- uint8_t *p = buf;
- *p = static_cast<uint8_t>(QUICFrameType::NEW_CONNECTION_ID);
- ++p;
- QUICTypeUtil::write_QUICVariableInt(this->_sequence, p, &n);
- p += n;
- QUICTypeUtil::write_QUICConnectionId(this->_connection_id, 8, p, &n);
- p += n;
- memcpy(p, this->_stateless_reset_token.buf(), QUICStatelessResetToken::LEN);
- p += QUICStatelessResetToken::LEN;
+ if (this->_buf) {
+ *len = this->size();
+ memcpy(buf, this->_buf, *len);
+ } else {
+ size_t n;
+ uint8_t *p = buf;
+ *p = static_cast<uint8_t>(QUICFrameType::NEW_CONNECTION_ID);
+ ++p;
+ QUICTypeUtil::write_QUICVariableInt(this->_sequence, p, &n);
+ p += n;
+ QUICTypeUtil::write_QUICConnectionId(this->_connection_id, 8, p, &n);
+ p += n;
+ memcpy(p, this->_stateless_reset_token.buf(), QUICStatelessResetToken::LEN);
+ p += QUICStatelessResetToken::LEN;
- *len = p - buf;
+ *len = p - buf;
+ }
}
uint64_t
@@ -1483,16 +1538,21 @@ QUICStopSendingFrame::size() const
void
QUICStopSendingFrame::store(uint8_t *buf, size_t *len) const
{
- size_t n;
- uint8_t *p = buf;
- *p = static_cast<uint8_t>(QUICFrameType::STOP_SENDING);
- ++p;
- QUICTypeUtil::write_QUICStreamId(this->_stream_id, p, &n);
- p += n;
- QUICTypeUtil::write_QUICAppErrorCode(this->_error_code, p, &n);
- p += n;
+ if (this->_buf) {
+ *len = this->size();
+ memcpy(buf, this->_buf, *len);
+ } else {
+ size_t n;
+ uint8_t *p = buf;
+ *p = static_cast<uint8_t>(QUICFrameType::STOP_SENDING);
+ ++p;
+ QUICTypeUtil::write_QUICStreamId(this->_stream_id, p, &n);
+ p += n;
+ QUICTypeUtil::write_QUICAppErrorCode(this->_error_code, p, &n);
+ p += n;
- *len = p - buf;
+ *len = p - buf;
+ }
}
QUICAppErrorCode
diff --git a/iocore/net/quic/test/test_QUICFrame.cc b/iocore/net/quic/test/test_QUICFrame.cc
index 6c71c83..b3aee21 100644
--- a/iocore/net/quic/test/test_QUICFrame.cc
+++ b/iocore/net/quic/test/test_QUICFrame.cc
@@ -1053,3 +1053,246 @@ TEST_CASE("QUICFrameFactory Create RST_STREAM with a QUICStreamError", "[quic]")
CHECK(rst_stream_frame1->stream_id() == 0x1234);
CHECK(rst_stream_frame1->final_offset() == 0);
}
+
+TEST_CASE("Retransmit", "[quic][frame][retransmit]")
+{
+ QUICPacketFactory factory;
+ MockQUICCrypto crypto;
+ factory.set_crypto_module(&crypto);
+ QUICPacketUPtr packet = factory.create_server_protected_packet(0x01020304, 0, {nullptr, [](void *p) { ats_free(p); }}, 0, true);
+
+ SECTION("STREAM frame")
+ {
+ uint8_t frame_buf[] = {
+ 0x12, // Type, 0b00010OLF (OLF=010)
+ 0x01, // Stream ID
+ 0x05, // Data Length
+ 0x01, 0x02, 0x03, 0x04, 0x05, // Stream Data
+ };
+
+ QUICFrameUPtr frame = QUICFrameFactory::create(frame_buf, sizeof(frame_buf));
+ frame = QUICFrameFactory::create_retransmission_frame(std::move(frame), *packet);
+
+ uint8_t buf[32] = {0};
+ size_t len;
+ frame->store(buf, &len);
+
+ CHECK(len == 8);
+ CHECK(memcmp(buf, frame_buf, len) == 0);
+ }
+
+ SECTION("RST_STREAM frame")
+ {
+ uint8_t frame_buf[] = {
+ 0x01, // Type
+ 0x92, 0x34, 0x56, 0x78, // Stream ID
+ 0x00, 0x01, // Error Code
+ 0xd1, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 // Final Offset
+ };
+
+ QUICFrameUPtr frame = QUICFrameFactory::create(frame_buf, sizeof(frame_buf));
+ frame = QUICFrameFactory::create_retransmission_frame(std::move(frame), *packet);
+
+ uint8_t buf[32] = {0};
+ size_t len;
+ frame->store(buf, &len);
+
+ CHECK(len == 15);
+ CHECK(memcmp(buf, frame_buf, len) == 0);
+ }
+
+ SECTION("CONNECTION_CLOSE frame")
+ {
+ uint8_t frame_buf[] = {
+ 0x02, // Type
+ 0x00, 0x0A, // Error Code
+ 0x05, // Reason Phrase Length
+ 0x41, 0x42, 0x43, 0x44, 0x45 // Reason Phrase ("ABCDE");
+ };
+
+ QUICFrameUPtr frame = QUICFrameFactory::create(frame_buf, sizeof(frame_buf));
+ frame = QUICFrameFactory::create_retransmission_frame(std::move(frame), *packet);
+
+ uint8_t buf[32] = {0};
+ size_t len;
+ frame->store(buf, &len);
+
+ CHECK(len == 9);
+ CHECK(memcmp(buf, frame_buf, len) == 0);
+ }
+
+ SECTION("APPLICATION_CLOSE frame")
+ {
+ uint8_t frame_buf[] = {
+ 0x03, // Type
+ 0x00, 0x01, // Error Code
+ 0x05, // Reason Phrase Length
+ 0x41, 0x42, 0x43, 0x44, 0x45 // Reason Phrase ("ABCDE");
+ };
+
+ QUICFrameUPtr frame = QUICFrameFactory::create(frame_buf, sizeof(frame_buf));
+ frame = QUICFrameFactory::create_retransmission_frame(std::move(frame), *packet);
+
+ uint8_t buf[32] = {0};
+ size_t len;
+ frame->store(buf, &len);
+
+ CHECK(len == 9);
+ CHECK(memcmp(buf, frame_buf, len) == 0);
+ }
+
+ SECTION("MAX_DATA frame")
+ {
+ uint8_t frame_buf[] = {
+ 0x04, // Type
+ 0xd1, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 // Maximum Data
+ };
+
+ QUICFrameUPtr frame = QUICFrameFactory::create(frame_buf, sizeof(frame_buf));
+ frame = QUICFrameFactory::create_retransmission_frame(std::move(frame), *packet);
+
+ uint8_t buf[32] = {0};
+ size_t len;
+ frame->store(buf, &len);
+
+ CHECK(len == 9);
+ CHECK(memcmp(buf, frame_buf, len) == 0);
+ }
+
+ SECTION("MAX_STREAM_DATA frame")
+ {
+ uint8_t frame_buf[] = {
+ 0x05, // Type
+ 0x81, 0x02, 0x03, 0x04, // Stream ID
+ 0xd1, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88 // Maximum Stream Data
+ };
+
+ QUICFrameUPtr frame = QUICFrameFactory::create(frame_buf, sizeof(frame_buf));
+ frame = QUICFrameFactory::create_retransmission_frame(std::move(frame), *packet);
+
+ uint8_t buf[32] = {0};
+ size_t len;
+ frame->store(buf, &len);
+
+ CHECK(len == 13);
+ CHECK(memcmp(buf, frame_buf, len) == 0);
+ }
+
+ SECTION("MAX_STREAM_ID frame")
+ {
+ uint8_t frame_buf[] = {
+ 0x06, // Type
+ 0x81, 0x02, 0x03, 0x04, // Stream ID
+ };
+
+ QUICFrameUPtr frame = QUICFrameFactory::create(frame_buf, sizeof(frame_buf));
+ frame = QUICFrameFactory::create_retransmission_frame(std::move(frame), *packet);
+
+ uint8_t buf[32] = {0};
+ size_t len;
+ frame->store(buf, &len);
+
+ CHECK(len == 5);
+ CHECK(memcmp(buf, frame_buf, len) == 0);
+ }
+
+ SECTION("PING frame")
+ {
+ // TODO
+ }
+
+ SECTION("BLOCKED frame")
+ {
+ uint8_t frame_buf[] = {
+ 0x08, // Type
+ 0x07, // Offset
+ };
+
+ QUICFrameUPtr frame = QUICFrameFactory::create(frame_buf, sizeof(frame_buf));
+ frame = QUICFrameFactory::create_retransmission_frame(std::move(frame), *packet);
+
+ uint8_t buf[32] = {0};
+ size_t len;
+ frame->store(buf, &len);
+
+ CHECK(len == 2);
+ CHECK(memcmp(buf, frame_buf, len) == 0);
+ }
+
+ SECTION("STREAM_BLOCKED frame")
+ {
+ uint8_t frame_buf[] = {
+ 0x09, // Type
+ 0x81, 0x02, 0x03, 0x04, // Stream ID
+ 0x07, // Offset
+ };
+
+ QUICFrameUPtr frame = QUICFrameFactory::create(frame_buf, sizeof(frame_buf));
+ frame = QUICFrameFactory::create_retransmission_frame(std::move(frame), *packet);
+
+ uint8_t buf[32] = {0};
+ size_t len;
+ frame->store(buf, &len);
+
+ CHECK(len == 6);
+ CHECK(memcmp(buf, frame_buf, len) == 0);
+ }
+
+ SECTION("STREAM_ID_BLOCKED frame")
+ {
+ uint8_t frame_buf[] = {
+ 0x0a, // Type
+ 0x41, 0x02, // Stream ID
+ };
+
+ QUICFrameUPtr frame = QUICFrameFactory::create(frame_buf, sizeof(frame_buf));
+ frame = QUICFrameFactory::create_retransmission_frame(std::move(frame), *packet);
+
+ uint8_t buf[32] = {0};
+ size_t len;
+ frame->store(buf, &len);
+
+ CHECK(len == 3);
+ CHECK(memcmp(buf, frame_buf, len) == 0);
+ }
+
+ SECTION("NEW_CONNECTION_ID frame")
+ {
+ uint8_t frame_buf[] = {
+ 0x0b, // Type
+ 0x41, 0x02, // Sequence
+ 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, // Connection ID
+ 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, // Stateless Reset Token
+ 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0,
+ };
+
+ QUICFrameUPtr frame = QUICFrameFactory::create(frame_buf, sizeof(frame_buf));
+ frame = QUICFrameFactory::create_retransmission_frame(std::move(frame), *packet);
+
+ uint8_t buf[32] = {0};
+ size_t len;
+ frame->store(buf, &len);
+
+ CHECK(len == 27);
+ CHECK(memcmp(buf, frame_buf, len) == 0);
+ }
+
+ SECTION("STOP_SENDING frame")
+ {
+ uint8_t frame_buf[] = {
+ 0x0c, // Type
+ 0x92, 0x34, 0x56, 0x78, // Stream ID
+ 0x00, 0x01, // Error Code
+ };
+
+ QUICFrameUPtr frame = QUICFrameFactory::create(frame_buf, sizeof(frame_buf));
+ frame = QUICFrameFactory::create_retransmission_frame(std::move(frame), *packet);
+
+ uint8_t buf[32] = {0};
+ size_t len;
+ frame->store(buf, &len);
+
+ CHECK(len == 7);
+ CHECK(memcmp(buf, frame_buf, len) == 0);
+ }
+}
--
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].