Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not send device capabilities change message to NB for unassigned … #97

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 76 additions & 52 deletions src/cgw_connection_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,21 +1114,66 @@ impl CGWConnectionServer {
.create_ifras_list(gid, mac_list.clone(), devices_cache_lock)
.await
{
Ok(()) => {
// All mac's GIDs been successfully changed;
Ok(success_ifras) => {
// Not all mac's GIDs might been successfully changed;
// Notify all of them about the change.
self.clone()
.notify_devices_on_gid_change(mac_list.clone(), gid);
.notify_devices_on_gid_change(success_ifras.clone(), gid);

if let Ok(resp) = cgw_construct_infra_group_device_add_response(
gid, mac_list, uuid, true, None,
gid,
success_ifras.clone(),
uuid,
true,
None,
) {
self.enqueue_mbox_message_from_cgw_to_nb_api(gid, resp);
} else {
error!(
"Failed to construct infra_group_device_add message!"
);
}

let devices_cache_read = self.devices_cache.read().await;
for mac in success_ifras {
if let Some(dev) = devices_cache_read.get_device(&mac) {
if dev.get_device_state()
== CGWDeviceState::CGWDeviceConnected
{
let dev_gid = dev.get_device_group_id();
let changes = cgw_detect_device_chages(
&CGWDeviceCapabilities::default(),
&dev.get_device_capabilities(),
);
match changes {
Some(diff) => {
if let Ok(resp) =
cgw_construct_device_capabilities_changed_msg(
mac,
dev_gid,
&diff,
)
{
self.enqueue_mbox_message_from_cgw_to_nb_api(
dev_gid,
resp,
);
} else {
error!(
"Failed to construct device_capabilities_changed message!"
);
}
}
None => {
debug!(
"Capabilities for device: {} was not changed",
mac.to_hex_string()
)
}
}
}
}
}
}
Err(macs) => {
if let Error::RemoteDiscoveryFailedInfras(mac_addresses) = macs
Expand Down Expand Up @@ -1535,6 +1580,33 @@ impl CGWConnectionServer {

debug!("Detected foreign infra {} connection. Group: {}, Group Shard Owner: {}", device_mac.to_hex_string(), group_id, group_owner_id);
}

let changes =
cgw_detect_device_chages(&device.get_device_capabilities(), &caps);
match changes {
Some(diff) => {
if let Ok(resp) = cgw_construct_device_capabilities_changed_msg(
device_mac,
device.get_device_group_id(),
&diff,
) {
self.enqueue_mbox_message_from_cgw_to_nb_api(
device.get_device_group_id(),
resp,
);
} else {
error!(
"Failed to construct device_capabilities_changed message!"
);
}
}
None => {
debug!(
"Capabilities for device: {} was not changed",
device_mac.to_hex_string()
)
}
}
} else {
if let Ok(resp) = cgw_construct_unassigned_infra_connection_msg(
device_mac,
Expand All @@ -1551,32 +1623,6 @@ impl CGWConnectionServer {
);
}

let changes =
cgw_detect_device_chages(&device.get_device_capabilities(), &caps);
match changes {
Some(diff) => {
if let Ok(resp) = cgw_construct_device_capabilities_changed_msg(
device_mac,
device.get_device_group_id(),
&diff,
) {
self.enqueue_mbox_message_from_cgw_to_nb_api(
device.get_device_group_id(),
resp,
);
} else {
error!(
"Failed to construct device_capabilities_changed message!"
);
}
}
None => {
debug!(
"Capabilities for device: {} was not changed",
device_mac.to_hex_string()
)
}
}
device.update_device_capabilities(&caps);
match serde_json::to_string(device) {
Ok(device_json) => {
Expand All @@ -1593,28 +1639,6 @@ impl CGWConnectionServer {
}
}
} else {
let default_caps: CGWDeviceCapabilities = Default::default();
let changes = cgw_detect_device_chages(&default_caps, &caps);
match changes {
Some(diff) => {
if let Ok(resp) = cgw_construct_device_capabilities_changed_msg(
device_mac, 0, &diff,
) {
self.enqueue_mbox_message_from_cgw_to_nb_api(0, resp);
} else {
error!(
"Failed to construct device_capabilities_changed message!"
);
}
}
None => {
debug!(
"Capabilities for device: {} was not changed",
device_mac.to_hex_string()
)
}
}

let device: CGWDevice = CGWDevice::new(
device_type,
CGWDeviceState::CGWDeviceConnected,
Expand Down
6 changes: 4 additions & 2 deletions src/cgw_remote_discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ impl CGWRemoteDiscovery {
gid: i32,
infras: Vec<MacAddress>,
cache: Arc<RwLock<CGWDevicesCache>>,
) -> Result<()> {
) -> Result<Vec<MacAddress>> {
// TODO: assign list to shards; currently - only created bulk, no assignment
let mut futures = Vec::with_capacity(infras.len());
// Results store vec of MACs we failed to add
Expand All @@ -906,6 +906,7 @@ impl CGWRemoteDiscovery {
return Err(Error::RemoteDiscoveryFailedInfras(infras));
}

let mut success_infras: Vec<MacAddress> = Vec::with_capacity(futures.len());
let mut failed_infras: Vec<MacAddress> = Vec::with_capacity(futures.len());
for x in infras.iter() {
let db_accessor_clone = self.db_accessor.clone();
Expand Down Expand Up @@ -974,6 +975,7 @@ impl CGWRemoteDiscovery {
}
}
}
success_infras.push(device_mac);
assigned_infras_num += 1;
}
}
Expand All @@ -995,7 +997,7 @@ impl CGWRemoteDiscovery {
return Err(Error::RemoteDiscoveryFailedInfras(failed_infras));
}

Ok(())
Ok(success_infras)
}

pub async fn destroy_ifras_list(
Expand Down