summaryrefslogtreecommitdiff
path: root/test/network_tests/routing_tests
diff options
context:
space:
mode:
Diffstat (limited to 'test/network_tests/routing_tests')
-rw-r--r--test/network_tests/routing_tests/conf/external_local_routing_test_client_external.json.in47
-rw-r--r--test/network_tests/routing_tests/conf/external_local_routing_test_service.json.in42
-rwxr-xr-xtest/network_tests/routing_tests/conf/local_routing_test_starter.sh.bat.in79
-rwxr-xr-xtest/network_tests/routing_tests/conf/local_routing_test_starter.sh.in79
-rwxr-xr-xtest/network_tests/routing_tests/external_local_routing_test_client_external_start.sh17
-rw-r--r--test/network_tests/routing_tests/external_local_routing_test_service.cpp185
-rw-r--r--test/network_tests/routing_tests/external_local_routing_test_service.hpp46
-rwxr-xr-xtest/network_tests/routing_tests/external_local_routing_test_service_start.sh9
-rwxr-xr-xtest/network_tests/routing_tests/external_local_routing_test_starter.sh121
-rw-r--r--test/network_tests/routing_tests/local_routing_test_client.cpp167
-rw-r--r--test/network_tests/routing_tests/local_routing_test_client.hpp48
-rw-r--r--test/network_tests/routing_tests/local_routing_test_client.json38
-rwxr-xr-xtest/network_tests/routing_tests/local_routing_test_client_start.sh9
-rw-r--r--test/network_tests/routing_tests/local_routing_test_service.cpp164
-rw-r--r--test/network_tests/routing_tests/local_routing_test_service.hpp45
-rw-r--r--test/network_tests/routing_tests/local_routing_test_service.json41
-rwxr-xr-xtest/network_tests/routing_tests/local_routing_test_service_start.sh9
17 files changed, 1146 insertions, 0 deletions
diff --git a/test/network_tests/routing_tests/conf/external_local_routing_test_client_external.json.in b/test/network_tests/routing_tests/conf/external_local_routing_test_client_external.json.in
new file mode 100644
index 0000000..0aaa664
--- /dev/null
+++ b/test/network_tests/routing_tests/conf/external_local_routing_test_client_external.json.in
@@ -0,0 +1,47 @@
+{
+ "unicast" : "@TEST_IP_SLAVE@",
+ "netmask" : "255.255.255.0",
+ "diagnosis" : "0x16",
+ "logging" :
+ {
+ "level" : "debug",
+ "console" : "true",
+ "file" :
+ {
+ "enable" : "true",
+ "path" : "/var/log/vsomeip.log"
+ },
+
+ "dlt" : "true"
+ },
+
+ "applications" :
+ [
+ {
+ "name" : "external_local_routing_test_client_external",
+ "id" : "0x1644"
+ }
+ ],
+
+ "services" :
+ [
+ {
+ "service" : "0x1234",
+ "instance" : "0x5678",
+ "unicast" : "@TEST_IP_MASTER@",
+ "unreliable" : "30509"
+ }
+ ],
+
+ "routing": {
+ "enabled": false,
+ "host": "external_local_routing_test_client_external"
+ },
+ "service-discovery" :
+ {
+ "enable" : "false",
+ "multicast" : "224.0.0.1",
+ "port" : "30491",
+ "protocol" : "udp"
+ }
+}
diff --git a/test/network_tests/routing_tests/conf/external_local_routing_test_service.json.in b/test/network_tests/routing_tests/conf/external_local_routing_test_service.json.in
new file mode 100644
index 0000000..a4deb82
--- /dev/null
+++ b/test/network_tests/routing_tests/conf/external_local_routing_test_service.json.in
@@ -0,0 +1,42 @@
+{
+ "unicast" : "@TEST_IP_MASTER@",
+ "diagnosis":"0x12",
+ "logging" :
+ {
+ "level" : "debug",
+ "console" : "true",
+ "file" :
+ {
+ "enable" : "false",
+ "path" : "/tmp/vsomeip.log"
+ },
+
+ "dlt" : "false"
+ },
+
+ "applications" :
+ [
+ {
+ "name" : "external_local_routing_test_service",
+ "id" : "0x1277"
+ }
+ ],
+
+ "services" :
+ [
+ {
+ "service" : "0x1234",
+ "instance" : "0x5678",
+ "unreliable" : "30509"
+ }
+ ],
+
+ "routing" : "external_local_routing_test_service",
+ "service-discovery" :
+ {
+ "enable" : "false",
+ "multicast" : "224.0.0.1",
+ "port" : "30490",
+ "protocol" : "udp"
+ }
+}
diff --git a/test/network_tests/routing_tests/conf/local_routing_test_starter.sh.bat.in b/test/network_tests/routing_tests/conf/local_routing_test_starter.sh.bat.in
new file mode 100755
index 0000000..d7abe64
--- /dev/null
+++ b/test/network_tests/routing_tests/conf/local_routing_test_starter.sh.bat.in
@@ -0,0 +1,79 @@
+#!/bin/bash
+# Copyright (C) 2015-2017 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/.
+
+# Purpose: This script is needed to start the client and service with
+# one command. This is necessary as ctest - which is used to run the
+# tests - isn't able to start two binaries for one testcase. Therefore
+# the testcase simply executes this script. This script then runs client
+# and service and checks that both exit sucessfully.
+
+FAIL=0
+
+# Parameter 1: the pid to check
+check_tcp_udp_sockets_are_closed ()
+{
+ # Check that the service does not listen on any TCP/UDP socket
+ # or has any active connection via a TCP/UDP socket
+ # awk is used to avoid the case when a inode number is the same as a PID. The awk
+ # program filters the netstat output down to the protocol (1st field) and
+ # the PID/Program name (last field) fields.
+ SERVICE_SOCKETS_LISTENING=$(netstat -tulpen 2> /dev/null | awk '{print $1 "\t" $NF}' | grep $1 | wc -l)
+ if [ $SERVICE_SOCKETS_LISTENING -ne 0 ]
+ then
+ ((FAIL+=1))
+ fi
+
+ SERVICE_SOCKETS_CONNECTED=$(netstat -tupen 2> /dev/null | awk '{print $1 "\t" $NF}' | grep $1 | wc -l)
+ if [ $SERVICE_SOCKETS_CONNECTED -ne 0 ]
+ then
+ ((FAIL+=1))
+ fi
+}
+
+# Start the service
+export VSOMEIP_APPLICATION_NAME=local_routing_test_service
+if [ "$VSOMEIP_CONFIGURATION_SERVICE" != "" ]
+then
+ export VSOMEIP_CONFIGURATION=$VSOMEIP_CONFIGURATION_SERVICE
+else
+ export VSOMEIP_CONFIGURATION=local_routing_test_service.json
+fi
+./local_routing_test_service &
+SERIVCE_PID=$!
+sleep 1;
+
+check_tcp_udp_sockets_are_closed $SERIVCE_PID
+
+# Start the client
+export VSOMEIP_APPLICATION_NAME=local_routing_test_client
+if [ "$VSOMEIP_CONFIGURATION_CLIENT" != "" ]
+then
+ export VSOMEIP_CONFIGURATION=$VSOMEIP_CONFIGURATION_CLIENT
+else
+ export VSOMEIP_CONFIGURATION=local_routing_test_client.json
+fi
+./local_routing_test_client &
+CLIENT_PID=$!
+
+check_tcp_udp_sockets_are_closed $SERIVCE_PID
+check_tcp_udp_sockets_are_closed $CLIENT_PID
+
+# Wait until client and service are finished
+for job in $(jobs -p)
+do
+ # Fail gets incremented if either client or service exit
+ # with a non-zero exit code
+ wait $job || ((FAIL+=1))
+done
+
+# Check if client and server both exited successfully and the service didnt't
+# have any open
+if [ $FAIL -eq 0 ]
+then
+ exit 0
+else
+ exit 1
+fi
diff --git a/test/network_tests/routing_tests/conf/local_routing_test_starter.sh.in b/test/network_tests/routing_tests/conf/local_routing_test_starter.sh.in
new file mode 100755
index 0000000..d5b83f4
--- /dev/null
+++ b/test/network_tests/routing_tests/conf/local_routing_test_starter.sh.in
@@ -0,0 +1,79 @@
+#!/bin/bash
+# Copyright (C) 2015-2017 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/.
+
+# Purpose: This script is needed to start the client and service with
+# one command. This is necessary as ctest - which is used to run the
+# tests - isn't able to start two binaries for one testcase. Therefore
+# the testcase simply executes this script. This script then runs client
+# and service and checks that both exit sucessfully.
+
+FAIL=0
+
+# Parameter 1: the pid to check
+check_tcp_udp_sockets_are_closed ()
+{
+ # Check that the service does not listen on any TCP/UDP socket
+ # or has any active connection via a TCP/UDP socket
+ # awk is used to avoid the case when a inode number is the same as a PID. The awk
+ # program filters the netstat output down to the protocol (1st field) and
+ # the PID/Program name (last field) fields.
+ SERVICE_SOCKETS_LISTENING=$(netstat -tulpen 2> /dev/null | awk '{print $1 "\t" $NF}' | grep $1 | wc -l)
+ if [ $SERVICE_SOCKETS_LISTENING -ne 0 ]
+ then
+ ((FAIL+=1))
+ fi
+
+ SERVICE_SOCKETS_CONNECTED=$(netstat -tupen 2> /dev/null | awk '{print $1 "\t" $NF}' | grep $1 | wc -l)
+ if [ $SERVICE_SOCKETS_CONNECTED -ne 0 ]
+ then
+ ((FAIL+=1))
+ fi
+}
+
+export VSOMEIP_CONFIGURATION=local_routing_test_service.json
+# start daemon
+../../examples/routingmanagerd/./routingmanagerd &
+PID_VSOMEIPD=$!
+
+WAIT_PIDS=()
+# Start the service
+export VSOMEIP_APPLICATION_NAME=local_routing_test_service
+./local_routing_test_service &
+SERIVCE_PID=$!
+WAIT_PIDS+=($!)
+sleep 1;
+
+check_tcp_udp_sockets_are_closed $SERIVCE_PID
+
+# Start the client
+export VSOMEIP_APPLICATION_NAME=local_routing_test_client
+export VSOMEIP_CONFIGURATION=local_routing_test_client.json
+./local_routing_test_client &
+CLIENT_PID=$!
+WAIT_PIDS+=($!)
+
+check_tcp_udp_sockets_are_closed $SERIVCE_PID
+check_tcp_udp_sockets_are_closed $CLIENT_PID
+
+# Wait until client and service are finished
+for job in ${WAIT_PIDS[*]}
+do
+ # Fail gets incremented if either client or service exit
+ # with a non-zero exit code
+ wait $job || ((FAIL+=1))
+done
+
+kill $PID_VSOMEIPD
+sleep 1
+
+# Check if client and server both exited successfully and the service didnt't
+# have any open
+if [ $FAIL -eq 0 ]
+then
+ exit 0
+else
+ exit 1
+fi
diff --git a/test/network_tests/routing_tests/external_local_routing_test_client_external_start.sh b/test/network_tests/routing_tests/external_local_routing_test_client_external_start.sh
new file mode 100755
index 0000000..098c777
--- /dev/null
+++ b/test/network_tests/routing_tests/external_local_routing_test_client_external_start.sh
@@ -0,0 +1,17 @@
+#!/bin/bash -ex
+# Copyright (C) 2015-2017 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/.
+
+export VSOMEIP_APPLICATION_NAME=external_local_routing_test_client_external
+export VSOMEIP_CONFIGURATION=external_local_routing_test_client_external.json
+./local_routing_test_client &
+client=$!
+
+for _ in {1..100}
+do
+ find /tmp -ls
+ lsof -nw -p "$client" || continue
+done
+wait "$client"
diff --git a/test/network_tests/routing_tests/external_local_routing_test_service.cpp b/test/network_tests/routing_tests/external_local_routing_test_service.cpp
new file mode 100644
index 0000000..46b8138
--- /dev/null
+++ b/test/network_tests/routing_tests/external_local_routing_test_service.cpp
@@ -0,0 +1,185 @@
+// Copyright (C) 2015-2017 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/.
+
+#include "external_local_routing_test_service.hpp"
+
+external_local_routing_test_service::external_local_routing_test_service(bool _use_static_routing) :
+ app_(vsomeip::runtime::get()->create_application()),
+ is_registered_(false),
+ use_static_routing_(_use_static_routing),
+ blocked_(false),
+ number_received_messages_local_(0),
+ number_received_messages_external_(0),
+ offer_thread_(std::bind(&external_local_routing_test_service::run, this))
+{
+}
+
+bool external_local_routing_test_service::init()
+{
+ std::lock_guard<std::mutex> its_lock(mutex_);
+
+ if (!app_->init()) {
+ ADD_FAILURE() << "Couldn't initialize application";
+ return false;
+ }
+ app_->register_message_handler(vsomeip_test::TEST_SERVICE_SERVICE_ID,
+ vsomeip_test::TEST_SERVICE_INSTANCE_ID, vsomeip_test::TEST_SERVICE_METHOD_ID,
+ std::bind(&external_local_routing_test_service::on_message, this,
+ std::placeholders::_1));
+
+ app_->register_message_handler(vsomeip_test::TEST_SERVICE_SERVICE_ID,
+ vsomeip_test::TEST_SERVICE_INSTANCE_ID, vsomeip_test::TEST_SERVICE_METHOD_ID,
+ std::bind(&external_local_routing_test_service::on_message, this,
+ std::placeholders::_1));
+
+ app_->register_state_handler(
+ std::bind(&external_local_routing_test_service::on_state, this,
+ std::placeholders::_1));
+
+ VSOMEIP_INFO << "Static routing " << (use_static_routing_ ? "ON" : "OFF");
+ return true;
+}
+
+void external_local_routing_test_service::start()
+{
+ VSOMEIP_INFO << "Starting...";
+ app_->start();
+}
+
+void external_local_routing_test_service::stop()
+{
+ VSOMEIP_INFO << "Stopping...";
+ app_->clear_all_handler();
+ app_->stop();
+}
+
+void external_local_routing_test_service::join_offer_thread()
+{
+ offer_thread_.join();
+}
+
+void external_local_routing_test_service::offer()
+{
+ app_->offer_service(vsomeip_test::TEST_SERVICE_SERVICE_ID, vsomeip_test::TEST_SERVICE_INSTANCE_ID);
+}
+
+void external_local_routing_test_service::stop_offer()
+{
+ app_->stop_offer_service(vsomeip_test::TEST_SERVICE_SERVICE_ID, vsomeip_test::TEST_SERVICE_INSTANCE_ID);
+}
+
+void external_local_routing_test_service::on_state(vsomeip::state_type_e _state)
+{
+ VSOMEIP_INFO << "Application " << app_->get_name() << " is "
+ << (_state == vsomeip::state_type_e::ST_REGISTERED ? "registered." :
+ "deregistered.");
+
+ if(_state == vsomeip::state_type_e::ST_REGISTERED)
+ {
+ if(!is_registered_)
+ {
+ std::lock_guard<std::mutex> its_lock(mutex_);
+ is_registered_ = true;
+ blocked_ = true;
+ // "start" the run method thread
+ condition_.notify_one();
+ }
+ }
+ else
+ {
+ is_registered_ = false;
+ }
+}
+
+void external_local_routing_test_service::on_message(
+ const 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() << "]";
+
+ ASSERT_EQ(_request->get_service(), vsomeip_test::TEST_SERVICE_SERVICE_ID);
+ ASSERT_EQ(_request->get_method(), vsomeip_test::TEST_SERVICE_METHOD_ID);
+
+ // Check the protocol version this shall be set to 0x01 according to the spec.
+ // TR_SOMEIP_00052
+ ASSERT_EQ(_request->get_protocol_version(), 0x01);
+ // Check the message type this shall be 0xx (REQUEST) according to the spec.
+ // TR_SOMEIP_00055
+ ASSERT_EQ(_request->get_message_type(), vsomeip::message_type_e::MT_REQUEST);
+
+ if(_request->get_client() == vsomeip_test::TEST_CLIENT_CLIENT_ID)
+ {
+ number_received_messages_local_++;
+ // check the session id.
+ ASSERT_EQ(_request->get_session(),
+ static_cast<vsomeip::session_t>(number_received_messages_local_));
+ }
+ else if (_request->get_client() == vsomeip_test::TEST_CLIENT_EXTERNAL_CLIENT_ID)
+ {
+ number_received_messages_external_++;
+ // check the session id.
+ ASSERT_EQ(_request->get_session(),
+ static_cast<vsomeip::session_t>(number_received_messages_external_));
+ }
+
+ // send response
+ std::shared_ptr<vsomeip::message> its_response =
+ vsomeip::runtime::get()->create_response(_request);
+
+ app_->send(its_response);
+
+ if(number_received_messages_local_ >= vsomeip_test::NUMBER_OF_MESSAGES_TO_SEND
+ && number_received_messages_external_ >= vsomeip_test::NUMBER_OF_MESSAGES_TO_SEND)
+ {
+ std::lock_guard<std::mutex> its_lock(mutex_);
+ blocked_ = true;
+ condition_.notify_one();
+ }
+ ASSERT_LT(number_received_messages_local_,
+ vsomeip_test::NUMBER_OF_MESSAGES_TO_SEND + 1);
+ ASSERT_LT(number_received_messages_external_,
+ vsomeip_test::NUMBER_OF_MESSAGES_TO_SEND + 1);
+}
+
+void external_local_routing_test_service::run()
+{
+ std::unique_lock<std::mutex> its_lock(mutex_);
+ while (!blocked_)
+ condition_.wait(its_lock);
+
+ blocked_ = false;
+ if(use_static_routing_)
+ {
+ offer();
+ }
+
+ while (!blocked_) {
+ condition_.wait(its_lock);
+ }
+
+ std::thread t2([](){ std::this_thread::sleep_for(std::chrono::microseconds(1000000 * 2));});
+ t2.join();
+ app_->stop();
+}
+
+TEST(someip_external_local_routing_test, receive_ten_messages_over_local_and_external_socket)
+{
+ bool use_static_routing = true;
+ external_local_routing_test_service test_service(use_static_routing);
+ if (test_service.init()) {
+ test_service.start();
+ test_service.join_offer_thread();
+ }
+}
+
+#if defined(__linux__) || defined(ANDROID)
+int main(int argc, char** argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
+#endif
diff --git a/test/network_tests/routing_tests/external_local_routing_test_service.hpp b/test/network_tests/routing_tests/external_local_routing_test_service.hpp
new file mode 100644
index 0000000..a25025e
--- /dev/null
+++ b/test/network_tests/routing_tests/external_local_routing_test_service.hpp
@@ -0,0 +1,46 @@
+// Copyright (C) 2015-2017 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 EXTERNALLOCALROUTINGTESTSERVICE_HPP_
+#define EXTERNALLOCALROUTINGTESTSERVICE_HPP_
+#include <gtest/gtest.h>
+
+#include <vsomeip/vsomeip.hpp>
+
+#include <thread>
+#include <mutex>
+#include <condition_variable>
+#include <functional>
+
+#include "../someip_test_globals.hpp"
+
+class external_local_routing_test_service
+{
+public:
+ external_local_routing_test_service(bool _use_static_routing);
+ bool init();
+ void start();
+ void stop();
+ void offer();
+ void stop_offer();
+ void join_offer_thread();
+ void on_state(vsomeip::state_type_e _state);
+ void on_message(const std::shared_ptr<vsomeip::message> &_request);
+ void run();
+
+private:
+ std::shared_ptr<vsomeip::application> app_;
+ bool is_registered_;
+ bool use_static_routing_;
+
+ std::mutex mutex_;
+ std::condition_variable condition_;
+ bool blocked_;
+ std::uint32_t number_received_messages_local_;
+ std::uint32_t number_received_messages_external_;
+ std::thread offer_thread_;
+};
+
+#endif /* EXTERNALLOCALROUTINGTESTSERVICE_HPP_ */
diff --git a/test/network_tests/routing_tests/external_local_routing_test_service_start.sh b/test/network_tests/routing_tests/external_local_routing_test_service_start.sh
new file mode 100755
index 0000000..81b2ef1
--- /dev/null
+++ b/test/network_tests/routing_tests/external_local_routing_test_service_start.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+# Copyright (C) 2015-2017 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/.
+
+export VSOMEIP_APPLICATION_NAME=external_local_routing_test_service
+export VSOMEIP_CONFIGURATION=external_local_routing_test_service.json
+./external_local_routing_test_service
diff --git a/test/network_tests/routing_tests/external_local_routing_test_starter.sh b/test/network_tests/routing_tests/external_local_routing_test_starter.sh
new file mode 100755
index 0000000..c67114f
--- /dev/null
+++ b/test/network_tests/routing_tests/external_local_routing_test_starter.sh
@@ -0,0 +1,121 @@
+#!/bin/bash
+# Copyright (C) 2015-2017 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/.
+
+# Purpose: This script is needed to start the client and service with
+# one command. This is necessary as ctest - which is used to run the
+# tests - isn't able to start two binaries for one testcase. Therefore
+# the testcase simply executes this script. This script then runs client
+# and service and checks that both exit sucessfully.
+
+FAIL=0
+
+# Parameter 1: the pid to check
+check_tcp_udp_sockets_are_open ()
+{
+ # Check that the service does listen on at least one TCP/UDP socket
+ # awk is used to avoid the case when a inode number is the same as a PID. The awk
+ # program filters the netstat output down to the protocol (1st field) and
+ # the PID/Program name (last field) fields.
+ SERVICE_SOCKETS_LISTENING=$(netstat -tulpen 2> /dev/null | awk '{print $1 "\t" $NF}' | grep $1 | wc -l)
+ if [ $SERVICE_SOCKETS_LISTENING -lt 1 ]
+ then
+ ((FAIL+=1))
+ fi
+}
+
+# Parameter 1: the pid to check
+check_tcp_udp_sockets_are_closed ()
+{
+ # Check that the service does not listen on any TCP/UDP socket
+ # or has any active connection via a TCP/UDP socket
+ # awk is used to avoid the case when a inode number is the same as a PID. The awk
+ # program filters the netstat output down to the protocol (1st field) and
+ # the PID/Program name (last field) fields.
+ SERVICE_SOCKETS_LISTENING=$(netstat -tulpen 2> /dev/null | awk '{print $1 "\t" $NF}' | grep $1 | wc -l)
+ if [ $SERVICE_SOCKETS_LISTENING -ne 0 ]
+ then
+ ((FAIL+=1))
+ fi
+
+ SERVICE_SOCKETS_CONNECTED=$(netstat -tupen 2> /dev/null | awk '{print $1 "\t" $NF}' | grep $1 | wc -l)
+ if [ $SERVICE_SOCKETS_CONNECTED -ne 0 ]
+ then
+ ((FAIL+=1))
+ fi
+}
+
+# Start the service
+export VSOMEIP_APPLICATION_NAME=external_local_routing_test_service
+export VSOMEIP_CONFIGURATION=external_local_routing_test_service.json
+./external_local_routing_test_service &
+SERIVCE_PID=$!
+sleep 1;
+
+check_tcp_udp_sockets_are_open $SERIVCE_PID
+
+# Start the client (we reuse the one from the local_routing_test to check
+# the local routing functionality).
+export VSOMEIP_APPLICATION_NAME=local_routing_test_client
+export VSOMEIP_CONFIGURATION=local_routing_test_client.json
+./local_routing_test_client &
+CLIENT_PID=$!
+
+check_tcp_udp_sockets_are_open $SERIVCE_PID
+sleep 1
+check_tcp_udp_sockets_are_closed $CLIENT_PID
+
+# wait that local client finishes
+sleep 2
+
+# Display a message to show the user that he must now call the external client
+# to finish the test successfully
+kill -0 $CLIENT_PID &> /dev/null
+CLIENT_STILL_THERE=$?
+if [ $CLIENT_STILL_THERE -ne 0 ]
+then
+ if [ ! -z "$USE_LXC_TEST" ]; then
+ echo "starting external_local_routing_test_starter.sh on slave LXC"
+ ssh -tt -i $SANDBOX_ROOT_DIR/commonapi_main/lxc-config/.ssh/mgc_lxc/rsa_key_file.pub -o StrictHostKeyChecking=no root@$LXC_TEST_SLAVE_IP "bash -ci \"set -m; cd \\\$SANDBOX_TARGET_DIR/vsomeip_lib/test/network_tests; ./external_local_routing_test_client_external_start.sh\"" &
+ echo "remote ssh job id: $!"
+ elif [ ! -z "$USE_DOCKER" ]; then
+ docker exec $DOCKER_IMAGE sh -c "cd $DOCKER_TESTS && ./external_local_routing_test_client_external_start.sh" &
+ else
+ cat <<End-of-message
+*******************************************************************************
+*******************************************************************************
+** Please now run:
+** external_local_routing_test_client_external_start.sh
+** from an external host to successfully complete this test.
+**
+** You probably will need to adapt the 'unicast' settings in
+** external_local_routing_test_client_external.json and
+** external_local_routing_test_service.json to your personal setup.
+*******************************************************************************
+*******************************************************************************
+End-of-message
+ fi
+fi
+
+if [ ! -z "$USE_DOCKER" ]; then
+ FAIL=0
+fi
+
+# Wait until client and service are finished
+for job in $(jobs -p)
+do
+ # Fail gets incremented if either client or service exit
+ # with a non-zero exit code
+ wait $job || ((FAIL+=1))
+done
+
+# Check if client and server both exited sucessfully and the service didnt't
+# have any open
+if [ $FAIL -eq 0 ]
+then
+ exit 0
+else
+ exit 1
+fi
diff --git a/test/network_tests/routing_tests/local_routing_test_client.cpp b/test/network_tests/routing_tests/local_routing_test_client.cpp
new file mode 100644
index 0000000..d8bdfcb
--- /dev/null
+++ b/test/network_tests/routing_tests/local_routing_test_client.cpp
@@ -0,0 +1,167 @@
+// Copyright (C) 2015-2017 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/.
+
+#include "local_routing_test_client.hpp"
+
+local_routing_test_client::local_routing_test_client(bool _use_tcp) :
+ app_(vsomeip::runtime::get()->create_application()),
+ request_(vsomeip::runtime::get()->create_request(_use_tcp)),
+ blocked_(false),
+ is_available_(false),
+ number_of_messages_to_send_(vsomeip_test::NUMBER_OF_MESSAGES_TO_SEND),
+ number_of_sent_messages_(0),
+ number_of_acknowledged_messages_(0),
+ sender_(std::bind(&local_routing_test_client::run, this))
+{
+}
+
+bool local_routing_test_client::init()
+{
+ if (!app_->init()) {
+ ADD_FAILURE() << "Couldn't initialize application";
+ return false;
+ }
+
+ app_->register_state_handler(
+ std::bind(&local_routing_test_client::on_state, this,
+ std::placeholders::_1));
+
+ app_->register_message_handler(vsomeip::ANY_SERVICE,
+ vsomeip_test::TEST_SERVICE_INSTANCE_ID, vsomeip::ANY_METHOD,
+ std::bind(&local_routing_test_client::on_message, this,
+ std::placeholders::_1));
+
+ app_->register_availability_handler(vsomeip_test::TEST_SERVICE_SERVICE_ID,
+ vsomeip_test::TEST_SERVICE_INSTANCE_ID,
+ std::bind(&local_routing_test_client::on_availability, this,
+ std::placeholders::_1, std::placeholders::_2,
+ std::placeholders::_3));
+ return true;
+}
+
+void local_routing_test_client::start()
+{
+ VSOMEIP_INFO << "Starting...";
+ app_->start();
+}
+
+void local_routing_test_client::stop()
+{
+ VSOMEIP_INFO << "Stopping...";
+ app_->clear_all_handler();
+ app_->stop();
+}
+
+void local_routing_test_client::join_sender_thread(){
+ sender_.join();
+
+ ASSERT_EQ(number_of_sent_messages_, number_of_acknowledged_messages_);
+}
+
+void local_routing_test_client::on_state(vsomeip::state_type_e _state)
+{
+ if(_state == vsomeip::state_type_e::ST_REGISTERED)
+ {
+ app_->request_service(vsomeip_test::TEST_SERVICE_SERVICE_ID,
+ vsomeip_test::TEST_SERVICE_INSTANCE_ID, false);
+ }
+}
+
+void local_routing_test_client::on_availability(vsomeip::service_t _service,
+ vsomeip::instance_t _instance, bool _is_available)
+{
+ VSOMEIP_INFO << "Service [" << std::setw(4) << std::setfill('0') << std::hex
+ << _service << "." << _instance << "] is "
+ << (_is_available ? "available." : "NOT available.");
+
+ if(vsomeip_test::TEST_SERVICE_SERVICE_ID == _service
+ && vsomeip_test::TEST_SERVICE_INSTANCE_ID == _instance)
+ {
+ if(is_available_ && !_is_available)
+ {
+ is_available_ = false;
+ }
+ else if(_is_available && !is_available_)
+ {
+ is_available_ = true;
+ send();
+ }
+ }
+}
+
+void local_routing_test_client::on_message(const std::shared_ptr<vsomeip::message>& _response)
+{
+ VSOMEIP_INFO << "Received a response from Service [" << std::setw(4)
+ << std::setfill('0') << std::hex << _response->get_service() << "."
+ << std::setw(4) << std::setfill('0') << std::hex
+ << _response->get_instance() << "] to Client/Session ["
+ << std::setw(4) << std::setfill('0') << std::hex
+ << _response->get_client() << "/" << std::setw(4)
+ << std::setfill('0') << std::hex << _response->get_session() << "]";
+ number_of_acknowledged_messages_++;
+ if(number_of_acknowledged_messages_ == number_of_messages_to_send_) {
+ std::lock_guard<std::mutex> its_lock(mutex_);
+ blocked_ = true;
+ condition_.notify_one();
+ }
+}
+
+void local_routing_test_client::send()
+{
+ std::lock_guard<std::mutex> its_lock(mutex_);
+ blocked_ = true;
+ condition_.notify_one();
+}
+
+void local_routing_test_client::run()
+{
+ std::unique_lock<std::mutex> its_lock(mutex_);
+ while (!blocked_)
+ {
+ condition_.wait(its_lock);
+ }
+ blocked_ = false;
+ request_->set_service(vsomeip_test::TEST_SERVICE_SERVICE_ID);
+ request_->set_instance(vsomeip_test::TEST_SERVICE_INSTANCE_ID);
+ request_->set_method(vsomeip_test::TEST_SERVICE_METHOD_ID);
+
+ for (uint32_t i = 0; i < number_of_messages_to_send_; i++)
+ {
+ app_->send(request_);
+ VSOMEIP_INFO << "Client/Session [" << std::setw(4) << std::setfill('0')
+ << std::hex << request_->get_client() << "/" << std::setw(4)
+ << std::setfill('0') << std::hex << request_->get_session()
+ << "] sent a request to Service [" << std::setw(4)
+ << std::setfill('0') << std::hex << request_->get_service()
+ << "." << std::setw(4) << std::setfill('0') << std::hex
+ << request_->get_instance() << "]";
+ number_of_sent_messages_++;
+ }
+ blocked_ = false;
+ // wait until all messages have been acknowledged
+ while (!blocked_)
+ {
+ condition_.wait(its_lock);
+ }
+ stop();
+}
+
+TEST(someip_local_routing_test, send_ten_messages_to_service_and_receive_reply)
+{
+ bool use_tcp = false;
+ local_routing_test_client test_client_(use_tcp);
+ if (test_client_.init()) {
+ test_client_.start();
+ test_client_.join_sender_thread();
+ }
+}
+
+#if defined(__linux__) || defined(ANDROID)
+int main(int argc, char** argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
+#endif
diff --git a/test/network_tests/routing_tests/local_routing_test_client.hpp b/test/network_tests/routing_tests/local_routing_test_client.hpp
new file mode 100644
index 0000000..7cc442a
--- /dev/null
+++ b/test/network_tests/routing_tests/local_routing_test_client.hpp
@@ -0,0 +1,48 @@
+// Copyright (C) 2015-2017 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 LOCALROUTINGTESTCLIENT_HPP_
+#define LOCALROUTINGTESTCLIENT_HPP_
+
+#include <gtest/gtest.h>
+
+#include <vsomeip/vsomeip.hpp>
+
+#include <thread>
+#include <mutex>
+#include <condition_variable>
+#include <functional>
+
+#include "../someip_test_globals.hpp"
+
+class local_routing_test_client
+{
+public:
+ local_routing_test_client(bool _use_tcp);
+ bool init();
+ void start();
+ void stop();
+ void join_sender_thread();
+ void on_state(vsomeip::state_type_e _state);
+ void on_availability(vsomeip::service_t _service,
+ vsomeip::instance_t _instance, bool _is_available);
+ void on_message(const std::shared_ptr<vsomeip::message> &_response);
+ void send();
+ void run();
+
+private:
+ std::shared_ptr<vsomeip::application> app_;
+ std::shared_ptr<vsomeip::message> request_;
+ std::mutex mutex_;
+ std::condition_variable condition_;
+ bool blocked_;
+ bool is_available_;
+ std::uint32_t number_of_messages_to_send_;
+ std::uint32_t number_of_sent_messages_;
+ std::uint32_t number_of_acknowledged_messages_;
+ std::thread sender_;
+};
+
+#endif /* LOCALROUTINGTESTCLIENT_HPP_ */
diff --git a/test/network_tests/routing_tests/local_routing_test_client.json b/test/network_tests/routing_tests/local_routing_test_client.json
new file mode 100644
index 0000000..e3521c8
--- /dev/null
+++ b/test/network_tests/routing_tests/local_routing_test_client.json
@@ -0,0 +1,38 @@
+{
+ "unicast" : "127.0.0.1",
+ "netmask" : "255.255.255.0",
+ "diagnosis":"0x12",
+ "logging" :
+ {
+ "level" : "debug",
+ "console" : "true",
+ "file" :
+ {
+ "enable" : "true",
+ "path" : "/var/log/vsomeip.log"
+ },
+
+ "dlt" : "true"
+ },
+
+ "applications" :
+ [
+ {
+ "name" : "local_routing_test_client",
+ "id" : "0x1255"
+ }
+ ],
+
+ "services" :
+ [
+ ],
+
+ "routing" : "routingmanagerd",
+ "service-discovery" :
+ {
+ "enable" : "false",
+ "multicast" : "224.0.0.1",
+ "port" : "30491",
+ "protocol" : "udp"
+ }
+} \ No newline at end of file
diff --git a/test/network_tests/routing_tests/local_routing_test_client_start.sh b/test/network_tests/routing_tests/local_routing_test_client_start.sh
new file mode 100755
index 0000000..ed4023e
--- /dev/null
+++ b/test/network_tests/routing_tests/local_routing_test_client_start.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+# Copyright (C) 2015-2017 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/.
+
+export VSOMEIP_APPLICATION_NAME=local_routing_test_client
+export VSOMEIP_CONFIGURATION=local_routing_test_client.json
+./local_routing_test_client
diff --git a/test/network_tests/routing_tests/local_routing_test_service.cpp b/test/network_tests/routing_tests/local_routing_test_service.cpp
new file mode 100644
index 0000000..6408057
--- /dev/null
+++ b/test/network_tests/routing_tests/local_routing_test_service.cpp
@@ -0,0 +1,164 @@
+// Copyright (C) 2015-2017 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/.
+
+#include "local_routing_test_service.hpp"
+
+local_routing_test_service::local_routing_test_service(bool _use_static_routing) :
+ app_(vsomeip::runtime::get()->create_application()),
+ is_registered_(false),
+ use_static_routing_(_use_static_routing),
+ blocked_(false),
+ number_of_received_messages_(0),
+ offer_thread_(std::bind(&local_routing_test_service::run, this))
+{
+}
+
+bool local_routing_test_service::init()
+{
+ std::lock_guard<std::mutex> its_lock(mutex_);
+
+ if (!app_->init()) {
+ ADD_FAILURE() << "Couldn't initialize application";
+ return false;
+ }
+ app_->register_message_handler(vsomeip_test::TEST_SERVICE_SERVICE_ID,
+ vsomeip_test::TEST_SERVICE_INSTANCE_ID, vsomeip_test::TEST_SERVICE_METHOD_ID,
+ std::bind(&local_routing_test_service::on_message, this,
+ std::placeholders::_1));
+
+ app_->register_state_handler(
+ std::bind(&local_routing_test_service::on_state, this,
+ std::placeholders::_1));
+
+ VSOMEIP_INFO << "Static routing " << (use_static_routing_ ? "ON" : "OFF");
+ return true;
+}
+
+void local_routing_test_service::start()
+{
+ VSOMEIP_INFO << "Starting...";
+ app_->start();
+}
+
+void local_routing_test_service::stop()
+{
+ VSOMEIP_INFO << "Stopping...";
+ app_->clear_all_handler();
+ app_->stop();
+}
+
+void local_routing_test_service::join_offer_thread()
+{
+ offer_thread_.join();
+}
+
+void local_routing_test_service::offer()
+{
+ app_->offer_service(vsomeip_test::TEST_SERVICE_SERVICE_ID, vsomeip_test::TEST_SERVICE_INSTANCE_ID);
+}
+
+void local_routing_test_service::stop_offer()
+{
+ app_->stop_offer_service(vsomeip_test::TEST_SERVICE_SERVICE_ID, vsomeip_test::TEST_SERVICE_INSTANCE_ID);
+}
+
+void local_routing_test_service::on_state(vsomeip::state_type_e _state)
+{
+ VSOMEIP_INFO << "Application " << app_->get_name() << " is "
+ << (_state == vsomeip::state_type_e::ST_REGISTERED ? "registered." :
+ "deregistered.");
+
+ if(_state == vsomeip::state_type_e::ST_REGISTERED)
+ {
+ if(!is_registered_)
+ {
+ is_registered_ = true;
+ std::lock_guard<std::mutex> its_lock(mutex_);
+ blocked_ = true;
+ // "start" the run method thread
+ condition_.notify_one();
+ }
+ }
+ else
+ {
+ is_registered_ = false;
+ }
+}
+
+void local_routing_test_service::on_message(const 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() << "]";
+
+ number_of_received_messages_++;
+
+ ASSERT_EQ(_request->get_service(), vsomeip_test::TEST_SERVICE_SERVICE_ID);
+ ASSERT_EQ(_request->get_method(), vsomeip_test::TEST_SERVICE_METHOD_ID);
+
+ // Check the protocol version this shall be set to 0x01 according to the spec.
+ // TR_SOMEIP_00052
+ ASSERT_EQ(_request->get_protocol_version(), 0x01);
+ // Check the message type this shall be 0xx (REQUEST) according to the spec.
+ // TR_SOMEIP_00055
+ ASSERT_EQ(_request->get_message_type(), vsomeip::message_type_e::MT_REQUEST);
+
+ // check the session id.
+ ASSERT_EQ(_request->get_session(), static_cast<vsomeip::session_t>(number_of_received_messages_));
+
+
+ // send response
+ std::shared_ptr<vsomeip::message> its_response =
+ vsomeip::runtime::get()->create_response(_request);
+
+ app_->send(its_response);
+
+ if(number_of_received_messages_ >= vsomeip_test::NUMBER_OF_MESSAGES_TO_SEND)
+ {
+ std::lock_guard<std::mutex> its_lock(mutex_);
+ blocked_ =true;
+ condition_.notify_one();
+ }
+ ASSERT_LT(number_of_received_messages_,
+ vsomeip_test::NUMBER_OF_MESSAGES_TO_SEND + 1);
+}
+
+void local_routing_test_service::run()
+{
+ std::unique_lock<std::mutex> its_lock(mutex_);
+ while (!blocked_)
+ condition_.wait(its_lock);
+
+ blocked_ = false;
+ if(use_static_routing_)
+ {
+ offer();
+ }
+ while (!blocked_)
+ condition_.wait(its_lock);
+
+ std::thread t2([](){ std::this_thread::sleep_for(std::chrono::microseconds(1000000 * 5));});
+ t2.join();
+ app_->stop();
+}
+
+TEST(someip_local_routing_test, receive_ten_messages_over_local_uds_socket)
+{
+ bool use_static_routing = true;
+ local_routing_test_service test_service(use_static_routing);
+ if (test_service.init()) {
+ test_service.start();
+ test_service.join_offer_thread();
+ }
+}
+
+#if defined(__linux__) || defined(ANDROID)
+int main(int argc, char** argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
+#endif
diff --git a/test/network_tests/routing_tests/local_routing_test_service.hpp b/test/network_tests/routing_tests/local_routing_test_service.hpp
new file mode 100644
index 0000000..531fdb7
--- /dev/null
+++ b/test/network_tests/routing_tests/local_routing_test_service.hpp
@@ -0,0 +1,45 @@
+// Copyright (C) 2015-2017 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 LOCALROUTINGTESTSERVICE_HPP_
+#define LOCALROUTINGTESTSERVICE_HPP_
+#include <gtest/gtest.h>
+
+#include <vsomeip/vsomeip.hpp>
+
+#include <thread>
+#include <mutex>
+#include <condition_variable>
+#include <functional>
+
+#include "../someip_test_globals.hpp"
+
+class local_routing_test_service
+{
+public:
+ local_routing_test_service(bool _use_static_routing);
+ bool init();
+ void start();
+ void stop();
+ void offer();
+ void stop_offer();
+ void join_offer_thread();
+ void on_state(vsomeip::state_type_e _state);
+ void on_message(const std::shared_ptr<vsomeip::message> &_request);
+ void run();
+
+private:
+ std::shared_ptr<vsomeip::application> app_;
+ bool is_registered_;
+ bool use_static_routing_;
+
+ bool blocked_;
+ std::uint32_t number_of_received_messages_;
+ std::mutex mutex_;
+ std::condition_variable condition_;
+ std::thread offer_thread_;
+};
+
+#endif /* LOCALROUTINGTESTSERVICE_HPP_ */
diff --git a/test/network_tests/routing_tests/local_routing_test_service.json b/test/network_tests/routing_tests/local_routing_test_service.json
new file mode 100644
index 0000000..6b7e11d
--- /dev/null
+++ b/test/network_tests/routing_tests/local_routing_test_service.json
@@ -0,0 +1,41 @@
+{
+ "unicast" : "127.0.0.1",
+ "diagnosis":"0x12",
+ "logging" :
+ {
+ "level" : "debug",
+ "console" : "true",
+ "file" :
+ {
+ "enable" : "false",
+ "path" : "/tmp/vsomeip.log"
+ },
+
+ "dlt" : "false"
+ },
+
+ "applications" :
+ [
+ {
+ "name" : "local_routing_test_service",
+ "id" : "0x1277"
+ }
+ ],
+
+ "services" :
+ [
+ {
+ "service" : "0x1234",
+ "instance" : "0x5678"
+ }
+ ],
+
+ "routing" : "routingmanagerd",
+ "service-discovery" :
+ {
+ "enable" : "false",
+ "multicast" : "224.0.0.1",
+ "port" : "30490",
+ "protocol" : "udp"
+ }
+}
diff --git a/test/network_tests/routing_tests/local_routing_test_service_start.sh b/test/network_tests/routing_tests/local_routing_test_service_start.sh
new file mode 100755
index 0000000..c59364c
--- /dev/null
+++ b/test/network_tests/routing_tests/local_routing_test_service_start.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+# Copyright (C) 2015-2017 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/.
+
+export VSOMEIP_APPLICATION_NAME=local_routing_test_service
+export VSOMEIP_CONFIGURATION=local_routing_test_service.json
+./local_routing_test_service