From 7750a92341adee5cac7ef1c51f2b687ae212f5d5 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Thu, 29 Oct 2020 20:14:48 -0500 Subject: ietf-interfaces: Add more operational nodes --- doc/roadmap.rst | 12 +++++++----- ncserver/module/interfaces.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/doc/roadmap.rst b/doc/roadmap.rst index e76e2d1..2ee73b0 100644 --- a/doc/roadmap.rst +++ b/doc/roadmap.rst @@ -233,23 +233,25 @@ Resolved TBDs * [/] Configuration nodes - * [/] Name, description, type + * [x] Name, type + + * [ ] Description * [ ] Enabled * [/] State nodes - * [ ] Operational state + * [x] Operational state * [ ] Time operational state entered - * [ ] Interface index + * [x] Interface index - * [ ] MAC address + * [x] MAC address * [ ] Related higher/lower layer interfaces - * [ ] Link speed (bits/second) + * [x] Link speed (bits/second) * [x] Statistics (``ifctrstat``) diff --git a/ncserver/module/interfaces.py b/ncserver/module/interfaces.py index 7e48b2e..b244bfc 100644 --- a/ncserver/module/interfaces.py +++ b/ncserver/module/interfaces.py @@ -123,6 +123,43 @@ def operational(node): for iface in ifaces.iterchildren(): name = iface.find('{'+M_NS+'}name').text + ifpath = pathlib.Path("/sys/class/net/" + name) + + # if-index + if (ifpath / "ifindex").exists(): + index_file = open(ifpath / "ifindex", 'r') + iface.append(util.leaf_elm('if:if-index', + index_file.read().strip())) + index_file.close() + + # oper-status + status = "unknown" + if (ifpath / "operstate").exists(): + status_file = open(ifpath / "operstate", 'r') + status = status_file.read().strip() + status_file.close() + iface.append(util.leaf_elm('if:oper-status', status)) + + # speed + if status == "up" and (ifpath / "speed").exists(): + try: + with open(ifpath / "speed", 'r') as speed_file: + speed = int(speed_file.read().strip()) + speed *= 1000 + iface.append(util.leaf_elm('if:speed', speed)) + except IOError: + pass # if the interface does not have measurable speed, omit + except ValueError: + LOGGER.warning("%s has non-integral speed; kernel bug?", name) + + # phys-address + if (ifpath / "address").exists(): + addr_file = open(ifpath / "address", 'r') + iface.append(util.leaf_elm('if:phys-address', + addr_file.read().strip())) + addr_file.close() + + # statistics stats = util.subelm(iface, 'if:statistics') # XXX BAD vvv stats.append(util.leaf_elm('if:discontinuity-time', '2020-01-01T01:01:01.011Z')) -- cgit v1.2.3-70-g09d2