summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Nosach <ANosach@luxoft.com>2015-08-05 17:52:21 +0300
committerArtem Nosach <ANosach@luxoft.com>2015-08-06 15:45:17 +0300
commit33968b78167e8071c315f0719326fb5c654e9261 (patch)
tree35cebd1486de2075ad6cdcfcec0b76feaba0f199
parentf261a06bbfb133d1662943e3b269906fa1fc0a5a (diff)
downloadsmartdevicelink-33968b78167e8071c315f0719326fb5c654e9261.tar.gz
Check MTU size according to new rules
- Use 1488 bytes MTU for protocol versions 1 and 2 - Use specified in ini file MTU size for protocol versions 3 and higher Implements: APPLINK-14656
-rw-r--r--src/components/include/protocol/common.h6
-rw-r--r--src/components/protocol_handler/src/protocol_handler_impl.cc37
-rw-r--r--src/components/protocol_handler/src/protocol_packet.cc20
3 files changed, 41 insertions, 22 deletions
diff --git a/src/components/include/protocol/common.h b/src/components/include/protocol/common.h
index 45d3a9e56..3f5d59df8 100644
--- a/src/components/include/protocol/common.h
+++ b/src/components/include/protocol/common.h
@@ -195,10 +195,10 @@ enum {
};
/**
- *\brief If FRAME_TYPE_CONTROL: Constant: Maximum size of one frame excluding
- *\brief frame header (used Ethernet MTU as default target transport)
+ *\brief If FRAME_TYPE_CONTROL: Constant: Default maximum size of one frame
+ *\brief excluding frame header (used Ethernet MTU as default target transport)
*/
-const uint32_t MAXIMUM_FRAME_DATA_SIZE = 1500;
+const size_t DEFAULT_FRAME_DATA_SIZE = 1488;
/**
*\brief If FRAME_TYPE_CONSECUTIVE: Constant: Size of first frame in
diff --git a/src/components/protocol_handler/src/protocol_handler_impl.cc b/src/components/protocol_handler/src/protocol_handler_impl.cc
index a5ed1adc9..2c7bad263 100644
--- a/src/components/protocol_handler/src/protocol_handler_impl.cc
+++ b/src/components/protocol_handler/src/protocol_handler_impl.cc
@@ -37,6 +37,7 @@
#include "connection_handler/connection_handler_impl.h"
#include "config_profile/profile.h"
#include "utils/byte_order.h"
+#include "protocol/common.h"
#ifdef ENABLE_SECURITY
#include "security_manager/ssl_context.h"
@@ -358,29 +359,39 @@ void ProtocolHandlerImpl::SendMessageToMobileApp(const RawMessagePtr message,
metric_observer_->StartMessageProcess(message_id, start_time);
}
#endif // TIME_TESTER
-
- const uint32_t header_size = (PROTOCOL_VERSION_1 == message->protocol_version())
- ? PROTOCOL_HEADER_V1_SIZE : PROTOCOL_HEADER_V2_SIZE;
- uint32_t max_frame_size = MAXIMUM_FRAME_DATA_SIZE - header_size;
+ const size_t max_frame_size =
+ profile::Profile::instance()->maximum_payload_size();
+ size_t frame_size = DEFAULT_FRAME_DATA_SIZE;
+ switch (message->protocol_version()) {
+ case PROTOCOL_VERSION_1:
+ case PROTOCOL_VERSION_2:
+ break;
+ case PROTOCOL_VERSION_3:
+ case PROTOCOL_VERSION_4:
+ frame_size = max_frame_size > DEFAULT_FRAME_DATA_SIZE ?
+ max_frame_size : DEFAULT_FRAME_DATA_SIZE;
+ break;
+ default:
+ break;
+ }
#ifdef ENABLE_SECURITY
const security_manager::SSLContext *ssl_context = session_observer_->
GetSSLContext(message->connection_key(), message->service_type());
if (ssl_context && ssl_context->IsInitCompleted()) {
- const size_t max_block_size = ssl_context->get_max_block_size(max_frame_size);
+ const size_t max_block_size = ssl_context->get_max_block_size(frame_size);
DCHECK(max_block_size > 0);
if (max_block_size > 0) {
- max_frame_size = max_block_size;
- LOG4CXX_DEBUG(logger_, "Security set new optimal packet size " << max_frame_size);
+ frame_size = max_block_size;
+ LOG4CXX_DEBUG(logger_, "Security set new optimal packet size " << frame_size);
} else {
LOG4CXX_ERROR(logger_, "Security could not return max block size, use the origin one");
}
}
- LOG4CXX_DEBUG(logger_, "Optimal packet size is " << max_frame_size);
+ LOG4CXX_DEBUG(logger_, "Optimal packet size is " << frame_size);
#endif // ENABLE_SECURITY
- DCHECK(MAXIMUM_FRAME_DATA_SIZE > max_frame_size);
-
+ DCHECK(DEFAULT_FRAME_DATA_SIZE <= frame_size);
- if (message->data_size() <= max_frame_size) {
+ if (message->data_size() <= frame_size) {
RESULT_CODE result = SendSingleFrameMessage(connection_handle, sessionID,
message->protocol_version(),
message->service_type(),
@@ -394,14 +405,14 @@ void ProtocolHandlerImpl::SendMessageToMobileApp(const RawMessagePtr message,
} else {
LOG4CXX_DEBUG(
logger_,
- "Message will be sent in multiple frames; max frame size is " << max_frame_size);
+ "Message will be sent in multiple frames; max frame size is " << frame_size);
RESULT_CODE result = SendMultiFrameMessage(connection_handle, sessionID,
message->protocol_version(),
message->service_type(),
message->data_size(),
message->data(),
- max_frame_size, final_message);
+ frame_size, final_message);
if (result != RESULT_OK) {
LOG4CXX_ERROR(logger_,
"ProtocolHandler failed to send multiframe messages.");
diff --git a/src/components/protocol_handler/src/protocol_packet.cc b/src/components/protocol_handler/src/protocol_packet.cc
index bdaabe3d3..e22d10e72 100644
--- a/src/components/protocol_handler/src/protocol_packet.cc
+++ b/src/components/protocol_handler/src/protocol_packet.cc
@@ -36,6 +36,7 @@
#include <cstring>
#include <limits>
+#include "protocol/common.h"
#include "protocol_handler/protocol_packet.h"
#include "utils/macro.h"
#include "utils/byte_order.h"
@@ -118,7 +119,8 @@ void ProtocolPacket::ProtocolHeader::deserialize(
}
ProtocolPacket::ProtocolHeaderValidator::ProtocolHeaderValidator()
- : max_payload_size_(std::numeric_limits<size_t>::max()) {}
+ : max_payload_size_(std::numeric_limits<size_t>::max()) {
+}
void ProtocolPacket::ProtocolHeaderValidator::set_max_payload_size(
const size_t max_payload_size) {
@@ -129,13 +131,20 @@ size_t ProtocolPacket::ProtocolHeaderValidator::max_payload_size() const {
return max_payload_size_;
}
-RESULT_CODE ProtocolPacket::ProtocolHeaderValidator::validate(const ProtocolHeader& header) const {
- // Protocol version shall be from 1 to 4
+RESULT_CODE ProtocolPacket::ProtocolHeaderValidator::validate(
+ const ProtocolHeader& header) const {
+ // expected payload size will be calculated depending
+ // on used protocol version
+ size_t payload_size = DEFAULT_FRAME_DATA_SIZE;
+ // Protocol version shall be from 1 to 3
switch (header.version) {
case PROTOCOL_VERSION_1:
case PROTOCOL_VERSION_2:
+ break;
case PROTOCOL_VERSION_3:
case PROTOCOL_VERSION_4:
+ payload_size = max_payload_size_ > DEFAULT_FRAME_DATA_SIZE ?
+ max_payload_size_ : DEFAULT_FRAME_DATA_SIZE;
break;
default:
return RESULT_FAIL;
@@ -185,8 +194,8 @@ RESULT_CODE ProtocolPacket::ProtocolHeaderValidator::validate(const ProtocolHead
}
// For Control frames Data Size value shall be less than MTU header
// For Single and Consecutive Data Size value shall be greater than 0x00
- // and shall be less than N (this value will be defined in .ini file)
- if (header.dataSize > max_payload_size_) {
+ // and shall be less than payload size
+ if (header.dataSize > payload_size) {
return RESULT_FAIL;
}
switch (header.frameType) {
@@ -209,7 +218,6 @@ RESULT_CODE ProtocolPacket::ProtocolHeaderValidator::validate(const ProtocolHead
return RESULT_OK;
}
-
ProtocolPacket::ProtocolPacket()
: payload_size_(0), connection_id_(0) {
}