Skip to content

Commit

Permalink
Merge pull request #97 from Telecominfraproject/dev-skip-cap-update-u…
Browse files Browse the repository at this point in the history
…nassigfned-infras

Do not send device capabilities change message to NB for unassigned …
  • Loading branch information
Cahb authored Oct 29, 2024
2 parents 678aa34 + 33d44a2 commit 97281d5
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 54 deletions.
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 @@ -895,7 +895,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 @@ -921,6 +921,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 @@ -989,6 +990,7 @@ impl CGWRemoteDiscovery {
}
}
}
success_infras.push(device_mac);
assigned_infras_num += 1;
}
}
Expand All @@ -1010,7 +1012,7 @@ impl CGWRemoteDiscovery {
return Err(Error::RemoteDiscoveryFailedInfras(failed_infras));
}

Ok(())
Ok(success_infras)
}

pub async fn destroy_ifras_list(
Expand Down

0 comments on commit 97281d5

Please sign in to comment.