"""FRR's OSPF state in neutral terms (napalm-device-types ``OspfMixin``). Reads the os-frr plugin's diagnostics (``/api/quagga/diagnostics/...``); the field names are FRR's. Whether an interface without neighbours or without authentication is a problem is the caller's to decide. """ from __future__ import annotations from typing import Any from napalm_device_types import OspfMixin _DIAG = "/api/quagga/diagnostics" def _interface(ifc: dict[str, Any]) -> dict[str, Any]: return { "address": ifc.get("ipAddress") or "", "prefix_length": int(ifc.get("ipAddressPrefixlen") or 0), "area": ifc.get("area") or "", "network_type": ifc.get("networkType") or "", "authentication": ifc.get("authentication") or "", "neighbors": int(ifc.get("nbrCount") or 0), "neighbors_adjacent": int(ifc.get("nbrAdjacentCount") or 0), "cost": int(ifc.get("cost") or 0), } class OPNsenseOspfMixin(OspfMixin): """Needs the driver's ``_get``.""" def get_ospf(self) -> dict[str, Any]: """Router ID, areas and OSPF per interface; empty when OSPF does not run.""" overview = self._get(f"{_DIAG}/ospfoverview").get("response") or {} # type: ignore[attr-defined] interfaces = (self._get(f"{_DIAG}/ospfinterface").get("response") or {}).get( "interfaces" ) or {} # type: ignore[attr-defined] return { "router_id": overview.get("routerId") or None, "areas": list((overview.get("areas") or {}).keys()), "interfaces": {name: _interface(ifc) for name, ifc in interfaces.items()}, }