diff --git a/CHANGELOG.md b/CHANGELOG.md index 844509ef..ee410771 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Size of data packets is limited to 65535 bytes. +- Update interval is now expressed as centiseconds, in accordance with the babel + RFC. ### Fixed diff --git a/src/babel.rs b/src/babel.rs index 98aa041f..d778488e 100644 --- a/src/babel.rs +++ b/src/babel.rs @@ -184,7 +184,7 @@ impl Encoder for Codec { #[cfg(test)] mod tests { - use std::net::Ipv6Addr; + use std::{net::Ipv6Addr, time::Duration}; use futures::{SinkExt, StreamExt}; use tokio_util::codec::Framed; @@ -238,7 +238,7 @@ mod tests { let mut receiver = Framed::new(rx, super::Codec::new()); let update = super::Update::new( - 400, + Duration::from_secs(400), 16.into(), 25.into(), Subnet::new(Ipv6Addr::new(0x400, 1, 2, 3, 0, 0, 0, 0).into(), 64) diff --git a/src/babel/update.rs b/src/babel/update.rs index 71a97b46..8d89ec11 100644 --- a/src/babel/update.rs +++ b/src/babel/update.rs @@ -1,6 +1,9 @@ //! The babel [Update TLV](https://datatracker.ietf.org/doc/html/rfc8966#name-update). -use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; +use std::{ + net::{IpAddr, Ipv4Addr, Ipv6Addr}, + time::Duration, +}; use bytes::{Buf, BufMut}; use log::trace; @@ -43,16 +46,17 @@ pub struct Update { impl Update { /// Create a new `Update`. pub fn new( - interval: u16, + interval: Duration, seqno: SeqNo, metric: Metric, subnet: Subnet, router_id: RouterId, ) -> Self { + let interval_centiseconds = (interval.as_millis() / 10) as u16; Self { // No flags used for now flags: 0, - interval, + interval: interval_centiseconds, seqno, metric, subnet, @@ -191,7 +195,10 @@ impl Update { #[cfg(test)] mod tests { - use std::net::{Ipv4Addr, Ipv6Addr}; + use std::{ + net::{Ipv4Addr, Ipv6Addr}, + time::Duration, + }; use crate::{router_id::RouterId, subnet::Subnet}; use bytes::Buf; @@ -352,7 +359,7 @@ mod tests { let mut buf = bytes::BytesMut::new(); let hello_src = super::Update::new( - 64, + Duration::from_secs(64), 10.into(), 25.into(), Subnet::new( diff --git a/src/packet/control.rs b/src/packet/control.rs index 65a3352b..d35ca3d4 100644 --- a/src/packet/control.rs +++ b/src/packet/control.rs @@ -1,4 +1,4 @@ -use std::{io, net::IpAddr}; +use std::{io, net::IpAddr, time::Duration}; use bytes::BytesMut; use tokio_util::codec::{Decoder, Encoder}; @@ -27,7 +27,7 @@ impl ControlPacket { } pub fn new_update( - interval: u16, + interval: Duration, seqno: SeqNo, metric: Metric, subnet: Subnet, diff --git a/src/router.rs b/src/router.rs index e0e61203..a355f7d5 100644 --- a/src/router.rs +++ b/src/router.rs @@ -33,9 +33,9 @@ const HELLO_INTERVAL: u16 = 20; const IHU_INTERVAL: u16 = HELLO_INTERVAL * 3; /// Base time used in UPDATE packets. For local (static) routes this is the timeout they are /// advertised with. -const UPDATE_INTERVAL: u16 = HELLO_INTERVAL * 3; +const UPDATE_INTERVAL: Duration = Duration::from_secs(HELLO_INTERVAL as u64 * 3); /// Time between route table dumps to peers. -const ROUTE_PROPAGATION_INTERVAL: Duration = Duration::from_secs(UPDATE_INTERVAL as u64); +const ROUTE_PROPAGATION_INTERVAL: Duration = UPDATE_INTERVAL; /// Amount of seconds that can elapse before we consider a [`Peer`] as dead from the routers POV. /// Since IHU's are sent in response to HELLO packets, this MUST be greater than the /// [`HELLO_INTERVAL`].