Skip to content

Commit d6508a7

Browse files
committed
Implement NTP client status
1 parent f6bd209 commit d6508a7

5 files changed

Lines changed: 116 additions & 1 deletion

File tree

src/confd/yang/confd.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ MODULES=(
3232
"infix-lldp@2023-08-23.yang"
3333
"infix-dhcp-client@2024-09-20.yang"
3434
"infix-meta@2024-10-18.yang"
35-
"infix-system@2024-09-13.yang"
35+
"infix-system@2024-11-27.yang"
3636
"infix-services@2024-05-30.yang"
3737
"ieee802-ethernet-interface@2019-06-21.yang"
3838
"infix-ethernet-interface@2024-02-27.yang"

src/confd/yang/infix-system.yang

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,22 @@ module infix-system {
1010
prefix iana-tz;
1111
}
1212

13+
import ietf-inet-types {
14+
prefix inet;
15+
reference
16+
"RFC 6991: Common YANG Data Types";
17+
}
18+
1319
include infix-system-software;
1420

1521
organization "KernelKit";
1622
contact "kernelkit@googlegroups.com";
1723
description "Infix augments and deviations to ietf-system.";
1824

25+
revision 2024-11-27 {
26+
description "Add NTP status";
27+
reference "internal";
28+
}
1929
revision 2024-09-13 {
2030
description "Add some informative help about different shells and security.";
2131
reference "internal";
@@ -115,6 +125,41 @@ module infix-system {
115125
base shell-type;
116126
}
117127

128+
typedef source-state {
129+
type enumeration {
130+
enum selected {
131+
description "Selected NTP server for synchronization";
132+
}
133+
enum candidate {
134+
description "Accepted by not selected source";
135+
}
136+
enum outlier {
137+
description "discarded by the clustering algorithm";
138+
}
139+
enum unreachable {
140+
description "unreachable or unresponsable";
141+
}
142+
enum falseticker {
143+
description "suspected of providing incorrect time";
144+
}
145+
enum unstable {
146+
description "Too variable or unstable source";
147+
}
148+
}
149+
}
150+
typedef source-mode {
151+
type enumeration {
152+
enum server {
153+
description "Normal NTP server";
154+
}
155+
enum peer {
156+
description "Symmetric peer";
157+
}
158+
enum local-clock {
159+
description "Reference clock";
160+
}
161+
}
162+
}
118163
/*
119164
* Typedefs
120165
*/
@@ -256,6 +301,37 @@ module infix-system {
256301
}
257302
}
258303

304+
augment "/sys:system-state" {
305+
container ntp {
306+
description "NTP status";
307+
container sources {
308+
list source {
309+
key address;
310+
leaf address {
311+
type inet:ip-address;
312+
description "Address to connected NTP server";
313+
}
314+
leaf source-mode {
315+
type source-mode;
316+
description "Source mode";
317+
}
318+
leaf source-state {
319+
type source-state;
320+
description "Source state";
321+
}
322+
leaf stratum {
323+
type uint8;
324+
description "Stratum of connected NTP server";
325+
}
326+
leaf poll {
327+
type uint8;
328+
description "Interval between transmitted NTP messages, expressed as a power of two in seconds.";
329+
}
330+
331+
}
332+
}
333+
}
334+
}
259335
deviation "/sys:system/sys:hostname" {
260336
deviate replace {
261337
type infix-sys:hostname;
File renamed without changes.

src/statd/python/yanger/yanger.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,36 @@ def add_interface(ifname, yang_ifaces):
10391039

10401040
add_container_ifaces(yang_ifaces)
10411041

1042+
def add_system_ntp(out):
1043+
data = run_cmd(["chronyc", "-c", "sources"], "chronyc-sources.txt", "")
1044+
source = []
1045+
state_mode_map = {
1046+
"^": "server",
1047+
"=": "peer",
1048+
"#": "local-clock"
1049+
}
1050+
source_state_map = {
1051+
"*": "selected",
1052+
"+": "candidate",
1053+
"-": "outlier",
1054+
"?": "unreachable",
1055+
"x": "falseticker",
1056+
"~": "unstable"
1057+
}
1058+
for line in data:
1059+
src = {}
1060+
line = line.split(',')
1061+
src["address"] = line[2]
1062+
src["source-mode"] = state_mode_map[line[0]]
1063+
src["source-state"] = source_state_map[line[1]]
1064+
src["stratum"] = int(line[3])
1065+
src["poll"] = int(line[4])
1066+
source.append(src)
1067+
1068+
insert(out, "infix-system:ntp", "sources", "source", source)
1069+
def add_system(yang_data):
1070+
add_system_ntp(yang_data)
1071+
10421072
def main():
10431073
global TESTPATH
10441074
global logger
@@ -1119,6 +1149,12 @@ def main():
11191149
}
11201150
add_container(yang_data['infix-containers:containers']['container'])
11211151

1152+
elif args.model == 'ietf-system':
1153+
yang_data = {
1154+
"ietf-system:system-state": {
1155+
}
1156+
}
1157+
add_system(yang_data['ietf-system:system-state'])
11221158
else:
11231159
logger.warning(f"Unsupported model {args.model}", file=sys.stderr)
11241160
sys.exit(1)

src/statd/statd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#define XPATH_ROUTING_BASE "/ietf-routing:routing/control-plane-protocols/control-plane-protocol"
3838
#define XPATH_ROUTING_TABLE "/ietf-routing:routing/ribs"
3939
#define XPATH_HARDWARE_BASE "/ietf-hardware:hardware"
40+
#define XPATH_SYSTEM_BASE "/ietf-system:system-state"
4041
#define XPATH_ROUTING_OSPF XPATH_ROUTING_BASE "/ospf"
4142
#define XPATH_CONTAIN_BASE "/infix-containers:containers"
4243

@@ -340,6 +341,8 @@ static int subscribe_to_all(struct statd *statd)
340341
return SR_ERR_INTERNAL;
341342
if (subscribe(statd, "ietf-hardware", XPATH_HARDWARE_BASE, sr_generic_cb))
342343
return SR_ERR_INTERNAL;
344+
if (subscribe(statd, "ietf-system", XPATH_SYSTEM_BASE, sr_generic_cb))
345+
return SR_ERR_INTERNAL;
343346
#ifdef CONTAINERS
344347
if (subscribe(statd, "infix-containers", XPATH_CONTAIN_BASE, sr_generic_cb))
345348
return SR_ERR_INTERNAL;

0 commit comments

Comments
 (0)