Skip to content

Commit 0e172f0

Browse files
committed
NOC: Send an ACK up-front since NOC operations take longer time
Ack the other end while we are processing stuff, so it doesn't bombard us with retransmissions
1 parent f5837b4 commit 0e172f0

File tree

6 files changed

+36
-12
lines changed

6 files changed

+36
-12
lines changed

matter/src/data_model/sdm/noc.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::interaction_model::messages::ib;
3030
use crate::tlv::{FromTLV, OctetStr, TLVElement, TLVWriter, TagType, ToTLV, UtfStr};
3131
use crate::transport::session::SessionMode;
3232
use crate::utils::writebuf::WriteBuf;
33-
use crate::{cmd_enter, error::*};
33+
use crate::{cmd_enter, error::*, secure_channel};
3434
use log::{error, info};
3535
use num_derive::FromPrimitive;
3636

@@ -177,6 +177,15 @@ impl NocCluster {
177177
return Err(NocStatus::InsufficientPrivlege);
178178
}
179179

180+
// This command's processing may take longer, send a stand alone ACK to the peer to avoid any retranmissions
181+
let ack_send = secure_channel::common::send_mrp_standalone_ack(
182+
cmd_req.trans.exch,
183+
cmd_req.trans.session,
184+
);
185+
if ack_send.is_err() {
186+
error!("Error sending Standalone ACK, falling back to piggybacked ACK");
187+
}
188+
180189
let r = AddNocReq::from_tlv(&cmd_req.data).map_err(|_| NocStatus::InvalidNOC)?;
181190

182191
let noc_value = Cert::new(r.noc_value.0).map_err(|_| NocStatus::InvalidNOC)?;
@@ -188,7 +197,6 @@ impl NocCluster {
188197
} else {
189198
None
190199
};
191-
192200
let fabric = Fabric::new(
193201
noc_data.key_pair,
194202
noc_data.root_ca,

matter/src/interaction_model/command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ macro_rules! cmd_enter {
3737
}};
3838
}
3939

40-
pub struct CommandReq<'a, 'b, 'c, 'd> {
40+
pub struct CommandReq<'a, 'b, 'c, 'd, 'e> {
4141
pub cmd: ib::CmdPath,
4242
pub data: TLVElement<'a>,
4343
pub resp: &'a mut TLVWriter<'b, 'c>,
44-
pub trans: &'a mut Transaction<'d>,
44+
pub trans: &'a mut Transaction<'d, 'e>,
4545
}
4646

4747
impl InteractionModel {

matter/src/interaction_model/core.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::{
2525
exchange::Exchange,
2626
packet::Packet,
2727
proto_demux::{self, ProtoCtx, ResponseRequired},
28-
session::Session,
28+
session::SessionHandle,
2929
},
3030
};
3131
use colored::Colorize;
@@ -59,8 +59,8 @@ pub enum OpCode {
5959
TimedRequest = 10,
6060
}
6161

62-
impl<'a> Transaction<'a> {
63-
pub fn new(session: &'a mut Session, exch: &'a mut Exchange) -> Self {
62+
impl<'a, 'b> Transaction<'a, 'b> {
63+
pub fn new(session: &'a mut SessionHandle<'b>, exch: &'a mut Exchange) -> Self {
6464
Self {
6565
state: TransactionState::Ongoing,
6666
session,

matter/src/interaction_model/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use crate::{
1919
error::Error,
2020
tlv::TLVWriter,
21-
transport::{exchange::Exchange, proto_demux::ResponseRequired, session::Session},
21+
transport::{exchange::Exchange, proto_demux::ResponseRequired, session::SessionHandle},
2222
};
2323

2424
use self::{
@@ -32,9 +32,9 @@ pub enum TransactionState {
3232
Complete,
3333
Terminate,
3434
}
35-
pub struct Transaction<'a> {
35+
pub struct Transaction<'a, 'b> {
3636
pub state: TransactionState,
37-
pub session: &'a mut Session,
37+
pub session: &'a mut SessionHandle<'b>,
3838
pub exch: &'a mut Exchange,
3939
}
4040

matter/src/secure_channel/common.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,18 @@
1515
* limitations under the License.
1616
*/
1717

18+
use boxslab::Slab;
19+
use log::info;
1820
use num_derive::FromPrimitive;
1921

20-
use crate::{error::Error, transport::packet::Packet};
22+
use crate::{
23+
error::Error,
24+
transport::{
25+
exchange::Exchange,
26+
packet::{Packet, PacketPool},
27+
session::SessionHandle,
28+
},
29+
};
2130

2231
use super::status_report::{create_status_report, GeneralCode};
2332

@@ -83,3 +92,10 @@ pub fn create_mrp_standalone_ack(proto_tx: &mut Packet) {
8392
proto_tx.set_proto_opcode(OpCode::MRPStandAloneAck as u8);
8493
proto_tx.unset_reliable();
8594
}
95+
96+
pub fn send_mrp_standalone_ack(exch: &mut Exchange, sess: &mut SessionHandle) -> Result<(), Error> {
97+
info!("Sending standalone ACK");
98+
let mut ack_packet = Slab::<PacketPool>::try_new(Packet::new_tx()?).ok_or(Error::NoMemory)?;
99+
create_mrp_standalone_ack(&mut ack_packet);
100+
exch.send(ack_packet, sess)
101+
}

matter/src/transport/exchange.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl Exchange {
175175
}
176176
}
177177

178-
fn send(
178+
pub fn send(
179179
&mut self,
180180
mut proto_tx: BoxSlab<PacketPool>,
181181
session: &mut SessionHandle,

0 commit comments

Comments
 (0)