Skip to content

Commit 976746f

Browse files
Sunil-K-Sssugiura
authored andcommitted
UDP Multicast implementation (COVESA#155)
The feature can be enabled by setting WITH_UDP_CONNECTION to ON. Signed-off-by: sunil.s <[email protected]>
1 parent d6baeb7 commit 976746f

14 files changed

+684
-3
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ option(WITH_DLT_LOGSTORAGE_CTRL_UDEV "PROTOTYPE! Set to ON to build logstorage c
7878
option(WITH_DLT_USE_IPv6 "Set to ON for IPv6 support" ON)
7979
option(WITH_DLT_KPI "Set to ON to build src/kpi binaries" OFF)
8080
option(WITH_DLT_FATAL_LOG_TRAP "Set to ON to enable DLT_LOG_FATAL trap(trigger segv inside dlt-user library)" OFF)
81+
option(WITH_UDP_CONNECTION "Set to ON to enable dlt UDP multicast SUPPORT" ON)
8182

8283
# RPM settings
8384
set(GENIVI_RPM_RELEASE "1") # ${DLT_REVISION}")
@@ -262,6 +263,7 @@ message(STATUS "CMAKE_HOST_SYSTEM_PROCESSOR = ${CMAKE_HOST_SYSTEM_PROCESSOR}")
262263
message(STATUS "CMAKE_SYSTEM_PROCESSOR = ${CMAKE_SYSTEM_PROCESSOR}")
263264
message(STATUS "WITH_DLT_LOGSTORAGE_CTRL_UDEV = ${WITH_DLT_LOGSTORAGE_CTRL_UDEV}")
264265
message(STATUS "DLT_IPC = ${DLT_IPC}(Path: ${DLT_USER_IPC_PATH})")
266+
message(STATUS "WITH_UDP_CONNECTION = ${WITH_UDP_CONNECTION}")
265267
message(STATUS "Change a value with: cmake -D<Variable>=<Value>")
266268
message(STATUS "-------------------------------------------------------------------------------")
267269
message(STATUS)

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ DLT\_USER | genivi | Set user for process not ru
6363
WITH\_CHECK\_CONFIG\_FILE | OFF | Set to ON to create a configure file of CheckIncludeFiles and CheckFunctionExists
6464
CMAKE\_INSTALL\_PREFIX | /usr/local
6565
CMAKE\_BUILD\_TYPE | RelWithDebInfo
66+
WITH\_UDP\_CONNECTION | ON | Set to ON to enable dlt UDP multicast SUPPORT
6667

6768
#### Command Line Tool Options
6869

doc/dlt.conf.5.md

+12
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,18 @@ Maximal used memory for log storage cache in KB.
321321

322322
Default: 30000 KB
323323

324+
## UDPConnectionSetup
325+
326+
Enable or disable UDP connection. 0 = disabled, 1 = enabled
327+
328+
## UDPMulticastIPAddress
329+
330+
The address on which daemon multicasts the log messages
331+
332+
## UDPMulticastIPPort
333+
334+
The Multicase IP port. Default: 3491
335+
324336
# AUTHOR
325337

326338
Alexander Wenzel (alexander.aw.wenzel (at) bmw (dot) de)

src/daemon/CMakeLists.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ if(WITH_DLT_SHM_ENABLE)
4545
${PROJECT_SOURCE_DIR}/src/shared/dlt_shm.c)
4646
endif()
4747

48-
add_executable(dlt-daemon ${dlt_daemon_SRCS} ${systemd_SRCS})
49-
5048
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
5149
set(RT_LIBRARY rt)
5250
set(SOCKET_LIBRARY "")
@@ -55,6 +53,13 @@ else()
5553
set(SOCKET_LIBRARY socket)
5654
endif()
5755

56+
if(WITH_UDP_CONNECTION)
57+
include_directories(${PROJECT_SOURCE_DIR}/src/daemon/udp_connection)
58+
add_definitions(-DUDP_CONNECTION_SUPPORT)
59+
set(dlt_daemon_SRCS ${dlt_daemon_SRCS} ${PROJECT_SOURCE_DIR}/src/daemon/udp_connection/dlt_daemon_udp_socket.c)
60+
endif(WITH_UDP_CONNECTION)
61+
62+
add_executable(dlt-daemon ${dlt_daemon_SRCS} ${systemd_SRCS})
5863
target_link_libraries(dlt-daemon ${RT_LIBRARY} ${SOCKET_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
5964

6065
install(TARGETS dlt-daemon

src/daemon/dlt-daemon.c

+49
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
#include "dlt_daemon_offline_logstorage.h"
6666
#include "dlt_gateway.h"
6767

68+
#ifdef UDP_CONNECTION_SUPPORT
69+
# include "dlt_daemon_udp_socket.h"
70+
#endif
6871
#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) || defined(DLT_SYSTEMD_ENABLE)
6972
# include "sd-daemon.h"
7073
#endif
@@ -289,6 +292,11 @@ int option_file_parser(DltDaemonLocal *daemon_local)
289292
daemon_local->flags.contextLogLevel = DLT_LOG_INFO;
290293
daemon_local->flags.contextTraceStatus = DLT_TRACE_STATUS_OFF;
291294
daemon_local->flags.enforceContextLLAndTS = 0; /* default is off */
295+
#ifdef UDP_CONNECTION_SUPPORT
296+
daemon_local->UDPConnectionSetup = MULTICAST_CONNECTION_ENABLED;
297+
strncpy(daemon_local->UDPMulticastIPAddress, MULTICASTIPADDRESS, MULTICASTIP_MAX_SIZE - 1);
298+
daemon_local->UDPMulticastIPPort = MULTICASTIPPORT;
299+
#endif
292300

293301
/* open configuration file */
294302
if (daemon_local->flags.cvalue[0])
@@ -597,6 +605,33 @@ int option_file_parser(DltDaemonLocal *daemon_local)
597605
strncpy(daemon_local->flags.daemonFifoGroup, value, NAME_MAX);
598606
daemon_local->flags.daemonFifoGroup[NAME_MAX] = 0;
599607
}
608+
#endif
609+
#ifdef UDP_CONNECTION_SUPPORT
610+
else if (strcmp(token, "UDPConnectionSetup") == 0)
611+
{
612+
const long longval = strtol(value, NULL, 10);
613+
614+
if ((longval == MULTICAST_CONNECTION_DISABLED)
615+
|| (longval == MULTICAST_CONNECTION_ENABLED)) {
616+
daemon_local->UDPConnectionSetup = longval;
617+
printf("Option: %s=%s\n", token, value);
618+
}
619+
else {
620+
daemon_local->UDPConnectionSetup = MULTICAST_CONNECTION_DISABLED;
621+
fprintf(stderr,
622+
"Invalid value for UDPConnectionSetup set to default %ld\n",
623+
longval);
624+
}
625+
}
626+
else if (strcmp(token, "UDPMulticastIPAddress") == 0)
627+
{
628+
strncpy(daemon_local->UDPMulticastIPAddress, value,
629+
MULTICASTIP_MAX_SIZE - 1);
630+
}
631+
else if (strcmp(token, "UDPMulticastIPPort") == 0)
632+
{
633+
daemon_local->UDPMulticastIPPort = strtol(value, NULL, 10);
634+
}
600635
#endif
601636
else {
602637
fprintf(stderr, "Unknown option: %s=%s\n", token, value);
@@ -1204,6 +1239,20 @@ int dlt_daemon_local_connection_init(DltDaemon *daemon,
12041239
return DLT_RETURN_ERROR;
12051240
}
12061241

1242+
#ifdef UDP_CONNECTION_SUPPORT
1243+
1244+
if (daemon_local->UDPConnectionSetup == MULTICAST_CONNECTION_ENABLED) {
1245+
if (dlt_daemon_udp_connection_setup(daemon_local) < 0) {
1246+
dlt_log(LOG_ERR, "UDP fd creation and register in epoll failed\n");
1247+
return DLT_RETURN_ERROR;
1248+
}
1249+
else {
1250+
dlt_log(LOG_INFO, "UDP fd creation and register in epoll success\n");
1251+
}
1252+
}
1253+
1254+
#endif
1255+
12071256
/* create and open unix socket to receive incoming connections from
12081257
* control application
12091258
* socket access permission set to srw-rw---- (660) */

src/daemon/dlt-daemon.h

+5
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ typedef struct
157157
unsigned long RingbufferMaxSize;
158158
unsigned long RingbufferStepSize;
159159
unsigned long daemonFifoSize;
160+
#ifdef UDP_CONNECTION_SUPPORT
161+
int UDPConnectionSetup; /* enable/disable the UDP connection */
162+
char UDPMulticastIPAddress[MULTICASTIP_MAX_SIZE]; /* multicast ip addres */
163+
int UDPMulticastIPPort; /* multicast port */
164+
#endif
160165
} DltDaemonLocal;
161166

162167
typedef struct

src/daemon/dlt.conf

+12
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,15 @@ ControlSocketPath = /tmp/dlt-ctrl.sock
183183

184184
# Maximal used memory for Logstorage Cache in KB (Default: 30000 KB)
185185
# OfflineLogstorageCacheSize = 30000
186+
187+
##############################################################################
188+
# UDP Multicast Configuration #
189+
##############################################################################
190+
# Enable UDP connection support for daemon(Control Message/Multicast is enabled)
191+
UDPConnectionSetup = 1
192+
193+
# UDP multicast address(default:225.0.0.37)
194+
UDPMulticastIPAddress = 225.0.0.37
195+
196+
# UDP multicast port(default:3491)
197+
UDPMulticastIPPort = 3491

src/daemon/dlt_daemon_client.c

+15
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ static inline int8_t getStatus(uint8_t request_log, int context_log)
8181
return (request_log <= context_log) ? request_log : context_log;
8282
}
8383

84+
#ifdef UDP_CONNECTION_SUPPORT
85+
# include "dlt_daemon_udp_socket.h"
86+
#endif
87+
8488
/** @brief Sends up to 2 messages to all the clients.
8589
*
8690
* Runs through the client list and sends the messages to them. If the message
@@ -284,6 +288,17 @@ int dlt_daemon_client_send(int sock,
284288

285289
/* send messages to daemon socket */
286290
if ((daemon->mode == DLT_USER_MODE_EXTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) {
291+
#ifdef UDP_CONNECTION_SUPPORT
292+
293+
if (daemon_local->UDPConnectionSetup == MULTICAST_CONNECTION_ENABLED)
294+
dlt_daemon_udp_dltmsg_multicast(data1,
295+
size1,
296+
data2,
297+
size2,
298+
verbose);
299+
300+
#endif
301+
287302
if ((sock == DLT_DAEMON_SEND_FORCE) || (daemon->state == DLT_DAEMON_STATE_SEND_DIRECT)) {
288303
sent = dlt_daemon_client_send_all_multiple(daemon,
289304
daemon_local,

src/daemon/dlt_daemon_common.h

+9
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ extern "C" {
104104
#define DLT_DAEMON_SEM_FREE() { sem_post(&dlt_daemon_mutex); }
105105
extern sem_t dlt_daemon_mutex;
106106

107+
/* UDPMulticart Default IP and Port */
108+
# ifdef UDP_CONNECTION_SUPPORT
109+
# define MULTICASTIPADDRESS "225.0.0.37"
110+
# define MULTICASTIPPORT 3491
111+
# define MULTICASTIP_MAX_SIZE 256
112+
# define MULTICAST_CONNECTION_DISABLED 0
113+
# define MULTICAST_CONNECTION_ENABLED 1
114+
# endif
115+
107116
/**
108117
* Definitions of DLT daemon logging states
109118
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2019 LG Electronics Inc.
3+
* SPDX-License-Identifier: MPL-2.0
4+
*
5+
* This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
6+
* If a copy of the MPL was not distributed with this file,
7+
* You can obtain one at http://mozilla.org/MPL/2.0/.
8+
*
9+
* For further information see http://www.genivi.org/.
10+
*/
11+
12+
/*!
13+
* \author
14+
* Guruprasad KN <[email protected]>
15+
* Sachin Sudhakar Shetty <[email protected]>
16+
* Sunil Kovila Sampath <[email protected]>
17+
*
18+
* \Copyright (c) 2019 LG Electronics Inc.
19+
* License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
20+
*
21+
* \file dlt_daemon_udp_common_socket.h
22+
*/
23+
24+
#ifndef DLT_DAEMON_UDP_COMMON_SOCKET_H
25+
#define DLT_DAEMON_UDP_COMMON_SOCKET_H
26+
27+
#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
28+
#include <errno.h>
29+
#include <net/if.h>
30+
#include <netdb.h>
31+
#include <netinet/in.h>
32+
#include <stdlib.h> /* for atoi() and exit() */
33+
#include <string.h> /* for memset() */
34+
#include <syslog.h>
35+
#include <sys/socket.h> /* for socket(), connect(), (), and recv() */
36+
#include <sys/ioctl.h>
37+
#include <sys/epoll.h>
38+
#include <unistd.h> /* for close() */
39+
40+
#include "dlt_common.h"
41+
#include "dlt-daemon.h"
42+
#include "dlt_daemon_common_cfg.h"
43+
#include "dlt_daemon_client.h"
44+
#include "dlt_daemon_connection.h"
45+
#include "dlt_daemon_udp_socket.h"
46+
#include "dlt_types.h"
47+
48+
/* #define variables */
49+
#define ADDRESS_VALID 1
50+
#define ADDRESS_INVALID 0
51+
#define SOCKPORT_MAX_LEN 6 /* port range 0-65535 */
52+
#define SYSTEM_CALL_ERROR -1
53+
#define ZERO_BYTE_RECIEVED 0
54+
#define ONE_BYTE_RECIEVED 0
55+
56+
typedef struct sockaddr_storage CLIENT_ADDR_STRUCT;
57+
typedef socklen_t CLIENT_ADDR_STRUCT_SIZE;
58+
59+
/* udp strutures */
60+
typedef struct
61+
{
62+
CLIENT_ADDR_STRUCT clientaddr;
63+
CLIENT_ADDR_STRUCT_SIZE clientaddr_size;
64+
int isvalidflag;
65+
} DltDaemonClientSockInfo;
66+
67+
/* Function prototype declaration */
68+
void dlt_daemon_udp_init_clientstruct(DltDaemonClientSockInfo *clientinfo_struct);
69+
DltReturnValue dlt_daemon_udp_socket_open(int *sock, unsigned int servPort);
70+
void dlt_daemon_udp_setmulticast_addr(DltDaemonLocal *daemon_local);
71+
72+
#endif /* DLT_DAEMON_UDP_COMMON_SOCKET_H */
73+

0 commit comments

Comments
 (0)