From c37054495083b28d6cf1a9b93fbd96625a71f16d Mon Sep 17 00:00:00 2001 From: Trey Aspelund Date: Tue, 10 Nov 2026 15:21:54 -0500 Subject: [PATCH] dpd: parse xcvr_defaults.rs without snake_case Use the older version of the PortFec type when parsing xcvr_defaults.csv then convert to the newer type. This allows us to parse old versions of the file without needing any producers of the file to update them. Signed-off-by: Trey Aspelund --- dpd/src/switch_port.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/dpd/src/switch_port.rs b/dpd/src/switch_port.rs index 9ba24091..d8604e0e 100644 --- a/dpd/src/switch_port.rs +++ b/dpd/src/switch_port.rs @@ -31,6 +31,7 @@ use common::ports::QsfpPort; use common::ports::RearPort; use common::ports::TxEq; use common::ports::XcvrSettings; +use dpd_types_versions::v1; use std::collections::BTreeMap; /// Return the backplane link information, if this is a rear port. @@ -54,8 +55,9 @@ pub fn module_id_from_qsfp(p: QsfpPort) -> transceiver_controller::ModuleId { struct XcvrDefaultsEntry { /// Manufacturer part number - unique identifer for a transceiver pub mpn: String, - /// FEC - pub fec: Option, + /// FEC. For stability, the on-disk format is parsed with the v1 + /// `PortFec` representation. + pub fec: Option, /// Precursor 2 pub pre2: Option, /// Precursor 1 @@ -99,7 +101,8 @@ pub fn load_xcvr_defaults( } else { None }; - settings.insert(e.mpn, XcvrSettings { tx_eq, fec: e.fec }); + settings + .insert(e.mpn, XcvrSettings { tx_eq, fec: e.fec.map(Into::into) }); } Ok(settings) } @@ -525,3 +528,21 @@ impl crate::Switch { Err(DpdError::NoTransceiverController) } } + +#[cfg(test)] +mod tests { + use super::load_xcvr_defaults; + use common::ports::PortFec; + + // The shipped defaults file must keep parsing even as the API's + // `PortFec` serialization changes. + #[test] + fn shipped_xcvr_defaults_parse() { + let path = + concat!(env!("CARGO_MANIFEST_DIR"), "/misc/xcvr_defaults.csv"); + let settings = load_xcvr_defaults(path).unwrap(); + assert_eq!(settings["OXIDESOFTNPU"].fec, Some(PortFec::RS)); + assert_eq!(settings["CAB-Q-Q-5M"].fec, Some(PortFec::None)); + assert_eq!(settings["FTLC9558REPM"].fec, None); + } +}