Skip to content

Commit

Permalink
Small fixes to master only mode and the handling of announce messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidv1992 committed Oct 13, 2023
1 parent bc98f5e commit 1260311
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
5 changes: 4 additions & 1 deletion statime/src/bmc/bmca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl<A: AcceptableMasterList> Bmca<A> {
&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
Expand All @@ -205,6 +205,9 @@ impl<A: AcceptableMasterList> Bmca<A> {
announce_message,
Duration::ZERO,
);
true
} else {
false
}
}

Expand Down
28 changes: 17 additions & 11 deletions statime/src/port/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,16 @@ impl<'a, A: AcceptableMasterList, C: Clock, F: Filter, R: Rng> Port<Running<'a>,
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
Expand Down Expand Up @@ -384,11 +389,12 @@ impl<'a, A, C: Clock, F: Filter, R: Rng> Port<InBmca<'a>, A, R, C, F> {
self.bmca.step_age(step);
}

pub(crate) fn best_local_announce_message(&self) -> Option<BestAnnounceMessage> {
pub(crate) fn best_local_announce_message(&self, global: bool) -> Option<BestAnnounceMessage> {
// 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.
if self.config.master_only {
// 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 && global {
None
} else {
self.lifecycle.local_best
Expand Down Expand Up @@ -724,7 +730,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(true).is_some());
}

#[test]
Expand Down Expand Up @@ -802,6 +808,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(true).is_some());
}
}
4 changes: 2 additions & 2 deletions statime/src/ptp_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(true)),
);

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(false), // erbest
port.state(),
);

Expand Down

0 comments on commit 1260311

Please sign in to comment.