On this page
$ technical

Using SOME/IP to Communicate Between Two EC2 Instances

Setting up vsomeip client-server communication across AWS EC2 instances with AWS Transit Gateway multicast.

All articles

Co-authored with Randheer Ramesh and Atri Sarkar.

SOME/IP client-server communication topology across AWS Transit Gateway

Context

In this article, we will explore running a SOME/IP application on an AWS EC2 instance. The application in itself is fairly simple. It is a client-server application, where the client will send “World” and the server replies with “Hello, World!”. Along the way we will cover setting up EC2 with vsomeip (an implementation of SOME/IP) and enabling multicast in AWS using VPC (you can skip this section if you are not using AWS EC2).

SOME/IP:

SOME/IP is a service-oriented architecture; it is an application layer protocol. It can use both TCP and UDP for the transport layer. As you might have guessed, it runs on top of IP. We will be using the C++ open-source implementation called vsomeip by COVESA.

Spin up EC2 instance

Setup the EC2 instances in AWS following the official documentation.

Install vsomeip

First, clone the vsomeip repository:

git clone git@github.com:COVESA/vsomeip.git

Next, execute the following command to build the project and store the build artifacts:

cd vsomeip && \
mkdir build && \
cd build && \
cmake . && \
make && \
sudo make install

Note: You might have to run with sudo make install as it installs the vsomeip library into system directories.

Allow multicasting in AWS:

Multicast communication is not supported by default in AWS VPC. In order to enable multicast communication between instances, you need to create an AWS Transit Gateway Multicast Domain.

Steps to enable Multicast communication between instances:

  1. Create Transit Gateway

    • Open VPC Console in AWS
    • Open Transit Gateway from the left pane
    • Create a Transit Gateway with multicast support
  2. Create Transit Gateway Multicast Domain

    • Open Transit Gateway Multicast Domains from the VPC Console
    • Create a new Transit Gateway Multicast Domain
    • Choose the Transit Gateway created in step 1
    • Enable IGMPv2 Support
  3. Create Transit Gateway Attachments

    • Open Transit Gateway Attachments from the VPC Console
    • Create a new Transit Gateway Attachment
    • Choose the transit gateway from step 1
    • Under attachment type, select VPC and select your VPC ID
    • Choose the subnet IDs from the VPC for attachment
  4. Create Transit Gateway Multicast Domain Associations

    • Open Transit Gateway Multicast Domains from the VPC Console
    • Select the multicast Domain
    • Create new Subnet Associations by clicking the create association button
    • Select the subnets to associate
  5. Add Group Members in the Multicast Domain

    • Open the Multicast Domain from the VPC Console
    • Click on Actions -> Add Group Members
    • Specify the Group IP (Multicast Address) and select the network interfaces of your EC2 instances

Setting up the sample application

We will build a simple server application using UDP that runs on port 30509. This application listens for requests from other SOME/IP services and responds by appending "Hello, {request}". It can be cloned from:

git clone git@github.com:gnana-ganesh-tw/vsomeip-sample.git

This project contains two folders:

  • client
  • server

Build the client:

cd vsomeip-sample/client && \
mkdir build && \
cd build && \
cmake .. && \
make

Build the server:

cd vsomeip-sample/server && \
mkdir build && \
cd build && \
cmake .. && \
make

In the client folder, all code related to the client application is present. The interesting part here is the JSON configuration:

{  
  "unicast": "<your-client-IP>",  
  "netmask": "<your-netmask-IP>",  
  "logging": {  
    "level": "debug",  
    "console": "true",  
    "file": { "enable": "false", "path": "/var/log/vsomeip.log" },  
    "dlt": "false"  
  },  
  "applications": [  
    {  
      "name": "hello_world_client",  
      "id": "0x1313"  
    }  
  ],  
  "routing": "hello_world_client",  
  "service-discovery": {  
    "enable": "true",  
    "multicast": "224.224.224.245",  
    "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"  
  }  
}
  • unicast: IP address of the client application.
  • netmask: Netmask address of your machine (find it using ifconfig).
  • logging: Log level of the application (currently set to debug).
  • applications: Application ID and name.
  • routing: Routing service identifier.
  • service-discovery: Parameters used by the SOME/IP-SD protocol.

Similarly, the configuration file of the server looks like this:

{  
  "unicast": "<your-server-IP>",  
  "netmask": "<your-netmask-IP>",  
  "logging": {  
    "level": "debug",  
    "console": "true",  
    "file": { "enable": "false", "path": "/tmp/vsomeip.log" },  
    "dlt": "false"  
  },  
  "applications": [  
    {  
      "name": "hello_world_service",  
      "id": "0x1212"  
    }  
  ],  
  "services": [  
    {  
      "service": "0x1111",  
      "instance": "0x2222",  
      "unreliable": "30509"  
    }  
  ],  
  "routing": "hello_world_service",  
  "service-discovery": {  
    "enable": "true",  
    "multicast": "224.224.224.245",  
    "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"  
  }  
}
  • services: Configuration related to your services, specifying port 30509 over UDP ("unreliable").

Running the application

Host 1 (Server):

Run the server application:

cd ~/vsomeip-sample/server/build && \
VSOMEIP_CONFIGURATION=<path-to-the-config> VSOMEIP_APPLICATION_NAME=hello_world_service LD_LIBRARY_PATH=/usr/local/lib ./hello_world_service

Note: Make sure LD_LIBRARY_PATH points to where vsomeip libraries are installed (/usr/local/lib).

Host 2 (Client):

Run the client application:

cd ~/vsomeip-sample/client/build && \
VSOMEIP_CONFIGURATION=<path-to-the-config> VSOMEIP_APPLICATION_NAME=hello_world_client LD_LIBRARY_PATH=/usr/local/lib ./hello_world_client

You should see the client receive the response "Hello, World!".

Conclusion

This walkthrough demonstrates setting up SOME/IP communication between two EC2 instances across AWS Transit Gateway multicast.