From 5c1ab0f9656838dcc9e151ca33757e41a4183281 Mon Sep 17 00:00:00 2001 From: David Venhoek Date: Fri, 13 Oct 2023 15:45:10 +0200 Subject: [PATCH] Small fixes to master only mode and the handling of announce messages. --- statime/src/bmc/bmca.rs | 5 ++++- statime/src/port/mod.rs | 34 ++++++++++++++++++++++++---------- statime/src/ptp_instance.rs | 4 ++-- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/statime/src/bmc/bmca.rs b/statime/src/bmc/bmca.rs index dcf4508db..802e36b31 100644 --- a/statime/src/bmc/bmca.rs +++ b/statime/src/bmc/bmca.rs @@ -193,7 +193,7 @@ impl Bmca { &mut self, header: &Header, announce_message: &AnnounceMessage, - ) { + ) -> bool { // Ignore messages comming from the same port if announce_message.header.source_port_identity != self.own_port_identity && self @@ -205,6 +205,9 @@ impl Bmca { announce_message, Duration::ZERO, ); + true + } else { + false } } diff --git a/statime/src/port/mod.rs b/statime/src/port/mod.rs index 4e6187dde..580e6c81e 100644 --- a/statime/src/port/mod.rs +++ b/statime/src/port/mod.rs @@ -309,11 +309,16 @@ impl<'a, A: AcceptableMasterList, C: Clock, F: Filter, R: Rng> Port, fn handle_general_internal(&mut self, message: Message<'_>) -> PortActionIterator<'_> { match message.body { MessageBody::Announce(announce) => { - self.bmca - .register_announce_message(&message.header, &announce); - actions![PortAction::ResetAnnounceReceiptTimer { - duration: self.config.announce_duration(&mut self.rng), - }] + if self + .bmca + .register_announce_message(&message.header, &announce) + { + actions![PortAction::ResetAnnounceReceiptTimer { + duration: self.config.announce_duration(&mut self.rng), + }] + } else { + actions![] + } } _ => { self.port_state @@ -384,10 +389,11 @@ impl<'a, A, C: Clock, F: Filter, R: Rng> Port, A, R, C, F> { self.bmca.step_age(step); } - pub(crate) fn best_local_announce_message(&self) -> Option { + pub(crate) fn best_local_announce_message_for_bmca(&self) -> Option { // Announce messages received on a masterOnly PTP Port shall not be considered - // in the operation of the best master clock algorithm or in the update - // of data sets. + // in the global operation of the best master clock algorithm or in the update + // of data sets. We still need them during the calculation of the recommended + // port state though to avoid getting multiple masters in the segment. if self.config.master_only { None } else { @@ -395,6 +401,14 @@ impl<'a, A, C: Clock, F: Filter, R: Rng> Port, A, R, C, F> { } } + pub(crate) fn best_local_announce_message_for_state(&self) -> Option { + // Announce messages received on a masterOnly PTP Port shall not be considered + // in the global operation of the best master clock algorithm or in the update + // of data sets. We still need them during the calculation of the recommended + // port state though to avoid getting multiple masters in the segment. + self.lifecycle.local_best + } + pub(crate) fn set_recommended_state( &mut self, recommended_state: RecommendedState, @@ -724,7 +738,7 @@ mod tests { let mut port = port.start_bmca(); port.calculate_best_local_announce_message(); - assert!(port.best_local_announce_message().is_some()); + assert!(port.best_local_announce_message_for_bmca().is_some()); } #[test] @@ -802,6 +816,6 @@ mod tests { let mut port = port.start_bmca(); port.calculate_best_local_announce_message(); - assert!(port.best_local_announce_message().is_some()); + assert!(port.best_local_announce_message_for_bmca().is_some()); } } diff --git a/statime/src/ptp_instance.rs b/statime/src/ptp_instance.rs index de560d457..15200131a 100644 --- a/statime/src/ptp_instance.rs +++ b/statime/src/ptp_instance.rs @@ -91,14 +91,14 @@ impl PtpInstanceState { let ebest = Bmca::<()>::find_best_announce_message( ports .iter() - .filter_map(|port| port.best_local_announce_message()), + .filter_map(|port| port.best_local_announce_message_for_bmca()), ); for port in ports.iter_mut() { let recommended_state = Bmca::<()>::calculate_recommended_state( &self.default_ds, ebest, - port.best_local_announce_message(), // erbest + port.best_local_announce_message_for_state(), // erbest port.state(), );