diff options
Diffstat (limited to 'implementation/service_discovery/src')
19 files changed, 219 insertions, 178 deletions
diff --git a/implementation/service_discovery/src/configuration_option_impl.cpp b/implementation/service_discovery/src/configuration_option_impl.cpp index 9666e5e..c1f6917 100755..100644 --- a/implementation/service_discovery/src/configuration_option_impl.cpp +++ b/implementation/service_discovery/src/configuration_option_impl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2018 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -21,8 +21,8 @@ configuration_option_impl::~configuration_option_impl() { } bool -configuration_option_impl::operator ==(const option_impl &_other) const { - bool is_equal(option_impl::operator ==(_other)); +configuration_option_impl::equals(const option_impl &_other) const { + bool is_equal(option_impl::equals(_other)); if (is_equal) { const configuration_option_impl &its_other @@ -123,8 +123,6 @@ bool configuration_option_impl::deserialize(vsomeip_v3::deserializer *_from) { is_successful = false; } } - } else { - break; } } while (is_successful && _from->get_remaining() > 0); diff --git a/implementation/service_discovery/src/deserializer.cpp b/implementation/service_discovery/src/deserializer.cpp index 88ce3be..046a523 100644 --- a/implementation/service_discovery/src/deserializer.cpp +++ b/implementation/service_discovery/src/deserializer.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/implementation/service_discovery/src/entry_impl.cpp b/implementation/service_discovery/src/entry_impl.cpp index 1fa1c89..3873d0a 100755..100644 --- a/implementation/service_discovery/src/entry_impl.cpp +++ b/implementation/service_discovery/src/entry_impl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2018 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/implementation/service_discovery/src/eventgroupentry_impl.cpp b/implementation/service_discovery/src/eventgroupentry_impl.cpp index 28fdcec..f23fd74 100755..100644 --- a/implementation/service_discovery/src/eventgroupentry_impl.cpp +++ b/implementation/service_discovery/src/eventgroupentry_impl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2018 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -118,8 +118,8 @@ bool eventgroupentry_impl::matches(const eventgroupentry_impl& _other, std::vector<std::shared_ptr<ip_option_impl>> its_options_current; std::vector<std::shared_ptr<ip_option_impl>> its_options_other; const std::size_t its_options_size = _options.size(); - for (const auto& option_run : {0,1}) { - for (const auto& option_index : options_[option_run]) { + for (const auto option_run : {0,1}) { + for (const auto option_index : options_[option_run]) { if (its_options_size > option_index) { switch (_options[option_index]->get_type()) { case option_type_e::IP4_ENDPOINT: @@ -137,7 +137,7 @@ bool eventgroupentry_impl::matches(const eventgroupentry_impl& _other, } } } - for (const auto& option_index : _other.options_[option_run]) { + for (const auto option_index : _other.options_[option_run]) { if (its_options_size > option_index) { switch (_options[option_index]->get_type()) { case option_type_e::IP4_ENDPOINT: @@ -165,7 +165,7 @@ bool eventgroupentry_impl::matches(const eventgroupentry_impl& _other, for (const auto& c : its_options_current) { bool found(false); for (const auto& o : its_options_other) { - if (*c == *o) { + if (c->equals(*o)) { switch (c->get_type()) { case option_type_e::IP4_ENDPOINT: if (static_cast<ipv4_option_impl*>(c.get())->get_address() @@ -212,8 +212,8 @@ std::shared_ptr<endpoint_definition> eventgroupentry_impl::get_target( std::shared_ptr<selective_option_impl> eventgroupentry_impl::get_selective_option() const { - for (const auto& i : {0, 1}) { - for (const auto& j : options_[i]) { + for (const auto i : {0, 1}) { + for (const auto j : options_[i]) { auto its_option = std::dynamic_pointer_cast< selective_option_impl>(owner_->get_option(j)); if (its_option) diff --git a/implementation/service_discovery/src/ip_option_impl.cpp b/implementation/service_discovery/src/ip_option_impl.cpp index 0f83511..197013f 100644 --- a/implementation/service_discovery/src/ip_option_impl.cpp +++ b/implementation/service_discovery/src/ip_option_impl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -29,8 +29,8 @@ ip_option_impl::~ip_option_impl() { } bool -ip_option_impl::operator ==(const option_impl &_other) const { - bool is_equal(option_impl::operator ==(_other)); +ip_option_impl::equals(const option_impl &_other) const { + bool is_equal(option_impl::equals(_other)); if (is_equal) { const ip_option_impl &its_other diff --git a/implementation/service_discovery/src/ipv4_option_impl.cpp b/implementation/service_discovery/src/ipv4_option_impl.cpp index f3389e8..f2eef95 100644 --- a/implementation/service_discovery/src/ipv4_option_impl.cpp +++ b/implementation/service_discovery/src/ipv4_option_impl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2018 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -31,8 +31,8 @@ ipv4_option_impl::~ipv4_option_impl() { } bool -ipv4_option_impl::operator ==(const option_impl &_other) const { - bool is_equal(ip_option_impl::operator ==(_other)); +ipv4_option_impl::equals(const option_impl &_other) const { + bool is_equal(ip_option_impl::equals(_other)); if (is_equal) { const ipv4_option_impl &its_other = dynamic_cast<const ipv4_option_impl &>(_other); diff --git a/implementation/service_discovery/src/ipv6_option_impl.cpp b/implementation/service_discovery/src/ipv6_option_impl.cpp index 1baba0f..e2bc30e 100755..100644 --- a/implementation/service_discovery/src/ipv6_option_impl.cpp +++ b/implementation/service_discovery/src/ipv6_option_impl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2018 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -31,8 +31,8 @@ ipv6_option_impl::~ipv6_option_impl() { } bool -ipv6_option_impl::operator ==(const option_impl &_other) const { - bool is_equal(ip_option_impl::operator ==(_other)); +ipv6_option_impl::equals(const option_impl &_other) const { + bool is_equal(ip_option_impl::equals(_other)); if (is_equal) { const ipv6_option_impl &its_other diff --git a/implementation/service_discovery/src/load_balancing_option_impl.cpp b/implementation/service_discovery/src/load_balancing_option_impl.cpp index a26509e..1e30788 100755..100644 --- a/implementation/service_discovery/src/load_balancing_option_impl.cpp +++ b/implementation/service_discovery/src/load_balancing_option_impl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2018 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -21,8 +21,8 @@ load_balancing_option_impl::~load_balancing_option_impl() { } bool -load_balancing_option_impl::operator ==(const option_impl &_other) const { - bool is_equal(option_impl::operator ==(_other)); +load_balancing_option_impl::equals(const option_impl &_other) const { + bool is_equal(option_impl::equals(_other)); if (is_equal) { const load_balancing_option_impl &its_other diff --git a/implementation/service_discovery/src/message_element_impl.cpp b/implementation/service_discovery/src/message_element_impl.cpp index 281a0a7..afdb507 100755..100644 --- a/implementation/service_discovery/src/message_element_impl.cpp +++ b/implementation/service_discovery/src/message_element_impl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/implementation/service_discovery/src/message_impl.cpp b/implementation/service_discovery/src/message_impl.cpp index a203ce7..c00da19 100755..100644 --- a/implementation/service_discovery/src/message_impl.cpp +++ b/implementation/service_discovery/src/message_impl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2018 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -178,7 +178,7 @@ const message_impl::options_t & message_impl::get_options() const { std::shared_ptr<option_impl> message_impl::find_option(const std::shared_ptr<option_impl> &_option) const { for (auto its_option : options_) { - if (its_option->equals(_option)) + if (its_option->equals(*_option)) return its_option; } return nullptr; @@ -419,13 +419,24 @@ length_t message_impl::get_someip_length() const { } uid_t message_impl::get_uid() const { - return ANY_UID; + return (ANY_UID); } gid_t message_impl::get_gid() const { - return ANY_GID; + return (ANY_GID); } +vsomeip_sec_client_t message_impl::get_sec_client() const { + static vsomeip_sec_client_t its_dummy_sec_client{ + VSOMEIP_CLIENT_UDS, {vsomeip_sec_uds_client_credentials_t{ANY_UID, ANY_GID}} + }; + + return (its_dummy_sec_client); +} + +std::string message_impl::get_env() const { + return (""); +} } // namespace sd } // namespace vsomeip_v3 diff --git a/implementation/service_discovery/src/option_impl.cpp b/implementation/service_discovery/src/option_impl.cpp index eb92c1a..c055ff4 100755..100644 --- a/implementation/service_discovery/src/option_impl.cpp +++ b/implementation/service_discovery/src/option_impl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2018 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -19,13 +19,9 @@ option_impl::option_impl() : option_impl::~option_impl() { } -bool option_impl::operator ==(const option_impl &_other) const { - return (type_ == _other.type_ && length_ == _other.length_); -} - bool -option_impl::equals(const std::shared_ptr<option_impl> &_other) const { - return (this->operator ==(*(_other.get()))); +option_impl::equals(const option_impl &_other) const { + return (type_ == _other.get_type() && length_ == _other.get_length()); } uint16_t option_impl::get_length() const { diff --git a/implementation/service_discovery/src/protection_option_impl.cpp b/implementation/service_discovery/src/protection_option_impl.cpp index 801ca88..6d79860 100755..100644 --- a/implementation/service_discovery/src/protection_option_impl.cpp +++ b/implementation/service_discovery/src/protection_option_impl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2018 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -21,8 +21,8 @@ protection_option_impl::~protection_option_impl() { } bool -protection_option_impl::operator ==(const option_impl &_other) const { - bool is_equal(option_impl::operator ==(_other)); +protection_option_impl::equals(const option_impl &_other) const { + bool is_equal(option_impl::equals(_other)); if (is_equal) { const protection_option_impl &its_other diff --git a/implementation/service_discovery/src/remote_subscription_ack.cpp b/implementation/service_discovery/src/remote_subscription_ack.cpp index 03270c9..45fa057 100644 --- a/implementation/service_discovery/src/remote_subscription_ack.cpp +++ b/implementation/service_discovery/src/remote_subscription_ack.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/implementation/service_discovery/src/request.cpp b/implementation/service_discovery/src/request.cpp index 819b1a5..ee6b10b 100644 --- a/implementation/service_discovery/src/request.cpp +++ b/implementation/service_discovery/src/request.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/implementation/service_discovery/src/runtime_impl.cpp b/implementation/service_discovery/src/runtime_impl.cpp index 75ce986..f0fa456 100644 --- a/implementation/service_discovery/src/runtime_impl.cpp +++ b/implementation/service_discovery/src/runtime_impl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/implementation/service_discovery/src/selective_option_impl.cpp b/implementation/service_discovery/src/selective_option_impl.cpp index 17063d9..7fe62c9 100755..100644 --- a/implementation/service_discovery/src/selective_option_impl.cpp +++ b/implementation/service_discovery/src/selective_option_impl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2018-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -21,8 +21,8 @@ selective_option_impl::~selective_option_impl() { } bool -selective_option_impl::operator ==(const option_impl &_other) const { - bool is_equal(option_impl::operator ==(_other)); +selective_option_impl::equals(const option_impl &_other) const { + bool is_equal(option_impl::equals(_other)); if (is_equal) { const selective_option_impl &its_other = dynamic_cast<const selective_option_impl &>(_other); diff --git a/implementation/service_discovery/src/service_discovery_impl.cpp b/implementation/service_discovery/src/service_discovery_impl.cpp index 74e509b..19effad 100644 --- a/implementation/service_discovery/src/service_discovery_impl.cpp +++ b/implementation/service_discovery/src/service_discovery_impl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2018 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -81,8 +81,7 @@ service_discovery_impl::service_discovery_impl( service_discovery_impl::~service_discovery_impl() { } -boost::asio::io_service & -service_discovery_impl::get_io() { +boost::asio::io_context &service_discovery_impl::get_io() { return io_; } @@ -164,11 +163,13 @@ service_discovery_impl::start() { i.second->set_sent_counter(0); } } + + // rejoin multicast group if (endpoint_ && !reliable_) { - auto its_endpoint = std::dynamic_pointer_cast< - udp_server_endpoint_impl>(endpoint_); - if (its_endpoint) - its_endpoint->join(sd_multicast_); + auto its_server_endpoint + = std::dynamic_pointer_cast<udp_server_endpoint_impl>(endpoint_); + if (its_server_endpoint) + its_server_endpoint->join(sd_multicast_); } } is_suspended_ = false; @@ -524,6 +525,7 @@ service_discovery_impl::unsubscribe_all( serialize_and_send(its_messages, its_address); } + void service_discovery_impl::unsubscribe_all_on_suspend() { @@ -616,12 +618,11 @@ service_discovery_impl::increment_session( bool service_discovery_impl::is_reboot( const boost::asio::ip::address &_sender, - const boost::asio::ip::address &_destination, + bool _is_multicast, bool _reboot_flag, session_t _session) { bool result(false); auto its_received = sessions_received_.find(_sender); - bool is_multicast = _destination.is_multicast(); // Initialize both sessions with 0. Thus, the session identifier // for the session not being received from the network is stored @@ -632,7 +633,7 @@ service_discovery_impl::is_reboot( // received from the network will never trigger the reboot detection. bool its_multicast_reboot_flag(true), its_unicast_reboot_flag(true); - if (is_multicast) { + if (_is_multicast) { its_multicast_session = _session; its_multicast_reboot_flag = _reboot_flag; } else { @@ -648,14 +649,14 @@ service_discovery_impl::is_reboot( // Reboot detection: Either the flag has changed from false to true, // or the session identifier overrun while the flag is true. if (_reboot_flag - && ((is_multicast && !std::get<2>(its_received->second)) - || (!is_multicast && !std::get<3>(its_received->second)))) { + && ((_is_multicast && !std::get<2>(its_received->second)) + || (!_is_multicast && !std::get<3>(its_received->second)))) { result = true; } else { session_t its_old_session; bool its_old_reboot_flag; - if (is_multicast) { + if (_is_multicast) { its_old_session = std::get<0>(its_received->second); its_old_reboot_flag = std::get<2>(its_received->second); } else { @@ -671,7 +672,7 @@ service_discovery_impl::is_reboot( if (result == false) { // no reboot -> update session/flag - if (is_multicast) { + if (_is_multicast) { std::get<0>(its_received->second) = its_multicast_session; std::get<2>(its_received->second) = its_multicast_reboot_flag; } else { @@ -687,6 +688,27 @@ service_discovery_impl::is_reboot( return result; } +bool +service_discovery_impl::check_session_id_sequence(const boost::asio::ip::address &_sender, + const bool _is_multicast, const session_t &_session, + session_t &_missing_session) { + + using address_pair_t = std::pair<boost::asio::ip::address, bool>; + static std::map<address_pair_t, session_t> session_peer; + address_pair_t peer_to_peer(_sender, _is_multicast); + std::map<address_pair_t, session_t>::iterator it = session_peer.find(peer_to_peer); + if (it != session_peer.end()) { + if ((_session > it->second) && (_session != (it->second+1))) { + _missing_session = static_cast<session_t>(it->second+1); + session_peer[peer_to_peer] = _session; + return false; + } + } + + session_peer[peer_to_peer] = _session; + return true; +} + void service_discovery_impl::insert_find_entries( std::vector<std::shared_ptr<message_impl> > &_messages, @@ -839,7 +861,7 @@ service_discovery_impl::create_eventgroup_entry( its_entry->set_ttl(_subscription->get_ttl()); its_data.entry_ = its_entry; - for (const auto& its_client : _subscription->get_clients()) { + for (const auto its_client : _subscription->get_clients()) { if (_subscription->get_state(its_client) == subscription_state_e::ST_RESUBSCRIBING_NOT_ACKNOWLEDGED) { its_other = std::make_shared<eventgroupentry_impl>(); @@ -890,7 +912,7 @@ service_discovery_impl::create_eventgroup_entry( its_data.entry_ = its_entry; } - for (const auto& its_client : _subscription->get_clients()) { + for (const auto its_client : _subscription->get_clients()) { if (_subscription->get_state(its_client) == subscription_state_e::ST_RESUBSCRIBING_NOT_ACKNOWLEDGED) { if (!its_other) { @@ -1043,7 +1065,7 @@ service_discovery_impl::send(bool _is_announcing) { std::lock_guard<std::mutex> its_lock(offer_mutex_); services_t its_offers = host_->get_offered_services(); - insert_offer_entries(its_messages, its_offers, true); + insert_offer_entries(its_messages, its_offers, false); // Serialize and send return send(its_messages); @@ -1057,7 +1079,7 @@ void service_discovery_impl::on_message( const byte_t *_data, length_t _length, const boost::asio::ip::address &_sender, - const boost::asio::ip::address &_destination) { + bool _is_multicast) { #if 0 std::stringstream msg; msg << "sdi::on_message: "; @@ -1075,8 +1097,8 @@ service_discovery_impl::on_message( if (!check_source_address(_sender)) { return; } - const bool received_via_mcast = (_destination == sd_multicast_address_); - if (received_via_mcast) { + + if (_is_multicast) { static bool must_start_last_msg_received_timer(true); boost::system::error_code ec; @@ -1102,7 +1124,7 @@ service_discovery_impl::on_message( return; } // Expire all subscriptions / services in case of reboot - if (is_reboot(_sender, _destination, + if (is_reboot(_sender, _is_multicast, its_message->get_reboot_flag(), its_message->get_session())) { VSOMEIP_INFO << "Reboot detected: IP=" << _sender.to_string(); remove_remote_offer_type_by_ip(_sender); @@ -1121,6 +1143,23 @@ service_discovery_impl::on_message( } } + session_t start_missing_sessions; + if (!check_session_id_sequence(_sender, _is_multicast, its_message->get_session(), start_missing_sessions)) { + std::stringstream log; + log << "SD messages lost from " << _sender.to_string() << " to "; + if (_is_multicast) { + log << sd_multicast_address_.to_string(); + } else { + log << unicast_.to_string(); + } + log << " - session_id[" << start_missing_sessions; + if (its_message->get_session() - start_missing_sessions != 1) { + log << ":" << its_message->get_session() -1; + } + log << "]"; + VSOMEIP_WARNING << log.str(); + } + std::vector<std::shared_ptr<option_impl> > its_options = its_message->get_options(); @@ -1171,7 +1210,7 @@ service_discovery_impl::on_message( bool its_unicast_flag = its_message->get_unicast_flag(); process_serviceentry(its_service_entry, its_options, its_unicast_flag, its_resubscribes, - received_via_mcast, accept_state); + _is_multicast, accept_state); } else { std::shared_ptr<eventgroupentry_impl> its_eventgroup_entry = std::dynamic_pointer_cast<eventgroupentry_impl>(*iter); @@ -1190,7 +1229,7 @@ service_discovery_impl::on_message( is_stop_subscribe_subscribe = check_stop_subscribe_subscribe(iter, its_end, its_options); process_eventgroupentry(its_eventgroup_entry, its_options, - its_acknowledgement, _sender, _destination, + its_acknowledgement, _sender, _is_multicast, is_stop_subscribe_subscribe, force_initial_events, accept_state); } @@ -1330,7 +1369,7 @@ service_discovery_impl::process_serviceentry( VSOMEIP_ERROR << __func__ << ": Unsupported service entry type"; } } else if (its_type != entry_type_e::FIND_SERVICE - && (!_sd_ac_state.sd_acceptance_required_ || _sd_ac_state.accept_entries_)) { + && (_sd_ac_state.sd_acceptance_required_ || _sd_ac_state.accept_entries_)) { // stop sending find service in repetition phase update_request(its_service, its_instance); @@ -1378,19 +1417,10 @@ service_discovery_impl::process_offerservice_serviceentry( // stop sending find service in repetition phase update_request(_service, _instance); - remote_offer_type_e offer_type(remote_offer_type_e::UNKNOWN); - if (_reliable_port != ILLEGAL_PORT - && _unreliable_port != ILLEGAL_PORT - && !_reliable_address.is_unspecified() - && !_unreliable_address.is_unspecified()) { - offer_type = remote_offer_type_e::RELIABLE_UNRELIABLE; - } else if (_unreliable_port != ILLEGAL_PORT - && !_unreliable_address.is_unspecified()) { - offer_type = remote_offer_type_e::UNRELIABLE; - } else if (_reliable_port != ILLEGAL_PORT - && !_reliable_address.is_unspecified()) { - offer_type = remote_offer_type_e::RELIABLE; - } else { + const reliability_type_e offer_type = configuration_->get_reliability_type( + _reliable_address, _reliable_port, _unreliable_address,_unreliable_port); + + if (offer_type == reliability_type_e::RT_UNKNOWN) { VSOMEIP_WARNING << __func__ << ": Unknown remote offer type [" << std::hex << std::setw(4) << std::setfill('0') << _service << "." << std::hex << std::setw(4) << std::setfill('0') << _instance << "]"; @@ -1419,7 +1449,7 @@ service_discovery_impl::process_offerservice_serviceentry( // return if the registered sd_acceptance handler returned false // and for the provided port sd_acceptance is necessary switch (offer_type) { - case remote_offer_type_e::UNRELIABLE: + case reliability_type_e::RT_UNRELIABLE: if (!_sd_ac_state.accept_entries_ && configuration_->is_protected_port( _unreliable_address, _unreliable_port, false)) { @@ -1428,7 +1458,7 @@ service_discovery_impl::process_offerservice_serviceentry( return; } break; - case remote_offer_type_e::RELIABLE: + case reliability_type_e::RT_RELIABLE: if (!_sd_ac_state.accept_entries_ && configuration_->is_protected_port( _reliable_address, _reliable_port, true)) { @@ -1437,7 +1467,7 @@ service_discovery_impl::process_offerservice_serviceentry( return; } break; - case remote_offer_type_e::RELIABLE_UNRELIABLE: + case reliability_type_e::RT_BOTH: if (!_sd_ac_state.accept_entries_ && (configuration_->is_protected_port( _unreliable_address, _unreliable_port, false) @@ -1450,7 +1480,7 @@ service_discovery_impl::process_offerservice_serviceentry( return; } break; - case remote_offer_type_e::UNKNOWN: + case reliability_type_e::RT_UNKNOWN: default: break; } @@ -1470,36 +1500,21 @@ service_discovery_impl::process_offerservice_serviceentry( _service, _instance, eg); if (its_info) { if (its_info->is_reliability_auto_mode()) { - reliability_type_e its_reliability(reliability_type_e::RT_UNKNOWN); - switch (offer_type) { - case remote_offer_type_e::RELIABLE: - its_reliability = reliability_type_e::RT_RELIABLE; - break; - case remote_offer_type_e::UNRELIABLE: - its_reliability = reliability_type_e::RT_UNRELIABLE; - break; - case remote_offer_type_e::RELIABLE_UNRELIABLE: - its_reliability = reliability_type_e::RT_BOTH; - break; - default: - ; - } - if (its_reliability != reliability_type_e::RT_UNKNOWN - && its_reliability != its_info->get_reliability()) { + if (offer_type != reliability_type_e::RT_UNKNOWN + && offer_type != its_info->get_reliability()) { VSOMEIP_WARNING << "sd::" << __func__ << ": eventgroup reliability type changed [" << std::hex << std::setw(4) << std::setfill('0') << _service << "." << std::hex << std::setw(4) << std::setfill('0') << _instance << "." << std::hex << std::setw(4) << std::setfill('0') << eg << "]" << " using reliability type: " - << std::hex << std::setw(4) << std::setfill('0') << (uint16_t) its_reliability; - its_info->set_reliability(its_reliability); + << std::hex << std::setw(4) << std::setfill('0') << (uint16_t) offer_type; + its_info->set_reliability(offer_type); } } } } } - // No need to resubscribe for unicast offers if (_received_via_mcast) { std::lock_guard<std::mutex> its_lock(subscribed_mutex_); @@ -1534,7 +1549,7 @@ service_discovery_impl::process_offerservice_serviceentry( if (its_data.entry_) { add_entry_data(_resubscribes, its_data); } - for (const auto& its_client : its_subscription->get_clients()) { + for (const auto its_client : its_subscription->get_clients()) { its_subscription->set_state(its_client, subscription_state_e::ST_NOT_ACKNOWLEDGED); } @@ -1770,7 +1785,7 @@ service_discovery_impl::process_eventgroupentry( const std::vector<std::shared_ptr<option_impl> > &_options, std::shared_ptr<remote_subscription_ack> &_acknowledgement, const boost::asio::ip::address &_sender, - const boost::asio::ip::address &_destination, + bool _is_multicast, bool _is_stop_subscribe_subscribe, bool _force_initial_events, const sd_acceptance_state_t& _sd_ac_state) { @@ -1835,8 +1850,8 @@ service_discovery_impl::process_eventgroupentry( return; } - if(its_type == entry_type_e::SUBSCRIBE_EVENTGROUP) { - if (_destination.is_multicast() ) { + if (its_type == entry_type_e::SUBSCRIBE_EVENTGROUP) { + if (_is_multicast) { boost::system::error_code ec; VSOMEIP_ERROR << __func__ << ": Received a SubscribeEventGroup entry on multicast address " @@ -1874,7 +1889,7 @@ service_discovery_impl::process_eventgroupentry( } if (_options.size() // cast is needed in order to get unsigned type since int will be promoted - // by the + operator on 16 bit or higher machines. + // by the + operator on 16 bit or higher machines. < static_cast<std::vector<std::shared_ptr<option_impl>>::size_type>( (_entry->get_num_options(1)) + (_entry->get_num_options(2)))) { boost::system::error_code ec; @@ -1916,10 +1931,7 @@ service_discovery_impl::process_eventgroupentry( std::shared_ptr < option_impl > its_option; try { its_option = _options.at(its_index); - } catch(const std::out_of_range& e) { -#ifdef _WIN32 - e; // silence MSVC warning C4101 -#endif + } catch(const std::out_of_range&) { boost::system::error_code ec; VSOMEIP_ERROR << __func__ << ": Fewer options in SD message than " @@ -2335,7 +2347,6 @@ service_discovery_impl::handle_eventgroup_subscription( // check if TCP connection is established by client if (_ttl > 0 && !is_tcp_connected(_service, _instance, its_reliable)) { insert_subscription_ack(_acknowledgement, _info, 0, nullptr, _clients); - boost::system::error_code ec; // TODO: Add sender and session id VSOMEIP_ERROR << "TCP connection to target1: [" << its_reliable->get_address().to_string() @@ -2365,7 +2376,6 @@ service_discovery_impl::handle_eventgroup_subscription( // check if TCP connection is established by client if (_ttl > 0 && !is_tcp_connected(_service, _instance, its_reliable)) { insert_subscription_ack(_acknowledgement, _info, 0, nullptr, _clients); - boost::system::error_code ec; // TODO: Add sender and session id VSOMEIP_ERROR << "TCP connection to target2 : [" << its_reliable->get_address().to_string() @@ -2456,10 +2466,10 @@ service_discovery_impl::handle_eventgroup_subscription_nack( auto found_eventgroup = found_instance->second.find(_eventgroup); if (found_eventgroup != found_instance->second.end()) { auto its_subscription = found_eventgroup->second; - for (const auto& its_client : _clients) { + for (const auto its_client : _clients) { host_->on_subscribe_nack(its_client, _service, _instance, _eventgroup, ANY_EVENT, - PENDING_SUBSCRIPTION_ID, false); // TODO: This is a dummy call... + PENDING_SUBSCRIPTION_ID); // TODO: This is a dummy call... } @@ -2491,7 +2501,7 @@ service_discovery_impl::handle_eventgroup_subscription_ack( if (found_instance != found_service->second.end()) { auto found_eventgroup = found_instance->second.find(_eventgroup); if (found_eventgroup != found_instance->second.end()) { - for (const auto& its_client : _clients) { + for (const auto its_client : _clients) { if (found_eventgroup->second->get_state(its_client) == subscription_state_e::ST_NOT_ACKNOWLEDGED) { found_eventgroup->second->set_state(its_client, @@ -2521,7 +2531,7 @@ bool service_discovery_impl::is_tcp_connected(service_t _service, auto its_reliable_server_endpoint = std::dynamic_pointer_cast< tcp_server_endpoint_impl>(its_info->get_endpoint(true)); if (its_reliable_server_endpoint - && its_reliable_server_endpoint->is_established(its_endpoint)) { + && its_reliable_server_endpoint->is_established_to(its_endpoint)) { is_connected = true; } } @@ -2538,7 +2548,7 @@ service_discovery_impl::send( std::pair<session_t, bool> its_session = get_session(unicast_); m->set_session(its_session.first); m->set_reboot_flag(its_session.second); - if (host_->send(VSOMEIP_SD_CLIENT, m)) { + if (host_->send(VSOMEIP_SD_CLIENT, m, true)) { increment_session(unicast_); } } else { @@ -2583,10 +2593,21 @@ service_discovery_impl::serialize_and_send( } void -service_discovery_impl::start_ttl_timer() { +service_discovery_impl::start_ttl_timer(int _shift) { + std::lock_guard<std::mutex> its_lock(ttl_timer_mutex_); + + std::chrono::milliseconds its_timeout(ttl_timer_runtime_); + if (_shift > 0) { + if (its_timeout.count() > _shift) + its_timeout -= std::chrono::milliseconds(_shift); + + if (its_timeout.count() > VSOMEIP_MINIMUM_CHECK_TTL_TIMEOUT) + its_timeout = std::chrono::milliseconds(VSOMEIP_MINIMUM_CHECK_TTL_TIMEOUT); + } + boost::system::error_code ec; - ttl_timer_.expires_from_now(std::chrono::milliseconds(ttl_timer_runtime_), ec); + ttl_timer_.expires_from_now(its_timeout, ec); ttl_timer_.async_wait( std::bind(&service_discovery_impl::check_ttl, shared_from_this(), std::placeholders::_1)); @@ -2601,12 +2622,20 @@ service_discovery_impl::stop_ttl_timer() { void service_discovery_impl::check_ttl(const boost::system::error_code &_error) { + + static int its_counter(0); // count the times we were not able to call + // update_routing_info if (!_error) { { - std::lock_guard<std::mutex> its_lock(check_ttl_mutex_); - host_->update_routing_info(ttl_timer_runtime_); + std::unique_lock<std::mutex> its_lock(check_ttl_mutex_, std::try_to_lock); + if (its_lock.owns_lock()) { + its_counter = 0; + host_->update_routing_info(ttl_timer_runtime_); + } else { + its_counter++; + } } - start_ttl_timer(); + start_ttl_timer(its_counter * VSOMEIP_MINIMUM_CHECK_TTL_TIMEOUT); } } @@ -2684,11 +2713,11 @@ service_discovery_impl::check_ipv4_address( //Check unallowed ipv4 address bool is_valid = true; - const boost::asio::ip::address_v4::bytes_type its_unicast_address = + static const boost::asio::ip::address_v4::bytes_type its_unicast_address = unicast_.to_v4().to_bytes(); const boost::asio::ip::address_v4::bytes_type endpoint_address = its_address.to_v4().to_bytes(); - const boost::asio::ip::address_v4::bytes_type its_netmask = + static const boost::asio::ip::address_v4::bytes_type its_netmask = configuration_->get_netmask().to_v4().to_bytes(); //same address as unicast address of DUT not allowed @@ -2750,8 +2779,6 @@ service_discovery_impl::start_offer_debounce_timer(bool _first_start) { this, std::placeholders::_1)); } - - void service_discovery_impl::start_find_debounce_timer(bool _first_start) { std::lock_guard<std::mutex> its_lock(find_debounce_timer_mutex_); @@ -2989,7 +3016,6 @@ service_discovery_impl::on_repetition_phase_timer_expired( } } - void service_discovery_impl::on_find_repetition_phase_timer_expired( const boost::system::error_code &_error, @@ -3033,7 +3059,6 @@ service_discovery_impl::on_find_repetition_phase_timer_expired( } } - void service_discovery_impl::move_offers_into_main_phase( const std::shared_ptr<boost::asio::steady_timer> &_timer) { @@ -3051,9 +3076,9 @@ service_discovery_impl::move_offers_into_main_phase( } } -void +bool service_discovery_impl::stop_offer_service( - const std::shared_ptr<serviceinfo> &_info) { + const std::shared_ptr<serviceinfo> &_info, bool _send) { std::lock_guard<std::mutex> its_lock(offer_mutex_); _info->set_ttl(0); const service_t its_service = _info->get_service(); @@ -3106,10 +3131,15 @@ service_discovery_impl::stop_offer_service( } } } - // Sent stop offer - if(_info->is_in_mainphase() || stop_offer_required) { - send_stop_offer(_info); + + if (!_send) { + // stop offer required + return (_info->is_in_mainphase() || stop_offer_required); + } else if(_info->is_in_mainphase() || stop_offer_required) { + // Send stop offer + return send_stop_offer(_info); } + return false; // sent out NACKs for all pending subscriptions // TODO: remote_subscription_not_acknowledge_all(its_service, its_instance); } @@ -3131,11 +3161,30 @@ service_discovery_impl::send_stop_offer(const std::shared_ptr<serviceinfo> &_inf return false; } +bool +service_discovery_impl::send_collected_stop_offers(const std::vector<std::shared_ptr<serviceinfo>> &_infos) { + + std::vector<std::shared_ptr<message_impl> > its_messages; + std::shared_ptr<message_impl> its_current_message( + std::make_shared<message_impl>()); + its_messages.push_back(its_current_message); + + // pack multiple stop offers together + for (auto its_info : _infos) { + if (its_info->get_endpoint(false) || its_info->get_endpoint(true)) { + insert_offer_service(its_messages, its_info); + } + } + + // Serialize and send + return send(its_messages); +} + void service_discovery_impl::start_main_phase_timer() { std::lock_guard<std::mutex> its_lock(main_phase_timer_mutex_); boost::system::error_code ec; - main_phase_timer_.expires_from_now(cyclic_offer_delay_); + main_phase_timer_.expires_from_now(cyclic_offer_delay_, ec); if (ec) { VSOMEIP_ERROR<< "service_discovery_impl::start_main_phase_timer " "setting expiry time of timer failed: " << ec.message(); @@ -3249,7 +3298,6 @@ service_discovery_impl::update_acknowledgement( } } - void service_discovery_impl::update_subscription_expiration_timer( const std::vector<std::shared_ptr<message_impl> > &_messages) { @@ -3426,10 +3474,12 @@ service_discovery_impl::on_last_msg_received_timer_expired( // Rejoin multicast group if (endpoint_ && !reliable_) { - auto its_endpoint = std::dynamic_pointer_cast< - udp_server_endpoint_impl>(endpoint_); - if (its_endpoint) - its_endpoint->join(sd_multicast_); + auto its_server_endpoint + = std::dynamic_pointer_cast<udp_server_endpoint_impl>(endpoint_); + if (its_server_endpoint) { + its_server_endpoint->leave(sd_multicast_); + its_server_endpoint->join(sd_multicast_); + } } { boost::system::error_code ec; @@ -3450,7 +3500,7 @@ service_discovery_impl::stop_last_msg_received_timer() { last_msg_received_timer_.cancel(ec); } -service_discovery_impl::remote_offer_type_e +reliability_type_e service_discovery_impl::get_remote_offer_type( service_t _service, instance_t _instance) const { std::lock_guard<std::mutex> its_lock(remote_offer_types_mutex_); @@ -3458,10 +3508,10 @@ service_discovery_impl::get_remote_offer_type( if (found_si != remote_offer_types_.end()) { return found_si->second; } - return remote_offer_type_e::UNKNOWN; + return reliability_type_e::RT_UNKNOWN; } -service_discovery_impl::remote_offer_type_e +reliability_type_e service_discovery_impl::get_remote_offer_type( const std::shared_ptr<subscription> &_subscription) const { bool has_reliable = (_subscription->get_endpoint(true) != nullptr); @@ -3469,18 +3519,18 @@ service_discovery_impl::get_remote_offer_type( return (has_reliable ? (has_unreliable ? - remote_offer_type_e::RELIABLE_UNRELIABLE : - remote_offer_type_e::RELIABLE) : + reliability_type_e::RT_BOTH : + reliability_type_e::RT_RELIABLE) : (has_unreliable ? - remote_offer_type_e::UNRELIABLE : - remote_offer_type_e::UNKNOWN)); + reliability_type_e::RT_UNRELIABLE : + reliability_type_e::RT_UNKNOWN)); } bool service_discovery_impl::update_remote_offer_type( service_t _service, instance_t _instance, - remote_offer_type_e _offer_type, + reliability_type_e _offer_type, const boost::asio::ip::address &_reliable_address, std::uint16_t _reliable_port, const boost::asio::ip::address &_unreliable_address, @@ -3498,26 +3548,26 @@ service_discovery_impl::update_remote_offer_type( remote_offer_types_[its_si_pair] = _offer_type; } switch (_offer_type) { - case remote_offer_type_e::UNRELIABLE: + case reliability_type_e::RT_UNRELIABLE: remote_offers_by_ip_[_unreliable_address][std::make_pair(false, _unreliable_port)].insert(its_si_pair); break; - case remote_offer_type_e::RELIABLE: + case reliability_type_e::RT_RELIABLE: remote_offers_by_ip_[_reliable_address][std::make_pair(true, _reliable_port)].insert(its_si_pair); break; - case remote_offer_type_e::RELIABLE_UNRELIABLE: + case reliability_type_e::RT_BOTH: remote_offers_by_ip_[_unreliable_address][std::make_pair(false, _unreliable_port)].insert(its_si_pair); remote_offers_by_ip_[_unreliable_address][std::make_pair(true, _reliable_port)].insert(its_si_pair); break; - case remote_offer_type_e::UNKNOWN: + case reliability_type_e::RT_UNKNOWN: default: VSOMEIP_WARNING << __func__ << ": unknown offer type [" << std::hex << std::setw(4) << std::setfill('0') << _service << "." << std::hex << std::setw(4) << std::setfill('0') << _instance << "]" - << _offer_type; + << static_cast<int>(_offer_type); break; } return ret; @@ -3754,13 +3804,13 @@ service_discovery_impl::add_entry_data_to_remote_subscription_ack_msg( void service_discovery_impl::register_sd_acceptance_handler( - sd_acceptance_handler_t _handler) { + const sd_acceptance_handler_t &_handler) { sd_acceptance_handler_ = _handler; } void service_discovery_impl::register_reboot_notification_handler( - reboot_notification_handler_t _handler) { + const reboot_notification_handler_t &_handler) { reboot_notification_handler_ = _handler; } @@ -3775,19 +3825,7 @@ reliability_type_e service_discovery_impl::get_eventgroup_reliability( && its_info->is_reliability_auto_mode()) { // fallback: determine how service is offered // and update reliability type of eventgroup - switch (get_remote_offer_type(_service, _instance)) { - case remote_offer_type_e::RELIABLE: - its_reliability = reliability_type_e::RT_RELIABLE; - break; - case remote_offer_type_e::UNRELIABLE: - its_reliability = reliability_type_e::RT_UNRELIABLE; - break; - case remote_offer_type_e::RELIABLE_UNRELIABLE: - its_reliability = reliability_type_e::RT_BOTH; - break; - default: - ; - } + its_reliability = get_remote_offer_type(_service, _instance); VSOMEIP_WARNING << "sd::" << __func__ << ": couldn't determine eventgroup reliability type for [" << std::hex << std::setw(4) << std::setfill('0') << _service << "." << std::hex << std::setw(4) << std::setfill('0') << _instance << "." @@ -3814,10 +3852,8 @@ reliability_type_e service_discovery_impl::get_eventgroup_reliability( << std::hex << std::setw(4) << std::setfill('0') << _instance << "." << std::hex << std::setw(4) << std::setfill('0') << _eventgroup << "]"; } - return its_reliability; } - } // namespace sd } // namespace vsomeip_v3 diff --git a/implementation/service_discovery/src/serviceentry_impl.cpp b/implementation/service_discovery/src/serviceentry_impl.cpp index 9ea86b1..f3fc70d 100755..100644 --- a/implementation/service_discovery/src/serviceentry_impl.cpp +++ b/implementation/service_discovery/src/serviceentry_impl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. diff --git a/implementation/service_discovery/src/subscription.cpp b/implementation/service_discovery/src/subscription.cpp index 9a95bec..8ceaf1b 100644 --- a/implementation/service_discovery/src/subscription.cpp +++ b/implementation/service_discovery/src/subscription.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -100,7 +100,7 @@ std::set<client_t> subscription::get_clients() const { std::set<client_t> its_clients; { std::lock_guard<std::mutex> its_lock(clients_mutex_); - for (const auto& its_item : clients_) + for (const auto its_item : clients_) its_clients.insert(its_item.first); } return its_clients; |