【vsomeip】如何让vsomeip在双系统运行起来----(三)


前言

书接上文【vsomeip】如何让vsomeip在双系统运行起来----(二),原计划是将这个topic能写完,无奈遇到的坑太多,要把一个一个多的问题以及解决方案 写清楚也太烧脑了。本文将争取完成这个topic的书写,后续将关注于commonAPI的验证。

本文继续先验证vsomeip可以在Host Linux和LXC 里面的Guest Linux之间进行通信。

验证vsomeip自带helloworld例程
创建helloworld的Service和client的配置文件
验证双机情况下vsomeip通信
验证LXC 内外系统的vsomeip通信


一、修改LXC网络设备节点名

ubuntu@will:/tmp/vsomeip/examples/hello_world/build$ ./hello_world_client
... ...
2023-11-13 08:23:18.324669 [info] Network interface "eth0" state changed: up
2023-11-13 08:23:18.325077 [info] Route "default route (0.0.0.0/0) if: eth0 gw: 10.0.3.1" state changed: up

Check the log, I don’t known why keyword “eth0” printed here but LXC default network device name is “lxcbr0”, so I want to try to modify current network device node name from lxcbr0 to eth0.

1. modify LXC_BRIDGE = "eth0"
will@will-OptiPlex-7050:~/work/vsomeip/examples/hello_world$ cat vi /etc/default/lxc-net 
... ...
# If you change the LXC_BRIDGE to something other than lxcbr0, then
# you will also need to update your /etc/lxc/default.conf as well as the
# configuration (/var/lib/lxc/<container>/config) for any containers
# already created using the default config to reflect the new bridge
# name.
# If you have the dnsmasq daemon installed, you'll also have to update
# /etc/dnsmasq.d/lxc and restart the system wide dnsmasq daemon.
LXC_BRIDGE="eth0"

2. modify lxc.net.0.link to eth0.
cat /etc/lxc/default.conf 
lxc.net.0.type = veth
lxc.net.0.link = eth0
lxc.net.0.flags = up
lxc.net.0.hwaddr = 00:16:3e:xx:xx:xx

3.modify lxc.net.0.link to eth0 as well.
will@will-OptiPlex-7050:~/work/vsomeip/examples/hello_world$ sudo cat /var/lib/lxc/will/config
... ...
lxc.net.0.link = eth0

4. after reboot, the modificaiton will take effect.

但是修改之后,对于这个问题的解决没帮助。。。

二、验证双机情况下vsomeip通信

Blocked basic communication issue several days, between HOST linux and GUEST linux. I have to settle for second best, refer to some sample on internet to verify vsomeip on two different physical PC, maybe easier for me.

  1. PC1, Ubuntu 18.04, as vsomeip service side
  2. PC2, Ubuntu 20.04, as vsomeip client side

1. Verify vsomeip on two physical PC1

helloworld-service.json

{
    "unicast":"192.168.168.121", //PC1 ip  add
    "netmask":"255.255.255.0",
    "logging":
    {
        "level":"debug",
        "console":"true"
    },

    "applications":
    [
        {
            "name":"hello_world_service",
            "id":"0x4444"
        },
		{
            "name":"hello_world_client",
            "id":"0x5555"
        }
    ],

    "services":
    [
        {
            "service":"0x1111",
            "instance":"0x2222",
            "unreliable": "30509"
        }
    ],

    "routing":"hello_world_service",
    "service-discovery":
    {
        "enable":"true",
        "multicast":"192.168.168.255",     //Set to gateway. Try to IP add randomly, vsomeip can't work!!!!!!!
        "port":"30490",
        "protocol":"udp",
        "initial_delay_min":"10",
        "initial_delay_max":"100",
        "repetitions_base_delay":"200",
        "repetitions_max":"3",
        "ttl":"3",
        "cyclic_offer_delay":"2000",
        "request_response_delay":"1500"
    }
}

在这里插入图片描述
log at service side:

will@ubuntu:~/work/vsomeip/examples/hello_world/build$ sudo ./hello_world_service
2023-11-14 10:36:20.819646 [info] Using configuration file: "../helloworld-service.json".
2023-11-14 10:36:20.820545 [info] Parsed vsomeip configuration in 0ms
2023-11-14 10:36:20.820698 [info] Configuration module loaded.
2023-11-14 10:36:20.820780 [info] Security disabled!
2023-11-14 10:36:20.821017 [info] Initializing vsomeip (3.4.9.1) application "hello_world_service".
2023-11-14 10:36:20.821440 [info] Instantiating routing manager [Host].
2023-11-14 10:36:20.823177 [info] create_routing_root: Routing root @ /tmp/vsomeip-0
2023-11-14 10:36:20.823997 [info] Service Discovery enabled. Trying to load module.
2023-11-14 10:36:20.827612 [info] Service Discovery module loaded.
2023-11-14 10:36:20.828350 [info] Application(hello_world_service, 4444) is initialized (11, 100).
2023-11-14 10:36:20.828766 [info] Starting vsomeip application "hello_world_service" (4444) using 2 threads I/O nice 255
2023-11-14 10:36:20.830273 [info] Client [4444] routes unicast:192.168.168.121, netmask:255.255.255.0
2023-11-14 10:36:20.830174 [info] main dispatch thread id from application: 4444 (hello_world_service) is: 7f59bb55c700 TID: 26021
2023-11-14 10:36:20.830478 [info] shutdown thread id from application: 4444 (hello_world_service) is: 7f59bad5b700 TID: 26022
2023-11-14 10:36:20.832176 [info] Watchdog is disabled!
2023-11-14 10:36:20.833586 [info] io thread id from application: 4444 (hello_world_service) is: 7f59bf429800 TID: 26018
2023-11-14 10:36:20.833729 [info] io thread id from application: 4444 (hello_world_service) is: 7f59b9d59700 TID: 26024
2023-11-14 10:36:20.834122 [info] create_local_server: Listening @ /tmp/vsomeip-4444
2023-11-14 10:36:20.835427 [info] OFFER(4444): [1111.2222:0.0] (true)
2023-11-14 10:36:20.838927 [info] vSomeIP 3.4.9.1 | (default)
2023-11-14 10:36:20.840206 [info] Network interface "ens38" state changed: up
2023-11-14 10:36:20.841301 [info] Route "default route (0.0.0.0/0) if: ens38 gw: 192.168.168.254" state changed: up
2023-11-14 10:36:20.841966 [info] udp_server_endpoint_impl: SO_RCVBUFFORCE successful.
2023-11-14 10:36:20.842251 [info] udp_server_endpoint_impl: SO_RCVBUF is: 1703936 (1703936) local port:30490
2023-11-14 10:36:20.842482 [debug] Joining to multicast group 192.168.168.255 from 192.168.168.121
2023-11-14 10:36:20.843202 [info] udp_server_endpoint_impl: SO_RCVBUFFORCE successful.
2023-11-14 10:36:20.843489 [info] udp_server_endpoint_impl: SO_RCVBUF is: 1703936 (1703936) local port:30509
2023-11-14 10:36:20.843683 [info] udp_server_endpoint_impl<multicast>: SO_RCVBUFFORCE: successful.
2023-11-14 10:36:20.844417 [info] udp_server_endpoint_impl<multicast>: SO_RCVBUF is: 1703936 (1703936) local port:30490
2023-11-14 10:36:20.843837 [info] SOME/IP routing ready.
2023-11-14 10:36:20.846047 [warning] Route "192.168.168.0/24 if: ens38 gw: n/a" state changed: up
2023-11-14 10:36:20.847393 [warning] Route "192.168.168.255/32 if: ens38 gw: n/a" state changed: up
2023-11-14 10:36:30.846980 [info] vSomeIP 3.4.9.1 | (default)
2023-11-14 10:36:40.857364 [info] vSomeIP 3.4.9.1 | (default)
2023-11-14 10:36:41.974417 [info] STOP OFFER(4444): [1111.2222:0.0] (true)
2023-11-14 10:36:41.976012 [info] Stopping vsomeip application "hello_world_service" (4444).
will@ubuntu:~/work/vsomeip/examples/hello_world/build$ will@ubuntu:

2. Verify vsomeip on two physical PC2

helloworld-client.json

{
    "unicast":"192.168.168.117",  //PC2 IP address
    "netmask":"255.255.255.0",
    "logging":
    {
        "level":"trace",
        "console":"true"
    },

    "applications":
    [
        {
            "name":"hello_world_service",
            "id":"0x4444"
        },
        {
            "name":"hello_world_client",
            "id":"0x5555"
        }
    ],

    "services":
    [
        {
            "service":"0x1111",
            "instance":"0x2222",
            "unreliable":"30509"
        }
    ],

    "routing":"hello_world_client",
    "service-discovery":
    {
        "enable":"true",
        "multicast":"192.168.168.254",  //Set to gateway!!!!
        "port":"30490",
        "protocol":"udp",
        "initial_delay_min":"10",
        "initial_delay_max":"100",
        "repetitions_base_delay":"200",
        "repetitions_max":"3",
        "ttl":"3",
        "cyclic_offer_delay":"2000",
        "request_response_delay":"1500"

    }
}

在这里插入图片描述
log at client side:

will@will-OptiPlex-7050:~/work/vsomeip/examples/hello_world/build$ ./hello_world_client
2023-11-14 10:36:35.642991 [info] Using configuration file: "../helloworld-client.json".
2023-11-14 10:36:35.643753 [info] Parsed vsomeip configuration in 0ms
2023-11-14 10:36:35.643878 [info] Configuration module loaded.
2023-11-14 10:36:35.643962 [info] Security disabled!
2023-11-14 10:36:35.644019 [info] Initializing vsomeip (3.4.9.1) application "hello_world_client".
2023-11-14 10:36:35.644637 [info] Instantiating routing manager [Host].
2023-11-14 10:36:35.645606 [info] create_routing_root: Routing root @ /tmp/vsomeip-0
2023-11-14 10:36:35.646351 [info] Service Discovery enabled. Trying to load module.
2023-11-14 10:36:35.649029 [info] Service Discovery module loaded.
2023-11-14 10:36:35.649597 [info] Application(hello_world_client, 5555) is initialized (11, 100).
2023-11-14 10:36:35.649852 [info] Starting vsomeip application "hello_world_client" (5555) using 2 threads I/O nice 255
2023-11-14 10:36:35.650737 [info] Client [5555] routes unicast:192.168.168.117, netmask:255.255.255.0
2023-11-14 10:36:35.651048 [info] shutdown thread id from application: 5555 (hello_world_client) is: 7f3867521700 TID: 28569
2023-11-14 10:36:35.650975 [info] main dispatch thread id from application: 5555 (hello_world_client) is: 7f3867d22700 TID: 28568
2023-11-14 10:36:35.653783 [info] Watchdog is disabled!
2023-11-14 10:36:35.654696 [info] io thread id from application: 5555 (hello_world_client) is: 7f3868632000 TID: 28566
2023-11-14 10:36:35.654730 [info] io thread id from application: 5555 (hello_world_client) is: 7f386651f700 TID: 28571
2023-11-14 10:36:35.654744 [info] REQUEST(5555): [1111.2222:255.4294967295]
2023-11-14 10:36:35.655790 [info] Avoid trigger SD find-service message for local service/instance/major/minor: 1111/2222/255/4294967295
2023-11-14 10:36:35.656571 [info] create_local_server: Listening @ /tmp/vsomeip-5555
2023-11-14 10:36:35.656991 [info] vSomeIP 3.4.9.1 | (default)
2023-11-14 10:36:35.657906 [info] Network interface "enp0s31f6" state changed: up
2023-11-14 10:36:35.658878 [info] Route "default route (0.0.0.0/0) if: enp0s31f6 gw: 192.168.168.254" state changed: up
2023-11-14 10:36:35.659530 [info] udp_server_endpoint_impl: SO_RCVBUF is: 212992 (1703936) local port:30490
2023-11-14 10:36:35.659852 [debug] Joining to multicast group 192.168.168.254 from 192.168.168.117
2023-11-14 10:36:35.660206 [info] SOME/IP routing ready.
2023-11-14 10:36:35.660807 [warning] Route "192.168.168.0/24 if: enp0s31f6 gw: n/a" state changed: up
2023-11-14 10:36:35.661042 [info] udp_server_endpoint_impl<multicast>: SO_RCVBUF is: 212992 (1703936) local port:30490
2023-11-14 10:36:36.021447 [info] endpoint_manager_impl::create_remote_client: 192.168.168.121:30509 reliable: 0 using local port: 0
2023-11-14 10:36:36.022291 [info] udp_client_endpoint_impl::connect: SO_RCVBUF is: 212992 (1703936) local port:0 remote:192.168.168.121:30509
**Sending: World
Received: Hello World**
2023-11-14 10:36:36.137838 [info] RELEASE(5555): [1111.2222]
2023-11-14 10:36:36.138285 [info] Stopping vsomeip application "hello_world_client" (5555).
will@will-OptiPlex-7050:~/work/vsomeip/examples/hello_world/build$

三、Important discovery in vsomeip

multicast in JSON file is determined by broadcast in ifconfig.!!!

四、验证LXC 内外系统的vsomeip通信

Actually I suspect the issue is caused by the wrong value of multicase, but no any clue found from internet. But I am glad to find the reason, and vsomeip can work between LXC internal and external after modify the multicase to correct one.

  1. HOST linux, LXC external OS, as vsomeip service side
  2. GUEST linux, LXC internal OS, as vsomeip client side
    配置文件修改对比:
    在这里插入图片描述
  3. unicast写入ifconfig里面的inet IP add,而multicast写入ifconfig里面broadcast的IP add。
  4. Client端的IP就写eth0那个就好,而Service端要写LXC bridge的IP信息,也就是default的lxcbr0,现在的eth0(被我前面修改过)。
    log at service side:
will@will-OptiPlex-7050:~/work/vsomeip/examples/hello_world/build$ ./hello_world_service 
2023-11-14 14:33:35.315366 [info] Using configuration file: "../helloworld-service.json".
2023-11-14 14:33:35.317193 [info] Parsed vsomeip configuration in 1ms
2023-11-14 14:33:35.317512 [info] Configuration module loaded.
2023-11-14 14:33:35.317750 [info] Security disabled!
2023-11-14 14:33:35.317927 [info] Initializing vsomeip (3.4.9.1) application "hello_world_service".
2023-11-14 14:33:35.318501 [info] Instantiating routing manager [Host].
2023-11-14 14:33:35.321988 [info] create_routing_root: Routing root @ /tmp/vsomeip-0
2023-11-14 14:33:35.324658 [info] Service Discovery enabled. Trying to load module.
2023-11-14 14:33:35.331264 [info] Service Discovery module loaded.
2023-11-14 14:33:35.332401 [info] Application(hello_world_service, 4444) is initialized (11, 100).
2023-11-14 14:33:35.332844 [info] Starting vsomeip application "hello_world_service" (4444) using 2 threads I/O nice 255
2023-11-14 14:33:35.334890 [info] Client [4444] routes unicast:10.0.3.1, netmask:255.255.255.0
2023-11-14 14:33:35.334977 [info] main dispatch thread id from application: 4444 (hello_world_service) is: 7fb3912f3700 TID: 31055
2023-11-14 14:33:35.335339 [info] shutdown thread id from application: 4444 (hello_world_service) is: 7fb390af2700 TID: 31056
2023-11-14 14:33:35.338993 [info] Watchdog is disabled!
2023-11-14 14:33:35.340629 [info] io thread id from application: 4444 (hello_world_service) is: 7fb392403ec0 TID: 31052
2023-11-14 14:33:35.341134 [info] io thread id from application: 4444 (hello_world_service) is: 7fb38b7fe700 TID: 31058
2023-11-14 14:33:35.343285 [info] create_local_server: Listening @ /tmp/vsomeip-4444
2023-11-14 14:33:35.344244 [info] OFFER(4444): [1111.2222:0.0] (true)
2023-11-14 14:33:35.344512 [info] vSomeIP 3.4.9.1 | (default)
2023-11-14 14:33:35.346158 [info] Network interface "eth0" state changed: up
2023-11-14 14:33:35.347912 [info] Route "10.0.3.0/24 if: eth0 gw: n/a" state changed: up
2023-11-14 14:33:35.349073 [info] udp_server_endpoint_impl: SO_RCVBUF is: 212992 (1703936) local port:30490
2023-11-14 14:33:35.349538 [debug] Joining to multicast group 10.0.3.255 from 10.0.3.1
2023-11-14 14:33:35.350794 [info] udp_server_endpoint_impl: SO_RCVBUF is: 212992 (1703936) local port:30509
2023-11-14 14:33:35.351177 [info] SOME/IP routing ready.
2023-11-14 14:33:35.352157 [info] udp_server_endpoint_impl<multicast>: SO_RCVBUF is: 212992 (1703936) local port:30490
2023-11-14 14:33:35.352698 [warning] Route "10.0.3.255/32 if: eth0 gw: n/a" state changed: up
2023-11-14 14:33:45.348377 [info] vSomeIP 3.4.9.1 | (default)
2023-11-14 14:33:48.426918 [info] STOP OFFER(4444): [1111.2222:0.0] (true)
2023-11-14 14:33:48.428843 [info] Stopping vsomeip application "hello_world_service" (4444).
will@will-OptiPlex-7050:~/work/vsomeip/examples/hello_world/build$

log at client side:

ubuntu@will:/tmp/vsomeip/examples/hello_world/build$ ./hello_world_client 
2023-11-14 06:33:42.321164 [info] Using configuration file: "../helloworld-client.json".
2023-11-14 06:33:42.321709 [info] Parsed vsomeip configuration in 0ms
2023-11-14 06:33:42.321769 [info] Configuration module loaded.
2023-11-14 06:33:42.321876 [info] Security disabled!
2023-11-14 06:33:42.321957 [info] Initializing vsomeip (3.4.9.1) application "hello_world_client".
2023-11-14 06:33:42.322747 [info] Instantiating routing manager [Host].
2023-11-14 06:33:42.323814 [info] create_routing_root: Routing root @ /tmp/vsomeip-0
2023-11-14 06:33:42.324808 [info] Service Discovery enabled. Trying to load module.
2023-11-14 06:33:42.326452 [info] Service Discovery module loaded.
2023-11-14 06:33:42.326745 [info] Application(hello_world_client, 5555) is initialized (11, 100).
2023-11-14 06:33:42.326935 [info] Starting vsomeip application "hello_world_client" (5555) using 2 threads I/O nice 255
2023-11-14 06:33:42.327611 [info] Client [5555] routes unicast:10.0.3.105, netmask:255.255.255.0
2023-11-14 06:33:42.327360 [info] main dispatch thread id from application: 5555 (hello_world_client) is: 7fe5a3a40700 TID: 2438
2023-11-14 06:33:42.327681 [info] shutdown thread id from application: 5555 (hello_world_client) is: 7fe5a323f700 TID: 2439
2023-11-14 06:33:42.329164 [info] Watchdog is disabled!
2023-11-14 06:33:42.329547 [info] REQUEST(5555): [1111.2222:255.4294967295]
2023-11-14 06:33:42.329803 [info] io thread id from application: 5555 (hello_world_client) is: 7fe5a4350000 TID: 2436
2023-11-14 06:33:42.329928 [info] Avoid trigger SD find-service message for local service/instance/major/minor: 1111/2222/255/4294967295
2023-11-14 06:33:42.329916 [info] io thread id from application: 5555 (hello_world_client) is: 7fe5a223d700 TID: 2441
2023-11-14 06:33:42.330474 [info] vSomeIP 3.4.9.1 | (default)
2023-11-14 06:33:42.330685 [info] create_local_server: Listening @ /tmp/vsomeip-5555
2023-11-14 06:33:42.331457 [info] Network interface "eth0" state changed: up
2023-11-14 06:33:42.332254 [info] Route "default route (0.0.0.0/0) if: eth0 gw: 10.0.3.1" state changed: up
2023-11-14 06:33:42.332977 [info] udp_server_endpoint_impl: SO_RCVBUF is: 212992 (1703936) local port:30490
2023-11-14 06:33:42.333297 [debug] Joining to multicast group 10.0.3.255 from 10.0.3.105
2023-11-14 06:33:42.333640 [info] SOME/IP routing ready.
2023-11-14 06:33:42.333884 [warning] Route "10.0.3.0/24 if: eth0 gw: n/a" state changed: up
2023-11-14 06:33:42.333944 [info] udp_server_endpoint_impl<multicast>: SO_RCVBUF is: 212992 (1703936) local port:30490
2023-11-14 06:33:42.334205 [warning] Route "10.0.3.255/32 if: eth0 gw: n/a" state changed: up
2023-11-14 06:33:43.365849 [info] endpoint_manager_impl::create_remote_client: 10.0.3.1:30509 reliable: 0 using local port: 0
2023-11-14 06:33:43.367132 [info] udp_client_endpoint_impl::connect: SO_RCVBUF is: 212992 (1703936) local port:0 remote:10.0.3.1:30509
Sending: World
Received: Hello World
2023-11-14 06:33:43.479656 [info] RELEASE(5555): [1111.2222]
2023-11-14 06:33:43.480653 [info] Stopping vsomeip application "hello_world_client" (5555).
ubuntu@will:/tmp/vsomeip/examples/hello_world/build$

总结

至此,这个topic就完成了。
这个topoic从开工到结束,大概用了5天时间,主要原因

  1. 开始用aliyun作为source list,会发现vsomeip前装lib会出现问题所以光切换Ubunt系统就花了不少时间
  2. LXC console卡住问题,找了很久原因也没解决
  3. vsomeip的一些error信息,以为是bug,但实际不影响
  4. JSON配置文件里面的IP,包含unicast和multicast的IP,不知道如何填写,后来经过摸索确认
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值