-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic.rs
57 lines (48 loc) · 1.73 KB
/
basic.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! Tests that exercise the base protocol described in [RFC5905](https://datatracker.ietf.org/doc/html/rfc5905).
use crate::macros::*;
use crate::udp::UdpConnection;
use crate::util::result::{TestResult, PASS};
use ntp_proto::{NtpAssociationMode, NtpPacket};
/// Sending a normal poll request should return an answer
///
/// Checks that the tested server actually responds to us.
pub fn test_responds_to_version_4(conn: &mut UdpConnection) -> TestResult {
let (request, id) = NtpPacket::poll_message(Default::default());
let response = conn.pester(request)?;
let packet = pester_assert_response!(response);
let header = pester_assert_version!(packet, packet, V4);
pester_assert_eq!(
packet,
header.origin_timestamp,
id.expected_origin_timestamp,
"Incorrect origin timestamp"
);
pester_assert!(
packet,
packet.valid_server_response(id, false),
"Server response not matching original packet"
);
pester_assert_gt!(
packet,
header.transmit_timestamp,
header.receive_timestamp,
"Receive should happen before send of response"
);
pester_assert_eq!(
packet,
header.mode,
NtpAssociationMode::Server,
"Incorrect mode in server response"
);
PASS
}
/// Check that unknown versions are ignore
///
/// Since NTPv5 is not released yet any compliant server should still ignore
/// packets with this version number.
pub fn test_ignores_version_5(conn: &mut UdpConnection) -> TestResult {
let (packet, _id) = NtpPacket::poll_message_v5(Default::default());
let response = conn.pester(packet)?;
pester_assert_no_response!(response, "Should not respond to ntp version 5 requests");
PASS
}