Skip to content

Commit f23e06c

Browse files
author
Arto Kinnunen
committed
Use separate method for each property
1 parent b754767 commit f23e06c

File tree

4 files changed

+133
-17
lines changed

4 files changed

+133
-17
lines changed

features/nanostack/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,18 @@ class InterfaceNanostack : public virtual NetworkInterface {
140140
*/
141141
virtual nsapi_error_t set_file_system_root_path(const char *root_path);
142142

143-
/** @copydoc NetworkInterface::get_interface_property */
144-
virtual nsapi_error_t get_interface_property(nsapi_size_t data_amount, nsapi_size_t *jitter);
143+
/** @copydoc NetworkInterface::get_interface_timing_property */
144+
virtual nsapi_error_t get_interface_timing_property(unsigned int data_amount,
145+
unsigned int *initial_delay_min,
146+
unsigned int *initial_delay_max,
147+
unsigned int *initial_delay_rand,
148+
unsigned int *expected_rtt);
149+
150+
/** @copydoc NetworkInterface::get_interface_initial_delay */
151+
virtual nsapi_error_t get_interface_initial_delay(unsigned int data_amount, unsigned int *initial_delay);
152+
153+
/** @copydoc NetworkInterface::get_interface_rtt */
154+
virtual nsapi_error_t get_interface_rtt(unsigned int *expected_rtt);
145155

146156
/** Get the interface ID
147157
* @return Interface identifier

features/nanostack/mbed-mesh-api/source/MeshInterfaceNanostack.cpp

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "NanostackLockGuard.h"
2020
#include "mesh_system.h"
2121
#include "nanostack/net_interface.h"
22-
#include "nanostack/ns_property.h"
2322
#include "thread_management_if.h"
2423
#include "ip6string.h"
2524
#include "mbed_error.h"
@@ -233,13 +232,55 @@ nsapi_error_t InterfaceNanostack::set_file_system_root_path(const char *root_pat
233232
return MESH_ERROR_UNKNOWN;
234233
}
235234

236-
nsapi_error_t InterfaceNanostack::get_interface_property(nsapi_size_t data_amount, nsapi_size_t *jitter) {
237-
ns_properties_t ns_properties;
235+
nsapi_error_t InterfaceNanostack::get_interface_timing_property(unsigned int data_amount,
236+
unsigned int *initial_delay_min,
237+
unsigned int *initial_delay_max,
238+
unsigned int *initial_delay_rand,
239+
unsigned int *expected_rtt)
240+
{
241+
net_timing_constraint_t net_timing_constraint;
242+
243+
if (!initial_delay_min || !initial_delay_max || !initial_delay_rand || !expected_rtt) {
244+
return NSAPI_ERROR_PARAMETER;
245+
}
246+
247+
if (arm_nwk_interface_timing_constraint_get(get_interface_id(), data_amount, &net_timing_constraint) == 0) {
248+
*initial_delay_min = net_timing_constraint.jitter_min;
249+
*initial_delay_max = net_timing_constraint.jitter_max;
250+
*initial_delay_rand = net_timing_constraint.jitter_rand;
251+
*expected_rtt = net_timing_constraint.network_latency * 2; // RTT = 2 * latency + some processing time
252+
return NSAPI_ERROR_OK;
253+
}
238254

239-
ns_properties.data_amount = data_amount;
255+
return NSAPI_ERROR_NO_CONNECTION;
256+
}
257+
258+
nsapi_error_t InterfaceNanostack::get_interface_initial_delay(unsigned int data_amount, unsigned int *initial_delay)
259+
{
260+
net_timing_constraint_t net_timing_constraint;
261+
262+
if (!initial_delay) {
263+
return NSAPI_ERROR_PARAMETER;
264+
}
265+
266+
if (arm_nwk_interface_timing_constraint_get(get_interface_id(), 0, &net_timing_constraint) == 0) {
267+
*initial_delay = net_timing_constraint.jitter_rand;
268+
return NSAPI_ERROR_OK;
269+
}
270+
271+
return NSAPI_ERROR_NO_CONNECTION;
272+
}
273+
274+
nsapi_error_t InterfaceNanostack::get_interface_rtt(unsigned int *expected_rtt)
275+
{
276+
net_timing_constraint_t net_timing_constraint;
277+
278+
if (!expected_rtt) {
279+
return NSAPI_ERROR_PARAMETER;
280+
}
240281

241-
if (ns_property_get(get_interface_id(), &ns_properties) == 0) {
242-
*jitter = ns_properties.tx_jitter;
282+
if (arm_nwk_interface_timing_constraint_get(get_interface_id(), 0, &net_timing_constraint) == 0) {
283+
*expected_rtt = net_timing_constraint.network_latency * 2; // RTT = 2 * latency + some processing time
243284
return NSAPI_ERROR_OK;
244285
}
245286

features/netsocket/NetworkInterface.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,22 @@ nsapi_error_t NetworkInterface::set_blocking(bool blocking)
174174
return NSAPI_ERROR_UNSUPPORTED;
175175
}
176176

177-
nsapi_error_t NetworkInterface::get_interface_property(unsigned int data_amount, unsigned int *jitter)
177+
nsapi_error_t NetworkInterface::get_interface_timing_property(unsigned int data_amount,
178+
unsigned int *initial_delay_min,
179+
unsigned int *initial_delay_max,
180+
unsigned int *initial_delay_rand,
181+
unsigned int *expected_rtt)
182+
{
183+
return NSAPI_ERROR_UNSUPPORTED;
184+
}
185+
186+
nsapi_error_t NetworkInterface::get_interface_initial_delay(unsigned int data_amount,
187+
unsigned int *initial_delay)
188+
{
189+
return NSAPI_ERROR_UNSUPPORTED;
190+
}
191+
192+
nsapi_error_t NetworkInterface::get_interface_rtt(unsigned int *expected_rtt)
178193
{
179194
return NSAPI_ERROR_UNSUPPORTED;
180195
}

features/netsocket/NetworkInterface.h

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,64 @@ class NetworkInterface: public DNS {
378378
*/
379379
virtual nsapi_error_t set_blocking(bool blocking);
380380

381-
/** Get suggested data transmission jitter from underlying network interface.
382-
*
383-
* @param data_amount Amount of data to be sent
384-
* @param jitter Address to location where suggested jitter value is written
385-
* @return NSAPI_ERROR_OK on success
386-
* @return NSAPI_ERROR_UNSUPPORTED, NSAPI_ERROR_NO_CONNECTION
387-
*/
388-
virtual nsapi_error_t get_interface_property(unsigned int data_amount, unsigned int *jitter);
381+
/** Get network interface timing properties.
382+
*
383+
* Network interfaces have different characteristics. Some wireless networks are
384+
* established slowly and may have a high latency while some wired networks are
385+
* ready almost instantly after power on.
386+
*
387+
* Application can use network timing properties to adapt to the varying network
388+
* interfaces. Properties include:
389+
* * initial delay, a estimated wait time that application should wait after startup before sending data to the network.
390+
* * round-trip time, a estimated time between sending a signal and receiving the response.
391+
*
392+
* @param data_amount Amount of data to be sent in kilobytes.
393+
* @param initial_delay_min Address to minimum delay value (ms), must be non-null.
394+
* @param initial_delay_max Address to maximum delay value (ms), must be non-null.
395+
* @param initial_delay_rand Address to randomized delay value (ms), must be non-null.
396+
* @param expected_rtt Address to expected round-trip time value (ms), must be non-null.
397+
* @return NSAPI_ERROR_OK on success.
398+
* @return NSAPI_ERROR_UNSUPPORTED if API is not implemented to interface.
399+
* @return NSAPI_ERROR_NO_CONNECTION if network is not connected.
400+
* @return NSAPI_ERROR_PARAMETER. if input parameters are not valid.
401+
*/
402+
virtual nsapi_error_t get_interface_timing_property(unsigned int data_amount,
403+
unsigned int *initial_delay_min,
404+
unsigned int *initial_delay_max,
405+
unsigned int *initial_delay_rand,
406+
unsigned int *expected_rtt);
407+
408+
/** Get initial delay for the network interface
409+
*
410+
* Initial delay can be used to optimize network performance. Some wireless networks
411+
* use a lot of network bandwidth to find and extend the network during startup.
412+
* Having an application sending data aggressively during the startup can result to
413+
* network congestion that will drop network performance even more.
414+
* Initial delay is a randomized value based on the selected interface properties.
415+
*
416+
* @param data_amount Amount of data in kilobytes that application is going to send.
417+
* @param initial_delay Address to location where initial_delay is written in milliseconds.
418+
* @return NSAPI_ERROR_OK on success.
419+
* @return NSAPI_ERROR_UNSUPPORTED if API is not implemented to interface.
420+
* @return NSAPI_ERROR_NO_CONNECTION if network is not connected.
421+
* @return NSAPI_ERROR_PARAMETER. if input parameters are not valid.
422+
*/
423+
virtual nsapi_error_t get_interface_initial_delay(unsigned int data_amount,
424+
unsigned int *initial_delay);
425+
426+
/** Get network interface expected round-trip time (RTT)
427+
*
428+
* Application can use expected RTT to adjust possible retry intervals.
429+
* Wired networks may have RTT value less than a seconds while some wireless
430+
* networks could have a RTT up to several minutes.
431+
*
432+
* @param expected_rtt Address to location where expected RTT is written (ms).
433+
* @return NSAPI_ERROR_OK on success.
434+
* @return NSAPI_ERROR_UNSUPPORTED if API is not implemented to interface.
435+
* @return NSAPI_ERROR_NO_CONNECTION if network is not connected.
436+
* @return NSAPI_ERROR_PARAMETER. if input parameters are not valid.
437+
*/
438+
virtual nsapi_error_t get_interface_rtt(unsigned int *expected_rtt);
389439

390440
/** Return pointer to an EthInterface.
391441
* @return Pointer to requested interface type or NULL if this class doesn't implement the interface.

0 commit comments

Comments
 (0)