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 authored and folkertdev committed Oct 25, 2023
1 parent ee81157 commit 5c1ab0f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 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
34 changes: 24 additions & 10 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,17 +389,26 @@ 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_for_bmca(&self) -> 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.
// 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 {
self.lifecycle.local_best
}
}

pub(crate) fn best_local_announce_message_for_state(&self) -> Option<BestAnnounceMessage> {
// 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,
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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());
}
}
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_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(),
);

Expand Down

0 comments on commit 5c1ab0f

Please sign in to comment.