How to Implement Client-Server Communication

Micael Coutinho,autosarapplicationarxml

Client-server is one of the multiple ways a Software Component is allowed to communicate at the VFB level, as described in the post (Types of Interfaces and Ports)[https://www.autosartoday.com/posts/types_of_interfaces_and_ports (opens in a new tab)].

Client-server communication is a form of API exchange at the VFB (Virtual Function Bus) level, used to provide functionalities from a Software Component (server) to one or more Software Components to consume (clients). A single interface can be used to provide multiple operations, which translate to C APIs, where each one has input, output and / or in-out arguments, again, just as a C function does. A PortPrototype typed by a ClientServerInterface is represented at the VFB level via a semi-circle, for a required port, or a circle, for a provided port, as seen in the picture below:

The port icons that represent server (left) and client (right) PortPrototypes

The port icons that represent server (left) and client (right) PortPrototypes

Client Behavior

A runnable can invoke a client-server operation connected to a require-port of its enclosing Software Component, synchronously, via a SynchronousServerCallPoint, or asynchronously, via an AsynchronousServerCallPoint (but an operation cannot be used by both at the same time). An operation can also take part on the same Software Component. Each of these call points reference a ClientServerOperation of an RPortPrototype.

The ServerCallPoints cannot be executed concurrently. If the call point is being used, it must be completed or returns with an error before it can be invoked again.

The serverCallPoints for the same operation that are part of the same Software Component must also define the same value for returnValueProvision, because the RTE generates the call point API once per Software Component (this also applies to the AsynchronousServerCallResultPoints in the same conditions). The timeout attribute must also have the same value.

In a SynchronousServerCallPoint, the call is blocking, meaning your runnable will not execute further until the respective call point is completed.

Client-Server communication via a SynchronousServerCallPoint

Client-Server communication via a SynchronousServerCallPoint

An AsynchronousServerCallPoint is defined by the runnable to trigger the execution of the operation. A response is returned via an AsynchronousServerCallReturnsEvent, which can also be associated with a WaitPoint, effectively blocking the runnable until the event is raised.

If a WaitPoint is not defined, the runnable executes until completion independently of the ClientServerOperation. Three elements need to be defined: an AsynchronousServerCallReturnsEvent, referencing a runnable that serves as a callback, which defines an AsynchronousServerCallResultPoint, where the results of the operation are retrieved (and is also referenced by the AsynchronousServerCallReturnsEvent) and an AsynchronousServerCallPoint, which references the operation and the AsynchronousServerCallResultPoint. This process can be observed in the figure below:

Client-Server communication via an AsynchronousServerCallPoint and an AsynchronousServerCallReturnsEvent triggering another runnable

Client-Server communication via an AsynchronousServerCallPoint and an AsynchronousServerCallReturnsEvent triggering another runnable

An AsynchronousServerCallPoint can only be referenced once by an AsynchronousServerCallResultPoint, which means the runnable defining the AsynchronousServerCallResultPoint can retrieve the result of the operation. The call result point must also only be referenced by one AsynchronousServerCallReturnsEvent.

If the AsynchronousServerCallPoint is not referenced by any result point, it means the result is not fetched and the result can be considered irrelevant by the RTE generator.

When the runnable calling the AsynchronousServerCallPoint must wait for the result, then a WaitPoint can be created, referring to the AsynchronousServerCallReturnsEvent that is associated with the AsynchronousServerCallResultPoint. The event does not reference a runnable via its startOnEvent attribute. In this configuration, the WaitPoint and the AsynchronousServerCallResultPoint must be part of the same runnable.

Client-Server communication via an AsynchronousServerCallPoint and an AsynchronousServerCallReturnsEvent unlocking a WaitPoint

Client-Server communication via an AsynchronousServerCallPoint and an AsynchronousServerCallReturnsEvent unlocking a WaitPoint

Meta-Model Elements Relevant to Client-Server Communication

There are a few meta-model elements relevant to the implementation of client-server communication: ClientServerInterface, ClientServerOperation, RunnableEntity, OperationInvokedEvent, SynchronousServerCallPoint and AsynchronousServerCallPoint. There are others, especially when you delve into inter-ECU communication, which requires data transformations.

For the sake of simplicity, we will consider the meta-classes for intra-ECU communication in this article. If you want to complement your learning, do read our post SomeIpXf Overview - SOME/IP Messages and VFB Serialization in Autosar (opens in a new tab), where you can learn in detail how client-server communication is serialized to be communicated via SOME/IP over a network.

ClientServerInterface

A ClientServerInterface is inherited from the PortInterface meta-class and includes the following attributes:

The PortInterface meta-class defines the properties:

ClientServerOperation

Each ClientServerOperation is comprised of the following elements:

The ArgumentDataPrototype element is used to define the arguments of an operation, similarly to a data element, while adding direction information over the argument. It can be based on the AutosarDataPrototype and DataPrototype classes and sets up the elements:

Client-server communication errors can be divided into two different types:

The ApplicationError element sets up the following property:

OperationInvokedEvent

On the Software Component defining the provider ports typed by ClientServerInterfaces, each ClientServerOperation is attached to a runnable that is invoked via an OperationInvokedEvent. The OperationInvokedEvent meta-class is not allowed to define disabledModes because the RTE does not support disabling the server via modes. If such functionality is desired, the server itself should implement it within its logic.

It is based on the RTEEvent meta-class and defines the attribute:

The RTEEvent meta-class is also an abstract class, serving multiple kinds of events involving the RTE. From the VFB perspective, a RunnableEntity can interact with RTE events in two ways: by the event enabling a runnable and via a WaitPoint, blocking a runnable until a specific RTE event occurs. It defines the attributes:

The RModeInAtomicSwcInstanceRef instance-reference contains the attributes:

SynchronousServerCallPoint and AsynchronousServerCallPoint

The ServerCallPoint is the abstract meta-class that serves the base for the SynchronousServerCallPoints and AsynchronousServerCallPoints. It is inherited from the AbstractAccessPoint meta-class and contains the properties:

The ROperationInAtomicSwcInstanceRef is defined by the properties:

The SynchronousServerCallPoint meta-class is defined by the property:

The AsynchronousServerCallPoint meta-class does not define further properties. The AsynchronousServerCallResultPoint meta-class defines the property:

WaitPoint

The WaitPoint meta-class defines a blocking point where a runnable must wait for an RTE event to proceed further (or a timeout period to expire). The presence of wait points in a runnable makes it a CAT2 runnable. The only events allowed to reference a runnable containing a WaitPoint are DataReceivedEvent, DataSendCompletedEvent, ModeSwitchedAckEvent and AsynchronousServerCallReturnsEvent or reference disabledModes. A CAT2 runnable cannot implement a mode switch because mode switches should be completed within a finite timing, and this is not guaranteed when in the presence of a WaitPoint. It is comprised by the attributes:

RunnableEntity

The RunnableEntity meta-class specifies the properties:

Closing Thoughts

This is almost everything you need to know when it comes to client-server communication. After reading this article, all you need to is practice! I recommend you pick up an Autosar ARXML design tool and connect the pieces together.

Do not forget to place yourself on the waiting list for the upcoming ebooks and see you next time!

Author: Micael Coutinho (opens in a new tab)

References:

© AutosarToday —@LinkedIn