Skip to content

Commit

Permalink
Added local CGW id to NB APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
SviatoslavBoichuk committed Nov 8, 2024
1 parent dc471c6 commit 388871d
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 17 deletions.
3 changes: 3 additions & 0 deletions src/cgw_connection_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ impl CGWConnectionProcessor {
*fsm_state = CGWUCentralMessageProcessorState::Idle;
debug!("Got reply event for pending request id: {pending_req_id}");
if let Ok(resp) = cgw_construct_infra_request_result_msg(
self.cgw_server.get_local_id(),
pending_req_uuid,
pending_req_id,
true,
Expand Down Expand Up @@ -595,6 +596,7 @@ impl CGWConnectionProcessor {

for req in flushed_reqs {
if let Ok(resp) = cgw_construct_infra_request_result_msg(
self.cgw_server.get_local_id(),
req.uuid,
req.command.id,
false,
Expand All @@ -620,6 +622,7 @@ impl CGWConnectionProcessor {
.await;
fsm_state = CGWUCentralMessageProcessorState::Idle;
if let Ok(resp) = cgw_construct_infra_request_result_msg(
self.cgw_server.get_local_id(),
pending_req_uuid,
pending_req_id,
false,
Expand Down
84 changes: 68 additions & 16 deletions src/cgw_connection_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ impl CGWConnectionServer {
if let Ok(resp) = cgw_construct_infra_group_create_response(
gid,
String::default(),
self.local_cgw_id,
uuid,
true,
None,
Expand All @@ -813,6 +814,7 @@ impl CGWConnectionServer {
if let Ok(resp) = cgw_construct_infra_group_create_response(
gid,
String::default(),
self.local_cgw_id,
uuid,
false,
Some(format!("Failed to create new group! Error: {e}")),
Expand Down Expand Up @@ -847,6 +849,7 @@ impl CGWConnectionServer {
if let Ok(resp) = cgw_construct_infra_group_create_response(
gid,
String::default(),
self.local_cgw_id,
uuid,
true,
None,
Expand All @@ -864,6 +867,7 @@ impl CGWConnectionServer {
if let Ok(resp) = cgw_construct_infra_group_create_response(
gid,
String::default(),
self.local_cgw_id,
uuid,
false,
Some(format!(
Expand Down Expand Up @@ -918,9 +922,13 @@ impl CGWConnectionServer {
topo_map.remove_gid(gid).await;
}

if let Ok(resp) =
cgw_construct_infra_group_delete_response(gid, uuid, true, None)
{
if let Ok(resp) = cgw_construct_infra_group_delete_response(
gid,
self.local_cgw_id,
uuid,
true,
None,
) {
self.enqueue_mbox_message_from_cgw_to_nb_api(gid, resp);
} else {
error!("Failed to construct infra_group_delete message!");
Expand All @@ -933,6 +941,7 @@ impl CGWConnectionServer {

if let Ok(resp) = cgw_construct_infra_group_delete_response(
gid,
self.local_cgw_id,
uuid,
false,
Some(format!("Failed to delete group! Error: {e}")),
Expand Down Expand Up @@ -987,6 +996,7 @@ impl CGWConnectionServer {
}
None => {
if let Ok(resp) = cgw_construct_infra_enqueue_response(
self.local_cgw_id,
Uuid::default(),
false,
Some(format!(
Expand Down Expand Up @@ -1047,6 +1057,7 @@ impl CGWConnectionServer {
.is_err()
{
if let Ok(resp) = cgw_construct_infra_enqueue_response(
self_clone.local_cgw_id,
Uuid::default(),
false,
Some(format!("Failed to relay MSG stream to remote CGW{cgw_id}")),
Expand Down Expand Up @@ -1102,6 +1113,7 @@ impl CGWConnectionServer {
if let Ok(resp) = cgw_construct_infra_group_infras_add_response(
gid,
mac_list.clone(),
self.local_cgw_id,
uuid,
false,
Some(format!("Failed to add infra list to nonexisting group, gid {gid}, uuid {uuid}")),
Expand All @@ -1127,7 +1139,12 @@ impl CGWConnectionServer {
.notify_devices_on_gid_change(success_ifras.clone(), gid);

if let Ok(resp) = cgw_construct_infra_group_infras_add_response(
gid, mac_list, uuid, true, None,
gid,
mac_list,
self.local_cgw_id,
uuid,
true,
None,
) {
self.enqueue_mbox_message_from_cgw_to_nb_api(gid, resp);
} else {
Expand Down Expand Up @@ -1164,6 +1181,7 @@ impl CGWConnectionServer {
mac,
dev_gid,
&diff,
self.local_cgw_id,
)
{
self.enqueue_mbox_message_from_cgw_to_nb_api(
Expand Down Expand Up @@ -1216,6 +1234,7 @@ impl CGWConnectionServer {
if let Ok(resp) = cgw_construct_infra_group_infras_add_response(
gid,
mac_addresses,
self.local_cgw_id,
uuid,
false,
Some(format!("Failed to create few MACs from infras list (partial create), gid {gid}, uuid {uuid}")),
Expand Down Expand Up @@ -1247,6 +1266,7 @@ impl CGWConnectionServer {
if let Ok(resp) = cgw_construct_infra_group_infras_del_response(
gid,
mac_list.clone(),
self.local_cgw_id,
uuid,
false,
Some(format!("Failed to delete MACs from infra list, gid {gid}, uuid {uuid}: group does not exist")),
Expand Down Expand Up @@ -1276,7 +1296,12 @@ impl CGWConnectionServer {
.notify_devices_on_gid_change(mac_list.clone(), 0i32);

if let Ok(resp) = cgw_construct_infra_group_infras_del_response(
gid, mac_list, uuid, true, None,
gid,
mac_list,
self.local_cgw_id,
uuid,
true,
None,
) {
self.enqueue_mbox_message_from_cgw_to_nb_api(gid, resp);
} else {
Expand Down Expand Up @@ -1307,6 +1332,7 @@ impl CGWConnectionServer {
if let Ok(resp) = cgw_construct_infra_group_infras_del_response(
gid,
mac_addresses,
self.local_cgw_id,
uuid,
false,
Some(format!("Failed to destroy few MACs from infras list (partial delete), gid {gid}, uuid {uuid}")),
Expand Down Expand Up @@ -1341,6 +1367,7 @@ impl CGWConnectionServer {
.is_none()
{
if let Ok(resp) = cgw_construct_infra_enqueue_response(
self.local_cgw_id,
uuid,
false,
Some(format!("Failed to sink down msg to device of nonexisting group, gid {gid}, uuid {uuid}: group does not exist")),
Expand Down Expand Up @@ -1381,9 +1408,10 @@ impl CGWConnectionServer {
Err(e) => {
error!("Failed to validate config message! Invalid configure message for device: {device_mac}!");
if let Ok(resp) = cgw_construct_infra_enqueue_response(
uuid,
false,
Some(format!("Failed to validate config message! Invalid configure message for device: {device_mac}, uuid {uuid}\nError: {e}")),
self.local_cgw_id,
uuid,
false,
Some(format!("Failed to validate config message! Invalid configure message for device: {device_mac}, uuid {uuid}\nError: {e}")),
) {
self.enqueue_mbox_message_from_cgw_to_nb_api(gid, resp);
} else {
Expand Down Expand Up @@ -1412,6 +1440,7 @@ impl CGWConnectionServer {
}
} else {
if let Ok(resp) = cgw_construct_infra_enqueue_response(
self.local_cgw_id,
uuid,
false,
Some(format!("Failed to parse command message to device: {device_mac}, uuid {uuid}")),
Expand All @@ -1432,7 +1461,11 @@ impl CGWConnectionServer {
match self.cgw_remote_discovery.rebalance_all_groups().await {
Ok(groups_res) => {
if let Ok(resp) = cgw_construct_rebalance_group_response(
gid, uuid, true, None,
gid,
self.local_cgw_id,
uuid,
true,
None,
) {
self.enqueue_mbox_message_from_cgw_to_nb_api(gid, resp);
} else {
Expand All @@ -1448,6 +1481,7 @@ impl CGWConnectionServer {

if let Ok(resp) = cgw_construct_rebalance_group_response(
gid,
self.local_cgw_id,
uuid,
false,
Some(format!("Failed to rebalance groups! Error: {e}")),
Expand Down Expand Up @@ -1616,6 +1650,7 @@ impl CGWConnectionServer {
device_mac,
device.get_device_group_id(),
&diff,
self.local_cgw_id,
) {
self.enqueue_mbox_message_from_cgw_to_nb_api(
device.get_device_group_id(),
Expand Down Expand Up @@ -1712,9 +1747,12 @@ impl CGWConnectionServer {
.await;
}

if let Ok(resp) =
cgw_construct_infra_join_msg(device_group_id, device_mac, ip_addr)
{
if let Ok(resp) = cgw_construct_infra_join_msg(
device_group_id,
device_mac,
ip_addr,
self.local_cgw_id,
) {
self.enqueue_mbox_message_from_cgw_to_nb_api(device_group_id, resp);
} else {
error!("Failed to construct device_join message!");
Expand Down Expand Up @@ -1785,7 +1823,11 @@ impl CGWConnectionServer {
.await;
}

if let Ok(resp) = cgw_construct_infra_leave_msg(device_group_id, device_mac) {
if let Ok(resp) = cgw_construct_infra_leave_msg(
device_group_id,
device_mac,
self.local_cgw_id,
) {
self.enqueue_mbox_message_from_cgw_to_nb_api(device_group_id, resp);
} else {
error!("Failed to construct device_leave message!");
Expand Down Expand Up @@ -1867,6 +1909,7 @@ impl CGWConnectionServer {
Ok(replaced_item) => {
if let Some(req) = replaced_item {
if let Ok(resp) = cgw_construct_infra_enqueue_response(
self.local_cgw_id,
req.uuid,
false,
Some("Request replaced with new!".to_string()),
Expand All @@ -1878,9 +1921,12 @@ impl CGWConnectionServer {
}
}
Err(e) => {
if let Ok(resp) =
cgw_construct_infra_enqueue_response(uuid, false, Some(e.to_string()))
{
if let Ok(resp) = cgw_construct_infra_enqueue_response(
self.local_cgw_id,
uuid,
false,
Some(e.to_string()),
) {
self.enqueue_mbox_message_from_cgw_to_nb_api(infra_gid, resp);
} else {
error!("Failed to construct infra_request_result message!");
Expand All @@ -1889,6 +1935,7 @@ impl CGWConnectionServer {
}
} else {
if let Ok(resp) = cgw_construct_infra_enqueue_response(
self.local_cgw_id,
uuid,
false,
Some(format!(
Expand All @@ -1914,6 +1961,7 @@ impl CGWConnectionServer {
for (infra, requests) in failed_requests {
for req in requests {
if let Ok(resp) = cgw_construct_infra_request_result_msg(
self.local_cgw_id,
req.1.uuid,
req.1.command.id,
false,
Expand All @@ -1927,6 +1975,10 @@ impl CGWConnectionServer {
}
}
}

pub fn get_local_id(&self) -> i32 {
self.local_cgw_id
}
}

#[cfg(test)]
Expand Down
Loading

0 comments on commit 388871d

Please sign in to comment.