Skip to content

Commit

Permalink
Remove the Method that Starts/Stops Connectivity Monitoring
Browse files Browse the repository at this point in the history
Reason for change: Since Internet Monitoring is one of the core feature of NetworkManager Plugin and as lot other component listens to this event, This method will will be always triggered internally when the interface status changes. The external API to start/stop is removed.
Test Procedure: Check the connectivity Monitoring
Risks: Medium
Signed-off-by: Karunakaran A <[email protected]>
  • Loading branch information
karuna2git committed Dec 18, 2024
1 parent 24312a3 commit e2c96de
Show file tree
Hide file tree
Showing 13 changed files with 392 additions and 437 deletions.
11 changes: 3 additions & 8 deletions INetworkManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace WPEFramework
INTERNET_LIMITED /* @text: LIMITED_INTERNET */,
INTERNET_CAPTIVE_PORTAL /* @text: CAPTIVE_PORTAL */,
INTERNET_FULLY_CONNECTED /* @text: FULLY_CONNECTED */,
INTERNET_UNKNOWN /* @text: NO_INTERNET */,
INTERNET_UNKNOWN /* @text: UNKNOWN */,
};

enum WiFiWPS : uint8_t
Expand Down Expand Up @@ -237,11 +237,6 @@ namespace WPEFramework
/* @brief Get Authentication URL if the device is behind Captive Portal */
virtual uint32_t GetCaptivePortalURI(string &uri/* @out */) const = 0;

/* @brief Start The Internet Connectivity Monitoring */
virtual uint32_t StartConnectivityMonitoring(const uint32_t interval /* @in */) = 0;
/* @brief Stop The Internet Connectivity Monitoring */
virtual uint32_t StopConnectivityMonitoring(void) const = 0;

/* @brief Get the Public IP used for external world communication */
virtual uint32_t GetPublicIP (const string &ipversion /* @in */, string& ipaddress /* @out */) = 0;

Expand Down Expand Up @@ -275,8 +270,8 @@ namespace WPEFramework
virtual uint32_t SetLogLevel(const Logging& level /* @in */) = 0;
virtual uint32_t GetLogLevel(Logging& level /* @out */) = 0;

/* @brief configure network manager plugin */
virtual uint32_t Configure(const string& configLine /* @in */) = 0;
/* @brief Configure the Network Manager plugin */
virtual uint32_t Configure(PluginHost::IShell* service /* @in */) = 0;

/* @event */
struct EXTERNAL INotification : virtual public Core::IUnknown
Expand Down
45 changes: 18 additions & 27 deletions LegacyPlugin_NetworkAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "NetworkManagerLogger.h"
#include "NetworkManagerJsonEnum.h"


using namespace std;
using namespace WPEFramework::Plugin;
#define API_VERSION_NUMBER_MAJOR 2
Expand Down Expand Up @@ -84,7 +83,6 @@ namespace WPEFramework
, m_subsInternetChange(false)
{
_gNWInstance = this;
m_defaultInterface = "wlan0";
m_timer.connect(std::bind(&Network::subscribeToEvents, this));
registerLegacyMethods();
}
Expand Down Expand Up @@ -167,7 +165,13 @@ namespace WPEFramework

void Network::Deinitialize(PluginHost::IShell* /* service */)
{
m_timer.stop();
unregisterLegacyMethods();

if (m_networkmanager)
m_networkmanager.reset();

m_networkmanager = NULL;
m_service->Release();
m_service = nullptr;
_gNWInstance = nullptr;
Expand Down Expand Up @@ -204,7 +208,7 @@ namespace WPEFramework
Register("getInternetConnectionState", &Network::getInternetConnectionState, this);
Register("ping", &Network::doPing, this);
Register("isConnectedToInternet", &Network::isConnectedToInternet, this);
Register("setStunEndPoint", &Network::setStunEndPoint, this);
Register("setStunEndPoint", &Network::setStunEndpoint, this);
Register("trace", &Network::doTrace, this);
Register("setConnectivityTestEndpoints", &Network::setConnectivityTestEndpoints, this);
Register("startConnectivityMonitoring", &Network::startConnectivityMonitoring, this);
Expand All @@ -219,6 +223,8 @@ namespace WPEFramework
*/
void Network::unregisterLegacyMethods(void)
{
Unregister("getStbIp");
Unregister("getSTBIPFamily");
Unregister("getInterfaces");
Unregister("isInterfaceEnabled");
Unregister("getPublicIP");
Expand All @@ -230,6 +236,8 @@ namespace WPEFramework
Unregister("getInternetConnectionState");
Unregister("ping");
Unregister("isConnectedToInternet");
Unregister("setStunEndPoint");
Unregister("trace");
Unregister("setConnectivityTestEndpoints");
Unregister("startConnectivityMonitoring");
Unregister("getCaptivePortalURI");
Expand Down Expand Up @@ -319,19 +327,19 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = {
returnJson(rc);
}

uint32_t Network::setStunEndPoint(const JsonObject& parameters, JsonObject& response)
uint32_t Network::setStunEndpoint(const JsonObject& parameters, JsonObject& response)
{
LOG_INPARAM();
uint32_t rc = Core::ERROR_GENERAL;
string endPoint = parameters["server"].String();
string endpoint = parameters["server"].String();
uint32_t port = parameters["port"].Number();
uint32_t bindTimeout = parameters["timeout"].Number();
uint32_t cacheTimeout = parameters["cache_timeout"].Number();

auto _nwmgr = m_service->QueryInterfaceByCallsign<Exchange::INetworkManager>(NETWORK_MANAGER_CALLSIGN);
if (_nwmgr)
{
rc = _nwmgr->SetStunEndpoint(endPoint, port, bindTimeout, cacheTimeout);
rc = _nwmgr->SetStunEndpoint(endpoint, port, bindTimeout, cacheTimeout);
_nwmgr->Release();
}
else
Expand Down Expand Up @@ -806,15 +814,9 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = {
uint32_t interval = parameters["interval"].Number();

NMLOG_DEBUG("connectivity interval = %d", interval);
auto _nwmgr = m_service->QueryInterfaceByCallsign<Exchange::INetworkManager>(NETWORK_MANAGER_CALLSIGN);
if (_nwmgr)
rc = _nwmgr->StartConnectivityMonitoring(interval);
else
rc = Core::ERROR_UNAVAILABLE;

if(_nwmgr)
_nwmgr->Release();

// No action
rc = Core::ERROR_NONE;
returnJson(rc);
}

Expand Down Expand Up @@ -844,14 +846,8 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = {
LOG_INPARAM();
uint32_t rc = Core::ERROR_GENERAL;

auto _nwmgr = m_service->QueryInterfaceByCallsign<Exchange::INetworkManager>(NETWORK_MANAGER_CALLSIGN);
if (_nwmgr)
{
rc = _nwmgr->StopConnectivityMonitoring();
_nwmgr->Release();
}
else
rc = Core::ERROR_UNAVAILABLE;
// No action
rc = Core::ERROR_NONE;

returnJson(rc);
}
Expand Down Expand Up @@ -1017,8 +1013,6 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = {
legacyParams["oldInterfaceName"] = getInterfaceNameToType(parameters["prevActiveInterface"].String());
legacyParams["newInterfaceName"] = getInterfaceNameToType(parameters["currentActiveInterface"].String());

m_defaultInterface = parameters["currentActiveInterface"].String();

string json;
legacyParams.ToString(json);

Expand Down Expand Up @@ -1049,9 +1043,6 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = {

Notify("onIPAddressStatusChanged", legacyParams);

// if ("ACQUIRED" == parameters["status"].String())
// m_defaultInterface = parameters["interface"].String();

return;
}

Expand Down
3 changes: 1 addition & 2 deletions LegacyPlugin_NetworkAPIs.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace WPEFramework {
uint32_t getCaptivePortalURI(const JsonObject& parameters, JsonObject& response);
uint32_t stopConnectivityMonitoring(const JsonObject& parameters, JsonObject& response);
uint32_t getPublicIP(const JsonObject& parameters, JsonObject& response);
uint32_t setStunEndPoint(const JsonObject& parameters, JsonObject& response);
uint32_t setStunEndpoint(const JsonObject& parameters, JsonObject& response);
uint32_t getStbIp(const JsonObject& parameters, JsonObject& response);
uint32_t getSTBIPFamily(const JsonObject& parameters, JsonObject& response);

Expand Down Expand Up @@ -88,7 +88,6 @@ namespace WPEFramework {
PluginHost::IShell* m_service;
std::shared_ptr<WPEFramework::JSONRPC::SmartLinkType<WPEFramework::Core::JSON::IElement>> m_networkmanager;
//WPEFramework::Exchange::INetworkManager* m_nwmgr;
string m_defaultInterface;
NetworkManagerTimer m_timer;

bool m_subsIfaceStateChange;
Expand Down
6 changes: 6 additions & 0 deletions LegacyPlugin_WiFiManagerAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@ namespace WPEFramework

void WiFiManager::Deinitialize(PluginHost::IShell* /* service */)
{
m_timer.stop();
unregisterLegacyMethods();

if (m_networkmanager)
m_networkmanager.reset();

m_networkmanager = NULL;
m_service->Release();
m_service = nullptr;
_gWiFiInstance = nullptr;
Expand Down
19 changes: 12 additions & 7 deletions NetworkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace WPEFramework
*/
const string NetworkManager::Initialize(PluginHost::IShell *service)
{
string message{};
// Make sure everything is null as we expect
ASSERT(_service == nullptr);
ASSERT(_networkManager == nullptr);
Expand All @@ -84,20 +85,24 @@ namespace WPEFramework
// Still running inside the main WPEFramework process - the child process will have now been spawned and registered if necessary
if (_networkManager != nullptr)
{
// set the plugin configuration
Exchange::INetworkManager::Logging _loglevel;
_networkManager->Configure(_service->ConfigLine());
if (_networkManager->Configure(service) != Core::ERROR_NONE)
{
SYSLOG(Logging::Startup, (_T("Configuring NetworkManager")));
message = _T("NetworkManager failed to configure");
}

// configure loglevel in libWPEFrameworkNetworkManager.so
// Set the plugin log level
Exchange::INetworkManager::Logging _loglevel;
_networkManager->GetLogLevel(_loglevel);
NetworkManagerLogger::SetLevel(static_cast <NetworkManagerLogger::LogLevel>(_loglevel));


// Register Notifications
_networkManager->Register(&_notification);

// Register all custom JSON-RPC methods
RegisterAllMethods();


// Get IPlugin interface for this plugin
_networkManagerImpl = _networkManager->QueryInterface<PluginHost::IPlugin>();
}
Expand All @@ -109,11 +114,11 @@ namespace WPEFramework
_service = nullptr;

// Returning a string signals that we failed to initialize - WPEFramework will print this as an error message
return "Failed to initialize NetworkManager";
message = _T("Failed to initialize NetworkManager");
}

// Success
return "";
return message;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion NetworkManager.json
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@
}
},
"GetWiFiSignalStrength":{
"summary": "Get WiFiSignalStrength of connected SSID. The signal quality is identifed based on the signal strength. The possible states are \n* 'Excellent' \n* 'Good' \n* 'Fair' \n* 'Weak' \n* 'Disconnected' \n",
"summary": "Get WiFiSignalStrength of connected SSID. The signal quality is identifed based on the signal strength. The possible states are\n* 'Excellent'\n* 'Good'\n* 'Fair'\n* 'Weak'\n* 'Disconnected'\n",
"events":{
"onWiFiSignalStrengthChange" : "Triggered when Wifi signal strength switches between Excellent, Good, Fair, Weak."
},
Expand Down
11 changes: 5 additions & 6 deletions NetworkManagerConnectivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,15 +387,12 @@ namespace WPEFramework
{
nsm_internetState internetState = nsm_internetState::UNKNOWN;
// If monitor connectivity is running take the cache value

if ( doContinuousMonitor && (nsm_ipversion::NSM_IPRESOLVE_V4 == ipversion || nsm_ipversion::NSM_IPRESOLVE_WHATEVER == ipversion)
&& m_Ipv4InternetState != nsm_internetState::UNKNOWN ) {
if ( doContinuousMonitor && (NSM_IPRESOLVE_V4 == ipversion || NSM_IPRESOLVE_WHATEVER == ipversion) && (m_Ipv4InternetState != nsm_internetState::UNKNOWN)) {
NMLOG_WARNING("Reading Ipv4 internet state cached value %s", getInternetStateString(m_Ipv4InternetState));
internetState = m_Ipv4InternetState;
ipversion = NSM_IPRESOLVE_V4;
}
else if ( doContinuousMonitor && (nsm_ipversion::NSM_IPRESOLVE_V6 == ipversion || nsm_ipversion::NSM_IPRESOLVE_WHATEVER == ipversion)
&& m_Ipv6InternetState != nsm_internetState::UNKNOWN ) {
else if ( doContinuousMonitor && (NSM_IPRESOLVE_V6 == ipversion || NSM_IPRESOLVE_WHATEVER == ipversion) && (m_Ipv6InternetState != nsm_internetState::UNKNOWN)) {
NMLOG_WARNING("Reading Ipv6 internet state cached value %s", getInternetStateString(m_Ipv6InternetState));
internetState = m_Ipv6InternetState;
ipversion = NSM_IPRESOLVE_V6;
Expand All @@ -405,7 +402,8 @@ namespace WPEFramework
TestConnectivity testInternet(getConnectivityMonitorEndpoints(), NMCONNECTIVITY_CURL_REQUEST_TIMEOUT_MS, NMCONNECTIVITY_CURL_GET_REQUEST, ipversion);
internetState = testInternet.getInternetState();
// TODO : Lets not hard code here.
ipversion = NSM_IPRESOLVE_V4;
if (NSM_IPRESOLVE_WHATEVER == ipversion)
ipversion = NSM_IPRESOLVE_V4;
}
return internetState;
}
Expand All @@ -426,6 +424,7 @@ namespace WPEFramework
{
if(_instance != nullptr )
NMLOG_INFO("interface status eth - %s wlan - %s ", _instance->m_ethConnected? "up":"down", _instance->m_wlanConnected? "up":"down");

continuousMonitorTimeout.store(timeoutInSeconds >= NMCONNECTIVITY_MONITOR_MIN_INTERVAL ? timeoutInSeconds : NMCONNECTIVITY_MONITOR_DEFAULT_INTERVAL);
if (doContinuousMonitor)
{
Expand Down
4 changes: 2 additions & 2 deletions NetworkManagerConnectivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ enum nsm_connectivity_httpcode {
#define NMCONNECTIVITY_CURL_HEAD_REQUEST true
#define NMCONNECTIVITY_CURL_GET_REQUEST false

#define NMCONNECTIVITY_MONITOR_DEFAULT_INTERVAL 60 // sec
#define NMCONNECTIVITY_MONITOR_DEFAULT_INTERVAL 30 // sec
#define NMCONNECTIVITY_MONITOR_MIN_INTERVAL 5 // sec
#define NMCONNECTIVITY_CURL_REQUEST_TIMEOUT_MS 5000 // ms
#define NMCONNECTIVITY_NO_INTERNET_RETRY_COUNT 4 // 4 retry
Expand Down Expand Up @@ -96,7 +96,7 @@ namespace WPEFramework
const TestConnectivity& operator=(const TestConnectivity&) = delete;

public:
TestConnectivity(const std::vector<std::string>& endpoints, long timeout_ms = 2000, bool = true, nsm_ipversion ipversion = NSM_IPRESOLVE_WHATEVER);
TestConnectivity(const std::vector<std::string>& endpoints, long timeout_ms = 2000, bool headReq = true, nsm_ipversion ipversion = NSM_IPRESOLVE_WHATEVER);
~TestConnectivity(){}
std::string getCaptivePortal() {return captivePortalURI;}
nsm_internetState getInternetState(){return internetSate;}
Expand Down
Loading

0 comments on commit e2c96de

Please sign in to comment.