Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,20 @@
"--compile-commands-dir=${workspaceFolder}/",
"--pretty",
"--background-index",
"--query-driver=/var/cache/bazel/*/execroot/_main/external/toolchains_llvm++llvm+llvm_toolchain/bin/cc_wrapper.sh"
"--query-driver=/var/cache/bazel/*/execroot/_main/external/toolchains_llvm++llvm+llvm_toolchain/bin/cc_wrapper.sh",
"--query-driver=${userHome}/.cache/bazel/**/execroot/_main/external/toolchains_llvm++llvm+llvm_toolchain/bin/cc_wrapper.sh"
],
"cSpell.words": [
"ASIL",
"bazelbuild",
"flatbuffer",
"flatbuffers",
"gatewayd",
"hdrs",
"socom",
"someip",
"someipd",
"srcs",
"vsomeip"
],
}
24 changes: 24 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run bazel-compile-commands",
"command": "bazel-compile-commands",
"type": "shell",
"isBackground": true,
"hide": true
},
{
"label": "Update compile_commands.json",
"command": "${command:clangd.restart}",
"isBackground": true,
"dependsOn": [
"Run bazel-compile-commands"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
20 changes: 20 additions & 0 deletions src/config/mw_someip_config.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ table ServiceInstance {
instance_id: uint16 (key);
}

union SerializationConfig {
NullSerializerConfig,
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the idea is then for an actual serializer configuration to add it to the union?
Shouldn't we define the table for this already as well? Or would that be done with the actual serializer implementation?
Maybe leave a comment/hint then?


/// Configuration for the null serializer, which does not perform actual serialization but
/// instead uses pre-serialized message buffers.
table NullSerializerConfig {
/// Size of the pre-serialized message buffers.
max_message_size: uint32;
}

/// Describes a single event within a service.
table Event {
/// 16-bit identifier for this event within the service.
Expand All @@ -54,6 +65,9 @@ table Event {
/// Name of the event. Must exactly match the field name in the score::mw::com
/// service interface definition to correlate SOME/IP event IDs with IPC events.
event_name: string (required);

/// Serialization configuration for this event.
serialization_config: SerializationConfig;
}

/// Describes a single method within a service.
Expand All @@ -65,6 +79,12 @@ table Method {
/// Name of the method. Must exactly match the field name in the score::mw::com
/// service interface definition to correlate SOME/IP method IDs with IPC methods.
method_name: string (required);

/// Serialization configuration for the request (call) of this method.
request_serialization_config: SerializationConfig;

/// Serialization configuration for the response (return) of this method.
response_serialization_config: SerializationConfig;
}

root_type Root;
72 changes: 60 additions & 12 deletions src/config/mw_someip_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,51 @@
"events": [
{
"event_name": "echo_request_tiny",
"event_id": 34680
"event_id": 34680,
"serialization_config_type": "NullSerializerConfig",
"serialization_config": {
"max_message_size": 32
}
},
{
"event_name": "echo_request_small",
"event_id": 2
"event_id": 2,
"serialization_config_type": "NullSerializerConfig",
"serialization_config": {
"max_message_size": 88
}
},
{
"event_name": "echo_request_medium",
"event_id": 3
"event_id": 3,
"serialization_config_type": "NullSerializerConfig",
"serialization_config": {
"max_message_size": 1048
}
},
{
"event_name": "echo_request_large",
"event_id": 4
"event_id": 4,
"serialization_config_type": "NullSerializerConfig",
"serialization_config": {
"max_message_size": 8216
}
},
{
"event_name": "echo_request_xlarge",
"event_id": 5
"event_id": 5,
"serialization_config_type": "NullSerializerConfig",
"serialization_config": {
"max_message_size": 65560
}
},
{
"event_name": "echo_request_xxlarge",
"event_id": 6
"event_id": 6,
"serialization_config_type": "NullSerializerConfig",
"serialization_config": {
"max_message_size": 1048600
}
}
],
"local_service_instances": [
Expand All @@ -64,27 +88,51 @@
"events": [
{
"event_name": "echo_response_tiny",
"event_id": 34680
"event_id": 34680,
"serialization_config_type": "NullSerializerConfig",
"serialization_config": {
"max_message_size": 32
}
},
{
"event_name": "echo_response_small",
"event_id": 1
"event_id": 2,
"serialization_config_type": "NullSerializerConfig",
"serialization_config": {
"max_message_size": 88
}
},
{
"event_name": "echo_response_medium",
"event_id": 2
"event_id": 3,
"serialization_config_type": "NullSerializerConfig",
"serialization_config": {
"max_message_size": 1048
}
},
{
"event_name": "echo_response_large",
"event_id": 3
"event_id": 4,
"serialization_config_type": "NullSerializerConfig",
"serialization_config": {
"max_message_size": 8216
}
},
{
"event_name": "echo_response_xlarge",
"event_id": 4
"event_id": 5,
"serialization_config_type": "NullSerializerConfig",
"serialization_config": {
"max_message_size": 65560
}
},
{
"event_name": "echo_response_xxlarge",
"event_id": 5
"event_id": 6,
"serialization_config_type": "NullSerializerConfig",
"serialization_config": {
"max_message_size": 1048600
}
}
],
"remote_service_instances": [
Expand Down
36 changes: 36 additions & 0 deletions src/config/mw_someip_config.schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"definitions": {
"score_mw_someip_config_SerializationConfig" : {
"type" : "string",
"enum": ["NONE", "NullSerializerConfig"]
},
"score_mw_someip_config_Root" : {
"type" : "object",
"description" : "Top-level element of the gateway configuration",
Expand Down Expand Up @@ -68,6 +72,17 @@
"required" : ["instance_specifier"],
"additionalProperties" : false
},
"score_mw_someip_config_NullSerializerConfig" : {
"type" : "object",
"description" : "Configuration for the null serializer, which does not perform actual serialization but\ninstead uses pre-serialized message buffers.",
"properties" : {
"max_message_size" : {
"type" : "integer", "minimum" : 0, "maximum" : 4294967295,
"description" : "Size of the pre-serialized message buffers."
}
},
"additionalProperties" : false
},
"score_mw_someip_config_Event" : {
"type" : "object",
"description" : "Describes a single event within a service.",
Expand All @@ -79,6 +94,13 @@
"event_name" : {
"type" : "string",
"description" : "Name of the event. Must exactly match the field name in the score::mw::com\nservice interface definition to correlate SOME/IP event IDs with IPC events."
},
"serialization_config_type" : {
"$ref" : "#/definitions/score_mw_someip_config_SerializationConfig"
},
"serialization_config" : {
"anyOf": [{ "$ref" : "#/definitions/score_mw_someip_config_NullSerializerConfig" }],
"description" : "Serialization configuration for this event."
}
},
"required" : ["event_name"],
Expand All @@ -95,6 +117,20 @@
"method_name" : {
"type" : "string",
"description" : "Name of the method. Must exactly match the field name in the score::mw::com\nservice interface definition to correlate SOME/IP method IDs with IPC methods."
},
"request_serialization_config_type" : {
"$ref" : "#/definitions/score_mw_someip_config_SerializationConfig"
},
"request_serialization_config" : {
"anyOf": [{ "$ref" : "#/definitions/score_mw_someip_config_NullSerializerConfig" }],
"description" : "Serialization configuration for the request (call) of this method."
},
"response_serialization_config_type" : {
"$ref" : "#/definitions/score_mw_someip_config_SerializationConfig"
},
"response_serialization_config" : {
"anyOf": [{ "$ref" : "#/definitions/score_mw_someip_config_NullSerializerConfig" }],
"description" : "Serialization configuration for the response (return) of this method."
}
},
"required" : ["method_name"],
Expand Down
5 changes: 4 additions & 1 deletion src/gatewayd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ cc_binary(
":remote_service_instance",
"//src/config:config_flatbuffers",
"//src/network_service:consumer",
"//src/serializer",
"@score_baselibs//score/filesystem",
"@score_communication//score/mw/com",
],
Expand All @@ -47,6 +48,7 @@ cc_library(
deps = [
"//src/config:config_flatbuffers",
"//src/network_service:consumer",
"//src/serializer",
"@score_communication//score/mw/com",
],
)
Expand All @@ -59,7 +61,7 @@ cc_library(
"//src/common",
"//src/config:config_flatbuffers",
"//src/network_service:consumer",
"//tests/benchmarks:echo_service",
"//src/serializer",
"@score_baselibs//score/containers:non_relocatable_vector",
"@score_communication//score/mw/com",
],
Expand All @@ -85,5 +87,6 @@ native_binary(
data = [
"etc/mw_com_config.json",
"//src/config:config_file",
"//src/serializer:null_serializer",
],
)
35 changes: 29 additions & 6 deletions src/gatewayd/local_service_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "score/mw/com/com_error_domain.h"
#include "score/mw/com/types.h"
#include "src/serializer/serializer.h"

using score::mw::com::GenericProxy;
using score::mw::com::SamplePtr;
Expand Down Expand Up @@ -51,7 +52,23 @@ LocalServiceInstance::LocalServiceInstance(
}
auto& ipc_event = result->second;

ipc_event.SetReceiveHandler([this, &ipc_event, event_config]() {
auto service_type_name = service_type_config_->service_type_name()->string_view();
auto event_name = event_config->event_name()->string_view();
const score_com_serializer* serializer = nullptr;
auto get_result =
score_com_serializer_get(service_type_name.data(), service_type_name.size(),
score_com_serializer_element_type_event, event_name.data(),
event_name.size(), &serializer);
if (get_result != score_com_serializer_result_ok) {
std::cerr << "[gatewayd] Failed to get serializer for " << service_type_name
<< "::" << event_name << std::endl;
continue;
}
auto& event_context =
event_contexts_.emplace(event_name, EventContext{event_config, serializer})
.first->second;

ipc_event.SetReceiveHandler([this, &ipc_event, &event_context]() {
ipc_event.GetNewSamples(
[&](SamplePtr<void> sample) {
auto maybe_message = someip_message_skeleton_.message_.Allocate();
Expand All @@ -73,7 +90,7 @@ LocalServiceInstance::LocalServiceInstance(
message.data()[pos++] = static_cast<std::byte>(service_id >> 8);
message.data()[pos++] = static_cast<std::byte>(service_id & 0xFF);

std::uint16_t method_id = event_config->event_id();
std::uint16_t method_id = event_context.config->event_id();
message.data()[pos++] = static_cast<std::byte>(method_id >> 8);
message.data()[pos++] = static_cast<std::byte>(method_id & 0xFF);

Expand Down Expand Up @@ -102,11 +119,17 @@ LocalServiceInstance::LocalServiceInstance(
message.data()[pos++] = static_cast<std::byte>(return_code);

// Serialize payload
// TODO: Call serialization plugin here
auto payload = message.subspan(pos);
std::size_t payload_size = std::min(payload.size(), ipc_event.GetSampleSize());
std::memcpy(payload.data(), sample.get(), payload_size);
pos += payload_size;
std::size_t written_length = 0;
auto serialize_result = score_com_serializer_serialize(
event_context.serializer, reinterpret_cast<uint8_t*>(payload.data()),
payload.size(), sample.get(), &written_length);
if (serialize_result != score_com_serializer_result_ok) {
std::cerr << "[gatewayd] Serialization failed for "
<< event_context.config->event_name()->string_view() << std::endl;
return;
}
pos += written_length;

message_sample->size = pos;

Expand Down
10 changes: 10 additions & 0 deletions src/gatewayd/local_service_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
#ifndef SRC_GATEWAYD_LOCAL_SERVICE_INSTANCE
#define SRC_GATEWAYD_LOCAL_SERVICE_INSTANCE

#include <map>
#include <memory>
#include <string_view>
#include <vector>

#include "score/mw/com/types.h"
#include "src/config/mw_someip_config_generated.h"
#include "src/network_service/interfaces/message_transfer.h"

struct score_com_serializer;

namespace score::someip_gateway::gatewayd {

/// \brief Instance of a locally available service
Expand Down Expand Up @@ -81,6 +85,12 @@ class LocalServiceInstance {
/// Reference to the SOME/IP message skeleton for forwarding messages to the someipd daemon
network_service::interfaces::message_transfer::SomeipMessageTransferSkeleton&
someip_message_skeleton_;

struct EventContext {
const mw_someip_config::Event* config;
const ::score_com_serializer* serializer;
};
std::map<std::string_view, EventContext> event_contexts_;
};
} // namespace score::someip_gateway::gatewayd

Expand Down
Loading
Loading