Skip to content

Commit 647e444

Browse files
committed
Append hiredis into link since swss-common required
1 parent 1886a9d commit 647e444

14 files changed

Lines changed: 977 additions & 66 deletions

Server/CMakeLists.txt

Lines changed: 99 additions & 29 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,22 +39,57 @@ find_library(LIBYAML_CPP_LIBRARY
3339
lib64
3440
lib)
3541

36-
37-
find_path(LIBSWSSCOMMON_INCLUDE_DIR
38-
sonic-swss-common/common/dbconnector.h
39-
HINTS
40-
${HINT_ROOT_DIR}
41-
PATH_SUFFIXES
42-
include)
43-
44-
find_library(LIBSWSSCOMMON_LIBRARY
45-
NAMES
46-
libswsscommon.a libswsscommon
47-
HINTS
48-
${HINT_ROOT_DIR}
49-
PATH_SUFFIXES
50-
lib64
51-
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+
swsscommon
87+
HINTS
88+
${HINT_ROOT_DIR}
89+
PATH_SUFFIXES
90+
lib64
91+
lib)
92+
endif ()
5293

5394
find_library(LIBRT_LIBRARY
5495
NAMES
@@ -59,14 +100,25 @@ find_library(LIBRT_LIBRARY
59100
lib64
60101
lib)
61102

62-
63-
if (NOT LIBSWSSCOMMON_INCLUDE_DIR OR NOT LIBSWSSCOMMON_LIBRARY)
64-
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.")
65-
#else ()
66-
# Message ("lib = " ${LIBSWSSCOMMON_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 1 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()
67120
endif()
68121

69-
70122
if (NOT LIBYAML_CPP_INCLUDE_DIR OR NOT LIBYAML_CPP_LIBRARY)
71123
Message (FATAL_ERROR "Libyaml-cpp was not found, cannot proceed. Visit https://github.com/jbeder/yaml-cpp for install details.")
72124
endif()
@@ -75,10 +127,13 @@ if (NOT LIBRT_LIBRARY AND NOT MACOSX)
75127
Message (FATAL_ERROR "librt was not found, cannot proceed.")
76128
endif()
77129

78-
79-
80130
# Update the include dir
81-
include_directories(${LIBSWSSCOMMON_INCLUDE_DIR} ${LIBYAML_CPP_INCLUDE_DIR} src/ src/bmp src/bgp src/bgp/linkstate )
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()
136+
#link_directories(${LIBRDKAFKA_LIBRARY})
82137

83138

84139
# Define the source files to compile
@@ -104,6 +159,17 @@ set (SRC_FILES
104159
src/bgp/linkstate/MPLinkStateAttr.cpp
105160
)
106161

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+
107173
# Disable warnings
108174
add_definitions ("-Wno-unused-result")
109175

@@ -124,18 +190,22 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
124190
endif()
125191

126192
# Set the libs to link
127-
set (LIBS pthread ${LIBYAML_CPP_LIBRARY} ${LIBSWSSCOMMON_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} z ${SSL_LIBS} dl)
197+
endif ()
128198

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

132202
# Link the binary
133-
target_link_libraries (openbmpd ${LIBS})
203+
target_link_libraries (openbmpd ${LIBS} ${LIBSWSSCOMMON_LIBRARY})
134204

135205
if (LIBRT_LIBRARY)
136-
target_link_libraries(openbmpd ${LIBRT_LIBRARY})
206+
target_link_libraries(openbmpd ${LIBRT_LIBRARY} ${LIBSWSSCOMMON_LIBRARY})
137207
endif()
138208

139209
# Install the binary and configs
140210
install(TARGETS openbmpd DESTINATION bin COMPONENT binaries)
141-
install(FILES openbmpd.conf DESTINATION etc/openbmp/ COMPONENT config)
211+
install(FILES openbmpd.conf DESTINATION etc/openbmp/ COMPONENT config)

Server/src/Config.cpp

Lines changed: 23 additions & 1 deletion
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-
//#include "kafka/KafkaTopicSelector.h"
24+
25+
#ifndef REDIS_ENABLED
26+
#include "kafka/KafkaTopicSelector.h"
27+
#endif
2528

2629
/*********************************************************************//**
2730
* Constructor for class
@@ -57,6 +60,25 @@ Config::Config() {
5760
pat_enabled = false;
5861
bzero(admin_id, sizeof(admin_id));
5962

63+
/*
64+
* Initialized the kafka topic names
65+
* The keys match the configuration node/vars. Topic name nodes will be ignored if
66+
* not initialized here.
67+
*/
68+
#ifndef REDIS_ENABLED
69+
topic_names_map[MSGBUS_TOPIC_VAR_COLLECTOR] = MSGBUS_TOPIC_COLLECTOR;
70+
topic_names_map[MSGBUS_TOPIC_VAR_ROUTER] = MSGBUS_TOPIC_ROUTER;
71+
topic_names_map[MSGBUS_TOPIC_VAR_PEER] = MSGBUS_TOPIC_PEER;
72+
topic_names_map[MSGBUS_TOPIC_VAR_BMP_STAT] = MSGBUS_TOPIC_BMP_STAT;
73+
topic_names_map[MSGBUS_TOPIC_VAR_BMP_RAW] = MSGBUS_TOPIC_BMP_RAW;
74+
topic_names_map[MSGBUS_TOPIC_VAR_BASE_ATTRIBUTE] = MSGBUS_TOPIC_BASE_ATTRIBUTE;
75+
topic_names_map[MSGBUS_TOPIC_VAR_UNICAST_PREFIX] = MSGBUS_TOPIC_UNICAST_PREFIX;
76+
topic_names_map[MSGBUS_TOPIC_VAR_LS_NODE] = MSGBUS_TOPIC_LS_NODE;
77+
topic_names_map[MSGBUS_TOPIC_VAR_LS_LINK] = MSGBUS_TOPIC_LS_LINK;
78+
topic_names_map[MSGBUS_TOPIC_VAR_LS_PREFIX] = MSGBUS_TOPIC_LS_PREFIX;
79+
topic_names_map[MSGBUS_TOPIC_VAR_L3VPN] = MSGBUS_TOPIC_L3VPN;
80+
topic_names_map[MSGBUS_TOPIC_VAR_EVPN] = MSGBUS_TOPIC_EVPN;
81+
#endif
6082
}
6183

6284
/*********************************************************************//**

0 commit comments

Comments
 (0)