Add generic FRR types that contain openfabric and ospf variants. Also add the FrrConfig, which holds the whole FRR configuration in a single struct, which will then be serialized.
Signed-off-by: Gabriel Goller <g.gol...@proxmox.com> --- proxmox-frr/src/lib.rs | 79 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/proxmox-frr/src/lib.rs b/proxmox-frr/src/lib.rs index 1a657c087ff0..08abdd371653 100644 --- a/proxmox-frr/src/lib.rs +++ b/proxmox-frr/src/lib.rs @@ -16,6 +16,46 @@ pub enum RouterNameError { FrrWordError(#[from] FrrWordError), } +/// Generic FRR router. +/// +/// This generic FRR router contains all the variants that are allowed. +#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize, Serialize, PartialOrd, Ord)] +pub enum Router { + OpenFabric(openfabric::OpenFabricRouter), + Ospf(ospf::OspfRouter), +} + +impl From<openfabric::OpenFabricRouter> for Router { + fn from(value: openfabric::OpenFabricRouter) -> Self { + Router::OpenFabric(value) + } +} + +/// Generic FRR routername. +/// +/// Can vary between different router-types. Some have `router <protocol> <name>`, others have +/// `router <protocol> <process-id>`. +#[derive(Clone, Debug, PartialEq, Eq, Hash, SerializeDisplay, PartialOrd, Ord)] +pub enum RouterName { + OpenFabric(openfabric::OpenFabricRouterName), + Ospf(ospf::OspfRouterName), +} + +impl From<openfabric::OpenFabricRouterName> for RouterName { + fn from(value: openfabric::OpenFabricRouterName) -> Self { + Self::OpenFabric(value) + } +} + +impl Display for RouterName { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::OpenFabric(r) => r.fmt(f), + Self::Ospf(r) => r.fmt(f), + } + } +} + /// The interface name is the same on ospf and openfabric, but it is an enum so we can have two /// different entries in the hashmap. This allows us to have an interface in an ospf and openfabric /// fabric. @@ -135,3 +175,42 @@ impl Display for CommonInterfaceName { self.0.fmt(f) } } + +/// Main FRR config. +/// +/// Contains the two main frr building blocks: routers and interfaces. To ease construction use the +/// [`FrrConfigBuilder`], which converts the intermediate representation to the FRR-specific +/// representation here. Eventually we can add different control options here, such as: `line vty`. +#[derive(Clone, Debug, PartialEq, Eq, Default)] +pub struct FrrConfig { + pub router: BTreeMap<RouterName, Router>, + pub interfaces: BTreeMap<InterfaceName, Interface>, + pub access_lists: BTreeMap<AccessListName, AccessList>, + pub routemaps: Vec<RouteMap>, + pub protocol_routemaps: Vec<ProtocolRouteMap>, +} + +impl FrrConfig { + pub fn new() -> Self { + Self::default() + } + + pub fn router(&self) -> impl Iterator<Item = (&RouterName, &Router)> + '_ { + self.router.iter() + } + + pub fn interfaces(&self) -> impl Iterator<Item = (&InterfaceName, &Interface)> + '_ { + self.interfaces.iter() + } + + pub fn access_lists(&self) -> impl Iterator<Item = (&AccessListName, &AccessList)> + '_ { + self.access_lists.iter() + } + pub fn routemaps(&self) -> impl Iterator<Item = &RouteMap> + '_ { + self.routemaps.iter() + } + + pub fn protocol_routemaps(&self) -> impl Iterator<Item = &ProtocolRouteMap> + '_ { + self.protocol_routemaps.iter() + } +} -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel