diff --git a/.rustfmt.toml b/.rustfmt.toml index 60a370b..8a0aff3 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,2 +1,7 @@ -edition = "2021" +# --------------------------------------------------------------------------- +# Stable features that we customize locally +# --------------------------------------------------------------------------- max_width = 80 +use_small_heuristics = "max" +edition = "2024" +style_edition = "2024" diff --git a/aal/src/lib.rs b/aal/src/lib.rs index eec2c41..1d06f67 100644 --- a/aal/src/lib.rs +++ b/aal/src/lib.rs @@ -295,9 +295,15 @@ pub trait TableOps { #[derive(Clone, Copy, Debug)] pub enum PortUpdate { /// Signal that a port's "enable" state has changed - Enable { asic_port_id: AsicId, enabled: bool }, + Enable { + asic_port_id: AsicId, + enabled: bool, + }, /// Signal that the linkup/linkdown state of a port has changed - LinkUp { asic_port_id: AsicId, linkup: bool }, + LinkUp { + asic_port_id: AsicId, + linkup: bool, + }, /// Signal that the port has transitioned from one state to another in the AN/LT finite state /// machine FSM { diff --git a/aal/src/match_action.rs b/aal/src/match_action.rs index 1dc54e6..c2b5523 100644 --- a/aal/src/match_action.rs +++ b/aal/src/match_action.rs @@ -178,10 +178,7 @@ macro_rules! unwrap_value_entry { impl From for MatchLpm { fn from(cidr: Ipv6Net) -> Self { let v: u128 = cidr.addr().into(); - MatchLpm { - prefix: v.into(), - len: cidr.width() as u16, - } + MatchLpm { prefix: v.into(), len: cidr.width() as u16 } } } @@ -208,10 +205,7 @@ unwrap_lpm_entry!(Ipv6Net); impl From for MatchLpm { fn from(cidr: Ipv4Net) -> Self { let v: u32 = cidr.addr().into(); - MatchLpm { - prefix: v.into(), - len: cidr.width() as u16, - } + MatchLpm { prefix: v.into(), len: cidr.width() as u16 } } } diff --git a/aal_macros/src/lib.rs b/aal_macros/src/lib.rs index 230a374..198f824 100644 --- a/aal_macros/src/lib.rs +++ b/aal_macros/src/lib.rs @@ -380,11 +380,7 @@ fn get_fields<'a>( None => name.to_string(), }; - fields.push(FieldInfo { - name, - field_name, - match_type, - }); + fields.push(FieldInfo { name, field_name, match_type }); } Ok(fields) @@ -436,11 +432,7 @@ fn get_actions<'a>( }; let action_args = get_action_args(v)?; - actions.push(Action { - name, - action_name, - action_args, - }); + actions.push(Action { name, action_name, action_args }); } Ok(actions) diff --git a/asic/src/chaos/mod.rs b/asic/src/chaos/mod.rs index f943d93..eed7817 100644 --- a/asic/src/chaos/mod.rs +++ b/asic/src/chaos/mod.rs @@ -320,10 +320,7 @@ impl Handle { /// `Chaos` member of [`AsicConfig`]. The `handle` is a [`Handle`] object. macro_rules! unfurl { ($handle:ident, $name:ident) => { - $handle - .config - .$name - .unfurled(&$handle.log, stringify!($name))? + $handle.config.$name.unfurled(&$handle.log, stringify!($name))? }; } pub(crate) use unfurl; @@ -332,10 +329,7 @@ pub(crate) use unfurl; /// `TableChaos` member of [`AsicConfig`]. The `handle` is a [`Handle`] object. macro_rules! table_unfurl { ($handle:ident, $id: expr, $name:ident) => { - $handle - .config - .$name - .unfurled(&$handle.log, $id, stringify!($name))? + $handle.config.$name.unfurled(&$handle.log, $id, stringify!($name))? }; } pub(crate) use table_unfurl; diff --git a/asic/src/chaos/table.rs b/asic/src/chaos/table.rs index 08acb4f..c7df523 100644 --- a/asic/src/chaos/table.rs +++ b/asic/src/chaos/table.rs @@ -56,10 +56,7 @@ pub struct Table { impl TableOps for Table { fn new(hdl: &Handle, name: &str) -> AsicResult { table_unfurl!(hdl, name, table_new); - Ok(Table { - name: name.into(), - keys: Mutex::new(HashSet::new()), - }) + Ok(Table { name: name.into(), keys: Mutex::new(HashSet::new()) }) } fn size(&self) -> usize { diff --git a/asic/src/lib.rs b/asic/src/lib.rs index 93aad08..db03e5c 100644 --- a/asic/src/lib.rs +++ b/asic/src/lib.rs @@ -100,10 +100,7 @@ impl FsmStats { /// Increases the counter for a single state by 1. pub fn bump(&mut self, state: PortFsmState) { - self.0 - .entry(state) - .and_modify(|count| *count += 1) - .or_insert(1); + self.0.entry(state).and_modify(|count| *count += 1).or_insert(1); } /// Returns the full set of possible states, giving the caller an easy way diff --git a/asic/src/softnpu/mgmt.rs b/asic/src/softnpu/mgmt.rs index aeb6ab1..1f5805f 100644 --- a/asic/src/softnpu/mgmt.rs +++ b/asic/src/softnpu/mgmt.rs @@ -88,11 +88,8 @@ fn write_uds(msg: ManagementRequest, socket_path: &str) { } fn read_uart(msg: ManagementRequest) -> String { - let mut f = OpenOptions::new() - .read(true) - .write(true) - .open(SOFTNPU_TTY) - .unwrap(); + let mut f = + OpenOptions::new().read(true).write(true).open(SOFTNPU_TTY).unwrap(); let mut buf = Vec::new(); buf.push(MANAGEMENT_MESSAGE_PREAMBLE); diff --git a/asic/src/softnpu/mod.rs b/asic/src/softnpu/mod.rs index cd980b4..5274d83 100644 --- a/asic/src/softnpu/mod.rs +++ b/asic/src/softnpu/mod.rs @@ -112,9 +112,9 @@ impl Handle { let mgmt_config = match config.softnpu_management { mgmt::SoftnpuManagement::UART => mgmt::ManagementConfig::UART, mgmt::SoftnpuManagement::UDS => match &config.uds_path { - Some(s) => mgmt::ManagementConfig::UDS { - socket_path: s.to_string(), - }, + Some(s) => { + mgmt::ManagementConfig::UDS { socket_path: s.to_string() } + } None => { return Err(AsicError::InvalidArg( "softnpu unix domain socket missing".to_string(), @@ -198,14 +198,9 @@ impl AsicOps for Handle { // When a port is enabled in softnpu, it automatically comes online. // When switching between enabled and disabled, we send the main body // of dpd the PortUpdate events we would expect to see on real hardware. - let present = PortUpdate::Presence { - asic_port_id, - presence: enabled, - }; - let ena = PortUpdate::Enable { - asic_port_id, - enabled, - }; + let present = + PortUpdate::Presence { asic_port_id, presence: enabled }; + let ena = PortUpdate::Enable { asic_port_id, enabled }; let fsm_state = match enabled { false => PortFsmState::Idle, true => PortFsmState::LinkUp, @@ -215,10 +210,7 @@ impl AsicOps for Handle { fsm: FsmType::Port.into(), state: fsm_state.into(), }; - let link = PortUpdate::LinkUp { - asic_port_id, - linkup: enabled, - }; + let link = PortUpdate::LinkUp { asic_port_id, linkup: enabled }; for event in &[present, ena, fsm, link] { if let Err(e) = tx.send(*event) { @@ -296,13 +288,7 @@ impl AsicOps for Handle { "Port {port_hdl:?} exists" ))); } - ports.insert( - port_hdl, - Port { - enabled: true, - tx_eq: 0, - }, - ); + ports.insert(port_hdl, Port { enabled: true, tx_eq: 0 }); self.port_to_asic_id(port_hdl).map(|id| (port_hdl, id)) } diff --git a/asic/src/softnpu/table.rs b/asic/src/softnpu/table.rs index 3f8a23e..69eea0e 100644 --- a/asic/src/softnpu/table.rs +++ b/asic/src/softnpu/table.rs @@ -104,11 +104,7 @@ impl TableOps for Table { } }; - Ok(Table { - id, - dpd_id, - size: TABLE_SIZE, - }) + Ok(Table { id, dpd_id, size: TABLE_SIZE }) } fn size(&self) -> usize { diff --git a/asic/src/tofino_asic/bf_wrapper.rs b/asic/src/tofino_asic/bf_wrapper.rs index 3a52b4d..c4a7d57 100644 --- a/asic/src/tofino_asic/bf_wrapper.rs +++ b/asic/src/tofino_asic/bf_wrapper.rs @@ -165,8 +165,7 @@ fn sanitize_dev_port( if dev_id != DEVICE_ID { Err(format!("invalid device id: {dev_id}")) } else { - port.try_into() - .map_err(|_| format!("invalid asic id: {port}")) + port.try_into().map_err(|_| format!("invalid asic id: {port}")) } } @@ -205,10 +204,7 @@ extern "C" fn port_admin_state_cb( }; send_port_update( "port_admin_state_cb()", - PortUpdate::Enable { - asic_port_id, - enabled, - }, + PortUpdate::Enable { asic_port_id, enabled }, ); BF_SUCCESS } @@ -229,10 +225,7 @@ extern "C" fn port_status_int_cb( }; send_port_update( "port_status_int_cb()", - PortUpdate::LinkUp { - asic_port_id, - linkup, - }, + PortUpdate::LinkUp { asic_port_id, linkup }, ); BF_SUCCESS } @@ -254,10 +247,7 @@ extern "C" fn port_presence_cb( send_port_update( "port_presence_cb()", - PortUpdate::Presence { - asic_port_id, - presence, - }, + PortUpdate::Presence { asic_port_id, presence }, ); BF_SUCCESS } @@ -373,10 +363,7 @@ pub fn bf_init( let log = log.new(o!("unit" => "callback")); assert!(cb.is_none()); - *cb = Some(CallbackState { - log, - update_tx: None, - }); + *cb = Some(CallbackState { log, update_tx: None }); } let devpath = bf_driver_path(devpath)?; diff --git a/asic/src/tofino_asic/link_fsm.rs b/asic/src/tofino_asic/link_fsm.rs index 7d50698..ae5b0e9 100644 --- a/asic/src/tofino_asic/link_fsm.rs +++ b/asic/src/tofino_asic/link_fsm.rs @@ -479,10 +479,6 @@ pub extern "C" fn bf_pm_fsm_transition_callback( }; bf_wrapper::send_port_update( "port_fsm_transition_cb()", - aal::PortUpdate::FSM { - asic_port_id, - fsm, - state: to, - }, + aal::PortUpdate::FSM { asic_port_id, fsm, state: to }, ) } diff --git a/asic/src/tofino_asic/mcast.rs b/asic/src/tofino_asic/mcast.rs index f064be5..44f7696 100644 --- a/asic/src/tofino_asic/mcast.rs +++ b/asic/src/tofino_asic/mcast.rs @@ -240,10 +240,7 @@ pub fn domain_add_port( rid: u16, level_1_excl_id: u16, ) -> AsicResult<()> { - debug!( - hdl.log, - "adding port {} to multicast domain {}", port, group_id - ); + debug!(hdl.log, "adding port {} to multicast domain {}", port, group_id); let mut domains = hdl.domains.lock().unwrap(); let domain = match domains.get_mut(&group_id) { @@ -303,10 +300,7 @@ pub fn domain_remove_port( group_id: u16, port: u16, ) -> AsicResult<()> { - debug!( - hdl.log, - "removing {} from multicast domain {}", port, group_id - ); + debug!(hdl.log, "removing {} from multicast domain {}", port, group_id); let mut domains = hdl.domains.lock().unwrap(); let domain = match domains.get_mut(&group_id) { Some(d) => Ok(d), @@ -341,11 +335,7 @@ pub fn domain_create(hdl: &Handle, group_id: u16) -> AsicResult<()> { let mgrp_hdl = mgrp_create(bf.mcast_hdl, bf.dev_id, group_id)?; domains.insert( group_id, - DomainState { - id: group_id, - mgrp_hdl, - ports: HashMap::new(), - }, + DomainState { id: group_id, mgrp_hdl, ports: HashMap::new() }, ); Ok(()) } diff --git a/asic/src/tofino_asic/mod.rs b/asic/src/tofino_asic/mod.rs index 46bf61f..39fa8b3 100644 --- a/asic/src/tofino_asic/mod.rs +++ b/asic/src/tofino_asic/mod.rs @@ -63,11 +63,7 @@ pub struct AsicConfig { impl Default for AsicConfig { fn default() -> Self { - Self { - devpath: None, - xcvr_iface: None, - board_rev: String::from("B"), - } + Self { devpath: None, xcvr_iface: None, board_rev: String::from("B") } } } @@ -276,16 +272,8 @@ fn wafer_loc_from_coords( y_sign: u8, y_pos: u8, ) -> (i16, i16) { - let x = if x_sign == 0 { - i16::from(x_pos) - } else { - -i16::from(x_pos) - }; - let y = if y_sign == 0 { - i16::from(y_pos) - } else { - -i16::from(y_pos) - }; + let x = if x_sign == 0 { i16::from(x_pos) } else { -i16::from(x_pos) }; + let y = if y_sign == 0 { i16::from(y_pos) } else { -i16::from(y_pos) }; (x, y) } diff --git a/asic/src/tofino_asic/ports.rs b/asic/src/tofino_asic/ports.rs index 98d40fd..6c23501 100644 --- a/asic/src/tofino_asic/ports.rs +++ b/asic/src/tofino_asic/ports.rs @@ -94,10 +94,7 @@ impl FrontPortHandle { /// Given a 16-bit ASIC ID, determine which front-panel port it maps to pub fn from_dev_port(hdl: &Handle, port: PortId) -> AsicResult { - let mut fp_hdl = bf_pal_front_port_handle_t { - conn_id: 0, - chnl_id: 0, - }; + let mut fp_hdl = bf_pal_front_port_handle_t { conn_id: 0, chnl_id: 0 }; unsafe { bf_pm_port_dev_port_to_front_panel_port_get( hdl.dev_id, @@ -106,10 +103,7 @@ impl FrontPortHandle { ) } .check_error("getting front port handle")?; - Ok(FrontPortHandle { - dev_id: hdl.dev_id, - fp_hdl, - }) + Ok(FrontPortHandle { dev_id: hdl.dev_id, fp_hdl }) } /// Given a PortHdl, return the front-panel port it maps to @@ -123,11 +117,7 @@ impl FrontPortHandle { }, Connector::QSFP(c) => Ok(c), }?; - Ok(FrontPortHandle::new( - hdl.dev_id, - connector, - port_hdl.channel, - )) + Ok(FrontPortHandle::new(hdl.dev_id, connector, port_hdl.channel)) } /// Get the first front-panel port. Whether this is actually "first" in any @@ -135,10 +125,7 @@ impl FrontPortHandle { /// is just used as an anchor point when iterating over all of the ports in the /// system. pub fn get_first(dev_id: i32) -> AsicResult { - let mut fp_hdl = bf_pal_front_port_handle_t { - conn_id: 0, - chnl_id: 0, - }; + let mut fp_hdl = bf_pal_front_port_handle_t { conn_id: 0, chnl_id: 0 }; unsafe { bf_pm_port_front_panel_port_get_first(dev_id, &mut fp_hdl) } .check_error("getting first front port handle")?; @@ -149,10 +136,7 @@ impl FrontPortHandle { /// Get the next front-panel port according to some consistent, well-known /// but opaque algorithm. pub fn get_next(&self) -> AsicResult { - let mut fp_hdl = bf_pal_front_port_handle_t { - conn_id: 0, - chnl_id: 0, - }; + let mut fp_hdl = bf_pal_front_port_handle_t { conn_id: 0, chnl_id: 0 }; unsafe { // The get_next() routine doesn't modify the old handle, so there is @@ -167,10 +151,7 @@ impl FrontPortHandle { } .check_error("getting first front port handle")?; - Ok(FrontPortHandle { - dev_id: self.dev_id, - fp_hdl, - }) + Ok(FrontPortHandle { dev_id: self.dev_id, fp_hdl }) } /// Get a raw pointer to the front_panel structure, so we can pass it as @@ -439,10 +420,7 @@ struct BerLanes { impl BerLanes { const fn all() -> Self { - Self { - start: 0, - end: MAX_N_LANES - 1, - } + Self { start: 0, end: MAX_N_LANES - 1 } } // Return the BER counters used for the provided number of lanes. @@ -462,9 +440,8 @@ impl BerLanes { // Add the number of lanes, being very conservative. We'll always return // all the counters, rather than overflow anything. let n_lanes = usize::try_from(n_lanes).unwrap_or(MAX_N_LANES - 1); - let Some(end) = start - .checked_add(n_lanes) - .map(|end| end.min(MAX_N_LANES - 1)) + let Some(end) = + start.checked_add(n_lanes).map(|end| end.min(MAX_N_LANES - 1)) else { return Self::all(); }; diff --git a/asic/src/tofino_asic/qsfp.rs b/asic/src/tofino_asic/qsfp.rs index 195870e..7004b33 100644 --- a/asic/src/tofino_asic/qsfp.rs +++ b/asic/src/tofino_asic/qsfp.rs @@ -177,13 +177,7 @@ impl SdeTransceiverMessage { oneshot::Receiver>, ) { let (response_tx, rx) = oneshot::channel(); - ( - Self { - request, - response_tx, - }, - rx, - ) + (Self { request, response_tx }, rx) } } @@ -355,10 +349,8 @@ pub extern "C" fn bf_pltfm_qsfp_init(_: *mut c_void) -> c_int { // Provide the SDE with our implementations of the module read/write // routines. - const IMPL: bf_qsfp_vec_t = bf_qsfp_vec_t { - write: write_qsfp_module, - read: read_qsfp_module, - }; + const IMPL: bf_qsfp_vec_t = + bf_qsfp_vec_t { write: write_qsfp_module, read: read_qsfp_module }; let ret = unsafe { bf_qsfp_vec_init(&IMPL as *const _ as *mut _) }; if ret == 0 { debug!(log, "initialized QSFP management with {} ports", n_ports); @@ -512,13 +504,7 @@ pub unsafe extern "C" fn write_qsfp_module( }; let data = unsafe { std::slice::from_raw_parts(src, usize::from(len)) }.to_vec(); - let body = WriteRequest { - module, - bank, - page, - offset, - data, - }; + let body = WriteRequest { module, bank, page, offset, data }; let message = SdeTransceiverRequest::Write(body); let (request, response_rx) = SdeTransceiverMessage::new(message.clone()); match send_to_dpd(tx, request, response_rx) { @@ -605,13 +591,7 @@ pub unsafe extern "C" fn read_qsfp_module( ); return -1; }; - let body = ReadRequest { - module, - bank, - page, - offset, - len, - }; + let body = ReadRequest { module, bank, page, offset, len }; let message = SdeTransceiverRequest::Read(body); let (request, response_rx) = SdeTransceiverMessage::new(message.clone()); match send_to_dpd(tx, request, response_rx) { diff --git a/asic/src/tofino_asic/serdes.rs b/asic/src/tofino_asic/serdes.rs index 3aa7165..f499109 100644 --- a/asic/src/tofino_asic/serdes.rs +++ b/asic/src/tofino_asic/serdes.rs @@ -49,17 +49,10 @@ fn port_encoding_mode(dev_id: i32, port_id: u16) -> AsicResult { /// Get the number of lanes configured for this port pub(crate) fn lane_count(hdl: &Handle, port: PortHdl) -> AsicResult { - match hdl - .phys_ports - .lock() - .unwrap() - .get_tofino_port(port)? - .channels - .len() - { - n if n < 1 || n > 8 => Err(AsicError::Internal(format!( - "configured port has {n} lanes" - ))), + match hdl.phys_ports.lock().unwrap().get_tofino_port(port)?.channels.len() { + n if n < 1 || n > 8 => { + Err(AsicError::Internal(format!("configured port has {n} lanes"))) + } n => Ok(n as u32), } } @@ -167,11 +160,7 @@ fn lane_rx_sig_info_get( .check_error("fetching rx signal info")? }; - Ok(RxSigInfo { - sig_detect, - phy_ready, - ppm, - }) + Ok(RxSigInfo { sig_detect, phy_ready, ppm }) } /// Collect all of the per-lane rx signal info for the specified port. @@ -836,11 +825,7 @@ pub fn an_lt_status_get(hdl: &Handle, port: PortHdl) -> AsicResult { let lane_done = an_done_get(hdl, port, lane)?; let lane_an_status = an_status_get(hdl, port, lane)?; let lane_lt_status = lt_status_get(hdl, port, lane)?; - lanes.push(LaneStatus { - lane_done, - lane_an_status, - lane_lt_status, - }) + lanes.push(LaneStatus { lane_done, lane_an_status, lane_lt_status }) } let lp_pages = an_lp_pages_get(hdl, port)?; Ok(AnLtStatus { lp_pages, lanes }) diff --git a/asic/src/tofino_asic/table.rs b/asic/src/tofino_asic/table.rs index 43de3a1..afea589 100644 --- a/asic/src/tofino_asic/table.rs +++ b/asic/src/tofino_asic/table.rs @@ -160,10 +160,7 @@ impl FieldOps for MatchLpm { bf_rt_key_field_get_value_lpm(k.key_hdl, id, &mut prefix, &mut len) } .check_error("getting short lpm")?; - Ok(MatchLpm { - prefix: prefix.into(), - len, - }) + Ok(MatchLpm { prefix: prefix.into(), len }) } fn get_long(k: &KeyHdl, id: u32, size: usize) -> AsicResult { @@ -179,10 +176,7 @@ impl FieldOps for MatchLpm { ) } .check_error("getting ptr value")?; - Ok(MatchLpm { - prefix: prefix.into(), - len, - }) + Ok(MatchLpm { prefix: prefix.into(), len }) } fn add_field(k: &KeyHdl, id: u32, x: &Self) -> AsicResult<()> { @@ -219,9 +213,7 @@ impl FieldOps for MatchMask { } fn get_long(_k: &KeyHdl, _id: u32, _size: usize) -> AsicResult { - Err(AsicError::InvalidArg( - "long masks aren't supported".to_string(), - )) + Err(AsicError::InvalidArg("long masks aren't supported".to_string())) } fn add_field(k: &KeyHdl, id: u32, x: &Self) -> AsicResult<()> { @@ -244,9 +236,7 @@ impl FieldOps for MatchRange { } fn get_long(_k: &KeyHdl, _id: u32, _size: usize) -> AsicResult { - Err(AsicError::InvalidArg( - "long ranges aren't supported".to_string(), - )) + Err(AsicError::InvalidArg("long ranges aren't supported".to_string())) } fn add_field(k: &KeyHdl, id: u32, x: &Self) -> AsicResult<()> { @@ -304,10 +294,7 @@ impl KeyHdl { ), }; - fields.push(MatchEntryField { - name: name.to_string(), - value, - }); + fields.push(MatchEntryField { name: name.to_string(), value }); } Ok(MatchData { fields }) } @@ -399,12 +386,10 @@ impl DataHdl { fn to_actiondata(&self, table: &Table) -> AsicResult { let action_id = self.get_action_id()?; - let (action_name, action) = &table - .info - .actions - .iter() - .find(|(_, a)| a.id == action_id) - .ok_or(AsicError::Internal("No matching action found".into()))?; + let (action_name, action) = + &table.info.actions.iter().find(|(_, a)| a.id == action_id).ok_or( + AsicError::Internal("No matching action found".into()), + )?; let mut args = Vec::new(); for (name, field) in &action.args { @@ -412,10 +397,7 @@ impl DataHdl { let name = name.clone(); args.push(ActionArg { name, value }); } - Ok(ActionData { - action: action_name.to_string(), - args, - }) + Ok(ActionData { action: action_name.to_string(), args }) } fn to_counterdata(&self, table: &Table) -> AsicResult { @@ -446,10 +428,7 @@ struct Trigger { impl Trigger { pub fn new() -> Trigger { - Trigger { - done: Mutex::new(false), - cv: Condvar::new(), - } + Trigger { done: Mutex::new(false), cv: Condvar::new() } } } diff --git a/asic/src/tofino_common/mod.rs b/asic/src/tofino_common/mod.rs index cebb27b..7d5a544 100644 --- a/asic/src/tofino_common/mod.rs +++ b/asic/src/tofino_common/mod.rs @@ -64,12 +64,7 @@ impl TableInfo { pub fn new(bfrt: &BfRt, name: &str) -> AsicResult { let (keys, actions, data, size) = bfrt.get_table(name)?; - Ok(TableInfo { - keys, - actions, - data, - size: size as usize, - }) + Ok(TableInfo { keys, actions, data, size: size as usize }) } #[cfg(feature = "tofino_asic")] diff --git a/asic/src/tofino_stub/mcast.rs b/asic/src/tofino_stub/mcast.rs index ec2ae3b..07339b6 100644 --- a/asic/src/tofino_stub/mcast.rs +++ b/asic/src/tofino_stub/mcast.rs @@ -114,7 +114,5 @@ impl McGroupData { } pub fn init() -> McGroupData { - McGroupData { - groups: HashMap::new(), - } + McGroupData { groups: HashMap::new() } } diff --git a/asic/src/tofino_stub/mod.rs b/asic/src/tofino_stub/mod.rs index 3e8d671..62185d4 100644 --- a/asic/src/tofino_stub/mod.rs +++ b/asic/src/tofino_stub/mod.rs @@ -175,10 +175,7 @@ impl AsicOps for StubHandle { rid: u16, level1_excl_id: u16, ) -> AsicResult<()> { - info!( - self.log, - "adding port {} to multicast group {}", port, group_id - ); + info!(self.log, "adding port {} to multicast group {}", port, group_id); let mut mc_data = self.mc_data.lock().unwrap(); mc_data.domain_port_add(group_id, port, rid, level1_excl_id) } diff --git a/asic/src/tofino_stub/ports.rs b/asic/src/tofino_stub/ports.rs index 874490b..94ea106 100644 --- a/asic/src/tofino_stub/ports.rs +++ b/asic/src/tofino_stub/ports.rs @@ -110,14 +110,8 @@ pub fn set_enable( // When a port is enabled in the stub, it automatically comes online. // When switching between enabled and disabled, we send the main body // of dpd the PortUpdate events we would expect to see on real hardware. - let present = PortUpdate::Presence { - asic_port_id, - presence: enabled, - }; - let ena = PortUpdate::Enable { - asic_port_id, - enabled, - }; + let present = PortUpdate::Presence { asic_port_id, presence: enabled }; + let ena = PortUpdate::Enable { asic_port_id, enabled }; let fsm_state = match enabled { false => PortFsmState::Idle, true => PortFsmState::LinkUp, @@ -127,10 +121,7 @@ pub fn set_enable( fsm: FsmType::Port.into(), state: fsm_state.into(), }; - let link = PortUpdate::LinkUp { - asic_port_id, - linkup: enabled, - }; + let link = PortUpdate::LinkUp { asic_port_id, linkup: enabled }; for event in &[present, ena, fsm, link] { if let Err(e) = tx.send(*event) { slog::error!( @@ -230,12 +221,7 @@ pub fn add_port( let mut ports = hdl.port_state.lock().unwrap(); ports.insert( port_hdl, - StubPort { - link_up: false, - enabled: false, - kr: false, - autoneg: false, - }, + StubPort { link_up: false, enabled: false, kr: false, autoneg: false }, ); Ok((port_hdl, port_id)) } diff --git a/common/src/logging.rs b/common/src/logging.rs index 2092477..3882a98 100644 --- a/common/src/logging.rs +++ b/common/src/logging.rs @@ -57,19 +57,13 @@ pub fn init( let drain = slog_bunyan::with_name(name, std::io::stdout()) .build() .fuse(); - slog_async::Async::new(drain) - .chan_size(32768) - .build() - .fuse() + slog_async::Async::new(drain).chan_size(32768).build().fuse() } LogFormat::Human => { let decorator = slog_term::TermDecorator::new().build(); let drain = slog_term::FullFormat::new(decorator).build().fuse(); - slog_async::Async::new(drain) - .chan_size(32768) - .build() - .fuse() + slog_async::Async::new(drain).chan_size(32768).build().fuse() } }, }; diff --git a/common/src/network.rs b/common/src/network.rs index 20f993c..6727804 100644 --- a/common/src/network.rs +++ b/common/src/network.rs @@ -56,15 +56,11 @@ impl From<[u8; 6]> for MacAddr { impl MacAddr { /// Oxide's Organizationally Unique Identifier. pub const OXIDE_OUI: [u8; 3] = [0xa8, 0x40, 0x25]; - pub const ZERO: Self = MacAddr { - a: [0, 0, 0, 0, 0, 0], - }; + pub const ZERO: Self = MacAddr { a: [0, 0, 0, 0, 0, 0] }; /// Create a new MAC address from octets in network byte order. pub fn new(o0: u8, o1: u8, o2: u8, o3: u8, o4: u8, o5: u8) -> MacAddr { - MacAddr { - a: [o0, o1, o2, o3, o4, o5], - } + MacAddr { a: [o0, o1, o2, o3, o4, o5] } } /// Create a new MAC address from a slice of bytes in network byte order. @@ -80,16 +76,12 @@ impl MacAddr { /// Convert `self` to an array of bytes in network byte order. pub fn to_vec(self) -> Vec { - vec![ - self.a[0], self.a[1], self.a[2], self.a[3], self.a[4], self.a[5], - ] + vec![self.a[0], self.a[1], self.a[2], self.a[3], self.a[4], self.a[5]] } /// Return `true` if `self` is the null MAC address, all zeros. pub fn is_null(self) -> bool { - const EMPTY: MacAddr = MacAddr { - a: [0, 0, 0, 0, 0, 0], - }; + const EMPTY: MacAddr = MacAddr { a: [0, 0, 0, 0, 0, 0] }; self == EMPTY } @@ -241,11 +233,7 @@ pub enum VlanError { pub fn validate_vlan(id: impl Into) -> Result<(), VlanError> { let id: u16 = id.into(); #[allow(clippy::manual_range_contains)] - if id < 2 || id > 4095 { - Err(VlanError::InvalidVlan(id)) - } else { - Ok(()) - } + if id < 2 || id > 4095 { Err(VlanError::InvalidVlan(id)) } else { Ok(()) } } /// A Geneve Virtual Network Identifier. @@ -276,11 +264,7 @@ impl Vni { /// Construct a new VNI, validating that it's a valid 24-bit value. pub const fn new(vni: u32) -> Option { // bool.then_some is not const, unforunately - if vni <= Self::MAX_VNI { - Some(Self(vni)) - } else { - None - } + if vni <= Self::MAX_VNI { Some(Self(vni)) } else { None } } /// Return the VNI as a u32. diff --git a/dpd-client/src/lib.rs b/dpd-client/src/lib.rs index 0e8c414..866976c 100644 --- a/dpd-client/src/lib.rs +++ b/dpd-client/src/lib.rs @@ -55,18 +55,12 @@ progenitor::generate_api!( impl Client { /// Helper to create an `Ipv4Entry` from an address, using the client's tag. pub fn ipv4_entry(&self, addr: Ipv4Addr) -> types::Ipv4Entry { - types::Ipv4Entry { - tag: self.inner().tag.clone(), - addr, - } + types::Ipv4Entry { tag: self.inner().tag.clone(), addr } } /// Helper to create an `Ipv6Entry` from an address, using the client's tag. pub fn ipv6_entry(&self, addr: Ipv6Addr) -> types::Ipv6Entry { - types::Ipv6Entry { - tag: self.inner().tag.clone(), - addr, - } + types::Ipv6Entry { tag: self.inner().tag.clone(), addr } } } @@ -246,19 +240,13 @@ impl From for types::MacAddr { impl From for ports::Ipv6Entry { fn from(e: types::Ipv6Entry) -> Self { - ports::Ipv6Entry { - tag: e.tag, - addr: e.addr, - } + ports::Ipv6Entry { tag: e.tag, addr: e.addr } } } impl From for ports::Ipv4Entry { fn from(e: types::Ipv4Entry) -> Self { - ports::Ipv4Entry { - tag: e.tag, - addr: e.addr, - } + ports::Ipv4Entry { tag: e.tag, addr: e.addr } } } diff --git a/dpd-client/tests/chaos_tests/harness.rs b/dpd-client/tests/chaos_tests/harness.rs index 0016c5e..36000b8 100644 --- a/dpd-client/tests/chaos_tests/harness.rs +++ b/dpd-client/tests/chaos_tests/harness.rs @@ -117,9 +117,6 @@ pub(crate) fn new_dpd_client(port: u16) -> Client { Client::new( &format!("http://localhost:{}", port), - ClientState { - tag: "tenagra".into(), - log, - }, + ClientState { tag: "tenagra".into(), log }, ) } diff --git a/dpd-client/tests/chaos_tests/port_settings.rs b/dpd-client/tests/chaos_tests/port_settings.rs index ff30ffa..bcc4d2a 100644 --- a/dpd-client/tests/chaos_tests/port_settings.rs +++ b/dpd-client/tests/chaos_tests/port_settings.rs @@ -115,9 +115,7 @@ async fn test_port_settings_addr_fail_1() -> anyhow::Result<()> { let (_guard, client) = init_harness("addr-fail-1", &config); - let mut settings = PortSettings { - links: HashMap::new(), - }; + let mut settings = PortSettings { links: HashMap::new() }; settings.links.insert( "0".into(), @@ -154,16 +152,11 @@ async fn test_port_settings_addr_fail_1() -> anyhow::Result<()> { // Test a simple successful port settings transaction. #[tokio::test] async fn test_port_settings_addr_success_1() -> anyhow::Result<()> { - let config = AsicConfig { - radix: TESTING_RADIX, - ..Default::default() - }; + let config = AsicConfig { radix: TESTING_RADIX, ..Default::default() }; let (_guard, client) = init_harness("addr-success", &config); - let mut settings = PortSettings { - links: HashMap::new(), - }; + let mut settings = PortSettings { links: HashMap::new() }; settings.links.insert( "0".into(), @@ -198,17 +191,12 @@ async fn test_port_settings_addr_success_1() -> anyhow::Result<()> { // Test multiple port settings transactions in sequence. #[tokio::test] async fn test_port_settings_addr_success_multi() -> anyhow::Result<()> { - let config = AsicConfig { - radix: TESTING_RADIX, - ..Default::default() - }; + let config = AsicConfig { radix: TESTING_RADIX, ..Default::default() }; let (_guard, client) = init_harness("addr-success-multi", &config); // Start with a link that has one IPv4 address. - let mut settings = PortSettings { - links: HashMap::new(), - }; + let mut settings = PortSettings { links: HashMap::new() }; settings.links.insert( "0".into(), LinkSettings { @@ -237,9 +225,7 @@ async fn test_port_settings_addr_success_multi() -> anyhow::Result<()> { // Update the link to have 2 IPv4 addresses and 4 IPv6 addresses. - let mut settings = PortSettings { - links: HashMap::new(), - }; + let mut settings = PortSettings { links: HashMap::new() }; settings.links.insert( "0".into(), LinkSettings { @@ -279,9 +265,7 @@ async fn test_port_settings_addr_success_multi() -> anyhow::Result<()> { // Reduce the addresses back down to 1 IPv4 and 1 IPv6. Add 1 IPv4 route and // two IPv6 routes. - let mut settings = PortSettings { - links: HashMap::new(), - }; + let mut settings = PortSettings { links: HashMap::new() }; settings.links.insert( "0".into(), LinkSettings { @@ -379,10 +363,7 @@ async fn test_port_settings_txn_sweep() -> anyhow::Result<()> { let target = random_port_settings(); print!("current/target: {}", Comparison::new(¤t, &target)); - match client - .port_settings_apply(&port, Some("chaos"), &target) - .await - { + match client.port_settings_apply(&port, Some("chaos"), &target).await { Ok(mut returned) => { sort_addrs(&mut returned); // Verify that what the server attempted to configure matches @@ -510,10 +491,8 @@ async fn current_port_settings( client: &Client, port: &PortId, ) -> anyhow::Result { - let mut settings = client - .port_settings_get(port, Some("chaos")) - .await? - .into_inner(); + let mut settings = + client.port_settings_get(port, Some("chaos")).await?.into_inner(); sort_addrs(&mut settings); Ok(settings) } @@ -528,9 +507,7 @@ fn random_port_settings() -> PortSettings { let mut rng = rand::rng(); if rng.random::() < 0.15 { - return PortSettings { - links: HashMap::new(), - }; + return PortSettings { links: HashMap::new() }; } // Create a link spec with random auto negotiation and kr settings. diff --git a/dpd-client/tests/integration_tests/attached_subnet.rs b/dpd-client/tests/integration_tests/attached_subnet.rs index a9a3c48..b42ba44 100644 --- a/dpd-client/tests/integration_tests/attached_subnet.rs +++ b/dpd-client/tests/integration_tests/attached_subnet.rs @@ -115,11 +115,7 @@ async fn test_egress(switch: &Switch, test: &ExternalTest) -> TestResult { addr: backplane_ip, tag: switch.client.inner().tag.clone(), }; - switch - .client - .link_ipv6_create(&port_id, &link_id, &entry) - .await - .unwrap(); + switch.client.link_ipv6_create(&port_id, &link_id, &entry).await.unwrap(); // populate the ndp/arp table with the upstream router's mac and IP. if test.upstream_router_ip.parse::().is_ok() { @@ -150,11 +146,7 @@ async fn test_egress(switch: &Switch, test: &ExternalTest) -> TestResult { inner_mac: test.instance_mac.parse::()?.into(), vni: test.geneve_vni.into(), }; - switch - .client - .attached_subnet_create(&attached_subnet, &tgt) - .await - .unwrap(); + switch.client.attached_subnet_create(&attached_subnet, &tgt).await.unwrap(); // Build a packet coming from an instance on an external subnet. // The inner packet may be IPv4 or IPv6 with a source address on the @@ -171,10 +163,8 @@ async fn test_egress(switch: &Switch, test: &ExternalTest) -> TestResult { L4Protocol::Icmp => common::gen_icmp_packet(src, dst), }; - let switch_mac = switch - .get_port_mac(test.backplane_port) - .unwrap() - .to_string(); + let switch_mac = + switch.get_port_mac(test.backplane_port).unwrap().to_string(); let payload = payload_pkt.deparse().unwrap().to_vec(); let to_send = common::gen_geneve_packet( Endpoint::parse(&test.gimlet_mac, &test.gimlet_ip, 3333).unwrap(), @@ -197,14 +187,10 @@ async fn test_egress(switch: &Switch, test: &ExternalTest) -> TestResult { common::gen_packet_routed(switch, test.uplink_port, &payload_pkt); eth::EthHdr::rewrite_dmac(&mut to_recv, router_mac); - let send = TestPacket { - packet: Arc::new(to_send), - port: test.backplane_port, - }; - let expected = TestPacket { - packet: Arc::new(to_recv), - port: test.uplink_port, - }; + let send = + TestPacket { packet: Arc::new(to_send), port: test.backplane_port }; + let expected = + TestPacket { packet: Arc::new(to_recv), port: test.uplink_port }; switch.packet_test(vec![send], vec![expected]) } @@ -222,11 +208,7 @@ async fn test_ingress(switch: &Switch, test: &ExternalTest) -> TestResult { }; // Create the backplane port on the sidecar, linking to the gimlet - switch - .client - .link_ipv6_create(&port_id, &link_id, &entry) - .await - .unwrap(); + switch.client.link_ipv6_create(&port_id, &link_id, &entry).await.unwrap(); let cidr = oxnet::Ipv6Net::new(test.gimlet_ip.parse().unwrap(), 64).unwrap(); let route = types::Ipv6RouteUpdate { @@ -289,10 +271,8 @@ async fn test_ingress(switch: &Switch, test: &ExternalTest) -> TestResult { // build the encapsulated packet for transporting the packet from the // switch to OPTE - let backplane_port_mac = switch - .get_port_mac(test.backplane_port) - .unwrap() - .to_string(); + let backplane_port_mac = + switch.get_port_mac(test.backplane_port).unwrap().to_string(); // XXX: The switch should be using the switch port IP, but isn't yet. let switch_port_ip = "::0"; diff --git a/dpd-client/tests/integration_tests/common.rs b/dpd-client/tests/integration_tests/common.rs index 41c5f3f..727bf89 100644 --- a/dpd-client/tests/integration_tests/common.rs +++ b/dpd-client/tests/integration_tests/common.rs @@ -251,10 +251,7 @@ impl Switch { let drain = slog_term::FullFormat::new(decorator).build().fuse(); let drain = slog_async::Async::new(drain).build().fuse(); let log = slog::Logger::root(drain, slog::o!()); - let client_state = ClientState { - tag: String::from("test"), - log, - }; + let client_state = ClientState { tag: String::from("test"), log }; let client = Client::new( &format!("http://{ctrl_host}:{ctrl_port}"), client_state, @@ -271,12 +268,7 @@ impl Switch { // rear ports, and then use `swadm` to return the ASIC ID for each link. let ports = vec![ None, - Some(Port::new( - 8, - PortId::try_from("rear29").unwrap(), - None, - None, - )), + Some(Port::new(8, PortId::try_from("rear29").unwrap(), None, None)), Some(Port::new( 16, PortId::try_from("rear31").unwrap(), @@ -625,15 +617,10 @@ impl Switch { } pcap::Ternary::Ok(data) => { let packet = packet::Packet::parse(&data).unwrap(); - let copy = Packet { - hdrs: packet.hdrs.clone(), - body: packet.body, - }; - - let cap = TestPacket { - port, - packet: Arc::new(copy), - }; + let copy = + Packet { hdrs: packet.hdrs.clone(), body: packet.body }; + + let cap = TestPacket { port, packet: Arc::new(copy) }; tx.send(cap).unwrap(); } } @@ -1113,11 +1100,7 @@ async fn set_route_ipv6_common( .await .expect("Failed to get just-added IPv6 route entry") .into_inner(); - assert_eq!( - route.len(), - 1, - "Just added Ipv6-route has more than 1 entry" - ); + assert_eq!(route.len(), 1, "Just added Ipv6-route has more than 1 entry"); assert_eq!( route[0].port_id, port_id, "Just-added IPv6 route entry doesn't match" @@ -1165,11 +1148,7 @@ pub async fn add_neighbor_ipv6( tag: switch.client.inner().tag.clone(), update: String::new(), }; - switch - .client - .ndp_create(&entry) - .await - .expect("Failed to add NDP entry"); + switch.client.ndp_create(&entry).await.expect("Failed to add NDP entry"); let neighbor = switch .client @@ -1177,11 +1156,7 @@ pub async fn add_neighbor_ipv6( .await .expect("Failed to get just-added NDP entry") .into_inner(); - assert_eq!( - neighbor.mac, - mac.into(), - "Just-added NDP entry doesn't match" - ); + assert_eq!(neighbor.mac, mac.into(), "Just-added NDP entry doesn't match"); assert_eq!(neighbor.ip, host, "Just-added NDP entry doesn't match"); Ok(()) } @@ -1219,11 +1194,7 @@ async fn set_route_ipv4_common( .await .expect("failed to get just-added IPv4 route entry") .into_inner(); - assert_eq!( - route.len(), - 1, - "Just added IPv4-route has more than 1 entry" - ); + assert_eq!(route.len(), 1, "Just added IPv4-route has more than 1 entry"); assert_eq!( route[0].port_id, port_id, "Just-added IPv4 route entry doesn't match" @@ -1261,11 +1232,7 @@ pub async fn add_arp_ipv4( tag: switch.client.inner().tag.clone(), update: String::new(), }; - switch - .client - .arp_create(&entry) - .await - .expect("Failed to add ARP entry"); + switch.client.arp_create(&entry).await.expect("Failed to add ARP entry"); let arp = switch .client @@ -1291,11 +1258,7 @@ pub async fn add_ndp_ipv6( tag: switch.client.inner().tag.clone(), update: String::new(), }; - switch - .client - .ndp_create(&entry) - .await - .expect("Failed to add ARP entry"); + switch.client.ndp_create(&entry).await.expect("Failed to add ARP entry"); let ndp = switch .client diff --git a/dpd-client/tests/integration_tests/counters.rs b/dpd-client/tests/integration_tests/counters.rs index 6d2ed4c..bbcb446 100644 --- a/dpd-client/tests/integration_tests/counters.rs +++ b/dpd-client/tests/integration_tests/counters.rs @@ -33,10 +33,7 @@ async fn one_drop_test( packet: packet::Packet, counter: &str, ) -> anyhow::Result { - let send = TestPacket { - packet: Arc::new(packet), - port, - }; + let send = TestPacket { packet: Arc::new(packet), port }; let old = switch.get_counter(counter, None).await?; switch.packet_test(vec![send], Vec::new())?; @@ -66,11 +63,7 @@ async fn add_switch_ipv4(switch: &Switch, port: PhysPort, addr: &str) { tag: switch.client.inner().tag.clone(), }; - switch - .client - .link_ipv4_create(&port_id, &link_id, &entry) - .await - .unwrap(); + switch.client.link_ipv4_create(&port_id, &link_id, &entry).await.unwrap(); } /// Assigns the address 10.10.10.11 to port 12 and then sends a packet with @@ -112,11 +105,7 @@ async fn test_ipv6_switch_addr_miss() -> TestResult { tag: switch.client.inner().tag.clone(), }; - switch - .client - .link_ipv6_create(&port_id, &link_id, &entry) - .await - .unwrap(); + switch.client.link_ipv6_create(&port_id, &link_id, &entry).await.unwrap(); let packet = common::gen_udp_packet( Endpoint::parse("e0:d5:5e:67:89:ab", "fd00:1122:3344:0200::1", 3333) @@ -214,11 +203,7 @@ async fn test_nat_filtering() -> TestResult { let (port_id, link_id) = switch.link_id(ingress).unwrap(); // Mark the port as NAT-only - switch - .client - .link_nat_only_set(&port_id, &link_id, true) - .await - .unwrap(); + switch.client.link_nat_only_set(&port_id, &link_id, true).await.unwrap(); // We run the test now, but defer the evaluation of the result. This lets // us clean up the NAT-only change even on a test failure. @@ -226,11 +211,7 @@ async fn test_nat_filtering() -> TestResult { one_drop_test(switch, ingress, packet, "nat_ingress_miss").await; // Remove the NAT-only property - switch - .client - .link_nat_only_set(&port_id, &link_id, false) - .await - .unwrap(); + switch.client.link_nat_only_set(&port_id, &link_id, false).await.unwrap(); assert!(result?); Ok(()) diff --git a/dpd-client/tests/integration_tests/geneve.rs b/dpd-client/tests/integration_tests/geneve.rs index 259c904..de98431 100644 --- a/dpd-client/tests/integration_tests/geneve.rs +++ b/dpd-client/tests/integration_tests/geneve.rs @@ -59,14 +59,8 @@ async fn test_geneve() -> TestResult { ); eth::EthHdr::rewrite_dmac(&mut to_send, router_mac); let to_recv = common::gen_packet_routed(switch, uplink_port, &to_send); - let send = TestPacket { - packet: Arc::new(to_send), - port: ingress_port, - }; - let expected = TestPacket { - packet: Arc::new(to_recv), - port: uplink_port, - }; + let send = TestPacket { packet: Arc::new(to_send), port: ingress_port }; + let expected = TestPacket { packet: Arc::new(to_recv), port: uplink_port }; // These tests are a bit slower, for non-obvious reasons. switch.packet_test(vec![send], vec![expected]) @@ -125,15 +119,10 @@ async fn test_geneve_multiopt() -> TestResult { ); eth::EthHdr::rewrite_dmac(&mut to_send, router_mac); let to_recv = common::gen_packet_routed(switch, uplink_port, &to_send); - let send = TestPacket { - packet: Arc::new(to_send), - port: ingress_port, - }; + let send = TestPacket { packet: Arc::new(to_send), port: ingress_port }; let to_recv = Arc::new(to_recv); - let expected = TestPacket { - packet: Arc::clone(&to_recv), - port: uplink_port, - }; + let expected = + TestPacket { packet: Arc::clone(&to_recv), port: uplink_port }; switch.packet_test(vec![send], vec![expected])?; @@ -158,14 +147,8 @@ async fn test_geneve_multiopt() -> TestResult { &payload, ); eth::EthHdr::rewrite_dmac(&mut to_send, router_mac); - let send = TestPacket { - packet: Arc::new(to_send), - port: ingress_port, - }; - let expected = TestPacket { - packet: to_recv, - port: uplink_port, - }; + let send = TestPacket { packet: Arc::new(to_send), port: ingress_port }; + let expected = TestPacket { packet: to_recv, port: uplink_port }; // Sidecar, at least for today, orders options by ID. switch.packet_test(vec![send], vec![expected]) diff --git a/dpd-client/tests/integration_tests/icmp_ipv4.rs b/dpd-client/tests/integration_tests/icmp_ipv4.rs index 9d353dc..7c27dcb 100644 --- a/dpd-client/tests/integration_tests/icmp_ipv4.rs +++ b/dpd-client/tests/integration_tests/icmp_ipv4.rs @@ -40,16 +40,10 @@ async fn test_ping_ipv4_deadend() -> TestResult { let to_send = common::gen_ipv4_ping(icmp::ICMP_ECHO, 0, from, to); let mut to_recv = to_send.clone(); - let send = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let send = TestPacket { packet: Arc::new(to_send), port: ingress }; common::set_icmp_unreachable(switch, &mut to_recv, ingress); - let expected = TestPacket { - packet: Arc::new(to_recv), - port: egress, - }; + let expected = TestPacket { packet: Arc::new(to_recv), port: egress }; switch.packet_test(vec![send], vec![expected]) } @@ -75,35 +69,22 @@ async fn execute_ping_reply_test( addr: to.get_ipv4("tgt")?, tag: switch.client.inner().tag.clone(), }; - switch - .client - .link_ipv4_create(&port_id, &link_id, &entry) - .await - .unwrap(); + switch.client.link_ipv4_create(&port_id, &link_id, &entry).await.unwrap(); let mut send_pkt = common::gen_ipv4_ping(icmp::ICMP_ECHO, 0, from, to); let mut recv_pkt = common::gen_ipv4_ping(icmp::ICMP_ECHOREPLY, 0, to, from); if add_vlan { - let vlan_hdr = eth::EthQHdr { - eth_pcp: 0, - eth_dei: 0, - eth_vlan_tag: 200, - }; + let vlan_hdr = + eth::EthQHdr { eth_pcp: 0, eth_dei: 0, eth_vlan_tag: 200 }; send_pkt.hdrs.eth_hdr.as_mut().unwrap().eth_8021q = Some(vlan_hdr.clone()); recv_pkt.hdrs.eth_hdr.as_mut().unwrap().eth_8021q = Some(vlan_hdr.clone()); } - let send = TestPacket { - packet: Arc::new(send_pkt), - port, - }; + let send = TestPacket { packet: Arc::new(send_pkt), port }; - let recv = TestPacket { - packet: Arc::new(recv_pkt), - port, - }; + let recv = TestPacket { packet: Arc::new(recv_pkt), port }; if enable_nat_filtering { // Mark the port as NAT-only @@ -187,18 +168,12 @@ async fn execute_ping_ipv4_forward_test( let send_pkt = common::gen_ipv4_ping(icmp::ICMP_ECHO, 0, from, to); let mut recv_pkt = send_pkt.clone(); - let send = TestPacket { - packet: Arc::new(send_pkt), - port: ingress, - }; + let send = TestPacket { packet: Arc::new(send_pkt), port: ingress }; eth::EthHdr::rewrite_smac(&mut recv_pkt, switch_mac); eth::EthHdr::rewrite_dmac(&mut recv_pkt, router_mac); ipv4::Ipv4Hdr::adjust_ttl(&mut recv_pkt, -1); - let recv = TestPacket { - packet: Arc::new(recv_pkt), - port: egress, - }; + let recv = TestPacket { packet: Arc::new(recv_pkt), port: egress }; if enable_nat_filtering { // Mark the port as NAT-only diff --git a/dpd-client/tests/integration_tests/loopback.rs b/dpd-client/tests/integration_tests/loopback.rs index 07f03d1..42680fa 100644 --- a/dpd-client/tests/integration_tests/loopback.rs +++ b/dpd-client/tests/integration_tests/loopback.rs @@ -21,19 +21,13 @@ async fn test_api() -> TestResult { switch .client - .loopback_ipv4_create(&Ipv4Entry { - tag: "test".into(), - addr: lo4, - }) + .loopback_ipv4_create(&Ipv4Entry { tag: "test".into(), addr: lo4 }) .await .expect("Should be able to create IPv4 loopback addr"); switch .client - .loopback_ipv6_create(&Ipv6Entry { - tag: "test".into(), - addr: lo6, - }) + .loopback_ipv6_create(&Ipv6Entry { tag: "test".into(), addr: lo6 }) .await .expect("Should be able to create IPv6 loopback addr"); @@ -53,19 +47,13 @@ async fn test_api() -> TestResult { switch .client - .loopback_ipv4_create(&Ipv4Entry { - tag: "test".into(), - addr: lo4, - }) + .loopback_ipv4_create(&Ipv4Entry { tag: "test".into(), addr: lo4 }) .await .expect("IPv4 loopback add should be idempotent"); switch .client - .loopback_ipv6_create(&Ipv6Entry { - tag: "test".into(), - addr: lo6, - }) + .loopback_ipv6_create(&Ipv6Entry { tag: "test".into(), addr: lo6 }) .await .expect("IPv6 loopback add should be idempotent"); diff --git a/dpd-client/tests/integration_tests/mcast.rs b/dpd-client/tests/integration_tests/mcast.rs index 5a4a586..4b05b8b 100644 --- a/dpd-client/tests/integration_tests/mcast.rs +++ b/dpd-client/tests/integration_tests/mcast.rs @@ -246,8 +246,7 @@ fn get_nat_target( match response { types::MulticastGroupResponse::Underlay { .. } => None, types::MulticastGroupResponse::External { - internal_forwarding, - .. + internal_forwarding, .. } => internal_forwarding.nat_target.as_ref(), } } @@ -372,10 +371,8 @@ fn prepare_expected_pkt( encapped.deparse().unwrap().to_vec() }; - let switch_port_mac = switch - .get_port_mac(switch_port.unwrap()) - .unwrap() - .to_string(); + let switch_port_mac = + switch.get_port_mac(switch_port.unwrap()).unwrap().to_string(); let mut forward_pkt = common::gen_external_geneve_packet( Endpoint::parse( @@ -766,9 +763,8 @@ async fn test_group_api_lifecycle() { .await .expect("Should be able to list groups"); - let found_in_list = groups - .iter() - .any(|g| get_external_group_id(g) == external_group_id); + let found_in_list = + groups.iter().any(|g| get_external_group_id(g) == external_group_id); assert!(found_in_list, "Created group should be in the list"); // Get groups by tag @@ -779,10 +775,7 @@ async fn test_group_api_lifecycle() { .await .expect("Should be able to get groups by tag"); - assert!( - !tagged_groups.is_empty(), - "Tagged group list should not be empty" - ); + assert!(!tagged_groups.is_empty(), "Tagged group list should not be empty"); let found_by_tag = tagged_groups .iter() .any(|g| get_external_group_id(g) == external_group_id); @@ -878,9 +871,8 @@ async fn test_group_api_lifecycle() { .expect("Should be able to list groups"); // Check if the specific deleted group is still in the list - let deleted_group_still_in_list = groups_after_delete - .iter() - .any(|g| get_group_ip(g) == group_ip); + let deleted_group_still_in_list = + groups_after_delete.iter().any(|g| get_group_ip(g) == group_ip); assert!( !deleted_group_still_in_list, "Deleted group should not be in the list" @@ -1299,12 +1291,8 @@ async fn test_api_invalid_combinations() -> TestResult { ), } - cleanup_test_group(switch, created_ipv4.group_ip) - .await - .unwrap(); - cleanup_test_group(switch, created_non_admin.group_ip) - .await - .unwrap(); + cleanup_test_group(switch, created_ipv4.group_ip).await.unwrap(); + cleanup_test_group(switch, created_non_admin.group_ip).await.unwrap(); cleanup_test_group(switch, internal_multicast_ip).await } @@ -1377,18 +1365,13 @@ async fn test_ipv4_multicast_invalid_destination_mac() -> TestResult { // Generate packet with invalid MAC let to_send = common::gen_udp_packet(src_endpoint, dst_endpoint); - let test_pkt = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let test_pkt = TestPacket { packet: Arc::new(to_send), port: ingress }; // Expect no output packets (invalid MAC should be dropped) let expected_pkts = vec![]; - let ctr_baseline = switch - .get_counter("multicast_invalid_mac", None) - .await - .unwrap(); + let ctr_baseline = + switch.get_counter("multicast_invalid_mac", None).await.unwrap(); switch.packet_test(vec![test_pkt], expected_pkts).unwrap(); @@ -1403,9 +1386,7 @@ async fn test_ipv4_multicast_invalid_destination_mac() -> TestResult { .unwrap(); // Cleanup: Remove both external IPv4 group and underlay IPv6 group - cleanup_test_group(switch, get_group_ip(&created_group)) - .await - .unwrap(); + cleanup_test_group(switch, get_group_ip(&created_group)).await.unwrap(); cleanup_test_group(switch, internal_multicast_ip).await } @@ -1453,18 +1434,13 @@ async fn test_ipv6_multicast_invalid_destination_mac() -> TestResult { // Generate packet with invalid MAC let to_send = common::gen_udp_packet(src_endpoint, dst_endpoint); - let test_pkt = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let test_pkt = TestPacket { packet: Arc::new(to_send), port: ingress }; // Expect no output packets (invalid MAC should be dropped) let expected_pkts = vec![]; - let ctr_baseline = switch - .get_counter("multicast_invalid_mac", None) - .await - .unwrap(); + let ctr_baseline = + switch.get_counter("multicast_invalid_mac", None).await.unwrap(); let port_label_ingress = switch.port_label(ingress).unwrap(); @@ -1555,10 +1531,7 @@ async fn test_multicast_ttl_zero() -> TestResult { // Set TTL to 0 (should be dropped) ipv4::Ipv4Hdr::adjust_ttl(&mut to_send, -255); // Set to 0 - let test_pkt = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let test_pkt = TestPacket { packet: Arc::new(to_send), port: ingress }; // Expect no output packets (should be dropped due to TTL=0) let expected_pkts = vec![]; @@ -1578,9 +1551,7 @@ async fn test_multicast_ttl_zero() -> TestResult { .await .unwrap(); - cleanup_test_group(switch, get_group_ip(&created_group)) - .await - .unwrap(); + cleanup_test_group(switch, get_group_ip(&created_group)).await.unwrap(); cleanup_test_group(switch, internal_multicast_ip).await } @@ -1639,10 +1610,7 @@ async fn test_multicast_ttl_one() -> TestResult { // because the switch decrements it to 0 during processing ipv4::Ipv4Hdr::adjust_ttl(&mut to_send, -254); // Set to 1 - let test_pkt = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let test_pkt = TestPacket { packet: Arc::new(to_send), port: ingress }; // Expect no output packets (should be dropped due to TTL=1) let expected_pkts = vec![]; @@ -1662,9 +1630,7 @@ async fn test_multicast_ttl_one() -> TestResult { .await .unwrap(); - cleanup_test_group(switch, get_group_ip(&created_group)) - .await - .unwrap(); + cleanup_test_group(switch, get_group_ip(&created_group)).await.unwrap(); cleanup_test_group(switch, internal_multicast_ip).await } @@ -1765,28 +1731,17 @@ async fn test_ipv4_multicast_basic_replication_nat_ingress() -> TestResult { Some(egress3), ); - let test_pkt = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let test_pkt = TestPacket { packet: Arc::new(to_send), port: ingress }; let expected_pkts = vec![ - TestPacket { - packet: Arc::new(to_recv1), - port: egress1, - }, - TestPacket { - packet: Arc::new(to_recv2), - port: egress3, - }, + TestPacket { packet: Arc::new(to_recv1), port: egress1 }, + TestPacket { packet: Arc::new(to_recv2), port: egress3 }, ]; let port_label_ingress = switch.port_label(ingress).unwrap(); - let ctr_baseline_ingress = switch - .get_counter(&port_label_ingress, Some("ingress")) - .await - .unwrap(); + let ctr_baseline_ingress = + switch.get_counter(&port_label_ingress, Some("ingress")).await.unwrap(); switch.packet_test(vec![test_pkt], expected_pkts).unwrap(); @@ -1902,30 +1857,19 @@ async fn test_encapped_multicast_geneve_mcast_tag_to_external_members() &payload, ); - let test_pkt = TestPacket { - packet: Arc::new(geneve_pkt), - port: ingress, - }; + let test_pkt = TestPacket { packet: Arc::new(geneve_pkt), port: ingress }; // We expect the packet to be decapsulated and forwarded to both egress // ports let expected_pkts = vec![ - TestPacket { - packet: Arc::new(expected_pkt1), - port: egress1, - }, - TestPacket { - packet: Arc::new(expected_pkt2), - port: egress2, - }, + TestPacket { packet: Arc::new(expected_pkt1), port: egress1 }, + TestPacket { packet: Arc::new(expected_pkt2), port: egress2 }, ]; let port_label_ingress = switch.port_label(ingress).unwrap(); - let ctr_baseline_ingress = switch - .get_counter(&port_label_ingress, Some("ingress")) - .await - .unwrap(); + let ctr_baseline_ingress = + switch.get_counter(&port_label_ingress, Some("ingress")).await.unwrap(); switch.packet_test(vec![test_pkt], expected_pkts).unwrap(); @@ -1939,9 +1883,7 @@ async fn test_encapped_multicast_geneve_mcast_tag_to_external_members() .await .unwrap(); - cleanup_test_group(switch, get_group_ip(&created_group)) - .await - .unwrap(); + cleanup_test_group(switch, get_group_ip(&created_group)).await.unwrap(); cleanup_test_group(switch, MULTICAST_NAT_IP.into()).await } @@ -2035,10 +1977,8 @@ async fn test_encapped_multicast_geneve_mcast_tag_to_underlay_members() &payload, ); - let test_pkt = TestPacket { - packet: Arc::new(geneve_pkt.clone()), - port: ingress, - }; + let test_pkt = + TestPacket { packet: Arc::new(geneve_pkt.clone()), port: ingress }; // Vlan should be stripped and we only replicate to underlay ports let recv_pkt1 = @@ -2049,22 +1989,14 @@ async fn test_encapped_multicast_geneve_mcast_tag_to_underlay_members() // We expect the packet not be decapped and forwarded to both egress // ports let expected_pkts = vec![ - TestPacket { - packet: Arc::new(recv_pkt1), - port: egress3, - }, - TestPacket { - packet: Arc::new(recv_pkt2), - port: egress4, - }, + TestPacket { packet: Arc::new(recv_pkt1), port: egress3 }, + TestPacket { packet: Arc::new(recv_pkt2), port: egress4 }, ]; let port_label_ingress = switch.port_label(ingress).unwrap(); - let ctr_baseline_ingress = switch - .get_counter(&port_label_ingress, Some("ingress")) - .await - .unwrap(); + let ctr_baseline_ingress = + switch.get_counter(&port_label_ingress, Some("ingress")).await.unwrap(); switch.packet_test(vec![test_pkt], expected_pkts).unwrap(); @@ -2078,9 +2010,7 @@ async fn test_encapped_multicast_geneve_mcast_tag_to_underlay_members() .await .unwrap(); - cleanup_test_group(switch, get_group_ip(&created_group)) - .await - .unwrap(); + cleanup_test_group(switch, get_group_ip(&created_group)).await.unwrap(); cleanup_test_group(switch, MULTICAST_NAT_IP.into()).await } @@ -2178,10 +2108,8 @@ async fn test_encapped_multicast_geneve_mcast_tag_to_underlay_and_external_membe &payload, ); - let test_pkt = TestPacket { - packet: Arc::new(geneve_pkt.clone()), - port: ingress, - }; + let test_pkt = + TestPacket { packet: Arc::new(geneve_pkt.clone()), port: ingress }; // External ports should be replicated with Vlan information let recv_pkt1 = @@ -2199,30 +2127,16 @@ async fn test_encapped_multicast_geneve_mcast_tag_to_underlay_and_external_membe // We expect 2 packets to be decapped and forwarded to external ports // and 2 packets to be forwarded to underlay ports (still encapped) let expected_pkts = vec![ - TestPacket { - packet: Arc::new(recv_pkt1), - port: egress1, - }, - TestPacket { - packet: Arc::new(recv_pkt2), - port: egress2, - }, - TestPacket { - packet: Arc::new(recv_pkt3), - port: egress3, - }, - TestPacket { - packet: Arc::new(recv_pkt4), - port: egress4, - }, + TestPacket { packet: Arc::new(recv_pkt1), port: egress1 }, + TestPacket { packet: Arc::new(recv_pkt2), port: egress2 }, + TestPacket { packet: Arc::new(recv_pkt3), port: egress3 }, + TestPacket { packet: Arc::new(recv_pkt4), port: egress4 }, ]; let port_label_ingress = switch.port_label(ingress).unwrap(); - let ctr_baseline_ingress = switch - .get_counter(&port_label_ingress, Some("ingress")) - .await - .unwrap(); + let ctr_baseline_ingress = + switch.get_counter(&port_label_ingress, Some("ingress")).await.unwrap(); switch.packet_test(vec![test_pkt], expected_pkts).unwrap(); @@ -2236,9 +2150,7 @@ async fn test_encapped_multicast_geneve_mcast_tag_to_underlay_and_external_membe .await .unwrap(); - cleanup_test_group(switch, get_group_ip(&created_group)) - .await - .unwrap(); + cleanup_test_group(switch, get_group_ip(&created_group)).await.unwrap(); cleanup_test_group(switch, MULTICAST_NAT_IP.into()).await } @@ -2292,19 +2204,14 @@ async fn test_ipv4_multicast_drops_ingress_is_egress_port() -> TestResult { dst_port, ); - let test_pkt = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let test_pkt = TestPacket { packet: Arc::new(to_send), port: ingress }; let expected_pkts = vec![]; let port_label_ingress = switch.port_label(ingress).unwrap(); - let ctr_baseline_ingress = switch - .get_counter(&port_label_ingress, Some("ingress")) - .await - .unwrap(); + let ctr_baseline_ingress = + switch.get_counter(&port_label_ingress, Some("ingress")).await.unwrap(); switch.packet_test(vec![test_pkt], expected_pkts).unwrap(); @@ -2318,9 +2225,7 @@ async fn test_ipv4_multicast_drops_ingress_is_egress_port() -> TestResult { .await .unwrap(); - cleanup_test_group(switch, get_group_ip(&created_group)) - .await - .unwrap(); + cleanup_test_group(switch, get_group_ip(&created_group)).await.unwrap(); cleanup_test_group(switch, internal_multicast_ip).await } @@ -2379,10 +2284,7 @@ async fn test_ipv6_multicast_hop_limit_zero() -> TestResult { // Set Hop Limit to 0 (should be dropped) ipv6::Ipv6Hdr::adjust_hlim(&mut to_send, -255); // Set to 0 - let test_pkt = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let test_pkt = TestPacket { packet: Arc::new(to_send), port: ingress }; // Expect no output packets (should be dropped due to Hop Limit=0) let expected_pkts = vec![]; @@ -2392,9 +2294,7 @@ async fn test_ipv6_multicast_hop_limit_zero() -> TestResult { switch.packet_test(vec![test_pkt], expected_pkts).unwrap(); - cleanup_test_group(switch, get_group_ip(&created_group)) - .await - .unwrap(); + cleanup_test_group(switch, get_group_ip(&created_group)).await.unwrap(); check_counter_incremented( switch, @@ -2468,10 +2368,7 @@ async fn test_ipv6_multicast_hop_limit_one() -> TestResult { // because the switch decrements it to 0 during processing ipv6::Ipv6Hdr::adjust_hlim(&mut to_send, -254); // Set to 1 (255 - 254 = 1) - let test_pkt = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let test_pkt = TestPacket { packet: Arc::new(to_send), port: ingress }; // Expect no output packets (should be dropped due to Hop Limit=1) let expected_pkts = vec![]; @@ -2563,22 +2460,15 @@ async fn test_ipv6_multicast_basic_replication_nat_ingress() -> TestResult { Some(egress1), ); - let test_pkt = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let test_pkt = TestPacket { packet: Arc::new(to_send), port: ingress }; - let expected_pkts = vec![TestPacket { - packet: Arc::new(to_recv1), - port: egress1, - }]; + let expected_pkts = + vec![TestPacket { packet: Arc::new(to_recv1), port: egress1 }]; let port_label_ingress = switch.port_label(ingress).unwrap(); - let ctr_baseline_ingress = switch - .get_counter(&port_label_ingress, Some("ingress")) - .await - .unwrap(); + let ctr_baseline_ingress = + switch.get_counter(&port_label_ingress, Some("ingress")).await.unwrap(); switch.packet_test(vec![test_pkt], expected_pkts).unwrap(); @@ -2679,32 +2569,18 @@ async fn test_ipv4_multicast_source_filtering_exact_match() -> TestResult { ); let test_pkts = vec![ - TestPacket { - packet: Arc::new(allowed_pkt), - port: ingress1, - }, - TestPacket { - packet: Arc::new(filtered_pkt), - port: ingress2, - }, + TestPacket { packet: Arc::new(allowed_pkt), port: ingress1 }, + TestPacket { packet: Arc::new(filtered_pkt), port: ingress2 }, ]; // Only expect packets from the allowed source let expected_pkts = vec![ - TestPacket { - packet: Arc::new(to_recv11), - port: egress1, - }, - TestPacket { - packet: Arc::new(to_recv12), - port: egress2, - }, + TestPacket { packet: Arc::new(to_recv11), port: egress1 }, + TestPacket { packet: Arc::new(to_recv12), port: egress2 }, ]; - let ctr_baseline = switch - .get_counter("multicast_src_filtered", None) - .await - .unwrap(); + let ctr_baseline = + switch.get_counter("multicast_src_filtered", None).await.unwrap(); switch.packet_test(test_pkts, expected_pkts).unwrap(); @@ -2718,9 +2594,7 @@ async fn test_ipv4_multicast_source_filtering_exact_match() -> TestResult { .await .unwrap(); - cleanup_test_group(switch, get_group_ip(&created_group)) - .await - .unwrap(); + cleanup_test_group(switch, get_group_ip(&created_group)).await.unwrap(); cleanup_test_group(switch, internal_multicast_ip).await } @@ -2836,44 +2710,21 @@ async fn test_ipv4_multicast_source_filtering_prefix_match() -> TestResult { ); let test_pkts = vec![ - TestPacket { - packet: Arc::new(allowed_pkt1), - port: ingress1, - }, - TestPacket { - packet: Arc::new(allowed_pkt2), - port: ingress2, - }, - TestPacket { - packet: Arc::new(filtered_pkt), - port: ingress2, - }, + TestPacket { packet: Arc::new(allowed_pkt1), port: ingress1 }, + TestPacket { packet: Arc::new(allowed_pkt2), port: ingress2 }, + TestPacket { packet: Arc::new(filtered_pkt), port: ingress2 }, ]; // Only expect packets from the allowed sources let expected_pkts = vec![ - TestPacket { - packet: Arc::new(to_recv11), - port: egress1, - }, - TestPacket { - packet: Arc::new(to_recv22), - port: egress2, - }, - TestPacket { - packet: Arc::new(to_recv12), - port: egress2, - }, - TestPacket { - packet: Arc::new(to_recv21), - port: egress1, - }, + TestPacket { packet: Arc::new(to_recv11), port: egress1 }, + TestPacket { packet: Arc::new(to_recv22), port: egress2 }, + TestPacket { packet: Arc::new(to_recv12), port: egress2 }, + TestPacket { packet: Arc::new(to_recv21), port: egress1 }, ]; - let ctr_baseline = switch - .get_counter("multicast_src_filtered", None) - .await - .unwrap(); + let ctr_baseline = + switch.get_counter("multicast_src_filtered", None).await.unwrap(); switch.packet_test(test_pkts, expected_pkts).unwrap(); @@ -2887,9 +2738,7 @@ async fn test_ipv4_multicast_source_filtering_prefix_match() -> TestResult { .await .unwrap(); - cleanup_test_group(switch, get_group_ip(&created_group)) - .await - .unwrap(); + cleanup_test_group(switch, get_group_ip(&created_group)).await.unwrap(); cleanup_test_group(switch, internal_multicast_ip).await } @@ -3008,46 +2857,23 @@ async fn test_ipv6_multicast_multiple_source_filtering() -> TestResult { ); let test_pkts = vec![ - TestPacket { - packet: Arc::new(allowed_pkt1), - port: ingress1, - }, - TestPacket { - packet: Arc::new(allowed_pkt2), - port: ingress2, - }, - TestPacket { - packet: Arc::new(filtered_pkt), - port: ingress3, - }, + TestPacket { packet: Arc::new(allowed_pkt1), port: ingress1 }, + TestPacket { packet: Arc::new(allowed_pkt2), port: ingress2 }, + TestPacket { packet: Arc::new(filtered_pkt), port: ingress3 }, ]; // Only expect packets from the allowed sources let expected_pkts = vec![ // First allowed source - TestPacket { - packet: Arc::new(to_recv11), - port: egress1, - }, - TestPacket { - packet: Arc::new(to_recv12), - port: egress2, - }, + TestPacket { packet: Arc::new(to_recv11), port: egress1 }, + TestPacket { packet: Arc::new(to_recv12), port: egress2 }, // Second allowed source - TestPacket { - packet: Arc::new(to_recv21), - port: egress1, - }, - TestPacket { - packet: Arc::new(to_recv22), - port: egress2, - }, + TestPacket { packet: Arc::new(to_recv21), port: egress1 }, + TestPacket { packet: Arc::new(to_recv22), port: egress2 }, ]; - let ctr_baseline = switch - .get_counter("multicast_src_filtered", None) - .await - .unwrap(); + let ctr_baseline = + switch.get_counter("multicast_src_filtered", None).await.unwrap(); switch.packet_test(test_pkts, expected_pkts).unwrap(); @@ -3061,9 +2887,7 @@ async fn test_ipv6_multicast_multiple_source_filtering() -> TestResult { .await .unwrap(); - cleanup_test_group(switch, get_group_ip(&created_group)) - .await - .unwrap(); + cleanup_test_group(switch, get_group_ip(&created_group)).await.unwrap(); cleanup_test_group(switch, internal_multicast_ip).await } @@ -3137,20 +2961,12 @@ async fn test_multicast_dynamic_membership() -> TestResult { Some(egress2), ); - let test_pkt = TestPacket { - packet: Arc::new(to_send.clone()), - port: ingress, - }; + let test_pkt = + TestPacket { packet: Arc::new(to_send.clone()), port: ingress }; let expected_pkts = vec![ - TestPacket { - packet: Arc::new(to_recv1), - port: egress1, - }, - TestPacket { - packet: Arc::new(to_recv2), - port: egress2, - }, + TestPacket { packet: Arc::new(to_recv1), port: egress1 }, + TestPacket { packet: Arc::new(to_recv2), port: egress2 }, ]; let result1 = switch.packet_test(vec![test_pkt], expected_pkts); @@ -3226,29 +3042,16 @@ async fn test_multicast_dynamic_membership() -> TestResult { Some(egress3), ); - let test_pkt_new = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let test_pkt_new = TestPacket { packet: Arc::new(to_send), port: ingress }; let expected_pkts_new = vec![ - TestPacket { - packet: Arc::new(to_recv1_new), - port: egress2, - }, - TestPacket { - packet: Arc::new(to_recv2_new), - port: egress3, - }, + TestPacket { packet: Arc::new(to_recv1_new), port: egress2 }, + TestPacket { packet: Arc::new(to_recv2_new), port: egress3 }, ]; - switch - .packet_test(vec![test_pkt_new], expected_pkts_new) - .unwrap(); + switch.packet_test(vec![test_pkt_new], expected_pkts_new).unwrap(); - cleanup_test_group(switch, get_group_ip(&created_group)) - .await - .unwrap(); + cleanup_test_group(switch, get_group_ip(&created_group)).await.unwrap(); cleanup_test_group(switch, internal_multicast_ip).await } @@ -3400,61 +3203,27 @@ async fn test_multicast_multiple_groups() -> TestResult { ); let test_pkts = vec![ - TestPacket { - packet: Arc::new(to_send1), - port: ingress, - }, - TestPacket { - packet: Arc::new(to_send2), - port: ingress, - }, + TestPacket { packet: Arc::new(to_send1), port: ingress }, + TestPacket { packet: Arc::new(to_send2), port: ingress }, ]; let expected_pkts = vec![ // First multicast group - replicates to all ports since both groups share same NAT target - TestPacket { - packet: Arc::new(to_recv1_1), - port: egress1, - }, - TestPacket { - packet: Arc::new(to_recv1_2), - port: egress2, - }, - TestPacket { - packet: Arc::new(to_recv1_3), - port: egress3, - }, - TestPacket { - packet: Arc::new(to_recv1_4), - port: egress4, - }, + TestPacket { packet: Arc::new(to_recv1_1), port: egress1 }, + TestPacket { packet: Arc::new(to_recv1_2), port: egress2 }, + TestPacket { packet: Arc::new(to_recv1_3), port: egress3 }, + TestPacket { packet: Arc::new(to_recv1_4), port: egress4 }, // Second multicast group - also replicates to all ports - TestPacket { - packet: Arc::new(to_recv2_3), - port: egress1, - }, - TestPacket { - packet: Arc::new(to_recv2_4), - port: egress2, - }, - TestPacket { - packet: Arc::new(to_recv2_1), - port: egress3, - }, - TestPacket { - packet: Arc::new(to_recv2_2), - port: egress4, - }, + TestPacket { packet: Arc::new(to_recv2_3), port: egress1 }, + TestPacket { packet: Arc::new(to_recv2_4), port: egress2 }, + TestPacket { packet: Arc::new(to_recv2_1), port: egress3 }, + TestPacket { packet: Arc::new(to_recv2_2), port: egress4 }, ]; switch.packet_test(test_pkts, expected_pkts).unwrap(); - cleanup_test_group(switch, get_group_ip(&created_group1)) - .await - .unwrap(); - cleanup_test_group(switch, get_group_ip(&created_group2)) - .await - .unwrap(); + cleanup_test_group(switch, get_group_ip(&created_group1)).await.unwrap(); + cleanup_test_group(switch, get_group_ip(&created_group2)).await.unwrap(); cleanup_test_group(switch, internal_multicast_ip).await } @@ -3758,10 +3527,7 @@ async fn test_multicast_reset_all_tables() -> TestResult { .await .expect("Should be able to list groups"); - assert!( - groups_after.is_empty(), - "No groups should exist after reset" - ); + assert!(groups_after.is_empty(), "No groups should exist after reset"); // Try to get each group specifically for group_ip in [ @@ -3821,9 +3587,7 @@ async fn test_multicast_vlan_translation_not_possible() -> TestResult { types::InternalForwarding { nat_target: Some(create_nat_target_ipv4()), }, // Create NAT target - types::ExternalForwarding { - vlan_id: output_vlan, - }, + types::ExternalForwarding { vlan_id: output_vlan }, None, ) .await; @@ -3841,16 +3605,10 @@ async fn test_multicast_vlan_translation_not_possible() -> TestResult { ); // Add input VLAN tag - to_send.hdrs.eth_hdr.as_mut().unwrap().eth_8021q = Some(eth::EthQHdr { - eth_pcp: 0, - eth_dei: 0, - eth_vlan_tag: input_vlan, - }); + to_send.hdrs.eth_hdr.as_mut().unwrap().eth_8021q = + Some(eth::EthQHdr { eth_pcp: 0, eth_dei: 0, eth_vlan_tag: input_vlan }); - let test_pkt = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let test_pkt = TestPacket { packet: Arc::new(to_send), port: ingress }; // Expect NO packets - this test demonstrates that VLAN translation // is not possible for multicast packets @@ -3858,9 +3616,7 @@ async fn test_multicast_vlan_translation_not_possible() -> TestResult { switch.packet_test(vec![test_pkt], expected_pkts).unwrap(); - cleanup_test_group(switch, get_group_ip(&created_group)) - .await - .unwrap(); + cleanup_test_group(switch, get_group_ip(&created_group)).await.unwrap(); cleanup_test_group(switch, internal_multicast_ip).await } */ @@ -3955,31 +3711,20 @@ async fn test_multicast_multiple_packets() -> TestResult { Some(egress3), ); - test_pkts.push(TestPacket { - packet: Arc::new(to_send), - port: ingress, - }); - - expected_pkts.push(TestPacket { - packet: Arc::new(to_recv1), - port: egress1, - }); - expected_pkts.push(TestPacket { - packet: Arc::new(to_recv2), - port: egress2, - }); - expected_pkts.push(TestPacket { - packet: Arc::new(to_recv3), - port: egress3, - }); + test_pkts.push(TestPacket { packet: Arc::new(to_send), port: ingress }); + + expected_pkts + .push(TestPacket { packet: Arc::new(to_recv1), port: egress1 }); + expected_pkts + .push(TestPacket { packet: Arc::new(to_recv2), port: egress2 }); + expected_pkts + .push(TestPacket { packet: Arc::new(to_recv3), port: egress3 }); } let port_label_ingress = switch.port_label(ingress).unwrap(); - let ctr_baseline_ingress = switch - .get_counter(&port_label_ingress, Some("ingress")) - .await - .unwrap(); + let ctr_baseline_ingress = + switch.get_counter(&port_label_ingress, Some("ingress")).await.unwrap(); switch.packet_test(test_pkts, expected_pkts).unwrap(); @@ -3993,9 +3738,7 @@ async fn test_multicast_multiple_packets() -> TestResult { .await .unwrap(); - cleanup_test_group(switch, get_group_ip(&created_group)) - .await - .unwrap(); + cleanup_test_group(switch, get_group_ip(&created_group)).await.unwrap(); cleanup_test_group(switch, internal_multicast_ip).await } @@ -4015,10 +3758,8 @@ async fn test_multicast_no_group_configured() -> TestResult { let src_mac = switch.get_port_mac(ingress).unwrap(); // Get baseline counter before any test packets - let initial_ctr_baseline = switch - .get_counter("multicast_no_group", None) - .await - .unwrap(); + let initial_ctr_baseline = + switch.get_counter("multicast_no_group", None).await.unwrap(); // Test IPv4 multicast with no configured group { @@ -4030,10 +3771,7 @@ async fn test_multicast_no_group_configured() -> TestResult { 4444, ); - let test_pkt = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let test_pkt = TestPacket { packet: Arc::new(to_send), port: ingress }; let expected_pkts = vec![]; @@ -4063,10 +3801,7 @@ async fn test_multicast_no_group_configured() -> TestResult { 4444, ); - let test_pkt = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let test_pkt = TestPacket { packet: Arc::new(to_send), port: ingress }; // Expect no output packets - should be dropped let expected_pkts = vec![]; @@ -4226,10 +3961,8 @@ async fn test_ipv6_multicast_scope_validation() { }], }; - let admin_local_result = switch - .client - .multicast_group_create_underlay(&admin_local_group) - .await; + let admin_local_result = + switch.client.multicast_group_create_underlay(&admin_local_group).await; assert!( admin_local_result.is_ok(), "Admin-local scope (ff04::/16) should work with internal API" @@ -4246,10 +3979,8 @@ async fn test_ipv6_multicast_scope_validation() { }], }; - let site_local_result = switch - .client - .multicast_group_create_underlay(&site_local_group) - .await; + let site_local_result = + switch.client.multicast_group_create_underlay(&site_local_group).await; assert!( site_local_result.is_ok(), "Site-local scope (ff05::/16) should work with internal API" @@ -4266,10 +3997,8 @@ async fn test_ipv6_multicast_scope_validation() { }], }; - let org_local_result = switch - .client - .multicast_group_create_underlay(&org_local_group) - .await; + let org_local_result = + switch.client.multicast_group_create_underlay(&org_local_group).await; assert!( org_local_result.is_ok(), "Organization-local scope (ff08::/16) should work with internal API" @@ -4405,10 +4134,7 @@ async fn test_multicast_group_id_recycling() -> TestResult { ) .await; - assert_ne!( - get_external_group_id(&group1), - get_external_group_id(&group2) - ); + assert_ne!(get_external_group_id(&group1), get_external_group_id(&group2)); // Delete the first group switch @@ -4425,9 +4151,7 @@ async fn test_multicast_group_id_recycling() -> TestResult { .await .expect("Should be able to list groups"); assert!( - !groups_after_delete1 - .iter() - .any(|g| get_group_ip(g) == group1_ip), + !groups_after_delete1.iter().any(|g| get_group_ip(g) == group1_ip), "Group1 should be deleted" ); @@ -4466,9 +4190,7 @@ async fn test_multicast_group_id_recycling() -> TestResult { .await .expect("Should be able to list groups"); assert!( - !groups_after_delete2 - .iter() - .any(|g| get_group_ip(g) == group2_ip), + !groups_after_delete2.iter().any(|g| get_group_ip(g) == group2_ip), "Group2 should be deleted" ); @@ -4564,15 +4286,11 @@ async fn test_multicast_empty_then_add_members_ipv6() -> TestResult { .expect("Should find the created external group"); assert!( - get_members(internal_group) - .map(|m| m.is_empty()) - .unwrap_or(true), + get_members(internal_group).map(|m| m.is_empty()).unwrap_or(true), "Empty internal group should have no members initially" ); assert!( - get_members(external_group) - .map(|m| m.is_empty()) - .unwrap_or(true), + get_members(external_group).map(|m| m.is_empty()).unwrap_or(true), "Empty external group should have no members initially" ); @@ -4615,10 +4333,8 @@ async fn test_multicast_empty_then_add_members_ipv6() -> TestResult { &payload, ); - let send = TestPacket { - packet: Arc::new(geneve_pkt.clone()), - port: ingress_port, - }; + let send = + TestPacket { packet: Arc::new(geneve_pkt.clone()), port: ingress_port }; // Verify no packets are replicated when group is empty switch.packet_test(vec![send], Vec::new())?; @@ -4759,24 +4475,13 @@ async fn test_multicast_empty_then_add_members_ipv6() -> TestResult { Some(egress3), ); - let send_again = TestPacket { - packet: Arc::new(to_send_again), - port: ingress_port, - }; + let send_again = + TestPacket { packet: Arc::new(to_send_again), port: ingress_port }; let expected_pkts = vec![ - TestPacket { - packet: Arc::new(expected1), - port: egress1, - }, - TestPacket { - packet: Arc::new(expected2), - port: egress2, - }, - TestPacket { - packet: Arc::new(expected3), - port: egress3, - }, + TestPacket { packet: Arc::new(expected1), port: egress1 }, + TestPacket { packet: Arc::new(expected2), port: egress2 }, + TestPacket { packet: Arc::new(expected3), port: egress3 }, ]; // Verify packets are now replicated to all 3 members (2 external + 1 underlay) @@ -4842,19 +4547,15 @@ async fn test_multicast_empty_then_add_members_ipv6() -> TestResult { "Bitmap table should be empty again when group has no members" ); - let send_final = TestPacket { - packet: Arc::new(to_send_final), - port: ingress_port, - }; + let send_final = + TestPacket { packet: Arc::new(to_send_final), port: ingress_port }; // Should only see packet on ingress, no replication to egress ports let expected_final = vec![]; switch.packet_test(vec![send_final], expected_final)?; - cleanup_test_group(&switch, external_group_ip) - .await - .unwrap(); + cleanup_test_group(&switch, external_group_ip).await.unwrap(); cleanup_test_group(&switch, internal_group_ip).await } @@ -4924,15 +4625,11 @@ async fn test_multicast_empty_then_add_members_ipv4() -> TestResult { .expect("Should find the created external group"); assert!( - get_members(internal_group) - .map(|m| m.is_empty()) - .unwrap_or(true), + get_members(internal_group).map(|m| m.is_empty()).unwrap_or(true), "Empty internal group should have no members initially" ); assert!( - get_members(external_group) - .map(|m| m.is_empty()) - .unwrap_or(true), + get_members(external_group).map(|m| m.is_empty()).unwrap_or(true), "Empty external group should have no members initially" ); @@ -4975,10 +4672,8 @@ async fn test_multicast_empty_then_add_members_ipv4() -> TestResult { &payload, ); - let send = TestPacket { - packet: Arc::new(geneve_pkt.clone()), - port: ingress_port, - }; + let send = + TestPacket { packet: Arc::new(geneve_pkt.clone()), port: ingress_port }; // Verify no packets are replicated when group is empty switch.packet_test(vec![send], Vec::new())?; @@ -5118,24 +4813,13 @@ async fn test_multicast_empty_then_add_members_ipv4() -> TestResult { Some(egress3), ); - let send_again = TestPacket { - packet: Arc::new(test_packet2), - port: ingress_port, - }; + let send_again = + TestPacket { packet: Arc::new(test_packet2), port: ingress_port }; let expected_pkts = vec![ - TestPacket { - packet: Arc::new(expected1), - port: egress1, - }, - TestPacket { - packet: Arc::new(expected2), - port: egress2, - }, - TestPacket { - packet: Arc::new(expected3), - port: egress3, - }, + TestPacket { packet: Arc::new(expected1), port: egress1 }, + TestPacket { packet: Arc::new(expected2), port: egress2 }, + TestPacket { packet: Arc::new(expected3), port: egress3 }, ]; // Verify packets are now replicated to all 3 members via NAT target @@ -5203,19 +4887,15 @@ async fn test_multicast_empty_then_add_members_ipv4() -> TestResult { ); // Test: Send packet again - should now only reach ingress (no replication) - let send_final = TestPacket { - packet: Arc::new(to_send_final), - port: ingress_port, - }; + let send_final = + TestPacket { packet: Arc::new(to_send_final), port: ingress_port }; // Should only see packet on ingress, no replication to egress ports let expected_final = vec![]; switch.packet_test(vec![send_final], expected_final)?; - cleanup_test_group(&switch, external_group_ip) - .await - .unwrap(); + cleanup_test_group(&switch, external_group_ip).await.unwrap(); cleanup_test_group(&switch, internal_group_ip).await } @@ -5301,16 +4981,11 @@ async fn test_multicast_rollback_external_group_creation_failure() -> TestResult }; // This should fail and trigger rollback - let result = switch - .client - .multicast_group_create_external(&external_entry) - .await; + let result = + switch.client.multicast_group_create_external(&external_entry).await; // Verify the creation failed - assert!( - result.is_err(), - "External group creation should have failed" - ); + assert!(result.is_err(), "External group creation should have failed"); // Verify rollback worked - check that no state was left behind @@ -5407,9 +5082,8 @@ async fn test_multicast_rollback_member_update_failure() -> TestResult { .multicast_group_get(&internal_group_ip) .await .expect("Should be able to get initial group state"); - let initial_member_count = get_members(&initial_group.into_inner()) - .map(|m| m.len()) - .unwrap_or(0); + let initial_member_count = + get_members(&initial_group.into_inner()).map(|m| m.len()).unwrap_or(0); // Try to add a member that should cause ASIC operations to fail // Use a valid port but with an invalid link ID that should cause issues @@ -5448,9 +5122,7 @@ async fn test_multicast_rollback_member_update_failure() -> TestResult { .into_inner(); assert_eq!( - get_members(&post_failure_group) - .map(|m| m.len()) - .unwrap_or(0), + get_members(&post_failure_group).map(|m| m.len()).unwrap_or(0), initial_member_count, "Member count should be unchanged after rollback" ); @@ -5549,11 +5221,10 @@ async fn test_multicast_rollback_nat_transition_failure() -> TestResult { assert!(result.is_err(), "NAT update should have failed"); // Verify rollback worked - external group should be unchanged - let post_failure_external_group = switch - .client - .multicast_group_get(&external_group_ip) - .await - .expect("Should be able to get external group state after rollback"); + let post_failure_external_group = + switch.client.multicast_group_get(&external_group_ip).await.expect( + "Should be able to get external group state after rollback", + ); // NAT target should be unchanged let initial_group_inner = initial_external_group.into_inner(); @@ -5562,14 +5233,8 @@ async fn test_multicast_rollback_nat_transition_failure() -> TestResult { let initial_nat = get_nat_target(&initial_group_inner); let current_nat = get_nat_target(&post_failure_group_inner); - assert!( - initial_nat.is_some(), - "Initial group should have NAT target" - ); - assert!( - current_nat.is_some(), - "Current group should have NAT target" - ); + assert!(initial_nat.is_some(), "Initial group should have NAT target"); + assert!(current_nat.is_some(), "Current group should have NAT target"); if let (Some(original), Some(current)) = (initial_nat, current_nat) { assert_eq!( @@ -5595,9 +5260,7 @@ async fn test_multicast_rollback_nat_transition_failure() -> TestResult { "NAT table should be unchanged after rollback" ); - cleanup_test_group(&switch, external_group_ip) - .await - .unwrap(); + cleanup_test_group(&switch, external_group_ip).await.unwrap(); cleanup_test_group(&switch, internal_group_ip).await } @@ -5670,10 +5333,8 @@ async fn test_multicast_rollback_vlan_propagation_consistency() { }; // This should fail because the NAT target (internal group) no longer exists - let result = switch - .client - .multicast_group_create_external(&external_entry) - .await; + let result = + switch.client.multicast_group_create_external(&external_entry).await; assert!( result.is_err(), @@ -5865,9 +5526,8 @@ async fn test_multicast_rollback_partial_member_addition() -> TestResult { .multicast_group_get(&internal_group_ip) .await .expect("Should be able to get initial group state"); - let initial_member_count = get_members(&initial_group.into_inner()) - .map(|m| m.len()) - .unwrap_or(0); + let initial_member_count = + get_members(&initial_group.into_inner()).map(|m| m.len()).unwrap_or(0); // Create a mix of valid and invalid members to trigger partial addition failure let (valid_port_1, valid_link_1) = switch.link_id(PhysPort(17)).unwrap(); @@ -5926,9 +5586,7 @@ async fn test_multicast_rollback_partial_member_addition() -> TestResult { .into_inner(); assert_eq!( - get_members(&post_failure_group) - .map(|m| m.len()) - .unwrap_or(0), + get_members(&post_failure_group).map(|m| m.len()).unwrap_or(0), initial_member_count, "Member count should be unchanged after partial addition rollback" ); @@ -6003,10 +5661,8 @@ async fn test_multicast_rollback_table_operation_failure() { }; // This should fail because the NAT target (internal group) doesn't exist - let result = switch - .client - .multicast_group_create_external(&external_entry) - .await; + let result = + switch.client.multicast_group_create_external(&external_entry).await; // Verify the creation failed assert!( @@ -6110,10 +5766,7 @@ async fn test_multicast_group_get_underlay() -> TestResult { // Verify the response matches what we created assert_eq!(retrieved_underlay.group_ip.to_ip_addr(), internal_group_ip); - assert_eq!( - retrieved_underlay.tag, - Some("underlay_get_test".to_string()) - ); + assert_eq!(retrieved_underlay.tag, Some("underlay_get_test".to_string())); assert_eq!(retrieved_underlay.members.len(), 2); // Compare with generic GET endpoint result diff --git a/dpd-client/tests/integration_tests/nat.rs b/dpd-client/tests/integration_tests/nat.rs index 7232f6b..572697e 100644 --- a/dpd-client/tests/integration_tests/nat.rs +++ b/dpd-client/tests/integration_tests/nat.rs @@ -60,20 +60,11 @@ async fn test_api() -> TestResult { .nat_ipv4_create(&ext0, 2000, 2000, &tgt) .await .expect_err("Should not be able to add overlapping NAT entry"); - switch - .client - .nat_ipv4_create(&ext0, 8192, 4096, &tgt) - .await - .expect_err( - "Should not be able to add NAT entry with invalid port range", - ); + switch.client.nat_ipv4_create(&ext0, 8192, 4096, &tgt).await.expect_err( + "Should not be able to add NAT entry with invalid port range", + ); assert_eq!( - switch - .client - .nat_ipv4_get(&ext0, 2048) - .await - .unwrap() - .into_inner(), + switch.client.nat_ipv4_get(&ext0, 2048).await.unwrap().into_inner(), tgt, "Failed to retrieve existing NAT entry", ); @@ -214,11 +205,7 @@ async fn test_nat_egress(switch: &Switch, test: &NatTest) -> TestResult { addr: gimlet_port_ip, tag: switch.client.inner().tag.clone(), }; - switch - .client - .link_ipv6_create(&port_id, &link_id, &entry) - .await - .unwrap(); + switch.client.link_ipv6_create(&port_id, &link_id, &entry).await.unwrap(); if test.router_ip.parse::().is_ok() { common::set_route_ipv4( @@ -310,14 +297,9 @@ async fn test_nat_egress(switch: &Switch, test: &NatTest) -> TestResult { common::gen_packet_routed(switch, test.uplink_port, &payload_pkt); eth::EthHdr::rewrite_dmac(&mut to_recv, router_mac); - let send = TestPacket { - packet: Arc::new(to_send), - port: test.gimlet_port, - }; - let expected = TestPacket { - packet: Arc::new(to_recv), - port: test.uplink_port, - }; + let send = TestPacket { packet: Arc::new(to_send), port: test.gimlet_port }; + let expected = + TestPacket { packet: Arc::new(to_recv), port: test.uplink_port }; switch.packet_test(vec![send], vec![expected]) } @@ -330,11 +312,7 @@ async fn test_nat_ingress(switch: &Switch, test: &NatTest) -> TestResult { addr: gimlet_port_ip, tag: switch.client.inner().tag.clone(), }; - switch - .client - .link_ipv6_create(&port_id, &link_id, &entry) - .await - .unwrap(); + switch.client.link_ipv6_create(&port_id, &link_id, &entry).await.unwrap(); let cidr = Ipv6Net::new(test.gimlet_ip.parse().unwrap(), 64).unwrap(); let route = types::Ipv6RouteUpdate { cidr, @@ -453,20 +431,14 @@ async fn test_nat_ingress(switch: &Switch, test: &NatTest) -> TestResult { forward_icmp_pkt.hdrs.udp_hdr.as_mut().unwrap().udp_sum = 0; let send = vec![ - TestPacket { - packet: Arc::new(ingress_pkt), - port: test.uplink_port, - }, + TestPacket { packet: Arc::new(ingress_pkt), port: test.uplink_port }, TestPacket { packet: Arc::new(ingress_icmp_pkt), port: test.uplink_port, }, ]; let expected = vec![ - TestPacket { - packet: Arc::new(forward_pkt), - port: test.gimlet_port, - }, + TestPacket { packet: Arc::new(forward_pkt), port: test.gimlet_port }, TestPacket { packet: Arc::new(forward_icmp_pkt), port: test.gimlet_port, diff --git a/dpd-client/tests/integration_tests/port_api.rs b/dpd-client/tests/integration_tests/port_api.rs index 1c20028..3fb5569 100644 --- a/dpd-client/tests/integration_tests/port_api.rs +++ b/dpd-client/tests/integration_tests/port_api.rs @@ -52,12 +52,7 @@ async fn test_bad_port() -> TestResult { async fn test_list_all_links() -> TestResult { let switch = &*get_switch().await; let mut expected_links: Vec<_> = switch.iter_links().collect(); - let links = switch - .client - .link_list_all(None) - .await - .unwrap() - .into_inner(); + let links = switch.client.link_list_all(None).await.unwrap().into_inner(); for link in links { let ix = expected_links .iter() @@ -134,11 +129,7 @@ async fn test_ipv4_set() -> TestResult { // Add one address at a time, assert we get back the new set. let entry = switch.client.ipv4_entry(a); - switch - .client - .link_ipv4_create(&port_id, &link_id, &entry) - .await - .unwrap(); + switch.client.link_ipv4_create(&port_id, &link_id, &entry).await.unwrap(); let l = switch .client .link_ipv4_list_stream(&port_id, &link_id, None) @@ -149,11 +140,7 @@ async fn test_ipv4_set() -> TestResult { addr_compare(vec![a], l).unwrap(); let entry = switch.client.ipv4_entry(b); - switch - .client - .link_ipv4_create(&port_id, &link_id, &entry) - .await - .unwrap(); + switch.client.link_ipv4_create(&port_id, &link_id, &entry).await.unwrap(); let l = switch .client .link_ipv4_list_stream(&port_id, &link_id, None) @@ -164,11 +151,7 @@ async fn test_ipv4_set() -> TestResult { addr_compare(vec![a, b], l).unwrap(); let entry = switch.client.ipv4_entry(c); - switch - .client - .link_ipv4_create(&port_id, &link_id, &entry) - .await - .unwrap(); + switch.client.link_ipv4_create(&port_id, &link_id, &entry).await.unwrap(); let l = switch .client .link_ipv4_list_stream(&port_id, &link_id, None) @@ -206,21 +189,9 @@ async fn test_ipv4_clear() -> TestResult { .await .unwrap(); - switch - .client - .link_ipv4_delete(&port_id, &link_id, &a) - .await - .unwrap(); - switch - .client - .link_ipv4_delete(&port_id, &link_id, &b) - .await - .unwrap(); - switch - .client - .link_ipv4_delete(&port_id, &link_id, &c) - .await - .unwrap(); + switch.client.link_ipv4_delete(&port_id, &link_id, &a).await.unwrap(); + switch.client.link_ipv4_delete(&port_id, &link_id, &b).await.unwrap(); + switch.client.link_ipv4_delete(&port_id, &link_id, &c).await.unwrap(); let l = switch .client .link_ipv4_list_stream(&port_id, &link_id, None) @@ -258,11 +229,7 @@ async fn test_ipv4_delete() -> TestResult { .await .unwrap(); - switch - .client - .link_ipv4_delete(&port_id, &link_id, &b) - .await - .unwrap(); + switch.client.link_ipv4_delete(&port_id, &link_id, &b).await.unwrap(); let l = switch .client .link_ipv4_list_stream(&port_id, &link_id, None) @@ -272,11 +239,7 @@ async fn test_ipv4_delete() -> TestResult { .unwrap(); addr_compare(vec![a, c], l).unwrap(); - switch - .client - .link_ipv4_delete(&port_id, &link_id, &a) - .await - .unwrap(); + switch.client.link_ipv4_delete(&port_id, &link_id, &a).await.unwrap(); let l = switch .client .link_ipv4_list_stream(&port_id, &link_id, None) @@ -367,21 +330,9 @@ async fn test_ipv6_clear() -> TestResult { .await .unwrap(); - switch - .client - .link_ipv6_delete(&port_id, &link_id, &a) - .await - .unwrap(); - switch - .client - .link_ipv6_delete(&port_id, &link_id, &b) - .await - .unwrap(); - switch - .client - .link_ipv6_delete(&port_id, &link_id, &c) - .await - .unwrap(); + switch.client.link_ipv6_delete(&port_id, &link_id, &a).await.unwrap(); + switch.client.link_ipv6_delete(&port_id, &link_id, &b).await.unwrap(); + switch.client.link_ipv6_delete(&port_id, &link_id, &c).await.unwrap(); assert!( switch .client @@ -420,11 +371,7 @@ async fn test_ipv6_delete() -> TestResult { .await .unwrap(); - switch - .client - .link_ipv6_delete(&port_id, &link_id, &b) - .await - .unwrap(); + switch.client.link_ipv6_delete(&port_id, &link_id, &b).await.unwrap(); let l = switch .client .link_ipv6_list_stream(&port_id, &link_id, None) @@ -434,11 +381,7 @@ async fn test_ipv6_delete() -> TestResult { .unwrap(); addr_compare(vec![a, c], l).unwrap(); - switch - .client - .link_ipv6_delete(&port_id, &link_id, &a) - .await - .unwrap(); + switch.client.link_ipv6_delete(&port_id, &link_id, &a).await.unwrap(); let l = switch .client .link_ipv6_list_stream(&port_id, &link_id, None) @@ -785,11 +728,7 @@ async fn test_set_mac_on_new_link_succeeds() -> TestResult { .first() .map(Clone::clone) .unwrap(); - switch - .client - .link_delete(&link.port_id, &link.link_id) - .await - .unwrap(); + switch.client.link_delete(&link.port_id, &link.link_id).await.unwrap(); // Put the link back, and then try to set the MAC on it. // @@ -810,9 +749,7 @@ async fn test_set_mac_on_new_link_succeeds() -> TestResult { .unwrap() .into_inner(); let new_mac = types::MacAddr::from( - "a8:40:25:ff:ff:ff" - .parse::() - .unwrap(), + "a8:40:25:ff:ff:ff".parse::().unwrap(), ); switch .client diff --git a/dpd-client/tests/integration_tests/route_ipv4.rs b/dpd-client/tests/integration_tests/route_ipv4.rs index bcd0ee5..e503383 100644 --- a/dpd-client/tests/integration_tests/route_ipv4.rs +++ b/dpd-client/tests/integration_tests/route_ipv4.rs @@ -27,12 +27,7 @@ struct Router { impl Router { pub fn new(port: u16, ip: &str, mac: &str, vlan: Option) -> Self { let mac = mac.parse().unwrap(); - Router { - port, - ip: ip.to_string(), - mac, - vlan, - } + Router { port, ip: ip.to_string(), mac, vlan } } pub fn build_route(&self, switch: &Switch) -> types::Ipv4Route { @@ -118,14 +113,8 @@ async fn test_route_ipv4_unicast_impl(switch: &Switch) -> TestResult { Endpoint::parse("e0:d5:5e:67:89:ac", "10.10.10.11", 4444).unwrap(), ); - let send = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; - let expected = TestPacket { - packet: Arc::new(to_recv), - port: egress, - }; + let send = TestPacket { packet: Arc::new(to_send), port: ingress }; + let expected = TestPacket { packet: Arc::new(to_recv), port: egress }; switch.packet_test(vec![send], vec![expected]) } @@ -154,16 +143,10 @@ async fn test_deleted_route_ipv4_impl(switch: &Switch) -> TestResult { ); let mut to_recv = to_send.clone(); - let send = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let send = TestPacket { packet: Arc::new(to_send), port: ingress }; common::set_icmp_unreachable(switch, &mut to_recv, ingress); - let expected = TestPacket { - packet: Arc::new(to_recv), - port: egress, - }; + let expected = TestPacket { packet: Arc::new(to_recv), port: egress }; switch.packet_test(vec![send], vec![expected]) } @@ -195,22 +178,13 @@ async fn test_route_ipv4_unicast_vlan() -> TestResult { Endpoint::parse("e0:d5:5e:67:89:ac", "10.10.10.11", 4444).unwrap(), ); - let send = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let send = TestPacket { packet: Arc::new(to_send), port: ingress }; // Add the VLAN tag to the expected packet - to_recv.hdrs.eth_hdr.as_mut().unwrap().eth_8021q = Some(EthQHdr { - eth_pcp: 0, - eth_dei: 0, - eth_vlan_tag: vlan, - }); + to_recv.hdrs.eth_hdr.as_mut().unwrap().eth_8021q = + Some(EthQHdr { eth_pcp: 0, eth_dei: 0, eth_vlan_tag: vlan }); - let expected = TestPacket { - packet: Arc::new(to_recv), - port: egress, - }; + let expected = TestPacket { packet: Arc::new(to_recv), port: egress }; switch.packet_test(vec![send], vec![expected]) } @@ -237,14 +211,8 @@ async fn test_updated_route_ipv4() -> TestResult { Endpoint::parse("e0:d5:5e:67:89:ac", "10.10.10.11", 4444).unwrap(), ); - let send = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; - let expected = TestPacket { - packet: Arc::new(to_recv), - port: egress, - }; + let send = TestPacket { packet: Arc::new(to_send), port: ingress }; + let expected = TestPacket { packet: Arc::new(to_recv), port: egress }; switch.packet_test(vec![send], vec![expected]) } @@ -278,16 +246,10 @@ async fn test_route_ipv4_unrouteable() -> TestResult { ); let mut to_recv = to_send.clone(); - let send = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let send = TestPacket { packet: Arc::new(to_send), port: ingress }; common::set_icmp_unreachable(switch, &mut to_recv, ingress); - let expected = TestPacket { - packet: Arc::new(to_recv), - port: egress, - }; + let expected = TestPacket { packet: Arc::new(to_recv), port: egress }; switch.packet_test(vec![send], vec![expected]) } @@ -319,14 +281,8 @@ async fn test_short_hit_ipv4_unicast() -> TestResult { Endpoint::parse("e0:d5:5e:67:89:ac", "10.10.10.11", 4444).unwrap(), ); - let send = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; - let expected = TestPacket { - packet: Arc::new(to_recv), - port: egress, - }; + let send = TestPacket { packet: Arc::new(to_send), port: ingress }; + let expected = TestPacket { packet: Arc::new(to_recv), port: egress }; switch.packet_test(vec![send], vec![expected]) } @@ -357,14 +313,8 @@ async fn test_long_hit_ipv4_unicast() -> TestResult { Endpoint::parse("e0:d5:5e:67:89:ac", "10.10.20.11", 4444).unwrap(), ); - let send = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; - let expected = TestPacket { - packet: Arc::new(to_recv), - port: egress, - }; + let send = TestPacket { packet: Arc::new(to_send), port: ingress }; + let expected = TestPacket { packet: Arc::new(to_recv), port: egress }; switch.packet_test(vec![send], vec![expected]) } @@ -431,10 +381,7 @@ async fn test_create_and_set_semantics_v4() -> TestResult { // Setting a new route should work client.route_ipv4_set(&route_set_47).await?; // Attempting to replace the route with "replace = false" should fail - client - .route_ipv4_set(&route_set_33) - .await - .expect_err("expected conflict"); + client.route_ipv4_set(&route_set_33).await.expect_err("expected conflict"); // Re-setting the existing route should succeed client.route_ipv4_set(&route_set_47).await?; @@ -457,10 +404,8 @@ async fn do_multipath_add( add_route(switch, *subnet, r).await?; } - let routes: Vec = routers - .iter() - .map(|router| router.build_route(switch)) - .collect(); + let routes: Vec = + routers.iter().map(|router| router.build_route(switch)).collect(); // Verify that the set of routes on the switch match those we just set validate_routes(client, subnet, &routes).await } @@ -531,10 +476,8 @@ async fn test_multipath_delete() -> TestResult { ]; do_multipath_add(switch, &cidr, &routers).await?; - let mut routes: Vec = routers - .iter() - .map(|router| router.build_route(switch)) - .collect(); + let mut routes: Vec = + routers.iter().map(|router| router.build_route(switch)).collect(); while let Some(route) = routes.pop() { delete_ipv4_route_target(client, &cidr, &route).await?; validate_routes(client, &cidr, &routes).await?; @@ -582,18 +525,13 @@ async fn test_multipath(switch: &Switch, routers: &[Router]) -> TestResult { Endpoint::parse("e0:d5:5e:67:89:ac", dst_ip, dst_port).unwrap(), ); - let send = TestPacket { - packet: Arc::new(to_send), - port: PhysPort(ingress), - }; + let send = + TestPacket { packet: Arc::new(to_send), port: PhysPort(ingress) }; // Add the VLAN tag to the expected packet if let Some(vlan) = routers[expected_egress].vlan { - to_recv.hdrs.eth_hdr.as_mut().unwrap().eth_8021q = Some(EthQHdr { - eth_pcp: 0, - eth_dei: 0, - eth_vlan_tag: vlan, - }); + to_recv.hdrs.eth_hdr.as_mut().unwrap().eth_8021q = + Some(EthQHdr { eth_pcp: 0, eth_dei: 0, eth_vlan_tag: vlan }); } let expected = TestPacket { diff --git a/dpd-client/tests/integration_tests/route_ipv6.rs b/dpd-client/tests/integration_tests/route_ipv6.rs index c6c81f9..6622a17 100644 --- a/dpd-client/tests/integration_tests/route_ipv6.rs +++ b/dpd-client/tests/integration_tests/route_ipv6.rs @@ -29,12 +29,7 @@ struct Router { impl Router { pub fn new(port: u16, ip: &str, mac: &str, vlan: Option) -> Self { let mac = mac.parse().unwrap(); - Router { - port, - ip: ip.to_string(), - mac, - vlan, - } + Router { port, ip: ip.to_string(), mac, vlan } } pub fn build_route(&self, switch: &Switch) -> types::Ipv6Route { @@ -131,10 +126,7 @@ async fn test_unicast_impl( .unwrap(), ); - let send = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let send = TestPacket { packet: Arc::new(to_send), port: ingress }; // Add the VLAN tag to the expected packet if let Some(vlan) = vlan_id { @@ -145,10 +137,7 @@ async fn test_unicast_impl( eth_vlan_tag: vlan, }); } - let expected = TestPacket { - packet: Arc::new(to_recv), - port: egress, - }; + let expected = TestPacket { packet: Arc::new(to_recv), port: egress }; switch.packet_test(vec![send], vec![expected]) } @@ -176,16 +165,10 @@ async fn test_deleted_unicast_impl(switch: &Switch) -> TestResult { ); let mut to_recv = to_send.clone(); - let send = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let send = TestPacket { packet: Arc::new(to_send), port: ingress }; common::set_icmp6_unreachable(switch, &mut to_recv, ingress); - let expected = TestPacket { - packet: Arc::new(to_recv), - port: egress, - }; + let expected = TestPacket { packet: Arc::new(to_recv), port: egress }; switch.packet_test(vec![send], vec![expected]) } @@ -226,14 +209,8 @@ async fn test_updated_unicast() -> TestResult { .unwrap(), ); - let send = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; - let expected = TestPacket { - packet: Arc::new(to_recv), - port: egress, - }; + let send = TestPacket { packet: Arc::new(to_send), port: ingress }; + let expected = TestPacket { packet: Arc::new(to_recv), port: egress }; switch.packet_test(vec![send], vec![expected]) } @@ -266,16 +243,10 @@ async fn test_unrouteable() -> TestResult { ); let mut to_recv = to_send.clone(); - let send = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; + let send = TestPacket { packet: Arc::new(to_send), port: ingress }; common::set_icmp6_unreachable(switch, &mut to_recv, ingress); - let expected = TestPacket { - packet: Arc::new(to_recv), - port: egress, - }; + let expected = TestPacket { packet: Arc::new(to_recv), port: egress }; switch.packet_test(vec![send], vec![expected]) } @@ -315,14 +286,8 @@ async fn test_short_hit_unicast() -> TestResult { .unwrap(), ); - let send = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; - let expected = TestPacket { - packet: Arc::new(to_recv), - port: egress, - }; + let send = TestPacket { packet: Arc::new(to_send), port: ingress }; + let expected = TestPacket { packet: Arc::new(to_recv), port: egress }; switch.packet_test(vec![send], vec![expected]) } @@ -361,14 +326,8 @@ async fn test_long_hit_unicast() -> TestResult { .unwrap(), ); - let send = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; - let expected = TestPacket { - packet: Arc::new(to_recv), - port: egress, - }; + let send = TestPacket { packet: Arc::new(to_send), port: ingress }; + let expected = TestPacket { packet: Arc::new(to_recv), port: egress }; switch.packet_test(vec![send], vec![expected]) } @@ -413,14 +372,8 @@ async fn test_middle_hit_unicast() -> TestResult { .unwrap(), ); - let send = TestPacket { - packet: Arc::new(to_send), - port: ingress, - }; - let expected = TestPacket { - packet: Arc::new(to_recv), - port: egress, - }; + let send = TestPacket { packet: Arc::new(to_send), port: ingress }; + let expected = TestPacket { packet: Arc::new(to_recv), port: egress }; switch.packet_test(vec![send], vec![expected]) } @@ -437,10 +390,7 @@ async fn test_interface_local_multicast() -> TestResult { let dst = Endpoint::parse("33:33:00:00:00:01", "ff01::1", 4444).unwrap(); let send = Arc::new(common::gen_udp_packet(src, dst)); - let send = TestPacket { - packet: send, - port: ingress, - }; + let send = TestPacket { packet: send, port: ingress }; switch.packet_test(vec![send], Vec::new()) } @@ -458,10 +408,7 @@ async fn test_link_local_multicast_inbound() -> TestResult { let dst = Endpoint::parse("33:33:00:00:00:01", "ff02::1", 4444).unwrap(); let send = Arc::new(common::gen_udp_packet(src, dst)); - let send = TestPacket { - packet: send, - port: ingress, - }; + let send = TestPacket { packet: send, port: ingress }; let mut recv = common::gen_udp_packet(src, dst); @@ -476,10 +423,7 @@ async fn test_link_local_multicast_inbound() -> TestResult { None, ); let recv = Arc::new(recv); - let expected = vec![TestPacket { - packet: recv, - port: SERVICE_PORT, - }]; + let expected = vec![TestPacket { packet: recv, port: SERVICE_PORT }]; switch.packet_test(vec![send], expected) } @@ -510,16 +454,10 @@ async fn test_link_local_multicast_outbound() -> TestResult { ); let send = Arc::new(send); - let send = TestPacket { - packet: send, - port: SERVICE_PORT, - }; + let send = TestPacket { packet: send, port: SERVICE_PORT }; let recv = Arc::new(common::gen_udp_packet(src, dst)); - let expected = vec![TestPacket { - packet: recv, - port: egress, - }]; + let expected = vec![TestPacket { packet: recv, port: egress }]; switch.packet_test(vec![send], expected) } @@ -539,10 +477,7 @@ async fn test_ipv6_link_local_multicast_hop_limit_one() -> TestResult { // Set hop limit to 1 - this should be ALLOWED for link-local multicast ipv6::Ipv6Hdr::adjust_hlim(&mut send, -254); // Set to 1 (255 - 254 = 1) - let test_pkt = TestPacket { - packet: Arc::new(send.clone()), - port: ingress, - }; + let test_pkt = TestPacket { packet: Arc::new(send.clone()), port: ingress }; // Link-local multicast packets should be forwarded to userspace with sidecar header let mut recv = send.clone(); @@ -555,10 +490,8 @@ async fn test_ipv6_link_local_multicast_hop_limit_one() -> TestResult { None, ); - let expected = vec![TestPacket { - packet: Arc::new(recv), - port: SERVICE_PORT, - }]; + let expected = + vec![TestPacket { packet: Arc::new(recv), port: SERVICE_PORT }]; // Verify that the hop limit invalid counter does NOT increment let ctr_baseline_hop_limit = @@ -642,11 +575,8 @@ async fn test_create_and_set_semantics_v6() -> TestResult { let mut target33 = target47.clone(); target33.tgt_ip = "fe80::1701:c:2000:33".parse().unwrap(); - let route47 = types::Ipv6RouteUpdate { - cidr, - target: target47, - replace: false, - }; + let route47 = + types::Ipv6RouteUpdate { cidr, target: target47, replace: false }; let mut route33 = types::Ipv6RouteUpdate { cidr, @@ -658,10 +588,7 @@ async fn test_create_and_set_semantics_v6() -> TestResult { client.route_ipv6_set(&route47).await?; // Attempting to replace the route with "replace = false" should fail - client - .route_ipv6_set(&route33) - .await - .expect_err("expected conflict"); + client.route_ipv6_set(&route33).await.expect_err("expected conflict"); // Re-setting the existing route should succeed client.route_ipv6_set(&route47).await?; // Attempting to replace the route with "replace = true" should success @@ -705,18 +632,13 @@ async fn test_multipath(switch: &Switch, routers: &[Router]) -> TestResult { Endpoint::parse("e0:d5:5e:67:89:ac", dst_ip, dst_port).unwrap(), ); - let send = TestPacket { - packet: Arc::new(to_send), - port: PhysPort(ingress), - }; + let send = + TestPacket { packet: Arc::new(to_send), port: PhysPort(ingress) }; // Add the VLAN tag to the expected packet if let Some(vlan) = routers[expected_egress].vlan { - to_recv.hdrs.eth_hdr.as_mut().unwrap().eth_8021q = Some(EthQHdr { - eth_pcp: 0, - eth_dei: 0, - eth_vlan_tag: vlan, - }); + to_recv.hdrs.eth_hdr.as_mut().unwrap().eth_8021q = + Some(EthQHdr { eth_pcp: 0, eth_dei: 0, eth_vlan_tag: vlan }); } let expected = TestPacket { diff --git a/dpd-client/tests/integration_tests/service.rs b/dpd-client/tests/integration_tests/service.rs index 20a7270..75d59ed 100644 --- a/dpd-client/tests/integration_tests/service.rs +++ b/dpd-client/tests/integration_tests/service.rs @@ -30,11 +30,7 @@ async fn test_service_ipv4_unicast() -> TestResult { addr: router_ip.parse().unwrap(), tag: switch.client.inner().tag.clone(), }; - switch - .client - .link_ipv4_create(&port_id, &link_id, &entry) - .await - .unwrap(); + switch.client.link_ipv4_create(&port_id, &link_id, &entry).await.unwrap(); let send_pkt = common::gen_udp_packet( Endpoint::parse("e0:d5:5e:67:89:ab", "10.10.10.10", 3333).unwrap(), @@ -42,10 +38,7 @@ async fn test_service_ipv4_unicast() -> TestResult { ); let mut recv_pkt = send_pkt.clone(); - let send = TestPacket { - packet: Arc::new(send_pkt), - port: ingress, - }; + let send = TestPacket { packet: Arc::new(send_pkt), port: ingress }; // The packet that gets delivered to the service port should be identical to // the one arriving at the ingress port, with the additional sidecar header. @@ -58,10 +51,8 @@ async fn test_service_ipv4_unicast() -> TestResult { NO_PORT, None, ); - let expected = TestPacket { - packet: Arc::new(recv_pkt), - port: SERVICE_PORT, - }; + let expected = + TestPacket { packet: Arc::new(recv_pkt), port: SERVICE_PORT }; switch.packet_test(vec![send], vec![expected]) } @@ -82,11 +73,7 @@ async fn test_service_ipv4_unicast_with_nat() -> TestResult { addr: router_ip.parse().unwrap(), tag: switch.client.inner().tag.clone(), }; - switch - .client - .link_ipv4_create(&port_id, &link_id, &entry) - .await - .unwrap(); + switch.client.link_ipv4_create(&port_id, &link_id, &entry).await.unwrap(); let send_pkt = common::gen_udp_packet( Endpoint::parse("e0:d5:5e:67:89:ab", "10.10.10.10", 3333).unwrap(), @@ -94,10 +81,7 @@ async fn test_service_ipv4_unicast_with_nat() -> TestResult { ); let mut recv_pkt = send_pkt.clone(); - let send = TestPacket { - packet: Arc::new(send_pkt), - port: ingress, - }; + let send = TestPacket { packet: Arc::new(send_pkt), port: ingress }; // The packet that gets delivered to the service port should be identical to // the one arriving at the ingress port, with the additional sidecar header. @@ -110,24 +94,14 @@ async fn test_service_ipv4_unicast_with_nat() -> TestResult { NO_PORT, None, ); - let expected = TestPacket { - packet: Arc::new(recv_pkt), - port: SERVICE_PORT, - }; + let expected = + TestPacket { packet: Arc::new(recv_pkt), port: SERVICE_PORT }; // Mark the port as NAT-only - switch - .client - .link_nat_only_set(&port_id, &link_id, true) - .await - .unwrap(); + switch.client.link_nat_only_set(&port_id, &link_id, true).await.unwrap(); let result = switch.packet_test(vec![send], vec![expected]); // Clear the port's NAT-only property - switch - .client - .link_nat_only_set(&port_id, &link_id, false) - .await - .unwrap(); + switch.client.link_nat_only_set(&port_id, &link_id, false).await.unwrap(); result } @@ -147,11 +121,7 @@ async fn test_service_ipv4_wrong_port() -> TestResult { addr: router_ip.parse().unwrap(), tag: switch.client.inner().tag.clone(), }; - switch - .client - .link_ipv4_create(&port_id, &link_id, &entry) - .await - .unwrap(); + switch.client.link_ipv4_create(&port_id, &link_id, &entry).await.unwrap(); let send_pkt = common::gen_udp_packet( Endpoint::parse("e0:d5:5e:67:89:ab", "10.10.10.10", 3333).unwrap(), @@ -159,16 +129,12 @@ async fn test_service_ipv4_wrong_port() -> TestResult { ); let mut recv_pkt = send_pkt.clone(); - let send = TestPacket { - packet: Arc::new(send_pkt), - port: PhysPort(ingress + 1), - }; + let send = + TestPacket { packet: Arc::new(send_pkt), port: PhysPort(ingress + 1) }; common::set_icmp_unreachable(switch, &mut recv_pkt, PhysPort(ingress + 1)); - let expected = TestPacket { - packet: Arc::new(recv_pkt), - port: SERVICE_PORT, - }; + let expected = + TestPacket { packet: Arc::new(recv_pkt), port: SERVICE_PORT }; switch.packet_test(vec![send], vec![expected]) } @@ -189,36 +155,22 @@ async fn test_service_ipv4_unknown_address() -> TestResult { addr: router_ip.parse().unwrap(), tag: switch.client.inner().tag.clone(), }; - switch - .client - .link_ipv4_create(&port_id, &link_id, &entry) - .await - .unwrap(); + switch.client.link_ipv4_create(&port_id, &link_id, &entry).await.unwrap(); // Mark the port as NAT-only - switch - .client - .link_nat_only_set(&port_id, &link_id, true) - .await - .unwrap(); + switch.client.link_nat_only_set(&port_id, &link_id, true).await.unwrap(); let send_pkt = common::gen_udp_packet( Endpoint::parse("e0:d5:5e:67:89:ab", "10.10.10.10", 3333).unwrap(), Endpoint::parse(router_mac, "192.10.12.1", 4444).unwrap(), ); - let send = TestPacket { - packet: Arc::new(send_pkt), - port: PhysPort(ingress), - }; + let send = + TestPacket { packet: Arc::new(send_pkt), port: PhysPort(ingress) }; let result = switch.packet_test(vec![send], Vec::new()); // Clear the port's NAT-only property - switch - .client - .link_nat_only_set(&port_id, &link_id, false) - .await - .unwrap(); + switch.client.link_nat_only_set(&port_id, &link_id, false).await.unwrap(); result } @@ -245,10 +197,7 @@ async fn test_arp_needed() -> TestResult { Endpoint::parse("e0:d5:5e:67:89:ac", "10.10.10.11", 4444).unwrap(), ); - let send = TestPacket { - packet: Arc::new(send_pkt), - port: ingress_port, - }; + let send = TestPacket { packet: Arc::new(send_pkt), port: ingress_port }; // This test is identical to the ipv4 unicast routing test, but we don't // add the ARP entry. We should see the packet arrive on the service port @@ -269,10 +218,8 @@ async fn test_arp_needed() -> TestResult { eth::EthHdr::rewrite_smac(&mut recv_pkt, src_eth.eth_smac); eth::EthHdr::rewrite_dmac(&mut recv_pkt, src_eth.eth_dmac); - let expected = TestPacket { - packet: Arc::new(recv_pkt), - port: SERVICE_PORT, - }; + let expected = + TestPacket { packet: Arc::new(recv_pkt), port: SERVICE_PORT }; switch.packet_test(vec![send], vec![expected]) } @@ -307,10 +254,7 @@ async fn test_ttl_exceeded() -> TestResult { let mut recv_pkt = send_pkt.clone(); - let send = TestPacket { - packet: Arc::new(send_pkt), - port: ingress, - }; + let send = TestPacket { packet: Arc::new(send_pkt), port: ingress }; common::set_icmp_needed( switch, @@ -320,10 +264,8 @@ async fn test_ttl_exceeded() -> TestResult { icmp::ICMP_TIME_EXCEEDED, 0, ); - let expected = TestPacket { - packet: Arc::new(recv_pkt), - port: SERVICE_PORT, - }; + let expected = + TestPacket { packet: Arc::new(recv_pkt), port: SERVICE_PORT }; switch.packet_test(vec![send], vec![expected]) } @@ -345,11 +287,7 @@ async fn execute_test_service_arp(nat_only: bool) -> TestResult { addr: tgt_ip.parse().unwrap(), tag: switch.client.inner().tag.clone(), }; - switch - .client - .link_ipv4_create(&port_id, &link_id, &entry) - .await - .unwrap(); + switch.client.link_ipv4_create(&port_id, &link_id, &entry).await.unwrap(); let send_pkt = common::gen_arp_reply( Endpoint::parse(src_mac, src_ip, 3333).unwrap(), @@ -357,10 +295,7 @@ async fn execute_test_service_arp(nat_only: bool) -> TestResult { ); let mut recv_pkt = send_pkt.clone(); - let send = TestPacket { - packet: Arc::new(send_pkt), - port: ingress, - }; + let send = TestPacket { packet: Arc::new(send_pkt), port: ingress }; common::add_sidecar_hdr( switch, @@ -370,10 +305,8 @@ async fn execute_test_service_arp(nat_only: bool) -> TestResult { NO_PORT, None, ); - let expected = TestPacket { - packet: Arc::new(recv_pkt), - port: SERVICE_PORT, - }; + let expected = + TestPacket { packet: Arc::new(recv_pkt), port: SERVICE_PORT }; if nat_only { // Mark the port as NAT-only @@ -433,10 +366,7 @@ async fn execute_test_service_lldp(nat_only: bool) -> TestResult { .unwrap(); let mut recv_pkt = send_pkt.clone(); - let send = TestPacket { - packet: Arc::new(send_pkt), - port: ingress, - }; + let send = TestPacket { packet: Arc::new(send_pkt), port: ingress }; common::add_sidecar_hdr( switch, @@ -446,10 +376,8 @@ async fn execute_test_service_lldp(nat_only: bool) -> TestResult { NO_PORT, None, ); - let expected = TestPacket { - packet: Arc::new(recv_pkt), - port: SERVICE_PORT, - }; + let expected = + TestPacket { packet: Arc::new(recv_pkt), port: SERVICE_PORT }; if nat_only { // Mark the port as NAT-only diff --git a/dpd-client/tests/integration_tests/table_tests.rs b/dpd-client/tests/integration_tests/table_tests.rs index f57686a..7985e05 100644 --- a/dpd-client/tests/integration_tests/table_tests.rs +++ b/dpd-client/tests/integration_tests/table_tests.rs @@ -63,9 +63,7 @@ fn gen_ipv4_addr(idx: usize) -> Ipv4Addr { } fn gen_ipv6_addr(idx: usize) -> Ipv6Addr { - Ipv6Addr::new( - 0xfc00, 0xaabb, 0xccdd, 0x18, 0x8, 0x20ff, 0xfe1d, idx as u16, - ) + Ipv6Addr::new(0xfc00, 0xaabb, 0xccdd, 0x18, 0x8, 0x20ff, 0xfe1d, idx as u16) } fn gen_ipv4_cidr(idx: usize) -> Ipv4Net { @@ -310,10 +308,7 @@ impl TableTest for types::Ipv4Nat { async fn delete_entry(switch: &Switch, idx: usize) -> OpResult<()> { let external_ip = Ipv4Addr::new(192, 168, 0, 1); - switch - .client - .nat_ipv4_delete(&external_ip, idx as u16) - .await + switch.client.nat_ipv4_delete(&external_ip, idx as u16).await } async fn count_entries(switch: &Switch) -> usize { @@ -351,10 +346,7 @@ impl TableTest for types::Ipv6Nat { async fn delete_entry(switch: &Switch, idx: usize) -> OpResult<()> { let external_ip = "fd00:1122:1122:0101::4".parse::().unwrap(); - switch - .client - .nat_ipv6_delete(&external_ip, idx as u16) - .await + switch.client.nat_ipv6_delete(&external_ip, idx as u16).await } async fn count_entries(switch: &Switch) -> usize { @@ -492,10 +484,7 @@ impl TableTest }, ], }; - switch - .client - .multicast_group_create_underlay(&internal_entry) - .await + switch.client.multicast_group_create_underlay(&internal_entry).await } async fn delete_entry(switch: &Switch, idx: usize) -> OpResult<()> { diff --git a/dpd-types/src/transceivers.rs b/dpd-types/src/transceivers.rs index 0906829..e2a9ab8 100644 --- a/dpd-types/src/transceivers.rs +++ b/dpd-types/src/transceivers.rs @@ -33,10 +33,7 @@ pub struct QsfpDevice { impl Default for QsfpDevice { fn default() -> Self { - Self { - transceiver: None, - management_mode: ManagementMode::Automatic, - } + Self { transceiver: None, management_mode: ManagementMode::Automatic } } } diff --git a/dpd-types/src/views.rs b/dpd-types/src/views.rs index fdd00cb..808e878 100644 --- a/dpd-types/src/views.rs +++ b/dpd-types/src/views.rs @@ -176,9 +176,6 @@ pub struct TableCounterEntry { impl TableCounterEntry { pub fn new(key: impl aal::MatchParse, data: aal::CounterData) -> Self { - TableCounterEntry { - keys: key.key_values(), - data, - } + TableCounterEntry { keys: key.key_values(), data } } } diff --git a/dpd/build.rs b/dpd/build.rs index 6c6660f..b59ff46 100644 --- a/dpd/build.rs +++ b/dpd/build.rs @@ -48,10 +48,8 @@ fn project_root() -> io::Result { } fn emit_sde_commit_sha() -> anyhow::Result<()> { - let path = concat!( - env!("CARGO_MANIFEST_DIR"), - "/../.github/buildomat/common.sh" - ); + let path = + concat!(env!("CARGO_MANIFEST_DIR"), "/../.github/buildomat/common.sh"); const NEEDLE: &str = "SDE_COMMIT"; let contents = std::fs::read_to_string(path) .context(format!("failed to read {path}"))?; @@ -143,9 +141,5 @@ fn main() -> anyhow::Result<()> { } // Emit detailed build information, for use in the `/build-info` endpoint. - vergen::EmitBuilder::builder() - .all_cargo() - .all_rustc() - .all_git() - .emit() + vergen::EmitBuilder::builder().all_cargo().all_rustc().all_git().emit() } diff --git a/dpd/src/api_server.rs b/dpd/src/api_server.rs index cd92224..dc3d67c 100644 --- a/dpd/src/api_server.rs +++ b/dpd/src/api_server.rs @@ -459,13 +459,7 @@ impl DpdApi for DpdApiImpl { rqctx: RequestContext>, ) -> Result>, HttpError> { Ok(HttpResponseOk( - rqctx - .context() - .switch_ports - .port_map - .port_ids() - .copied() - .collect(), + rqctx.context().switch_ports.port_map.port_ids().copied().collect(), )) } @@ -635,11 +629,7 @@ impl DpdApi for DpdApiImpl { rqctx: RequestContext>, ) -> Result>, HttpError> { let switch = rqctx.context(); - switch - .all_leds() - .await - .map(HttpResponseOk) - .map_err(HttpError::from) + switch.all_leds().await.map(HttpResponseOk).map_err(HttpError::from) } async fn led_set_auto( @@ -816,10 +806,7 @@ impl DpdApi for DpdApiImpl { ) -> Result>, HttpError> { let switch = &rqctx.context(); let port_id = path.into_inner().port_id; - switch - .list_links(port_id) - .map(HttpResponseOk) - .map_err(HttpError::from) + switch.list_links(port_id).map(HttpResponseOk).map_err(HttpError::from) } async fn link_list_all( @@ -2155,11 +2142,7 @@ impl DpdApi for DpdApiImpl { "failed to lookup port and link ID from \ an existing port handle: {port_hdl}" )))?; - out.push(LinkPcsCounters { - port_id, - link_id, - counters, - }); + out.push(LinkPcsCounters { port_id, link_id, counters }); } Ok(HttpResponseOk(out)) } @@ -2186,11 +2169,7 @@ impl DpdApi for DpdApiImpl { let port_handle = switch.link_id_to_hdl(port_id, link_id)?; stats::port_get_pcs_counters(&switch.asic_hdl, port_handle) .map(|counters| { - HttpResponseOk(LinkPcsCounters { - port_id, - link_id, - counters, - }) + HttpResponseOk(LinkPcsCounters { port_id, link_id, counters }) }) .map_err(|e| HttpError::from(DpdError::from(e))) } @@ -2223,11 +2202,7 @@ impl DpdApi for DpdApiImpl { "failed to lookup port and link ID from \ an existing port handle: {port_hdl}" )))?; - out.push(LinkFecRSCounters { - port_id, - link_id, - counters, - }); + out.push(LinkFecRSCounters { port_id, link_id, counters }); } Ok(HttpResponseOk(out)) } @@ -2254,11 +2229,7 @@ impl DpdApi for DpdApiImpl { let port_handle = switch.link_id_to_hdl(port_id, link_id)?; stats::port_get_fec_rs_counters(&switch.asic_hdl, port_handle) .map(|counters| { - HttpResponseOk(LinkFecRSCounters { - port_id, - link_id, - counters, - }) + HttpResponseOk(LinkFecRSCounters { port_id, link_id, counters }) }) .map_err(|e| HttpError::from(DpdError::from(e))) } @@ -2286,11 +2257,7 @@ impl DpdApi for DpdApiImpl { let port_handle = switch.link_id_to_hdl(port_id, link_id)?; stats::port_get_rmon_counters(&switch.asic_hdl, port_handle) .map(|counters| { - HttpResponseOk(LinkRMonCounters { - port_id, - link_id, - counters, - }) + HttpResponseOk(LinkRMonCounters { port_id, link_id, counters }) }) .map_err(|e| HttpError::from(DpdError::from(e))) } @@ -2378,10 +2345,7 @@ impl DpdApi for DpdApiImpl { serdes::port_tx_eq_get(&switch.asic_hdl, port_handle) .map_err(|e| HttpError::from(DpdError::from(e)))? .into_iter() - .map(|t| TxEqSwHw { - sw: t.sw.into(), - hw: t.hw.into(), - }) + .map(|t| TxEqSwHw { sw: t.sw.into(), hw: t.hw.into() }) .collect(), )) } @@ -2405,16 +2369,10 @@ impl DpdApi for DpdApiImpl { .asic_hdl .port_tx_eq_get(port_handle) .map_err(|e| HttpError::from(DpdError::from(e)))?; - let softnpu_tx_eq = TxEq { - main: Some(tx_eq), - ..Default::default() - }; + let softnpu_tx_eq = TxEq { main: Some(tx_eq), ..Default::default() }; Ok(HttpResponseOk( (0..lane_cnt) - .map(|_| TxEqSwHw { - sw: softnpu_tx_eq, - hw: softnpu_tx_eq, - }) + .map(|_| TxEqSwHw { sw: softnpu_tx_eq, hw: softnpu_tx_eq }) .collect(), )) } @@ -2798,11 +2756,8 @@ mod tests { fn test_build_info() { let info = build_info(); println!("{info:#?}"); - let out = Command::new("git") - .arg("rev-parse") - .arg("HEAD") - .output() - .unwrap(); + let out = + Command::new("git").arg("rev-parse").arg("HEAD").output().unwrap(); assert!(out.status.success()); let ours = std::str::from_utf8(&out.stdout).unwrap().trim(); assert_eq!(info.git_sha, ours); diff --git a/dpd/src/arp.rs b/dpd/src/arp.rs index 51237e2..e7ccd74 100644 --- a/dpd/src/arp.rs +++ b/dpd/src/arp.rs @@ -50,11 +50,7 @@ pub fn add_entry_ipv4( } else { debug!(switch.log, "new ipv4 arp entry {} -> {}", ip, mac); table::arp_ipv4::add_entry(switch, ip, mac)?; - let e = ArpEntry { - tag: tag.to_string(), - mac, - update: Utc::now(), - }; + let e = ArpEntry { tag: tag.to_string(), mac, update: Utc::now() }; arp_data.v4.insert(idx, e); } Ok(()) @@ -85,11 +81,7 @@ pub fn add_entry_ipv6( } else { debug!(switch.log, "new ipv6 arp entry {} -> {}", ip, mac); table::neighbor_ipv6::add_entry(switch, ip, mac)?; - let e = ArpEntry { - tag: tag.to_string(), - mac, - update: Utc::now(), - }; + let e = ArpEntry { tag: tag.to_string(), mac, update: Utc::now() }; arp_data.v6.insert(idx, e); } Ok(()) @@ -261,8 +253,5 @@ pub fn reset_ipv6(switch: &Switch) -> DpdResult<()> { } pub fn init() -> ArpData { - ArpData { - v4: BTreeMap::new(), - v6: BTreeMap::new(), - } + ArpData { v4: BTreeMap::new(), v6: BTreeMap::new() } } diff --git a/dpd/src/attached_subnet.rs b/dpd/src/attached_subnet.rs index 1a5a2db..60b921c 100644 --- a/dpd/src/attached_subnet.rs +++ b/dpd/src/attached_subnet.rs @@ -148,7 +148,5 @@ pub fn reset(switch: &Switch) -> DpdResult<()> { } pub fn init() -> AttachedSubnetData { - AttachedSubnetData { - mappings: BTreeMap::new(), - } + AttachedSubnetData { mappings: BTreeMap::new() } } diff --git a/dpd/src/freemap.rs b/dpd/src/freemap.rs index 36fe6f5..c97d4e9 100644 --- a/dpd/src/freemap.rs +++ b/dpd/src/freemap.rs @@ -227,11 +227,7 @@ impl FreeMap { #[cfg(test)] fn first(&self) -> Option { - if self.freelist.is_empty() { - None - } else { - Some(self.freelist[0]) - } + if self.freelist.is_empty() { None } else { Some(self.freelist[0]) } } } diff --git a/dpd/src/link.rs b/dpd/src/link.rs index 324a2e0..571afef 100644 --- a/dpd/src/link.rs +++ b/dpd/src/link.rs @@ -1064,10 +1064,7 @@ impl Switch { // Equality only considers the address, so create an entry // with an empty tag. use std::ops::Bound; - let entry = Ipv4Entry { - tag: String::new(), - addr, - }; + let entry = Ipv4Entry { tag: String::new(), addr }; link.ipv4 .range((Bound::Excluded(entry), Bound::Unbounded)) .take(limit) @@ -1085,10 +1082,7 @@ impl Switch { link: &mut Link, address: Ipv4Addr, ) -> DpdResult<()> { - let entry = Ipv4Entry { - tag: String::new(), - addr: address, - }; + let entry = Ipv4Entry { tag: String::new(), addr: address }; if link.ipv4.contains(&entry) { port_ip::ipv4_delete(self, link.asic_port_id, address)?; @@ -1172,10 +1166,7 @@ impl Switch { // Equality only considers the address, so create an entry // with an empty tag. use std::ops::Bound; - let entry = Ipv6Entry { - tag: String::new(), - addr, - }; + let entry = Ipv6Entry { tag: String::new(), addr }; link.ipv6 .range((Bound::Excluded(entry), Bound::Unbounded)) .take(limit) @@ -1193,10 +1184,7 @@ impl Switch { link: &mut Link, address: Ipv6Addr, ) -> DpdResult<()> { - let entry = Ipv6Entry { - tag: String::new(), - addr: address, - }; + let entry = Ipv6Entry { tag: String::new(), addr: address }; if link.ipv6.contains(&entry) { port_ip::ipv6_delete(self, link.asic_port_id, address)?; @@ -1459,11 +1447,7 @@ impl Switch { let link = link_lock.lock().unwrap(); let link_path = (*link).to_string(); let (current, total) = link.linkup_tracker.get_counters(); - all.push(LinkUpCounter { - link_path, - current, - total, - }); + all.push(LinkUpCounter { link_path, current, total }); } all } @@ -1639,11 +1623,10 @@ fn plumb_link( mpn: &Option, ) -> DpdResult<()> { debug!(log, "plumbing link"); - let connector = switch - .switch_ports - .port_map - .id_to_connector(&link.port_id) - .ok_or(DpdError::Invalid("PortId has no matching Connector".into()))?; + let connector = + switch.switch_ports.port_map.id_to_connector(&link.port_id).ok_or( + DpdError::Invalid("PortId has no matching Connector".into()), + )?; // If the admin hasn't configured the FEC setting for this link, try to find // a default value for this transceiver. @@ -1696,9 +1679,7 @@ fn plumb_link( log, "setting autonegotiation to {} at link creation", link.config.autoneg ); - switch - .asic_hdl - .port_autoneg_set(link.port_hdl, link.config.autoneg)?; + switch.asic_hdl.port_autoneg_set(link.port_hdl, link.config.autoneg)?; link.plumbed.autoneg = link.config.autoneg; // Set the kr value @@ -1971,9 +1952,8 @@ async fn reconcile_link( false => "disabled", } ); - if let Err(e) = switch - .asic_hdl - .port_enable_set(link.port_hdl, link.config.enabled) + if let Err(e) = + switch.asic_hdl.port_enable_set(link.port_hdl, link.config.enabled) { let action = match link.config.enabled { true => "enabling the link", @@ -2003,10 +1983,7 @@ pub struct LinkReconciler { impl LinkReconciler { pub fn new() -> Self { let (tx, rx) = mpsc::unbounded_channel(); - LinkReconciler { - tx, - rx: Mutex::new(Some(rx)), - } + LinkReconciler { tx, rx: Mutex::new(Some(rx)) } } pub fn run(&self, switch: Arc) { diff --git a/dpd/src/loopback.rs b/dpd/src/loopback.rs index 1275d82..a66ac89 100644 --- a/dpd/src/loopback.rs +++ b/dpd/src/loopback.rs @@ -20,10 +20,7 @@ pub struct LoopbackData { /// Initialize loopback data to empty sets of IPv4 and IPv6 addresses. pub fn init() -> LoopbackData { - LoopbackData { - v4_addrs: BTreeSet::new(), - v6_addrs: BTreeSet::new(), - } + LoopbackData { v4_addrs: BTreeSet::new(), v6_addrs: BTreeSet::new() } } /// Add a loopback IPv4 address to the switch. @@ -53,10 +50,7 @@ pub fn add_loopback_ipv4(switch: &Switch, addr: &Ipv4Entry) -> DpdResult<()> { /// Delete a loopback IPv4 address from the switch. pub fn delete_loopback_ipv4(switch: &Switch, addr: &Ipv4Addr) -> DpdResult<()> { let mut loopback_data = switch.loopback.lock().unwrap(); - let entry = Ipv4Entry { - addr: *addr, - tag: "".into(), - }; + let entry = Ipv4Entry { addr: *addr, tag: "".into() }; if !loopback_data.v4_addrs.contains(&entry) { debug!(switch.log, "loopback entry {} not set", addr); return Ok(()); @@ -106,10 +100,7 @@ pub fn add_loopback_ipv6(switch: &Switch, addr: &Ipv6Entry) -> DpdResult<()> { /// Delete a loopback IPv6 address from the switch. pub fn delete_loopback_ipv6(switch: &Switch, addr: &Ipv6Addr) -> DpdResult<()> { let mut loopback_data = switch.loopback.lock().unwrap(); - let entry = Ipv6Entry { - addr: *addr, - tag: "".into(), - }; + let entry = Ipv6Entry { addr: *addr, tag: "".into() }; if !loopback_data.v6_addrs.contains(&entry) { debug!(switch.log, "loopback entry {} not set", addr); return Ok(()); diff --git a/dpd/src/main.rs b/dpd/src/main.rs index ac0ce15..635d8e4 100644 --- a/dpd/src/main.rs +++ b/dpd/src/main.rs @@ -487,10 +487,7 @@ fn handle_smf_refresh( // property. let mut curr_config = switch.config.lock().unwrap(); let mac_base = curr_config.mac_base.or(new_config.mac_base); - *curr_config = config::Config { - mac_base, - ..new_config - }; + *curr_config = config::Config { mac_base, ..new_config }; info!(switch.log, "refreshed config: {:#?}", curr_config); } Err(e) => { @@ -667,10 +664,7 @@ async fn sidecar_main(mut switch: Switch) -> anyhow::Result<()> { api_server::api_server_manager(switch.clone(), smf_rx.clone()), ); - info!( - switch.log, - "spawning fetching of switch identifiers from MGS" - ); + info!(switch.log, "spawning fetching of switch identifiers from MGS"); tokio::task::spawn(update_switch_identifiers(switch.clone())); @@ -809,10 +803,7 @@ async fn run_dpd(opt: Opt) -> anyhow::Result<()> { if p4_name == "sidecar" { sidecar_main(switch).await } else { - info!( - switch.log, - "running as stub to support p4 program: {p4_name}" - ); + info!(switch.log, "running as stub to support p4 program: {p4_name}"); stub_main(switch).await } } diff --git a/dpd/src/mcast/mod.rs b/dpd/src/mcast/mod.rs index fa246d9..9e8a518 100644 --- a/dpd/src/mcast/mod.rs +++ b/dpd/src/mcast/mod.rs @@ -269,8 +269,7 @@ impl MulticastGroupData { external_group_ip: IpAddr, admin_scoped_ip: AdminScopedIpv6, ) { - self.nat_target_refs - .insert(admin_scoped_ip, external_group_ip); + self.nat_target_refs.insert(admin_scoped_ip, external_group_ip); } /// Remove 1:1 forwarding reference. @@ -494,10 +493,8 @@ pub(crate) fn del_group(s: &Switch, group_ip: IpAddr) -> DpdResult<()> { )) })?; - let nat_target_to_remove = group - .int_fwding - .nat_target - .map(|nat| nat.internal_ip.into()); + let nat_target_to_remove = + group.int_fwding.nat_target.map(|nat| nat.internal_ip.into()); debug!(s.log, "deleting multicast group for IP {group_ip}"); @@ -568,14 +565,11 @@ pub(crate) fn modify_group_external( } let nat_target = - new_group_info - .internal_forwarding - .nat_target - .ok_or_else(|| { - DpdError::Invalid( - "external groups must have NAT target".to_string(), - ) - })?; + new_group_info.internal_forwarding.nat_target.ok_or_else(|| { + DpdError::Invalid( + "external groups must have NAT target".to_string(), + ) + })?; validate_multicast_address(group_ip, new_group_info.sources.as_deref())?; validate_nat_target(nat_target)?; @@ -1214,14 +1208,12 @@ fn create_asic_group( group_id: MulticastGroupId, group_ip: IpAddr, ) -> DpdResult<()> { - s.asic_hdl - .mc_group_create(group_id) - .map_err(|e: AsicError| { - DpdError::McastGroupFailure(format!( - "failed to create multicast group for IP {group_ip} with ID \ + s.asic_hdl.mc_group_create(group_id).map_err(|e: AsicError| { + DpdError::McastGroupFailure(format!( + "failed to create multicast group for IP {group_ip} with ID \ {group_id}: {e:?}" - )) - }) + )) + }) } fn add_ports_to_groups( @@ -1270,9 +1262,7 @@ fn process_membership_changes( ) -> DpdResult<(Vec, Vec)> { // First validate that IPv4 doesn't have underlay members if group_ip.is_ipv4() - && new_members - .iter() - .any(|m| m.direction == Direction::Underlay) + && new_members.iter().any(|m| m.direction == Direction::Underlay) { return Err(DpdError::Invalid(format!( "multicast group for IPv4 {group_ip} cannot have underlay members" @@ -1467,16 +1457,9 @@ fn update_external_tables( } // Update NAT target - external groups always have NAT targets - if Some( - new_group_info - .internal_forwarding - .nat_target - .ok_or_else(|| { - DpdError::Invalid( - "external groups must have NAT target".to_string(), - ) - })?, - ) != group_entry.int_fwding.nat_target + if Some(new_group_info.internal_forwarding.nat_target.ok_or_else(|| { + DpdError::Invalid("external groups must have NAT target".to_string()) + })?) != group_entry.int_fwding.nat_target { update_nat_tables( s, diff --git a/dpd/src/mcast/rollback.rs b/dpd/src/mcast/rollback.rs index c2c20dd..54c5330 100644 --- a/dpd/src/mcast/rollback.rs +++ b/dpd/src/mcast/rollback.rs @@ -657,11 +657,7 @@ impl<'a> GroupUpdateRollbackContext<'a> { group_ip: IpAddr, original_group: &'a MulticastGroup, ) -> Self { - Self { - switch, - group_ip, - original_group, - } + Self { switch, group_ip, original_group } } /// Restore tables and return error. diff --git a/dpd/src/nat.rs b/dpd/src/nat.rs index 937fe3f..8c887a5 100644 --- a/dpd/src/nat.rs +++ b/dpd/src/nat.rs @@ -141,21 +141,9 @@ fn test_mapping() { }; let entries = vec![ - Ipv4NatEntry { - low: 1, - high: 4, - tgt: dummy_target, - }, - Ipv4NatEntry { - low: 7, - high: 10, - tgt: dummy_target, - }, - Ipv4NatEntry { - low: 12, - high: 18, - tgt: dummy_target, - }, + Ipv4NatEntry { low: 1, high: 4, tgt: dummy_target }, + Ipv4NatEntry { low: 7, high: 10, tgt: dummy_target }, + Ipv4NatEntry { low: 12, high: 18, tgt: dummy_target }, ]; assert_eq!(find_first_mapping(&entries, 2, 2), Some(0)); @@ -193,11 +181,7 @@ pub fn get_ipv6_addrs_range( None => (Bound::Unbounded, Bound::Unbounded), }; - nat.ipv6_mappings - .range(range) - .take(max) - .map(|(ip, _)| *ip) - .collect() + nat.ipv6_mappings.range(range).take(max).map(|(ip, _)| *ip).collect() } /// Paginates through `Ipv6Nat` using `last_port` as the starting offset @@ -353,11 +337,7 @@ pub fn get_ipv4_addrs_range( None => (Bound::Unbounded, Bound::Unbounded), }; - nat.ipv4_mappings - .range(range) - .take(max) - .map(|(ip, _)| *ip) - .collect() + nat.ipv4_mappings.range(range).take(max).map(|(ip, _)| *ip).collect() } /// Paginates through `Ipv4Nat` using `last_port` as the starting offset diff --git a/dpd/src/oxstats.rs b/dpd/src/oxstats.rs index b2899a5..e350e1e 100644 --- a/dpd/src/oxstats.rs +++ b/dpd/src/oxstats.rs @@ -144,33 +144,15 @@ impl TableStats { pub fn new(table: SwitchTable) -> Self { TableStats { table, - capacity: Capacity { - datum: Default::default(), - }, - occupancy: Occupancy { - datum: Default::default(), - }, - inserts: Inserts { - datum: Default::default(), - }, - deletes: Deletes { - datum: Default::default(), - }, - updates: Updates { - datum: Default::default(), - }, - collisions: Collisions { - datum: Default::default(), - }, - update_misses: UpdateMisses { - datum: Default::default(), - }, - delete_misses: DeleteMisses { - datum: Default::default(), - }, - exhaustion: Exhaustion { - datum: Default::default(), - }, + capacity: Capacity { datum: Default::default() }, + occupancy: Occupancy { datum: Default::default() }, + inserts: Inserts { datum: Default::default() }, + deletes: Deletes { datum: Default::default() }, + updates: Updates { datum: Default::default() }, + collisions: Collisions { datum: Default::default() }, + update_misses: UpdateMisses { datum: Default::default() }, + delete_misses: DeleteMisses { datum: Default::default() }, + exhaustion: Exhaustion { datum: Default::default() }, } } @@ -487,11 +469,7 @@ async fn get_oximeter_config( fetch_underlay_listen_address(switch, log, smf_rx.clone()).await?; let sled_identifiers = fetch_sled_identifiers(switch, log, smf_rx).await?; let switch_identifiers = wait_for_switch_identifiers(switch, log).await?; - Ok(OximeterConfig { - listen_address, - sled_identifiers, - switch_identifiers, - }) + Ok(OximeterConfig { listen_address, sled_identifiers, switch_identifiers }) } /// Extract the underlay IPv6 listening address we're provided in our SMF @@ -510,17 +488,14 @@ async fn fetch_underlay_listen_address( loop { // Find any non-localhost IPv6 address. That should be reachable by // Oximeter, since it's on the underlay. - let maybe_listen_addr = switch - .config - .lock() - .unwrap() - .listen_addresses - .iter() - .find_map(|addr| match addr.ip() { - IpAddr::V4(_) => None, - IpAddr::V6(v6) if v6 == Ipv6Addr::LOCALHOST => None, - IpAddr::V6(v6) => Some(v6), - }); + let maybe_listen_addr = + switch.config.lock().unwrap().listen_addresses.iter().find_map( + |addr| match addr.ip() { + IpAddr::V4(_) => None, + IpAddr::V6(v6) if v6 == Ipv6Addr::LOCALHOST => None, + IpAddr::V6(v6) => Some(v6), + }, + ); if let Some(listen_address) = maybe_listen_addr { info!( log, @@ -665,10 +640,8 @@ pub async fn oximeter_register( ^ config.switch_identifiers.sidecar_id.as_u128(), ); debug!(log, "created producer ID"; "producer_id" => %producer_id); - let metadata = OximeterMetadata { - config: config.clone(), - registered_at: None, - }; + let metadata = + OximeterMetadata { config: config.clone(), registered_at: None }; let old = switch.oximeter_meta.lock().unwrap().replace(metadata); assert!(old.is_none()); diff --git a/dpd/src/port_map.rs b/dpd/src/port_map.rs index 2f00119..320f402 100644 --- a/dpd/src/port_map.rs +++ b/dpd/src/port_map.rs @@ -141,11 +141,7 @@ impl PortMap { }; let connector_to_id = id_to_connector.iter().map(|(k, v)| (*v, *k)).collect(); - Self { - _revision: revision, - id_to_connector, - connector_to_id, - } + Self { _revision: revision, id_to_connector, connector_to_id } } /// Return the internal `Connector` corresponding to the physical switch port, diff --git a/dpd/src/port_settings.rs b/dpd/src/port_settings.rs index 3ef0366..1abcbfd 100644 --- a/dpd/src/port_settings.rs +++ b/dpd/src/port_settings.rs @@ -435,19 +435,11 @@ impl PortSettingsDiff { }); // ipv4 addrs - let v4_add: BTreeSet = spec - .after - .ipv4 - .difference(&spec.before.ipv4) - .copied() - .collect(); + let v4_add: BTreeSet = + spec.after.ipv4.difference(&spec.before.ipv4).copied().collect(); - let v4_del: BTreeSet = spec - .before - .ipv4 - .difference(&spec.after.ipv4) - .copied() - .collect(); + let v4_del: BTreeSet = + spec.before.ipv4.difference(&spec.after.ipv4).copied().collect(); for addr in v4_add { Self::addr_add_v4(ctx, &mut link, rb, addr)?; @@ -457,19 +449,11 @@ impl PortSettingsDiff { } // ipv6 addrs - let v6_add: BTreeSet = spec - .after - .ipv6 - .difference(&spec.before.ipv6) - .copied() - .collect(); + let v6_add: BTreeSet = + spec.after.ipv6.difference(&spec.before.ipv6).copied().collect(); - let v6_del: BTreeSet = spec - .before - .ipv6 - .difference(&spec.after.ipv6) - .copied() - .collect(); + let v6_del: BTreeSet = + spec.before.ipv6.difference(&spec.after.ipv6).copied().collect(); for addr in v6_add { Self::addr_add_v6(ctx, &mut link, rb, addr)?; @@ -489,10 +473,8 @@ impl PortSettingsDiff { ) -> DpdResult<()> { trace!(ctx.log, "ipv4 add {addr}"); // Create address on ASIC first. - let entry = Ipv4Entry { - tag: ctx.tag.clone().unwrap_or("".into()), - addr, - }; + let entry = + Ipv4Entry { tag: ctx.tag.clone().unwrap_or("".into()), addr }; let switch = ctx.switch; switch.create_ipv4_address_locked(link, entry)?; @@ -513,10 +495,8 @@ impl PortSettingsDiff { addr: Ipv4Addr, ) -> DpdResult<()> { trace!(ctx.log, "ipv4 del {addr}"); - let entry = Ipv4Entry { - tag: ctx.tag.clone().unwrap_or("".into()), - addr, - }; + let entry = + Ipv4Entry { tag: ctx.tag.clone().unwrap_or("".into()), addr }; let switch = ctx.switch; let link_id = link.link_id; switch.delete_ipv4_address_locked(link, addr)?; @@ -538,10 +518,8 @@ impl PortSettingsDiff { ) -> DpdResult<()> { trace!(ctx.log, "ipv6 add {addr}"); // Create address on ASIC first. - let entry = Ipv6Entry { - tag: ctx.tag.clone().unwrap_or("".into()), - addr, - }; + let entry = + Ipv6Entry { tag: ctx.tag.clone().unwrap_or("".into()), addr }; let switch = ctx.switch; let link_id = link.link_id; switch.create_ipv6_address_locked(link, entry)?; @@ -567,10 +545,8 @@ impl PortSettingsDiff { switch.delete_ipv6_address_locked(link, addr)?; rb.wind(move |ctx: &mut Context<'_>| -> DpdResult<()> { - let entry = Ipv6Entry { - tag: ctx.tag.clone().unwrap_or("".into()), - addr, - }; + let entry = + Ipv6Entry { tag: ctx.tag.clone().unwrap_or("".into()), addr }; let switch = ctx.switch; let link_lock = ctx.link(link_id)?; let mut link = link_lock.lock().unwrap(); diff --git a/dpd/src/route.rs b/dpd/src/route.rs index 28a8bb6..c35bf85 100644 --- a/dpd/src/route.rs +++ b/dpd/src/route.rs @@ -229,10 +229,7 @@ pub struct RouteEntry { impl RouteEntry { fn targets(&self) -> Vec { - self.targets - .iter() - .map(|target| target.route.clone()) - .collect() + self.targets.iter().map(|target| target.route.clone()).collect() } } @@ -377,10 +374,7 @@ fn replace_route_targets( ) -> DpdResult<()> { // Remove the old entry from our in-core and on-chip indexes, but don't free // the data yet. - debug!( - switch.log, - "replacing targets for {subnet} with: {targets:?}" - ); + debug!(switch.log, "replacing targets for {subnet} with: {targets:?}"); let old_entry = route_data.remove(subnet); if let Some(ref old) = old_entry && let Err(e) = match subnet { @@ -503,14 +497,10 @@ fn add_route_locked( } // Get the old set of targets that we'll be adding to - let mut targets = route_data - .get(subnet) - .map_or(Vec::new(), |e| e.targets.clone()); + let mut targets = + route_data.get(subnet).map_or(Vec::new(), |e| e.targets.clone()); // Add the new target - targets.push(NextHop { - asic_port_id, - route, - }); + targets.push(NextHop { asic_port_id, route }); if targets.len() > max_targets { Err(DpdError::InvalidRoute(format!( @@ -566,10 +556,7 @@ async fn set_route( Err(DpdError::Exists("route {cidr} already exists".into())) } else { info!(switch.log, "replacing subnet {subnet}"); - let target = vec![NextHop { - asic_port_id, - route, - }]; + let target = vec![NextHop { asic_port_id, route }]; replace_route_targets(switch, &mut route_data, subnet, target) } } else { diff --git a/dpd/src/switch_identifiers.rs b/dpd/src/switch_identifiers.rs index 04c0897..93ae761 100644 --- a/dpd/src/switch_identifiers.rs +++ b/dpd/src/switch_identifiers.rs @@ -34,9 +34,7 @@ use omicron_common::{ pub(crate) async fn fetch_switch_identifiers_loop( switch: Arc, ) -> DpdResult { - let log = switch - .log - .new(o!("unit" => "fetch-switch-identifiers-task")); + let log = switch.log.new(o!("unit" => "fetch-switch-identifiers-task")); // Get the UUID for the switch let sidecar_idents = switch.asic_hdl.get_sidecar_identifiers()?; diff --git a/dpd/src/switch_port.rs b/dpd/src/switch_port.rs index 8362449..a01fda3 100644 --- a/dpd/src/switch_port.rs +++ b/dpd/src/switch_port.rs @@ -138,11 +138,7 @@ impl SwitchPorts { None => BTreeMap::new(), }; - Ok(Self { - port_map, - ports, - xcvr_defaults, - }) + Ok(Self { port_map, ports, xcvr_defaults }) } pub fn verify_exists(&self, port_id: PortId) -> DpdResult<()> { @@ -197,9 +193,7 @@ impl SwitchPort { mode: ManagementMode, ) -> DpdResult<()> { let Some(device) = self.as_qsfp_mut() else { - return Err(DpdError::NotAQsfpPort { - port_id: self.port_id(), - }); + return Err(DpdError::NotAQsfpPort { port_id: self.port_id() }); }; device.management_mode = mode; Ok(()) @@ -209,9 +203,7 @@ impl SwitchPort { /// this is another kind of port. pub fn management_mode(&self) -> DpdResult { let Some(device) = self.as_qsfp() else { - return Err(DpdError::NotAQsfpPort { - port_id: self.port_id(), - }); + return Err(DpdError::NotAQsfpPort { port_id: self.port_id() }); }; Ok(device.management_mode) } @@ -285,10 +277,7 @@ impl From<&SwitchPort> for views::SwitchPort { FixedSideDevice::Qsfp { device, .. } => Some(device.clone()), _ => None, }; - Self { - port_id: p.port_id(), - qsfp_device, - } + Self { port_id: p.port_id(), qsfp_device } } } @@ -333,11 +322,9 @@ impl crate::Switch { if let Some(tx_eq) = match (link.tx_eq, &mpn) { (Some(user_defined), _) => Some(user_defined), - (None, Some(mpn)) => self - .switch_ports - .xcvr_defaults - .get(mpn) - .and_then(|x| x.tx_eq), + (None, Some(mpn)) => { + self.switch_ports.xcvr_defaults.get(mpn).and_then(|x| x.tx_eq) + } (_, _) => None, } { let mpn = mpn @@ -366,11 +353,7 @@ impl crate::Switch { /// also fail. pub fn qsfp_default_fec(&self, qsfp_mpn: &str) -> DpdResult { slog::debug!(self.log, "looking up default FEC for {qsfp_mpn}"); - match self - .switch_ports - .xcvr_defaults - .get(qsfp_mpn) - .and_then(|x| x.fec) + match self.switch_ports.xcvr_defaults.get(qsfp_mpn).and_then(|x| x.fec) { Some(fec) => Ok(fec), None => Err(DpdError::Missing( @@ -397,12 +380,10 @@ impl crate::Switch { }; let (controller, mut sp) = self.acquire_transceiver_resources(qsfp_port).await?; - let led_policy = sp - .led_policy_mut() - .ok_or(DpdError::NotAQsfpPort { port_id })?; - let result = controller - .set_leds(module_id_from_qsfp(qsfp_port), state) - .await?; + let led_policy = + sp.led_policy_mut().ok_or(DpdError::NotAQsfpPort { port_id })?; + let result = + controller.set_leds(module_id_from_qsfp(qsfp_port), state).await?; if result.is_success() { *led_policy = LedPolicy::Override; Ok(()) @@ -456,10 +437,7 @@ impl crate::Switch { let controller = self.transceiver_controller().await?; let result = controller.leds(module_id_from_qsfp(qsfp_port)).await?; if result.is_success() { - Ok(Led { - policy, - state: result.data[0], - }) + Ok(Led { policy, state: result.data[0] }) } else { Err(DpdError::from( result.error_iter().next().map(|(_, err)| err).unwrap(), diff --git a/dpd/src/table/attached_subnet_v4.rs b/dpd/src/table/attached_subnet_v4.rs index 8f729fb..afd3e21 100644 --- a/dpd/src/table/attached_subnet_v4.rs +++ b/dpd/src/table/attached_subnet_v4.rs @@ -30,11 +30,7 @@ struct AttachedSubnetV4MatchKey { #[derive(ActionParse)] enum AttachedSubnetV4Action { #[action_xlate(name = "forward_to_v4")] - Forward { - target: Ipv6Addr, - inner_mac: MacAddr, - vni: u32, - }, + Forward { target: Ipv6Addr, inner_mac: MacAddr, vni: u32 }, } pub fn add_entry( diff --git a/dpd/src/table/attached_subnet_v6.rs b/dpd/src/table/attached_subnet_v6.rs index 0465c8f..c700c7c 100644 --- a/dpd/src/table/attached_subnet_v6.rs +++ b/dpd/src/table/attached_subnet_v6.rs @@ -29,11 +29,7 @@ struct AttachedSubnetV6MatchKey { #[derive(ActionParse)] enum AttachedSubnetV6Action { #[action_xlate(name = "forward_to_v6")] - Forward { - target: Ipv6Addr, - inner_mac: MacAddr, - vni: u32, - }, + Forward { target: Ipv6Addr, inner_mac: MacAddr, vni: u32 }, } pub fn add_entry( diff --git a/dpd/src/table/mcast/mcast_egress.rs b/dpd/src/table/mcast/mcast_egress.rs index e050c2a..a6dbfed 100644 --- a/dpd/src/table/mcast/mcast_egress.rs +++ b/dpd/src/table/mcast/mcast_egress.rs @@ -206,14 +206,9 @@ pub(crate) fn add_port_mapping_entry( let (port, _) = s.asic_id_to_port_link(asic_port_id)?; - let action_data = PortIdAction::SetPortNumber { - port_number: port.as_u8(), - }; + let action_data = PortIdAction::SetPortNumber { port_number: port.as_u8() }; - debug!( - s.log, - "add port id entry {} -> {:?}", match_key, action_data - ); + debug!(s.log, "add port id entry {} -> {:?}", match_key, action_data); s.table_entry_add( TableType::McastEgressPortMapping, @@ -233,14 +228,9 @@ pub(crate) fn update_port_mapping_entry( let (port, _) = s.asic_id_to_port_link(asic_port_id)?; - let action_data = PortIdAction::SetPortNumber { - port_number: port.as_u8(), - }; + let action_data = PortIdAction::SetPortNumber { port_number: port.as_u8() }; - debug!( - s.log, - "update port id entry {} -> {:?}", match_key, action_data - ); + debug!(s.log, "update port id entry {} -> {:?}", match_key, action_data); s.table_entry_update( TableType::McastEgressPortMapping, @@ -257,10 +247,7 @@ pub(crate) fn del_port_mapping_entry( ) -> DpdResult<()> { let match_key = MatchKeyPortId::new(asic_port_id); - debug!( - s.log, - "delete port id entry {} -> {}", match_key, asic_port_id - ); + debug!(s.log, "delete port id entry {} -> {}", match_key, asic_port_id); s.table_entry_del(TableType::McastEgressPortMapping, &match_key) } diff --git a/dpd/src/table/mcast/mcast_nat.rs b/dpd/src/table/mcast/mcast_nat.rs index 36fe0fa..62c5cd9 100644 --- a/dpd/src/table/mcast/mcast_nat.rs +++ b/dpd/src/table/mcast/mcast_nat.rs @@ -27,21 +27,13 @@ pub(crate) const IPV6_TABLE_NAME: &str = #[derive(ActionParse, Debug)] enum Ipv4Action { #[action_xlate(name = "mcast_forward_ipv4_to")] - Forward { - target: Ipv6Addr, - inner_mac: MacAddr, - vni: u32, - }, + Forward { target: Ipv6Addr, inner_mac: MacAddr, vni: u32 }, } #[derive(ActionParse, Debug)] enum Ipv6Action { #[action_xlate(name = "mcast_forward_ipv6_to")] - Forward { - target: Ipv6Addr, - inner_mac: MacAddr, - vni: u32, - }, + Forward { target: Ipv6Addr, inner_mac: MacAddr, vni: u32 }, } /// Add a NAT entry for IPv4 multicast traffic, keyed on `ip`. @@ -57,10 +49,7 @@ pub(crate) fn add_ipv4_entry( vni: tgt.vni.as_u32(), }; - debug!( - s.log, - "add ingress mcast entry {} -> {:?}", match_key, action_key - ); + debug!(s.log, "add ingress mcast entry {} -> {:?}", match_key, action_key); s.table_entry_add(TableType::NatIngressIpv4Mcast, &match_key, &action_key) } @@ -130,10 +119,7 @@ pub(crate) fn add_ipv6_entry( vni: tgt.vni.as_u32(), }; - debug!( - s.log, - "add ingress mcast entry {} -> {:?}", match_key, action_key - ); + debug!(s.log, "add ingress mcast entry {} -> {:?}", match_key, action_key); s.table_entry_add(TableType::NatIngressIpv6Mcast, &match_key, &action_key) } diff --git a/dpd/src/table/mcast/mcast_replication.rs b/dpd/src/table/mcast/mcast_replication.rs index 46fef82..a94b1e7 100644 --- a/dpd/src/table/mcast/mcast_replication.rs +++ b/dpd/src/table/mcast/mcast_replication.rs @@ -69,10 +69,7 @@ pub(crate) fn add_ipv6_entry( level2_excl_id, }; - debug!( - s.log, - "add mcast_ipv6 entry {} -> {:?}", dst_addr, action_data - ); + debug!(s.log, "add mcast_ipv6 entry {} -> {:?}", dst_addr, action_data); s.table_entry_add(TableType::McastIpv6, &match_key, &action_data) } @@ -107,10 +104,7 @@ pub(crate) fn update_ipv6_entry( level2_excl_id, }; - debug!( - s.log, - "update mcast_ipv6 entry {} -> {:?}", dst_addr, action_data - ); + debug!(s.log, "update mcast_ipv6 entry {} -> {:?}", dst_addr, action_data); s.table_entry_update(TableType::McastIpv6, &match_key, &action_data) } diff --git a/dpd/src/table/mcast/mcast_route.rs b/dpd/src/table/mcast/mcast_route.rs index 8fcf789..56c9af4 100644 --- a/dpd/src/table/mcast/mcast_route.rs +++ b/dpd/src/table/mcast/mcast_route.rs @@ -57,10 +57,7 @@ pub(crate) fn add_ipv4_entry( } }; - debug!( - s.log, - "add multicast route entry {} -> {:?}", route, action_data - ); + debug!(s.log, "add multicast route entry {} -> {:?}", route, action_data); s.table_entry_add(TableType::RouteIpv4Mcast, &match_key, &action_data) } @@ -142,10 +139,7 @@ pub(crate) fn add_ipv6_entry( } }; - debug!( - s.log, - "add multicast route entry {} -> {:?}", route, action_data - ); + debug!(s.log, "add multicast route entry {} -> {:?}", route, action_data); s.table_entry_add(TableType::RouteIpv6Mcast, &match_key, &action_data) } diff --git a/dpd/src/table/mcast/mcast_src_filter.rs b/dpd/src/table/mcast/mcast_src_filter.rs index 133de4b..66040ad 100644 --- a/dpd/src/table/mcast/mcast_src_filter.rs +++ b/dpd/src/table/mcast/mcast_src_filter.rs @@ -84,10 +84,7 @@ pub(crate) fn add_ipv4_entry( let match_key = Ipv4MatchKey::new(src_addr, dst_addr); let action_data = Ipv4Action::AllowSrc; - debug!( - s.log, - "add source filter entry {} -> {:?}", src_addr, action_data - ); + debug!(s.log, "add source filter entry {} -> {:?}", src_addr, action_data); s.table_entry_add(TableType::McastIpv4SrcFilter, &match_key, &action_data) } @@ -101,10 +98,7 @@ pub(crate) fn del_ipv4_entry( ) -> DpdResult<()> { let match_key = Ipv4MatchKey::new(src_addr, dst_addr); - debug!( - s.log, - "delete source filter entry {} -> {}", src_addr, dst_addr - ); + debug!(s.log, "delete source filter entry {} -> {}", src_addr, dst_addr); s.table_entry_del(TableType::McastIpv4SrcFilter, &match_key) } @@ -137,10 +131,7 @@ pub(crate) fn add_ipv6_entry( let match_key = Ipv6MatchKey::new(src_addr, dst_addr); let action_data = Ipv6Action::AllowSrc; - debug!( - s.log, - "add source filter entry {} -> {:?}", src_addr, action_data - ); + debug!(s.log, "add source filter entry {} -> {:?}", src_addr, action_data); s.table_entry_add(TableType::McastIpv6SrcFilter, &match_key, &action_data) } @@ -154,10 +145,7 @@ pub(crate) fn del_ipv6_entry( ) -> DpdResult<()> { let match_key = Ipv6MatchKey::new(src_addr, dst_addr); - debug!( - s.log, - "delete source filter entry {} -> {}", src_addr, dst_addr - ); + debug!(s.log, "delete source filter entry {} -> {}", src_addr, dst_addr); s.table_entry_del(TableType::McastIpv6SrcFilter, &match_key) } diff --git a/dpd/src/table/mod.rs b/dpd/src/table/mod.rs index 16f13f0..09869eb 100644 --- a/dpd/src/table/mod.rs +++ b/dpd/src/table/mod.rs @@ -50,34 +50,13 @@ const NAME_TO_TYPE: [(&str, TableType); 24] = [ attached_subnet_v6::EXT_SUBNET_IPV6_TABLE_NAME, TableType::AttachedSubnetIpv6, ), - ( - mcast::mcast_replication::IPV6_TABLE_NAME, - TableType::McastIpv6, - ), - ( - mcast::mcast_src_filter::IPV4_TABLE_NAME, - TableType::McastIpv4SrcFilter, - ), - ( - mcast::mcast_src_filter::IPV6_TABLE_NAME, - TableType::McastIpv6SrcFilter, - ), - ( - mcast::mcast_nat::IPV4_TABLE_NAME, - TableType::NatIngressIpv4Mcast, - ), - ( - mcast::mcast_nat::IPV6_TABLE_NAME, - TableType::NatIngressIpv6Mcast, - ), - ( - mcast::mcast_route::IPV4_TABLE_NAME, - TableType::RouteIpv4Mcast, - ), - ( - mcast::mcast_route::IPV6_TABLE_NAME, - TableType::RouteIpv6Mcast, - ), + (mcast::mcast_replication::IPV6_TABLE_NAME, TableType::McastIpv6), + (mcast::mcast_src_filter::IPV4_TABLE_NAME, TableType::McastIpv4SrcFilter), + (mcast::mcast_src_filter::IPV6_TABLE_NAME, TableType::McastIpv6SrcFilter), + (mcast::mcast_nat::IPV4_TABLE_NAME, TableType::NatIngressIpv4Mcast), + (mcast::mcast_nat::IPV6_TABLE_NAME, TableType::NatIngressIpv6Mcast), + (mcast::mcast_route::IPV4_TABLE_NAME, TableType::RouteIpv4Mcast), + (mcast::mcast_route::IPV6_TABLE_NAME, TableType::RouteIpv6Mcast), (mcast::mcast_port_mac::TABLE_NAME, TableType::PortMacMcast), ( mcast::mcast_egress::DECAP_PORTS_TABLE_NAME, @@ -246,9 +225,7 @@ impl Table { M: MatchParse, A: ActionParse, { - self.asic_data - .get_entries::(hdl) - .map_err(|e| e.into()) + self.asic_data.get_entries::(hdl).map_err(|e| e.into()) } /// Ask the ASIC-level code to fetch the counter data from the ASIC's @@ -261,18 +238,12 @@ impl Table { where M: MatchParse, { - self.asic_data - .get_counters::(hdl, force_sync) - .map_err(|e| e.into()) + self.asic_data.get_counters::(hdl, force_sync).map_err(|e| e.into()) } } pub fn list(switch: &Switch) -> Vec { - switch - .tables - .values() - .map(|t| t.lock().unwrap().name.to_string()) - .collect() + switch.tables.values().map(|t| t.lock().unwrap().name.to_string()).collect() } /// Given the name of a table, call into the table-specific code to get the diff --git a/dpd/src/table/nat.rs b/dpd/src/table/nat.rs index 84c2404..70041c2 100644 --- a/dpd/src/table/nat.rs +++ b/dpd/src/table/nat.rs @@ -35,21 +35,14 @@ impl Ipv6MatchKey { { Ipv6MatchKey { dst_addr, - ports: MatchRange { - low: low.into(), - high: high.into(), - }, + ports: MatchRange { low: low.into(), high: high.into() }, } } } impl fmt::Display for Ipv6MatchKey { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!( - f, - "({}/{}-{})", - self.dst_addr, self.ports.low, self.ports.high - ) + write!(f, "({}/{}-{})", self.dst_addr, self.ports.low, self.ports.high) } } @@ -68,42 +61,27 @@ impl Ipv4MatchKey { { Ipv4MatchKey { dst_addr, - ports: MatchRange { - low: low.into(), - high: high.into(), - }, + ports: MatchRange { low: low.into(), high: high.into() }, } } } impl fmt::Display for Ipv4MatchKey { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!( - f, - "({}/{}-{})", - self.dst_addr, self.ports.low, self.ports.high - ) + write!(f, "({}/{}-{})", self.dst_addr, self.ports.low, self.ports.high) } } #[derive(ActionParse)] enum Ipv6Action { #[action_xlate(name = "forward_ipv6_to")] - Forward { - target: Ipv6Addr, - inner_mac: MacAddr, - vni: u32, - }, + Forward { target: Ipv6Addr, inner_mac: MacAddr, vni: u32 }, } #[derive(ActionParse)] enum Ipv4Action { #[action_xlate(name = "forward_ipv4_to")] - Forward { - target: Ipv6Addr, - inner_mac: MacAddr, - vni: u32, - }, + Forward { target: Ipv6Addr, inner_mac: MacAddr, vni: u32 }, } pub fn add_ipv6_entry( diff --git a/dpd/src/table/port_ip.rs b/dpd/src/table/port_ip.rs index f81524a..7cf12f2 100644 --- a/dpd/src/table/port_ip.rs +++ b/dpd/src/table/port_ip.rs @@ -72,17 +72,11 @@ const REPAIR_ATTEMPTS: usize = 3; fn match_keys_ipv4(ipv4: Ipv4Addr, port: u16) -> (Ipv4MatchKey, Ipv4MatchKey) { let claim_key = Ipv4MatchKey { dst_addr: ipv4, - in_port: MatchMask { - val: port.into(), - mask: 0x1ffu16.into(), - }, + in_port: MatchMask { val: port.into(), mask: 0x1ffu16.into() }, }; let drop_key = Ipv4MatchKey { dst_addr: ipv4, - in_port: MatchMask { - val: port.into(), - mask: 0u16.into(), - }, + in_port: MatchMask { val: port.into(), mask: 0u16.into() }, }; (claim_key, drop_key) } @@ -90,17 +84,11 @@ fn match_keys_ipv4(ipv4: Ipv4Addr, port: u16) -> (Ipv4MatchKey, Ipv4MatchKey) { fn match_keys_ipv6(ipv6: Ipv6Addr, port: u16) -> (Ipv6MatchKey, Ipv6MatchKey) { let claim_key = Ipv6MatchKey { dst_addr: ipv6, - in_port: MatchMask { - val: port.into(), - mask: 0x1ffu16.into(), - }, + in_port: MatchMask { val: port.into(), mask: 0x1ffu16.into() }, }; let drop_key = Ipv6MatchKey { dst_addr: ipv6, - in_port: MatchMask { - val: 0u16.into(), - mask: 0u16.into(), - }, + in_port: MatchMask { val: 0u16.into(), mask: 0u16.into() }, }; (claim_key, drop_key) } @@ -108,10 +96,7 @@ fn match_keys_ipv6(ipv6: Ipv6Addr, port: u16) -> (Ipv6MatchKey, Ipv6MatchKey) { pub fn loopback_ipv4_add(s: &Switch, ipv4: Ipv4Addr) -> DpdResult<()> { let claim_key = Ipv4MatchKey { dst_addr: ipv4, - in_port: MatchMask { - val: 0u16.into(), - mask: 0u16.into(), - }, + in_port: MatchMask { val: 0u16.into(), mask: 0u16.into() }, }; s.table_entry_add(TableType::PortIpv4, &claim_key, &ActionV4::ClaimIpv4) .map(|_| info!(s.log, "added ipv4 loopback"; "addr" => %ipv4)) @@ -125,10 +110,7 @@ pub fn loopback_ipv4_add(s: &Switch, ipv4: Ipv4Addr) -> DpdResult<()> { pub fn loopback_ipv4_delete(s: &Switch, ipv4: Ipv4Addr) -> DpdResult<()> { let claim_key = Ipv4MatchKey { dst_addr: ipv4, - in_port: MatchMask { - val: 0u16.into(), - mask: 0u16.into(), - }, + in_port: MatchMask { val: 0u16.into(), mask: 0u16.into() }, }; s.table_entry_del(TableType::PortIpv4, &claim_key) .map(|_| info!(s.log, "deleted ipv4 loopback"; "addr" => %ipv4)) @@ -142,10 +124,7 @@ pub fn loopback_ipv4_delete(s: &Switch, ipv4: Ipv4Addr) -> DpdResult<()> { pub fn loopback_ipv6_add(s: &Switch, ipv6: Ipv6Addr) -> DpdResult<()> { let claim_key = Ipv6MatchKey { dst_addr: ipv6, - in_port: MatchMask { - val: 0u16.into(), - mask: 0u16.into(), - }, + in_port: MatchMask { val: 0u16.into(), mask: 0u16.into() }, }; s.table_entry_add(TableType::PortIpv6, &claim_key, &ActionV6::ClaimIpv6) .map(|_| info!(s.log, "added ipv6 loopback"; "addr" => %ipv6)) @@ -159,10 +138,7 @@ pub fn loopback_ipv6_add(s: &Switch, ipv6: Ipv6Addr) -> DpdResult<()> { pub fn loopback_ipv6_delete(s: &Switch, ipv6: Ipv6Addr) -> DpdResult<()> { let claim_key = Ipv6MatchKey { dst_addr: ipv6, - in_port: MatchMask { - val: 0u16.into(), - mask: 0u16.into(), - }, + in_port: MatchMask { val: 0u16.into(), mask: 0u16.into() }, }; s.table_entry_del(TableType::PortIpv6, &claim_key) .map(|_| info!(s.log, "deleted ipv6 loopback"; "addr" => %ipv6)) @@ -225,20 +201,19 @@ fn ipv4_delete_work(s: &Switch, port: u16, ipv4: Ipv4Addr) -> DpdResult<()> { let (claim_key, drop_key) = match_keys_ipv4(ipv4, port); s.table_entry_del(TableType::PortIpv4, &claim_key)?; - s.table_entry_del(TableType::PortIpv4, &drop_key) - .inspect_err(|_| { - endeavour_to_repair( - s, - format!("ipv4 address {ipv4} only half deleted"), - || { - s.table_entry_add( - TableType::PortIpv4, - &claim_key, - &ActionV4::ClaimIpv4, - ) - }, - ); - }) + s.table_entry_del(TableType::PortIpv4, &drop_key).inspect_err(|_| { + endeavour_to_repair( + s, + format!("ipv4 address {ipv4} only half deleted"), + || { + s.table_entry_add( + TableType::PortIpv4, + &claim_key, + &ActionV4::ClaimIpv4, + ) + }, + ); + }) } /// Delete one IPv4 address from the ASIC tables. @@ -303,20 +278,19 @@ fn ipv6_delete_work(s: &Switch, port: u16, ipv6: Ipv6Addr) -> DpdResult<()> { let (claim_key, drop_key) = match_keys_ipv6(ipv6, port); s.table_entry_del(TableType::PortIpv6, &claim_key)?; - s.table_entry_del(TableType::PortIpv6, &drop_key) - .inspect_err(|_| { - endeavour_to_repair( - s, - format!("ipv6 address {ipv6} only half deleted"), - || { - s.table_entry_add( - TableType::PortIpv6, - &claim_key, - &ActionV6::ClaimIpv6, - ) - }, - ); - }) + s.table_entry_del(TableType::PortIpv6, &drop_key).inspect_err(|_| { + endeavour_to_repair( + s, + format!("ipv6 address {ipv6} only half deleted"), + || { + s.table_entry_add( + TableType::PortIpv6, + &claim_key, + &ActionV6::ClaimIpv6, + ) + }, + ); + }) } /// Delete one IPv6 address from the ASIC tables. diff --git a/dpd/src/table/route_ipv4.rs b/dpd/src/table/route_ipv4.rs index 93d1003..184e688 100644 --- a/dpd/src/table/route_ipv4.rs +++ b/dpd/src/table/route_ipv4.rs @@ -34,11 +34,7 @@ enum RouteAction { #[action_xlate(name = "forward")] Forward { port: u16, nexthop: Ipv4Addr }, #[action_xlate(name = "forward_vlan")] - ForwardVlan { - port: u16, - nexthop: Ipv4Addr, - vlan_id: u16, - }, + ForwardVlan { port: u16, nexthop: Ipv4Addr, vlan_id: u16 }, } // Used to identify entries in the route->index table @@ -112,11 +108,7 @@ pub fn add_route_target( None => RouteAction::Forward { port, nexthop }, Some(vlan_id) => { common::network::validate_vlan(vlan_id)?; - RouteAction::ForwardVlan { - port, - nexthop, - vlan_id, - } + RouteAction::ForwardVlan { port, nexthop, vlan_id } } }; diff --git a/dpd/src/table/route_ipv6.rs b/dpd/src/table/route_ipv6.rs index e96c20f..a32775e 100644 --- a/dpd/src/table/route_ipv6.rs +++ b/dpd/src/table/route_ipv6.rs @@ -34,11 +34,7 @@ enum RouteAction { #[action_xlate(name = "forward")] Forward { port: u16, nexthop: Ipv6Addr }, #[action_xlate(name = "forward_vlan")] - ForwardVlan { - port: u16, - nexthop: Ipv6Addr, - vlan_id: u16, - }, + ForwardVlan { port: u16, nexthop: Ipv6Addr, vlan_id: u16 }, } // Used to identify entries in the route->index table @@ -112,11 +108,7 @@ pub fn add_route_target( None => RouteAction::Forward { port, nexthop }, Some(vlan_id) => { common::network::validate_vlan(vlan_id)?; - RouteAction::ForwardVlan { - port, - nexthop, - vlan_id, - } + RouteAction::ForwardVlan { port, nexthop, vlan_id } } }; diff --git a/dpd/src/transceivers/mod.rs b/dpd/src/transceivers/mod.rs index 1e894b8..985e9c1 100644 --- a/dpd/src/transceivers/mod.rs +++ b/dpd/src/transceivers/mod.rs @@ -128,12 +128,8 @@ impl Default for FakeQsfpModule { // Mfg date, assume 2022-01-1 with lot "ab". map[212..220].copy_from_slice(b"220101ab"); - let mut self_ = Self { - map, - present: true, - lp_mode: true, - in_reset: true, - }; + let mut self_ = + Self { map, present: true, lp_mode: true, in_reset: true }; let (base_sum, ext_sum) = self_.compute_checksums(); self_.map[Self::CC_BASE_CHECKSUM] = base_sum; @@ -166,10 +162,7 @@ impl FakeQsfpModule { // Return the base and extended checksums. #[cfg(all(test, feature = "tofino_asic"))] fn checksums(&self) -> (u8, u8) { - ( - self.map[Self::CC_BASE_CHECKSUM], - self.map[Self::EXTENDED_CHECKSUM], - ) + (self.map[Self::CC_BASE_CHECKSUM], self.map[Self::EXTENDED_CHECKSUM]) } } @@ -203,10 +196,8 @@ mod mpn_test { serial: "serial".to_string(), date: None, }; - let vendor_info = VendorInfo { - identifier: Identifier::Soldered, - vendor, - }; + let vendor_info = + VendorInfo { identifier: Identifier::Soldered, vendor }; let transceiver = Transceiver::Supported(TransceiverInfo { vendor_info: Some(vendor_info), diff --git a/dpd/src/transceivers/tofino_impl.rs b/dpd/src/transceivers/tofino_impl.rs index e8e308b..3e9392f 100644 --- a/dpd/src/transceivers/tofino_impl.rs +++ b/dpd/src/transceivers/tofino_impl.rs @@ -202,10 +202,7 @@ impl<'a> LockedController<'a> { // modified. We also check that the contained Option is none, so the // unwrap is safe. let guard = MutexGuard::map(guard, |f| f.as_mut().unwrap()); - Ok(LockedController { - guard, - id: StdMutex::new(id), - }) + Ok(LockedController { guard, id: StdMutex::new(id) }) } } @@ -379,12 +376,7 @@ impl TransceiverState { } } - Self { - controller: ctl, - can_be_notified, - rebuild: notify, - channels, - } + Self { controller: ctl, can_be_notified, rebuild: notify, channels } } /// Trigger a rebuild of the transceiver controller. @@ -713,11 +705,7 @@ mod transceiver_chaos { // Create the new response, potentially with injected errors, and notify // about any injections. - let new = StatusResult { - modules, - data, - failures, - }; + let new = StatusResult { modules, data, failures }; if !injected_failures.modules.is_empty() { debug!( log, @@ -756,11 +744,7 @@ mod transceiver_chaos { } } let failures = res.failures.merge(&injected_failures); - let new = ModuleResult { - modules, - data, - failures, - }; + let new = ModuleResult { modules, data, failures }; if !injected_failures.modules.is_empty() { debug!( log, @@ -1700,10 +1684,8 @@ impl Switch { let mut sp_request_rx = self.transceivers.channels.sp_request_rx.lock().await; - while let Some(SpRequest { - request, - response_tx, - }) = sp_request_rx.recv().await + while let Some(SpRequest { request, response_tx }) = + sp_request_rx.recv().await { // TODO-implement We need to actually handle requests here, such as // by updating the control plane if, say, a module is removed or @@ -1754,10 +1736,8 @@ impl Switch { // Await a possible request from the SDE. loop { probes::sde__request__queue__wait__start!(|| ()); - let Some(SdeTransceiverMessage { - request, - response_tx, - }) = sde_request_rx.recv().await + let Some(SdeTransceiverMessage { request, response_tx }) = + sde_request_rx.recv().await else { break; }; @@ -2182,9 +2162,7 @@ async fn handle_detect_request( "module" => module, "present" => device.present, ); - Ok(SdeTransceiverResponse::Detect { - present: device.present, - }) + Ok(SdeTransceiverResponse::Detect { present: device.present }) } PortId::Qsfp(qsfp) => { let Ok(controller) = LockedController::new(controller).await else { @@ -2661,13 +2639,7 @@ async fn handle_write_request( controller: &Arc>>, write: WriteRequest, ) -> Result { - let WriteRequest { - module, - bank, - page, - offset, - data, - } = write; + let WriteRequest { module, bank, page, offset, data } = write; let port_id = tofino_connector_to_port_id(&switch_ports.port_map, log, module)?; match port_id { @@ -2757,13 +2729,7 @@ async fn handle_read_request( controller: &Arc>>, read: ReadRequest, ) -> Result { - let ReadRequest { - module, - bank, - page, - offset, - len, - } = read; + let ReadRequest { module, bank, page, offset, len } = read; let port_id = tofino_connector_to_port_id(&switch_ports.port_map, log, module)?; match port_id { @@ -4079,10 +4045,8 @@ mod tests { // We set the backplane module corresponding to cubby 0 into LPMode. We // need to map that into the bit position of the Tofino connector number // we use to report that to the SDE. - let Connector::QSFP(connector) = switch_ports - .port_map - .id_to_connector(&backplane_port) - .unwrap() + let Connector::QSFP(connector) = + switch_ports.port_map.id_to_connector(&backplane_port).unwrap() else { unreachable!(); }; @@ -4117,9 +4081,8 @@ mod tests { let controller = Arc::new(Mutex::new(Some(controller))); let log = logger(); - let result = handle_interrupt_mask_request(&log, &controller) - .await - .unwrap(); + let result = + handle_interrupt_mask_request(&log, &controller).await.unwrap(); let SdeTransceiverResponse::InterruptMask { backplane, qsfp } = result else { panic!("Expected a `SdeTransceiverResponse::InterruptMask`"); @@ -4811,13 +4774,7 @@ mod tests { let offset = 100; let expected_data = vec![0, 1, 2, 3]; let len = expected_data.len() as u8; - let read = ReadRequest { - module, - bank, - page, - offset, - len, - }; + let read = ReadRequest { module, bank, page, offset, len }; // Describe the read operation we expect the controller to be called // with. @@ -4874,13 +4831,7 @@ mod tests { let offset = 200; let expected_data = vec![0, 1, 2, 3]; let len = expected_data.len() as u8; - let read = ReadRequest { - module, - bank, - page, - offset, - len, - }; + let read = ReadRequest { module, bank, page, offset, len }; // Describe the read operation we expect the controller to be called // with. @@ -4943,13 +4894,7 @@ mod tests { let page = 0; let offset = 100; let len = 4; - let read = ReadRequest { - module, - bank, - page, - offset, - len, - }; + let read = ReadRequest { module, bank, page, offset, len }; // The function should call to the controller to check the Identifier. // Upon finding an SFF-8636 module, it should fail any request with a @@ -4994,13 +4939,7 @@ mod tests { let offset = 100; let expected_data = vec![0, 1, 2, 3]; let len = expected_data.len() as u8; - let read = ReadRequest { - module, - bank, - page, - offset, - len, - }; + let read = ReadRequest { module, bank, page, offset, len }; // Describe the read operation we expect the controller to be called // with. @@ -5060,13 +4999,7 @@ mod tests { let offset = 100; let expected_data = vec![0; 24]; let len = expected_data.len() as u8; - let read = ReadRequest { - module, - bank, - page, - offset, - len, - }; + let read = ReadRequest { module, bank, page, offset, len }; // Describe the read operations we expect the controller to be called // with. diff --git a/dpd/src/types.rs b/dpd/src/types.rs index d466d96..56f49f7 100644 --- a/dpd/src/types.rs +++ b/dpd/src/types.rs @@ -49,11 +49,7 @@ pub enum DpdError { #[error( "Address {address} is not associated with port \"{port_id}\" link \"{link_id}\"" )] - NoSuchAddress { - port_id: PortId, - link_id: LinkId, - address: IpAddr, - }, + NoSuchAddress { port_id: PortId, link_id: LinkId, address: IpAddr }, #[error("no matching route found")] NoSuchRoute, #[error("No such table: {0}")] @@ -69,10 +65,7 @@ pub enum DpdError { #[error("Port \"{port_id}\" is not a QSFP port")] NotAQsfpPort { port_id: PortId }, #[error("Unwind: initial: {initial}, unwind: {unwind}")] - Unwind { - initial: Box, - unwind: Box, - }, + Unwind { initial: Box, unwind: Box }, #[error("No transceiver controller initialized")] NoTransceiverController, #[error("Failed to operate on transceivers")] diff --git a/packet/src/icmp.rs b/packet/src/icmp.rs index 787fb31..9a0f8f3 100644 --- a/packet/src/icmp.rs +++ b/packet/src/icmp.rs @@ -160,10 +160,7 @@ impl Protocol for IcmpHdr { ( None, None, - Some(format!( - "type: {} code: {}", - self.icmp_type, self.icmp_code - )), + Some(format!("type: {} code: {}", self.icmp_type, self.icmp_code)), ) } } @@ -268,12 +265,8 @@ fn test_v4_checksum() { 0x00, 0x00, 0x00, 0x00, 0x00, ]; - let icmp_hdr = IcmpHdr { - icmp_type: 11, - icmp_code: 0, - icmp_sum: 0, - icmp_data: 0, - }; + let icmp_hdr = + IcmpHdr { icmp_type: 11, icmp_code: 0, icmp_sum: 0, icmp_data: 0 }; let mut pkt = Packet::new(Some(&data)); pkt.hdrs.icmp_hdr = Some(icmp_hdr); diff --git a/packet/src/lib.rs b/packet/src/lib.rs index 4fba21d..7f8c176 100644 --- a/packet/src/lib.rs +++ b/packet/src/lib.rs @@ -52,10 +52,7 @@ pub enum PacketError { /// Utility function to generate a Parse error pub fn parse_error(pb: &ParseBuffer, message: impl ToString) -> PacketError { - PacketError::Parse { - message: message.to_string(), - byte: pb.offset(), - } + PacketError::Parse { message: message.to_string(), byte: pb.offset() } } /// Utility function to generate a Deparse error @@ -151,11 +148,7 @@ impl L4Endpoint { } pub fn from_l3(l3: L3Endpoint, port: u16) -> L4Endpoint { - L4Endpoint { - mac: l3.mac, - ip: l3.ip, - port, - } + L4Endpoint { mac: l3.mac, ip: l3.ip, port } } } @@ -255,10 +248,7 @@ impl From<&L4Endpoint> for L2Endpoint { impl From for L3Endpoint { fn from(l4: L4Endpoint) -> Self { - L3Endpoint { - mac: l4.mac, - ip: l4.ip, - } + L3Endpoint { mac: l4.mac, ip: l4.ip } } } @@ -281,10 +271,7 @@ impl TryFrom for L3Endpoint { Err(PacketError::Invalid("not an L3 endpoint".into())) } Endpoint::L3(e) => Ok(e), - Endpoint::L4(e) => Ok(L3Endpoint { - mac: e.mac, - ip: e.ip, - }), + Endpoint::L4(e) => Ok(L3Endpoint { mac: e.mac, ip: e.ip }), } } } @@ -389,11 +376,8 @@ impl PartialEq for Packet { let b = &other.hdrs; let mut is_eq = test("eth hdr", a.eth_hdr.as_ref(), b.eth_hdr.as_ref()); - is_eq &= test( - "sidecar hdr", - a.sidecar_hdr.as_ref(), - b.sidecar_hdr.as_ref(), - ); + is_eq &= + test("sidecar hdr", a.sidecar_hdr.as_ref(), b.sidecar_hdr.as_ref()); is_eq &= test("lldp hdr", a.lldp_hdr.as_ref(), b.lldp_hdr.as_ref()); is_eq &= test("ipv4 hdr", a.ipv4_hdr.as_ref(), b.ipv4_hdr.as_ref()); is_eq &= test("ipv6 hdr", a.ipv6_hdr.as_ref(), b.ipv6_hdr.as_ref()); @@ -415,10 +399,7 @@ impl Default for Packet { impl Packet { pub fn new(body: Option<&[u8]>) -> Packet { - Packet { - hdrs: Headers::new(), - body: body.map(|b| b.to_vec()), - } + Packet { hdrs: Headers::new(), body: body.map(|b| b.to_vec()) } } pub fn generate( @@ -444,10 +425,7 @@ impl Packet { hdrs.bytes = pb.offset(); let offset = hdrs.bytes; - Ok(Packet { - hdrs, - body: Some(data[offset..].to_vec()), - }) + Ok(Packet { hdrs, body: Some(data[offset..].to_vec()) }) } pub fn parse(data: &[u8]) -> PacketResult { diff --git a/packet/src/lldp.rs b/packet/src/lldp.rs index 01cc245..c42c337 100644 --- a/packet/src/lldp.rs +++ b/packet/src/lldp.rs @@ -40,11 +40,7 @@ impl LldpTlv { } let lldp_tlv_octets = pb.get_bytes(lldp_tlv_size as usize)?; - Ok(LldpTlv { - lldp_tlv_type, - lldp_tlv_size, - lldp_tlv_octets, - }) + Ok(LldpTlv { lldp_tlv_type, lldp_tlv_size, lldp_tlv_octets }) } } diff --git a/packet/src/pbuf.rs b/packet/src/pbuf.rs index a001b6b..27bece9 100644 --- a/packet/src/pbuf.rs +++ b/packet/src/pbuf.rs @@ -19,12 +19,7 @@ pub struct ParseBuffer<'a> { impl ParseBuffer<'_> { pub fn new_from_slice(d: &[u8]) -> ParseBuffer<'_> { - ParseBuffer { - data: d, - byte: 0, - bit: 0, - len: d.len() * 8, - } + ParseBuffer { data: d, byte: 0, bit: 0, len: d.len() * 8 } } pub fn offset(&self) -> usize { @@ -206,9 +201,7 @@ impl ParseBuffer<'_> { w[i] = ((x[2 * i] as u16) << 8) | (x[2 * i + 1] as u16); } - Ok(Ipv6Addr::new( - w[0], w[1], w[2], w[3], w[4], w[5], w[6], w[7], - )) + Ok(Ipv6Addr::new(w[0], w[1], w[2], w[3], w[4], w[5], w[6], w[7])) } } diff --git a/packet/src/tcp.rs b/packet/src/tcp.rs index f9c3433..c1a8ea8 100644 --- a/packet/src/tcp.rs +++ b/packet/src/tcp.rs @@ -158,11 +158,7 @@ fn parse_options( return Err(crate::parse_error(&pb, "tcp packet too short")); } let opt_data = pb.get_bytes(opt_len as usize)?; - opts.push(TcpOption { - opt_kind, - opt_len, - opt_data, - }); + opts.push(TcpOption { opt_kind, opt_len, opt_data }); } Ok(opts) } diff --git a/pcap/src/lib.rs b/pcap/src/lib.rs index 0762f23..2476f30 100644 --- a/pcap/src/lib.rs +++ b/pcap/src/lib.rs @@ -52,9 +52,7 @@ pub enum Ternary { impl Pcap { fn get_error(hdl: *mut ffi::pcap) -> String { unsafe { - CStr::from_ptr(ffi::pcap_geterr(hdl)) - .to_string_lossy() - .into_owned() + CStr::from_ptr(ffi::pcap_geterr(hdl)).to_string_lossy().into_owned() } } @@ -249,10 +247,8 @@ impl Pcap { program: &str, netmask: u32, ) -> Result { - let mut bpf = ffi::bpf_program { - bf_len: 0, - bf_insns: std::ptr::null_mut(), - }; + let mut bpf = + ffi::bpf_program { bf_len: 0, bf_insns: std::ptr::null_mut() }; match unsafe { let arg = CString::new(program).expect("CString::new failed"); diff --git a/swadm/src/addr.rs b/swadm/src/addr.rs index 76b4024..f1b0098 100644 --- a/swadm/src/addr.rs +++ b/swadm/src/addr.rs @@ -422,12 +422,9 @@ async fn addr_del_loopback( pub async fn addr_cmd(client: &Client, a: Addr) -> anyhow::Result<()> { match a { - Addr::List { - ipv4, - ipv6, - parseable, - link, - } => addr_list(client, ipv4, ipv6, parseable, link).await, + Addr::List { ipv4, ipv6, parseable, link } => { + addr_list(client, ipv4, ipv6, parseable, link).await + } Addr::Add { link, addr } => match &link { LinkName::Loopback => addr_add_loopback(client, addr).await, LinkName::Link(l) => addr_add(client, l, addr).await, diff --git a/swadm/src/arp.rs b/swadm/src/arp.rs index cf01f36..bc8638e 100644 --- a/swadm/src/arp.rs +++ b/swadm/src/arp.rs @@ -114,11 +114,8 @@ async fn arp_list( )?; for e in entries { let mac = common::network::MacAddr::from(e.mac); - let mac = if mac.is_null() { - "incomplete".into() - } else { - mac.to_string() - }; + let mac = + if mac.is_null() { "incomplete".into() } else { mac.to_string() }; let age = timestamp_to_age(e.update); writeln!(tw, "{}\t{}\t{}", e.ip, mac, age).unwrap(); } @@ -148,15 +145,9 @@ async fn arp_add( update: String::new(), }; if ip.is_ipv4() { - client - .arp_create(&entry) - .await - .context("failed to add IPv4 ARP entry") + client.arp_create(&entry).await.context("failed to add IPv4 ARP entry") } else { - client - .ndp_create(&entry) - .await - .context("failed to add IPv6 NDP entry") + client.ndp_create(&entry).await.context("failed to add IPv6 NDP entry") } .map(|_| ()) } diff --git a/swadm/src/attached.rs b/swadm/src/attached.rs index 5aa27fb..87d72a7 100644 --- a/swadm/src/attached.rs +++ b/swadm/src/attached.rs @@ -150,12 +150,9 @@ pub async fn attsub_cmd( match e { AttachedSubnet::List { v4, v6 } => attsub_list(client, v4, v6).await, AttachedSubnet::Get { attsub } => attsub_get(client, attsub).await, - AttachedSubnet::Add { - attsub, - internal, - inner, - vni, - } => attsub_add(client, attsub, internal, inner, vni).await, + AttachedSubnet::Add { attsub, internal, inner, vni } => { + attsub_add(client, attsub, internal, inner, vni).await + } AttachedSubnet::Del { attsub } => attsub_del(client, attsub).await, } } diff --git a/swadm/src/compliance.rs b/swadm/src/compliance.rs index 5e6628f..98b2f4c 100644 --- a/swadm/src/compliance.rs +++ b/swadm/src/compliance.rs @@ -145,14 +145,7 @@ pub async fn compliance_cmd( compliance_ports_enable(client, pattern.as_deref(), false, all) .await } - PortAction::Setup { - pattern, - speed, - fec, - autoneg, - kr, - all, - } => { + PortAction::Setup { pattern, speed, fec, autoneg, kr, all } => { compliance_ports_setup( client, pattern.as_deref(), @@ -167,11 +160,7 @@ pub async fn compliance_cmd( PortAction::Teardown { pattern, all } => { compliance_ports_teardown(client, pattern.as_deref(), all).await } - PortAction::Power { - state, - pattern, - force, - } => { + PortAction::Power { state, pattern, force } => { compliance_ports_power(client, pattern.as_deref(), state, force) .await } diff --git a/swadm/src/link.rs b/swadm/src/link.rs index f04d4d2..7ea7c45 100644 --- a/swadm/src/link.rs +++ b/swadm/src/link.rs @@ -669,9 +669,7 @@ async fn link_fec_rs_counters( .map(|r| r.into_inner()) .context("failed to get FEC counters")?; counters.sort_by(|a, b| { - a.port_id - .cmp(&b.port_id) - .then_with(|| a.link_id.cmp(&b.link_id)) + a.port_id.cmp(&b.port_id).then_with(|| a.link_id.cmp(&b.link_id)) }); counters }; @@ -820,11 +818,7 @@ fn port_rmon_counters_brief(old: &RMonCounters, new: &RMonCounters) { macro_rules! print_one { ($field:ident, $old:ident, $new:ident) => { - println!( - "{:35} {:>10}", - stringify!($field), - $new.$field - $old.$field - ) + println!("{:35} {:>10}", stringify!($field), $new.$field - $old.$field) }; } @@ -1067,9 +1061,7 @@ async fn link_serdes_eye( print_eye_fields!("eye3", eye3_data); Ok(()) } else { - Err(anyhow::anyhow!( - "link_eye_get() returned mixed NRZ and PAM4 data" - )) + Err(anyhow::anyhow!("link_eye_get() returned mixed NRZ and PAM4 data")) } } @@ -1153,13 +1145,7 @@ async fn link_serdes_tx_eq_set( post1: Option, post2: Option, ) -> anyhow::Result<()> { - let settings = types::TxEq { - pre2, - pre1, - main, - post1, - post2, - }; + let settings = types::TxEq { pre2, pre1, main, post1, post2 }; let port = link.port_id; let link = link.link_id; client @@ -1545,14 +1531,7 @@ fn display_link_history( pub async fn link_cmd(client: &Client, link: Link) -> anyhow::Result<()> { match link { - Link::Create(LinkCreate { - port_id, - speed, - lane, - fec, - autoneg, - kr, - }) => { + Link::Create(LinkCreate { port_id, speed, lane, fec, autoneg, kr }) => { let params = types::LinkCreate { lane, speed: speed.into(), @@ -1602,13 +1581,7 @@ pub async fn link_cmd(client: &Client, link: Link) -> anyhow::Result<()> { tw.flush()?; } } - Link::List { - port_id, - parseable, - fields, - sep, - list_fields, - } => { + Link::List { port_id, parseable, fields, sep, list_fields } => { if list_fields { print_link_fields(); return Ok(()); @@ -1635,21 +1608,13 @@ pub async fn link_cmd(client: &Client, link: Link) -> anyhow::Result<()> { tw.flush()?; } } - Link::Delete { - link_path: LinkPath { port_id, link_id }, - } => { + Link::Delete { link_path: LinkPath { port_id, link_id } } => { client .link_delete(&port_id, &link_id) .await .context("failed to delete link")?; } - Link::ListAll { - parseable, - fields, - sep, - list_fields, - filter, - } => { + Link::ListAll { parseable, fields, sep, list_fields, filter } => { if list_fields { print_link_fields(); return Ok(()); @@ -1896,12 +1861,7 @@ pub async fn link_cmd(client: &Client, link: Link) -> anyhow::Result<()> { .await .with_context(|| "failed to disable link")?; } - Link::History { - link, - raw, - reverse, - n, - } => { + Link::History { link, raw, reverse, n } => { let history = client .link_history_get(&link.port_id, &link.link_id) .await @@ -1937,11 +1897,7 @@ pub async fn link_cmd(client: &Client, link: Link) -> anyhow::Result<()> { } }, Link::Counters { cmd: counters } => match counters { - LinkCounters::Rmon { - link, - level, - interval, - } => { + LinkCounters::Rmon { link, level, interval } => { link_rmon_counters(client, &link, level, interval) .await .context("failed to fetch link RMON counters")?; @@ -2042,9 +1998,7 @@ pub async fn link_cmd(client: &Client, link: Link) -> anyhow::Result<()> { post2, } => { let port_id = &link.port_id; - let mut body = types::PortSettings { - links: HashMap::default(), - }; + let mut body = types::PortSettings { links: HashMap::default() }; let txeq = if pre1.is_none() && pre2.is_none() @@ -2060,13 +2014,7 @@ pub async fn link_cmd(client: &Client, link: Link) -> anyhow::Result<()> { post2: Some(x), }) } else { - Some(types::TxEq { - pre1, - pre2, - main, - post1, - post2, - }) + Some(types::TxEq { pre1, pre2, main, post1, post2 }) }; body.links.insert( String::from("0"), diff --git a/swadm/src/main.rs b/swadm/src/main.rs index a9e3b91..2a20f05 100644 --- a/swadm/src/main.rs +++ b/swadm/src/main.rs @@ -132,10 +132,7 @@ impl FromStr for LinkPath { let Ok(port_id) = types::PortId::try_from(port_id) else { anyhow::bail!("Invalid switch port: {port_id}"); }; - Ok(Self { - port_id, - link_id: link_id.parse()?, - }) + Ok(Self { port_id, link_id: link_id.parse()? }) } } @@ -211,10 +208,7 @@ async fn main_impl() -> anyhow::Result<()> { let port = opts.port.unwrap_or_else(default_port); let host = opts.host.unwrap_or_else(|| "localhost".to_string()); let log = slog::Logger::root(slog::Discard, slog::o!()); - let client_state = ClientState { - tag: String::from("cli"), - log, - }; + let client_state = ClientState { tag: String::from("cli"), log }; let client = Client::new(&format!("http://{host}:{port}"), client_state); match opts.cmd { diff --git a/swadm/src/nat.rs b/swadm/src/nat.rs index 574caee..5beec07 100644 --- a/swadm/src/nat.rs +++ b/swadm/src/nat.rs @@ -226,14 +226,9 @@ pub async fn nat_cmd(client: &Client, n: Nat) -> anyhow::Result<()> { match n { Nat::List { external } => nat_list(client, external).await, Nat::Get { external, port } => nat_get(client, external, port).await, - Nat::Add { - external, - low, - high, - internal, - inner, - vni, - } => nat_add(client, external, low, high, internal, inner, vni).await, + Nat::Add { external, low, high, internal, inner, vni } => { + nat_add(client, external, low, high, internal, inner, vni).await + } Nat::Del { external, port } => nat_del(client, external, port).await, } } diff --git a/swadm/src/route.rs b/swadm/src/route.rs index c946a5b..d9f7e34 100644 --- a/swadm/src/route.rs +++ b/swadm/src/route.rs @@ -280,16 +280,11 @@ pub async fn route_cmd(client: &Client, cmd: Route) -> anyhow::Result<()> { match cmd { Route::List { family } => route_list(client, family).await, Route::Get { cidr } => route_get(client, cidr).await, - Route::Add { - cidr, - link_path, - gw, - vlan_id, - } => route_add(client, cidr, link_path, gw, vlan_id).await, - Route::Del { - cidr, - link_path, - gw, - } => route_del(client, cidr, link_path, gw).await, + Route::Add { cidr, link_path, gw, vlan_id } => { + route_add(client, cidr, link_path, gw, vlan_id).await + } + Route::Del { cidr, link_path, gw } => { + route_del(client, cidr, link_path, gw).await + } } } diff --git a/swadm/src/switchport.rs b/swadm/src/switchport.rs index 847c753..441789e 100644 --- a/swadm/src/switchport.rs +++ b/swadm/src/switchport.rs @@ -319,9 +319,7 @@ fn stringify_optional_item(item: &Option) -> String where T: std::string::ToString, { - item.as_ref() - .map(|i| i.to_string()) - .unwrap_or_else(|| String::from("-")) + item.as_ref().map(|i| i.to_string()).unwrap_or_else(|| String::from("-")) } fn print_transceiver_header( @@ -414,11 +412,8 @@ fn print_supported_transceiver_row( } fn extract_trailing_integer(s: &str, offset: usize) -> u32 { - let s = s - .get(offset..) - .expect("parse succeeded, so this length is valid"); - s.parse() - .expect("parse succeeded, so this ends with an integer") + let s = s.get(offset..).expect("parse succeeded, so this length is valid"); + s.parse().expect("parse succeeded, so this ends with an integer") } fn order_by_trailing_integer( @@ -664,10 +659,8 @@ async fn transceivers_cmd( } } Transceiver::Datapath { port_id } => { - let datapath = client - .transceiver_datapath_get(&port_id) - .await? - .into_inner(); + let datapath = + client.transceiver_datapath_get(&port_id).await?.into_inner(); print_transceiver_datapath(port_id, datapath); } } @@ -677,18 +670,10 @@ async fn transceivers_cmd( // Print the datapath for a single transceiver in a switch port. fn print_transceiver_datapath(port_id: PortId, datapath: types::Datapath) { match datapath { - types::Datapath::Cmis { - connector, - datapaths, - .. - } => { + types::Datapath::Cmis { connector, datapaths, .. } => { print_cmis_datapath(port_id, &connector, datapaths); } - types::Datapath::Sff8636 { - connector, - lanes, - specification, - } => { + types::Datapath::Sff8636 { connector, lanes, specification } => { print_sff_datapath(port_id, &connector, lanes, specification); } } @@ -746,8 +731,7 @@ fn print_sff_datapath( // Display a value that's optional, with `-` for `None`. fn display_optional(val: Option) -> String { - val.map(|v| v.to_string()) - .unwrap_or_else(|| String::from("-")) + val.map(|v| v.to_string()).unwrap_or_else(|| String::from("-")) } // Given the lane assignment options and count in a CMIS datapath, return @@ -784,34 +768,24 @@ fn print_cmis_datapath( type GetFn = fn(&CmisLaneStatus) -> String; const GETTERS: [(&str, GetFn); 15] = [ ("State", |st| st.state.to_string()), - ("Rx Output Enabled", |st| { - display_optional(st.rx_output_enabled) - }), + ("Rx Output Enabled", |st| display_optional(st.rx_output_enabled)), ("Rx Output Status", |st| st.rx_output_status.to_string()), ("Rx Loss-of-lock", |st| display_optional(st.rx_lol)), ("Rx Loss-of-signal", |st| display_optional(st.rx_los)), ("Rx Auto-squelch Disable", |st| { display_optional(st.rx_auto_squelch_disable) }), - ("Tx Output Enabled", |st| { - display_optional(st.tx_output_enabled) - }), + ("Tx Output Enabled", |st| display_optional(st.tx_output_enabled)), ("Tx Output Status", |st| st.tx_output_status.to_string()), ("Tx Loss-of-lock", |st| display_optional(st.tx_lol)), ("Tx Loss-of-signal", |st| display_optional(st.tx_los)), ("Tx Auto-squelch Disable", |st| { display_optional(st.tx_auto_squelch_disable) }), - ("Tx Adaptive EQ Fail", |st| { - display_optional(st.tx_adaptive_eq_fail) - }), + ("Tx Adaptive EQ Fail", |st| display_optional(st.tx_adaptive_eq_fail)), ("Tx Failure", |st| display_optional(st.tx_failure)), - ("Tx Force Squelch", |st| { - display_optional(st.tx_force_squelch) - }), - ("Tx Input Polarity", |st| { - display_optional(st.tx_input_polarity) - }), + ("Tx Force Squelch", |st| display_optional(st.tx_force_squelch)), + ("Tx Input Polarity", |st| display_optional(st.tx_input_polarity)), ]; // The datapaths are keyed by index, which is actually an integer. The @@ -824,13 +798,7 @@ fn print_cmis_datapath( (index, dp) }) .collect(); - for ( - i, - CmisDatapath { - application, - lane_status, - }, - ) in datapaths.into_iter() + for (i, CmisDatapath { application, lane_status }) in datapaths.into_iter() { // Print general information about the datapath and the lanes it uses. println!(); @@ -866,11 +834,8 @@ fn print_cmis_datapath( // Print each piece of state as a row. for (name, getter) in GETTERS.iter() { - let cols = lane_status - .values() - .map(getter) - .collect::>() - .join("\t"); + let cols = + lane_status.values().map(getter).collect::>().join("\t"); writeln!(tw, "{name:>WIDTH$}: {cols}").unwrap(); } tw.flush().unwrap(); @@ -882,10 +847,7 @@ fn print_cmis_datapath( fn display_list( items: impl Iterator, ) -> String { - items - .map(|i| format!("{i:0.4}")) - .collect::>() - .join(",") + items.map(|i| format!("{i:0.4}")).collect::>().join(",") } async fn led_cmd(client: &Client, led: Led) -> anyhow::Result<()> { @@ -993,11 +955,7 @@ pub async fn switch_cmd( client.management_mode_set(&port_id, mode).await?; } SwitchPort::Led { cmd: led } => led_cmd(client, led).await?, - SwitchPort::BackplaneMap { - parseable, - fields, - list_fields, - } => { + SwitchPort::BackplaneMap { parseable, fields, list_fields } => { if list_fields { print_backplane_map_fields(); return Ok(()); diff --git a/swadm/src/table.rs b/swadm/src/table.rs index d4be99c..85755f3 100644 --- a/swadm/src/table.rs +++ b/swadm/src/table.rs @@ -121,11 +121,8 @@ async fn table_dump( continue; } - let keys: Vec = schema - .keys - .iter() - .map(|key| entry.keys[key].clone()) - .collect(); + let keys: Vec = + schema.keys.iter().map(|key| entry.keys[key].clone()).collect(); if parseable { let mut output = keys; @@ -164,10 +161,7 @@ async fn table_counters( force_sync: bool, parseable: bool, ) -> anyhow::Result<()> { - let ctrs = client - .table_counters(&table, force_sync) - .await? - .into_inner(); + let ctrs = client.table_counters(&table, force_sync).await?.into_inner(); if ctrs.is_empty() { return Ok(()); } @@ -241,16 +235,11 @@ pub async fn table_cmd( } Ok(()) } - Table::Dump { - schema, - parseable, - action, - name, - } => table_dump(client, name, schema, parseable, action).await, - Table::Counters { - force_sync, - parseable, - name, - } => table_counters(client, name, force_sync, parseable).await, + Table::Dump { schema, parseable, action, name } => { + table_dump(client, name, schema, parseable, action).await + } + Table::Counters { force_sync, parseable, name } => { + table_counters(client, name, force_sync, parseable).await + } } } diff --git a/swadm/tests/counters.rs b/swadm/tests/counters.rs index 50d7739..e1470f4 100644 --- a/swadm/tests/counters.rs +++ b/swadm/tests/counters.rs @@ -35,10 +35,7 @@ fn test_p4_counter_list() { let stdout = String::from_utf8_lossy(&output.stdout); // Verify output is not empty and contains expected counter information - assert!( - !stdout.is_empty(), - "Counter list output should not be empty" - ); + assert!(!stdout.is_empty(), "Counter list output should not be empty"); // Expected P4 counters from dpd/src/counters.rs COUNTERS array let expected_counters = [ diff --git a/swadm/tests/port-link.rs b/swadm/tests/port-link.rs index 7b1d958..5bb4be6 100644 --- a/swadm/tests/port-link.rs +++ b/swadm/tests/port-link.rs @@ -112,14 +112,8 @@ fn set_port_prop(name: &str, value: &str) { #[ignore] fn test_mac() { let test = SetTest { - port: PropertyValue { - name: "mac", - value: "a8:40:25:ff:ff:01", - }, - link: PropertyValue { - name: "mac", - value: "a8:40:25:ff:ff:02", - }, + port: PropertyValue { name: "mac", value: "a8:40:25:ff:ff:01" }, + link: PropertyValue { name: "mac", value: "a8:40:25:ff:ff:02" }, }; test.run(); } @@ -128,14 +122,8 @@ fn test_mac() { #[ignore] fn test_an() { let test = SetTest { - port: PropertyValue { - name: "an", - value: "true", - }, - link: PropertyValue { - name: "an", - value: "false", - }, + port: PropertyValue { name: "an", value: "true" }, + link: PropertyValue { name: "an", value: "false" }, }; test.run(); } @@ -144,14 +132,8 @@ fn test_an() { #[ignore] fn test_kr() { let test = SetTest { - port: PropertyValue { - name: "kr", - value: "true", - }, - link: PropertyValue { - name: "kr", - value: "false", - }, + port: PropertyValue { name: "kr", value: "true" }, + link: PropertyValue { name: "kr", value: "false" }, }; test.run(); } @@ -160,14 +142,8 @@ fn test_kr() { #[ignore] fn test_enable() { let test = SetTest { - port: PropertyValue { - name: "ena", - value: "true", - }, - link: PropertyValue { - name: "ena", - value: "false", - }, + port: PropertyValue { name: "ena", value: "true" }, + link: PropertyValue { name: "ena", value: "false" }, }; test.run(); } @@ -187,13 +163,7 @@ fn test_ip_addresses() { // Check that both schemes have the same addresses. let port_addrs = String::from_utf8( - swadm() - .arg("addr") - .arg("list") - .arg(PORT) - .output() - .unwrap() - .stdout, + swadm().arg("addr").arg("list").arg(PORT).output().unwrap().stdout, ) .unwrap(); let link_addrs = String::from_utf8( @@ -221,13 +191,7 @@ fn test_ip_addresses() { .unwrap(); } let port_addrs: Vec = String::from_utf8( - swadm() - .arg("addr") - .arg("list") - .arg(PORT) - .output() - .unwrap() - .stdout, + swadm().arg("addr").arg("list").arg(PORT).output().unwrap().stdout, ) .unwrap() .lines() @@ -263,13 +227,7 @@ fn test_ip_addresses() { .unwrap(); } let port_addrs: Vec = String::from_utf8( - swadm() - .arg("addr") - .arg("list") - .arg(PORT) - .output() - .unwrap() - .stdout, + swadm().arg("addr").arg("list").arg(PORT).output().unwrap().stdout, ) .unwrap() .lines() diff --git a/tfportd/build.rs b/tfportd/build.rs index d696633..618099b 100644 --- a/tfportd/build.rs +++ b/tfportd/build.rs @@ -9,7 +9,5 @@ extern crate cc; fn main() { println!("cargo:rustc-link-lib=socket"); - cc::Build::new() - .file("src/netsupport.c") - .compile("netsupport"); + cc::Build::new().file("src/netsupport.c").compile("netsupport"); } diff --git a/tfportd/src/arp.rs b/tfportd/src/arp.rs index 2969267..18fef60 100644 --- a/tfportd/src/arp.rs +++ b/tfportd/src/arp.rs @@ -126,26 +126,15 @@ fn parse_arp(line: &str) -> anyhow::Result { let ip = fields[1] .parse() .map_err(|_| anyhow!("bad IP address: {}:", fields[1]))?; - let mask = fields[2] - .parse() - .map_err(|_| anyhow!("bad mask: {}:", fields[2]))?; + let mask = + fields[2].parse().map_err(|_| anyhow!("bad mask: {}:", fields[2]))?; let mac = match fields[last].parse() { Ok(m) => m, _ => MacAddr::new(0, 0, 0, 0, 0, 0), }; - let flags = if last > 3 { - fields[last].to_string() - } else { - String::new() - }; + let flags = if last > 3 { fields[last].to_string() } else { String::new() }; - Ok(Arp { - iface, - ip, - _mask: mask, - _flags: flags, - mac, - }) + Ok(Arp { iface, ip, _mask: mask, _flags: flags, mac }) } // arp doesn't have a "parseable" output option, so we have to do it by hand. We diff --git a/tfportd/src/config.rs b/tfportd/src/config.rs index cefe4d6..a34e8e5 100644 --- a/tfportd/src/config.rs +++ b/tfportd/src/config.rs @@ -145,10 +145,7 @@ pub(crate) fn update_from_smf(config: &mut Config) -> SmfResult<()> { if config.listen_addresses.is_empty() { eprintln!("No IPv6 addresses found in provided listen_addresses"); - } else if config - .listen_addresses - .iter() - .all(|addr| addr.ip().is_loopback()) + } else if config.listen_addresses.iter().all(|addr| addr.ip().is_loopback()) { eprintln!("No non-localhost IPv6 addresses found in SMF properties"); } diff --git a/tfportd/src/main.rs b/tfportd/src/main.rs index 17f2239..29237b6 100644 --- a/tfportd/src/main.rs +++ b/tfportd/src/main.rs @@ -291,11 +291,7 @@ async fn main_impl() -> anyhow::Result<()> { client_state, ); - info!( - log, - "connected to dpd running {}", - dpd_version(&log, &client).await - ); + info!(log, "connected to dpd running {}", dpd_version(&log, &client).await); // If the reset fails, we'll just log the error and continue, as we will // try to clean-up the any stale settings during the normal reconciliation diff --git a/tfportd/src/ndp.rs b/tfportd/src/ndp.rs index a4325ab..9b61d14 100644 --- a/tfportd/src/ndp.rs +++ b/tfportd/src/ndp.rs @@ -167,22 +167,15 @@ fn parse_ndp(line: &str) -> anyhow::Result { } let iface = fields[0].to_string(); - let mac = fields[1] - .parse() - .map_err(|_| anyhow!("bad mac: {}:", fields[1]))?; + let mac = + fields[1].parse().map_err(|_| anyhow!("bad mac: {}:", fields[1]))?; let ntype = fields[2].parse().map_err(|e: String| anyhow!(e))?; let state = fields[3].parse().map_err(|e: String| anyhow!(e))?; let ip = fields[4] .parse() .map_err(|_| anyhow!("bad IP address: {}:", fields[1]))?; - Ok(Ndp { - iface, - mac, - ip, - _ntype: ntype, - _state: state, - }) + Ok(Ndp { iface, mac, ip, _ntype: ntype, _state: state }) } // ndp doesn't have a "parseable" output option, so we have to do it by hand. We diff --git a/tfportd/src/oxstats.rs b/tfportd/src/oxstats.rs index ce69ed9..fc43117 100644 --- a/tfportd/src/oxstats.rs +++ b/tfportd/src/oxstats.rs @@ -73,13 +73,7 @@ impl LinkTracker { /// The Receiver will be notified whenever links are added or removed. pub fn new() -> (Self, watch::Receiver<()>) { let (tx, rx) = watch::channel(()); - ( - Self { - tracked_links: RwLock::new(HashSet::new()), - tx, - }, - rx, - ) + (Self { tracked_links: RwLock::new(HashSet::new()), tx }, rx) } /// Track a new link by name and model type, which updates [LinkTracker] @@ -89,10 +83,8 @@ impl LinkTracker { name: impl Into, model_type: ModelType, ) -> anyhow::Result<()> { - let mut links = self - .tracked_links - .write() - .unwrap_or_else(|e| e.into_inner()); + let mut links = + self.tracked_links.write().unwrap_or_else(|e| e.into_inner()); if links.insert((name.into(), model_type)) { // Only notify if change occurred let _ = self.tx.send(()); @@ -107,10 +99,8 @@ impl LinkTracker { name: impl Into, ) -> anyhow::Result<()> { let name = name.into(); - let mut links = self - .tracked_links - .write() - .unwrap_or_else(|e| e.into_inner()); + let mut links = + self.tracked_links.write().unwrap_or_else(|e| e.into_inner()); let len_before = links.len(); links.retain(|(link_name, _)| link_name != &name); @@ -338,9 +328,7 @@ fn start_producer_server( // Listen on any available socket, using our underlay address. let address = SocketAddr::new(listen_address.into(), 0); let registry = ProducerRegistry::with_id(producer_id); - registry - .register_producer(sampler) - .expect("actually infallible"); + registry.register_producer(sampler).expect("actually infallible"); let config = oximeter_producer::Config { server_info: ProducerEndpoint { @@ -383,11 +371,7 @@ async fn get_oximeter_config( e })?; - Ok(OximeterConfig { - listen_address, - sled_identifiers, - switch_identifiers, - }) + Ok(OximeterConfig { listen_address, sled_identifiers, switch_identifiers }) } /// Extract the underlay IPv6 listening address we're provided in our SMF @@ -410,15 +394,12 @@ async fn fetch_underlay_listen_address( // Find any non-localhost IPv6 address. That should be reachable by // Oximeter, since it's on the underlay. - let maybe_listen_addr = g - .config - .lock() - .unwrap() - .listen_addresses - .iter() - .find_map(|addr| match *addr.ip() { - v6 if v6.is_loopback() => None, - v6 => Some(v6), + let maybe_listen_addr = + g.config.lock().unwrap().listen_addresses.iter().find_map(|addr| { + match *addr.ip() { + v6 if v6.is_loopback() => None, + v6 => Some(v6), + } }); if let Some(listen_address) = maybe_listen_addr { info!( diff --git a/tfportd/src/packet_queue.rs b/tfportd/src/packet_queue.rs index f1bfa63..ac8f7fc 100644 --- a/tfportd/src/packet_queue.rs +++ b/tfportd/src/packet_queue.rs @@ -49,12 +49,7 @@ pub struct PacketQueue { impl PacketQueue { /// Create a new, empty packet queue pub fn new(name: impl ToString, max: usize) -> Self { - PacketQueue { - name: name.to_string(), - max, - cnt: 0, - queue: Vec::new(), - } + PacketQueue { name: name.to_string(), max, cnt: 0, queue: Vec::new() } } /// Pull all of the packets from the queue that were waiting on the given IP @@ -80,10 +75,7 @@ impl PacketQueue { "iface" => &self.name, "idx" => qp.idx); - pkts.push(Packet { - hdrs: qp.hdrs, - body: qp.body, - }); + pkts.push(Packet { hdrs: qp.hdrs, body: qp.body }); } } pkts diff --git a/tfportd/src/ports.rs b/tfportd/src/ports.rs index 9f202c3..08e852e 100644 --- a/tfportd/src/ports.rs +++ b/tfportd/src/ports.rs @@ -124,9 +124,8 @@ async fn dpd_port_update(g: &Global, links: &mut LinkMap) -> Result<()> { for entry in dpd_data { let expected_tfport = tfport_name(&entry); let _ = current_links.remove(&expected_tfport); - let link = links - .entry(expected_tfport.clone()) - .or_insert((&entry).into()); + let link = + links.entry(expected_tfport.clone()).or_insert((&entry).into()); let entry_mac = entry.mac.into(); link.dpd_link_local = entry.link_local; @@ -253,10 +252,7 @@ async fn ensure_address_match(g: &Global, link: &LinkInfo) -> Result<()> { .link_ipv6_create( &link.port_id, &link.link_id, - &types::Ipv6Entry { - tag: g.client.inner().tag.clone(), - addr, - }, + &types::Ipv6Entry { tag: g.client.inner().tag.clone(), addr }, ) .await .context("sending new link-local address")?; diff --git a/tfportd/src/simport.rs b/tfportd/src/simport.rs index 31eb207..91c88f6 100644 --- a/tfportd/src/simport.rs +++ b/tfportd/src/simport.rs @@ -24,10 +24,7 @@ async fn simnet_tfport_get() -> anyhow::Result> { .await .map_err(|e| e.into()) .map(|lines| { - lines - .into_iter() - .filter(|s| s.starts_with("tfport")) - .collect() + lines.into_iter().filter(|s| s.starts_with("tfport")).collect() }) } @@ -80,16 +77,13 @@ async fn simnet_process(g: &Global) -> anyhow::Result<()> { warn!(g.log, "{e}"); continue; } - let p_addrs = addrs - .iter() - .filter_map(|(name, addr)| { - if name.starts_with(p) { - Some(*addr) - } else { - None - } - }) - .collect::>(); + let p_addrs = + addrs + .iter() + .filter_map(|(name, addr)| { + if name.starts_with(p) { Some(*addr) } else { None } + }) + .collect::>(); if p_addrs.is_empty() { warn!(g.log, "{p} has no addrs"); diff --git a/tfportd/src/techport.rs b/tfportd/src/techport.rs index 78f176a..b61b471 100644 --- a/tfportd/src/techport.rs +++ b/tfportd/src/techport.rs @@ -148,10 +148,7 @@ pub async fn sync_dhcp6_addr(g: &Arc, addr: Ipv6Addr) { dpd_client::types::Internal::from_str("int0").unwrap(), ); let link = &types::LinkId(0); - let entry = types::Ipv6Entry { - tag: g.client.inner().tag.clone(), - addr, - }; + let entry = types::Ipv6Entry { tag: g.client.inner().tag.clone(), addr }; if let Err(e) = g.client.link_ipv6_create(&port, link, &entry).await { if e.status() != Some(http::StatusCode::CONFLICT) { warn!( @@ -179,10 +176,7 @@ async fn address_ensure_dpd(g: &Arc, pfx0: Ipv6Addr, pfx1: Ipv6Addr) { // Use the tfportd tag for making dpd entries. let tag = g.client.inner().tag.clone(); - let addr = types::Ipv6Entry { - tag: tag.clone(), - addr: addr0, - }; + let addr = types::Ipv6Entry { tag: tag.clone(), addr: addr0 }; if let Err(e) = g.client.link_ipv6_create(&port, link, &addr).await { if e.status() != Some(http::StatusCode::CONFLICT) { warn!(g.log, "failed to set up dpd techport address: {e}"); @@ -193,10 +187,7 @@ async fn address_ensure_dpd(g: &Arc, pfx0: Ipv6Addr, pfx1: Ipv6Addr) { info!(g.log, "dpd techport0 addressing setup complete"); } - let addr = types::Ipv6Entry { - tag: tag.clone(), - addr: addr1, - }; + let addr = types::Ipv6Entry { tag: tag.clone(), addr: addr1 }; if let Err(e) = g.client.link_ipv6_create(&port, link, &addr).await { if e.status() != Some(http::StatusCode::CONFLICT) { warn!(g.log, "failed to set up dpd techport address: {e}"); diff --git a/tfportd/src/tfport.rs b/tfportd/src/tfport.rs index 2285707..590e7b8 100644 --- a/tfportd/src/tfport.rs +++ b/tfportd/src/tfport.rs @@ -62,21 +62,11 @@ fn parse_tfport_line(line: &str) -> Result { // separator, so the `:` separating the MAC address octets are escaped. // Remove the escaping before parsing, and then return whether the data // matches exactly or not. - let mac = maybe_mac - .trim() - .replace('\\', "") - .parse::() - .map_err(|_| { - anyhow!("unable to parse {maybe_mac} as a mac address for {name}") - })?; - - Ok(TfportInfo { - name, - port, - mac, - ifindex: None, - link_local: None, - }) + let mac = maybe_mac.trim().replace('\\', "").parse::().map_err( + |_| anyhow!("unable to parse {maybe_mac} as a mac address for {name}"), + )?; + + Ok(TfportInfo { name, port, mac, ifindex: None, link_local: None }) } async fn lldp_toggle_disabled( @@ -273,17 +263,13 @@ pub async fn tfport_cleanup(g: &Global) { /// If tfport0 doesn't already exist, create it. pub async fn create_tfport0(g: &Global) { // Once the tfport0 is created or re-created, we can then start tracking it. - if let Err(e) = g - .link_tracker - .track_link("tfport0", link::ModelType::Tfport) + if let Err(e) = + g.link_tracker.track_link("tfport0", link::ModelType::Tfport) { error!(g.log, "failed to track tfport0: {e}"); } - match illumos::tfport_exists("tfport0") - .await - .expect("dladm failed") - { + match illumos::tfport_exists("tfport0").await.expect("dladm failed") { true => { info!( g.log, diff --git a/tfportd/src/vlans.rs b/tfportd/src/vlans.rs index 4038e10..5eddc6c 100644 --- a/tfportd/src/vlans.rs +++ b/tfportd/src/vlans.rs @@ -68,14 +68,7 @@ async fn vlans_get(tfport: &str) -> anyhow::Result> { let vid = fields[1].parse::().context("invalid vlan_id")?; let ifindex = crate::netsupport::get_ifindex(&link); let link_local = link_locals.get(&link).copied(); - rval.insert( - link, - VlanInfo { - vid, - ifindex, - link_local, - }, - ); + rval.insert(link, VlanInfo { vid, ifindex, link_local }); } Ok(rval) } @@ -152,11 +145,7 @@ pub async fn ensure_vlans(g: &Global, link: &str) -> anyhow::Result<()> { info!(g.log, "created vlan {vid}:{name} on {link}"); existing_vlans.insert( name.to_string(), - VlanInfo { - vid, - ifindex: None, - link_local: None, - }, + VlanInfo { vid, ifindex: None, link_local: None }, ); // Once the vlan is created, we can track it as a potential @@ -226,10 +215,7 @@ pub fn init(csv_file: &str) -> anyhow::Result> { for entry in rdr.deserialize() { let e: PortMapEntry = entry?; - vlans.push(Vlan { - vid: e.port + 0x100, - name: e.vlan_name, - }); + vlans.push(Vlan { vid: e.port + 0x100, name: e.vlan_name }); } Ok(vlans) } diff --git a/uplinkd/src/main.rs b/uplinkd/src/main.rs index ef918f0..0a49044 100644 --- a/uplinkd/src/main.rs +++ b/uplinkd/src/main.rs @@ -133,9 +133,8 @@ fn refresh_smf_config(g: &mut Global) -> Result<()> { // Create an SMF context and take a snapshot of the current settings let scf = smf::Scf::new().context("creating scf handle")?; let instance = scf.get_self_instance().context("getting smf instance")?; - let snapshot = instance - .get_running_snapshot() - .context("getting running snapshot")?; + let snapshot = + instance.get_running_snapshot().context("getting running snapshot")?; // All the properties relevant to us fall under the "uplinks" property group let pg = match snapshot @@ -320,9 +319,7 @@ async fn create_v4_ptp_link_ipadm( ]) .await?; - Ok(format!( - "created {local} as PtP link to {remote} as {addrobj}" - )) + Ok(format!("created {local} as PtP link to {remote} as {addrobj}")) } // Create an IPv4 PtP link using ifconfig @@ -366,10 +363,7 @@ async fn create_addrobj( tag: &str, addr: &IpNet, ) -> Result<()> { - debug!( - log, - "create_addrobj addr: {addr} iface: {iface} tag: {tag}" - ); + debug!(log, "create_addrobj addr: {addr} iface: {iface} tag: {tag}"); // ipadm can't create point-to-point links, so we need to special-case them match addr { IpNet::V4(v4cidr) if v4cidr.width() == 31 => match ipadm_works { @@ -435,11 +429,8 @@ async fn reconcile_interfaces(g: &mut Global) { // Delete any addresses we created on these abandoned interfaces. for iface in unmanaged { debug!(g.log, "cleaning up addresses on unmanaged {iface}"); - for addrobj in g - .current - .get(&iface) - .expect("existence guaranteed above") - .keys() + for addrobj in + g.current.get(&iface).expect("existence guaranteed above").keys() { let _ = delete_addrobj(&g.log, addrobj).await; } diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs index 3416b6e..5aa1979 100644 --- a/xtask/src/codegen.rs +++ b/xtask/src/codegen.rs @@ -116,10 +116,7 @@ impl P4Config { agent0: "lib/libpltfm_mgr.so".to_string(), }; - P4Config { - chip_list: vec![chip], - p4_devices: vec![device], - } + P4Config { chip_list: vec![chip], p4_devices: vec![device] } } } diff --git a/xtask/src/illumos.rs b/xtask/src/illumos.rs index ae912d3..5c89228 100644 --- a/xtask/src/illumos.rs +++ b/xtask/src/illumos.rs @@ -97,11 +97,7 @@ fn collect_sde(dst: &str, p4_root: &str) -> Result<()> { let xml_path = "share/cli/xml"; let xml_src = format!("{src}/{xml_path}"); let xml_dst = format!("{p4_root}/{xml_path}"); - collect( - &xml_src, - &xml_dst, - vec!["pipemgr.xml", "startup.xml", "types.xml"], - ) + collect(&xml_src, &xml_dst, vec!["pipemgr.xml", "startup.xml", "types.xml"]) } fn illumos_package() -> Result<()> { @@ -161,9 +157,7 @@ fn illumos_package() -> Result<()> { // populate the repo let status = Command::new("/usr/bin/pkgsend") - .args(vec![ - "publish", "-d", proto_root, "-s", &repo_dir, &manifest, - ]) + .args(vec!["publish", "-d", proto_root, "-s", &repo_dir, &manifest]) .status()?; if !status.success() { return Err(anyhow!("repo population failed")); @@ -191,8 +185,7 @@ fn generate_manifest(features: &str) -> Result { let mut file = fs::File::open(manifest_path) .with_context(|| "attempting to open omicron manifest")?; let mut data = String::new(); - file.read_to_string(&mut data) - .with_context(|| "reading manifest")?; + file.read_to_string(&mut data).with_context(|| "reading manifest")?; Ok(data) } @@ -211,9 +204,8 @@ async fn omicron_package(features: Option) -> Result<()> { let build_config = BuildConfig::default(); for package in cfg.packages.values() { - if let Err(e) = package - .create(&PACKAGE_NAME, output_dir, &build_config) - .await + if let Err(e) = + package.create(&PACKAGE_NAME, output_dir, &build_config).await { eprintln!("omicron packaging failed: {e:?}"); return Err(e); diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 95d1f9f..c3d45f9 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -221,11 +221,8 @@ fn collect_binaries( false => "./target/debug", }; - let mut binaries = vec![ - "tfportd".to_string(), - "swadm".to_string(), - "uplinkd".to_string(), - ]; + let mut binaries = + vec!["tfportd".to_string(), "swadm".to_string(), "uplinkd".to_string()]; for name in names { if name.to_string() == "sidecar" { binaries.push("dpd".to_string()); @@ -253,12 +250,9 @@ async fn main() { XtaskCommands::Codegen { name, sde, stages } => { codegen::build(name, sde, stages) } - XtaskCommands::Dist { - features, - names, - release, - format, - } => plat::dist(features, names, release, format).await, + XtaskCommands::Dist { features, names, release, format } => { + plat::dist(features, names, release, format).await + } } { eprintln!("failed: {e}"); std::process::exit(-1);