Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ if(ENABLE_ETHERNET_CONNECTION_HANDLING)
add_definitions(-DENABLE_ETHERNET_CONNECTION_HANDLING)
message(STATUS "Ethernet connection handling: enabled")
endif()
option(USE_TELEMETRY "Enable Telemetry T2 support" OFF)

if (USE_TELEMETRY)
find_package(T2 REQUIRED)
add_compile_definitions(USE_TELEMETRY=1)
message("Telemetry support enabled")
endif(USE_TELEMETRY)

add_subdirectory(interface)
add_subdirectory(definition)
Expand All @@ -76,4 +83,3 @@ if(ENABLE_UNIT_TESTING)
add_subdirectory(tests/l1Test)
add_subdirectory(tests/l2Test)
endif(ENABLE_UNIT_TESTING)

9 changes: 8 additions & 1 deletion plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ if (USE_RDK_LOGGER)
include_directories(${RDKLOGGER_INCLUDE_DIRS})
endif (USE_RDK_LOGGER)


if (USE_TELEMETRY)
include_directories(${T2_INCLUDE_DIRS})
endif (USE_TELEMETRY)

if(ENABLE_GNOME_NETWORKMANAGER)
pkg_check_modules(GLIB REQUIRED glib-2.0)
Expand Down Expand Up @@ -142,6 +144,11 @@ if (USE_RDK_LOGGER)
target_link_libraries(${MODULE_IMPL_NAME} PRIVATE ${RDKLOGGER_LIBRARIES})
endif (USE_RDK_LOGGER)

if (USE_TELEMETRY)
target_link_libraries(${MODULE_NAME} PRIVATE ${T2_LIBRARIES})
target_link_libraries(${MODULE_IMPL_NAME} PRIVATE ${T2_LIBRARIES})
endif (USE_TELEMETRY)

install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/${STORAGE_DIRECTORY}/plugins)
install(TARGETS ${MODULE_IMPL_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/${STORAGE_DIRECTORY}/plugins)

Expand Down
58 changes: 58 additions & 0 deletions plugin/NetworkManagerImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
#include <thread>
#include <chrono>
#include "NetworkManagerImplementation.h"

#if USE_TELEMETRY
#include "NetworkManagerJsonEnum.h"
#include <telemetry_busmessage_sender.h>
#endif

using namespace WPEFramework;
using namespace WPEFramework::Plugin;
using namespace NetworkManagerLogger;
Expand Down Expand Up @@ -58,6 +64,10 @@ namespace WPEFramework
NetworkManagerLogger::Init();
NMLOG_INFO((_T("NWMgrPlugin Out-Of-Process Instantiation; SHA: " _T(EXPAND_AND_QUOTE(PLUGIN_BUILD_REFERENCE)))));
m_processMonThread = std::thread(&NetworkManagerImplementation::processMonitor, this, NM_PROCESS_MONITOR_INTERVAL_SEC);
#if USE_TELEMETRY
// Initialize Telemetry T2 for NwMgrPlugin
t2_init("NwMgrPlugin");
#endif
}

NetworkManagerImplementation::~NetworkManagerImplementation()
Expand Down Expand Up @@ -361,6 +371,18 @@ namespace WPEFramework
interface = m_defaultInterface;

ipaddress = result.public_ip;
#if USE_TELEMETRY
if(ipversion == "IPv4")
{
NMLOG_INFO("NM_PUBLIC_IPV4 = %s", ipaddress.c_str());
logTelemetry("NM_PUBLIC_IPV4", ipaddress);
}
else
{
NMLOG_INFO("NM_PUBLIC_IPV6 = %s", ipaddress.c_str());
logTelemetry("NM_PUBLIC_IPV6", ipaddress);
}
#endif
return Core::ERROR_NONE;
}
else
Expand Down Expand Up @@ -714,6 +736,10 @@ namespace WPEFramework
for (const auto callback : _notificationCallbacks) {
callback->onActiveInterfaceChange(prevActiveInterface, currentActiveinterface);
}
#if USE_TELEMETRY
NMLOG_INFO("NM_INTERFACE_STATUS = Interface changed to %s", currentActiveinterface.c_str());
logTelemetry("NM_INTERFACE_STATUS", "Interface changed to " + currentActiveinterface);
#endif
_notificationLock.Unlock();
}
Comment on lines 736 to 744

Expand Down Expand Up @@ -760,9 +786,25 @@ namespace WPEFramework
{
_notificationLock.Lock();
NMLOG_INFO("Posting onInternetStatusChange with current state as %u", (unsigned)currState);
#if USE_TELEMETRY
// Log error only when ethernet is up and there's no internet
if(currState == Exchange::INetworkManager::INTERNET_NOT_AVAILABLE &&
m_ethConnected.load() &&
interface == "eth0" &&
prevState != Exchange::INetworkManager::INTERNET_NOT_AVAILABLE)
{
NMLOG_INFO("NM_ETHERNET_CONNECTIVITY = Ethernet connectivity failed");
logTelemetry("NM_ETHERNET_CONNECTIVITY", "Ethernet connectivity failed");
}
#endif
for (const auto callback : _notificationCallbacks) {
callback->onInternetStatusChange(prevState, currState, interface);
}
#if USE_TELEMETRY
string stateStr = Core::EnumerateType<Exchange::INetworkManager::InternetStatus>(currState).Data();
NMLOG_INFO("NM_INTERNET_STATUS = %s", stateStr.c_str());
logTelemetry("NM_INTERNET_STATUS", stateStr);
#endif
_notificationLock.Unlock();
}
Comment on lines 786 to 809

Expand Down Expand Up @@ -1111,6 +1153,11 @@ namespace WPEFramework

_notificationLock.Lock();
NMLOG_INFO("Posting onWiFiStateChange (%d)", state);
#if USE_TELEMETRY
string stateStr = Core::EnumerateType<Exchange::INetworkManager::WiFiState>(state).Data();
NMLOG_INFO("NM_WIFI_STATUS = %s", stateStr.c_str());
logTelemetry("NM_WIFI_STATUS", stateStr);
#endif
Comment on lines +1156 to +1160
for (const auto callback : _notificationCallbacks) {
callback->onWiFiStateChange(state);
}
Expand Down Expand Up @@ -1246,5 +1293,16 @@ namespace WPEFramework
}
}
}

void NetworkManagerImplementation::logTelemetry(const std::string& eventName, const std::string& message)
{
#if USE_TELEMETRY
T2ERROR t2error = t2_event_s(eventName.c_str(), const_cast<char*>(message.c_str()));
if (t2error != T2ERROR_SUCCESS) {
NMLOG_ERROR("t2_event_s(\"%s\", \"%s\") failed with error %d",
eventName.c_str(), message.c_str(), t2error);
}
#endif
}
Comment on lines +1297 to +1306
}
}
1 change: 1 addition & 0 deletions plugin/NetworkManagerImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ namespace WPEFramework
void ReportAvailableSSIDs(const JsonArray &arrayofWiFiScanResults);
void ReportWiFiStateChange(const Exchange::INetworkManager::WiFiState state);
void ReportWiFiSignalQualityChange(const string ssid, const int strength, const int noise, const int snr, const Exchange::INetworkManager::WiFiSignalQuality quality);
void logTelemetry(const std::string& eventName, const std::string& message);

// INetworkPowerCallback overrides
void OnPowerModePreChange(const Exchange::IPowerManager::PowerState currentState,
Expand Down
32 changes: 30 additions & 2 deletions plugin/gnome/NetworkManagerGnomeEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ namespace WPEFramework
case NM_DEVICE_STATE_ACTIVATED:
wifiState = "WIFI_STATE_CONNECTED";
GnomeNetworkManagerEvents::onWIFIStateChanged(Exchange::INetworkManager::WIFI_STATE_CONNECTED);
#if USE_TELEMETRY
{
static std::string lastWlanGatewayMac;
std::string gatewayMac = nmUtils::getGatewayMacAddress(device);
if (!gatewayMac.empty() && lastWlanGatewayMac != gatewayMac) {
lastWlanGatewayMac = gatewayMac;
NMLOG_INFO("NM_WIFI_GW_MAC = %s", gatewayMac.c_str());
if (_instance != nullptr)
{
_instance->logTelemetry("NM_WIFI_GW_MAC", gatewayMac);
}
}
}
#endif
break;
case NM_DEVICE_STATE_DEACTIVATING:
wifiState = "WIFI_STATE_CONNECTION_LOST";
Expand Down Expand Up @@ -211,9 +225,22 @@ namespace WPEFramework
case NM_DEVICE_STATE_IP_CONFIG:
GnomeNetworkManagerEvents::onInterfaceStateChangeCb(Exchange::INetworkManager::INTERFACE_ACQUIRING_IP, nmUtils::ethIface());
break;
case NM_DEVICE_STATE_ACTIVATED:
#if USE_TELEMETRY
{
static std::string lastEthGatewayMac;
std::string gatewayMac = nmUtils::getGatewayMacAddress(device);
if (!gatewayMac.empty() && lastEthGatewayMac != gatewayMac) {
lastEthGatewayMac = gatewayMac;
NMLOG_INFO("NM_ETHERNET_GW_MAC = %s", gatewayMac.c_str());
if (_instance != nullptr)
_instance->logTelemetry("NM_ETHERNET_GW_MAC", gatewayMac);
}
}
#endif
break;
case NM_DEVICE_STATE_NEED_AUTH:
case NM_DEVICE_STATE_SECONDARIES:
case NM_DEVICE_STATE_ACTIVATED:
case NM_DEVICE_STATE_DEACTIVATING:
default:
NMLOG_WARNING("Unhandiled state change %d", deviceState);
Expand Down Expand Up @@ -271,8 +298,9 @@ namespace WPEFramework
}
if (nm_ip_address_get_family(address) == AF_INET) {
const char *ipAddress = nm_ip_address_get_address(address);
if(ipAddress != NULL)
if(ipAddress != NULL) {
GnomeNetworkManagerEvents::onAddressChangeCb(iface, ipAddress, true, false);
}
}
}
}
Expand Down
69 changes: 69 additions & 0 deletions plugin/gnome/NetworkManagerGnomeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <thread>
#include <string>
#include <map>
#include <sstream>
#include <fstream>
#include <NetworkManager.h>
#include <libnm/NetworkManager.h>
#include "Module.h"
Expand Down Expand Up @@ -389,5 +391,72 @@ namespace WPEFramework
return false;
}

std::string nmUtils::resolveGatewayMac(const std::string& gatewayIp)
{
std::string mac = "";
std::string arpFile = "/proc/net/arp";
std::ifstream file(arpFile);
std::string line;

if (!file.is_open()) {
NMLOG_ERROR("Failed to open %s", arpFile.c_str());
return mac;
}

// Skip header
std::getline(file, line);

while (std::getline(file, line)) {
std::istringstream iss(line);
std::string ip, hwType, flags, hwAddr;

if (iss >> ip >> hwType >> flags >> hwAddr) {
if (ip == gatewayIp && hwAddr != "00:00:00:00:00:00") {
mac = hwAddr;
NMLOG_INFO("Resolved gateway IP %s to MAC %s", gatewayIp.c_str(), mac.c_str());
break;
}
}
}

if (mac.empty()) {
NMLOG_WARNING("Could not resolve gateway IP %s to MAC address", gatewayIp.c_str());
}

return mac;
}

std::string nmUtils::getGatewayMacAddress(NMDevice* device)
{
std::string gatewayMac = "";

if (!device) {
NMLOG_ERROR("device is NULL");
return gatewayMac;
}

if (!NM_IS_DEVICE(device)) {
NMLOG_ERROR("device is not an NMDevice");
return gatewayMac;
}

NMIPConfig *ip4Config = nm_device_get_ip4_config(device);
if (!ip4Config) {
NMLOG_WARNING("No IPv4 configuration found");
return gatewayMac;
}

const char *ifname = nm_device_get_iface(device);
const char *gateway = nm_ip_config_get_gateway(ip4Config);
if (!gateway) {
NMLOG_WARNING("No gateway found for %s", ifname ? ifname : "unknown");
return gatewayMac;
}

NMLOG_DEBUG("Found gateway IP for %s: %s", ifname ? ifname : "unknown", gateway);
gatewayMac = resolveGatewayMac(gateway);
return gatewayMac;
}

} // Plugin
} // WPEFramework
2 changes: 2 additions & 0 deletions plugin/gnome/NetworkManagerGnomeUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ namespace WPEFramework
static bool isInterfaceEnabled(const std::string& interface);
static bool writePersistentHostname(const std::string& hostname);
static bool readPersistentHostname(std::string& hostname);
static std::string resolveGatewayMac(const std::string& gatewayIp);
static std::string getGatewayMacAddress(NMDevice* device);
};
}
}
1 change: 0 additions & 1 deletion plugin/gnome/NetworkManagerGnomeWIFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,6 @@ m_cancellable(nullptr){
std::string activeSSID{};

NMLOG_DEBUG("wifi connect ssid: %s, security %d persist %d", ssidInfoParam.ssid.c_str(), ssidInfoParam.security, ssidInfoParam.persist);

Exchange::INetworkManager::WiFiConnectTo ssidInfo = ssidInfoParam;
m_isSuccess = false;
if(!createClientNewConnection())
Expand Down
5 changes: 5 additions & 0 deletions tests/l2Test/libnm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ add_executable(${NM_LIBNM_PROXY_L2_TEST}
${CMAKE_SOURCE_DIR}/tests/mocks/thunder/Module.cpp
${CMAKE_SOURCE_DIR}/tests/mocks/Iarm.cpp
${CMAKE_SOURCE_DIR}/tests/mocks/Wraps.cpp
${CMAKE_SOURCE_DIR}/tests/mocks/CurlWraps.cpp
${CMAKE_SOURCE_DIR}/tests/mocks/LibnmWraps.cpp
${CMAKE_SOURCE_DIR}/tests/mocks/GLibWraps.cpp
${CMAKE_SOURCE_DIR}/plugin/NetworkManager.cpp
Expand Down Expand Up @@ -164,6 +165,10 @@ target_link_options(${NM_LIBNM_PROXY_L2_TEST} PUBLIC
-Wl,-wrap,nm_remote_connection_delete
-Wl,-wrap,nm_remote_connection_delete_finish
-Wl,-wrap,nm_access_point_connection_valid
-Wl,-wrap,curl_multi_perform
-Wl,-wrap,curl_multi_info_read
-Wl,-wrap,curl_multi_poll
-Wl,-wrap,nm_device_get_ip4_config
)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
Expand Down
Loading
Loading