use crate::{statement_words, value_after};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct IsisGracefulRestart {
pub disable: bool,
pub helper_disable: bool,
pub restart_duration: Option<String>,
}
pub(super) fn parse_graceful_restart(isis: &ConfigLine) -> Option<IsisGracefulRestart> {
let words = statement_words(isis, "graceful-restart")?;
Some(IsisGracefulRestart {
disable: words.contains(&"disable"),
helper_disable: words.contains(&"helper-disable"),
restart_duration: value_after(&words, "restart-duration"),
})
}
#[cfg(test)]
mod tests {
use crate::protocols::isis::isis;
use asterust::config::juniper;
const CONFIG: &str = r#"
protocols {
isis {
graceful-restart {
helper-disable;
restart-duration 60;
}
}
}
"#;
#[test]
fn reads_the_helper_and_duration() {
let restart = isis(&juniper::parse_braces(CONFIG)).unwrap().graceful_restart.unwrap();
assert!(restart.helper_disable);
assert_eq!(restart.restart_duration.as_deref(), Some("60"));
assert!(!restart.disable);
}
#[test]
fn reads_disable() {
let config = juniper::parse_braces(
"protocols {\n isis {\n graceful-restart {\n disable;\n }\n }\n}\n",
);
let restart = isis(&config).unwrap().graceful_restart.unwrap();
assert!(restart.disable);
assert!(!restart.helper_disable);
}
}