Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in_someip: SOME/IP input plugin #9570

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,11 @@ if(FLB_WASM)
endif ()
endif()

# SOME/IP
if(FLB_IN_SOMEIP)
add_subdirectory(${FLB_PATH_LIB_SOMEIP_C} EXCLUDE_FROM_ALL)
endif()

# AWS
if (FLB_AWS)
FLB_DEFINITION(FLB_HAVE_AWS)
Expand Down
1 change: 1 addition & 0 deletions cmake/libraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ set(FLB_PATH_LIB_SNAPPY "lib/snappy-fef67ac")
set(FLB_PATH_LIB_RDKAFKA "lib/librdkafka-2.4.0")
set(FLB_PATH_LIB_RING_BUFFER "lib/lwrb")
set(FLB_PATH_LIB_WASM_MICRO_RUNTIME "lib/wasm-micro-runtime-WAMR-1.3.0")
set(FLB_PATH_LIB_SOMEIP_C "lib/libsomeip-c")
1 change: 1 addition & 0 deletions cmake/plugins_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ DEFINE_OPTION(FLB_IN_PROMETHEUS_REMOTE_WRITE "Enable prometheus remote write in
DEFINE_OPTION(FLB_IN_PROMETHEUS_SCRAPE "Enable Prometheus Scrape input plugin" ON)
DEFINE_OPTION(FLB_IN_RANDOM "Enable random input plugin" ON)
DEFINE_OPTION(FLB_IN_SERIAL "Enable Serial input plugin" ON)
DEFINE_OPTION(FLB_IN_SOMEIP "Enable SOME/IP input plugin" OFF)
DEFINE_OPTION(FLB_IN_SPLUNK "Enable Splunk HTTP HEC input plugin" ON)
DEFINE_OPTION(FLB_IN_STATSD "Enable StatsD input plugin" ON)
DEFINE_OPTION(FLB_IN_STDIN "Enable Standard input plugin" ON)
Expand Down
54 changes: 54 additions & 0 deletions conf/in_someip.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[SERVICE]
# Flush
# =====
# Set an interval of seconds before to flush records to a destination
Flush 5

# Daemon
# ======
# Instruct Fluent Bit to run in foreground or background mode.
Daemon Off

# Log_Level
# =========
# Set the verbosity level of the service, values can be:
#
# - error
# - warning
# - info
# - debug
# - trace
#
# By default 'info' is set, that means it includes 'error' and 'warning'.
Log_Level trace

# HTTP Monitoring Server
# ======================
#
# HTTP_Monitor: enable/disable the HTTP Server to monitor
# Fluent Bit internals.
# HTTP_Port : specify the TCP port of the HTTP Server
HTTP_Monitor Off
HTTP_Port 2020

[INPUT]
Name someip
Tag in.someip

# Events to subscribe to.
# Each event should have form:
# Event <service id>,<instance id>,<event id>,<event group 1>,...
#
# Each event must have at least one event group
Event 4,1,32768,1
Event 4,1,32769,2

# RPC to send on startup
# Each RPC entry should have form:
# RPC <service id>,<instance id>,<method id>,<Request Payload>
#
# Request payload should be base64 encoded
RPC 4,1,1,CgAQAw==
[OUTPUT]
Name stdout
Match *
9 changes: 9 additions & 0 deletions dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ RUN echo "deb http://deb.debian.org/debian bookworm-backports main" >> /etc/apt/
flex \
bison \
libyaml-dev \
libboost-system-dev \
libboost-thread-dev \
libboost-filesystem-dev \
patrick-stephens marked this conversation as resolved.
Show resolved Hide resolved
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand Down Expand Up @@ -141,6 +144,9 @@ RUN echo "deb http://deb.debian.org/debian bookworm-backports main" >> /etc/apt/
liblzma5 \
libyaml-0-2 \
libcap2 \
libboost-system-dev \
libboost-thread-dev \
libboost-filesystem-dev \
Comment on lines +147 to +149
Copy link
Contributor

Choose a reason for hiding this comment

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

This is including the dev libraries in the runtime image - we should just have the minimal set of libraries needed for running fluent bit, not those for building it.

Copy link
Author

Choose a reason for hiding this comment

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

Hi @patrick-stephens, I tried to take these out, leaving only the entries above (line 57). But when I did, I was not able to build the SOME/IP input plugin and its dependent libraries from the dev container.

Likewise when I tried to replace these in this section with the "non-dev" version (libboost-filesystem1.74.0) the header files are not installed in the container and the build fails as well.

Please advise if there is something I am doing wrong here.

Copy link
Contributor

@patrick-stephens patrick-stephens Nov 18, 2024

Choose a reason for hiding this comment

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

Yeah I think you need to look at why, the dev libraries should only be in the build stage which is fine. At runtime we need the minimal set of dependencies required to run with, otherwise we end up opening a big bag of security worms with extra dependencies.

Header files are not needed at runtime, they should not be in the runtime image.

So I think you need to ensure the builder stage has the dev libraries to compile everything but then the dep-extractor stage only includes the runtime libraries.

&& \
mkdir -p /dpkg/var/lib/dpkg/status.d/ && \
for deb in *.deb; do \
Expand Down Expand Up @@ -221,6 +227,9 @@ RUN echo "deb http://deb.debian.org/debian bookworm-backports main" >> /etc/apt/
libatomic1 \
libgcrypt20 \
libyaml-0-2 \
libboost-system-dev \
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, do we really need the development libraries here or can we just use the runtime ones?

Copy link
Author

Choose a reason for hiding this comment

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

Same as above, I tried to change this section to the use the non-dev libs and was not able to build the SOME/IP plugin/libs from the dev container.

Copy link
Contributor

Choose a reason for hiding this comment

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

This section is unrelated to building so changing it here should have no impact on compilation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes but this is not compiling anything, this is the debug image so again should just have the minimum set of packages per the deb-extractor stage.

libboost-thread-dev \
libboost-filesystem-dev \
bash gdb valgrind build-essential \
git bash-completion vim tmux jq \
dnsutils iputils-ping iputils-arping iputils-tracepath iputils-clockdiff \
Expand Down
12 changes: 12 additions & 0 deletions lib/libsomeip-c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
project(someipc CXX)

add_subdirectory(vsomeip-3.5.1)

find_package(vsomeip3 REQUIRED)

add_library(someip-c SHARED src/someip_wrapper.cc)
target_include_directories(someip-c PUBLIC include)
target_link_libraries(someip-c PRIVATE vsomeip3 vsomeip3-sd vsomeip3-cfg vsomeip3-e2e)
target_link_options(someip-c PUBLIC "-Wl,--disable-new-dtags")

add_subdirectory(example)
3 changes: 3 additions & 0 deletions lib/libsomeip-c/example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

add_executable(someip_test_service test_service.c)
target_link_libraries(someip_test_service PRIVATE someip-c)
133 changes: 133 additions & 0 deletions lib/libsomeip-c/example/test_service.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/* Fluent Bit
* ==========
* Copyright (C) 2015-2024 The Fluent Bit Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "someip_api.h"


static const char* NAME = "Test Service";
static const uint16_t SERVICE_ID = 4;
static const uint16_t INSTANCE_ID = 1;
static const uint16_t METHOD_ID = 1;
static const uint16_t EVENT_ID = 0x8000U;
static const uint16_t EVENT_GROUP_ID = 1;

static uint16_t client_id = 0;

/*
* Function to handle callback when a request is received.
* @param request_ptr Pointer to the structure that has the request details.
*/
void HandleRequest(void*, struct some_ip_request *request_ptr) {
static const char* response = "This is the response to the request";
int ret = 0;
if (request_ptr == NULL) {
return;
}
printf("Received request (method = %d)\n", request_ptr->method_id);
printf("Payload length = %ld\n", request_ptr->payload_len);

/* Normal service would Parse the request and perform/initiate some actions on it*/
/* For this example just send back a canned response */

ret = someip_send_response(client_id, request_ptr->request_id.client_request_id,
(void*)response, strlen(response));
if (ret != SOMEIP_RET_SUCCESS) {
printf("Failed to send response: %d\n", ret);
}
}

/*
* Function to initialize the test service with the SOME/IP library.
* @return 0 on success, -1 on failure.
*/
int Initialize() {
int ret = someip_initialize(NAME, &client_id);
if (ret != SOMEIP_RET_SUCCESS) {
printf("Failed to initialize SOME/IP: %d\n", ret);
return -1;
}

/* Register Request Handler */
ret = someip_register_request_handler(client_id, SERVICE_ID, INSTANCE_ID,
METHOD_ID, NULL, HandleRequest);

if (ret != SOMEIP_RET_SUCCESS) {
printf("Failed to register request handler: %d\n", ret);
someip_shutdown(client_id);
return -1;
}

/* Offer Event */
ret = someip_offer_event(client_id, SERVICE_ID, INSTANCE_ID, EVENT_ID, (uint16_t*)&EVENT_GROUP_ID, 1);
if (ret != SOMEIP_RET_SUCCESS) {
printf("Failed to Offer Event: %d\n", ret);
someip_shutdown(client_id);
return -1;
}

/* Offer Service */
ret = someip_offer_service(client_id, SERVICE_ID, INSTANCE_ID);
if (ret != SOMEIP_RET_SUCCESS) {
printf("Failed to Offer Service: %d\n", ret);
someip_shutdown(client_id);
return -1;
}

return 0;
}

void Teardown() {
someip_shutdown(client_id);
}

void SendEvent(const int num) {
const char* base_msg = "Event Number ";
char buffer[128];
int ret = 0;
strcpy(buffer, base_msg);
sprintf(buffer + strlen(base_msg), "%d", num);

printf("Sending event with message %s\n", buffer);

ret = someip_send_event(client_id, SERVICE_ID, INSTANCE_ID, EVENT_ID,
buffer, strlen(buffer));
if (ret != SOMEIP_RET_SUCCESS) {
printf ("Failed to send event, %d\n", ret);
}
}


int main() {
int num_events = 10;
if (Initialize() != 0) {
return EXIT_FAILURE;
}


for (int i = 0; i <= num_events; ++i) {
SendEvent(i);
sleep(2);
}

Teardown();
return EXIT_SUCCESS;
}
Loading