From 2b154c18258ec8858238d0cb4ffc81912ec44dbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Thu, 21 Dec 2023 10:37:53 +0100 Subject: [PATCH] infix-routing: Add support for operational data Now these are implemented: * OSPF Router ID * Neighbor status * OSPF routing table --- board/netconf/rootfs/libexec/infix/yanger | 64 +++++++++++++++++++- src/confd/yang/infix-routing@2023-11-23.yang | 20 +++--- 2 files changed, 70 insertions(+), 14 deletions(-) diff --git a/board/netconf/rootfs/libexec/infix/yanger b/board/netconf/rootfs/libexec/infix/yanger index cce9631b..8676a7a1 100755 --- a/board/netconf/rootfs/libexec/infix/yanger +++ b/board/netconf/rootfs/libexec/infix/yanger @@ -167,10 +167,53 @@ def add_ipv6_route(routes): data = run_json_cmd(cmd) get_routes(routes, "ipv6", data) -def add_ospf_area(ospf): +def frr_to_ietf_neighbor_state(state): + state=state.split("/")[0] + if(state == "TwoWay"): + return "2-way" + return state.lower() + +def add_ospf_routes(ospf): + cmd = ['vtysh', '-c', "show ip ospf rout json"] + data = run_json_cmd(cmd) + routes=[] + for prefix,info in data.items(): + route={} + if prefix.find("/") == -1: + prefix = prefix+"/32" + route["prefix"] = prefix + nexthops=[] + routetype=info["routeType"].split(" ") + if(len(routetype) > 1): + if(routetype[1]=="E1"): + route["route-type"] = "external-1" + elif(routetype[1]=="E2"): + route["route-type"] = "external-2" + elif(routetype[1]=="IA"): + route["route-type"] = "inter-area" + else: + route["route-type"] = "intra-area" + else: + route["route-type"] = "intra-area" + for hop in info["nexthops"]: + nexthop={} + if(hop["ip"] != " "): + nexthop["next-hop"] = hop["ip"] + else: + nexthop["outgoing-interface"] = hop["directlyAttachedTo"] + nexthops.append(nexthop) + route["next-hops"] = {} + route["next-hops"]["next-hop"] = nexthops + routes.append(route) + insert(ospf, "ietf-ospf:local-rib", "ietf-ospf:route", routes) + +def add_ospf(ospf): cmd = ['/libexec/infix/ospf-status'] data = run_json_cmd(cmd) + ospf["ietf-ospf:router-id"] = data["routerId"] + ospf["ietf-ospf:address-family"] = "ipv4" areas=[] + for area_id,values in data["areas"].items(): area={} area["ietf-ospf:area-id"] = area_id @@ -178,6 +221,7 @@ def add_ospf_area(ospf): interfaces=[] for iface in values["interfaces"]: interface={} + interface["ietf-ospf:neighbors"] = {} interface["name"]=iface["name"] if(iface.get("drId")): interface["dr-router-id"]=iface["drId"] @@ -187,10 +231,24 @@ def add_ospf_area(ospf): interface["bdr-router-id"]=iface["bdrId"] if(iface.get("bdrAddress")): interface["bdr-ip-addr"]=iface["bdrAddress"] + + neighbors = [] + for neigh in iface["neighbors"]: + neighbor={} + neighbor["neighbor-router-id"] = neigh["neighborIp"] + neighbor["address"] = neigh["ifaceAddress"] + neighbor["dr-router-id"] = neigh["routerDesignatedId"] + neighbor["bdr-router-id"] = neigh["routerDesignatedBackupId"] + neighbor["dead-timer"] = neigh["routerDeadIntervalTimerDueMsec"] + neighbor["state"]=frr_to_ietf_neighbor_state(neigh["nbrState"]) + neighbors.append(neighbor) + interface["ietf-ospf:neighbors"] = {} + interface["ietf-ospf:neighbors"]["ietf-ospf:neighbor"] = neighbors interfaces.append(interface) area["ietf-ospf:interfaces"]["ietf-ospf:interface"] = interfaces areas.append(area) - insert(ospf, "area", areas) + insert(ospf, "ietf-ospf:areas", "area", areas) + add_ospf_routes(ospf) def add_ip_link(ifname, iface_out, test): if test: @@ -477,7 +535,7 @@ if __name__ == "__main__": } } } - add_ospf_area(yang_data['ietf-routing:routing']['control-plane-protocols']['control-plane-protocol'][0]["ietf-ospf:ospf"]["ietf-ospf:areas"]) + add_ospf(yang_data['ietf-routing:routing']['control-plane-protocols']['control-plane-protocol'][0]["ietf-ospf:ospf"]) else: print(f"Unsupported model {args.model}", file=sys.stderr) sys.exit(1) diff --git a/src/confd/yang/infix-routing@2023-11-23.yang b/src/confd/yang/infix-routing@2023-11-23.yang index 8f6cec81..ea4503ea 100644 --- a/src/confd/yang/infix-routing@2023-11-23.yang +++ b/src/confd/yang/infix-routing@2023-11-23.yang @@ -135,6 +135,7 @@ module infix-routing { } /* OSPF */ + augment "/ietf-r:routing/ietf-r:control-plane-protocols/ietf-r:control-plane-protocol/ospf:ospf" { description "ietf-ospf does not contain redistribution 7. How should route redistribution be configured? I see ietf-rip.yang has a separate @@ -156,6 +157,7 @@ module infix-routing { } } } + deviation "/ietf-r:routing/ietf-r:ribs/ietf-r:rib/ietf-r:routes/ietf-r:route/ospf:metric" { deviate not-supported; } @@ -213,9 +215,6 @@ module infix-routing { deviation "/ietf-r:routing/ietf-r:control-plane-protocols/ietf-r:control-plane-protocol/ospf:ospf/ospf:node-tags" { deviate not-supported; } - deviation "/ietf-r:routing/ietf-r:control-plane-protocols/ietf-r:control-plane-protocol/ospf:ospf/ospf:local-rib" { - deviate not-supported; - } deviation "/ietf-r:routing/ietf-r:control-plane-protocols/ietf-r:control-plane-protocol/ospf:ospf/ospf:mpls" { deviate not-supported; } @@ -253,6 +252,11 @@ module infix-routing { } /* OSPF Area Interface */ + deviation "/ietf-r:routing/ietf-r:control-plane-protocols/ietf-r:control-plane-protocol/ospf:ospf/ospf:areas/ospf:area/ospf:interfaces/ospf:interface/ospf:static-neighbors" + { + deviate not-supported; + } + deviation "/ietf-r:routing/ietf-r:control-plane-protocols/ietf-r:control-plane-protocol/ospf:ospf/ospf:areas/ospf:area/ospf:interfaces/ospf:interface/ospf:multi-areas" { deviate not-supported; } @@ -266,6 +270,7 @@ module infix-routing { { deviate not-supported; } + deviation "/ietf-r:routing/ietf-r:control-plane-protocols/ietf-r:control-plane-protocol/ospf:ospf/ospf:areas/ospf:area/ospf:interfaces/ospf:interface/ospf:interface-type" { deviate not-supported; @@ -286,10 +291,7 @@ module infix-routing { { deviate not-supported; } - deviation "/ietf-r:routing/ietf-r:control-plane-protocols/ietf-r:control-plane-protocol/ospf:ospf/ospf:areas/ospf:area/ospf:interfaces/ospf:interface/ospf:neighbors" - { - deviate not-supported; - } + deviation "/ietf-r:routing/ietf-r:control-plane-protocols/ietf-r:control-plane-protocol/ospf:ospf/ospf:areas/ospf:area/ospf:interfaces/ospf:interface/ospf:database" { deviate not-supported; @@ -310,10 +312,6 @@ module infix-routing { { deviate not-supported; } - deviation "/ietf-r:routing/ietf-r:control-plane-protocols/ietf-r:control-plane-protocol/ospf:ospf/ospf:areas/ospf:area/ospf:interfaces/ospf:interface/ospf:static-neighbors" - { - deviate not-supported; - } deviation "/ietf-r:routing/ietf-r:control-plane-protocols/ietf-r:control-plane-protocol/ospf:ospf/ospf:areas/ospf:area/ospf:interfaces/ospf:interface/ospf:ttl-security" { deviate not-supported;