|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +// Copyright Open Network Fabric Authors |
| 3 | + |
| 4 | +use crate::frr::renderer::builder::{ConfigBuilder, MARKER, Render}; |
| 5 | + |
| 6 | +use crate::models::internal::routing::ospf::Ospf; |
| 7 | +use crate::models::internal::routing::ospf::OspfInterface; |
| 8 | +use crate::models::internal::routing::ospf::OspfNetwork; |
| 9 | + |
| 10 | +use std::fmt::Display; |
| 11 | + |
| 12 | +impl Display for OspfNetwork { |
| 13 | + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 14 | + match self { |
| 15 | + OspfNetwork::Broadcast => write!(f, "broadcast"), |
| 16 | + OspfNetwork::NonBroadcast => write!(f, "non-broadcast"), |
| 17 | + OspfNetwork::Point2Point => write!(f, "point-to-point"), |
| 18 | + OspfNetwork::Point2Multipoint => write!(f, "point-to-multipoint"), |
| 19 | + } |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +impl Render for Ospf { |
| 24 | + type Context = (); |
| 25 | + type Output = ConfigBuilder; |
| 26 | + fn render(&self, _: &Self::Context) -> ConfigBuilder { |
| 27 | + let mut config = ConfigBuilder::new(); |
| 28 | + let mut heading = "router ospf".to_string(); |
| 29 | + if let Some(vrf) = &self.vrf { |
| 30 | + heading += format!(" vrf {vrf}").as_str(); |
| 31 | + } |
| 32 | + config += heading; |
| 33 | + config += format!(" ospf router-id {}", self.router_id); |
| 34 | + |
| 35 | + config += MARKER; |
| 36 | + config |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +impl Render for OspfInterface { |
| 41 | + type Context = (); |
| 42 | + type Output = ConfigBuilder; |
| 43 | + fn render(&self, _: &Self::Context) -> ConfigBuilder { |
| 44 | + let mut config = ConfigBuilder::new(); |
| 45 | + config += format!(" ip ospf area {}", self.area); |
| 46 | + if let Some(network) = &self.network { |
| 47 | + config += format!(" ip ospf network {}", network); |
| 48 | + } |
| 49 | + if let Some(cost) = &self.cost { |
| 50 | + config += format!(" ip ospf cost {cost}"); |
| 51 | + } |
| 52 | + if self.passive { |
| 53 | + config += " ip ospf passive".to_string(); |
| 54 | + } |
| 55 | + config |
| 56 | + } |
| 57 | +} |
0 commit comments