Skip to content

Commit

Permalink
Express update interval as centiseconds
Browse files Browse the repository at this point in the history
Closes #175

Signed-off-by: Lee Smet <[email protected]>
  • Loading branch information
LeeSmet committed Mar 26, 2024
1 parent 6ecb376 commit 96eaa67
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/babel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl Encoder<Tlv> 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;
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 12 additions & 5 deletions src/babel/update.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/packet/control.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -27,7 +27,7 @@ impl ControlPacket {
}

pub fn new_update(
interval: u16,
interval: Duration,
seqno: SeqNo,
metric: Metric,
subnet: Subnet,
Expand Down
4 changes: 2 additions & 2 deletions src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
Expand Down

0 comments on commit 96eaa67

Please sign in to comment.