-
Notifications
You must be signed in to change notification settings - Fork 32
Feature/add bml cli commands to dynamic channel selection bml apis #699
Feature/add bml cli commands to dynamic channel selection bml apis #699
Conversation
@@ -190,6 +190,18 @@ class cli_bml : public cli { | |||
int steering_client_measure(uint32_t steeringGroupIndex, const std::string &str_bssid, | |||
const std::string &str_client_mac); | |||
#endif | |||
int set_dcs_continuous_scan_enable(const std::string &radio_mac, int8_t enable); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add doxygen to all new APIs either here or in the implementation file.
A rule of thumb - every new function comes with doxygen comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added inside the CPP file (not to clatter the class header)
} else if (numOfArgs == 3) { | ||
return set_dcs_continuous_scan_params(args.stringArgs[0], args.intArgs[1], args.intArgs[2]); | ||
} else if (numOfArgs == 4) { | ||
std::cout << "Invalid number of arguments, set of channel_pool must also provide " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we print such an error in other failure cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a special case where 2 params must be provided together or omitted together
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code was removed as part of refactoring due to @morantr comment
return -1; | ||
} | ||
|
||
struct BML_DCS_NEIGHBOR_AP *results = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for struct
keyword - its CPP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the struct keyword
|
||
results = | ||
(struct BML_DCS_NEIGHBOR_AP *)calloc(max_results_size, sizeof(struct BML_DCS_NEIGHBOR_AP)); | ||
if (results == nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you run KW on this? please refrain from using if (ptr == nullptr)
and instead use if (!ptr)
to avoid KW issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the entirely - and will run KW
std::cout << __func__ << "ERROR: results_count(" << results_count << ")" | ||
<< " > max_results_size(" << max_results_size << ")" << std::endl; | ||
} else if (status == 0 && results_count > 0) { | ||
//todo: replace the temporary debug print with actual prints of the new results structure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow - what is temporary with the debug print? Aren't the results already in the new structure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no - since the PR that changes the structure is not available yet
(PRs 4/5):
#694
struct BML_DCS_NEIGHBOR_AP *results = nullptr; | ||
|
||
results = | ||
(struct BML_DCS_NEIGHBOR_AP *)calloc(max_results_size, sizeof(struct BML_DCS_NEIGHBOR_AP)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is absolutely no good reason to use calloc
or alloc
in c++, and especially in this function where you simply print the returned results and free them right after.
Simply declare the results on the stack:
BML_DCS_NEIGHBOR_AP results[max_results_size];
Also - why is the max_results_size
argument even needed? This can also be statically declared in the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the max_results_size is to simulate the max-results-size limit also used in in RDKB (currently set as 200)
when DCS supports ordering of the results by RSSI or another ranking, it is possible to the get only the X best results even if more are available
I replaced the with a stack declaration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The best would be to change the DCS WLAN APIs as well - is it feasible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be - you can create a JIRA to check this at a later time - shouldn't block this PR
int set_dcs_continuous_scan_params(const std::string &radio_mac, | ||
int dwell_time = BML_DCS_INVALID_PARAM, | ||
int interval_time = BML_DCS_INVALID_PARAM, | ||
const std::string &channel_pool = std::string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you passing channel_pool
as a string and not a vector or array? The caller function should parse it and convert it to vector/array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
none of the caller functions in the BML CLI perform any parsing. they are all a wrapper for getting the information from the CLI command to the cli_bml command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Moran here - we should do the conversion in the BML CLI and get rid of the size of channel pool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed - removed the channel pool size from user input params. calculated from channel_pool input.
} | ||
|
||
int cli_bml::get_dcs_scan_results(const std::string &radio_mac, unsigned int max_results_size, | ||
int8_t is_single_scan) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the is_single_scan
is int8 and not bool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was changed to bool
1, STRING_ARG); | ||
insertCommandToMap( | ||
"bml_set_dcs_continuous_scan_params", | ||
"<mac> <dwell_time_msec> [<interval_time>] [<channel_pool>] [<channel_pool_size>]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can define it like this only if you set all the optional arguments altogether. This is not the case here, so what you need to do is to explicitly write to what argument do you mean:
<mac> <dwell_time_msec> [ interval_time=<interval_time>] [channel_pool=<channel_pool>]
on the caller function you will need to parse it, and here convert all the argument types to STRING_ARG
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok - replaced the implementation to what you suggested (used the beerocks_cli_socket::client_beacon_11k_req as reference)
int ret = bml_get_dcs_continuous_scan_enable(ctx, radio_mac.c_str(), &enable); | ||
|
||
if (ret == BML_RET_OK) { | ||
std::cout << "dcs-continuous-scan-enable=" << ((enable == 1) ? "True" : "False") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string_utils::bool_str(enable);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasn't familiar with it - very useful - fixed, thanks
struct BML_DCS_NEIGHBOR_AP *results = nullptr; | ||
|
||
results = | ||
(struct BML_DCS_NEIGHBOR_AP *)calloc(max_results_size, sizeof(struct BML_DCS_NEIGHBOR_AP)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why didn't you declare it on the stack???
Anyway, this is C allocation. The CPP way is with new
/delete
and the better option will be to use smart pointers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tomereli already mentioned it - I fixed it and am using a user-defined-sized array declared on the stack.
"<mac> <dwell_time_msec> [<interval_time>] [<channel_pool>] [<channel_pool_size>]", | ||
"Set the continuous scan params for the given AP mac: dwell_time - dwell time in " | ||
"miliseconds, interval_time - interval time in seconds," | ||
" channel_pool - channels seperated by commas (set of channel_pool must also provide " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: should be "separated"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed - thanks
"bml_set_dcs_continuous_scan_params", | ||
"<mac> <dwell_time_msec> [<interval_time>] [<channel_pool>] [<channel_pool_size>]", | ||
"Set the continuous scan params for the given AP mac: dwell_time - dwell time in " | ||
"miliseconds, interval_time - interval time in seconds," |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: "milliseconds"
This typo is repeated in other commands
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed - thanks
static_cast<pFunction>(&cli_bml::get_dcs_continuous_scan_params_caller), 1, | ||
1, STRING_ARG); | ||
insertCommandToMap( | ||
"bml_start_dcs_single_scan", "<mac> <dwell_time_msec> <channel_pool_size> <channel_pool>", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the sake of consistency, channel_pool_size and channel_pool should be given in the same order in all commands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I felt the same itch - but this was aligned to the signature of DCS BML APIS.
we decided to remove the channel_pool_size completely (and parse it from the string of channel_pool) - so will be fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update - removed the channel_pool_size from user input
|
||
int cli_bml::get_dcs_continuous_scan_params(const std::string &radio_mac) | ||
{ | ||
std::cout << "get_dcs_continuous_scan_params" << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably be using func instead of a literal string to avoid copy & paste errors. This way maintenance is easier (if method name changes, there is no need to change anything else).
This is something to be considered in all the methods in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
&interval_time, channel_pool, &channel_pool_size); | ||
|
||
if (ret == BML_RET_OK) { | ||
std::cout << "dcs-continuous-scan-params for mac:" << std::endl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MAC address is not being printed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
std::cout << "start_dcs_single_scan" << std::endl; | ||
|
||
if (dwell_time <= 0) { | ||
std::cout << __func__ << "invalid input: dwell_time(" << dwell_time << ") <= 0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method name is being printed together with next literal string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
||
int cli_bml::get_dcs_continuous_scan_enable_caller(int numOfArgs) | ||
{ | ||
if (numOfArgs == 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been using Yoda conditions for a long time now that these lines make me feel uncomfortable.
Some static code analyzers would also complain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am familiar with this approach - but this is not maintained in the prpl.
if @tomereli and @arnout want to add this requirement to prplmesh guidelines it is OK, but a short search of the following regex. <[a-z,A-Z] == [0-9]> produced 375 results in 93 files
will not be handled in this PR, but we can set a task for this change across the code if decided
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3672fab
to
612d86b
Compare
2357762
to
ee5d3aa
Compare
ee5d3aa
to
0ecb7a3
Compare
0ecb7a3
to
5da3456
Compare
5da3456
to
6836550
Compare
487e46f
to
dffb919
Compare
dffb919
to
d51494c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some more comments, I think you should fix them but if this is urgent it can be done as part of #665 , so approving again.
@@ -24,6 +24,17 @@ using namespace net; | |||
/////////////////////////// Local Module Functions /////////////////////////// | |||
////////////////////////////////////////////////////////////////////////////// | |||
|
|||
static const std::string string_from_int_array(void *arr, size_t arr_max_size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of this function implies it creates a string from an array of integers. So it should be
static const std::string string_from_int_array(int arr[], size_t len);
Also - please add a doxygen comment explaining this function.
<< " channel=" << int(res.ap_Channel) << std::endl | ||
<< " signal_strength=" << int(res.ap_SignalStrength) << std::endl | ||
<< " security_mode_enabled=" | ||
<< string_from_int_array(res.ap_SecurityModeEnabled, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm think that security mode should be a single value - I'm dazzled why you chose array. Please make it a single value unless there's a very good reason why you need an array. Then we can get rid of this weird string_from_int_array
function.
BML_CHANNEL_SCAN_ENUM_LIST_SIZE) | ||
<< std::endl | ||
<< " encryption_mode=" | ||
<< string_from_int_array(res.ap_EncryptionMode, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here - there is a single encryption mode set at a given time. I don't understand why it is an array.
@@ -2021,28 +2032,40 @@ int cli_bml::get_dcs_scan_results(const std::string &radio_mac, uint32_t max_res | |||
std::cout << __func__ << "ERROR: results_count(" << results_count << ")" | |||
<< " > max_results_size(" << max_results_size << ")" << std::endl; | |||
} else if ((status == 0) && (results_count > 0)) { | |||
//todo: replace the temporary debug print with actual prints of the new results structure | |||
for (size_t i = 0; i < results_count; i++) { | |||
auto res = results[i]; | |||
std::cout << "result[" << i << "]:" << std::endl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this whole big print, why not add inline std::ostream &operator<<(std::ostream &os, const BML_NEIGHBOR_AP &neigh);
to struct BML_NEIGHBOR_AP
in bml_defs.h
then you can replace this with:
for (size_t i = 0; i < results_count; i++) {
std::cout << "result[" << i << "]:" << std::endl << results[i] << std::endl;
}
Finally, please rebase and squash before merge. |
added the following stubs of BML CLI commands of DCS BML APIs: set_dcs_continuous_scan_enable get_dcs_continuous_scan_enable set_dcs_continuous_scan_params get_dcs_continuous_scan_params start_dcs_single_scan get_dcs_scan_results Signed-off-by: Adam Dov <[email protected]> Signed-off-by: itay elenzweig <[email protected]>
Signed-off-by: Adam Dov <[email protected]> Signed-off-by: itay elenzweig <[email protected]>
The insertion of the BML commands is performed in the setFunctionsMapAndArray() using the insertCommandToMap command. After this change, the following commands are available in the BML CLI: set_dcs_continuous_scan_enable get_dcs_continuous_scan_enable set_dcs_continuous_scan_params get_dcs_continuous_scan_params start_dcs_single_scan get_dcs_scan_results Signed-off-by: Adam Dov <[email protected]> Signed-off-by: itay elenzweig <[email protected]>
The implementation of each command is aligned with the existing DCS wave functions implementation in "wave-api" in RDKB. A detailed description of each command use is available in the CLI help menu. Signed-off-by: Adam Dov <[email protected]> Signed-off-by: itay elenzweig <[email protected]>
d51494c
to
4ed6526
Compare
fixed all code review comments and passed all tests |
This PR adds CLI BML commands to the beerocks_cli for the following DCS BML APIS:
bml_set_dcs_continuous_scan_enable
bml_get_dcs_continuous_scan_enable
bml_set_dcs_continuous_scan_params
bml_get_dcs_continuous_scan_params
bml_start_dcs_single_scan
bml_get_dcs_scan_results
The commands naming are aligned to the called APIs without the 'bml_' initial:
set_dcs_continuous_scan_enable
get_dcs_continuous_scan_enable
set_dcs_continuous_scan_params
get_dcs_continuous_scan_params
start_dcs_single_scan
get_dcs_scan_results
The command's description is available in the beerocks_cli help menu