diff options
author | Diogo Pedrosa <diogo12pedrosa@gmail.com> | 2023-03-09 17:57:35 +0000 |
---|---|---|
committer | Diogo Pedrosa <diogo12pedrosa@gmail.com> | 2023-03-10 14:41:51 +0000 |
commit | 826ebb8d352245a36ecaec32b6af61e7abf4696e (patch) | |
tree | d4e984dd100f3257ce784c9e30aefb6e60a93ab5 /implementation/service_discovery | |
parent | fc73f40fa1501dc53210c63cb7c0d7623d106370 (diff) | |
download | vSomeIP-826ebb8d352245a36ecaec32b6af61e7abf4696e.tar.gz |
vsomeip 3.3.0
Diffstat (limited to 'implementation/service_discovery')
45 files changed, 303 insertions, 262 deletions
diff --git a/implementation/service_discovery/include/configuration_option_impl.hpp b/implementation/service_discovery/include/configuration_option_impl.hpp index 567762d..e1dde72 100644 --- a/implementation/service_discovery/include/configuration_option_impl.hpp +++ b/implementation/service_discovery/include/configuration_option_impl.hpp @@ -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/. @@ -25,7 +25,7 @@ public: configuration_option_impl(); virtual ~configuration_option_impl(); - bool operator==(const option_impl &_other) const; + bool equals(const option_impl &_other) const; void add_item(const std::string &_key, const std::string &_value); void remove_item(const std::string &_key); diff --git a/implementation/service_discovery/include/constants.hpp b/implementation/service_discovery/include/constants.hpp index c50fac1..3ebb259 100644 --- a/implementation/service_discovery/include/constants.hpp +++ b/implementation/service_discovery/include/constants.hpp @@ -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/include/defines.hpp b/implementation/service_discovery/include/defines.hpp index b7e840b..b7642f1 100644 --- a/implementation/service_discovery/include/defines.hpp +++ b/implementation/service_discovery/include/defines.hpp @@ -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/. @@ -12,7 +12,7 @@ #define VSOMEIP_SOMEIP_SD_DATA_SIZE 12 #define VSOMEIP_SOMEIP_SD_ENTRY_LENGTH_SIZE 4 #define VSOMEIP_SOMEIP_SD_ENTRY_SIZE 16 -#define VSOMEIP_SOMEIP_SD_IPV4_OPTION_SIZE 12 +#define VSOMEIP_SOMEIP_SD_IPV3_OPTION_SIZE 12 #define VSOMEIP_SOMEIP_SD_IPV6_OPTION_SIZE 24 #define VSOMEIP_SOMEIP_SD_LOAD_BALANCING_OPTION_SIZE 8 #define VSOMEIP_SOMEIP_SD_PROTECTION_OPTION_SIZE 12 diff --git a/implementation/service_discovery/include/deserializer.hpp b/implementation/service_discovery/include/deserializer.hpp index 97ebcd4..866ebda 100755..100644 --- a/implementation/service_discovery/include/deserializer.hpp +++ b/implementation/service_discovery/include/deserializer.hpp @@ -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/include/entry_impl.hpp b/implementation/service_discovery/include/entry_impl.hpp index 39d5416..ed22c8f 100755..100644 --- a/implementation/service_discovery/include/entry_impl.hpp +++ b/implementation/service_discovery/include/entry_impl.hpp @@ -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/include/enumeration_types.hpp b/implementation/service_discovery/include/enumeration_types.hpp index 63d0378..0b6c71b 100644 --- a/implementation/service_discovery/include/enumeration_types.hpp +++ b/implementation/service_discovery/include/enumeration_types.hpp @@ -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/include/eventgroupentry_impl.hpp b/implementation/service_discovery/include/eventgroupentry_impl.hpp index 08b25a6..efb9b07 100755..100644 --- a/implementation/service_discovery/include/eventgroupentry_impl.hpp +++ b/implementation/service_discovery/include/eventgroupentry_impl.hpp @@ -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/include/ip_option_impl.hpp b/implementation/service_discovery/include/ip_option_impl.hpp index c83d745..842be84 100644 --- a/implementation/service_discovery/include/ip_option_impl.hpp +++ b/implementation/service_discovery/include/ip_option_impl.hpp @@ -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,7 +19,7 @@ public: ip_option_impl(); ip_option_impl(const uint16_t _port, const bool _is_reliable); virtual ~ip_option_impl(); - virtual bool operator ==(const option_impl &_other) const; + bool equals(const option_impl &_other) const; uint16_t get_port() const; void set_port(uint16_t _port); diff --git a/implementation/service_discovery/include/ipv4_option_impl.hpp b/implementation/service_discovery/include/ipv4_option_impl.hpp index 15c04b2..7e97078 100644 --- a/implementation/service_discovery/include/ipv4_option_impl.hpp +++ b/implementation/service_discovery/include/ipv4_option_impl.hpp @@ -1,10 +1,10 @@ -// 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/. -#ifndef VSOMEIP_V3_SD_IPV4_OPTION_IMPL_HPP_ -#define VSOMEIP_V3_SD_IPV4_OPTION_IMPL_HPP_ +#ifndef VSOMEIP_V3_SD_IPV3_OPTION_IMPL_HPP_ +#define VSOMEIP_V3_SD_IPV3_OPTION_IMPL_HPP_ #include <boost/asio/ip/address.hpp> @@ -22,7 +22,7 @@ public: const uint16_t _port, const bool _is_reliable); virtual ~ipv4_option_impl(); - bool operator ==(const option_impl &_other) const; + bool equals(const option_impl &_other) const; const ipv4_address_t & get_address() const; void set_address(const ipv4_address_t &_address); @@ -38,5 +38,5 @@ private: } // namespace sd } // namespace vsomeip_v3 -#endif // VSOMEIP_V3_SD_IPV4_OPTION_IMPL_HPP_ +#endif // VSOMEIP_V3_SD_IPV3_OPTION_IMPL_HPP_ diff --git a/implementation/service_discovery/include/ipv6_option_impl.hpp b/implementation/service_discovery/include/ipv6_option_impl.hpp index d896300..17a613b 100644 --- a/implementation/service_discovery/include/ipv6_option_impl.hpp +++ b/implementation/service_discovery/include/ipv6_option_impl.hpp @@ -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/. @@ -23,7 +23,7 @@ public: const uint16_t _port, const bool _is_reliable); virtual ~ipv6_option_impl(); - bool operator ==(const option_impl &_other) const; + bool equals(const option_impl &_other) const; const ipv6_address_t & get_address() const; void set_address(const ipv6_address_t &_address); diff --git a/implementation/service_discovery/include/load_balancing_option_impl.hpp b/implementation/service_discovery/include/load_balancing_option_impl.hpp index dafcfc7..15fa917 100755..100644 --- a/implementation/service_discovery/include/load_balancing_option_impl.hpp +++ b/implementation/service_discovery/include/load_balancing_option_impl.hpp @@ -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/. @@ -17,7 +17,7 @@ public: load_balancing_option_impl(); virtual ~load_balancing_option_impl(); - bool operator ==(const option_impl &_other) const; + bool equals(const option_impl &_other) const; priority_t get_priority() const; void set_priority(priority_t _priority); diff --git a/implementation/service_discovery/include/message_element_impl.hpp b/implementation/service_discovery/include/message_element_impl.hpp index 29b5d86..2ce979b 100755..100644 --- a/implementation/service_discovery/include/message_element_impl.hpp +++ b/implementation/service_discovery/include/message_element_impl.hpp @@ -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/include/message_impl.hpp b/implementation/service_discovery/include/message_impl.hpp index b9e858d..faeb9d6 100755..100644 --- a/implementation/service_discovery/include/message_impl.hpp +++ b/implementation/service_discovery/include/message_impl.hpp @@ -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/. @@ -36,7 +36,7 @@ class serviceentry_impl; class option_impl; class configuration_option_impl; -class ipv4_option_impl; +class ipv3_option_impl; class ipv6_option_impl; class load_balancing_option_impl; class protection_option_impl; @@ -45,8 +45,8 @@ class selective_option_impl; class message_impl : public vsomeip_v3::message, public vsomeip_v3::message_base_impl { public: - typedef std::vector<std::shared_ptr<entry_impl>> entries_t; - typedef std::vector<std::shared_ptr<option_impl>> options_t; + using entries_t = std::vector<std::shared_ptr<entry_impl>>; + using options_t = std::vector<std::shared_ptr<option_impl>>; struct forced_initial_events_t { std::shared_ptr<vsomeip_v3::endpoint_definition> target_; vsomeip_v3::service_t service_; @@ -104,6 +104,8 @@ public: uid_t get_uid() const; gid_t get_gid() const; + vsomeip_sec_client_t get_sec_client() const; + std::string get_env() const; private: entry_impl * deserialize_entry(vsomeip_v3::deserializer *_from); diff --git a/implementation/service_discovery/include/option_impl.hpp b/implementation/service_discovery/include/option_impl.hpp index e171c74..3c898b6 100644 --- a/implementation/service_discovery/include/option_impl.hpp +++ b/implementation/service_discovery/include/option_impl.hpp @@ -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/. @@ -26,8 +26,7 @@ public: option_impl(); virtual ~option_impl(); - virtual bool operator ==(const option_impl &_other) const; - bool equals(const std::shared_ptr<option_impl> &_other) const; + virtual bool equals(const option_impl &_other) const; uint16_t get_length() const; option_type_e get_type() const; diff --git a/implementation/service_discovery/include/primitive_types.hpp b/implementation/service_discovery/include/primitive_types.hpp index fd093e9..cf152c8 100644 --- a/implementation/service_discovery/include/primitive_types.hpp +++ b/implementation/service_discovery/include/primitive_types.hpp @@ -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/. @@ -12,15 +12,15 @@ namespace vsomeip_v3 { namespace sd { // Load balancing -typedef uint16_t priority_t; -typedef uint16_t weight_t; +using priority_t = std::uint16_t; +using weight_t = std::uint16_t; // Protection -typedef uint32_t alive_counter_t; -typedef uint32_t crc_t; +using alive_counter_t = std::uint32_t; +using crc_t = std::uint32_t; // -typedef uint8_t flags_t; +using flags_t = std::uint8_t; } // namespace sd } // namespace vsomeip_v3 diff --git a/implementation/service_discovery/include/protection_option_impl.hpp b/implementation/service_discovery/include/protection_option_impl.hpp index 792d7cc..7e34eb5 100755..100644 --- a/implementation/service_discovery/include/protection_option_impl.hpp +++ b/implementation/service_discovery/include/protection_option_impl.hpp @@ -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/. @@ -17,7 +17,7 @@ public: protection_option_impl(); virtual ~protection_option_impl(); - bool operator ==(const option_impl &_other) const; + bool equals(const option_impl &_other) const; alive_counter_t get_alive_counter() const; void set_alive_counter(alive_counter_t _counter); diff --git a/implementation/service_discovery/include/remote_subscription_ack.hpp b/implementation/service_discovery/include/remote_subscription_ack.hpp index 1bc8792..7b2b635 100644 --- a/implementation/service_discovery/include/remote_subscription_ack.hpp +++ b/implementation/service_discovery/include/remote_subscription_ack.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 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/include/request.hpp b/implementation/service_discovery/include/request.hpp index 0e6e2ec..4d4dba0 100644 --- a/implementation/service_discovery/include/request.hpp +++ b/implementation/service_discovery/include/request.hpp @@ -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/include/runtime.hpp b/implementation/service_discovery/include/runtime.hpp index 0772de4..fe9f27b 100644 --- a/implementation/service_discovery/include/runtime.hpp +++ b/implementation/service_discovery/include/runtime.hpp @@ -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/include/runtime_impl.hpp b/implementation/service_discovery/include/runtime_impl.hpp index 0010de6..1b5bfa4 100644 --- a/implementation/service_discovery/include/runtime_impl.hpp +++ b/implementation/service_discovery/include/runtime_impl.hpp @@ -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/include/selective_option_impl.hpp b/implementation/service_discovery/include/selective_option_impl.hpp index 863408f..b4d7bcb 100644 --- a/implementation/service_discovery/include/selective_option_impl.hpp +++ b/implementation/service_discovery/include/selective_option_impl.hpp @@ -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/. @@ -25,7 +25,7 @@ public: selective_option_impl(); virtual ~selective_option_impl(); - bool operator==(const option_impl &_other) const; + bool equals(const option_impl &_other) const; std::set<client_t> get_clients() const; void set_clients(const std::set<client_t> &_clients); diff --git a/implementation/service_discovery/include/service_discovery.hpp b/implementation/service_discovery/include/service_discovery.hpp index 77b4258..cab33a8 100644 --- a/implementation/service_discovery/include/service_discovery.hpp +++ b/implementation/service_discovery/include/service_discovery.hpp @@ -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/. @@ -6,7 +6,6 @@ #ifndef VSOMEIP_V3_SD_SERVICE_DISCOVERY_HPP_ #define VSOMEIP_V3_SD_SERVICE_DISCOVERY_HPP_ -#include <boost/asio/io_service.hpp> #include <boost/asio/ip/address.hpp> #include <vsomeip/primitive_types.hpp> @@ -28,7 +27,7 @@ public: virtual ~service_discovery() { } - virtual boost::asio::io_service & get_io() = 0; + virtual boost::asio::io_context &get_io() = 0; virtual void init() = 0; virtual void start() = 0; @@ -51,14 +50,15 @@ public: virtual void on_message(const byte_t *_data, length_t _length, const boost::asio::ip::address &_sender, - const boost::asio::ip::address &_destination) = 0; + bool _is_multicast) = 0; virtual void on_endpoint_connected( service_t _service, instance_t _instance, const std::shared_ptr<endpoint> &_endpoint) = 0; virtual void offer_service(const std::shared_ptr<serviceinfo> &_info) = 0; - virtual void stop_offer_service(const std::shared_ptr<serviceinfo> &_info) = 0; + virtual bool stop_offer_service(const std::shared_ptr<serviceinfo> &_info, bool _send) = 0; + virtual bool send_collected_stop_offers(const std::vector<std::shared_ptr<serviceinfo>> &_infos) = 0; virtual void set_diagnosis_mode(const bool _activate) = 0; @@ -68,9 +68,9 @@ public: const std::shared_ptr<remote_subscription> &_subscription) = 0; virtual void register_sd_acceptance_handler( - sd_acceptance_handler_t _handler) = 0; + const sd_acceptance_handler_t &_handler) = 0; virtual void register_reboot_notification_handler( - reboot_notification_handler_t _handler) = 0; + const reboot_notification_handler_t &_handler) = 0; }; } // namespace sd diff --git a/implementation/service_discovery/include/service_discovery_host.hpp b/implementation/service_discovery/include/service_discovery_host.hpp index 0f992d7..09b5301 100644 --- a/implementation/service_discovery/include/service_discovery_host.hpp +++ b/implementation/service_discovery/include/service_discovery_host.hpp @@ -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/. @@ -11,7 +11,12 @@ #include <chrono> #include <boost/asio/ip/address.hpp> -#include <boost/asio/io_service.hpp> +#if VSOMEIP_BOOST_VERSION < 106600 +# include <boost/asio/io_service.hpp> +# define io_context io_service +#else +# include <boost/asio/io_context.hpp> +#endif #include "../../routing/include/function_types.hpp" #include "../../routing/include/types.hpp" @@ -31,7 +36,7 @@ public: virtual ~service_discovery_host() { } - virtual boost::asio::io_service & get_io() = 0; + virtual boost::asio::io_context &get_io() = 0; virtual std::shared_ptr<endpoint> create_service_discovery_endpoint( const std::string &_address, uint16_t _port, bool _reliable) = 0; @@ -40,7 +45,8 @@ public: virtual std::shared_ptr<eventgroupinfo> find_eventgroup(service_t _service, instance_t _instance, eventgroup_t _eventgroup) const = 0; - virtual bool send(client_t _client, std::shared_ptr<message> _message) = 0; + virtual bool send(client_t _client, std::shared_ptr<message> _message, + bool _force) = 0; virtual bool send_via_sd(const std::shared_ptr<endpoint_definition> &_target, const byte_t *_data, uint32_t _size, uint16_t _sd_port) = 0; @@ -86,7 +92,7 @@ public: virtual void on_subscribe_nack(client_t _client, service_t _service, instance_t _instance, eventgroup_t _eventgroup, - event_t _event, remote_subscription_id_t _subscription_id, bool _simulated) = 0; + event_t _event, remote_subscription_id_t _subscription_id) = 0; virtual std::chrono::steady_clock::time_point expire_subscriptions(bool _force) = 0; diff --git a/implementation/service_discovery/include/service_discovery_impl.hpp b/implementation/service_discovery/include/service_discovery_impl.hpp index c4e3835..b2270e1 100644 --- a/implementation/service_discovery/include/service_discovery_impl.hpp +++ b/implementation/service_discovery/include/service_discovery_impl.hpp @@ -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/. @@ -44,11 +44,7 @@ class serviceentry_impl; class service_discovery_host; class subscription; -typedef std::map<service_t, - std::map<instance_t, - std::shared_ptr<request> - > - > requests_t; +using requests_t = std::map<service_t, std::map<instance_t, std::shared_ptr<request>>>; struct entry_data_t { std::shared_ptr<entry_impl> entry_; @@ -63,7 +59,7 @@ public: const std::shared_ptr<configuration>& _configuration); virtual ~service_discovery_impl(); - boost::asio::io_service & get_io(); + boost::asio::io_context &get_io(); void init(); void start(); @@ -86,14 +82,15 @@ public: void on_message(const byte_t *_data, length_t _length, const boost::asio::ip::address &_sender, - const boost::asio::ip::address &_destination); + bool _is_multicast); void on_endpoint_connected( service_t _service, instance_t _instance, const std::shared_ptr<endpoint> &_endpoint); void offer_service(const std::shared_ptr<serviceinfo> &_info); - void stop_offer_service(const std::shared_ptr<serviceinfo> &_info); + bool stop_offer_service(const std::shared_ptr<serviceinfo> &_info, bool _send); + bool send_collected_stop_offers(const std::vector<std::shared_ptr<serviceinfo>> &_infos); void set_diagnosis_mode(const bool _activate); @@ -103,16 +100,19 @@ public: void update_remote_subscription( const std::shared_ptr<remote_subscription> &_subscription); - void register_sd_acceptance_handler(sd_acceptance_handler_t _handler); + void register_sd_acceptance_handler(const sd_acceptance_handler_t &_handler); void register_reboot_notification_handler( - reboot_notification_handler_t _handler); + const reboot_notification_handler_t &_handler); private: std::pair<session_t, bool> get_session(const boost::asio::ip::address &_address); void increment_session(const boost::asio::ip::address &_address); bool is_reboot(const boost::asio::ip::address &_sender, - const boost::asio::ip::address &_destination, - bool _reboot_flag, session_t _session); + bool _is_multicast, bool _reboot_flag, session_t _session); + + bool check_session_id_sequence(const boost::asio::ip::address &_sender, + const bool _is_multicast, const session_t &_session, + session_t &_missing_session); void insert_find_entries(std::vector<std::shared_ptr<message_impl> > &_messages, const requests_t &_requests); @@ -120,12 +120,6 @@ private: const services_t &_services, bool _ignore_phase); void insert_offer_service(std::vector<std::shared_ptr<message_impl> > &_messages, const std::shared_ptr<const serviceinfo> &_info); - enum remote_offer_type_e : std::uint8_t { - RELIABLE_UNRELIABLE, - RELIABLE, - UNRELIABLE, - UNKNOWN = 0xff - }; entry_data_t create_eventgroup_entry( service_t _service, instance_t _instance, eventgroup_t _eventgroup, @@ -138,7 +132,7 @@ private: const std::shared_ptr<endpoint_definition> &_target, const std::set<client_t> &_clients); - typedef std::set<std::pair<bool, std::uint16_t>> expired_ports_t; + using expired_ports_t = std::set<std::pair<bool, std::uint16_t>>; struct sd_acceptance_state_t { explicit sd_acceptance_state_t(expired_ports_t& _expired_ports) : expired_ports_(_expired_ports), @@ -178,7 +172,7 @@ private: 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); void handle_eventgroup_subscription(service_t _service, @@ -215,7 +209,7 @@ private: instance_t _instance, const std::shared_ptr<endpoint_definition>& its_endpoint); - void start_ttl_timer(); + void start_ttl_timer(int _shift = 0); void stop_ttl_timer(); void check_ttl(const boost::system::error_code &_error); @@ -310,13 +304,13 @@ private: void on_last_msg_received_timer_expired(const boost::system::error_code &_error); void stop_last_msg_received_timer(); - remote_offer_type_e get_remote_offer_type( + reliability_type_e get_remote_offer_type( service_t _service, instance_t _instance) const; - remote_offer_type_e get_remote_offer_type( + reliability_type_e get_remote_offer_type( const std::shared_ptr<subscription> &_subscription) const; bool 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, @@ -362,7 +356,7 @@ private: const std::shared_ptr<subscription>& _subscription); private: - boost::asio::io_service &io_; + boost::asio::io_context &io_; service_discovery_host *host_; std::shared_ptr<configuration> configuration_; @@ -463,7 +457,7 @@ private: std::chrono::milliseconds last_msg_received_timer_timeout_; mutable std::mutex remote_offer_types_mutex_; - std::map<std::pair<service_t, instance_t>, remote_offer_type_e> remote_offer_types_; + std::map<std::pair<service_t, instance_t>, reliability_type_e> remote_offer_types_; std::map<boost::asio::ip::address, std::map<std::pair<bool, std::uint16_t>, std::set<std::pair<service_t, instance_t>>>> remote_offers_by_ip_; @@ -479,4 +473,3 @@ private: } // namespace vsomeip_v3 #endif // VSOMEIP_V3_SD_SERVICE_DISCOVERY_IMPL_ - diff --git a/implementation/service_discovery/include/serviceentry_impl.hpp b/implementation/service_discovery/include/serviceentry_impl.hpp index f7b2b92..8e1cf70 100644 --- a/implementation/service_discovery/include/serviceentry_impl.hpp +++ b/implementation/service_discovery/include/serviceentry_impl.hpp @@ -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/include/subscription.hpp b/implementation/service_discovery/include/subscription.hpp index adbd66c..8c1e074 100644 --- a/implementation/service_discovery/include/subscription.hpp +++ b/implementation/service_discovery/include/subscription.hpp @@ -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/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; |