Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions dpd/src/switch_port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<PortFec>,
/// FEC. For stability, the on-disk format is parsed with the v1
/// `PortFec` representation.
pub fec: Option<v1::port::PortFec>,
/// Precursor 2
pub pre2: Option<i32>,
/// Precursor 1
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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);
}
}
Loading