diff options
author | Jürgen Gehring <Juergen.Gehring@bmw.de> | 2016-09-20 03:59:53 -0700 |
---|---|---|
committer | Jürgen Gehring <Juergen.Gehring@bmw.de> | 2016-09-20 03:59:53 -0700 |
commit | 273814c76be4a8f906dc053492529b8d53b9e807 (patch) | |
tree | e7160dc68fe3f478a0c5c86aaccaeb620d528b63 /implementation/service_discovery/include | |
parent | 4c5d160362d8693aed8abd642212e68c9778bbda (diff) | |
download | vSomeIP-273814c76be4a8f906dc053492529b8d53b9e807.tar.gz |
vSomeIP 2.2.42.2.4
Diffstat (limited to 'implementation/service_discovery/include')
27 files changed, 333 insertions, 88 deletions
diff --git a/implementation/service_discovery/include/configuration_option_impl.hpp b/implementation/service_discovery/include/configuration_option_impl.hpp index de8a97f..d2351bc 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-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// Copyright (C) 2014-2016 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/constants.hpp b/implementation/service_discovery/include/constants.hpp index cc476a7..01c55cb 100644 --- a/implementation/service_discovery/include/constants.hpp +++ b/implementation/service_discovery/include/constants.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2016 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 2d23c3c..52c7216 100644 --- a/implementation/service_discovery/include/defines.hpp +++ b/implementation/service_discovery/include/defines.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2016 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,14 +6,24 @@ #ifndef VSOMEIP_SD_DEFINES_HPP #define VSOMEIP_SD_DEFINES_HPP +#include "../../configuration/include/internal.hpp" + +#define VSOMEIP_MAX_TCP_SD_PAYLOAD 4075 // Available for entries & options +#define VSOMEIP_MAX_UDP_SD_PAYLOAD 1380 + #define VSOMEIP_SOMEIP_SD_DATA_SIZE 12 #define VSOMEIP_SOMEIP_SD_ENTRY_SIZE 16 +#define VSOMEIP_SOMEIP_SD_IPV4_OPTION_SIZE 12 +#define VSOMEIP_SOMEIP_SD_IPV6_OPTION_SIZE 24 #define VSOMEIP_SOMEIP_SD_OPTION_HEADER_SIZE 3 +#define VSOMEIP_SD_IPV4_OPTION_LENGTH 0x0009 +#define VSOMEIP_SD_IPV6_OPTION_LENGTH 0x0015 + #define VSOMEIP_SD_SERVICE 0xFFFF #define VSOMEIP_SD_INSTANCE 0x0000 #define VSOMEIP_SD_METHOD 0x8100 -#define VSOMEIP_SD_CLIENT 0x0000 +#define VSOMEIP_SD_CLIENT (VSOMEIP_DIAGNOSIS_ADDRESS << 8) // SIP_SD_1139 #define VSOMEIP_SD_DEFAULT_ENABLED true @@ -25,7 +35,7 @@ #define VSOMEIP_SD_DEFAULT_INITIAL_DELAY_MAX 3000 #define VSOMEIP_SD_DEFAULT_REPETITIONS_BASE_DELAY 10 #define VSOMEIP_SD_DEFAULT_REPETITIONS_MAX 3 -#define VSOMEIP_SD_DEFAULT_TTL 5 +#define VSOMEIP_SD_DEFAULT_TTL DEFAULT_TTL #define VSOMEIP_SD_DEFAULT_CYCLIC_OFFER_DELAY 1000 #define VSOMEIP_SD_DEFAULT_REQUEST_RESPONSE_DELAY 2000 diff --git a/implementation/service_discovery/include/deserializer.hpp b/implementation/service_discovery/include/deserializer.hpp index 1625e80..085bc7c 100755 --- a/implementation/service_discovery/include/deserializer.hpp +++ b/implementation/service_discovery/include/deserializer.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// Copyright (C) 2014-2016 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 fde425c..25f08d2 100755 --- a/implementation/service_discovery/include/entry_impl.hpp +++ b/implementation/service_discovery/include/entry_impl.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// Copyright (C) 2014-2016 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/.
@@ -46,8 +46,7 @@ public: void set_ttl(ttl_t _ttl);
const std::vector<uint8_t> & get_options(uint8_t _run) const;
- void assign_option(const std::shared_ptr<option_impl> &_option,
- uint8_t _run);
+ void assign_option(const std::shared_ptr<option_impl> &_option);
bool is_service_entry() const;
bool is_eventgroup_entry() const;
diff --git a/implementation/service_discovery/include/enumeration_types.hpp b/implementation/service_discovery/include/enumeration_types.hpp index 016fdae..6fb66f2 100644 --- a/implementation/service_discovery/include/enumeration_types.hpp +++ b/implementation/service_discovery/include/enumeration_types.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2016 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 cde7497..0eb8893 100755 --- a/implementation/service_discovery/include/eventgroupentry_impl.hpp +++ b/implementation/service_discovery/include/eventgroupentry_impl.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// Copyright (C) 2014-2016 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/.
@@ -20,11 +20,22 @@ public: eventgroup_t get_eventgroup() const;
void set_eventgroup(eventgroup_t _eventgroup);
+ uint16_t get_reserved() const;
+ void set_reserved(uint16_t _reserved);
+
+ uint8_t get_counter() const;
+ void set_counter(uint8_t _counter);
+
bool serialize(vsomeip::serializer *_to) const;
bool deserialize(vsomeip::deserializer *_from);
private:
eventgroup_t eventgroup_;
+ uint16_t reserved_;
+
+ // counter field to differentiate parallel subscriptions on same event group
+ // 4Bit only (max 16. parralel subscriptions)
+ uint8_t counter_;
};
} // namespace sd
diff --git a/implementation/service_discovery/include/fsm_base.hpp b/implementation/service_discovery/include/fsm_base.hpp index 13b7158..ede92d3 100644 --- a/implementation/service_discovery/include/fsm_base.hpp +++ b/implementation/service_discovery/include/fsm_base.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2016 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,15 +19,17 @@ public: fsm_base(boost::asio::io_service &_io); virtual ~fsm_base(); - void start_timer(uint32_t _ms); - void stop_timer(); + void start_timer(uint32_t _ms, bool _use_alt_timer = false); + void stop_timer(bool _use_alt_timer = false); - uint32_t expired_from_now(); + uint32_t expired_from_now(bool _use_alt_timer = false); - virtual void timer_expired(const boost::system::error_code &_error) = 0; + virtual void timer_expired(const boost::system::error_code &_error, + bool _use_alt_timer) = 0; private: boost::asio::system_timer timer_; + boost::asio::system_timer alt_timer_; }; } // namespace sd diff --git a/implementation/service_discovery/include/fsm_events.hpp b/implementation/service_discovery/include/fsm_events.hpp index 1624b00..75279e2 100644 --- a/implementation/service_discovery/include/fsm_events.hpp +++ b/implementation/service_discovery/include/fsm_events.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2016 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/. @@ -9,6 +9,7 @@ #include <boost/statechart/event.hpp> #include <vsomeip/primitive_types.hpp> +#include "../../routing/include/serviceinfo.hpp" namespace sc = boost::statechart; @@ -21,6 +22,9 @@ struct ev_none: sc::event<ev_none> { struct ev_timeout: sc::event<ev_timeout> { }; +struct ev_alt_timeout: sc::event<ev_alt_timeout> { +}; + struct ev_status_change: sc::event<ev_status_change> { ev_status_change(bool _is_up) : is_up_(_is_up) { @@ -31,22 +35,25 @@ struct ev_status_change: sc::event<ev_status_change> { struct ev_find_service: sc::event<ev_find_service> { - ev_find_service(service_t _service, instance_t _instance, - major_version_t _major, minor_version_t _minor, ttl_t _ttl) - : service_(_service), instance_(_instance), major_(_major), minor_( - _minor), ttl_(_ttl) { + ev_find_service(const std::shared_ptr<const serviceinfo> &_info, service_t _service, instance_t _instance, + major_version_t _major, minor_version_t _minor, bool _unicast_flag) + : info_(_info), service_(_service), instance_(_instance), major_(_major), minor_( + _minor), unicast_flag_(_unicast_flag) { } - + const std::shared_ptr<const serviceinfo> &info_; service_t service_; instance_t instance_; major_version_t major_; minor_version_t minor_; - ttl_t ttl_; + bool unicast_flag_; }; struct ev_offer_change: sc::event<ev_offer_change> { }; +struct ev_request_service: sc::event<ev_request_service> { +}; + } // namespace sd } // namespace vsomeip diff --git a/implementation/service_discovery/include/ip_option_impl.hpp b/implementation/service_discovery/include/ip_option_impl.hpp index 8fd426b..e753b4e 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-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2016 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/ipv4_option_impl.hpp b/implementation/service_discovery/include/ipv4_option_impl.hpp index b8051cc..c233f0f 100644 --- a/implementation/service_discovery/include/ipv4_option_impl.hpp +++ b/implementation/service_discovery/include/ipv4_option_impl.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// Copyright (C) 2014-2016 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/ipv6_option_impl.hpp b/implementation/service_discovery/include/ipv6_option_impl.hpp index 48938b0..c2b962f 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-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// Copyright (C) 2014-2016 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/load_balancing_option_impl.hpp b/implementation/service_discovery/include/load_balancing_option_impl.hpp index 0308a06..7504657 100755 --- 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-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// Copyright (C) 2014-2016 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_element_impl.hpp b/implementation/service_discovery/include/message_element_impl.hpp index 39ae3a1..c05b76e 100755 --- 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-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// Copyright (C) 2014-2016 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 b0702df..a8573b8 100755 --- a/implementation/service_discovery/include/message_impl.hpp +++ b/implementation/service_discovery/include/message_impl.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// Copyright (C) 2014-2016 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/.
@@ -14,6 +14,16 @@ #include "../include/primitive_types.hpp"
#include "../../message/include/message_base_impl.hpp"
+# if _MSC_VER >= 1300
+/*
+* Diamond inheritance is used for the vsomeip::message_base base class.
+* The Microsoft compiler put warning (C4250) using a desired c++ feature: "Delegating to a sister class"
+* A powerful technique that arises from using virtual inheritance is to delegate a method from a class in another class
+* by using a common abstract base class. This is also called cross delegation.
+*/
+# pragma warning( disable : 4250 )
+# endif
+
namespace vsomeip {
namespace sd {
diff --git a/implementation/service_discovery/include/option_impl.hpp b/implementation/service_discovery/include/option_impl.hpp index 90a6a48..21e8b9c 100644 --- a/implementation/service_discovery/include/option_impl.hpp +++ b/implementation/service_discovery/include/option_impl.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// Copyright (C) 2014-2016 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/primitive_types.hpp b/implementation/service_discovery/include/primitive_types.hpp index fd12698..13f4478 100644 --- a/implementation/service_discovery/include/primitive_types.hpp +++ b/implementation/service_discovery/include/primitive_types.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2016 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/protection_option_impl.hpp b/implementation/service_discovery/include/protection_option_impl.hpp index 565b22b..e1f8d1e 100755 --- 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-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// Copyright (C) 2014-2016 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 9e62deb..99fe507 100644 --- a/implementation/service_discovery/include/request.hpp +++ b/implementation/service_discovery/include/request.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2016 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,10 +29,15 @@ public: ttl_t get_ttl() const; void set_ttl(ttl_t _ttl); + uint8_t get_sent_counter() const; + void set_sent_counter(uint8_t _sent_counter); + private: major_version_t major_; minor_version_t minor_; ttl_t ttl_; + + uint8_t sent_counter_; }; } // namespace sd diff --git a/implementation/service_discovery/include/runtime.hpp b/implementation/service_discovery/include/runtime.hpp index 47255a2..656e2d5 100644 --- a/implementation/service_discovery/include/runtime.hpp +++ b/implementation/service_discovery/include/runtime.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// Copyright (C) 2014-2016 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 cc0e14e..111d56e 100644 --- a/implementation/service_discovery/include/runtime_impl.hpp +++ b/implementation/service_discovery/include/runtime_impl.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2016 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/service_discovery.hpp b/implementation/service_discovery/include/service_discovery.hpp index 894de0c..ebc81fa 100644 --- a/implementation/service_discovery/include/service_discovery.hpp +++ b/implementation/service_discovery/include/service_discovery.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2016 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,6 +11,8 @@ #include <vsomeip/primitive_types.hpp> #include <vsomeip/enumeration_types.hpp> +#include "../../routing/include/serviceinfo.hpp" +#include "../../endpoints/include/endpoint.hpp" namespace vsomeip { @@ -41,12 +43,28 @@ public: eventgroup_t _eventgroup, client_t _client) = 0; virtual void unsubscribe_all(service_t _service, instance_t _instance) = 0; - virtual void send(bool _is_announcing) = 0; + virtual bool send(bool _is_announcing, bool _is_find = false) = 0; virtual void on_message(const byte_t *_data, length_t _length, - const boost::asio::ip::address &_sender) = 0; + const boost::asio::ip::address &_sender, + const boost::asio::ip::address &_destination) = 0; virtual void on_offer_change() = 0; + + virtual void send_subscriptions(service_t _service, instance_t _instance, + client_t _client, bool _reliable) = 0; + + virtual void send_unicast_offer_service(const std::shared_ptr<const serviceinfo> &_info, + service_t _service, instance_t _instance, + major_version_t _major, + minor_version_t _minor) = 0; + virtual void send_multicast_offer_service(const std::shared_ptr<const serviceinfo>& _info, + service_t _service, instance_t _instance, + major_version_t _major, + minor_version_t _minor) = 0; + virtual void on_reliable_endpoint_connected( + service_t _service, instance_t _instance, + const std::shared_ptr<const vsomeip::endpoint> &_endpoint) = 0; }; } // namespace sd diff --git a/implementation/service_discovery/include/service_discovery_fsm.hpp b/implementation/service_discovery/include/service_discovery_fsm.hpp index f3fe7fd..915b3e3 100644 --- a/implementation/service_discovery/include/service_discovery_fsm.hpp +++ b/implementation/service_discovery/include/service_discovery_fsm.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2016 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/. @@ -14,6 +14,8 @@ #include <boost/statechart/state.hpp> #include <boost/statechart/state_machine.hpp> #include <boost/statechart/transition.hpp> +#include "../../routing/include/serviceinfo.hpp" + #include "../include/fsm_base.hpp" #include "../include/fsm_events.hpp" @@ -40,7 +42,8 @@ struct fsm: sc::state_machine<fsm, inactive>, public fsm_base { void set_fsm(std::shared_ptr<service_discovery_fsm> _fsm); - void timer_expired(const boost::system::error_code &_error); + void timer_expired(const boost::system::error_code &_error, + bool _use_alt_timeout); uint32_t initial_delay_; uint32_t repetitions_base_delay_; @@ -95,9 +98,15 @@ struct repeat: sc::state<repeat, active> { sc::result react(const ev_find_service &_event); }; -struct announce: sc::state<announce, active> { +struct offer; +struct find; +struct main: sc::state<main, active, mpl::list<offer, find>> { + main(my_context _context); +}; + +struct offer: sc::state<offer, main::orthogonal<0> > { - announce(my_context _context); + offer(my_context _context); typedef mpl::list<sc::custom_reaction<ev_timeout>, sc::custom_reaction<ev_find_service>, @@ -106,9 +115,39 @@ struct announce: sc::state<announce, active> { sc::result react(const ev_timeout &_event); sc::result react(const ev_find_service &_event); sc::result react(const ev_offer_change &_event); + + uint8_t run_; +}; + +struct idle; +struct find: sc::state<find, main::orthogonal<1>, idle> { + + find(my_context _context); + + uint8_t run_; +}; + +struct idle: sc::state<idle, find> { + idle(my_context _context); + + typedef mpl::list<sc::custom_reaction<ev_request_service> >reactions; + + sc::result react(const ev_request_service &_event); }; -} // namespace _offer +struct send: sc::state<send, find> { + send(my_context _context); + + typedef mpl::list< + sc::custom_reaction<ev_alt_timeout>, + sc::custom_reaction<ev_none> + > reactions; + + sc::result react(const ev_alt_timeout &_event); + sc::result react(const ev_none &_event); +}; + +} // namespace _sd /////////////////////////////////////////////////////////////////////////////// // Interface @@ -121,13 +160,36 @@ public: void start(); void stop(); - void send(bool _is_announcing); + bool send(bool _is_announcing, bool _is_find = false); + + void send_unicast_offer_service( + const std::shared_ptr<const serviceinfo> &_info, + service_t _service, instance_t _instance, + major_version_t _major, + minor_version_t _minor); + + void send_multicast_offer_service( + const std::shared_ptr<const serviceinfo> &_info, + service_t _service, instance_t _instance, + major_version_t _major, + minor_version_t _minor); inline void process(const sc::event_base &_event) { std::lock_guard<std::mutex> its_lock(lock_); fsm_->process_event(_event); } + inline uint8_t get_repetition_max() const { + if (!fsm_) + return 0; + + return fsm_->repetitions_max_; + } + + std::chrono::milliseconds get_elapsed_offer_timer(); + + bool check_is_multicast_offer(); + private: std::weak_ptr<service_discovery> discovery_; std::shared_ptr<_sd::fsm> fsm_; diff --git a/implementation/service_discovery/include/service_discovery_host.hpp b/implementation/service_discovery/include/service_discovery_host.hpp index 27d8007..1795d89 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-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2016 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/. @@ -41,7 +41,7 @@ public: bool _flush) = 0; virtual bool send_to(const std::shared_ptr<endpoint_definition> &_target, - const byte_t *_data, uint32_t _size) = 0; + const byte_t *_data, uint32_t _size, uint16_t _sd_port) = 0; virtual void add_routing_info(service_t _service, instance_t _instance, major_version_t _major, minor_version_t _minor, ttl_t _ttl, @@ -53,12 +53,14 @@ public: virtual void del_routing_info(service_t _service, instance_t _instance, bool _has_reliable, bool _has_unreliable) = 0; - virtual ttl_t update_routing_info(ttl_t _elapsed) = 0; + virtual std::chrono::milliseconds update_routing_info( + std::chrono::milliseconds _elapsed) = 0; virtual void on_subscribe(service_t _service, instance_t _instance, eventgroup_t _eventgroup, std::shared_ptr<endpoint_definition> _subscriber, - std::shared_ptr<endpoint_definition> _target) = 0; + std::shared_ptr<endpoint_definition> _target, + const std::chrono::high_resolution_clock::time_point &_expiration) = 0; virtual void on_unsubscribe(service_t _service, instance_t _instance, eventgroup_t _eventgroup, @@ -67,11 +69,27 @@ public: virtual void on_subscribe_ack(service_t _service, instance_t _instance, const boost::asio::ip::address &_address, uint16_t _port) = 0; - virtual std::shared_ptr<endpoint> find_or_create_remote_client(service_t _service, - instance_t _instance, bool _reliable, client_t _client) = 0; + virtual void on_subscribe_ack(client_t _client, + service_t _service, instance_t _instance, eventgroup_t _eventgroup) = 0; + + virtual std::shared_ptr<endpoint> find_or_create_remote_client( + service_t _service, instance_t _instance, + bool _reliable, client_t _client) = 0; virtual void expire_subscriptions(const boost::asio::ip::address &_address) = 0; virtual void expire_services(const boost::asio::ip::address &_address) = 0; + + virtual bool on_subscribe_accepted(service_t _service, instance_t _instance, + eventgroup_t _eventgroup, std::shared_ptr<endpoint_definition> _target, + const std::chrono::high_resolution_clock::time_point &_expiration) = 0; + + virtual void on_subscribe_nack(client_t _client, + service_t _service, instance_t _instance, eventgroup_t _eventgroup) = 0; + + virtual bool has_identified(client_t _client, service_t _service, + instance_t _instance, bool _reliable) = 0; + + virtual std::chrono::high_resolution_clock::time_point expire_subscriptions() = 0; }; } // namespace sd diff --git a/implementation/service_discovery/include/service_discovery_impl.hpp b/implementation/service_discovery/include/service_discovery_impl.hpp index 7efb6eb..4e64328 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-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2016 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/. @@ -14,8 +14,11 @@ #include <boost/asio/system_timer.hpp> #include "service_discovery.hpp" +#include "../../endpoints/include/endpoint_definition.hpp" #include "../../routing/include/types.hpp" #include "ip_option_impl.hpp" +#include "ipv4_option_impl.hpp" +#include "ipv6_option_impl.hpp" namespace vsomeip { @@ -35,6 +38,15 @@ class subscription; typedef std::map<service_t, std::map<instance_t, std::shared_ptr<request> > > requests_t; +struct accepted_subscriber_t { + std::shared_ptr < endpoint_definition > subscriber; + std::shared_ptr < endpoint_definition > target; + std::chrono::high_resolution_clock::time_point its_expiration; + vsomeip::service_t service_id; + vsomeip::instance_t instance_id; + vsomeip::eventgroup_t eventgroup_; +}; + class service_discovery_impl: public service_discovery, public std::enable_shared_from_this<service_discovery_impl> { public: @@ -59,18 +71,36 @@ public: eventgroup_t _eventgroup, client_t _client); void unsubscribe_all(service_t _service, instance_t _instance); - void send(bool _is_announcing); + bool send(bool _is_announcing, bool _is_find); void on_message(const byte_t *_data, length_t _length, - const boost::asio::ip::address &_sender); + const boost::asio::ip::address &_sender, + const boost::asio::ip::address &_destination); void on_offer_change(); + void send_unicast_offer_service(const std::shared_ptr<const serviceinfo> &_info, + service_t _service, instance_t _instance, + major_version_t _major, + minor_version_t _minor); + + void send_multicast_offer_service(const std::shared_ptr<const serviceinfo>& _info, + service_t _service, instance_t _instance, + major_version_t _major, + minor_version_t _minor); + + void on_reliable_endpoint_connected( + service_t _service, instance_t _instance, + const std::shared_ptr<const vsomeip::endpoint> &_endpoint); + 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 &_address, + bool is_reboot(const boost::asio::ip::address &_sender, + const boost::asio::ip::address &_destination, bool _reboot_flag, session_t _session); void insert_option(std::shared_ptr<message_impl> &_message, @@ -78,24 +108,29 @@ private: const boost::asio::ip::address &_address, uint16_t _port, bool _is_reliable); void insert_find_entries(std::shared_ptr<message_impl> &_message, - requests_t &_requests); + requests_t &_requests, uint32_t _start, uint32_t &_size, bool &_done); void insert_offer_entries(std::shared_ptr<message_impl> &_message, - services_t &_services); - void insert_offer_service(std::shared_ptr<message_impl> _message, + services_t &_services, uint32_t &_start, uint32_t _size, bool &_done); + bool insert_offer_service(std::shared_ptr<message_impl> _message, service_t _service, instance_t _instance, - const std::shared_ptr<const serviceinfo> &_info); + const std::shared_ptr<const serviceinfo> &_info, + uint32_t &_size); void insert_subscription(std::shared_ptr<message_impl> &_message, service_t _service, instance_t _instance, eventgroup_t _eventgroup, + std::shared_ptr<subscription> &_subscription, bool _insert_reliable, bool _insert_unreliable); + void insert_nack_subscription_on_resubscribe(std::shared_ptr<message_impl> &_message, + service_t _service, instance_t _instance, eventgroup_t _eventgroup, std::shared_ptr<subscription> &_subscription); void insert_subscription_ack(std::shared_ptr<message_impl> &_message, service_t _service, instance_t _instance, eventgroup_t _eventgroup, - std::shared_ptr<eventgroupinfo> &_info, ttl_t _ttl); + std::shared_ptr<eventgroupinfo> &_info, ttl_t _ttl, uint8_t _counter, major_version_t _major, uint16_t _reserved); void insert_subscription_nack(std::shared_ptr<message_impl> &_message, service_t _service, instance_t _instance, eventgroup_t _eventgroup, - std::shared_ptr<eventgroupinfo> &_info); + uint8_t _counter, major_version_t _major, uint16_t _reserved); void process_serviceentry(std::shared_ptr<serviceentry_impl> &_entry, - const std::vector<std::shared_ptr<option_impl> > &_options); + const std::vector<std::shared_ptr<option_impl> > &_options, + bool _unicast_flag); void process_offerservice_serviceentry( service_t _service, instance_t _instance, major_version_t _major, minor_version_t _minor, ttl_t _ttl, @@ -103,39 +138,63 @@ private: uint16_t _reliable_port, const boost::asio::ip::address &_unreliable_address, uint16_t _unreliable_port); - void send_unicast_offer_service(const std::shared_ptr<const serviceinfo>& _info, - service_t _service, instance_t _instance, - major_version_t _major, - minor_version_t _minor); - void process_findservice_serviceentry(service_t _service, - instance_t _instance, - major_version_t _major, - minor_version_t _minor); - void process_eventgroupentry(std::shared_ptr<eventgroupentry_impl> &_entry, - const std::vector<std::shared_ptr<option_impl> > &_options); + void send_offer_service( + const std::shared_ptr<const serviceinfo> &_info, service_t _service, + instance_t _instance, major_version_t _major, minor_version_t _minor, + bool _unicast_flag); + void process_findservice_serviceentry(service_t _service, + instance_t _instance, + major_version_t _major, + minor_version_t _minor, + bool _unicast_flag); + void process_eventgroupentry( + std::shared_ptr<eventgroupentry_impl> &_entry, + const std::vector<std::shared_ptr<option_impl> > &_options, + std::shared_ptr < message_impl > &its_message_response, + std::vector <accepted_subscriber_t> &accepted_subscribers); void handle_eventgroup_subscription(service_t _service, instance_t _instance, eventgroup_t _eventgroup, - major_version_t _major, ttl_t _ttl, - const boost::asio::ip::address &_reliable_address, - uint16_t _reliable_port, uint16_t _unreliable_port); + major_version_t _major, ttl_t _ttl, uint8_t _counter, uint16_t _reserved, + const boost::asio::ip::address &_first_address, uint16_t _first_port, + bool _is_first_reliable, + const boost::asio::ip::address &_second_address, uint16_t _second_port, + bool _is_second_reliable, + std::shared_ptr < message_impl > &its_message, + std::vector <accepted_subscriber_t> &accepted_subscribers); void handle_eventgroup_subscription_ack(service_t _service, instance_t _instance, eventgroup_t _eventgroup, - major_version_t _major, ttl_t _ttl, + major_version_t _major, ttl_t _ttl, uint8_t _counter, const boost::asio::ip::address &_address, uint16_t _port); + void handle_eventgroup_subscription_nack(service_t _service, + instance_t _instance, eventgroup_t _eventgroup, uint8_t _counter); void serialize_and_send(std::shared_ptr<message_impl> _message, const boost::asio::ip::address &_address); + bool is_tcp_connected(service_t _service, + instance_t _instance, + std::shared_ptr<vsomeip::endpoint_definition> its_endpoint); + void start_ttl_timer(); - ttl_t stop_ttl_timer(); + std::chrono::milliseconds stop_ttl_timer(); + void check_ttl(const boost::system::error_code &_error); boost::asio::ip::address get_current_remote_address() const; + + void start_subscription_expiration_timer(); + void stop_subscription_expiration_timer(); + void expire_subscriptions(const boost::system::error_code &_error); + + bool check_ipv4_address(boost::asio::ip::address its_address); + bool check_static_header_fields( const std::shared_ptr<const message> &_message) const; void send_eventgroup_subscription_nack(service_t _service, instance_t _instance, eventgroup_t _eventgroup, - major_version_t _major); + major_version_t _major, + uint8_t _counter, + uint16_t _reserved); bool check_layer_four_protocol( const std::shared_ptr<const ip_option_impl> _ip_option) const; void get_subscription_endpoints(subscription_type_e _subscription_type, @@ -146,6 +205,28 @@ private: service_t _service, instance_t _instance, client_t _client) const; + void send_subscriptions(service_t _service, instance_t _instance, client_t _client, bool _reliable); + + template<class Option, typename AddressType> + std::shared_ptr<option_impl> find_existing_option( + std::shared_ptr<message_impl> &_message, + AddressType _address, uint16_t _port, + layer_four_protocol_e _protocol, + option_type_e _option_type); + template<class Option, typename AddressType> + bool check_message_for_ip_option_and_assign_existing( + std::shared_ptr<message_impl> &_message, + std::shared_ptr<entry_impl> _entry, AddressType _address, + uint16_t _port, layer_four_protocol_e _protocol, + option_type_e _option_type); + template<class Option, typename AddressType> + void assign_ip_option_to_entry(std::shared_ptr<Option> _option, + AddressType _address, uint16_t _port, + layer_four_protocol_e _protocol, + std::shared_ptr<entry_impl> _entry); + + std::shared_ptr<request> find_request(service_t _service, instance_t _instance); + private: boost::asio::io_service &io_; service_discovery_host *host_; @@ -165,25 +246,31 @@ private: std::mutex requested_mutex_; std::map<service_t, std::map<instance_t, - std::map<eventgroup_t, std::map<client_t, std::shared_ptr<subscription> > > > > subscribed_; + std::map<eventgroup_t, + std::map<client_t, + std::shared_ptr<subscription> > > > > subscribed_; std::mutex subscribed_mutex_; std::mutex serialize_mutex_; // Sessions - std::map<boost::asio::ip::address, std::pair<session_t, bool> > sessions_; - std::map<boost::asio::ip::address, session_t > sessions_receiving_; - - // Reboots - std::set<boost::asio::ip::address> reboots_; + std::map<boost::asio::ip::address, std::pair<session_t, bool> > sessions_sent_; + std::map<boost::asio::ip::address, + std::tuple<session_t, session_t, bool> > sessions_received_; // Runtime std::weak_ptr<runtime> runtime_; - // TTL handling + // TTL handling for services offered by other hosts boost::asio::system_timer ttl_timer_; - ttl_t smallest_ttl_; + std::chrono::milliseconds smallest_ttl_; ttl_t ttl_; + + // TTL handling for subscriptions done by other hosts + boost::asio::system_timer subscription_expiration_timer_; + std::chrono::high_resolution_clock::time_point next_subscription_expiration_; + + uint32_t max_message_size_; }; } // namespace sd diff --git a/implementation/service_discovery/include/serviceentry_impl.hpp b/implementation/service_discovery/include/serviceentry_impl.hpp index f83e62a..1385f84 100644 --- a/implementation/service_discovery/include/serviceentry_impl.hpp +++ b/implementation/service_discovery/include/serviceentry_impl.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// Copyright (C) 2014-2016 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 25df7b3..eb2fb66 100644 --- a/implementation/service_discovery/include/subscription.hpp +++ b/implementation/service_discovery/include/subscription.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +// Copyright (C) 2014-2016 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,6 +6,7 @@ #ifndef VSOMEIP_SD_SUBSCRIPTION_HPP #define VSOMEIP_SD_SUBSCRIPTION_HPP +#include <chrono> #include <memory> #include <vsomeip/primitive_types.hpp> @@ -22,7 +23,9 @@ public: subscription(major_version_t _major, ttl_t _ttl, std::shared_ptr<endpoint> _reliable, std::shared_ptr<endpoint> _unreliable, - subscription_type_e _subscription_type); + subscription_type_e _subscription_type, + uint8_t _counter, + std::chrono::high_resolution_clock::time_point _expiration); ~subscription(); major_version_t get_major() const; @@ -34,8 +37,16 @@ public: bool is_acknowledged() const; void set_acknowledged(bool _is_acknowledged); + bool is_tcp_connection_established() const; + void set_tcp_connection_established(bool _is_established); + subscription_type_e get_subscription_type() const; + uint8_t get_counter() const; + + std::chrono::high_resolution_clock::time_point get_expiration() const; + void set_expiration(std::chrono::high_resolution_clock::time_point _expiration); + private: major_version_t major_; ttl_t ttl_; @@ -44,8 +55,13 @@ private: std::shared_ptr<endpoint> unreliable_; bool is_acknowledged_; + bool tcp_connection_established_; subscription_type_e subscription_type_; + + uint8_t counter_; + + std::chrono::high_resolution_clock::time_point expiration_; }; } // namespace sd |