31 #include "Device_IP_Diagnostics_SpeedTest.h"
32 #include "hostIf_utils.h"
37 #define TR69DIR "/opt/tr-181/"
38 #define STORE_EXTENSION "sdb"
41 #define DIAGNOSTICS_DIR "/opt/diagnostics/"
42 #define PROD_DIR "/usr/bin/"
45 #define SPEEDTEST_BIN "speedtest.sh"
46 #define NON_BLOCKING " &"
49 const char* hostIf_IP_Diagnostics_SpeedTest::SpeedTestProfile =
"Device.IP.Diagnostics.X_RDKCENTRAL-COM_SpeedTest.";
59 filename.append (TR69DIR).append(SpeedTestProfile).append (STORE_EXTENSION);
61 bCalledEnable =
false;
65 if (!dbStore.load (filename))
68 std::ofstream output_stream (filename.c_str());
72 RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF,
"[%s] dbStore for SpeedTest is already present\n", __FUNCTION__);
103 std::string spdtst_parameter_name (stMsgData->
paramName + strlen (SpeedTestProfile));
105 if (spdtst_parameter_name.compare(
"Enable_Speedtest") &&
106 spdtst_parameter_name.compare (
"Run") &&
107 spdtst_parameter_name.compare (
"Argument") &&
108 spdtst_parameter_name.compare (
"ClientType") &&
109 spdtst_parameter_name.compare (
"Authentication") &&
110 spdtst_parameter_name.compare (
"Status"))
112 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"[%s] Unsupported SpeedTest parameter '%s'\n", __FUNCTION__, stMsgData->
paramName);
113 stMsgData->
faultCode = fcInvalidParameterName;
117 RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF,
"[%s] SpeedTest parameter '%s' is being set\n", __FUNCTION__, stMsgData->
paramName);
118 std::string value = dbStore.value (stMsgData->
paramName,
"");
119 putValue(stMsgData, value);
142 std::string spdtst_parameter_name (stMsgData->
paramName + strlen (SpeedTestProfile));
144 if (spdtst_parameter_name.compare(
"Enable_Speedtest") &&
145 spdtst_parameter_name.compare (
"Run") &&
146 spdtst_parameter_name.compare (
"Argument") &&
147 spdtst_parameter_name.compare (
"ClientType") &&
148 spdtst_parameter_name.compare (
"Authentication") &&
149 spdtst_parameter_name.compare (
"Status"))
151 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"[%s] Unsupported SpeedTest parameter '%s'\n", __FUNCTION__, stMsgData->
paramName);
152 stMsgData->
faultCode = fcInvalidParameterName;
154 else if (
false == dbStore.setValue (stMsgData->
paramName, getStringValue(stMsgData)))
156 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"[%s] SpeedTest setValue failed '%s'\n", __FUNCTION__, stMsgData->
paramName);
165 if( stMsgData->
faultCode == fcInternalError )
168 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"[%s] SpeedTest setValue failed '%s'\n", __FUNCTION__, stMsgData->
paramName);
172 RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF,
"[%s] SpeedTest setValue succeeded '%s'\n", __FUNCTION__, stMsgData->
paramName);
188 std::string spdtst_parameter_name (stMsgData->
paramName + strlen (SpeedTestProfile));
190 if (spdtst_parameter_name.compare (
"Enable_Speedtest") == 0)
192 bCalledEnable = get_boolean(stMsgData->
paramValue);
195 if (spdtst_parameter_name.compare (
"Run") == 0)
197 bCalledRun = get_boolean(stMsgData->
paramValue);
199 if (bCalledEnable && bCalledRun)
201 RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF,
"[%s] Speedtest application is being launched '%s'\n", __FUNCTION__, stMsgData->
paramName);
202 std::string application_diagnostics;
203 std::string application_prod;
204 std::string application;
206 ifstream launch_script;
209 application_prod.append (PROD_DIR).append(SPEEDTEST_BIN);
210 application_diagnostics.append (DIAGNOSTICS_DIR).append(SPEEDTEST_BIN);
213 application = application_prod;
215 #ifdef SPEEDTEST_DIAGNOSTICS
216 application = application_diagnostics;
220 launch_script.open(application.c_str());
221 if (launch_script.fail())
223 application = application_prod;
224 launch_script.open(application.c_str());
225 if (launch_script.fail())
227 RDK_LOG (RDK_LOG_INFO, LOG_TR69HOSTIF,
"[%s] Speedtest launch script is not found anywhere\n", __FUNCTION__);
231 application.append(NON_BLOCKING);
232 system(application.c_str());
235 if(
false == dbStore.setValue (stMsgData->
paramName,
"false"))