diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 1be83baa6..56f48d3f5 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -42,9 +42,9 @@ jobs: libboost-system-dev libboost-filesystem-dev libboost-thread-dev \ libevent-dev libtool flex bison pkg-config g++ libssl-dev bash ./ci/install-thrift.sh - bash ./ci/install-nanomsg.sh - bash ./ci/install-pynng.sh + bash ./ci/install-nng.sh sudo ldconfig + bash ./ci/install-pynng.sh - name: Configure CMake run: | @@ -79,9 +79,9 @@ jobs: libboost-system-dev libboost-filesystem-dev libboost-thread-dev \ libevent-dev libtool flex bison pkg-config g++ libssl-dev bash ./ci/install-thrift.sh - bash ./ci/install-nanomsg.sh - bash ./ci/install-pynng.sh + bash ./ci/install-nng.sh sudo ldconfig + bash ./ci/install-pynng.sh - name: Configure CMake run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index d8c4aeedc..dd7ad01f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # Options -option(WITH_NANOMSG "Support generating Nanomsg events" ON) +option(WITH_NNG "Support generating Nanomsg-nng events" ON) option(WITH_THRIFT "Build Thrift RPC service" ON) option(WITH_PI "Build PI implementation for bmv2" OFF) option(WITH_PDFIXED "Build pdfixed for bmv2" OFF) @@ -46,7 +46,7 @@ option(WITH_STRESS_TESTS "Include stress tests" OFF) option(ENABLE_DEBUGGER "Enable bmv2 remote debugger" OFF) option(ENABLE_COVERAGE "Enable code coverage tracking" OFF) option(ENABLE_LOGGING_MACROS "Enable compile time debug and trace logging macros" ON) -option(ENABLE_ELOGGER "Enable nanomsg event logger" ON) +option(ENABLE_ELOGGER "Enable nanomsg-nng event logger" ON) option(ENABLE_MODULES "Allow loading third-party modules at runtime" ON) option(REQUIRE_MODULES "Require support for loading third-party modules at runtime" OFF) option(ENABLE_UNDETERMINISTIC_TESTS "Run undeterministic tests (e.g. queueing) when running tests" ON) @@ -127,9 +127,17 @@ endforeach() find_library(GMP_LIBRARY gmp REQUIRED) find_library(PCAP_LIBRARY pcap REQUIRED) -if(WITH_NANOMSG) - find_library(NANOMSG_LIBRARY nanomsg REQUIRED) - add_definitions(-DNANOMSG_ON) +if(WITH_NNG) + find_library(NNG_LIBRARY NAMES nng) + + # Check if the library was found + if(NNG_LIBRARY) + message(STATUS "Found nng: ${NNG_LIBRARY}") + else() + message(FATAL_ERROR "Could not find nng library") + endif() + + add_definitions(-DNNG_ON) if(ENABLE_ELOGGER) add_definitions(-DELOG_ON) @@ -208,7 +216,7 @@ add_subdirectory(third_party) add_subdirectory(src) add_subdirectory(include) -if(WITH_THRIFT AND WITH_NANOMSG AND WITH_TARGETS) +if(WITH_THRIFT AND WITH_NNG AND WITH_TARGETS) add_subdirectory(tests) endif() @@ -236,7 +244,7 @@ message(STATUS "Configuration summary:") message(STATUS " Version: ${BM_VERSION}") message(STATUS " Coverage enabled: ${ENABLE_COVERAGE}") message(STATUS " Logging macros enabled: ${ENABLE_LOGGING_MACROS}") -message(STATUS " With Nanomsg: ${WITH_NANOMSG}") +message(STATUS " With Nanomsg-nng: ${WITH_NNG}") message(STATUS " Event logger enabled: ${ENABLE_ELOGGER}") message(STATUS " Debugger enabled: ${ENABLE_DEBUGGER}") message(STATUS " With Thrift: ${WITH_THRIFT}") diff --git a/README.md b/README.md index d56a19341..e31ca6822 100644 --- a/README.md +++ b/README.md @@ -182,8 +182,8 @@ sudo dpkg -i /path/to/package.deb The following options can be specified during the configuration step: ```bash - # Disable Nanomsg support - cmake -DWITH_NANOMSG=OFF .. + # Disable Nanomsg-nng support + cmake -DWITH_NNG=OFF .. # Disable Thrift support cmake -DWITH_THRIFT=OFF .. @@ -247,7 +247,7 @@ To run the unit tests, simply do: make check -**If you get a nanomsg error when running the tests (make check), try running +**If you get a nanomsg-nng error when running the tests (make check), try running them as sudo** ### cmake-based build @@ -425,8 +425,8 @@ directory. You can also browse this documentation 32-bit fields) and **variable-length fields are now supported**. - We finally have unit tests! - While it is still incomplete, we provide a convenient 'event-logger' built on - top of nanomsg. Every time a 'significant' event happens (e.g. table hit, - parser transition,...) a message is broadcast on a nanomsg channel and any + top of nanomsg-nng. Every time a 'significant' event happens (e.g. table hit, + parser transition,...) a message is broadcast on a nanomsg-nng channel and any client can consume it. ### Are all features supported yet? diff --git a/ci/install-nanomsg.sh b/ci/install-nanomsg.sh deleted file mode 100644 index 63f8ff1c7..000000000 --- a/ci/install-nanomsg.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -source $THIS_DIR/common.sh - -# nanomsg is very confusing in how it manages SOVERSION vs VERSION, but this -# should be okay... (5.0.0 is the SOVERSION) -check_lib libnanomsg libnanomsg.so.5.0.0 - -set -e -wget https://github.com/nanomsg/nanomsg/archive/1.0.0.tar.gz -O nanomsg-1.0.0.tar.gz -tar -xzvf nanomsg-1.0.0.tar.gz -cd nanomsg-1.0.0 -mkdir build -cd build -# I added -DCMAKE_INSTALL_PREFIX=/usr because on my Ubuntu 14.04 machine, the -# library is installed in /usr/local/lib/x86_64-linux-gnu/ by default, and for -# some reason ldconfig cannot find it -cmake .. -DCMAKE_INSTALL_PREFIX=/usr -cmake --build . -sudo cmake --build . --target install -cd .. diff --git a/ci/install-nng.sh b/ci/install-nng.sh new file mode 100755 index 000000000..6bf60d0f6 --- /dev/null +++ b/ci/install-nng.sh @@ -0,0 +1,20 @@ +#! /bin/bash + +THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +source $THIS_DIR/common.sh + +check_lib libnng libnng.so.1 + +exit 0 + +set -ex +git clone https://github.com/nanomsg/nng +cd nng +git checkout v1.11 + +mkdir build +cd build +cmake -DBUILD_SHARED_LIBS=ON .. +make +# Installs into /usr/local by default +sudo make install diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index afcd84f21..761cdc3dd 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,5 +1,5 @@ # Translate some variables for use by config.h -if (WITH_NANOMSG AND ENABLE_ELOGGER) +if (WITH_NNG AND ENABLE_ELOGGER) set (BM_ELOG_ON 1) endif() if (HAVE_DLFCN_H) @@ -11,15 +11,15 @@ endif() if (HAVE_THRIFT_STDCXX_H) set (BM_HAVE_THRIFT_STDCXX_H 1) endif() -if (WITH_NANOMSG AND ENABLE_DEBUGGER) +if (WITH_NNG AND ENABLE_DEBUGGER) set(BM_DEBUG_ON 1) endif() if (ENABLE_LOGGING_MACROS) set(BM_LOG_DEBUG_ON 1) set(BM_LOG_TRACE_ON 1) endif() -if (WITH_NANOMSG) - set(BM_NANOMSG_ON 1) +if (WITH_NNG) + set(BM_NNG_ON 1) endif() if (WITH_THRIFT) set(BM_THRIFT_ON 1) @@ -74,8 +74,8 @@ if(WITH_THRIFT) ) endif() -# Install bm_apps headers if nanomsg is enabled -if(WITH_NANOMSG) +# Install bm_apps headers if nanomsg-nng is enabled +if(WITH_NNG) set(BM_APPS_HEADERS bm/bm_apps/notifications.h bm/bm_apps/packet_pipe.h diff --git a/include/bm/bm_sim/dev_mgr.h b/include/bm/bm_sim/dev_mgr.h index ac47f38d1..7b4f4bdc7 100644 --- a/include/bm/bm_sim/dev_mgr.h +++ b/include/bm/bm_sim/dev_mgr.h @@ -174,7 +174,7 @@ class DevMgr : public PacketDispatcherIface { // wait before starting to process packets. void set_dev_mgr_files(unsigned wait_time_in_seconds); -#ifdef BM_NANOMSG_ON +#ifdef BM_NNG_ON // if enforce ports is set to true, packets coming in on un-registered ports // are dropped void set_dev_mgr_packet_in( diff --git a/include/bm/bm_sim/nn.h b/include/bm/bm_sim/nn.h index c44f0b56d..8d29ad7e5 100644 --- a/include/bm/bm_sim/nn.h +++ b/include/bm/bm_sim/nn.h @@ -23,7 +23,7 @@ #ifndef NN_HPP_INCLUDED #define NN_HPP_INCLUDED -#include +#include #include #include diff --git a/include/bm/bm_sim/transport.h b/include/bm/bm_sim/transport.h index 3fe794381..e510ea8ea 100644 --- a/include/bm/bm_sim/transport.h +++ b/include/bm/bm_sim/transport.h @@ -61,7 +61,7 @@ class TransportIface { return send_msgs_(msgs); } -#ifdef BM_NANOMSG_ON +#ifdef BM_NNG_ON static std::unique_ptr make_nanomsg(const std::string &addr); #endif static std::unique_ptr make_dummy(); diff --git a/include/bm/config.h.in b/include/bm/config.h.in index 6b72426c6..7e31f1f8e 100644 --- a/include/bm/config.h.in +++ b/include/bm/config.h.in @@ -76,7 +76,7 @@ #cmakedefine BM_LOG_TRACE_ON @BM_LOG_TRACE_ON@ /* Enable Nanomsg support */ -#cmakedefine BM_NANOMSG_ON @BM_NANOMSG_ON@ +#cmakedefine BM_NNG_ON @BM_NNG_ON@ /* Enable Thrift support */ #cmakedefine BM_THRIFT_ON @BM_THRIFT_ON@ diff --git a/install_deps.sh b/install_deps.sh index db304f382..a715c00a7 100755 --- a/install_deps.sh +++ b/install_deps.sh @@ -28,7 +28,7 @@ tmpdir=`mktemp -d -p .` cd $tmpdir bash ../ci/install-thrift.sh -bash ../ci/install-nanomsg.sh +bash ../ci/install-nng.sh sudo ldconfig bash ../ci/install-pynng.sh diff --git a/install_deps_ubuntu_22.04.sh b/install_deps_ubuntu_22.04.sh index 550774fd9..b54361f48 100755 --- a/install_deps_ubuntu_22.04.sh +++ b/install_deps_ubuntu_22.04.sh @@ -23,7 +23,7 @@ apt-get install -qq --no-install-recommends \ libgrpc++-dev \ libgrpc-dev \ libopenmpi-dev \ - libnanomsg-dev \ + libnng-dev \ libpcap-dev \ libprotobuf-dev \ libprotoc-dev \ diff --git a/pdfixed/src/pd_notifications.cpp b/pdfixed/src/pd_notifications.cpp index 383a37435..2336c763a 100644 --- a/pdfixed/src/pd_notifications.cpp +++ b/pdfixed/src/pd_notifications.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4df6adb6f..f1e474fa3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,7 +6,7 @@ if(WITH_THRIFT) add_subdirectory(bm_runtime) endif() -if(WITH_NANOMSG) +if(WITH_NNG) add_subdirectory(bm_apps) endif() @@ -38,9 +38,9 @@ install(TARGETS bmall ARCHIVE DESTINATION lib ) -# Create apps library if nanomsg is enabled +# Create apps library if nanomsg-nng is enabled # FIXME: do we need bmp4apps? -##if(WITH_NANOMSG) +##if(WITH_NNG) ## add_library(bmp4apps SHARED) ## target_link_libraries(bmp4apps ## PUBLIC diff --git a/src/bm_apps/CMakeLists.txt b/src/bm_apps/CMakeLists.txt index f5cb389bc..6b0b06535 100644 --- a/src/bm_apps/CMakeLists.txt +++ b/src/bm_apps/CMakeLists.txt @@ -1,6 +1,6 @@ -# Should only be built if compiling with nanomsg -if(NOT WITH_NANOMSG) - message(SEND_ERROR "bm_apps compilation requires NANOMSG") +# Should only be built if compiling with nanomsg-nng +if(NOT WITH_NNG) + message(SEND_ERROR "bm_apps compilation requires nanomsg-nng") endif() add_subdirectory(examples) @@ -14,7 +14,7 @@ add_library(bmapps STATIC # Link libraries target_link_libraries(bmapps PUBLIC ${CMAKE_THREAD_LIBS_INIT} - ${NANOMSG_LIBRARY} + ${NNG_LIBRARY} ) if(WITH_THRIFT) diff --git a/src/bm_apps/learn.cpp b/src/bm_apps/learn.cpp index 6eda4cf41..050da7961 100644 --- a/src/bm_apps/learn.cpp +++ b/src/bm_apps/learn.cpp @@ -32,7 +32,7 @@ namespace thrift_provider = apache::thrift; #include #include -#include +#include #include #include diff --git a/src/bm_apps/nn.h b/src/bm_apps/nn.h index c44f0b56d..8d29ad7e5 100644 --- a/src/bm_apps/nn.h +++ b/src/bm_apps/nn.h @@ -23,7 +23,7 @@ #ifndef NN_HPP_INCLUDED #define NN_HPP_INCLUDED -#include +#include #include #include diff --git a/src/bm_apps/notifications.cpp b/src/bm_apps/notifications.cpp index 546514674..8a591be08 100644 --- a/src/bm_apps/notifications.cpp +++ b/src/bm_apps/notifications.cpp @@ -20,7 +20,7 @@ #include -#include +#include #include #include diff --git a/src/bm_apps/packet_pipe.cpp b/src/bm_apps/packet_pipe.cpp index 8e2dcacf9..c8bf44fc9 100644 --- a/src/bm_apps/packet_pipe.cpp +++ b/src/bm_apps/packet_pipe.cpp @@ -20,7 +20,7 @@ #include -#include +#include #include #include diff --git a/src/bm_sim/CMakeLists.txt b/src/bm_sim/CMakeLists.txt index a5fd07924..4a85bdd49 100644 --- a/src/bm_sim/CMakeLists.txt +++ b/src/bm_sim/CMakeLists.txt @@ -80,6 +80,6 @@ target_link_libraries(bmsim PUBLIC Boost::thread ) -if(WITH_NANOMSG) - target_link_libraries(bmsim PUBLIC ${NANOMSG_LIBRARY}) +if(WITH_NNG) + target_link_libraries(bmsim PUBLIC ${NNG_LIBRARY}) endif() diff --git a/src/bm_sim/debugger.cpp b/src/bm_sim/debugger.cpp index e7cae35c5..704f5e3cb 100644 --- a/src/bm_sim/debugger.cpp +++ b/src/bm_sim/debugger.cpp @@ -28,7 +28,7 @@ // temporary deps? #include #include -#include +#include #include #include diff --git a/src/bm_sim/dev_mgr_packet_in.cpp b/src/bm_sim/dev_mgr_packet_in.cpp index b1787f41a..5ad2ee6e1 100644 --- a/src/bm_sim/dev_mgr_packet_in.cpp +++ b/src/bm_sim/dev_mgr_packet_in.cpp @@ -20,13 +20,13 @@ #include -#ifdef BM_NANOMSG_ON +#ifdef BM_NNG_ON #include #include #include -#include +#include #include #include @@ -327,4 +327,4 @@ DevMgr::set_dev_mgr_packet_in( } // namespace bm -#endif // BM_NANOMSG_ON +#endif // BM_NNG_ON diff --git a/src/bm_sim/options_parse.cpp b/src/bm_sim/options_parse.cpp index a92e75134..3fa6b6da5 100644 --- a/src/bm_sim/options_parse.cpp +++ b/src/bm_sim/options_parse.cpp @@ -105,7 +105,7 @@ OptionsParser::parse(int argc, char *argv[], TargetParserIface *tp, "(interface X corresponds to two files X_in.pcap and X_out.pcap). " "Argument is the time to wait (in seconds) before starting to process " "the packet files.") -#ifdef BM_NANOMSG_ON +#ifdef BM_NNG_ON ("packet-in", po::value(), "Enable receiving packet on this (nanomsg) socket. " "The --interface options will be ignored.") @@ -133,7 +133,7 @@ OptionsParser::parse(int argc, char *argv[], TargetParserIface *tp, "default is 5242880 (5 MB)") ("log-file-max-files", po::value(), "Maximum number of rotated backup log files to keep; default is 3") -#ifdef BM_NANOMSG_ON +#ifdef BM_NNG_ON ("notifications-addr", po::value(), "Specify the nanomsg address to use for notifications " "(e.g. learning, ageing, ...); " @@ -258,7 +258,7 @@ OptionsParser::parse(int argc, char *argv[], TargetParserIface *tp, device_id = vm["device-id"].as(); } -#ifdef BM_NANOMSG_ON +#ifdef BM_NNG_ON if (vm.count("notifications-addr")) { notifications_addr = vm["notifications-addr"].as(); } else { @@ -389,7 +389,7 @@ OptionsParser::parse(int argc, char *argv[], TargetParserIface *tp, wait_time = 0; } -#ifdef BM_NANOMSG_ON +#ifdef BM_NNG_ON if (vm.count("packet-in")) { packet_in = true; packet_in_addr = vm["packet-in"].as(); diff --git a/src/bm_sim/switch.cpp b/src/bm_sim/switch.cpp index 296e283d5..0e4f5e261 100644 --- a/src/bm_sim/switch.cpp +++ b/src/bm_sim/switch.cpp @@ -226,7 +226,7 @@ SwitchWContexts::init_from_options_parser( auto transport = my_transport; if (transport == nullptr) { -#ifdef BM_NANOMSG_ON +#ifdef BM_NNG_ON notifications_addr = parser.notifications_addr; transport = std::shared_ptr( TransportIface::make_nanomsg(notifications_addr)); @@ -268,7 +268,7 @@ SwitchWContexts::init_from_options_parser( set_dev_mgr(std::move(my_dev_mgr)); else if (parser.use_files) set_dev_mgr_files(parser.wait_time); -#ifdef BM_NANOMSG_ON +#ifdef BM_NNG_ON else if (parser.packet_in) set_dev_mgr_packet_in(device_id, parser.packet_in_addr, transport); #endif diff --git a/src/bm_sim/transport_nn.cpp b/src/bm_sim/transport_nn.cpp index d829b1494..be7b86a08 100644 --- a/src/bm_sim/transport_nn.cpp +++ b/src/bm_sim/transport_nn.cpp @@ -20,12 +20,12 @@ #include -#ifdef BM_NANOMSG_ON +#ifdef BM_NNG_ON #include #include -#include +#include #include #include @@ -124,4 +124,4 @@ TransportIface::make_nanomsg(const std::string &addr) { } // namespace bm -#endif // BM_NANOMSG_ON +#endif // BM_NNG_ON diff --git a/targets/l2_switch/CMakeLists.txt b/targets/l2_switch/CMakeLists.txt index e624f830f..f910d5358 100644 --- a/targets/l2_switch/CMakeLists.txt +++ b/targets/l2_switch/CMakeLists.txt @@ -1,4 +1,4 @@ -if(WITH_NANOMSG) +if(WITH_NNG) add_subdirectory(learn_client) endif() diff --git a/targets/pna_nic/CMakeLists.txt b/targets/pna_nic/CMakeLists.txt index 434c602fa..300cee8f4 100644 --- a/targets/pna_nic/CMakeLists.txt +++ b/targets/pna_nic/CMakeLists.txt @@ -1,4 +1,4 @@ -if(WITH_NANOMSG) +if(WITH_NNG) add_subdirectory(tests) endif() diff --git a/targets/psa_switch/CMakeLists.txt b/targets/psa_switch/CMakeLists.txt index acdb35557..4c1d5e824 100644 --- a/targets/psa_switch/CMakeLists.txt +++ b/targets/psa_switch/CMakeLists.txt @@ -1,4 +1,4 @@ -if(WITH_NANOMSG) +if(WITH_NNG) add_subdirectory(tests) endif() diff --git a/targets/simple_switch/CMakeLists.txt b/targets/simple_switch/CMakeLists.txt index ed603f745..74861708d 100644 --- a/targets/simple_switch/CMakeLists.txt +++ b/targets/simple_switch/CMakeLists.txt @@ -152,8 +152,8 @@ if(WITH_THRIFT) ) endif() -# Add tests if nanomsg is enabled -if(WITH_NANOMSG) +# Add tests if nanomsg-nng is enabled +if(WITH_NNG) add_subdirectory(tests) endif() diff --git a/targets/test_utils/utils.h b/targets/test_utils/utils.h index 76f3f6fa1..8aa4f5d9b 100644 --- a/targets/test_utils/utils.h +++ b/targets/test_utils/utils.h @@ -23,7 +23,7 @@ #include -#include +#include #include #include diff --git a/tests/test_bm_apps.cpp b/tests/test_bm_apps.cpp index 9439e39fa..54cff783f 100644 --- a/tests/test_bm_apps.cpp +++ b/tests/test_bm_apps.cpp @@ -20,7 +20,7 @@ #include -#ifdef BM_NANOMSG_ON +#ifdef BM_NNG_ON #include @@ -208,4 +208,4 @@ TEST_F(NotificationsTest, PortEvent) { test(1, PortStatus::PORT_UP, true, PortEvent::PORT_UP); } -#endif // BM_NANOMSG_ON +#endif // BM_NNG_ON diff --git a/tests/test_devmgr.cpp b/tests/test_devmgr.cpp index 89feeb263..ebc0b3b43 100644 --- a/tests/test_devmgr.cpp +++ b/tests/test_devmgr.cpp @@ -256,7 +256,7 @@ class PacketInReceiver { mutable std::condition_variable can_read{}; }; -#ifdef BM_NANOMSG_ON +#ifdef BM_NNG_ON // is here because DevMgr has a protected destructor class PacketInSwitch : public DevMgr { }; @@ -446,7 +446,7 @@ TEST_F(PacketInDevMgrPortStatusTest, Status) { check_and_reset_counts(0u, 1u, 0u, 0u); } -#endif // BM_NANOMSG_ON +#endif // BM_NNG_ON struct PMActive { }; struct PMPassive { }; diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index b0bd832c5..0ffe42b06 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -22,8 +22,8 @@ if(WITH_THRIFT) ) endif() -# Add Nanomsg-related scripts -if(WITH_NANOMSG) +# Add Nanomsg-nng-related scripts +if(WITH_NNG) list(APPEND PYTHON_SCRIPTS p4dbg.py nanomsg_client.py