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

Make openbmp support redis subscription/population on sonic. #7

Merged
merged 48 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
f3dc99b
Make openbmp support redis subscription/population on sonic.
FengPan-Frank Apr 9, 2024
d37c454
Make openbmp support redis subscription/population on sonic.
FengPan-Frank Apr 9, 2024
5130a39
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank May 7, 2024
c02fb34
Merge branch 'master' of https://github.com/FengPan-Frank/sonic-openb…
FengPan-Frank May 7, 2024
3e81104
Merge branch 'master' of https://github.com/FengPan-Frank/sonic-openb…
FengPan-Frank May 7, 2024
846efdd
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank May 8, 2024
32e46c9
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank May 8, 2024
3d318b0
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank May 9, 2024
3055ca0
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank May 9, 2024
8f9bcbe
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank May 9, 2024
306b26d
Merge branch 'master' into fenpan_openbmp_redis
FengPan-Frank May 11, 2024
18f9d20
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank May 9, 2024
70d036e
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank May 13, 2024
83edca5
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank May 13, 2024
3d1a087
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Sep 19, 2024
81f3699
Update AzurePipeline
FengPan-Frank Oct 17, 2024
fdc7809
Update AzurePipeline
FengPan-Frank Oct 17, 2024
b37ad43
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Oct 17, 2024
c5cde33
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Oct 17, 2024
b336f7a
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Oct 17, 2024
1a12e1b
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Oct 17, 2024
ea2b2e5
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Oct 17, 2024
73f7499
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Oct 17, 2024
d92e3ac
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Oct 18, 2024
ebb2ba0
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Oct 18, 2024
b7e0993
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Oct 18, 2024
2d9436d
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Oct 18, 2024
ab30185
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Oct 18, 2024
6cadfc6
Fix comments
FengPan-Frank Oct 21, 2024
19eaffb
Fix comments for multiple asic
FengPan-Frank Oct 24, 2024
2d1d221
Fix comments for multiple asic
FengPan-Frank Oct 24, 2024
f096dee
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Oct 24, 2024
46a9d86
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Oct 24, 2024
ff7be6d
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Oct 24, 2024
d472ae2
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Oct 24, 2024
253e05c
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Oct 24, 2024
1c8f4b1
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Oct 24, 2024
18ed8d8
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Oct 24, 2024
770b83c
Fix comments
FengPan-Frank Nov 1, 2024
c9b4930
Fix comments
FengPan-Frank Nov 1, 2024
7227b99
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Nov 1, 2024
17d178d
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Nov 1, 2024
3335281
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Nov 2, 2024
76904f7
Remove initializeGlobalConfig
FengPan-Frank Nov 12, 2024
f35b88f
Remove initializeGlobalConfig
FengPan-Frank Nov 12, 2024
55593d6
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Nov 12, 2024
dc3d240
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Nov 12, 2024
cb079df
Merge branch 'fenpan_openbmp_redis' of https://github.com/FengPan-Fra…
FengPan-Frank Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 97 additions & 44 deletions Server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ if(ENABLE_REDIS)
add_definitions(-DREDIS_ENABLED)
endif()


# Find and set the env for the mysql c++ connector
set(HINT_ROOT_DIR
"${HINT_ROOT_DIR}"
Expand All @@ -40,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
swss/dbconnector.h
HINTS
${HINT_ROOT_DIR}
PATH_SUFFIXES
include)

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

find_library(LIBSWSSCOMMON_LIBRARY
NAMES
swsscommon
HINTS
${HINT_ROOT_DIR}
PATH_SUFFIXES
lib64
lib)
endif ()

find_library(LIBRT_LIBRARY
NAMES
Expand All @@ -74,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 (ENABLE_REDIS)
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()
else ()
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()
endif()

if (NOT LIBYAML_CPP_INCLUDE_DIR OR NOT LIBYAML_CPP_LIBRARY)
Expand All @@ -89,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 @@ -121,36 +159,51 @@ 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")

# Add C++11
# Add C++14
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(--std=c++11 SUPPORTS_STD_CXX11)
check_cxx_compiler_flag(--std=c++14 SUPPORTS_STD_CXX14)
check_cxx_compiler_flag(--std=c++0x SUPPORTS_STD_CXX01)
if(SUPPORTS_STD_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c++11")
if(SUPPORTS_STD_CXX14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++14")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c++14")
elseif(SUPPORTS_STD_CXX01)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++0x")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c++0x")
else()
message(ERROR "Compiler does not support --std=c++11 or --std=c++0x. Upgrade gcc 4.7 or greater")
message(ERROR "Compiler does not support --std=c++14 or --std=c++0x. Upgrade gcc 4.7 or greater")
endif()
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 zstd)
else ()
set (LIBS pthread ${LIBYAML_CPP_LIBRARY} z ${SSL_LIBS} dl)
endif ()

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

# Link the binary
target_link_libraries (openbmpd ${LIBS})
target_link_libraries (openbmpd ${LIBS} ${LIBSWSSCOMMON_LIBRARY})

if (LIBRT_LIBRARY)
target_link_libraries(openbmpd ${LIBRT_LIBRARY})
target_link_libraries(openbmpd ${LIBRT_LIBRARY} ${LIBSWSSCOMMON_LIBRARY})
endif()

# Install the binary and configs
Expand Down
2 changes: 2 additions & 0 deletions Server/openbmpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ debug:
bgp: false # BGP related
msgbus: false # Kafka/message bus - this will enable librdkafka debugging as well

redis:
multiAsic: false # SONiC multiASIC related
Copy link
Collaborator

@qiluo-msft qiluo-msft Oct 31, 2024

Choose a reason for hiding this comment

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

multiAsic

Could you explain what does it mean? I assume this feature should be supported on multi-asic. #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Per Hua's comments, existing use case for multiple asic is use api check and corresponding initialize flow.
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

You do not need to change this file. You need to call function is_multi_asic() to get the info in runtime.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

https://github.com/sonic-net/sonic-swss-common/blob/acc4805a8c2766a4d200c17fdfaba04b94792274/common/dbconnector.h#L100, is_multi_asic() is not exposed in swss-common now, could you suggest which API you mean in specific?
And double checked current sonic_py_common reads device path to get is_multi_asic value, refer https://github.com/sonic-net/sonic-buildimage/blob/master/src/sonic-py-common/sonic_py_common/multi_asic.py

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Made some test on multi-asic env, it's true that for bmp we only need to do SonicDBConfig::initializeConfig
(), only database docker needs SonicDBConfig::initializeGlobalConfig() and for database-xx docker only needs initializeConfig()
image


kafka:

Expand Down
31 changes: 31 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 All @@ -34,6 +37,9 @@ Config::Config() {
debug_bgp = false;
debug_bmp = false;
debug_msgbus = false;
#ifdef REDIS_ENABLED
redis_multiAsic = false;
#endif
bmp_buffer_size = 15 * 1024 * 1024; // 15MB
svr_ipv6 = false;
svr_ipv4 = true;
Expand Down Expand Up @@ -62,6 +68,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 +81,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 Expand Up @@ -104,6 +112,10 @@ void Config::load(const char *cfg_filename) {
parseDebug(node);
else if (key.compare("kafka") == 0)
parseKafka(node);
#ifdef REDIS_ENABLED
else if (key.compare("redis") == 0)
parseRedis(node);
#endif
else if (key.compare("mapping") == 0)
parseMapping(node);

Expand Down Expand Up @@ -578,7 +590,26 @@ void Config::parseKafka(const YAML::Node &node) {
}
}

#ifdef REDIS_ENABLED
/**
* Parse the Redis configuration
*
* \param [in] node Reference to the yaml NODE
*/
void Config::parseRedis(const YAML::Node &node) {
if (!redis_multiAsic and node["multiAsic"]) {
try {
redis_multiAsic = node["multiAsic"].as<bool>();

if (redis_multiAsic)
std::cout << " Config: redis multiAsic : " << redis_multiAsic << std::endl;

} catch (YAML::TypedBadConversion<bool> err) {
printWarning("redis.multiAsic is not of type boolean", node["multiAsic"]);
}
}
}
#endif

/**
* Parse the kafka topics configuration
Expand Down
12 changes: 12 additions & 0 deletions Server/src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class Config {
bool debug_bgp;
bool debug_bmp;
bool debug_msgbus;
#ifdef REDIS_ENABLED
bool redis_multiAsic;
#endif

int heartbeat_interval; ///< Heartbeat interval in seconds for collector updates
int tx_max_bytes; ///< Maximum transmit message size
Expand Down Expand Up @@ -150,6 +153,15 @@ class Config {
*/
void parseKafka(const YAML::Node &node);

#ifdef REDIS_ENABLED
/**
* Parse the redis configuration
*
* \param [in] node Reference to the yaml NODE
*/
void parseRedis(const YAML::Node &node);
#endif

/**
* Parse the kafka topics configuration
*
Expand Down
Loading
Loading