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 c20192b Add tests for QUICStreamManager
c20192b is described below
commit c20192b930196249719fc0922254ecd88bc8457c
Author: Masakazu Kitajo <[email protected]>
AuthorDate: Mon Sep 4 11:22:20 2017 +0900
Add tests for QUICStreamManager
---
.gitignore | 1 +
iocore/net/quic/Mock.h | 8 ++++
iocore/net/quic/QUICFrame.cc | 6 ++-
iocore/net/quic/QUICStreamManager.cc | 36 ++++++++++++--
iocore/net/quic/QUICStreamManager.h | 15 +++---
iocore/net/quic/test/Makefile.am | 31 ++++++++++++
iocore/net/quic/test/test_QUICStreamManager.cc | 66 ++++++++++++++++++++++++++
7 files changed, 149 insertions(+), 14 deletions(-)
diff --git a/.gitignore b/.gitignore
index e68e278..9f94fa6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -93,6 +93,7 @@ iocore/net/quic/test/test_QUICPacket
iocore/net/quic/test/test_QUICPacketFactory
iocore/net/quic/test/test_QUICStream
iocore/net/quic/test/test_QUICStreamState
+iocore/net/quic/test/test_QUICStreamManager
iocore/net/quic/test/test_QUICTransportParameters
iocore/net/quic/test/test_QUICCrypto
iocore/net/quic/test/test_QUICLossDetector
diff --git a/iocore/net/quic/Mock.h b/iocore/net/quic/Mock.h
index dd538e2..270b83b 100644
--- a/iocore/net/quic/Mock.h
+++ b/iocore/net/quic/Mock.h
@@ -21,6 +21,7 @@
* limitations under the License.
*/
+#include "QUICApplication.h"
#include "QUICStreamManager.h"
#include "QUICCongestionController.h"
#include "QUICLossDetector.h"
@@ -344,9 +345,16 @@ private:
int _frameCount[256] = {0};
};
+class MockQUICApplication : public QUICApplication
+{
+public:
+ MockQUICApplication() : QUICApplication(new MockQUICConnection) {}
+};
+
void NetVConnection::cancel_OOB(){};
Action *
NetVConnection::send_OOB(Continuation *, char *, int)
{
return nullptr;
}
+
diff --git a/iocore/net/quic/QUICFrame.cc b/iocore/net/quic/QUICFrame.cc
index e99eda6..e64b37b 100644
--- a/iocore/net/quic/QUICFrame.cc
+++ b/iocore/net/quic/QUICFrame.cc
@@ -691,7 +691,11 @@ QUICRstStreamFrame::error_code() const
QUICStreamId
QUICRstStreamFrame::stream_id() const
{
- return QUICTypeUtil::read_QUICStreamId(this->_buf + 5, 4);
+ if (this->_buf) {
+ return QUICTypeUtil::read_QUICStreamId(this->_buf + 5, 4);
+ } else {
+ return this->_stream_id;
+ }
}
QUICOffset
diff --git a/iocore/net/quic/QUICStreamManager.cc
b/iocore/net/quic/QUICStreamManager.cc
index 035da95..8db20ca 100644
--- a/iocore/net/quic/QUICStreamManager.cc
+++ b/iocore/net/quic/QUICStreamManager.cc
@@ -84,6 +84,9 @@ QUICStreamManager::handle_frame(std::shared_ptr<const
QUICFrame> frame)
case QUICFrameType::STREAM:
error = this->_handle_frame(std::dynamic_pointer_cast<const
QUICStreamFrame>(frame));
break;
+ case QUICFrameType::RST_STREAM:
+ error = this->_handle_frame(std::dynamic_pointer_cast<const
QUICRstStreamFrame>(frame));
+ break;
default:
Debug(tag, "Unexpected frame type: %02x", static_cast<unsigned
int>(frame->type()));
ink_assert(false);
@@ -96,7 +99,7 @@ QUICStreamManager::handle_frame(std::shared_ptr<const
QUICFrame> frame)
QUICError
QUICStreamManager::_handle_frame(const std::shared_ptr<const
QUICMaxStreamDataFrame> &frame)
{
- QUICStream *stream = this->_find_stream(frame->stream_id());
+ QUICStream *stream = this->_find_or_create_stream(frame->stream_id());
if (stream) {
return stream->recv(frame);
} else {
@@ -109,7 +112,7 @@ QUICStreamManager::_handle_frame(const
std::shared_ptr<const QUICMaxStreamDataFr
QUICError
QUICStreamManager::_handle_frame(const std::shared_ptr<const
QUICStreamBlockedFrame> &frame)
{
- QUICStream *stream = this->_find_stream(frame->stream_id());
+ QUICStream *stream = this->_find_or_create_stream(frame->stream_id());
if (stream) {
return stream->recv(frame);
} else {
@@ -138,6 +141,19 @@ QUICStreamManager::_handle_frame(const
std::shared_ptr<const QUICStreamFrame> &f
return error;
}
+QUICError
+QUICStreamManager::_handle_frame(const std::shared_ptr<const
QUICRstStreamFrame> &frame)
+{
+ QUICStream *stream = this->_find_or_create_stream(frame->stream_id());
+ if (stream) {
+ // TODO Reset the stream
+ } else {
+ // TODO: connection error?
+ }
+
+ return QUICError(QUICErrorClass::NONE);
+}
+
/**
* @brief Send stream frame
*/
@@ -206,7 +222,7 @@ QUICStreamManager::total_offset_received() const
// FIXME Iterating all (open + closed) streams is expensive
for (QUICStream *s = this->stream_list.head; s; s = s->link.next) {
if (s->id() != 0) {
- total_offset_received += s->largest_offset_received();
+ total_offset_received += s->largest_offset_received() / 1024;
}
}
return total_offset_received;
@@ -220,8 +236,18 @@ QUICStreamManager::total_offset_sent() const
// FIXME Iterating all (open + closed) streams is expensive
for (QUICStream *s = this->stream_list.head; s; s = s->link.next) {
if (s->id() != 0) {
- total_offset_sent += s->largest_offset_sent();
+ total_offset_sent += s->largest_offset_sent() / 1024;
}
}
- return this->_total_offset_sent;
+ return total_offset_sent;
+}
+
+uint32_t
+QUICStreamManager::stream_count() const
+{
+ uint32_t count = 0;
+ for (QUICStream *s = this->stream_list.head; s; s = s->link.next) {
+ ++count;
+ }
+ return count;
}
diff --git a/iocore/net/quic/QUICStreamManager.h
b/iocore/net/quic/QUICStreamManager.h
index 605496f..70af464 100644
--- a/iocore/net/quic/QUICStreamManager.h
+++ b/iocore/net/quic/QUICStreamManager.h
@@ -37,22 +37,26 @@ class QUICStreamManager : public QUICFrameHandler
public:
QUICStreamManager(){};
QUICStreamManager(QUICFrameTransmitter *tx, QUICApplicationMap *app_map);
- virtual std::vector<QUICFrameType> interests() override;
- virtual QUICError handle_frame(std::shared_ptr<const QUICFrame>) override;
+
virtual void send_frame(std::unique_ptr<QUICFrame, QUICFrameDeleterFunc>
frame);
virtual void send_frame(std::unique_ptr<QUICStreamFrame,
QUICFrameDeleterFunc> frame);
void init_flow_control_params(const std::shared_ptr<const
QUICTransportParameters> &local_tp,
const std::shared_ptr<const
QUICTransportParameters> &remote_tp);
uint64_t total_offset_received() const;
uint64_t total_offset_sent() const;
+ uint32_t stream_count() const;
DLL<QUICStream> stream_list;
+ // QUICFrameHandler
+ virtual std::vector<QUICFrameType> interests() override;
+ virtual QUICError handle_frame(std::shared_ptr<const QUICFrame>) override;
+
private:
QUICStream *_find_or_create_stream(QUICStreamId stream_id);
QUICStream *_find_stream(QUICStreamId id);
- QUICError _handle_frame(const std::shared_ptr<const QUICMaxDataFrame> &);
QUICError _handle_frame(const std::shared_ptr<const QUICStreamFrame> &);
+ QUICError _handle_frame(const std::shared_ptr<const QUICRstStreamFrame> &);
QUICError _handle_frame(const std::shared_ptr<const QUICMaxStreamDataFrame>
&);
QUICError _handle_frame(const std::shared_ptr<const QUICStreamBlockedFrame>
&);
@@ -63,9 +67,4 @@ private:
QUICMaximumData _recv_max_data = {0};
QUICMaximumData _send_max_data = {0};
-
- // TODO: Maximum Data is in units of 1024 octets, but those total offset are
in units of octets.
- // Add new uint16_t fields for remainder and treat those total offset in
units of 1024 octets if needed
- uint64_t _total_offset_received = 0;
- uint64_t _total_offset_sent = 0;
};
diff --git a/iocore/net/quic/test/Makefile.am b/iocore/net/quic/test/Makefile.am
index dc6e12f..a958fe8 100644
--- a/iocore/net/quic/test/Makefile.am
+++ b/iocore/net/quic/test/Makefile.am
@@ -24,6 +24,7 @@ check_PROGRAMS = \
test_QUICFrameDispatcher \
test_QUICStreamState \
test_QUICStream \
+ test_QUICStreamManager \
test_QUICTransportParameters \
test_QUICCrypto \
test_QUICLossDetector \
@@ -232,6 +233,36 @@ test_QUICStream_LDADD = \
@HWLOC_LIBS@
#
+# test_QUICStreamManager
+#
+test_QUICStreamManager_CPPFLAGS = \
+ $(AM_CPPFLAGS)
+
+test_QUICStreamManager_LDFLAGS = \
+ @AM_LDFLAGS@
+
+test_QUICStreamManager_SOURCES = \
+ event_processor_main.cc \
+ test_QUICStreamManager.cc \
+ ../QUICStream.cc \
+ ../QUICFrameDispatcher.cc \
+ ../QUICStreamManager.cc \
+ ../QUICApplicationMap.cc \
+ ../QUICCongestionController.cc \
+ ../../SSLNextProtocolSet.cc
+
+test_QUICStreamManager_LDADD = \
+ $(top_builddir)/lib/ts/libtsutil.la \
+ $(top_builddir)/iocore/eventsystem/libinkevent.a \
+ $(top_builddir)/iocore/net/quic/libquic.a \
+ $(top_builddir)/lib/records/librecords_p.a \
+ $(top_builddir)/mgmt/libmgmt_p.la \
+ $(top_builddir)/lib/ts/libtsutil.la \
+ $(top_builddir)/proxy/shared/libUglyLogStubs.a \
+ @LIBTCL@ \
+ @HWLOC_LIBS@
+
+#
# test_QUICTransportParameters
#
test_QUICTransportParameters_CPPFLAGS = \
diff --git a/iocore/net/quic/test/test_QUICStreamManager.cc
b/iocore/net/quic/test/test_QUICStreamManager.cc
new file mode 100644
index 0000000..752859b
--- /dev/null
+++ b/iocore/net/quic/test/test_QUICStreamManager.cc
@@ -0,0 +1,66 @@
+/** @file
+ *
+ * A brief file description
+ *
+ * @section license License
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "catch.hpp"
+
+#include <memory>
+
+#include "quic/QUICStreamManager.h"
+#include "quic/QUICFrame.h"
+#include "quic/Mock.h"
+
+TEST_CASE("QUICStreamManager_NewStream", "[quic]")
+{
+ MockQUICFrameTransmitter tx;
+ QUICApplicationMap app_map;
+ MockQUICApplication mock_app;
+ app_map.set_default(&mock_app);
+ QUICStreamManager sm(&tx, &app_map);
+ std::shared_ptr<QUICTransportParameters> local_tp =
std::make_shared<QUICTransportParametersInEncryptedExtensions>();
+ std::shared_ptr<QUICTransportParameters> remote_tp =
std::make_shared<QUICTransportParametersInClientHello>(static_cast<QUICVersion>(0),
static_cast<QUICVersion>(0));
+ sm.init_flow_control_params(local_tp, remote_tp);
+
+ // STREAM frames create new streams
+ std::shared_ptr<QUICFrame> stream_frame_0 =
QUICFrameFactory::create_stream_frame(reinterpret_cast<const uint8_t *>("abc"),
3, 0, 0);
+ std::shared_ptr<QUICFrame> stream_frame_1 =
QUICFrameFactory::create_stream_frame(reinterpret_cast<const uint8_t *>("abc"),
3, 1, 0);
+ CHECK(sm.stream_count() == 0);
+ sm.handle_frame(stream_frame_0);
+ CHECK(sm.stream_count() == 1);
+ sm.handle_frame(stream_frame_1);
+ CHECK(sm.stream_count() == 2);
+
+ // RST_STREAM frames create new streams
+ std::shared_ptr<QUICFrame> rst_stream_frame =
QUICFrameFactory::create_rst_stream_frame(2,
QUICErrorCode::QUIC_INTERNAL_ERROR, 0);
+ sm.handle_frame(rst_stream_frame);
+ CHECK(sm.stream_count() == 3);
+
+ // MAX_STREAM_DATA frames create new streams
+ std::shared_ptr<QUICFrame> max_stream_data_frame =
QUICFrameFactory::create_max_stream_data_frame(3, 0);
+ sm.handle_frame(max_stream_data_frame);
+ CHECK(sm.stream_count() == 4);
+
+ // STREAM_BLOCKED frames create new streams
+ std::shared_ptr<QUICFrame> stream_blocked_frame =
QUICFrameFactory::create_stream_blocked_frame(4);
+ sm.handle_frame(stream_blocked_frame);
+ CHECK(sm.stream_count() == 5);
+}
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].