-
Notifications
You must be signed in to change notification settings - Fork 14
NTP server support #1302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
NTP server support #1302
Conversation
Fixes #904 Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
mattiaswal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, will be a great addition to Infix 💪
| NTP uses a hierarchical system called **stratum** to indicate distance from | ||
| authoritative time sources: | ||
|
|
||
| - **Stratum 0**: Reference clocks (atomic clocks, GPS receivers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stratum 0 is atom clocks, GPS receivers will have 1 (derectly connected to stratum 0 as you say below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching that!
| } | ||
|
|
||
| /* Upstream server/peer configuration (unicast-configuration) */ | ||
| rc = sr_get_items(session, XPATH_NTP_"/unicast-configuration", 0, 0, &val, &cnt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a better API to get the xpath from the config struct ly_set *lydx_find_xpathf(struct lyd_node *ctx, const char *xpfmt, ...) no neet do allocate more memory.
| fprintf(fp, "# Upstream NTP servers and peers\n"); | ||
|
|
||
| for (size_t i = 0; i < cnt; i++) { | ||
| char *address = srx_get_str(session, "%s/address", val[i].xpath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all srx_get_get_str can also be changed to use lydx_ API to reduce memory allocation
|
|
||
| /* Reference clock (local stratum) - fallback time source */ | ||
| if (lydx_get_xpathf(config, XPATH_NTP_"/refclock-master")) { | ||
| SRX_GET_UINT8(session, stratum, XPATH_NTP_"/refclock-master/master-stratum"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, store the result of lydx_get_xpath and use lydx api.
|
|
||
| /* Infer refclock-master with stratum 10 (safe fallback) */ | ||
| DEBUG("Inferring NTP refclock-master with stratum 10"); | ||
| inferred_uint8.data.uint8_val = 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be default in the YANG model instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, of course! I see now that the YANG model does have a default value (16):
container refclock-master {
presence "NTP master clock is enabled.";
description
"Configures the local clock of this device as NTP server.";
leaf master-stratum {
type ntp-stratum;
default "16";
description
"Stratum level from which NTP clients get their time
synchronized.";
}
}I'll make sure to just infer the container.
Description
This PR adds NTP server support using the ietf-ntp (RFC 9249) YANG model. The implementation supports three operational modes aligned with the documentation:
Features Implemented
Deviations & Limitations
Several advanced features from ietf-ntp have been deviated as not-supported:
Testing
server_mode_standalone: Standalone operation with local reference clockserver_mode_server: Upstream sync while serving clientsserver_mode_peer: Bidirectional peer synchronizationserver_makestep: Configuration and operational state verificationserver_client: Verifies ietf-ntp (server) and ietf-system (client)Checklist
Tick relevant boxes, this PR is-a or has-a: