Skip to content

Commit

Permalink
vsomeip 2.10.21
Browse files Browse the repository at this point in the history
  • Loading branch information
juergengehring committed May 22, 2018
1 parent 23b6a4b commit 9fb9bee
Show file tree
Hide file tree
Showing 35 changed files with 699 additions and 251 deletions.
14 changes: 14 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
Changes
=======

v2.10.21
- Improve memory usage of routing manager.
- Improve handling of incoming SD messages with uncommon entry
combinations.
- Name all threads under Linux and log thread IDs during startup.
- Optimize memory allocation for internal message handling.
- Ensure an (extra) dispatch thread is running in case the main
dispatch thread is (still) blocked.
- Fix race condition which could lead to missing initial events for
local subscriptions if the application hosting the service called
application::offer_event and additionally application::request_event
for the same event.
- Fixed crash

v2.10.20
- Add security config (i.e. vsomeip_security.json) to mandatory config files
- Enable local_routing_test_starter.sh to use externally defined configuration
Expand Down
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ project (vsomeip)

set (VSOMEIP_MAJOR_VERSION 2)
set (VSOMEIP_MINOR_VERSION 10)
set (VSOMEIP_PATCH_VERSION 20)
set (VSOMEIP_PATCH_VERSION 21)
set (VSOMEIP_HOTFIX_VERSION 0)

set (VSOMEIP_VERSION ${VSOMEIP_MAJOR_VERSION}.${VSOMEIP_MINOR_VERSION}.${VSOMEIP_PATCH_VERSION})
set (PACKAGE_VERSION ${VSOMEIP_VERSION}) # Used in documentatin/doxygen.in
set (CMAKE_VERBOSE_MAKEFILE off)
Expand Down Expand Up @@ -148,7 +150,11 @@ file(GLOB_RECURSE vsomeip_e2e_SRC
list(SORT vsomeip_SRC)
list(SORT vsomeip_e2e_SRC)

if (${VSOMEIP_HOTFIX_VERSION} EQUAL 0)
add_definitions(-DVSOMEIP_VERSION="${VSOMEIP_VERSION}")
else()
add_definitions(-DVSOMEIP_VERSION="${VSOMEIP_VERSION}.${VSOMEIP_HOTFIX_VERSION}")
endif()

if (MSVC)
message("using MSVC Compiler")
Expand Down
12 changes: 11 additions & 1 deletion implementation/configuration/include/internal.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
#define VSOMEIP_COMMAND_TYPE_POS 0
#define VSOMEIP_COMMAND_CLIENT_POS 1
#define VSOMEIP_COMMAND_SIZE_POS_MIN 3
#define VSOMEIP_COMMAND_SIZE_POS_MAX 5
#define VSOMEIP_COMMAND_SIZE_POS_MAX 6
#define VSOMEIP_COMMAND_PAYLOAD_POS 7

#define VSOMEIP_REGISTER_APPLICATION 0x00
Expand Down Expand Up @@ -105,6 +105,16 @@
#define VSOMEIP_OFFERED_SERVICES_RESPONSE 0x20
#define VSOMEIP_UNSUBSCRIBE_ACK 0x21

#define VSOMEIP_SEND_COMMAND_SIZE 14
#define VSOMEIP_SEND_COMMAND_INSTANCE_POS_MIN 7
#define VSOMEIP_SEND_COMMAND_INSTANCE_POS_MAX 8
#define VSOMEIP_SEND_COMMAND_FLUSH_POS 9
#define VSOMEIP_SEND_COMMAND_RELIABLE_POS 10
#define VSOMEIP_SEND_COMMAND_VALID_CRC_POS 11
#define VSOMEIP_SEND_COMMAND_DST_CLIENT_POS_MIN 12
#define VSOMEIP_SEND_COMMAND_DST_CLIENT_POS_MAX 13
#define VSOMEIP_SEND_COMMAND_PAYLOAD_POS 14

#define VSOMEIP_OFFER_SERVICE_COMMAND_SIZE 16
#define VSOMEIP_REQUEST_SERVICE_COMMAND_SIZE 17
#define VSOMEIP_RELEASE_SERVICE_COMMAND_SIZE 11
Expand Down
4 changes: 1 addition & 3 deletions implementation/configuration/src/configuration_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2400,9 +2400,7 @@ std::uint32_t configuration_impl::get_max_message_size_local() const {

// add sizes of the the routing_manager_proxy's messages
// to the routing_manager stub
return std::uint32_t(its_max_message_size
+ VSOMEIP_COMMAND_HEADER_SIZE + sizeof(instance_t)
+ sizeof(bool) + sizeof(bool) + sizeof(client_t));
return std::uint32_t(its_max_message_size + VSOMEIP_SEND_COMMAND_SIZE);
}

std::uint32_t configuration_impl::get_max_message_size_reliable(
Expand Down
7 changes: 7 additions & 0 deletions implementation/endpoints/include/client_endpoint_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class client_endpoint_impl: public endpoint_impl<Protocol>, public client_endpoi
virtual ~client_endpoint_impl();

bool send(const uint8_t *_data, uint32_t _size, bool _flush);
bool send(const std::vector<byte_t>& _cmd_header, const byte_t *_data,
uint32_t _size, bool _flush = true);
bool send_to(const std::shared_ptr<endpoint_definition> _target,
const byte_t *_data, uint32_t _size, bool _flush = true);
bool flush();
Expand Down Expand Up @@ -81,6 +83,11 @@ class client_endpoint_impl: public endpoint_impl<Protocol>, public client_endpoi
void shutdown_and_close_socket_unlocked(bool _recreate_socket);
void start_connect_timer();

bool check_message_size(std::uint32_t _size) const;
bool check_packetizer_space(std::uint32_t _size);
bool check_queue_limit(const uint8_t *_data, std::uint32_t _size) const;
void send_or_start_flush_timer(bool _flush, bool _queue_size_zero_on_entry);

mutable std::mutex socket_mutex_;
std::unique_ptr<socket_type> socket_;
endpoint_type remote_;
Expand Down
4 changes: 4 additions & 0 deletions implementation/endpoints/include/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include <vsomeip/primitive_types.hpp>

#include <vector>

namespace vsomeip {

class endpoint_definition;
Expand All @@ -27,6 +29,8 @@ class endpoint {

virtual bool send(const byte_t *_data, uint32_t _size,
bool _flush = true) = 0;
virtual bool send(const std::vector<byte_t>& _cmd_header, const byte_t *_data,
uint32_t _size, bool _flush = true) = 0;
virtual bool send_to(const std::shared_ptr<endpoint_definition> _target,
const byte_t *_data, uint32_t _size, bool _flush = true) = 0;
virtual void enable_magic_cookies() = 0;
Expand Down
9 changes: 3 additions & 6 deletions implementation/endpoints/include/endpoint_definition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ class endpoint_definition {
bool is_reliable_;

static std::mutex definitions_mutex_;
static std::map<service_t,
std::map<instance_t,
std::map<boost::asio::ip::address,
std::map<uint16_t,
std::map<bool,
std::shared_ptr<endpoint_definition> > > > > > definitions_;
static std::map<
std::tuple<service_t, instance_t, boost::asio::ip::address, uint16_t, bool>,
std::shared_ptr<endpoint_definition> > definitions_;
};

} // namespace vsomeip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class local_client_endpoint_impl: public local_client_endpoint_base_impl {
void restart(bool _force);
void print_status();

bool send(const std::vector<byte_t>& _cmd_header, const byte_t *_data,
uint32_t _size, bool _flush = true);
private:
void send_queued();

Expand Down
2 changes: 2 additions & 0 deletions implementation/endpoints/include/server_endpoint_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class server_endpoint_impl: public endpoint_impl<Protocol>,
bool is_connected() const;
void set_connected(bool _connected);
bool send(const uint8_t *_data, uint32_t _size, bool _flush);
bool send(const std::vector<byte_t>& _cmd_header, const byte_t *_data,
uint32_t _size, bool _flush = true);

virtual void stop();
bool flush(endpoint_type _target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class virtual_server_endpoint_impl : public endpoint {
void set_connected(bool _connected);

bool send(const byte_t *_data, uint32_t _size, bool _flush);
bool send(const std::vector<byte_t>& _cmd_header, const byte_t *_data,
uint32_t _size, bool _flush);
bool send_to(const std::shared_ptr<endpoint_definition> _target,
const byte_t *_data, uint32_t _size, bool _flush);
void enable_magic_cookies();
Expand Down
204 changes: 118 additions & 86 deletions implementation/endpoints/src/client_endpoint_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,96 +105,37 @@ template<typename Protocol>
bool client_endpoint_impl<Protocol>::send(const uint8_t *_data,
uint32_t _size, bool _flush) {
std::lock_guard<std::mutex> its_lock(mutex_);
if (endpoint_impl<Protocol>::sending_blocked_) {
return false;
}
#if 0
std::stringstream msg;
msg << "cei::send: ";
for (uint32_t i = 0; i < _size; i++)
msg << std::hex << std::setw(2) << std::setfill('0')
<< (int)_data[i] << " ";
VSOMEIP_INFO << msg.str();
#endif

if (endpoint_impl<Protocol>::max_message_size_ != MESSAGE_SIZE_UNLIMITED
&& _size > endpoint_impl<Protocol>::max_message_size_) {
VSOMEIP_ERROR << "cei::send: Dropping to big message (" << std::dec
<< _size << " Bytes). Maximum allowed message size is: "
<< endpoint_impl<Protocol>::max_message_size_ << " Bytes.";
return false;
}

bool ret(true);
const bool queue_size_zero_on_entry(queue_.empty());
if (packetizer_->size() + _size < packetizer_->size()) {
VSOMEIP_ERROR << "Overflow in packetizer addition ~> abort sending!";
return false;
}
if (packetizer_->size() + _size > endpoint_impl<Protocol>::max_message_size_
&& !packetizer_->empty()) {
queue_.push_back(packetizer_);
queue_size_ += packetizer_->size();
packetizer_ = std::make_shared<message_buffer_t>();
}

if (endpoint_impl<Protocol>::queue_limit_ != QUEUE_SIZE_UNLIMITED
&& queue_size_ + _size > endpoint_impl<Protocol>::queue_limit_) {
service_t its_service(0);
method_t its_method(0);
client_t its_client(0);
session_t its_session(0);
if (_size >= VSOMEIP_SESSION_POS_MAX) {
// this will yield wrong IDs for local communication as the commands
// are prepended to the actual payload
// it will print:
// (lowbyte service ID + highbyte methoid)
// [(Command + lowerbyte sender's client ID).
// highbyte sender's client ID + lowbyte command size.
// lowbyte methodid + highbyte vsomeipd length]
its_service = VSOMEIP_BYTES_TO_WORD(_data[VSOMEIP_SERVICE_POS_MIN],
_data[VSOMEIP_SERVICE_POS_MAX]);
its_method = VSOMEIP_BYTES_TO_WORD(_data[VSOMEIP_METHOD_POS_MIN],
_data[VSOMEIP_METHOD_POS_MAX]);
its_client = VSOMEIP_BYTES_TO_WORD(_data[VSOMEIP_CLIENT_POS_MIN],
_data[VSOMEIP_CLIENT_POS_MAX]);
its_session = VSOMEIP_BYTES_TO_WORD(_data[VSOMEIP_SESSION_POS_MIN],
_data[VSOMEIP_SESSION_POS_MAX]);
}
VSOMEIP_ERROR << "cei::send: queue size limit (" << std::dec
<< endpoint_impl<Protocol>::queue_limit_
<< ") reached. Dropping message ("
<< std::hex << std::setw(4) << std::setfill('0') << its_client <<"): ["
<< std::hex << std::setw(4) << std::setfill('0') << its_service << "."
<< std::hex << std::setw(4) << std::setfill('0') << its_method << "."
<< std::hex << std::setw(4) << std::setfill('0') << its_session << "] "
<< "queue_size: " << std::dec << queue_size_
<< " data size: " << std::dec << _size;
return false;
}
packetizer_->insert(packetizer_->end(), _data, _data + _size);

if (_flush) {
flush_timer_.cancel();
queue_.push_back(packetizer_);
queue_size_ += packetizer_->size();
packetizer_ = std::make_shared<message_buffer_t>();
if (endpoint_impl<Protocol>::sending_blocked_ ||
!check_message_size(_size) ||
!check_packetizer_space(_size) ||
!check_queue_limit(_data, _size)) {
ret = false;
} else {
flush_timer_.expires_from_now(
std::chrono::milliseconds(VSOMEIP_DEFAULT_FLUSH_TIMEOUT)); // TODO: use config variable
flush_timer_.async_wait(
std::bind(
&client_endpoint_impl<Protocol>::flush_cbk,
this->shared_from_this(),
std::placeholders::_1
)
);
}

if (queue_size_zero_on_entry && !queue_.empty()) { // no writing in progress
send_queued();
#if 0
std::stringstream msg;
msg << "cei::send: ";
for (uint32_t i = 0; i < _size; i++)
msg << std::hex << std::setw(2) << std::setfill('0')
<< (int)_data[i] << " ";
VSOMEIP_INFO << msg.str();
#endif
packetizer_->insert(packetizer_->end(), _data, _data + _size);
send_or_start_flush_timer(_flush, queue_size_zero_on_entry);
}
return ret;
}

return (true);
template<typename Protocol>
bool client_endpoint_impl<Protocol>::send(const std::vector<byte_t>& _cmd_header,
const byte_t *_data, uint32_t _size,
bool _flush) {
(void) _cmd_header;
(void) _data;
(void) _size;
(void) _flush;
return false;
}

template<typename Protocol>
Expand Down Expand Up @@ -427,6 +368,97 @@ void client_endpoint_impl<Protocol>::start_connect_timer() {
this->shared_from_this(), std::placeholders::_1));
}

template<typename Protocol>
bool client_endpoint_impl<Protocol>::check_message_size(std::uint32_t _size) const {
if (endpoint_impl<Protocol>::max_message_size_ != MESSAGE_SIZE_UNLIMITED
&& _size > endpoint_impl<Protocol>::max_message_size_) {
VSOMEIP_ERROR << "cei::check_message_size: Dropping to big message ("
<< std::dec << _size << " Bytes). Maximum allowed message size is: "
<< endpoint_impl<Protocol>::max_message_size_ << " Bytes.";
return false;
}
return true;
}

template<typename Protocol>
bool client_endpoint_impl<Protocol>::check_packetizer_space(std::uint32_t _size) {
if (packetizer_->size() + _size < packetizer_->size()) {
VSOMEIP_ERROR << "Overflow in packetizer addition ~> abort sending!";
return false;
}
if (packetizer_->size() + _size > endpoint_impl<Protocol>::max_message_size_
&& !packetizer_->empty()) {
queue_.push_back(packetizer_);
queue_size_ += packetizer_->size();
packetizer_ = std::make_shared<message_buffer_t>();
}
return true;
}

template<typename Protocol>
bool client_endpoint_impl<Protocol>::check_queue_limit(const uint8_t *_data, std::uint32_t _size) const {
if (endpoint_impl<Protocol>::queue_limit_ != QUEUE_SIZE_UNLIMITED
&& queue_size_ + _size > endpoint_impl<Protocol>::queue_limit_) {
service_t its_service(0);
method_t its_method(0);
client_t its_client(0);
session_t its_session(0);
if (_size >= VSOMEIP_SESSION_POS_MAX) {
// this will yield wrong IDs for local communication as the commands
// are prepended to the actual payload
// it will print:
// (lowbyte service ID + highbyte methoid)
// [(Command + lowerbyte sender's client ID).
// highbyte sender's client ID + lowbyte command size.
// lowbyte methodid + highbyte vsomeipd length]
its_service = VSOMEIP_BYTES_TO_WORD(_data[VSOMEIP_SERVICE_POS_MIN],
_data[VSOMEIP_SERVICE_POS_MAX]);
its_method = VSOMEIP_BYTES_TO_WORD(_data[VSOMEIP_METHOD_POS_MIN],
_data[VSOMEIP_METHOD_POS_MAX]);
its_client = VSOMEIP_BYTES_TO_WORD(_data[VSOMEIP_CLIENT_POS_MIN],
_data[VSOMEIP_CLIENT_POS_MAX]);
its_session = VSOMEIP_BYTES_TO_WORD(_data[VSOMEIP_SESSION_POS_MIN],
_data[VSOMEIP_SESSION_POS_MAX]);
}
VSOMEIP_ERROR << "cei::check_queue_limit: queue size limit (" << std::dec
<< endpoint_impl<Protocol>::queue_limit_
<< ") reached. Dropping message ("
<< std::hex << std::setw(4) << std::setfill('0') << its_client <<"): ["
<< std::hex << std::setw(4) << std::setfill('0') << its_service << "."
<< std::hex << std::setw(4) << std::setfill('0') << its_method << "."
<< std::hex << std::setw(4) << std::setfill('0') << its_session << "] "
<< "queue_size: " << std::dec << queue_size_
<< " data size: " << std::dec << _size;
return false;
}
return true;
}

template<typename Protocol>
void client_endpoint_impl<Protocol>::send_or_start_flush_timer(
bool _flush, bool _queue_size_zero_on_entry) {
if (_flush) {
flush_timer_.cancel();
queue_.push_back(packetizer_);
queue_size_ += packetizer_->size();
packetizer_ = std::make_shared<message_buffer_t>();

if (_queue_size_zero_on_entry && !queue_.empty()) { // no writing in progress
send_queued();
}
} else {
flush_timer_.expires_from_now(
std::chrono::milliseconds(VSOMEIP_DEFAULT_FLUSH_TIMEOUT)); // TODO: use config variable
flush_timer_.async_wait(
std::bind(
&client_endpoint_impl<Protocol>::flush_cbk,
this->shared_from_this(),
std::placeholders::_1
)
);
}
}

// Instantiate template
#ifndef _WIN32
template class client_endpoint_impl<boost::asio::local::stream_protocol>;
Expand Down
Loading

0 comments on commit 9fb9bee

Please sign in to comment.