Skip to content

Commit

Permalink
make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
thvdveld committed Mar 18, 2024
1 parent c7629e4 commit b761f58
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 40 deletions.
1 change: 1 addition & 0 deletions src/iface/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub(crate) enum EthernetPacket<'a> {

#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[allow(clippy::large_enum_variant)]
pub(crate) enum Packet<'p> {
#[cfg(feature = "proto-ipv4")]
Ipv4(PacketV4<'p>),
Expand Down
1 change: 1 addition & 0 deletions src/iface/rpl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ pub(crate) struct Dao {
}

impl Dao {
#[allow(clippy::too_many_arguments)]
pub(crate) fn new(
to: Ipv6Address,
child: Ipv6Address,
Expand Down
4 changes: 2 additions & 2 deletions src/iface/rpl/trickle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ mod tests {
}

#[test]
#[allow(clippy::field_reassign_with_default)]
fn trickle_timer_hear_inconsistency() {
let mut rand = Rand::new(1234);
let mut now = Instant::ZERO;
let mut trickle = TrickleTimer::default();

trickle.counter = 1;

while now <= Instant::from_secs(10_000) {
Expand Down Expand Up @@ -251,11 +251,11 @@ mod tests {
}

#[test]
#[allow(clippy::field_reassign_with_default)]
fn trickle_timer_hear_consistency() {
let mut rand = Rand::new(1234);
let mut now = Instant::ZERO;
let mut trickle = TrickleTimer::default();

trickle.counter = 1;

let mut transmit_counter = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/wire/rpl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,8 +913,8 @@ mod tests {
&mut buffer[..repr.buffer_len()],
));
icmp_repr.emit(
&repr.src_addr.into(),
&repr.dst_addr.into(),
&repr.src_addr,
&repr.dst_addr,
&mut Icmpv6Packet::new_unchecked(
&mut buffer[repr.buffer_len()..][..icmp_repr.buffer_len()],
),
Expand Down
2 changes: 1 addition & 1 deletion src/wire/rpl/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ impl<'p> Repr<'p> {
}) => {
packet.clear_rpl_target_flags();
packet.set_rpl_target_prefix_length(*prefix_length);
packet.set_rpl_target_prefix(&prefix);
packet.set_rpl_target_prefix(prefix);
}
Repr::TransitInformation(TransitInformation {
external,
Expand Down
2 changes: 0 additions & 2 deletions src/wire/sixlowpan/iphc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ impl<T: AsRef<[u8]>> Packet<T> {
/// Return the ECN field (when it is inlined).
pub fn ecn_field(&self) -> Option<u8> {
match self.tf_field() {
#[allow(clippy::manual_range_patterns)]
0b00 | 0b01 | 0b10 => {
let start = self.ip_fields_start() as usize;
Some(self.buffer.as_ref()[start..][0] & 0b1100_0000)
Expand Down Expand Up @@ -342,7 +341,6 @@ impl<T: AsRef<[u8]>> Packet<T> {
0,
AddressMode::NotSupported,
))),
#[allow(clippy::manual_range_patterns)]
(1, 1, 0b01 | 0b10 | 0b11) => Ok(UnresolvedAddress::Reserved),
_ => Err(Error),
}
Expand Down
12 changes: 6 additions & 6 deletions tests/rpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ fn message_forwarding_to_root(#[case] mop: RplModeOfOperation) {
// 59 messages. The node is not in range of the destination (which is the root). There is one
// node inbetween that has to forward it. Thus, it is forwarding 59 messages.
let udp_count = sim.msgs().iter().filter(|m| m.is_udp()).count();
assert!(udp_count >= 59 * 2 && udp_count <= 60 * 2);
assert!((118..=120).contains(&udp_count));

for msg in sim.msgs() {
match mop {
Expand Down Expand Up @@ -280,20 +280,20 @@ fn message_forwarding_up_and_down(#[case] mop: RplModeOfOperation) {
assert!(!sim.msgs().is_empty());

let dio_count = sim.msgs().iter().filter(|m| m.is_dio()).count();
assert!(dio_count >= 30 && dio_count <= 40);
assert!((30..=40).contains(&dio_count));

// We transmit a message every 60 seconds. We simulate for 1 hour, so the node will transmit
// 59 messages. The node is not in range of the destination (which is the root). There is one
// node inbetween that has to forward it. Thus, it is forwarding 59 messages.
let udp_count = sim.msgs().iter().filter(|m| m.is_udp()).count();
match mop {
RplModeOfOperation::NoDownwardRoutesMaintained => {
assert!(udp_count >= 14 * 2 && udp_count <= 15 * 2);
assert!((28..=30).contains(&udp_count));
}
RplModeOfOperation::NonStoringMode
| RplModeOfOperation::StoringMode
| RplModeOfOperation::StoringModeWithMulticast => {
assert!(udp_count >= 14 * 4 && udp_count <= 15 * 4);
assert!((52..=60).contains(&udp_count));
}
}

Expand Down Expand Up @@ -403,10 +403,10 @@ fn normal_node_change_parent(#[case] mop: RplModeOfOperation) {
RplModeOfOperation::StoringMode => {
// The node sends a NO-PATH DAO to the parent that forwards it to its own parent
// until it reaches the root, that is why there will be 3 NO-PATH DAOs sent
assert!(no_path_dao_count == 1 * 3,);
assert!(no_path_dao_count == 3);
// NO-PATH DAO should have the ack request flag set to false only when it is sent
// to the old parent
assert!(dao_no_ack_req_count == 1,);
assert!(dao_no_ack_req_count == 1);
assert!(dio_count > 9 && dio_count < 12);
}
// In MOP 1 and MOP 0 there should be no NO-PATH DAOs sent
Expand Down
8 changes: 4 additions & 4 deletions tests/sim/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ impl Message {
return Some(
SixlowpanUdpNhcRepr::parse(
&udp,
&src_addr.into(),
&dst_addr.into(),
&src_addr,
&dst_addr,
&ChecksumCapabilities::ignored(),
)
.unwrap(),
Expand Down Expand Up @@ -97,8 +97,8 @@ impl Message {

return Some(
Icmpv6Repr::parse(
&src_addr.into(),
&dst_addr.into(),
&src_addr,
&dst_addr,
&icmp,
&ChecksumCapabilities::ignored(),
)
Expand Down
36 changes: 13 additions & 23 deletions tests/sim/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ use smoltcp::time::*;
use smoltcp::wire::*;
use std::collections::VecDeque;

type InitFn = Box<dyn Fn(&mut SocketSet<'static>) -> Vec<SocketHandle> + Send + Sync + 'static>;

type AppFn = Box<
dyn Fn(Instant, &mut SocketSet<'static>, &mut Vec<SocketHandle>, &mut Instant)
+ Send
+ Sync
+ 'static,
>;

pub struct Node {
pub id: usize,
pub range: f32,
Expand All @@ -22,16 +31,8 @@ pub struct Node {
pub interface: Interface,
pub sockets: SocketSet<'static>,
pub socket_handles: Vec<SocketHandle>,
pub init:
Option<Box<dyn Fn(&mut SocketSet<'static>) -> Vec<SocketHandle> + Send + Sync + 'static>>,
pub application: Option<
Box<
dyn Fn(Instant, &mut SocketSet<'static>, &mut Vec<SocketHandle>, &mut Instant)
+ Send
+ Sync
+ 'static,
>,
>,
pub init: Option<InitFn>,
pub application: Option<AppFn>,
pub next_poll: Option<Instant>,
}

Expand Down Expand Up @@ -106,22 +107,11 @@ impl Node {
self.device.tx_queue.pop_front()
}

pub fn set_init(
&mut self,
init: Box<dyn Fn(&mut SocketSet) -> Vec<SocketHandle> + Send + Sync>,
) {
pub fn set_init(&mut self, init: InitFn) {
self.init = Some(init);
}

pub fn set_application(
&mut self,
application: Box<
dyn Fn(Instant, &mut SocketSet<'static>, &mut Vec<SocketHandle>, &mut Instant)
+ Send
+ Sync
+ 'static,
>,
) {
pub fn set_application(&mut self, application: AppFn) {
self.application = Some(application);
}
}
Expand Down

0 comments on commit b761f58

Please sign in to comment.