pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/43377?usp=email )
Change subject: Introduce library/NTP_Functions.ttcn ...................................................................... Introduce library/NTP_Functions.ttcn This is useful to encdec timestamps in NTP format, which are used by other protocols, eg. PFCP. Change-Id: I1551c3424679da8cb71aadb6f34a545c698eb329 --- A library/NTP_Functions.ttcn 1 file changed, 36 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/77/43377/1 diff --git a/library/NTP_Functions.ttcn b/library/NTP_Functions.ttcn new file mode 100644 index 0000000..4072153 --- /dev/null +++ b/library/NTP_Functions.ttcn @@ -0,0 +1,36 @@ +/* NTP Functions in TTCN-3, (RFC 5905) + * (C) 2026 sysmocom - s.f.m.c. GmbH <[email protected]> + * All rights reserved. + * + * Released under the terms of GNU General Public License, Version 2 or + * (at your option) any later version. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +module NTP_Functions { + +import from TCCDateTime_Functions all; + +const integer TIME_NTP32_1970_1900_SEC_DIFF := 2208988800; /* 1970 - 1900 in seconds */ + +function f_time_to_ntp32(integer time) return integer +{ + return (time + TIME_NTP32_1970_1900_SEC_DIFF) mod 4294967296; +} + +function f_time_from_ntp32(integer ntp_timestamp) return integer +{ + if (ntp_timestamp < TIME_NTP32_1970_1900_SEC_DIFF) { + return 0; + } + return ntp_timestamp - TIME_NTP32_1970_1900_SEC_DIFF; +} + +function f_time_ntp32_now() return integer +{ + var integer now := f_time(); + return f_time_to_ntp32(now); +} + +} -- To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/43377?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: osmo-ttcn3-hacks Gerrit-Branch: master Gerrit-Change-Id: I1551c3424679da8cb71aadb6f34a545c698eb329 Gerrit-Change-Number: 43377 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <[email protected]>
