From 0c68f557fa026f78237396f8fb4a3e2688d555ec Mon Sep 17 00:00:00 2001 From: Tibor Schneider Date: Sun, 24 Mar 2024 12:43:50 +0100 Subject: [PATCH] fix clippy warnings --- bgpsim-macros/examples/net.rs | 3 +- bgpsim-web/build.rs | 8 ++-- bgpsim-web/src/draw/mapping.rs | 23 +++++++---- bgpsim-web/src/draw/ospf_state.rs | 2 +- bgpsim-web/src/draw/router.rs | 5 +-- bgpsim-web/src/header/verifier.rs | 1 + bgpsim-web/src/main.rs | 2 + bgpsim-web/src/net/spring_layout.rs | 4 +- .../router_cfg/static_route_entry_cfg.rs | 2 +- bgpsim-web/src/sidebar/text_field.rs | 4 +- bgpsim/Cargo.toml | 6 +-- bgpsim/benches/benchmark.rs | 1 - bgpsim/benches/common.rs | 4 +- bgpsim/benches/roland.rs | 8 ++-- bgpsim/generate_topology_zoo.rs | 1 + bgpsim/src/builder.rs | 5 +-- bgpsim/src/event/rand_queue.rs | 2 +- bgpsim/src/export/exabgp.rs | 4 +- bgpsim/src/interactive.rs | 38 ++++++++++--------- bgpsim/src/ospf/local/database.rs | 2 +- bgpsim/src/ospf/local/mod.rs | 5 ++- bgpsim/src/ospf/local/test.rs | 2 - bgpsim/src/test/test_router.rs | 1 - 23 files changed, 70 insertions(+), 63 deletions(-) diff --git a/bgpsim-macros/examples/net.rs b/bgpsim-macros/examples/net.rs index 726e43e..3c315b8 100644 --- a/bgpsim-macros/examples/net.rs +++ b/bgpsim-macros/examples/net.rs @@ -14,10 +14,9 @@ // limitations under the License. use bgpsim::prelude::*; -use bgpsim_macros::*; fn main() { - let (net, ((b0, b1), (e0, e1))) = net! { + let (_net, ((_b0, _b1), (_e0, _e1))) = net! { Prefix = SimplePrefix; links = { b0 -> r0: 1; diff --git a/bgpsim-web/build.rs b/bgpsim-web/build.rs index 03973eb..6c680cf 100644 --- a/bgpsim-web/build.rs +++ b/bgpsim-web/build.rs @@ -101,14 +101,14 @@ fn main() { .open(&path) .unwrap(), ); - write!(&mut f, "const LOD: [f64; {}] = {:?};\n", LOD.len(), LOD).unwrap(); - write!(&mut f, "const INDEX: [Bbox; {}] = [\n", chunks.len()).unwrap(); + writeln!(&mut f, "const LOD: [f64; {}] = {:?};", LOD.len(), LOD).unwrap(); + writeln!(&mut f, "const INDEX: [Bbox; {}] = [", chunks.len()).unwrap(); for chunk in chunks { let min = chunk.bbox.min; let max = chunk.bbox.max; - write!( + writeln!( &mut f, - " Bbox {{ min: Point {{ x: {}f64, y: {}f64 }}, max: Point {{ x: {}f64, y: {}f64 }} }},\n", + " Bbox {{ min: Point {{ x: {}f64, y: {}f64 }}, max: Point {{ x: {}f64, y: {}f64 }} }},", min.x, min.y, max.x, max.y ) .unwrap() diff --git a/bgpsim-web/src/draw/mapping.rs b/bgpsim-web/src/draw/mapping.rs index e0bc450..90c7677 100644 --- a/bgpsim-web/src/draw/mapping.rs +++ b/bgpsim-web/src/draw/mapping.rs @@ -18,6 +18,7 @@ //! Mapping when displaying TopologyZoo stuff. use gloo_net::http::Request; +use std::fmt::Write; use yew::prelude::*; use yewdux::prelude::*; @@ -70,7 +71,7 @@ fn current_lod(bbox: Bbox) -> usize { #[function_component] pub fn Lines(props: &Properties) -> Html { - let lines = use_state::<[Option, Bbox)>>; NUM_LOD], _>(|| Default::default()); + let lines = use_state::<[Option, Bbox)>>; NUM_LOD], _>(Default::default); let dim = use_selector(|net: &Net| net.dim); let screen_bbox = dim.visible_net_bbox(); let shown = props.show && screen_bbox.overlaps(&props.bbox); @@ -101,12 +102,20 @@ pub fn Lines(props: &Properties) -> Html { .map(|(lod_line, _)| { // compute the line let transformed = lod_line.iter().map(|p| dim.get(*p)); - let mut d: String = transformed - .enumerate() - .map(|(i, p)| { - format!("{} {} {} ", if i == 0 { "M" } else { "L" }, p.x(), p.y()) - }) - .collect(); + let mut d: String = + transformed + .enumerate() + .fold(String::new(), |mut s, (i, p)| { + write!( + &mut s, + "{} {} {} ", + if i == 0 { "M" } else { "L" }, + p.x(), + p.y() + ) + .unwrap(); + s + }); // close path in the end d.push('Z'); html! { } diff --git a/bgpsim-web/src/draw/ospf_state.rs b/bgpsim-web/src/draw/ospf_state.rs index c0df71d..5b93356 100644 --- a/bgpsim-web/src/draw/ospf_state.rs +++ b/bgpsim-web/src/draw/ospf_state.rs @@ -137,7 +137,7 @@ fn local_ospf_state(props: &LocalOspfStateProps) -> Html { let areas = router_state .areas() - .map(|a| Some(a)) + .map(Some) .chain(std::iter::once(None)) .collect::>(); diff --git a/bgpsim-web/src/draw/router.rs b/bgpsim-web/src/draw/router.rs index 32a9a27..e0eb34f 100644 --- a/bgpsim-web/src/draw/router.rs +++ b/bgpsim-web/src/draw/router.rs @@ -161,10 +161,7 @@ impl VisualizationState { fn new(id: RouterId, state: &State) -> Self { let mut s = Self { simple: state.features().simple, - glow: match state.hover() { - Hover::Router(r) | Hover::Policy(r, _) if r == id => true, - _ => false, - }, + glow: matches!(state.hover(), Hover::Router(r) | Hover::Policy(r, _) if r == id), ..Self::default() }; match state.selected() { diff --git a/bgpsim-web/src/header/verifier.rs b/bgpsim-web/src/header/verifier.rs index bdf28af..73cf736 100644 --- a/bgpsim-web/src/header/verifier.rs +++ b/bgpsim-web/src/header/verifier.rs @@ -33,6 +33,7 @@ pub struct Verifier { skip_update: bool, } +#[allow(dead_code)] pub enum Msg { State(Rc), StateNet(Rc), diff --git a/bgpsim-web/src/main.rs b/bgpsim-web/src/main.rs index 220d93a..436d0a8 100644 --- a/bgpsim-web/src/main.rs +++ b/bgpsim-web/src/main.rs @@ -16,6 +16,8 @@ // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #![allow(clippy::let_unit_value)] +#![allow(clippy::approx_constant)] +#![allow(clippy::type_complexity)] mod context_menu; mod dim; diff --git a/bgpsim-web/src/net/spring_layout.rs b/bgpsim-web/src/net/spring_layout.rs index 8e40fb6..d6c44cf 100644 --- a/bgpsim-web/src/net/spring_layout.rs +++ b/bgpsim-web/src/net/spring_layout.rs @@ -100,8 +100,8 @@ pub fn fruchterman_reingold_fixed( // force that will be applied to the node let mut force = Vec3::ZERO; - force += fr_get_repulsion(idx, repulsion_factor, &graph); - force += fr_get_attraction(idx, scale, &graph); + force += fr_get_repulsion(idx, repulsion_factor, graph); + force += fr_get_attraction(idx, scale, graph); // apply new location let node = &mut graph[idx]; diff --git a/bgpsim-web/src/sidebar/router_cfg/static_route_entry_cfg.rs b/bgpsim-web/src/sidebar/router_cfg/static_route_entry_cfg.rs index 27ad6ff..276958b 100644 --- a/bgpsim-web/src/sidebar/router_cfg/static_route_entry_cfg.rs +++ b/bgpsim-web/src/sidebar/router_cfg/static_route_entry_cfg.rs @@ -137,7 +137,7 @@ impl Component for StaticRouteEntryCfg { let options = get_available_options(self.net.clone(), ctx.props().router, ctx.props().target); let target = if val && !options.is_empty() { - StaticRoute::Direct(*options.get(0).unwrap()) + StaticRoute::Direct(*options.first().unwrap()) } else { StaticRoute::Drop }; diff --git a/bgpsim-web/src/sidebar/text_field.rs b/bgpsim-web/src/sidebar/text_field.rs index 5fc0367..a91da59 100644 --- a/bgpsim-web/src/sidebar/text_field.rs +++ b/bgpsim-web/src/sidebar/text_field.rs @@ -142,8 +142,8 @@ impl Component for TextField { fn changed(&mut self, ctx: &Context, _old_props: &Self::Properties) -> bool { if self.original_text != ctx.props().text { - self.current_text = ctx.props().text.clone(); - self.original_text = ctx.props().text.clone(); + self.current_text.clone_from(&ctx.props().text); + self.original_text.clone_from(&ctx.props().text); } if self.ignore_changed { self.ignore_changed = false; diff --git a/bgpsim/Cargo.toml b/bgpsim/Cargo.toml index 65e0658..54cd8fb 100644 --- a/bgpsim/Cargo.toml +++ b/bgpsim/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bgpsim" -version = "0.17.2" +version = "0.17.3" edition = "2021" license-file = "LICENSE" description = "A network control-plane simulator" @@ -9,10 +9,6 @@ repository = "https://github.com/nsg-ethz/bgpsim" readme = "../README.md" keywords = ["bgp", "ospf", "routing", "network"] categories = ["simulation"] -exclude = [ - "generate_topology_zoo.rs", - "topology_zoo/*" -] [package.metadata.docs.rs] all-features = true diff --git a/bgpsim/benches/benchmark.rs b/bgpsim/benches/benchmark.rs index f9d298a..baf91ea 100644 --- a/bgpsim/benches/benchmark.rs +++ b/bgpsim/benches/benchmark.rs @@ -16,7 +16,6 @@ use std::time::Duration; use std::time::Instant; -use bgpsim::event::EventQueue; use criterion::black_box; use criterion::{criterion_group, criterion_main, Criterion}; diff --git a/bgpsim/benches/common.rs b/bgpsim/benches/common.rs index 54ad9d8..13f3ae7 100644 --- a/bgpsim/benches/common.rs +++ b/bgpsim/benches/common.rs @@ -17,7 +17,7 @@ use bgpsim::prelude::*; -use bgpsim::event::{EventQueue, ModelParams, SimpleTimingModel}; +use bgpsim::event::{ModelParams, SimpleTimingModel}; pub fn basic_queue() -> BasicEventQueue

{ BasicEventQueue::new() @@ -59,3 +59,5 @@ fn try_setup_net>(queue: Q) -> Result, net.build_advertisements(P::from(0), unique_preferences, 5)?; Ok(net) } + +fn main() {} diff --git a/bgpsim/benches/roland.rs b/bgpsim/benches/roland.rs index 43e787c..f3a5624 100644 --- a/bgpsim/benches/roland.rs +++ b/bgpsim/benches/roland.rs @@ -18,10 +18,11 @@ use std::time::Duration; use std::time::Instant; +use bgpsim::interactive::PartialClone; use bgpsim::record::ConvergenceRecording; +use bgpsim::types::StepUpdate; use bgpsim::{ builder::*, - event::EventQueue, forwarding_state::ForwardingState, policies::{FwPolicy, Policy}, prelude::*, @@ -93,7 +94,7 @@ pub fn compute_sample>( // simulate the event while let Some((step, event)) = t.simulate_step().unwrap() { - if step.changed() { + if let StepUpdate::Single(step) = step { trace.push(( vec![(event.router(), step.old, step.new)], t.queue().get_time().into(), @@ -149,8 +150,7 @@ pub fn setup_measure_roland + std::fmt::Debug + Clone + Partial let start = Instant::now(); fw_state = compute_sample(&mut worker, fw_state, trace, policies); unsafe { - worker = net - .partial_clone() + worker = PartialClone::new(net) .reuse_advertisements(true) .reuse_config(true) .reuse_igp_state(true) diff --git a/bgpsim/generate_topology_zoo.rs b/bgpsim/generate_topology_zoo.rs index 0185988..a1c937c 100644 --- a/bgpsim/generate_topology_zoo.rs +++ b/bgpsim/generate_topology_zoo.rs @@ -193,6 +193,7 @@ fn main() { if let Ok(mut fp) = OpenOptions::new() .write(true) .create(true) + .truncate(true) .open("src/topology_zoo/topos.rs") { write!(fp, "{topos_file}").unwrap(); diff --git a/bgpsim/src/builder.rs b/bgpsim/src/builder.rs index 407970d..d751ec5 100644 --- a/bgpsim/src/builder.rs +++ b/bgpsim/src/builder.rs @@ -23,10 +23,7 @@ use std::{ use itertools::Itertools; #[cfg(feature = "rand")] -use rand::{ - distributions::{Distribution, Uniform}, - prelude::*, -}; +use rand::{distributions::Uniform, prelude::*}; use crate::{ event::EventQueue, diff --git a/bgpsim/src/event/rand_queue.rs b/bgpsim/src/event/rand_queue.rs index fe2f4e9..87b881b 100644 --- a/bgpsim/src/event/rand_queue.rs +++ b/bgpsim/src/event/rand_queue.rs @@ -25,7 +25,7 @@ use itertools::Itertools; use ordered_float::NotNan; use priority_queue::PriorityQueue; use rand::prelude::*; -use rand_distr::{Beta, Distribution}; +use rand_distr::Beta; use serde::{Deserialize, Serialize}; use std::{ cmp::Reverse, diff --git a/bgpsim/src/export/exabgp.rs b/bgpsim/src/export/exabgp.rs index fca4424..74422e7 100644 --- a/bgpsim/src/export/exabgp.rs +++ b/bgpsim/src/export/exabgp.rs @@ -35,11 +35,11 @@ use itertools::Itertools; use maplit::btreemap; /// The python preamble of the runner script (to import time and sleep for 5 seconds) -pub const RUNNER_PREAMBLE: &'static str = +pub const RUNNER_PREAMBLE: &str = "#!/usr/bin/env python3\n\nimport sys\nimport time\n\n\ntime.sleep(5)\n\n"; /// The python preamble of the runner script (to import time and sleep for 5 seconds) -pub const RUNNER_POSTAMBLE: &'static str = "\nwhile True:\n time.sleep(1)\n"; +pub const RUNNER_POSTAMBLE: &str = "\nwhile True:\n time.sleep(1)\n"; /// Config generator for [ExaBGP](https://github.com/Exa-Networks/exabgp) /// diff --git a/bgpsim/src/interactive.rs b/bgpsim/src/interactive.rs index 700407a..91c86ce 100644 --- a/bgpsim/src/interactive.rs +++ b/bgpsim/src/interactive.rs @@ -264,7 +264,7 @@ impl, Ospf: OspfImpl> InteractiveNetwork /// use bgpsim::interactive::PartialClone; /// /// // let mut net = ... -/// let original_net = net.clone(); +/// let original_net.clone_from(&net); /// net.withdraw_external_route(ext, prefix)?; /// assert_ne!(net, original_net); /// let net = unsafe { @@ -388,17 +388,17 @@ impl<'a, P: Prefix, Q> PartialClone<'a, P, Q> { // clone new.net if the configuration is different if !self.reuse_config { - new.ospf = source.ospf.clone(); + new.ospf.clone_from(&source.ospf); } if !self.reuse_advertisements { - new.known_prefixes = source.known_prefixes.clone(); + new.known_prefixes.clone_from(&source.known_prefixes); } if self.reuse_queue_params { new.queue = source.queue.clone_events(new.queue); } else { - new.queue = source.queue.clone(); + new.queue.clone_from(&source.queue); } // handle all external routers @@ -406,10 +406,10 @@ impl<'a, P: Prefix, Q> PartialClone<'a, P, Q> { let id = r.router_id(); let r_source = source.get_device(id).unwrap().external_or_err().unwrap(); if !self.reuse_config { - r.neighbors = r_source.neighbors.clone(); + r.neighbors.clone_from(&r_source.neighbors); } if !self.reuse_advertisements { - r.active_routes = r_source.active_routes.clone(); + r.active_routes.clone_from(&r_source.active_routes); } } @@ -420,23 +420,27 @@ impl<'a, P: Prefix, Q> PartialClone<'a, P, Q> { if !self.reuse_config { r.do_load_balancing = r_source.do_load_balancing; - r.ospf.neighbors = r_source.ospf.neighbors.clone(); - r.sr = r_source.sr.clone(); - r.bgp.sessions = r_source.bgp.sessions.clone(); - r.bgp.sessions = r_source.bgp.sessions.clone(); - r.bgp.route_maps_in = r_source.bgp.route_maps_in.clone(); - r.bgp.route_maps_out = r_source.bgp.route_maps_out.clone(); + r.ospf.neighbors.clone_from(&r_source.ospf.neighbors); + r.sr.clone_from(&r_source.sr); + r.bgp.sessions.clone_from(&r_source.bgp.sessions); + r.bgp.sessions.clone_from(&r_source.bgp.sessions); + r.bgp.route_maps_in.clone_from(&r_source.bgp.route_maps_in); + r.bgp + .route_maps_out + .clone_from(&r_source.bgp.route_maps_out); } if !self.reuse_igp_state { - r.ospf.ospf_table = r_source.ospf.ospf_table.clone(); + r.ospf.ospf_table.clone_from(&r_source.ospf.ospf_table); } if !self.reuse_bgp_state { - r.bgp.rib_in = r_source.bgp.rib_in.clone(); - r.bgp.rib = r_source.bgp.rib.clone(); - r.bgp.rib_out = r_source.bgp.rib_out.clone(); - r.bgp.known_prefixes = r_source.bgp.known_prefixes.clone(); + r.bgp.rib_in.clone_from(&r_source.bgp.rib_in); + r.bgp.rib.clone_from(&r_source.bgp.rib); + r.bgp.rib_out.clone_from(&r_source.bgp.rib_out); + r.bgp + .known_prefixes + .clone_from(&r_source.bgp.known_prefixes); } } diff --git a/bgpsim/src/ospf/local/database.rs b/bgpsim/src/ospf/local/database.rs index b5924db..74d72b6 100644 --- a/bgpsim/src/ospf/local/database.rs +++ b/bgpsim/src/ospf/local/database.rs @@ -697,7 +697,7 @@ impl OspfRibEntry { } // The new path is better. Replace it. Ordering::Greater => { - self.fibs = path.fibs.clone(); + self.fibs.clone_from(&path.fibs); self.cost = path.cost; self.inter_area = path.inter_area; self.keys = btreemap! {Some(area) => path.key}; diff --git a/bgpsim/src/ospf/local/mod.rs b/bgpsim/src/ospf/local/mod.rs index b99c1d5..412f20b 100644 --- a/bgpsim/src/ospf/local/mod.rs +++ b/bgpsim/src/ospf/local/mod.rs @@ -199,7 +199,10 @@ impl OspfImpl for LocalOspf { } // add the external-lsas - local_p.areas.external_lsas = global_coordinator.external_lsas.clone(); + local_p + .areas + .external_lsas + .clone_from(&global_coordinator.external_lsas); // set the RIB. local_p.areas.rib = global_coordinator.ribs.remove(&router).unwrap_or_default(); diff --git a/bgpsim/src/ospf/local/test.rs b/bgpsim/src/ospf/local/test.rs index e4b7d8c..f6643df 100644 --- a/bgpsim/src/ospf/local/test.rs +++ b/bgpsim/src/ospf/local/test.rs @@ -17,8 +17,6 @@ use ordered_float::NotNan; -use crate::event::Event; -use crate::ospf::OspfProcess; use crate::types::SinglePrefix; use super::*; diff --git a/bgpsim/src/test/test_router.rs b/bgpsim/src/test/test_router.rs index a5aabd7..c823b3c 100644 --- a/bgpsim/src/test/test_router.rs +++ b/bgpsim/src/test/test_router.rs @@ -463,7 +463,6 @@ mod t1 { mod ipv4 { use super::*; - use crate::bgp::BgpSessionType::{EBgp, IBgpClient, IBgpPeer}; use ipnet::Ipv4Net; #[test]