diff options
author | Lutz Bichler <Lutz.Bichler@bmw.de> | 2015-02-10 09:13:03 +0100 |
---|---|---|
committer | Lutz Bichler <Lutz.Bichler@bmw.de> | 2015-02-10 09:13:03 +0100 |
commit | 03409d2b56a28bd3a9111da2cd16e950544a9a39 (patch) | |
tree | f3257bea9fa3f84bf6f8ce8a7c3bf9d7f51b90e8 | |
parent | 0900dc5544fc68f9dca7e298cab851b99015c000 (diff) | |
download | vSomeIP-03409d2b56a28bd3a9111da2cd16e950544a9a39.tar.gz |
Fixed handling of Magic Cookies. Adapted configuration files. Added a
description to run the tests.
-rw-r--r-- | config/vsomeip-local-tcp-client.json | 83 | ||||
-rw-r--r-- | config/vsomeip-local-tcp-service.json | 82 | ||||
-rw-r--r-- | config/vsomeip-magic-cookies-client.json | 59 | ||||
-rw-r--r-- | config/vsomeip-magic-cookies-service.json | 57 | ||||
-rw-r--r-- | config/vsomeip-tcp-client.json | 6 | ||||
-rw-r--r-- | config/vsomeip-tcp-service.json | 25 | ||||
-rw-r--r-- | examples/response-sample.cpp | 242 | ||||
-rw-r--r-- | implementation/endpoints/include/endpoint_impl.hpp | 2 | ||||
-rw-r--r-- | implementation/endpoints/src/endpoint_impl.cpp | 21 | ||||
-rw-r--r-- | implementation/endpoints/src/tcp_client_endpoint_impl.cpp | 33 | ||||
-rw-r--r-- | implementation/endpoints/src/tcp_server_endpoint_impl.cpp | 243 | ||||
-rw-r--r-- | implementation/routing/src/routing_manager_impl.cpp | 8 | ||||
-rw-r--r-- | test/magic-cookies-test-client.cpp | 4 | ||||
-rw-r--r-- | test/readme.txt | 86 |
14 files changed, 657 insertions, 294 deletions
diff --git a/config/vsomeip-local-tcp-client.json b/config/vsomeip-local-tcp-client.json new file mode 100644 index 0000000..eecd9ad --- /dev/null +++ b/config/vsomeip-local-tcp-client.json @@ -0,0 +1,83 @@ +{ + "unicast" : "10.0.2.15", + "netmask" : "255.255.255.0", + "logging" : + { + "level" : "info", + "console" : "true", + "file" : { "enable" : "true", "path" : "/var/log/vsomeip.log" }, + "dlt" : "true" + }, + "applications" : + [ + { + "name" : "client-sample", + "id" : "0x1343" + }, + { + "name" : "second-client-sample", + "id" : "0x1344" + }, + { + "name" : "third-client-sample", + "id" : "0x1345" + }, + { + "name" : "fourth-client-sample", + "id" : "0x1346" + } + ], + "servicegroups" : + [ + { + "name" : "remote", + "unicast" : "192.168.56.104", + "services" : + [ + { + "service" : "0x1234", + "instance" : "0x5678", + "reliable" : { "port" : "30509", "magic-cookies" : false }, + "events" : + [ + { + "event" : "0x0777", + "is_field" : "true" + }, + { + "event" : "0x0778", + "is_field" : "false" + }, + { + "event" : "0x0779", + "is_field" : "true" + } + ], + "eventgroups" : + [ + { + "eventgroup" : "0x4455", + "events" : [ "0x777", "0x778" ] + }, + { + "eventgroup" : "0x4465", + "events" : [ "0x778", "0x779" ] + }, + { + "eventgroup" : "0x4555", + "events" : [ "0x777", "0x779" ] + } + ] + } + ] + } + ], + "routing" : "client-sample", + "service-discovery" : + { + "enable" : "true", + "multicast" : "224.0.0.1", + "port" : "30491", + "protocol" : "udp" + } +} diff --git a/config/vsomeip-local-tcp-service.json b/config/vsomeip-local-tcp-service.json new file mode 100644 index 0000000..7c1fe8b --- /dev/null +++ b/config/vsomeip-local-tcp-service.json @@ -0,0 +1,82 @@ +{ + "unicast" : "10.0.2.15", + "logging" : + { + "level" : "debug", + "console" : "true", + "file" : { "enable" : "false", "path" : "/tmp/vsomeip.log" }, + "dlt" : "false" + }, + "applications" : + [ + { + "name" : "service-sample", + "id" : "0x1277" + } + ], + "servicegroups" : + [ + { + "name" : "default", + "delays" : + { + "initial" : { "minimum" : "10", "maximum" : 100 }, + "repetition-base" : "200", + "repetition-max" : "3", + "cyclic-offer" : "2000", + "cyclic-request" : "2001" + }, + "services" : + [ + { + "service" : "0x1234", + "instance" : "0x5678", + "reliable" : { "port" : "30509", "magic-cookies" : "false" }, + "events" : + [ + { + "event" : "0x0777", + "is_field" : "false", + "is_reliable" : "true", + "update-cycle" : 2000 + }, + { + "event" : "0x0778", + "is_field" : "true", + "is_reliable" : "true", + "update-cycle" : 0 + }, + { + "event" : "0x0779", + "is_field" : "false", + "is_reliable" : "true" + } + ], + "eventgroups" : + [ + { + "eventgroup" : "0x4455", + "events" : [ "0x777", "0x778" ] + }, + { + "eventgroup" : "0x4465", + "events" : [ "0x778", "0x779" ] + }, + { + "eventgroup" : "0x4555", + "events" : [ "0x777", "0x779" ] + } + ] + } + ] + } + ], + "routing" : "service-sample", + "service-discovery" : + { + "enable" : "true", + "multicast" : "224.0.0.1", + "port" : "30490", + "protocol" : "udp" + } +} diff --git a/config/vsomeip-magic-cookies-client.json b/config/vsomeip-magic-cookies-client.json index 828661b..b0982ce 100644 --- a/config/vsomeip-magic-cookies-client.json +++ b/config/vsomeip-magic-cookies-client.json @@ -1,42 +1,73 @@ { "unicast" : "192.168.56.101", - "logging" : - { - "level" : "trace", + "netmask" : "255.255.255.0", + "logging" : + { + "level" : "info", "console" : "true", - "file" : { "enable" : "false", "path" : "/var/log/vsomeip.log" }, - "dlt" : "false" + "file" : { "enable" : "true", "path" : "/var/log/vsomeip.log" }, + "dlt" : "true" }, "applications" : [ { "name" : "client-sample", - "id" : 0x1343 + "id" : "0x1343" }, { "name" : "second-client-sample", - "id" : 0x1344 + "id" : "0x1344" }, { "name" : "third-client-sample", - "id" : 0x1345 + "id" : "0x1345" }, { "name" : "fourth-client-sample", - "id" : 0x1346 + "id" : "0x1346" } ], - "servicegroups" : + "servicegroups" : [ { "name" : "remote", - "address" : "192.168.56.102", - "services" : + "unicast" : "192.168.56.105", + "services" : [ { "service" : "0x1234", "instance" : "0x5678", - "reliable" : { "port" : 30511, "magic-cookies" : "true" }, + "reliable" : { "port" : "30509", "enable-magic-cookies" : "true" }, + "events" : + [ + { + "event" : "0x0777", + "is_field" : "true" + }, + { + "event" : "0x0778", + "is_field" : "false" + }, + { + "event" : "0x0779", + "is_field" : "true" + } + ], + "eventgroups" : + [ + { + "eventgroup" : "0x4455", + "events" : [ "0x777", "0x778" ] + }, + { + "eventgroup" : "0x4465", + "events" : [ "0x778", "0x779" ] + }, + { + "eventgroup" : "0x4555", + "events" : [ "0x777", "0x779" ] + } + ] } ] } @@ -45,7 +76,7 @@ "service-discovery" : { "enable" : "false", - "multicast" : "224.244.224.245", + "multicast" : "224.0.0.1", "port" : "30490", "protocol" : "udp" } diff --git a/config/vsomeip-magic-cookies-service.json b/config/vsomeip-magic-cookies-service.json index ca73fe0..97f7106 100644 --- a/config/vsomeip-magic-cookies-service.json +++ b/config/vsomeip-magic-cookies-service.json @@ -1,13 +1,13 @@ { - "unicast" : "192.168.56.102", + "unicast" : "192.168.56.101", "logging" : { - "level" : "trace", + "level" : "debug", "console" : "true", - "file" : { "enable" : "false", "path" : "/var/log/vsomeip.log" }, + "file" : { "enable" : "false", "path" : "/tmp/vsomeip.log" }, "dlt" : "false" }, - "applications" : + "applications" : [ { "name" : "service-sample", @@ -16,33 +16,68 @@ ], "servicegroups" : [ - { + { "name" : "default", + "unicast" : "local", "delays" : { - "initial" : { minimum : "10", maximum : "100" }, + "initial" : { "minimum" : "10", "maximum" : 100 }, "repetition-base" : "200", "repetition-max" : "3", "cyclic-offer" : "2000", "cyclic-request" : "2001" }, - "services" : + "services" : [ { "service" : "0x1234", "instance" : "0x5678", - "reliable" : { "port" : "30511", "magic-cookies" : "true" }, + "reliable" : { "port" : "30509", "enable-magic-cookies" : "true" }, + "events" : + [ + { + "event" : "0x0777", + "is_field" : "false", + "is_reliable" : "true", + "update-cycle" : 2000 + }, + { + "event" : "0x0778", + "is_field" : "true", + "is_reliable" : "true", + "update-cycle" : 0 + }, + { + "event" : "0x0779", + "is_field" : "false", + "is_reliable" : "true" + } + ], + "eventgroups" : + [ + { + "eventgroup" : "0x4455", + "events" : [ "0x777", "0x778" ] + }, + { + "eventgroup" : "0x4465", + "events" : [ "0x778", "0x779" ] + }, + { + "eventgroup" : "0x4555", + "events" : [ "0x777", "0x779" ] + } + ] } ] } ], "routing" : "service-sample", - "service-discovery" : + "service-discovery" : { "enable" : "false", - "multicast" : "224.244.224.245", + "multicast" : "224.0.0.1", "port" : "30490", "protocol" : "udp" } } - diff --git a/config/vsomeip-tcp-client.json b/config/vsomeip-tcp-client.json index ead6173..17aadbd 100644 --- a/config/vsomeip-tcp-client.json +++ b/config/vsomeip-tcp-client.json @@ -31,13 +31,13 @@ [ { "name" : "remote", - "unicast" : "192.168.56.104", + "unicast" : "192.168.56.105", "services" : [ { "service" : "0x1234", "instance" : "0x5678", - "reliable" : { "port" : "30509", "magic-cookies" : false }, + "reliable" : { "port" : "30509", "enable-magic-cookies" : false }, "events" : [ { @@ -76,7 +76,7 @@ "service-discovery" : { "enable" : "true", - "multicast" : "224.0.0.1", + "multicast" : "224.244.224.245", "port" : "30490", "protocol" : "udp" } diff --git a/config/vsomeip-tcp-service.json b/config/vsomeip-tcp-service.json index e0311ab..3f344a6 100644 --- a/config/vsomeip-tcp-service.json +++ b/config/vsomeip-tcp-service.json @@ -1,5 +1,5 @@ { - "unicast" : "192.168.56.104", + "unicast" : "192.168.56.101", "logging" : { "level" : "debug", @@ -18,9 +18,14 @@ [ { "name" : "default", + "unicast" : "local", "delays" : { - "initial" : { "minimum" : "10", "maximum" : 100 }, + "initial" : + { + "minimum" : "10", + "maximum" : 100 + }, "repetition-base" : "200", "repetition-max" : "3", "cyclic-offer" : "2000", @@ -31,7 +36,7 @@ { "service" : "0x1234", "instance" : "0x5678", - "reliable" : { "port" : "30509", "magic-cookies" : "false" }, + "reliable" : { "port" : "30509", "enable-magic-cookies" : "false" }, "events" : [ { @@ -67,7 +72,17 @@ "events" : [ "0x777", "0x779" ] } ] - } + }, + { + "service" : "0x1235", + "instance" : "0x5678", + "unreliable" : "30509", + "multicast" : + { + "address" : "224.225.226.234", + "port" : "32344" + } + } ] } ], @@ -75,7 +90,7 @@ "service-discovery" : { "enable" : "true", - "multicast" : "224.0.0.1", + "multicast" : "224.244.224.245", "port" : "30490", "protocol" : "udp" } diff --git a/examples/response-sample.cpp b/examples/response-sample.cpp index 54b1137..f782969 100644 --- a/examples/response-sample.cpp +++ b/examples/response-sample.cpp @@ -16,123 +16,137 @@ #include "sample-ids.hpp" class service_sample { - public: - service_sample(bool _use_tcp) - : app_(vsomeip::runtime::get()->create_application()), - is_registered_(false), - use_tcp_(_use_tcp), - offer_thread_(std::bind(&service_sample::run, this)) { - } - - void init() { - std::lock_guard < std::mutex > its_lock(mutex_); - - app_->init(); - app_->register_message_handler( - SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_METHOD_ID, - std::bind(&service_sample::on_message, this, std::placeholders::_1)); - - app_->register_event_handler( - std::bind(&service_sample::on_event, this, std::placeholders::_1)); - } - - void start() { - app_->start(); - } - - void offer() { - app_->offer_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID); - app_->offer_service(SAMPLE_SERVICE_ID + 1, SAMPLE_INSTANCE_ID); - } - - void stop_offer() { - app_->stop_offer_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID); - app_->stop_offer_service(SAMPLE_SERVICE_ID + 1, SAMPLE_INSTANCE_ID); - } - - void on_event(vsomeip::event_type_e _event) { - VSOMEIP_INFO << "Application " << app_->get_name() << " is " - << (_event == vsomeip::event_type_e::REGISTERED ? - "registered." : "deregistered."); - - if (_event == vsomeip::event_type_e::REGISTERED) { - if (!is_registered_) { - is_registered_ = true; - blocked_ = true; - condition_.notify_one(); - } - } else { - is_registered_ = false; - } - } - - void on_message(std::shared_ptr<vsomeip::message> &_request) { - VSOMEIP_INFO << "Received a message with Client/Session [" << std::setw(4) - << std::setfill('0') << std::hex << _request->get_client() << "/" - << std::setw(4) << std::setfill('0') << std::hex - << _request->get_session() << "]"; - - std::shared_ptr<vsomeip::message> its_response = vsomeip::runtime::get() - ->create_response(_request); - - std::shared_ptr<vsomeip::payload> its_payload = vsomeip::runtime::get() - ->create_payload(); - std::vector<vsomeip::byte_t> its_payload_data; - for (std::size_t i = 0; i < 120; ++i) - its_payload_data.push_back(i % 256); - its_payload->set_data(its_payload_data); - its_response->set_payload(its_payload); - - app_->send(its_response, true, use_tcp_); - } - - void run() { - std::unique_lock<std::mutex> its_lock(mutex_); - while (!blocked_) - condition_.wait(its_lock); - - bool is_offer(true); - while (true) { - if (is_offer) - offer(); - else - stop_offer(); - std::this_thread::sleep_for(std::chrono::milliseconds(10000)); - is_offer = !is_offer; - } - } +public: + service_sample(bool _use_tcp, bool _use_static_routing) : + app_(vsomeip::runtime::get()->create_application()), is_registered_( + false), use_tcp_(_use_tcp), use_static_routing_( + _use_static_routing), offer_thread_( + std::bind(&service_sample::run, this)) { + } + + void init() { + std::lock_guard<std::mutex> its_lock(mutex_); + + app_->init(); + app_->register_message_handler( + SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_METHOD_ID, + std::bind(&service_sample::on_message, this, + std::placeholders::_1)); + + app_->register_event_handler( + std::bind(&service_sample::on_event, this, + std::placeholders::_1)); + + VSOMEIP_INFO<< "Static routing " << (use_static_routing_ ? "ON" : "OFF"); + } + + void start() { + app_->start(); + } + + void offer() { + app_->offer_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID); + app_->offer_service(SAMPLE_SERVICE_ID + 1, SAMPLE_INSTANCE_ID); + } + + void stop_offer() { + app_->stop_offer_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID); + app_->stop_offer_service(SAMPLE_SERVICE_ID + 1, SAMPLE_INSTANCE_ID); + } + + void on_event(vsomeip::event_type_e _event) { + VSOMEIP_INFO << "Application " << app_->get_name() << " is " + << (_event == vsomeip::event_type_e::REGISTERED ? + "registered." : "deregistered."); + + if (_event == vsomeip::event_type_e::REGISTERED) { + if (!is_registered_) { + is_registered_ = true; + blocked_ = true; + condition_.notify_one(); + } + } else { + is_registered_ = false; + } + } + + void on_message(std::shared_ptr<vsomeip::message> &_request) { + VSOMEIP_INFO << "Received a message with Client/Session [" << std::setw(4) + << std::setfill('0') << std::hex << _request->get_client() << "/" + << std::setw(4) << std::setfill('0') << std::hex + << _request->get_session() << "]"; + + std::shared_ptr<vsomeip::message> its_response = vsomeip::runtime::get() + ->create_response(_request); + + std::shared_ptr<vsomeip::payload> its_payload = vsomeip::runtime::get() + ->create_payload(); + std::vector<vsomeip::byte_t> its_payload_data; + for (std::size_t i = 0; i < 120; ++i) + its_payload_data.push_back(i % 256); + its_payload->set_data(its_payload_data); + its_response->set_payload(its_payload); + + app_->send(its_response, true, use_tcp_); + } + + void run() { + std::unique_lock<std::mutex> its_lock(mutex_); + while (!blocked_) + condition_.wait(its_lock); + + bool is_offer(true); + + if (use_static_routing_) { + offer(); + while (true); + } else { + while (true) { + if (is_offer) + offer(); + else + stop_offer(); + std::this_thread::sleep_for(std::chrono::milliseconds(10000)); + is_offer = !is_offer; + } + } + } private: - std::shared_ptr<vsomeip::application> app_; - bool is_registered_; - bool use_tcp_; - - std::thread offer_thread_; - std::mutex mutex_; - std::condition_variable condition_; - bool blocked_; + std::shared_ptr<vsomeip::application> app_; + bool is_registered_; + bool use_tcp_; + bool use_static_routing_; + + std::thread offer_thread_; + std::mutex mutex_; + std::condition_variable condition_; + bool blocked_; }; int main(int argc, char **argv) { - bool use_tcp = false; - - std::string tcp_enable("--tcp"); - std::string udp_enable("--udp"); - - for (int i = 1; i < argc; i++) { - if (tcp_enable == argv[i]) { - use_tcp = true; - break; - } - if (udp_enable == argv[i]) { - use_tcp = false; - break; - } - } - - service_sample its_sample(use_tcp); - its_sample.init(); - its_sample.start(); - - return 0; + bool use_tcp(false); + bool use_static_routing(false); + + std::string tcp_enable("--tcp"); + std::string udp_enable("--udp"); + std::string static_routing_enable("--static-routing"); + + for (int i = 1; i < argc; i++) { + if (tcp_enable == argv[i]) { + use_tcp = true; + } + if (udp_enable == argv[i]) { + use_tcp = false; + } + if (static_routing_enable == argv[i]) { + use_static_routing = true; + } + } + + service_sample its_sample(use_tcp, use_static_routing); + its_sample.init(); + its_sample.start(); + + return 0; } diff --git a/implementation/endpoints/include/endpoint_impl.hpp b/implementation/endpoints/include/endpoint_impl.hpp index 8e4bd9f..058c9cd 100644 --- a/implementation/endpoints/include/endpoint_impl.hpp +++ b/implementation/endpoints/include/endpoint_impl.hpp @@ -49,7 +49,7 @@ public: // required protected:
virtual bool is_magic_cookie() const;
- bool resync_on_magic_cookie(message_buffer_t &_buffer);
+ uint32_t find_magic_cookie(message_buffer_t &_buffer);
protected:
// Reference to service context
diff --git a/implementation/endpoints/src/endpoint_impl.cpp b/implementation/endpoints/src/endpoint_impl.cpp index f22771a..63c2c18 100644 --- a/implementation/endpoints/src/endpoint_impl.cpp +++ b/implementation/endpoints/src/endpoint_impl.cpp @@ -37,10 +37,10 @@ bool endpoint_impl< MaxBufferSize >::is_magic_cookie() const { }
template < int MaxBufferSize >
-bool endpoint_impl< MaxBufferSize >::resync_on_magic_cookie(message_buffer_t &_buffer) {
- bool is_resynced = false;
+uint32_t endpoint_impl< MaxBufferSize >::find_magic_cookie(message_buffer_t &_buffer) {
+ bool is_found(false);
+ uint32_t its_offset = 0xFFFFFFFF;
if (has_enabled_magic_cookies_) {
- uint32_t its_offset = 0xFFFFFFFF;
uint8_t its_cookie_identifier, its_cookie_type;
if (is_client()) {
@@ -56,9 +56,9 @@ bool endpoint_impl< MaxBufferSize >::resync_on_magic_cookie(message_buffer_t &_b }
do {
- its_offset++;
+ its_offset++; // --> first loop has "its_offset = 0"
if (_buffer.size() > its_offset + 16) {
- is_resynced = (
+ is_found = (
_buffer[its_offset] == 0xFF &&
_buffer[its_offset+1] == 0xFF &&
_buffer[its_offset+2] == its_cookie_identifier &&
@@ -80,17 +80,10 @@ bool endpoint_impl< MaxBufferSize >::resync_on_magic_cookie(message_buffer_t &_b break;
}
- } while (!is_resynced);
-
- if (is_resynced) {
- _buffer.erase(_buffer.begin(),
- _buffer.begin() + its_offset +
- VSOMEIP_SOMEIP_HEADER_SIZE +
- VSOMEIP_SOMEIP_MAGIC_COOKIE_SIZE);
- }
+ } while (!is_found);
}
- return is_resynced;
+ return (is_found ? its_offset : 0xFFFFFFFF);
}
template < int MaxBufferSize >
diff --git a/implementation/endpoints/src/tcp_client_endpoint_impl.cpp b/implementation/endpoints/src/tcp_client_endpoint_impl.cpp index 2f44baf..7a587bd 100644 --- a/implementation/endpoints/src/tcp_client_endpoint_impl.cpp +++ b/implementation/endpoints/src/tcp_client_endpoint_impl.cpp @@ -110,7 +110,7 @@ void tcp_client_endpoint_impl::send_magic_cookie(message_buffer_ptr_t &_buffer) void tcp_client_endpoint_impl::receive_cbk(
packet_buffer_ptr_t _buffer,
boost::system::error_code const &_error, std::size_t _bytes) {
-#if 0
+#if 1
std::stringstream msg;
msg << "cei::rcb (" << _error.message() << "): ";
for (std::size_t i = 0; i < _bytes; ++i)
@@ -122,23 +122,34 @@ void tcp_client_endpoint_impl::receive_cbk( bool has_full_message;
do {
- uint32_t current_message_size = utility::get_message_size(this->message_);
- has_full_message = (current_message_size > 0 && current_message_size <= this->message_.size());
+ uint32_t current_message_size = utility::get_message_size(message_);
+ has_full_message = (current_message_size > 0 && current_message_size <= message_.size());
if (has_full_message) {
+ bool needs_forwarding(true);
if (is_magic_cookie()) {
has_enabled_magic_cookies_ = true;
} else {
- host_->on_message(&this->message_[0], current_message_size, this);
+ if (has_enabled_magic_cookies_) {
+ uint32_t its_offset = find_magic_cookie(message_);
+ if (its_offset < current_message_size) {
+ VSOMEIP_ERROR << "Message includes Magic Cookie. Ignoring it.";
+ current_message_size = its_offset;
+ needs_forwarding = false;
+ }
+ }
+ }
+ if (needs_forwarding)
+ host_->on_message(&message_[0], current_message_size, this);
+ message_.erase(message_.begin(), message_.begin() + current_message_size);
+ } else if (has_enabled_magic_cookies_ && message_.size() > 0){
+ uint32_t its_offset = find_magic_cookie(message_);
+ if (its_offset < message_.size()) {
+ message_.erase(message_.begin(), message_.begin() + its_offset);
+ has_full_message = true; // trigger next loop
}
- this->message_.erase(this->message_.begin(), this->message_.begin() + current_message_size);
- } else if (has_enabled_magic_cookies_ && this->message_.size() > 0){
- // Note that the following will be done each time a message
- // is not (yet) completely available. If no magic cookie can
- // be found, the message data is not touched.
- has_full_message = resync_on_magic_cookie(message_);
} else if (message_.size() > VSOMEIP_MAX_TCP_MESSAGE_SIZE) {
VSOMEIP_ERROR << "Message exceeds maximum message size. Resetting receiver.";
- this->message_.clear();
+ message_.clear();
}
} while (has_full_message);
restart();
diff --git a/implementation/endpoints/src/tcp_server_endpoint_impl.cpp b/implementation/endpoints/src/tcp_server_endpoint_impl.cpp index 55ac20e..9d1f918 100644 --- a/implementation/endpoints/src/tcp_server_endpoint_impl.cpp +++ b/implementation/endpoints/src/tcp_server_endpoint_impl.cpp @@ -21,194 +21,205 @@ namespace ip = boost::asio::ip; namespace vsomeip {
tcp_server_endpoint_impl::tcp_server_endpoint_impl(
- std::shared_ptr<endpoint_host> _host, endpoint_type _local,
- boost::asio::io_service &_io)
- : tcp_server_endpoint_base_impl(_host, _local, _io),
- acceptor_(_io, _local),
- current_(0) {
- is_supporting_magic_cookies_ = true;
+ std::shared_ptr<endpoint_host> _host, endpoint_type _local,
+ boost::asio::io_service &_io) :
+ tcp_server_endpoint_base_impl(_host, _local, _io), acceptor_(_io,
+ _local), current_(0) {
+ is_supporting_magic_cookies_ = true;
}
tcp_server_endpoint_impl::~tcp_server_endpoint_impl() {
}
void tcp_server_endpoint_impl::start() {
- connection::ptr new_connection = connection::create(this);
+ connection::ptr new_connection = connection::create(this);
- acceptor_.async_accept(
- new_connection->get_socket(),
- std::bind(
- &tcp_server_endpoint_impl::accept_cbk,
- std::dynamic_pointer_cast < tcp_server_endpoint_impl
- > (shared_from_this()),
- new_connection, std::placeholders::_1));
+ acceptor_.async_accept(new_connection->get_socket(),
+ std::bind(&tcp_server_endpoint_impl::accept_cbk,
+ std::dynamic_pointer_cast<tcp_server_endpoint_impl>(
+ shared_from_this()), new_connection,
+ std::placeholders::_1));
}
void tcp_server_endpoint_impl::stop() {
- for (auto& i : connections_)
- i.second->stop();
- acceptor_.close();
+ for (auto& i : connections_)
+ i.second->stop();
+ acceptor_.close();
}
bool tcp_server_endpoint_impl::send_to(
- const std::shared_ptr<endpoint_definition> _target,
- const byte_t *_data, uint32_t _size, bool _flush) {
- endpoint_type its_target(_target->get_address(), _target->get_port());
- return send_intern(its_target, _data, _size, _flush);
+ const std::shared_ptr<endpoint_definition> _target, const byte_t *_data,
+ uint32_t _size, bool _flush) {
+ endpoint_type its_target(_target->get_address(), _target->get_port());
+ return send_intern(its_target, _data, _size, _flush);
}
void tcp_server_endpoint_impl::send_queued(endpoint_type _target,
- message_buffer_ptr_t _buffer) {
- auto connection_iterator = connections_.find(_target);
- if (connection_iterator != connections_.end())
- connection_iterator->second->send_queued(_buffer);
+ message_buffer_ptr_t _buffer) {
+ auto connection_iterator = connections_.find(_target);
+ if (connection_iterator != connections_.end())
+ connection_iterator->second->send_queued(_buffer);
}
tcp_server_endpoint_impl::endpoint_type tcp_server_endpoint_impl::get_remote() const {
- return current_->get_socket().remote_endpoint();
+ return current_->get_socket().remote_endpoint();
}
-bool tcp_server_endpoint_impl::get_multicast(
- service_t, event_t, tcp_server_endpoint_impl::endpoint_type &) const {
- return false;
+bool tcp_server_endpoint_impl::get_multicast(service_t, event_t,
+ tcp_server_endpoint_impl::endpoint_type &) const {
+ return false;
}
-void tcp_server_endpoint_impl::accept_cbk(
- connection::ptr _connection, boost::system::error_code const &_error) {
+void tcp_server_endpoint_impl::accept_cbk(connection::ptr _connection,
+ boost::system::error_code const &_error) {
- if (!_error) {
- socket_type &new_connection_socket = _connection->get_socket();
- endpoint_type remote = new_connection_socket.remote_endpoint();
+ if (!_error) {
+ socket_type &new_connection_socket = _connection->get_socket();
+ endpoint_type remote = new_connection_socket.remote_endpoint();
- connections_[remote] = _connection;
- _connection->start();
- }
+ connections_[remote] = _connection;
+ _connection->start();
+ }
- start();
+ start();
}
unsigned short tcp_server_endpoint_impl::get_port() const {
- return acceptor_.local_endpoint().port();
+ return acceptor_.local_endpoint().port();
}
bool tcp_server_endpoint_impl::is_reliable() const {
- return true;
+ return true;
}
///////////////////////////////////////////////////////////////////////////////
// class tcp_service_impl::connection
///////////////////////////////////////////////////////////////////////////////
tcp_server_endpoint_impl::connection::connection(
- tcp_server_endpoint_impl *_server)
- : socket_(_server->service_),
- server_(_server) {
+ tcp_server_endpoint_impl *_server) :
+ socket_(_server->service_), server_(_server) {
}
tcp_server_endpoint_impl::connection::ptr tcp_server_endpoint_impl::connection::create(
- tcp_server_endpoint_impl *_server) {
- return ptr(new connection(_server));
+ tcp_server_endpoint_impl *_server) {
+ return ptr(new connection(_server));
}
tcp_server_endpoint_impl::socket_type & tcp_server_endpoint_impl::connection::get_socket() {
- return socket_;
+ return socket_;
}
void tcp_server_endpoint_impl::connection::start() {
- packet_buffer_ptr_t its_buffer = std::make_shared<packet_buffer_t>();
- socket_.async_receive(
- boost::asio::buffer(*its_buffer),
- std::bind(&tcp_server_endpoint_impl::connection::receive_cbk,
- shared_from_this(), its_buffer, std::placeholders::_1,
- std::placeholders::_2));
+ packet_buffer_ptr_t its_buffer = std::make_shared<packet_buffer_t>();
+ socket_.async_receive(boost::asio::buffer(*its_buffer),
+ std::bind(&tcp_server_endpoint_impl::connection::receive_cbk,
+ shared_from_this(), its_buffer, std::placeholders::_1,
+ std::placeholders::_2));
}
void tcp_server_endpoint_impl::connection::stop() {
- socket_.close();
+ socket_.close();
}
void tcp_server_endpoint_impl::connection::send_queued(
- message_buffer_ptr_t _buffer) {
- if (server_->has_enabled_magic_cookies_)
- send_magic_cookie(_buffer);
+ message_buffer_ptr_t _buffer) {
+ if (server_->has_enabled_magic_cookies_)
+ send_magic_cookie(_buffer);
- boost::asio::async_write(
- socket_,
- boost::asio::buffer(*_buffer),
- std::bind(&tcp_server_endpoint_base_impl::send_cbk,
- server_->shared_from_this(), _buffer, std::placeholders::_1,
- std::placeholders::_2));
+ boost::asio::async_write(socket_, boost::asio::buffer(*_buffer),
+ std::bind(&tcp_server_endpoint_base_impl::send_cbk,
+ server_->shared_from_this(), _buffer, std::placeholders::_1,
+ std::placeholders::_2));
}
void tcp_server_endpoint_impl::connection::send_magic_cookie(
- message_buffer_ptr_t &_buffer) {
- if (VSOMEIP_MAX_TCP_MESSAGE_SIZE - _buffer->size() >=
- VSOMEIP_SOMEIP_HEADER_SIZE + VSOMEIP_SOMEIP_MAGIC_COOKIE_SIZE) {
- _buffer->insert(_buffer->begin(), SERVICE_COOKIE,
- SERVICE_COOKIE + sizeof(SERVICE_COOKIE));
- }
+ message_buffer_ptr_t &_buffer) {
+ if (VSOMEIP_MAX_TCP_MESSAGE_SIZE - _buffer->size() >=
+ VSOMEIP_SOMEIP_HEADER_SIZE + VSOMEIP_SOMEIP_MAGIC_COOKIE_SIZE) {
+ _buffer->insert(_buffer->begin(), SERVICE_COOKIE,
+ SERVICE_COOKIE + sizeof(SERVICE_COOKIE));
+ }
}
bool tcp_server_endpoint_impl::connection::is_magic_cookie() const {
- return (0 == std::memcmp(CLIENT_COOKIE, &message_[0], sizeof(CLIENT_COOKIE)));
+ return (0 == std::memcmp(CLIENT_COOKIE, &message_[0], sizeof(CLIENT_COOKIE)));
}
void tcp_server_endpoint_impl::connection::receive_cbk(
- packet_buffer_ptr_t _buffer, boost::system::error_code const &_error,
- std::size_t _bytes) {
+ packet_buffer_ptr_t _buffer, boost::system::error_code const &_error,
+ std::size_t _bytes) {
#if 0
- std::stringstream msg;
- for (std::size_t i = 0; i < _bytes; ++i)
- msg << std::hex << std::setw(2) << std::setfill('0') << (int)(*_buffer))[i] << " ";
- VSOMEIP_DEBUG << msg.str();
+ std::stringstream msg;
+ for (std::size_t i = 0; i < _bytes; ++i)
+ msg << std::hex << std::setw(2) << std::setfill('0')
+ << (int) (*_buffer)[i] << " ";
+ VSOMEIP_DEBUG<< msg.str();
#endif
- if (!_error && 0 < _bytes) {
- message_.insert(message_.end(), _buffer->begin(),
- _buffer->begin() + _bytes);
-
- bool has_full_message;
- do {
- uint32_t current_message_size = utility::get_message_size(message_);
- has_full_message = (current_message_size > 0
- && current_message_size <= message_.size());
- if (has_full_message) {
- if (is_magic_cookie()) {
- server_->has_enabled_magic_cookies_ = true;
- } else {
- if (utility::is_request(message_[VSOMEIP_MESSAGE_TYPE_POS])) {
- client_t its_client;
- std::memcpy(&its_client, &message_[VSOMEIP_CLIENT_POS_MIN],
- sizeof(client_t));
- session_t its_session;
- std::memcpy(&its_session, &message_[VSOMEIP_SESSION_POS_MIN],
- sizeof(session_t));
- server_->clients_[its_client][its_session] =
- socket_.remote_endpoint();
- }
- server_->host_->on_message(&message_[0], current_message_size,
- server_);
- }
- message_.erase(message_.begin(),
- message_.begin() + current_message_size);
- } else if (server_->has_enabled_magic_cookies_ && message_.size() > 0) {
- has_full_message = server_->resync_on_magic_cookie(message_);
- } else if (message_.size() > VSOMEIP_MAX_TCP_MESSAGE_SIZE) {
- VSOMEIP_ERROR
- << "Message exceeds maximum message size. Resetting receiver.";
- message_.clear();
- }
- } while (has_full_message);
-
- start();
- }
+ if (!_error && 0 < _bytes) {
+ message_.insert(message_.end(), _buffer->begin(),
+ _buffer->begin() + _bytes);
+
+ static int i = 1;
+
+ bool has_full_message;
+ do {
+ uint32_t current_message_size = utility::get_message_size(message_);
+ has_full_message = (current_message_size > 0 && current_message_size <= message_.size());
+ if (has_full_message) {
+ bool needs_forwarding(true);
+ if (is_magic_cookie()) {
+ server_->has_enabled_magic_cookies_ = true;
+ } else {
+ if (server_->has_enabled_magic_cookies_) {
+ uint32_t its_offset = server_->find_magic_cookie(message_);
+ if (its_offset < current_message_size) {
+ VSOMEIP_ERROR << "Detected Magic Cookie within message data. Resyncing.";
+ current_message_size = its_offset;
+ needs_forwarding = false;
+ }
+ }
+ }
+ if (needs_forwarding) {
+ if (utility::is_request(message_[VSOMEIP_MESSAGE_TYPE_POS])) {
+ client_t its_client;
+ std::memcpy(&its_client,
+ &message_[VSOMEIP_CLIENT_POS_MIN],
+ sizeof(client_t));
+ session_t its_session;
+ std::memcpy(&its_session,
+ &message_[VSOMEIP_SESSION_POS_MIN],
+ sizeof(session_t));
+ server_->clients_[its_client][its_session] =
+ socket_.remote_endpoint();
+ }
+ server_->host_->on_message(&message_[0],
+ current_message_size, server_);
+ }
+ message_.erase(message_.begin(), message_.begin() + current_message_size);
+ } else if (server_->has_enabled_magic_cookies_ && message_.size() > 0){
+ uint32_t its_offset = server_->find_magic_cookie(message_);
+ if (its_offset < message_.size()) {
+ VSOMEIP_ERROR << "Detected Magic Cookie within message data. Resyncing.";
+ message_.erase(message_.begin(), message_.begin() + its_offset);
+ has_full_message = true; // trigger next loop
+ }
+ } else if (message_.size() > VSOMEIP_MAX_TCP_MESSAGE_SIZE) {
+ VSOMEIP_ERROR << "Message exceeds maximum message size. Resetting receiver.";
+ message_.clear();
+ }
+ } while (has_full_message);
+
+ start();
+ }
}
// Dummies
void tcp_server_endpoint_impl::receive() {
- // intentionally left empty
+ // intentionally left empty
}
void tcp_server_endpoint_impl::restart() {
- // intentionally left empty
+ // intentionally left empty
}
} // namespace vsomeip
diff --git a/implementation/routing/src/routing_manager_impl.cpp b/implementation/routing/src/routing_manager_impl.cpp index 2ffcdf8..0e516bb 100644 --- a/implementation/routing/src/routing_manager_impl.cpp +++ b/implementation/routing/src/routing_manager_impl.cpp @@ -159,9 +159,9 @@ void routing_manager_impl::request_service(client_t _client, service_t _service, std::shared_ptr<serviceinfo> its_info(find_service(_service, _instance)); if (its_info) { - if ((_major > its_info->get_major()) + if ((_major < ANY_MAJOR && _major > its_info->get_major()) || (_major == its_info->get_major() - && _minor > its_info->get_minor()) + && _minor < ANY_MINOR && _minor > its_info->get_minor()) || (_ttl > its_info->get_ttl())) { host_->on_error(error_code_e::SERVICE_PROPERTY_MISMATCH); } else { @@ -295,7 +295,7 @@ bool routing_manager_impl::send(client_t _client, const byte_t *_data, _data[VSOMEIP_METHOD_POS_MAX]); std::shared_ptr<event> its_event = find_event(its_service, _instance, its_method); if (its_event) { - std::vector< byte_t > its_data(); + std::vector< byte_t > its_data; for (auto its_group : its_event->get_eventgroups()) { // local @@ -1086,6 +1086,8 @@ void routing_manager_impl::init_routing_info() { i.second); if (VSOMEIP_INVALID_PORT != its_reliable) { + VSOMEIP_DEBUG << "Initializing route to service [" + << std::hex << i.first << "." << i.second << "]"; add_routing_info(i.first, i.second, DEFAULT_MAJOR, DEFAULT_MINOR, DEFAULT_TTL, boost::asio::ip::address::from_string(its_address), diff --git a/test/magic-cookies-test-client.cpp b/test/magic-cookies-test-client.cpp index c65a565..b3b273e 100644 --- a/test/magic-cookies-test-client.cpp +++ b/test/magic-cookies-test-client.cpp @@ -108,7 +108,7 @@ public: vsomeip::routing_manager *its_routing = app_->get_routing_manager(); vsomeip::byte_t its_good_payload_data[] = { - 0x12, 0x34, 0x04, 0x21, + 0x12, 0x34, 0x84, 0x21, 0x00, 0x00, 0x00, 0x11, 0x13, 0x43, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, @@ -116,7 +116,7 @@ public: }; vsomeip::byte_t its_bad_payload_data[] = { - 0x12, 0x34, 0x04, 0x21, + 0x12, 0x34, 0x84, 0x21, 0x00, 0x00, 0x01, 0x23, 0x13, 0x43, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, diff --git a/test/readme.txt b/test/readme.txt new file mode 100644 index 0000000..b69cea9 --- /dev/null +++ b/test/readme.txt @@ -0,0 +1,86 @@ +Configuration Test +------------------ +To start the configuration test from the build directory do: + +./configuration-test -someip ../config/vsomeip-test.json + +The expected output is: + +2015-02-10 08:47:31.503874 [info] Test "HOST ADDRESS" succeeded. +2015-02-10 08:47:31.507609 [info] Test "HAS CONSOLE" succeeded. +2015-02-10 08:47:31.507865 [info] Test "HAS FILE" succeeded. +2015-02-10 08:47:31.508001 [info] Test "HAS DLT" succeeded. +2015-02-10 08:47:31.508143 [info] Test "LOGFILE" succeeded. +2015-02-10 08:47:31.508315 [info] Test "LOGLEVEL" succeeded. +2015-02-10 08:47:31.508456 [info] Test "RELIABLE_TEST_1234_0022" succeeded. +2015-02-10 08:47:31.508593 [info] Test "UNRELIABLE_TEST_1234_0022" succeeded. +2015-02-10 08:47:31.508759 [info] Test "RELIABLE_TEST_1234_0023" succeeded. +2015-02-10 08:47:31.508896 [info] Test "UNRELIABLE_TEST_1234_0023" succeeded. +2015-02-10 08:47:31.509032 [info] Test "RELIABLE_TEST_2277_0022" succeeded. +2015-02-10 08:47:31.509185 [info] Test "UNRELIABLE_TEST_2277_0022" succeeded. +2015-02-10 08:47:31.509330 [info] Test "RELIABLE_TEST_4466_0321" succeeded. +2015-02-10 08:47:31.509467 [info] Test "UNRELIABLE_TEST_4466_0321" succeeded. +2015-02-10 08:47:31.509602 [info] Test "RELIABLE_TEST_2277_0022" succeeded. +2015-02-10 08:47:31.509771 [info] Test "UNRELIABLE_TEST_2277_0022" succeeded. +2015-02-10 08:47:31.509915 [info] Test "ADDRESS_TEST_1234_0022" succeeded. +2015-02-10 08:47:31.510049 [info] Test "MIN_INITIAL_DELAY_TEST_1234_0022" succeeded. +2015-02-10 08:47:31.510354 [info] Test "MAX_INITIAL_DELAY_TEST_1234_0022" succeeded. +2015-02-10 08:47:31.510610 [info] Test "REPETITION_BASE_DELAY_TEST_1234_0022" succeeded. +2015-02-10 08:47:31.513978 [info] Test "REPETITION_MAX_TEST_1234_0022" succeeded. +2015-02-10 08:47:31.514177 [info] Test "CYCLIC_OFFER_DELAY_TEST_1234_0022" succeeded. +2015-02-10 08:47:31.514280 [info] Test "CYCLIC_REQUEST_DELAY_TEST_1234_0022" succeeded. +2015-02-10 08:47:31.514397 [info] Test "MIN_INITIAL_DELAY_TEST_1234_0023" succeeded. +2015-02-10 08:47:31.514618 [info] Test "MAX_INITIAL_DELAY_TEST_1234_0023" succeeded. +2015-02-10 08:47:31.514754 [info] Test "REPETITION_BASE_DELAY_TEST_1234_0023" succeeded. +2015-02-10 08:47:31.514901 [info] Test "REPETITION_MAX_TEST_1234_0023" succeeded. +2015-02-10 08:47:31.515052 [info] Test "CYCLIC_OFFER_DELAY_TEST_1234_0023" succeeded. +2015-02-10 08:47:31.515186 [info] Test "CYCLIC_REQUEST_DELAY_TEST_1234_0023" succeeded. +2015-02-10 08:47:31.515325 [info] Test "MIN_INITIAL_DELAY_TEST_2277_0022" succeeded. +2015-02-10 08:47:31.515395 [info] Test "MAX_INITIAL_DELAY_TEST_2277_0022" succeeded. +2015-02-10 08:47:31.515536 [info] Test "REPETITION_BASE_DELAY_TEST_2277_0022" succeeded. +2015-02-10 08:47:31.515691 [info] Test "REPETITION_MAX_TEST_2277_0022" succeeded. +2015-02-10 08:47:31.515834 [info] Test "CYCLIC_OFFER_DELAY_TEST_2277_0022" succeeded. +2015-02-10 08:47:31.515971 [info] Test "CYCLIC_REQUEST_DELAY_TEST_2277_0022" succeeded. +2015-02-10 08:47:31.516109 [info] Test "MIN_INITIAL_DELAY_TEST_2266_0022" succeeded. +2015-02-10 08:47:31.516279 [info] Test "MAX_INITIAL_DELAY_TEST_2266_0022" succeeded. +2015-02-10 08:47:31.516380 [info] Test "REPETITION_BASE_DELAY_TEST_2266_0022" succeeded. +2015-02-10 08:47:31.516512 [info] Test "REPETITION_MAX_TEST_2266_0022" succeeded. +2015-02-10 08:47:31.516610 [info] Test "CYCLIC_OFFER_DELAY_TEST_2266_0022" succeeded. +2015-02-10 08:47:31.516736 [info] Test "CYCLIC_REQUEST_DELAY_TEST_2266_0022" succeeded. +2015-02-10 08:47:31.516874 [info] Test "ADDRESS_TEST_4466_0321" succeeded. +2015-02-10 08:47:31.516974 [info] Test "SERVICE DISCOVERY PROTOCOL" succeeded. +2015-02-10 08:47:31.517106 [info] Test "SERVICE DISCOVERY PORT" succeeded. + + +Magic Cookies Test +------------------ +To run the magic cookies test you need two devices on the same network. The network addresses within +the configuration files need to be adapted to match the devices addresses. + +To start the magic-cookies-test from the build-directory do: + +HOST1: +env VSOMEIP_CONFIGURATION_FILE=../config/vsomeip-magic-cookies-client.json \ +VSOMEIP_APPLICATION_NAME=client-sample ./magic-cookies-test-client + +HOST2: +env VSOMEIP_CONFIGURATION_FILE=../config/vsomeip-magic-cookies-service.json \ +VSOMEIP_APPLICATION_NAME=service-sample ./response-sample --tcp --static-routing + +The expected result is an output like this on service side: + +2015-02-10 08:42:07.317695 [info] Received a message with Client/Session [1343/0001] +2015-02-10 08:42:07.360105 [error] Detected Magic Cookie within message data. Resyncing. +2015-02-10 08:42:07.360298 [info] Received a message with Client/Session [1343/0003] +2015-02-10 08:42:07.360527 [error] Detected Magic Cookie within message data. Resyncing. +2015-02-10 08:42:07.360621 [error] Detected Magic Cookie within message data. Resyncing. +2015-02-10 08:42:07.360714 [info] Received a message with Client/Session [1343/0006] +2015-02-10 08:42:07.360850 [info] Received a message with Client/Session [1343/0007] +2015-02-10 08:42:07.361021 [error] Detected Magic Cookie within message data. Resyncing. +2015-02-10 08:42:07.361107 [error] Detected Magic Cookie within message data. Resyncing. +2015-02-10 08:42:07.361191 [error] Detected Magic Cookie within message data. Resyncing. +2015-02-10 08:42:07.361276 [info] Received a message with Client/Session [1343/000b] +2015-02-10 08:42:07.361434 [info] Received a message with Client/Session [1343/000c] +2015-02-10 08:42:07.361558 [info] Received a message with Client/Session [1343/000d] +2015-02-10 08:42:07.361672 [error] Detected Magic Cookie within message data. Resyncing. +2015-02-10 08:42:07.361761 [info] Received a message with Client/Session [1343/000f] |