handler: Don't hardcode channel information
We can use the functions from the ipmi daemon to get the proper channel
for the named NIC.
Change-Id: I9f479ec90bffed147a68131a6dda5aebd9cfc910
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/handler.cpp b/handler.cpp
index e99bfff..a9f428e 100644
--- a/handler.cpp
+++ b/handler.cpp
@@ -42,13 +42,6 @@
#include <tuple>
#include <xyz/openbmc_project/Common/error.hpp>
-// The phosphor-host-ipmi daemon requires a configuration that maps
-// the if_name to the IPMI LAN channel. However, that doesn't strictly
-// define which is meant to be used for NCSI.
-#ifndef NCSI_IPMI_CHANNEL
-#define NCSI_IPMI_CHANNEL 1
-#endif
-
#ifndef NCSI_IF_NAME
#define NCSI_IF_NAME eth0
#endif
@@ -58,6 +51,11 @@
#define STR(macro) QUOTE(macro)
#define NCSI_IF_NAME_STR STR(NCSI_IF_NAME)
+namespace ipmi
+{
+std::uint8_t getChannelByName(const std::string& chName);
+}
+
namespace google
{
namespace ipmi
@@ -70,7 +68,8 @@
std::tuple<std::uint8_t, std::string> Handler::getEthDetails() const
{
- return std::make_tuple(NCSI_IPMI_CHANNEL, NCSI_IF_NAME_STR);
+ return std::make_tuple<std::uint8_t, std::string>(
+ ::ipmi::getChannelByName(NCSI_IF_NAME_STR), NCSI_IF_NAME_STR);
}
std::int64_t Handler::getRxPackets(const std::string& name) const
diff --git a/test/common.cpp b/test/common.cpp
new file mode 100644
index 0000000..08c3eaa
--- /dev/null
+++ b/test/common.cpp
@@ -0,0 +1,10 @@
+#include <cstdint>
+#include <string>
+
+namespace ipmi
+{
+std::uint8_t getChannelByName(const std::string&)
+{
+ return 1;
+}
+} // namespace ipmi
diff --git a/test/meson.build b/test/meson.build
index 0dc3b49..6630893 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -1,6 +1,19 @@
gtest = dependency('gtest', main: true, disabler: true, required: get_option('tests'))
gmock = dependency('gmock', disabler: true, required: get_option('tests'))
+tests_pre = declare_dependency(
+ dependencies: [sys_dep, gtest, gmock])
+
+tests_lib = static_library(
+ 'common',
+ 'common.cpp',
+ implicit_include_directories: false,
+ dependencies: tests_pre)
+
+tests_dep = declare_dependency(
+ link_with: tests_lib,
+ dependencies: tests_pre)
+
tests = [
'cable',
'cpld',
@@ -21,5 +34,5 @@
t.underscorify(),
t + '_unittest.cpp',
implicit_include_directories: false,
- dependencies: [sys_dep, gtest, gmock]))
+ dependencies: tests_dep))
endforeach