Skip to content

Commit

Permalink
Make openbmp support redis subscription/population on sonic.
Browse files Browse the repository at this point in the history
  • Loading branch information
FengPan-Frank committed Apr 18, 2024
1 parent 1a615a3 commit f3dc99b
Show file tree
Hide file tree
Showing 10 changed files with 887 additions and 45 deletions.
130 changes: 95 additions & 35 deletions Server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ else()
set(SSL_LIBS )
endif()

# cmake -DENABLE_REDIS=ON
option(ENABLE_REDIS "Enable Redis population" OFF)

# Add the compile flag
if(ENABLE_REDIS)
add_definitions(-DREDIS_ENABLED)
endif()

# Find and set the env for the mysql c++ connector
set(HINT_ROOT_DIR
Expand All @@ -33,30 +39,57 @@ find_library(LIBYAML_CPP_LIBRARY
lib64
lib)

find_path(LIBRDKAFKA_INCLUDE_DIR
librdkafka/rdkafkacpp.h
HINTS
${HINT_ROOT_DIR}
PATH_SUFFIXES
include)

find_library(LIBRDKAFKA_LIBRARY
NAMES
librdkafka.a rdkafka
HINTS
${HINT_ROOT_DIR}
PATH_SUFFIXES
lib64
lib)

find_library(LIBRDKAFKA_CPP_LIBRARY
NAMES
librdkafka++.a rdkafka++
HINTS
${HINT_ROOT_DIR}
PATH_SUFFIXES
lib64
lib)
if (NOT ENABLE_REDIS)
find_path(LIBRDKAFKA_INCLUDE_DIR
librdkafka/rdkafkacpp.h
HINTS
${HINT_ROOT_DIR}
PATH_SUFFIXES
include)

find_library(LIBRDKAFKA_LIBRARY
NAMES
librdkafka.a rdkafka
HINTS
${HINT_ROOT_DIR}
PATH_SUFFIXES
lib64
lib)

find_library(LIBRDKAFKA_CPP_LIBRARY
NAMES
librdkafka++.a rdkafka++
HINTS
${HINT_ROOT_DIR}
PATH_SUFFIXES
lib64
lib)
else ()
find_path(LIBSWSSCOMMON_INCLUDE_DIR
sonic-swss-common/common/dbconnector.h
HINTS
${HINT_ROOT_DIR}
PATH_SUFFIXES
include)

find_library(LIBHIREDIS_LIBRARY
NAMES
libhiredis.a hiredis
HINTS
${HINT_ROOT_DIR}
PATH_SUFFIXES
lib64
lib)

find_library(LIBSWSSCOMMON_LIBRARY
NAMES
libswsscommon.a libswsscommon
HINTS
${HINT_ROOT_DIR}
PATH_SUFFIXES
lib64
lib)
endif ()

find_library(LIBRT_LIBRARY
NAMES
Expand All @@ -67,10 +100,23 @@ find_library(LIBRT_LIBRARY
lib64
lib)

if (NOT LIBRDKAFKA_INCLUDE_DIR OR NOT LIBRDKAFKA_LIBRARY OR NOT LIBRDKAFKA_CPP_LIBRARY)
Message (FATAL_ERROR "Librdkafka was not found, cannot proceed. Visit https://github.com/edenhill/librdkafka for details on how to install it.")
#else ()
# Message ("lib = " ${LIBRDKAFKA_LIBRARY})
if (NOT ENABLE_REDIS)
if (NOT LIBRDKAFKA_INCLUDE_DIR OR NOT LIBRDKAFKA_LIBRARY OR NOT LIBRDKAFKA_CPP_LIBRARY)
Message (FATAL_ERROR "Librdkafka was not found, cannot proceed. Visit https://github.com/edenhill/librdkafka for details on how to install it.")
else ()
Message ("lib = " ${LIBRDKAFKA_LIBRARY})
endif()
else ()
if (NOT LIBHIREDIS_LIBRARY)
Message (FATAL_ERROR "Libhiredis was not found, cannot proceed. Visit https://github.com/redis/hiredis for details on how to install it.")
else ()
Message ("lib = " ${LIBHIREDIS_LIBRARY})
endif()
if (NOT LIBSWSSCOMMON_INCLUDE_DIR OR NOT LIBSWSSCOMMON_LIBRARY)
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.")
else ()
Message ("lib = " ${LIBSWSSCOMMON_LIBRARY})
endif()
endif()

if (NOT LIBYAML_CPP_INCLUDE_DIR OR NOT LIBYAML_CPP_LIBRARY)
Expand All @@ -82,19 +128,18 @@ if (NOT LIBRT_LIBRARY AND NOT MACOSX)
endif()

# Update the include dir
include_directories(${LIBRDKAFKA_INCLUDE_DIR} ${LIBYAML_CPP_INCLUDE_DIR} src/ src/bmp src/bgp src/bgp/linkstate src/kafka)
if (NOT ENABLE_REDIS)
include_directories(${LIBRDKAFKA_INCLUDE_DIR} ${LIBYAML_CPP_INCLUDE_DIR} src/ src/bmp src/bgp src/bgp/linkstate src/kafka)
else()
include_directories(${LIBSWSSCOMMON_INCLUDE_DIR} ${LIBYAML_CPP_INCLUDE_DIR} src/ src/bmp src/bgp src/bgp/linkstate src/redis)
endif()
#link_directories(${LIBRDKAFKA_LIBRARY})


# Define the source files to compile
set (SRC_FILES
src/bmp/BMPListener.cpp
src/bmp/BMPReader.cpp
src/kafka/MsgBusImpl_kafka.cpp
src/kafka/KafkaEventCallback.cpp
src/kafka/KafkaDeliveryReportCallback.cpp
src/kafka/KafkaTopicSelector.cpp
src/kafka/KafkaPeerPartitionerCallback.cpp
src/openbmp.cpp
src/bmp/parseBMP.cpp
src/md5.cpp
Expand All @@ -114,6 +159,17 @@ set (SRC_FILES
src/bgp/linkstate/MPLinkStateAttr.cpp
)

# Add specific files used
if (NOT ENABLE_REDIS)
# Add Kafka-specific source files
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)
list(APPEND SRC_FILES ${KAFKA_FILES})
else ()
# Add Redis-specific source files
file(GLOB REDIS_FILES src/RedisManager.cpp src/redis/MsgBusImpl_redis.cpp)
list(APPEND SRC_FILES ${REDIS_FILES})
endif ()

# Disable warnings
add_definitions ("-Wno-unused-result")

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

# Set the libs to link
set (LIBS pthread ${LIBYAML_CPP_LIBRARY} ${LIBRDKAFKA_CPP_LIBRARY} ${LIBRDKAFKA_LIBRARY} z ${SSL_LIBS} dl)
if (NOT ENABLE_REDIS)
set (LIBS pthread ${LIBYAML_CPP_LIBRARY} ${LIBRDKAFKA_CPP_LIBRARY} ${LIBRDKAFKA_LIBRARY} z ${SSL_LIBS} dl)
else ()
set (LIBS pthread ${LIBYAML_CPP_LIBRARY} ${LIBHIREDIS_LIBRARY} ${LIBSWSSCOMMON_LIBRARY} z ${SSL_LIBS} dl)
endif ()

# Set the binary
add_executable (openbmpd ${SRC_FILES})
Expand Down
5 changes: 5 additions & 0 deletions Server/src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
#include <boost/algorithm/string/replace.hpp>

#include "Config.h"

#ifndef REDIS_ENABLED
#include "kafka/KafkaTopicSelector.h"
#endif

/*********************************************************************//**
* Constructor for class
Expand Down Expand Up @@ -62,6 +65,7 @@ Config::Config() {
* The keys match the configuration node/vars. Topic name nodes will be ignored if
* not initialized here.
*/
#ifndef REDIS_ENABLED
topic_names_map[MSGBUS_TOPIC_VAR_COLLECTOR] = MSGBUS_TOPIC_COLLECTOR;
topic_names_map[MSGBUS_TOPIC_VAR_ROUTER] = MSGBUS_TOPIC_ROUTER;
topic_names_map[MSGBUS_TOPIC_VAR_PEER] = MSGBUS_TOPIC_PEER;
Expand All @@ -74,6 +78,7 @@ Config::Config() {
topic_names_map[MSGBUS_TOPIC_VAR_LS_PREFIX] = MSGBUS_TOPIC_LS_PREFIX;
topic_names_map[MSGBUS_TOPIC_VAR_L3VPN] = MSGBUS_TOPIC_L3VPN;
topic_names_map[MSGBUS_TOPIC_VAR_EVPN] = MSGBUS_TOPIC_EVPN;
#endif
}

/*********************************************************************//**
Expand Down
Loading

0 comments on commit f3dc99b

Please sign in to comment.