summaryrefslogtreecommitdiff
path: root/src/components/protocol_handler
diff options
context:
space:
mode:
authorElisey Zamakhov <EZamakhov@luxoft.com>2015-03-12 11:27:11 +0300
committerElisey Zamakhov <EZamakhov@luxoft.com>2015-03-18 14:02:33 +0300
commit917bd4265356425ff014b468e2a978f07ebad27e (patch)
tree4f6ce7b1b8fc2aa31ffd86a50aee2a624dce9564 /src/components/protocol_handler
parentc3be7a11e525ab3de3f388075a23c6ac9bdc83cb (diff)
downloadsdl_core-917bd4265356425ff014b468e2a978f07ebad27e.tar.gz
Change malformed messages counting strategy
Diffstat (limited to 'src/components/protocol_handler')
-rw-r--r--src/components/protocol_handler/src/protocol_handler_impl.cc5
-rw-r--r--src/components/protocol_handler/test/protocol_handler_tm_test.cc83
2 files changed, 85 insertions, 3 deletions
diff --git a/src/components/protocol_handler/src/protocol_handler_impl.cc b/src/components/protocol_handler/src/protocol_handler_impl.cc
index fda88f675c..ca44f330c8 100644
--- a/src/components/protocol_handler/src/protocol_handler_impl.cc
+++ b/src/components/protocol_handler/src/protocol_handler_impl.cc
@@ -441,7 +441,10 @@ void ProtocolHandlerImpl::OnTMMessageReceived(const RawMessagePtr tm_message) {
if (result != RESULT_OK) {
if (result == RESULT_MALFORMED_OCCURS) {
LOG4CXX_WARN(logger_, "Malformed message occurs.");
- TrackMalformedMessage(tm_message->connection_key());
+ // For tracking only malformed occurrence check outpute
+ if(!protocol_frames.empty()) {
+ TrackMalformedMessage(tm_message->connection_key());
+ }
} else {
LOG4CXX_ERROR(logger_, "Incoming data processing failed.");
transport_manager_->DisconnectForce(tm_message->connection_key());
diff --git a/src/components/protocol_handler/test/protocol_handler_tm_test.cc b/src/components/protocol_handler/test/protocol_handler_tm_test.cc
index 3e38813f33..144003c63b 100644
--- a/src/components/protocol_handler/test/protocol_handler_tm_test.cc
+++ b/src/components/protocol_handler/test/protocol_handler_tm_test.cc
@@ -755,10 +755,38 @@ TEST_F(ProtocolHandlerImplTest,
}
}
+
TEST_F(ProtocolHandlerImplTest,
- MalformedLimitVerification) {
+ MalformedLimitVerification) {
const size_t period_msec = 10000;
- const size_t max_messages = 1000;
+ const size_t max_messages = 100;
+ InitProtocolHandlerImpl(0u, 0u, period_msec, max_messages);
+ AddConnection();
+ AddSession();
+
+ // expect malformed notification to CH
+ EXPECT_CALL(session_observer_mock,
+ OnMalformedMessageCallback(connection_id)).
+ Times(1);
+
+ // Sending malformed packets
+ const uint8_t malformed_version = PROTOCOL_VERSION_MAX;
+ for (size_t i = 0; i < max_messages * 2; ++i) {
+ // Malformed message
+ SendTMMessage(connection_id, malformed_version, PROTECTION_OFF, FRAME_TYPE_SINGLE,
+ kControl, FRAME_DATA_SINGLE, session_id,
+ some_data.size(), message_id, &some_data[0]);
+ // Common message
+ SendTMMessage(connection_id, PROTOCOL_VERSION_1, PROTECTION_OFF, FRAME_TYPE_SINGLE,
+ kControl, FRAME_DATA_SINGLE, session_id,
+ some_data.size(), message_id, &some_data[0]);
+ }
+}
+
+TEST_F(ProtocolHandlerImplTest,
+ MalformedLimitVerification_MalformedStock) {
+ const size_t period_msec = 10000;
+ const size_t max_messages = 100;
InitProtocolHandlerImpl(0u, 0u, period_msec, max_messages);
AddConnection();
AddSession();
@@ -770,10 +798,61 @@ TEST_F(ProtocolHandlerImplTest,
// Sending malformed packets
const uint8_t malformed_version = PROTOCOL_VERSION_MAX;
+ const uint8_t malformed_frame_type = FRAME_TYPE_MAX_VALUE;
+ const uint8_t malformed_service_type = kInvalidServiceType;
for (size_t i = 0; i < max_messages * 2; ++i) {
+ // Malformed message 1
SendTMMessage(connection_id, malformed_version, PROTECTION_OFF, FRAME_TYPE_SINGLE,
kControl, FRAME_DATA_SINGLE, session_id,
some_data.size(), message_id, &some_data[0]);
+ // Malformed message 2
+ SendTMMessage(connection_id, PROTOCOL_VERSION_1, PROTECTION_OFF, malformed_frame_type,
+ kControl, FRAME_DATA_SINGLE, session_id,
+ some_data.size(), message_id, &some_data[0]);
+ // Malformed message 3
+ SendTMMessage(connection_id, PROTOCOL_VERSION_1, PROTECTION_OFF, FRAME_TYPE_SINGLE,
+ malformed_service_type, FRAME_DATA_SINGLE, session_id,
+ some_data.size(), message_id, &some_data[0]);
+
+ // Common message
+ SendTMMessage(connection_id, PROTOCOL_VERSION_1, PROTECTION_OFF, FRAME_TYPE_SINGLE,
+ kControl, FRAME_DATA_SINGLE, session_id,
+ some_data.size(), message_id, &some_data[0]);
+ }
+}
+
+TEST_F(ProtocolHandlerImplTest,
+ MalformedLimitVerification_MalformedOnly) {
+ const size_t period_msec = 10000;
+ const size_t max_messages = 100;
+ InitProtocolHandlerImpl(0u, 0u, period_msec, max_messages);
+ AddConnection();
+ AddSession();
+
+ // expect NO malformed notification to CH
+ EXPECT_CALL(session_observer_mock,
+ OnMalformedMessageCallback(connection_id)).
+ Times(0);
+
+ // Sending malformed packets
+ const uint8_t malformed_version = PROTOCOL_VERSION_MAX;
+ const uint8_t malformed_frame_type = FRAME_TYPE_MAX_VALUE;
+ const uint8_t malformed_service_type = kInvalidServiceType;
+ for (size_t i = 0; i < max_messages * 2; ++i) {
+ // Malformed message 1
+ SendTMMessage(connection_id, malformed_version, PROTECTION_OFF, FRAME_TYPE_SINGLE,
+ kControl, FRAME_DATA_SINGLE, session_id,
+ some_data.size(), message_id, &some_data[0]);
+ // Malformed message 2
+ SendTMMessage(connection_id, PROTOCOL_VERSION_1, PROTECTION_OFF, malformed_frame_type,
+ kControl, FRAME_DATA_SINGLE, session_id,
+ some_data.size(), message_id, &some_data[0]);
+ // Malformed message 3
+ SendTMMessage(connection_id, PROTOCOL_VERSION_1, PROTECTION_OFF, FRAME_TYPE_SINGLE,
+ malformed_service_type, FRAME_DATA_SINGLE, session_id,
+ some_data.size(), message_id, &some_data[0]);
+
+ // No common message
}
}