Skip to content

Commit

Permalink
fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tiborschneider committed Mar 24, 2024
1 parent d8763d6 commit 0c68f55
Show file tree
Hide file tree
Showing 23 changed files with 70 additions and 63 deletions.
3 changes: 1 addition & 2 deletions bgpsim-macros/examples/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions bgpsim-web/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
23 changes: 16 additions & 7 deletions bgpsim-web/src/draw/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//! Mapping when displaying TopologyZoo stuff.

use gloo_net::http::Request;
use std::fmt::Write;
use yew::prelude::*;
use yewdux::prelude::*;

Expand Down Expand Up @@ -70,7 +71,7 @@ fn current_lod(bbox: Bbox) -> usize {

#[function_component]
pub fn Lines(props: &Properties) -> Html {
let lines = use_state::<[Option<Vec<(Vec<Point>, Bbox)>>; NUM_LOD], _>(|| Default::default());
let lines = use_state::<[Option<Vec<(Vec<Point>, 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);
Expand Down Expand Up @@ -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! { <path class="stroke-base-4 stroke-2 fill-base-1" {d} /> }
Expand Down
2 changes: 1 addition & 1 deletion bgpsim-web/src/draw/ospf_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();

Expand Down
5 changes: 1 addition & 4 deletions bgpsim-web/src/draw/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions bgpsim-web/src/header/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct Verifier {
skip_update: bool,
}

#[allow(dead_code)]
pub enum Msg {
State(Rc<State>),
StateNet(Rc<Net>),
Expand Down
2 changes: 2 additions & 0 deletions bgpsim-web/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions bgpsim-web/src/net/spring_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ pub fn fruchterman_reingold_fixed<E, Ty: EdgeType>(
// 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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
4 changes: 2 additions & 2 deletions bgpsim-web/src/sidebar/text_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ impl Component for TextField {

fn changed(&mut self, ctx: &Context<Self>, _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;
Expand Down
6 changes: 1 addition & 5 deletions bgpsim/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion bgpsim/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
4 changes: 3 additions & 1 deletion bgpsim/benches/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use bgpsim::prelude::*;

use bgpsim::event::{EventQueue, ModelParams, SimpleTimingModel};
use bgpsim::event::{ModelParams, SimpleTimingModel};

pub fn basic_queue<P: Prefix>() -> BasicEventQueue<P> {
BasicEventQueue::new()
Expand Down Expand Up @@ -59,3 +59,5 @@ fn try_setup_net<P: Prefix, Q: EventQueue<P>>(queue: Q) -> Result<Network<P, Q>,
net.build_advertisements(P::from(0), unique_preferences, 5)?;
Ok(net)
}

fn main() {}
8 changes: 4 additions & 4 deletions bgpsim/benches/roland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*,
Expand Down Expand Up @@ -93,7 +94,7 @@ pub fn compute_sample<Q: EventQueue<P>>(

// 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(),
Expand Down Expand Up @@ -149,8 +150,7 @@ pub fn setup_measure_roland<Q: EventQueue<P> + 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)
Expand Down
1 change: 1 addition & 0 deletions bgpsim/generate_topology_zoo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 1 addition & 4 deletions bgpsim/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion bgpsim/src/event/rand_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions bgpsim/src/export/exabgp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
///
Expand Down
38 changes: 21 additions & 17 deletions bgpsim/src/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl<P: Prefix, Q: EventQueue<P>, Ospf: OspfImpl> InteractiveNetwork<P, Q, Ospf>
/// use bgpsim::interactive::PartialClone;
///
/// // let mut net = ...
/// let original_net = net.clone();
/// let original_net.clone_from(&net);
/// net.withdraw_external_route(ext, prefix)?;

Check failure on line 268 in bgpsim/src/interactive.rs

View workflow job for this annotation

GitHub Actions / Test Suite

expected a pattern, found a method call
/// assert_ne!(net, original_net);
/// let net = unsafe {

Check failure on line 270 in bgpsim/src/interactive.rs

View workflow job for this annotation

GitHub Actions / Test Suite

cannot find value `original_net` in this scope
Expand Down Expand Up @@ -388,28 +388,28 @@ 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
for r in new.external_routers_mut() {
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);
}
}

Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion bgpsim/src/ospf/local/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
5 changes: 4 additions & 1 deletion bgpsim/src/ospf/local/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions bgpsim/src/ospf/local/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

use ordered_float::NotNan;

use crate::event::Event;
use crate::ospf::OspfProcess;
use crate::types::SinglePrefix;

use super::*;
Expand Down
1 change: 0 additions & 1 deletion bgpsim/src/test/test_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ mod t1 {

mod ipv4 {
use super::*;
use crate::bgp::BgpSessionType::{EBgp, IBgpClient, IBgpPeer};
use ipnet::Ipv4Net;

#[test]
Expand Down

0 comments on commit 0c68f55

Please sign in to comment.