Skip to content

Commit f3dc99b

Browse files
committed
Make openbmp support redis subscription/population on sonic.
1 parent 1a615a3 commit f3dc99b

10 files changed

Lines changed: 887 additions & 45 deletions

Server/CMakeLists.txt

Lines changed: 95 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ else()
77
set(SSL_LIBS )
88
endif()
99

10+
# cmake -DENABLE_REDIS=ON
11+
option(ENABLE_REDIS "Enable Redis population" OFF)
1012

13+
# Add the compile flag
14+
if(ENABLE_REDIS)
15+
add_definitions(-DREDIS_ENABLED)
16+
endif()
1117

1218
# Find and set the env for the mysql c++ connector
1319
set(HINT_ROOT_DIR
@@ -33,30 +39,57 @@ find_library(LIBYAML_CPP_LIBRARY
3339
lib64
3440
lib)
3541

36-
find_path(LIBRDKAFKA_INCLUDE_DIR
37-
librdkafka/rdkafkacpp.h
38-
HINTS
39-
${HINT_ROOT_DIR}
40-
PATH_SUFFIXES
41-
include)
42-
43-
find_library(LIBRDKAFKA_LIBRARY
44-
NAMES
45-
librdkafka.a rdkafka
46-
HINTS
47-
${HINT_ROOT_DIR}
48-
PATH_SUFFIXES
49-
lib64
50-
lib)
51-
52-
find_library(LIBRDKAFKA_CPP_LIBRARY
53-
NAMES
54-
librdkafka++.a rdkafka++
55-
HINTS
56-
${HINT_ROOT_DIR}
57-
PATH_SUFFIXES
58-
lib64
59-
lib)
42+
if (NOT ENABLE_REDIS)
43+
find_path(LIBRDKAFKA_INCLUDE_DIR
44+
librdkafka/rdkafkacpp.h
45+
HINTS
46+
${HINT_ROOT_DIR}
47+
PATH_SUFFIXES
48+
include)
49+
50+
find_library(LIBRDKAFKA_LIBRARY
51+
NAMES
52+
librdkafka.a rdkafka
53+
HINTS
54+
${HINT_ROOT_DIR}
55+
PATH_SUFFIXES
56+
lib64
57+
lib)
58+
59+
find_library(LIBRDKAFKA_CPP_LIBRARY
60+
NAMES
61+
librdkafka++.a rdkafka++
62+
HINTS
63+
${HINT_ROOT_DIR}
64+
PATH_SUFFIXES
65+
lib64
66+
lib)
67+
else ()
68+
find_path(LIBSWSSCOMMON_INCLUDE_DIR
69+
sonic-swss-common/common/dbconnector.h
70+
HINTS
71+
${HINT_ROOT_DIR}
72+
PATH_SUFFIXES
73+
include)
74+
75+
find_library(LIBHIREDIS_LIBRARY
76+
NAMES
77+
libhiredis.a hiredis
78+
HINTS
79+
${HINT_ROOT_DIR}
80+
PATH_SUFFIXES
81+
lib64
82+
lib)
83+
84+
find_library(LIBSWSSCOMMON_LIBRARY
85+
NAMES
86+
libswsscommon.a libswsscommon
87+
HINTS
88+
${HINT_ROOT_DIR}
89+
PATH_SUFFIXES
90+
lib64
91+
lib)
92+
endif ()
6093

6194
find_library(LIBRT_LIBRARY
6295
NAMES
@@ -67,10 +100,23 @@ find_library(LIBRT_LIBRARY
67100
lib64
68101
lib)
69102

70-
if (NOT LIBRDKAFKA_INCLUDE_DIR OR NOT LIBRDKAFKA_LIBRARY OR NOT LIBRDKAFKA_CPP_LIBRARY)
71-
Message (FATAL_ERROR "Librdkafka was not found, cannot proceed. Visit https://github.com/edenhill/librdkafka for details on how to install it.")
72-
#else ()
73-
# Message ("lib = " ${LIBRDKAFKA_LIBRARY})
103+
if (NOT ENABLE_REDIS)
104+
if (NOT LIBRDKAFKA_INCLUDE_DIR OR NOT LIBRDKAFKA_LIBRARY OR NOT LIBRDKAFKA_CPP_LIBRARY)
105+
Message (FATAL_ERROR "Librdkafka was not found, cannot proceed. Visit https://github.com/edenhill/librdkafka for details on how to install it.")
106+
else ()
107+
Message ("lib = " ${LIBRDKAFKA_LIBRARY})
108+
endif()
109+
else ()
110+
if (NOT LIBHIREDIS_LIBRARY)
111+
Message (FATAL_ERROR "Libhiredis was not found, cannot proceed. Visit https://github.com/redis/hiredis for details on how to install it.")
112+
else ()
113+
Message ("lib = " ${LIBHIREDIS_LIBRARY})
114+
endif()
115+
if (NOT LIBSWSSCOMMON_INCLUDE_DIR OR NOT LIBSWSSCOMMON_LIBRARY)
116+
Message (FATAL_ERROR "swsscommon was not found, cannot proceed. Visit https://github.com/sonic-net/sonic-swss-common for details on how to install it.")
117+
else ()
118+
Message ("lib = " ${LIBSWSSCOMMON_LIBRARY})
119+
endif()
74120
endif()
75121

76122
if (NOT LIBYAML_CPP_INCLUDE_DIR OR NOT LIBYAML_CPP_LIBRARY)
@@ -82,19 +128,18 @@ if (NOT LIBRT_LIBRARY AND NOT MACOSX)
82128
endif()
83129

84130
# Update the include dir
85-
include_directories(${LIBRDKAFKA_INCLUDE_DIR} ${LIBYAML_CPP_INCLUDE_DIR} src/ src/bmp src/bgp src/bgp/linkstate src/kafka)
131+
if (NOT ENABLE_REDIS)
132+
include_directories(${LIBRDKAFKA_INCLUDE_DIR} ${LIBYAML_CPP_INCLUDE_DIR} src/ src/bmp src/bgp src/bgp/linkstate src/kafka)
133+
else()
134+
include_directories(${LIBSWSSCOMMON_INCLUDE_DIR} ${LIBYAML_CPP_INCLUDE_DIR} src/ src/bmp src/bgp src/bgp/linkstate src/redis)
135+
endif()
86136
#link_directories(${LIBRDKAFKA_LIBRARY})
87137

88138

89139
# Define the source files to compile
90140
set (SRC_FILES
91141
src/bmp/BMPListener.cpp
92142
src/bmp/BMPReader.cpp
93-
src/kafka/MsgBusImpl_kafka.cpp
94-
src/kafka/KafkaEventCallback.cpp
95-
src/kafka/KafkaDeliveryReportCallback.cpp
96-
src/kafka/KafkaTopicSelector.cpp
97-
src/kafka/KafkaPeerPartitionerCallback.cpp
98143
src/openbmp.cpp
99144
src/bmp/parseBMP.cpp
100145
src/md5.cpp
@@ -114,6 +159,17 @@ set (SRC_FILES
114159
src/bgp/linkstate/MPLinkStateAttr.cpp
115160
)
116161

162+
# Add specific files used
163+
if (NOT ENABLE_REDIS)
164+
# Add Kafka-specific source files
165+
file(GLOB KAFKA_FILES src/kafka/MsgBusImpl_kafka.cpp src/kafka/KafkaEventCallback.cpp src/kafka/KafkaDeliveryReportCallback.cpp src/kafka/KafkaTopicSelector.cpp src/kafka/KafkaPeerPartitionerCallback.cpp)
166+
list(APPEND SRC_FILES ${KAFKA_FILES})
167+
else ()
168+
# Add Redis-specific source files
169+
file(GLOB REDIS_FILES src/RedisManager.cpp src/redis/MsgBusImpl_redis.cpp)
170+
list(APPEND SRC_FILES ${REDIS_FILES})
171+
endif ()
172+
117173
# Disable warnings
118174
add_definitions ("-Wno-unused-result")
119175

@@ -134,7 +190,11 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
134190
endif()
135191

136192
# Set the libs to link
137-
set (LIBS pthread ${LIBYAML_CPP_LIBRARY} ${LIBRDKAFKA_CPP_LIBRARY} ${LIBRDKAFKA_LIBRARY} z ${SSL_LIBS} dl)
193+
if (NOT ENABLE_REDIS)
194+
set (LIBS pthread ${LIBYAML_CPP_LIBRARY} ${LIBRDKAFKA_CPP_LIBRARY} ${LIBRDKAFKA_LIBRARY} z ${SSL_LIBS} dl)
195+
else ()
196+
set (LIBS pthread ${LIBYAML_CPP_LIBRARY} ${LIBHIREDIS_LIBRARY} ${LIBSWSSCOMMON_LIBRARY} z ${SSL_LIBS} dl)
197+
endif ()
138198

139199
# Set the binary
140200
add_executable (openbmpd ${SRC_FILES})

Server/src/Config.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
#include <boost/algorithm/string/replace.hpp>
2222

2323
#include "Config.h"
24+
25+
#ifndef REDIS_ENABLED
2426
#include "kafka/KafkaTopicSelector.h"
27+
#endif
2528

2629
/*********************************************************************//**
2730
* Constructor for class
@@ -62,6 +65,7 @@ Config::Config() {
6265
* The keys match the configuration node/vars. Topic name nodes will be ignored if
6366
* not initialized here.
6467
*/
68+
#ifndef REDIS_ENABLED
6569
topic_names_map[MSGBUS_TOPIC_VAR_COLLECTOR] = MSGBUS_TOPIC_COLLECTOR;
6670
topic_names_map[MSGBUS_TOPIC_VAR_ROUTER] = MSGBUS_TOPIC_ROUTER;
6771
topic_names_map[MSGBUS_TOPIC_VAR_PEER] = MSGBUS_TOPIC_PEER;
@@ -74,6 +78,7 @@ Config::Config() {
7478
topic_names_map[MSGBUS_TOPIC_VAR_LS_PREFIX] = MSGBUS_TOPIC_LS_PREFIX;
7579
topic_names_map[MSGBUS_TOPIC_VAR_L3VPN] = MSGBUS_TOPIC_L3VPN;
7680
topic_names_map[MSGBUS_TOPIC_VAR_EVPN] = MSGBUS_TOPIC_EVPN;
81+
#endif
7782
}
7883

7984
/*********************************************************************//**

0 commit comments

Comments
 (0)