Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

[DCS Patch 4/5] port dynamic channel selection from rdkb flow #694

Merged
Merged
137 changes: 134 additions & 3 deletions agent/src/beerocks/monitor/monitor_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <beerocks/tlvf/beerocks_message.h>

#include <cmath>
#include <vector>

using namespace beerocks;
using namespace net;
Expand Down Expand Up @@ -79,10 +80,10 @@ void monitor_thread::stop_monitor_thread()
} else {

LOG(ERROR) << "disconnecting monitor_thread sockets";
if (mon_hal_ext_events || slave_socket)
LOG(DEBUG) << "stop_monitor_thread()";

LOG_IF(mon_hal_ext_events || mon_hal_nl_events || slave_socket, DEBUG)
<< "stop_monitor_thread()";
if (mon_hal_ext_events) {
LOG(DEBUG) << "stopping mon_hal_ext_events!";
mon_rssi.stop();
mon_stats.stop();
#ifdef BEEROCKS_RDKB
Expand All @@ -96,12 +97,21 @@ void monitor_thread::stop_monitor_thread()
}

if (mon_hal_int_events) {
LOG(DEBUG) << "stopping mon_hal_int_events!";
remove_socket(mon_hal_int_events);
delete mon_hal_int_events;
mon_hal_int_events = nullptr;
}

if (mon_hal_nl_events) {
LOG(DEBUG) << "stopping mon_hal_nl_events!";
remove_socket(mon_hal_nl_events);
delete mon_hal_nl_events;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By looking at the rest of the file I wonder why we have to resort to explicitly calling delete here, though that's not related to this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kantera800
I'm not sure myself if this is needed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from looking at the code remove_socket just isn't strong enough

mon_hal_nl_events = nullptr;
}

if (slave_socket) {
LOG(DEBUG) << "stopping slave_socket!";
remove_socket(slave_socket);
slave_socket->closeSocket();
delete slave_socket;
Expand Down Expand Up @@ -135,6 +145,11 @@ bool monitor_thread::socket_disconnected(Socket *sd)
thread_last_error_code = MONITOR_THREAD_ERROR_HAL_DISCONNECTED;
stop_monitor_thread();
return false;
} else if (mon_hal_nl_events && (sd == mon_hal_nl_events)) {
LOG(ERROR) << "mon_hal_nl_events socket disconnected!";
thread_last_error_code = MONITOR_THREAD_ERROR_NL_EVENTS_SOCKET_DISCONNECTED;
stop_monitor_thread();
return false;
}

return true;
Expand Down Expand Up @@ -262,6 +277,17 @@ void monitor_thread::after_select(bool timeout)
return;
}

int nl_events_fd = mon_wlan_hal->get_nl_events_fd();
if (nl_events_fd > 0) {
mon_hal_nl_events = new Socket(nl_events_fd);
add_socket(mon_hal_nl_events);
LOG(DEBUG) << "nl socket created for FD #" << nl_events_fd;
} else {
LOG(ERROR) << "Couldn't get NL socket ";
mon_hal_nl_events = nullptr;
thread_last_error_code = MONITOR_THREAD_ERROR_NL_ATTACH_FAIL;
}

// start local monitors //
LOG(TRACE) << "mon_stats.start()";
if (!mon_stats.start(&mon_db, slave_socket)) {
Expand Down Expand Up @@ -346,6 +372,19 @@ void monitor_thread::after_select(bool timeout)
}
}

// Process nl events
if (mon_hal_nl_events) {
tomereli marked this conversation as resolved.
Show resolved Hide resolved
if (read_ready(mon_hal_nl_events)) {
if (!mon_wlan_hal->process_nl_events()) {
LOG(ERROR) << "process_nl_events() failed!";
thread_last_error_code = MONITOR_THREAD_ERROR_NL_REPORT_PROCESS_FAIL;
stop_monitor_thread();
return;
}
clear_ready(mon_hal_nl_events);
}
}

if (pending_11k_events.size() > 0) {
auto now_time = std::chrono::steady_clock::now();
for (auto it = pending_11k_events.begin(); it != pending_11k_events.end();) {
Expand Down Expand Up @@ -1106,6 +1145,52 @@ bool monitor_thread::handle_cmdu(Socket *sd, ieee1905_1::CmduMessageRx &cmdu_rx)
mon_wlan_hal->sta_link_measurements_11k_request(mac_str);
break;
}
case beerocks_message::ACTION_MONITOR_CHANNEL_SCAN_TRIGGER_SCAN_REQUEST: {
auto request =
beerocks_header
->addClass<beerocks_message::cACTION_MONITOR_CHANNEL_SCAN_TRIGGER_SCAN_REQUEST>();
if (!request) {
LOG(ERROR) << "addClass cACTION_MONITOR_CHANNEL_SCAN_TRIGGER_SCAN_REQUEST failed";
return false;
}

auto radio_mac = request->scan_params().radio_mac;
auto dwell_time_ms = request->scan_params().dwell_time_ms;
auto channel_pool = request->scan_params().channel_pool;
auto channel_pool_size = request->scan_params().channel_pool_size;
auto channel_pool_vector =
std::vector<unsigned int>(channel_pool, channel_pool + channel_pool_size);
std::string channels;

//loop for priting the channal pool
for (int index = 0; index < int(channel_pool_size); index++) {
channels += ((index != 0) ? "," : "") + std::to_string(channel_pool[index]);
}

//debug print incoming information:
LOG(DEBUG) << std::endl
<< "scan_params:" << std::endl
<< "radio_mac=" << radio_mac << std::endl
<< "dwell_time_ms=" << dwell_time_ms << std::endl
<< "channel_pool_size=" << int(channel_pool_size) << std::endl
<< "channel_pool=" << channels;

auto response_out = message_com::create_vs_message<
beerocks_message::cACTION_MONITOR_CHANNEL_SCAN_TRIGGER_SCAN_RESPONSE>(
cmdu_tx, beerocks_header->id());
if (!response_out) {
LOG(ERROR)
<< "Failed building cACTION_MONITOR_CHANNEL_SCAN_TRIGGER_SCAN_RESPONSE message!";
return false;
}

bool result = mon_wlan_hal->channel_scan_trigger(int(dwell_time_ms), channel_pool_vector);
LOG_IF(!result, ERROR) << "channel_scan_trigger Failed";

response_out->success() = (result) ? 1 : 0;
message_com::send_cmdu(slave_socket, cmdu_tx);
break;
}
default: {
LOG(ERROR) << "Unsupported MONITOR action_op: " << int(beerocks_header->action_op());
break;
Expand Down Expand Up @@ -1369,6 +1454,52 @@ bool monitor_thread::hal_event_handler(bwl::base_wlan_hal::hal_event_ptr_t event
update_vaps_in_db();

} break;
case Event::Channel_Scan_Triggered: {
auto notification = message_com::create_vs_message<
beerocks_message::cACTION_MONITOR_CHANNEL_SCAN_TRIGGERED_NOTIFICATION>(cmdu_tx);
if (!notification) {
LOG(ERROR) << "Failed building cACTION_MONITOR_CHANNEL_SCAN_TRIGGERED_NOTIFICATION msg";
return false;
}

message_com::send_cmdu(slave_socket, cmdu_tx);
} break;
case Event::Channel_Scan_New_Results_Ready:
case Event::Channel_Scan_Dump_Result: {
auto notification = message_com::create_vs_message<
beerocks_message::cACTION_MONITOR_CHANNEL_SCAN_RESULTS_NOTIFICATION>(cmdu_tx);
if (!notification) {
LOG(ERROR) << "Failed building cACTION_MONITOR_CHANNEL_SCAN_RESULTS_NOTIFICATION msg";
return false;
}

// If event == Channel_Scan_New_Results_Ready do nothing since is_dump's default is 0
if (event == Event::Channel_Scan_Dump_Result) {
itayx marked this conversation as resolved.
Show resolved Hide resolved
notification->is_dump() = 1;
}

message_com::send_cmdu(slave_socket, cmdu_tx);
} break;
case Event::Channel_Scan_Finished: {
auto notification = message_com::create_vs_message<
beerocks_message::cACTION_MONITOR_CHANNEL_SCAN_FINISHED_NOTIFICATION>(cmdu_tx);
if (!notification) {
LOG(ERROR) << "Failed building cACTION_MONITOR_CHANNEL_SCAN_FINISHED_NOTIFICATION msg";
return false;
}

message_com::send_cmdu(slave_socket, cmdu_tx);
} break;
case Event::Channel_Scan_Abort: {
auto notification = message_com::create_vs_message<
beerocks_message::cACTION_MONITOR_CHANNEL_SCAN_ABORT_NOTIFICATION>(cmdu_tx);
if (!notification) {
LOG(ERROR) << "Failed building cACTION_MONITOR_CHANNEL_SCAN_ABORT_NOTIFICATION msg";
return false;
}

message_com::send_cmdu(slave_socket, cmdu_tx);
} break;

// Unhandled events
default: {
Expand Down
16 changes: 10 additions & 6 deletions agent/src/beerocks/monitor/monitor_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ class monitor_thread : public beerocks::socket_thread {
virtual bool init() override;

enum eThreadErrors : uint32_t {
MONITOR_THREAD_ERROR_NO_ERROR = 0,
MONITOR_THREAD_ERROR_HOSTAP_DISABLED = 1,
MONITOR_THREAD_ERROR_ATTACH_FAIL = 2,
MONITOR_THREAD_ERROR_SUDDEN_DETACH = 3,
MONITOR_THREAD_ERROR_HAL_DISCONNECTED = 4,
MONITOR_THREAD_ERROR_REPORT_PROCESS_FAIL = 5,
MONITOR_THREAD_ERROR_NO_ERROR = 0,
MONITOR_THREAD_ERROR_HOSTAP_DISABLED = 1,
MONITOR_THREAD_ERROR_ATTACH_FAIL = 2,
MONITOR_THREAD_ERROR_SUDDEN_DETACH = 3,
MONITOR_THREAD_ERROR_HAL_DISCONNECTED = 4,
MONITOR_THREAD_ERROR_REPORT_PROCESS_FAIL = 5,
MONITOR_THREAD_ERROR_NL_ATTACH_FAIL = 6,
MONITOR_THREAD_ERROR_NL_REPORT_PROCESS_FAIL = 7,
MONITOR_THREAD_ERROR_NL_EVENTS_SOCKET_DISCONNECTED = 8,
};

protected:
Expand Down Expand Up @@ -80,6 +83,7 @@ class monitor_thread : public beerocks::socket_thread {
Socket *slave_socket = nullptr;
Socket *mon_hal_ext_events = nullptr;
Socket *mon_hal_int_events = nullptr;
Socket *mon_hal_nl_events = nullptr;
beerocks::logging &logger;

typedef struct {
Expand Down
123 changes: 123 additions & 0 deletions agent/src/beerocks/slave/son_slave_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,30 @@ bool slave_thread::handle_cmdu_control_message(Socket *sd,

break;
}
case beerocks_message::ACTION_CONTROL_CHANNEL_SCAN_TRIGGER_SCAN_REQUEST: {
LOG(TRACE) << "ACTION_CONTROL_CHANNEL_SCAN_TRIGGER_SCAN_REQUEST";
auto request_in =
beerocks_header
->addClass<beerocks_message::cACTION_CONTROL_CHANNEL_SCAN_TRIGGER_SCAN_REQUEST>();
if (!request_in) {
LOG(ERROR) << "addClass cACTION_CONTROL_CHANNEL_SCAN_TRIGGER_SCAN_REQUEST failed";
return false;
}

auto request_out = message_com::create_vs_message<
beerocks_message::cACTION_MONITOR_CHANNEL_SCAN_TRIGGER_SCAN_REQUEST>(cmdu_tx);
if (!request_out) {
LOG(ERROR)
<< "Failed building cACTION_MONITOR_CHANNEL_SCAN_TRIGGER_SCAN_REQUEST message!";
return false;
}

request_out->scan_params() = request_in->scan_params();

LOG(DEBUG) << "send cACTION_MONITOR_CHANNEL_SCAN_TRIGGER_SCAN_REQUEST";
message_com::send_cmdu(monitor_socket, cmdu_tx);
break;
}
default: {
LOG(ERROR) << "Unknown CONTROL message, action_op: " << int(beerocks_header->action_op());
return false;
Expand Down Expand Up @@ -2794,6 +2818,105 @@ bool slave_thread::handle_cmdu_monitor_message(Socket *sd,
send_cmdu_to_controller(cmdu_tx);
break;
}
case beerocks_message::ACTION_MONITOR_CHANNEL_SCAN_TRIGGER_SCAN_RESPONSE: {
auto response_in =
beerocks_header
->addClass<beerocks_message::cACTION_MONITOR_CHANNEL_SCAN_TRIGGER_SCAN_RESPONSE>();
if (!response_in) {
LOG(ERROR) << "addClass cACTION_MONITOR_CHANNEL_SCAN_TRIGGER_SCAN_RESPONSE failed";
return false;
}

auto response_out = message_com::create_vs_message<
beerocks_message::cACTION_CONTROL_CHANNEL_SCAN_TRIGGER_SCAN_RESPONSE>(cmdu_tx);
if (!response_out) {
LOG(ERROR) << "Failed building cACTION_CONTROL_CHANNEL_SCAN_TRIGGER_SCAN_RESPONSE";
return false;
}

response_out->success() = response_in->success();
send_cmdu_to_controller(cmdu_tx);
break;
}
case beerocks_message::ACTION_MONITOR_CHANNEL_SCAN_TRIGGERED_NOTIFICATION: {
auto notification_in =
beerocks_header
->addClass<beerocks_message::cACTION_MONITOR_CHANNEL_SCAN_TRIGGERED_NOTIFICATION>();
if (!notification_in) {
LOG(ERROR) << "addClass cACTION_MONITOR_CHANNEL_SCAN_TRIGGERED_NOTIFICATION failed";
return false;
}

auto notification_out = message_com::create_vs_message<
beerocks_message::cACTION_CONTROL_CHANNEL_SCAN_TRIGGERED_NOTIFICATION>(cmdu_tx);
if (!notification_out) {
LOG(ERROR) << "Failed building cACTION_CONTROL_CHANNEL_SCAN_TRIGGERED_NOTIFICATION !";
return false;
}

send_cmdu_to_controller(cmdu_tx);
break;
}
case beerocks_message::ACTION_MONITOR_CHANNEL_SCAN_RESULTS_NOTIFICATION: {
auto notification_in =
beerocks_header
->addClass<beerocks_message::cACTION_MONITOR_CHANNEL_SCAN_RESULTS_NOTIFICATION>();
if (!notification_in) {
LOG(ERROR) << "addClass cACTION_MONITOR_CHANNEL_SCAN_RESULTS_NOTIFICATION failed";
return false;
}

auto notification_out = message_com::create_vs_message<
beerocks_message::cACTION_MONITOR_CHANNEL_SCAN_RESULTS_NOTIFICATION>(cmdu_tx);
if (!notification_out) {
LOG(ERROR) << "Failed building cACTION_MONITOR_CHANNEL_SCAN_RESULTS_NOTIFICATION !";
return false;
}

notification_out->scan_results() = notification_in->scan_results();
notification_out->is_dump() = notification_in->is_dump();
tomereli marked this conversation as resolved.
Show resolved Hide resolved

send_cmdu_to_controller(cmdu_tx);
break;
}
case beerocks_message::ACTION_MONITOR_CHANNEL_SCAN_FINISHED_NOTIFICATION: {
auto notification_in =
beerocks_header
->addClass<beerocks_message::cACTION_MONITOR_CHANNEL_SCAN_FINISHED_NOTIFICATION>();
if (!notification_in) {
LOG(ERROR) << "addClass cACTION_MONITOR_CHANNEL_SCAN_FINISHED_NOTIFICATION failed";
return false;
}

auto notification_out = message_com::create_vs_message<
beerocks_message::cACTION_CONTROL_CHANNEL_SCAN_FINISHED_NOTIFICATION>(cmdu_tx);
if (!notification_out) {
LOG(ERROR) << "Failed building cACTION_CONTROL_CHANNEL_SCAN_FINISHED_NOTIFICATION !";
return false;
}

send_cmdu_to_controller(cmdu_tx);
break;
}
case beerocks_message::ACTION_MONITOR_CHANNEL_SCAN_ABORT_NOTIFICATION: {
auto notification_in =
beerocks_header
->addClass<beerocks_message::cACTION_MONITOR_CHANNEL_SCAN_ABORT_NOTIFICATION>();
if (!notification_in) {
LOG(ERROR) << "addClass cACTION_MONITOR_CHANNEL_SCAN_ABORT_NOTIFICATION failed";
return false;
}

auto notification_out = message_com::create_vs_message<
beerocks_message::cACTION_CONTROL_CHANNEL_SCAN_ABORT_NOTIFICATION>(cmdu_tx);
if (!notification_out) {
LOG(ERROR) << "Failed building cACTION_CONTROL_CHANNEL_SCAN_ABORT_NOTIFICATION !";
return false;
}

send_cmdu_to_controller(cmdu_tx);
break;
}
default: {
LOG(ERROR) << "Unknown MONITOR message, action_op: " << int(beerocks_header->action_op());
return false;
Expand Down
Loading