Skip to content

Commit

Permalink
Revert "DELIA-66968 Disable continuous connectivity monitor when Inte…
Browse files Browse the repository at this point in the history
…rface is disconnected (rdkcentral#51)"

This reverts commit da274ff.
  • Loading branch information
karuna2git committed Dec 18, 2024
1 parent 457977e commit 9272b7e
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 212 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gnome_unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
run: >
PATH=${{github.workspace}}/install/usr/bin:${PATH}
LD_LIBRARY_PATH=${{github.workspace}}/install/usr/lib:${{github.workspace}}/install/usr/lib/wpeframework/plugins:${LD_LIBRARY_PATH}
unit_tests
tests
- name: Generate coverage
run: |
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,6 @@ write_config(PLUGINS LegacyPlugin_NetworkAPIs CLASSNAME Network LOCATOR lib${PLU
write_config(PLUGINS LegacyPlugin_WiFiManagerAPIs CLASSNAME WiFiManager LOCATOR lib${PLUGIN_LEGACY_DEPRECATED_WIFI}.so)

if(ENABLE_UNIT_TESTING)
include(Tests/unit_test/unit_tests.cmake)
include(Tests/unit_test/tests.cmake)
endif(ENABLE_UNIT_TESTING)

93 changes: 39 additions & 54 deletions NetworkManagerConnectivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ namespace WPEFramework
curl_easy_setopt(curl_easy_handle, CURLOPT_TIMEOUT_MS, deadline - current_time());
if ((ipversion == CURL_IPRESOLVE_V4) || (ipversion == CURL_IPRESOLVE_V6))
{
NMLOG_DEBUG("curlopt ipversion = %s reqtyp = %s", ipversion == CURL_IPRESOLVE_V4?"IPv4":"IPv6", headReq? "HEAD":"GET");
NMLOG_DEBUG("curlopt ipversion = %s reqtyp = %s", ipversion == CURL_IPRESOLVE_V4?"ipv4 only":"ipv6 only", headReq? "HEAD":"GET");
curl_easy_setopt(curl_easy_handle, CURLOPT_IPRESOLVE, ipversion);
}
else
Expand Down Expand Up @@ -324,9 +324,10 @@ namespace WPEFramework

doContinuousMonitor = false;
doConnectivityMonitor = false;
m_InternetState = nsm_internetState::UNKNOWN;
m_Ipv4InternetState = nsm_internetState::UNKNOWN;
m_Ipv6InternetState = nsm_internetState::UNKNOWN;
gInternetState = nsm_internetState::UNKNOWN;
gIpv4InternetState = nsm_internetState::UNKNOWN;
gIpv6InternetState = nsm_internetState::UNKNOWN;
ginterfaceStatus = false;
}

ConnectivityMonitor::~ConnectivityMonitor()
Expand Down Expand Up @@ -389,15 +390,15 @@ namespace WPEFramework
// 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 ) {
NMLOG_WARNING("Reading Ipv4 internet state cached value %s", getInternetStateString(m_Ipv4InternetState));
internetState = m_Ipv4InternetState;
&& gIpv4InternetState != nsm_internetState::UNKNOWN ) {
NMLOG_WARNING("Reading Ipv4 internet state cached value %s", getInternetStateString(gIpv4InternetState));
internetState = gIpv4InternetState;
ipversion = NSM_IPRESOLVE_V4;
}
else if ( doContinuousMonitor && (nsm_ipversion::NSM_IPRESOLVE_V6 == ipversion || nsm_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;
&& gIpv6InternetState != nsm_internetState::UNKNOWN ) {
NMLOG_WARNING("Reading Ipv6 internet state cached value %s", getInternetStateString(gIpv6InternetState));
internetState = gIpv6InternetState;
ipversion = NSM_IPRESOLVE_V6;
}
else
Expand All @@ -424,8 +425,6 @@ namespace WPEFramework

bool ConnectivityMonitor::startContinuousConnectivityMonitor(int timeoutInSeconds)
{
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 Expand Up @@ -473,11 +472,12 @@ namespace WPEFramework
* --> when IP address accuired
* --> when etherenet/wifi disconnected
*/
bool ConnectivityMonitor::startConnectivityMonitor()
bool ConnectivityMonitor::startConnectivityMonitor(bool interfaceStatus)
{
m_InternetState = nsm_internetState::UNKNOWN;
m_Ipv4InternetState = nsm_internetState::UNKNOWN;
m_Ipv6InternetState = nsm_internetState::UNKNOWN;
ginterfaceStatus = interfaceStatus; /* this will give interface status connected/ disconnected */
gInternetState = UNKNOWN;
gIpv4InternetState = UNKNOWN;
gIpv6InternetState = UNKNOWN;
if (doConnectivityMonitor)
{
cvConnectivityMonitor.notify_one();
Expand All @@ -497,26 +497,21 @@ namespace WPEFramework
return false;
}

if(_instance != nullptr) {
NMLOG_INFO("connectivity monitor started %d sec - eth %s - wlan %s", NMCONNECTIVITY_MONITOR_MIN_INTERVAL,
_instance->m_ethConnected? "up":"down", _instance->m_wlanConnected? "up":"down");
}
NMLOG_ERROR("connectivity monitor started %d", NMCONNECTIVITY_MONITOR_MIN_INTERVAL);
return true;
}

void ConnectivityMonitor::notifyInternetStatusChangedEvent(nsm_internetState newInternetState)
{
static Exchange::INetworkManager::InternetStatus oldState = Exchange::INetworkManager::InternetStatus::INTERNET_UNKNOWN;
if(_instance != nullptr)
{
NMLOG_INFO("notify internet state %s", getInternetStateString(newInternetState));
Exchange::INetworkManager::InternetStatus oldState = static_cast<Exchange::INetworkManager::InternetStatus>(gInternetState.load());
Exchange::INetworkManager::InternetStatus newState = static_cast<Exchange::INetworkManager::InternetStatus>(newInternetState);
_instance->ReportInternetStatusChange(oldState , newState);
m_InternetState = newInternetState;
oldState = newState; // 'm_InternetState' not exactly previous state, it may change to unknow when interface changed
gInternetState = newInternetState;
}
else
NMLOG_FATAL("NetworkManagerImplementation Instance NULL notifyInternetStatusChange failed.");
NMLOG_WARNING("NetworkManagerImplementation Instance NULL notifyInternetStatusChange failed.");
}

void ConnectivityMonitor::continuousMonitorFunction()
Expand All @@ -529,31 +524,20 @@ namespace WPEFramework

do
{
if(_instance != nullptr && (!_instance->m_ethConnected && !_instance->m_wlanConnected)) // no wifi no ethernet connected
{
NMLOG_DEBUG("no interface connected; no ccm check");
m_Ipv4InternetState = NO_INTERNET;
m_Ipv6InternetState = NO_INTERNET;
std::unique_lock<std::mutex> lock(connMutex);
cvContinuousMonitor.wait_for(lock, std::chrono::seconds(continuousMonitorTimeout.load()));
ipResolveTyp = NSM_IPRESOLVE_WHATEVER;
continue;
}

if(doConnectivityMonitor)
{
NMLOG_DEBUG("connectivity monitor running so skiping ccm check");
m_Ipv4InternetState = nsm_internetState::UNKNOWN;
m_Ipv6InternetState = nsm_internetState::UNKNOWN;
gIpv4InternetState = UNKNOWN;
gIpv6InternetState = UNKNOWN;
std::unique_lock<std::mutex> lock(connMutex);
cvContinuousMonitor.wait_for(lock, std::chrono::seconds(continuousMonitorTimeout.load()));
ipResolveTyp = NSM_IPRESOLVE_WHATEVER; /* some interface change happense */
ipResolveTyp = NSM_IPRESOLVE_WHATEVER; /* some interface change happense*/
continue;
}
else if (ipResolveTyp == NSM_IPRESOLVE_WHATEVER)
{
nsm_internetState ipV4InternetState = nsm_internetState::UNKNOWN;
nsm_internetState ipV6InternetState = nsm_internetState::UNKNOWN;
nsm_internetState ipV4InternetState = UNKNOWN;
nsm_internetState ipV6InternetState = UNKNOWN;
auto curlCheckThrdIpv4 = [&]() {
TestConnectivity testInternet(getConnectivityMonitorEndpoints(), NMCONNECTIVITY_CURL_REQUEST_TIMEOUT_MS,
NMCONNECTIVITY_CURL_GET_REQUEST, NSM_IPRESOLVE_V4);
Expand Down Expand Up @@ -589,17 +573,17 @@ namespace WPEFramework
NMCONNECTIVITY_CURL_HEAD_REQUEST, ipResolveTyp);
currentInternetState = testInternet.getInternetState();
if(ipResolveTyp == NSM_IPRESOLVE_V4)
m_Ipv4InternetState = currentInternetState;
gIpv4InternetState = currentInternetState;
else if(ipResolveTyp == NSM_IPRESOLVE_V6)
m_Ipv6InternetState = currentInternetState;
gIpv6InternetState = currentInternetState;
}

if (currentInternetState == NO_INTERNET)
{
if(m_InternetState == FULLY_CONNECTED && notifyPreRetry < NMCONNECTIVITY_NO_INTERNET_RETRY_COUNT)
if(gInternetState == FULLY_CONNECTED && notifyPreRetry < NMCONNECTIVITY_NO_INTERNET_RETRY_COUNT)
{
/* it will prevent posting notification */
currentInternetState = m_InternetState;
currentInternetState = gInternetState;
TempInterval = 5;
NMLOG_INFO("No internet retrying connection check %d ...", notifyPreRetry);
notifyPreRetry++;
Expand All @@ -617,8 +601,9 @@ namespace WPEFramework
TempInterval = continuousMonitorTimeout.load();
}

if(m_InternetState != currentInternetState)
if(gInternetState != currentInternetState)
{
NMLOG_INFO("Internet state changed to %s", getInternetStateString(currentInternetState));
/* Notify Internet state change */
notifyInternetStatusChangedEvent(currentInternetState);
}
Expand All @@ -634,8 +619,8 @@ namespace WPEFramework

} while(doContinuousMonitor);

m_Ipv4InternetState = nsm_internetState::UNKNOWN;
m_Ipv6InternetState = nsm_internetState::UNKNOWN;
gIpv4InternetState = UNKNOWN;
gIpv6InternetState = UNKNOWN;
NMLOG_DEBUG("continous connectivity monitor exit");
}

Expand Down Expand Up @@ -678,8 +663,8 @@ namespace WPEFramework
NMLOG_INFO("Connectivity check retrying %d ...", notifyPreRetry);
}

if(m_InternetState != nsm_internetState::UNKNOWN)
currentInternetState = m_InternetState;
if(gInternetState != UNKNOWN)
currentInternetState = gInternetState;
TempInterval = 5;
}
else if(tempInternetState != currentInternetState) // last state have change
Expand All @@ -696,9 +681,8 @@ namespace WPEFramework
doConnectivityMonitor = false; // self exit
notifyNow = true; // post current state when retry complete
}
else if(_instance != nullptr && (_instance->m_ethConnected | _instance->m_wlanConnected))
else if(ginterfaceStatus) // interface is active and still no internet, continue check every 30 sec
{
/* interface is connected and still no internet, continue check every 30 sec */
TempInterval = NMCONNECTIVITY_CONN_MONITOR_RETRY_INTERVAL;
/* notify if retry completed and state stil no internet state */
if(notifyPreRetry == NMCONNECTIVITY_CONN_MONITOR_RETRY_COUNT)
Expand All @@ -715,9 +699,10 @@ namespace WPEFramework
}
}

if(m_InternetState != currentInternetState || notifyNow)
if(gInternetState != currentInternetState || notifyNow)
{
notifyNow = false;
NMLOG_INFO("notify internet state %s", getInternetStateString(currentInternetState));
notifyInternetStatusChangedEvent(currentInternetState);
}

Expand All @@ -734,7 +719,7 @@ namespace WPEFramework
} while(doConnectivityMonitor);

if(!doContinuousMonitor)
m_InternetState = nsm_internetState::UNKNOWN; // no continous monitor running reset to unknow
gInternetState = nsm_internetState::UNKNOWN; // no continous monitor running reset to unknow
NMLOG_DEBUG("initial connectivity monitor exit");
}

Expand Down
9 changes: 5 additions & 4 deletions NetworkManagerConnectivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace WPEFramework
~ConnectivityMonitor();
bool startContinuousConnectivityMonitor(int timeoutInSeconds);
bool stopContinuousConnectivityMonitor();
bool startConnectivityMonitor();
bool startConnectivityMonitor(bool interfaceStatus);
void setConnectivityMonitorEndpoints(const std::vector<std::string> &endpoints);
std::vector<std::string> getConnectivityMonitorEndpoints();
bool isConnectedToInternet(nsm_ipversion ipversion);
Expand All @@ -140,9 +140,10 @@ namespace WPEFramework

EndpointCache endpointCache;
std::mutex endpointMutex;
std::atomic<nsm_internetState> m_InternetState;
std::atomic<nsm_internetState> m_Ipv4InternetState;
std::atomic<nsm_internetState> m_Ipv6InternetState;
std::atomic<bool> ginterfaceStatus;
std::atomic<nsm_internetState> gInternetState;
std::atomic<nsm_internetState> gIpv4InternetState;
std::atomic<nsm_internetState> gIpv6InternetState;
};
} // namespace Plugin
} // namespace WPEFramework
20 changes: 9 additions & 11 deletions NetworkManagerGnomeProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,23 @@ namespace WPEFramework
{
NMDeviceState deviceState = NM_DEVICE_STATE_UNKNOWN;
Exchange::INetworkManager::InterfaceDetails interface;
interface.mac = nm_device_get_hw_address(device);
deviceState = nm_device_get_state(device);
interface.enabled = (deviceState >= NM_DEVICE_STATE_UNAVAILABLE)? true : false;
if(deviceState > NM_DEVICE_STATE_DISCONNECTED && deviceState < NM_DEVICE_STATE_DEACTIVATING)
interface.connected = true;
else
interface.connected = false;

if(ifaceStr == wifiname) {
interface.type = INTERFACE_TYPE_WIFI;
interface.name = wifiname;
m_wlanConnected = interface.connected;
}
if(ifaceStr == ethname) {
interface.type = INTERFACE_TYPE_ETHERNET;
interface.name = ethname;
m_ethConnected = interface.connected;
}

interface.mac = nm_device_get_hw_address(device);
deviceState = nm_device_get_state(device);
interface.enabled = (deviceState >= NM_DEVICE_STATE_UNAVAILABLE) ? true : false;
if(deviceState > NM_DEVICE_STATE_DISCONNECTED && deviceState < NM_DEVICE_STATE_DEACTIVATING){
interface.connected = true;
m_defaultInterface = interface.name;
}
else
interface.connected = false;
interfaceList.push_back(interface);
rc = Core::ERROR_NONE;
}
Expand Down
Loading

0 comments on commit 9272b7e

Please sign in to comment.