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 10 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 @@ -656,6 +656,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 @@ -25,3 +25,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.3")
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 @@ -63,6 +63,7 @@ DEFINE_OPTION(FLB_IN_WINDOWS_EXPORTER_METRICS "Enable windows exporter metrics i
DEFINE_OPTION(FLB_IN_WINEVTLOG "Enable Windows EvtLog input plugin" OFF)
DEFINE_OPTION(FLB_IN_WINSTAT "Enable Windows Stat input plugin" OFF)
DEFINE_OPTION(FLB_IN_EBPF "Enable Linux eBPF input plugin" OFF)
DEFINE_OPTION(FLB_IN_SOMEIP "Enable SOME/IP input plugin" OFF)

# Processors
# ==========
Expand Down
1 change: 1 addition & 0 deletions cmake/windows-setup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ if(FLB_WINDOWS_DEFAULTS)
set(FLB_IN_EMITTER Yes)
set(FLB_IN_PODMAN_METRICS No)
set(FLB_IN_EBPF No)
set(FLB_IN_SOMEIP No)
set(FLB_IN_ELASTICSEARCH Yes)
set(FLB_IN_SPLUNK Yes)
set(FLB_IN_PROMETHEUS_REMOTE_WRITE Yes)
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-system1.74.0 \
libboost-thread1.74.0 \
libboost-filesystem1.74.0 \
&& \
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-system1.74.0 \
libboost-thread1.74.0 \
libboost-filesystem1.74.0 \
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
Loading