COVESA / vsomeip

An implementation of Scalable service-Oriented MiddlewarE over IP
Mozilla Public License 2.0
1.1k stars 681 forks source link

[BUG]: Facing an issue in while communicating between host and virtual machine #741

Open DharaniAllada opened 2 months ago

DharaniAllada commented 2 months ago

vSomeip Version

v3.4.10

Boost Version

1.71

Environment

Ubuntu 20.04.6

Describe the bug

The Problem statement i have to do is " Automate client server communication between the host PC and QEMU using SOMEIP. Validate the communication using wireshark."

So from the starting the steps i followed are:

sudo apt install cmake git gcc g++ libboost-system-dev libboost-thread-dev libboost-log-dev libboost-chrono-dev libboost-date-time-dev libboost-atomic-dev libboost-program-options-dev git clone https://github.com/GENIVI/vsomeip.git cd vsomeip mkdir build cd build cmake .. make sudo make install

In the host machine i wrote the client code and vsomeip.json under the vsomeip/examples

client-sample.cpp: :

include <vsomeip/vsomeip.hpp>

include

include

define SAMPLE_SERVICE_ID 0x1234

define SAMPLE_INSTANCE_ID 0x5678

define SAMPLE_METHOD_ID 0x0421

class Client { public: Client() : app_(vsomeip::runtime::get()->create_application("Client")) {}

        bool init()
    {
            if(!app_->init()) {
            std::cerr << "Failed to initialize application" << std::endl;
                    return false;
            }

            app_->register_message_handler(
                    SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_METHOD_ID,
                    std::bind(&Client::on_response, this, std::placeholders::_1));

            return true;
        }

        void start()
    {
        std::cout << "Client application started and initialized." << std::endl;
            app_->request_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);
            std::shared_ptr<vsomeip::message> request = vsomeip::runtime::get()->create_request();
        std::cout << "Sending request to service" << std::endl;
            app_->send(request);
            app_->start();
        }

        void stop()
    {
            app_->stop();
        }

private:
        void on_response(const std::shared_ptr<vsomeip::message> &_response)
    {
            std::shared_ptr<vsomeip::payload> payload = _response->get_payload();
            vsomeip::length_t length = payload->get_length();
            const vsomeip::byte_t* data = payload->get_data();

            std::vector<vsomeip::byte_t> response_data(data, data + length);
            std::string response_string(response_data.begin(), response_data.end());

            std::cout << "Received response: " << response_string << std::endl;
        }

        std::shared_ptr<vsomeip::application> app_;

};

int main() { Client cli; if (cli.init()) { cli.start(); }else { std::cerr << "Failed to initialize client application" << std::endl; } return 0; }

vsomeip.json :

{ "unicast": "Ip address of my host machine which is in network interface virbr0", "logging": { "level": "info" }, "applications": [ { "name": "Client", "id": "0x5678" } ], "services": [ { "service": "0x1234", "instance": "0x5678", "unreliable": { "port": 30509 }, "reliable": { "port": 30510 } } ], "service-discovery": { "enabled": true, "multicast": "244.0.0.1", "port": 30490 } }

Now in VM : i followed the steps

sudo apt install cmake git gcc g++ libboost-system-dev libboost-thread-dev libboost-log-dev libboost-chrono-dev libboost-date-time-dev libboost-atomic-dev libboost-program-options-dev git clone https://github.com/GENIVI/vsomeip.git cd vsomeip mkdir build cd build cmake .. make sudo make install

and later in vsomeip/examples i wrote :

service-sample.cpp:

include<vsomeip/vsomeip.hpp>

include

include

define SAMPLE_SERVICE_ID 0x1234

define SAMPLE_INSTANCE_ID 0x5678

define SAMPLE_METHOD_ID 0x0421

class Service { public: Service() : app_(vsomeip::runtime::get()->create_application("Service")){}

    bool init() {
        if(!app_ -> init()) {
            std::cerr << "Failed to initialize application" << std::endl;
            return false;
        }

        app_ -> register_message_handler(
            SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_METHOD_ID,
            std::bind(&Service::on_message, this, std::placeholders::_1));

        return true;
    }

    void start() {
        std::cout << "Service application started and initialized" << std::endl;
        app_ -> start();
    }

    void stop() {
        app_ -> stop();
    }

private:
    void on_message(const std::shared_ptr<vsomeip::message> &_request) {
        std::cout << "Received message and sending response..." << std::endl;
        std::shared_ptr<vsomeip::message> response = vsomeip::runtime::get() -> create_response(_request);
        response -> set_payload(vsomeip::runtime::get() -> create_payload());
        app_ -> send(response);
    }

    std::shared_ptr<vsomeip::application> app_;

};

int main() { Service srv; if(srv.init()) { srv.start(); } else { std::cerr << "Failed to initialize service application" << std::endl; } return 0; }

vsomeip.json:

{ "unicast": "Ip address of vm which is in network interface enp1s0", "logging": { "level": "info" }, "applications": [ { "name": "Service", "id": "0x1234" } ], "services": [ { "service": "0x1234", "instance": "0x5678", "unreliable": { "port": 30509 }, "reliable": { "port": 30510 } } ], "service-discovery": { "enabled": true, "multicast": "244.0.0.1", "port": 30490 } }

Now while running the cpp file in VM showing the log like:

2024-07-13 12:33:46.013083 [info] Using configuration file: "./vsomeip.json". 2024-07-13 12:33:46.013576 [info] Parsed vsomeip configuration in 0ms 2024-07-13 12:33:46.013649 [info] Configuration module loaded. 2024-07-13 12:33:46.013702 [info] Security disabled! 2024-07-13 12:33:46.013749 [info] Initializing vsomeip (3.4.10) application "Service". 2024-07-13 12:33:46.014694 [info] Instantiating routing manager [Host]. 2024-07-13 12:33:46.015743 [info] create_routing_root: Routing root @ /tmp/vsomeip-0 2024-07-13 12:33:46.016271 [info] Service Discovery enabled. Trying to load module. 2024-07-13 12:33:46.031342 [info] Service Discovery module loaded. 2024-07-13 12:33:46.031831 [info] Application(Service, 1234) is initialized (11, 100). Service application started and initialized 2024-07-13 12:33:46.032080 [info] Starting vsomeip application "Service" (1234) using 2 threads I/O nice 255 2024-07-13 12:33:46.032703 [info] Client [1234] routes unicast:192.168.122.245, netmask:255.255.255.0 2024-07-13 12:33:46.032558 [info] main dispatch thread id from application: 1234 (Service) is: 7f2785fd1700 TID: 2000 2024-07-13 12:33:46.033012 [info] shutdown thread id from application: 1234 (Service) is: 7f27857d0700 TID: 2001 2024-07-13 12:33:46.034135 [info] Watchdog is disabled! 2024-07-13 12:33:46.035344 [info] io thread id from application: 1234 (Service) is: 7f27868da000 TID: 1998 2024-07-13 12:33:46.035375 [info] io thread id from application: 1234 (Service) is: 7f277ffff700 TID: 2003 2024-07-13 12:33:46.035804 [info] vSomeIP 3.4.10 | (default) 2024-07-13 12:33:46.036234 [info] Network interface "enp1s0" state changed: up 2024-07-13 12:33:46.036464 [info] Route "default route (0.0.0.0/0) if: enp1s0 gw: 192.168.122.1" state changed: up 2024-07-13 12:33:46.037770 [info] udp_server_endpoint_impl: SO_RCVBUF is: 212992 (1703936) local port:30490 2024-07-13 12:33:46.038102 [info] SOME/IP routing ready. 2024-07-13 12:33:46.044640 [info] udp_server_endpoint_impl: SO_RCVBUF is: 212992 (1703936) local port:30490 2024-07-13 12:33:56.039503 [info] vSomeIP 3.4.10 | (default) 2024-07-13 12:34:06.043767 [info] vSomeIP 3.4.10 | (default)

And in Host machine when running cilient.cpp files :

2024-07-13 12:34:59.719344 [info] Using configuration file: "./vsomeip.json". 2024-07-13 12:34:59.721066 [info] Parsed vsomeip configuration in 5ms 2024-07-13 12:34:59.721124 [info] Configuration module loaded. 2024-07-13 12:34:59.721164 [info] Security disabled! 2024-07-13 12:34:59.721199 [info] Initializing vsomeip (3.4.10) application "Client". 2024-07-13 12:34:59.723491 [info] Instantiating routing manager [Host]. 2024-07-13 12:34:59.724106 [info] create_routing_root: Routing root @ /tmp/vsomeip-0 2024-07-13 12:34:59.724503 [info] Service Discovery enabled. Trying to load module. 2024-07-13 12:34:59.030269 [info] Service Discovery module loaded. 2024-07-13 12:34:59.111173 [info] Application(Client, 5678) is initialized (11, 100). Client application started and initialized. 2024-07-13 12:34:59.111636 [info] REQUEST(5678): [1234.5678:255.4294967295] 2024-07-13 12:34:59.111693 [info] Avoid trigger SD find-service message for local service/instance/major/minor: 1234/5678/255/4294967295 2024-07-13 12:34:59.112443 [info] create_local_server: Listening @ /tmp/vsomeip-5678

Sending request to service 2024-07-13 12:34:59.112758 [error] Routing info for remote service could not be found! (5678): [0000.0000.0000] 0001

2024-07-13 12:34:59.112855 [info] Starting vsomeip application "Client" (5678) using 2 threads I/O nice 255 2024-07-13 12:34:59.113666 [info] Client [5678] routes unicast:192.168.122.1, netmask:255.255.255.0 2024-07-13 12:34:59.113787 [info] main dispatch thread id from application: 5678 (Client) is: 7fdc550a4700 TID: 5498 2024-07-13 12:34:59.114274 [info] shutdown thread id from application: 5678 (Client) is: 7fdc548a3700 TID: 5499 2024-07-13 12:34:59.114675 [info] Watchdog is disabled! 2024-07-13 12:34:59.114946 [info] io thread id from application: 5678 (Client) is: 7fdc559ad000 TID: 5496 2024-07-13 12:34:59.114969 [info] io thread id from application: 5678 (Client) is: 7fdc4f7fe700 TID: 5501 2024-07-13 12:34:59.119681 [info] vSomeIP 3.4.10 | (default) 2024-07-13 12:34:59.120100 [info] Network interface "virbr0" state changed: up 2024-07-13 12:35:09.122365 [info] vSomeIP 3.4.10 | (default) 2024-07-13 12:35:19.124010 [info] vSomeIP 3.4.10 | (default) 2024-07-13 12:35:29.126866 [info] vSomeIP 3.4.10 | (default) 2024-07-13 12:35:39.127914 [info] vSomeIP 3.4.10 | (default)

Here in the log file of host it is showing like:

Sending request to service 2024-07-13 12:34:59.112758 [error] Routing info for remote service could not be found! (5678): [0000.0000.0000] 0001

i think there might some error there in finding the service can any one please help me with this

Reproduction Steps

No response

Expected behaviour

No response

Logs and Screenshots

No response

lutzbichler commented 1 month ago

Do your ever call to offer_service to actually offer your service to the client? From the log it seems you do not.

duartenfonseca commented 2 weeks ago

@DharaniAllada is this still an issue from your side?