biz.neustar.wpm.api
Interface Sntp


public interface Sntp

Makes SNTP requests and parses/validates the response.

For simple requests Net.verifySntp(String, int, int, int) can be used. The Ntp module should be used when more control over the request is needed and/or for accessing to the response structure.

Example script:
   var ntp = require('sntp');

   // optionally set a custom timeout
   ntp.setTimeout(3000);
   ntp.setNtpVersion(4); // optionally set the ntp version

   test.beginTransaction();
   test.beginStep("Step 1");
   var ntpHosts = [
     "3.amazon.pool.ntp.org",
     "time3.google.com",
      "ntp.nasa.gov"];

   // Uncomment to perform IP address lookups using only IPv6 only,
   // by default IPv4 only is used.
   // var dns = require('dns');
   // dns.setLookupMode("ipv6");

   // For each host issue an NTP request
   for (var i = 0; i < ntpHosts.length; i++) {
     var host = ntpHosts[i];
     test.log("===== " + host + " =====");
     ntp.setHost(host);
     // Do the request, if the request fails or times out an exception will be thrown
     // and the script will report the failure
     test.log(ntp.execute());
   }

   test.endStep();
   test.endTransaction();
 


Nested Class Summary
static interface Sntp.SntpResult
          SNTP V4 message according to RFC 4330 (backward compatible with V3)
 
Method Summary
 Sntp.SntpResult execute()
          Connect, send SNTP request and get response.
 int getBytesReceived()
          Number of bytes received.
 int getBytesSent()
          Number of bytes sent.
 java.lang.String getHost()
          Get NTP host URL.
 int getNtpVersion()
          Get NTP version, 3 or 4, default is 4.
 int getPort()
          Get NTP port, default is 123.
 int getTimeout()
          Get timeout, default is 3000 ms.
 void setHost(java.lang.String host)
          Set NTP host to test.
 void setNtpVersion(int version)
          Set NTP version, 3 or 4, default is 4.
 void setPort(int port)
          Set NTP port, default is 123.
 void setTimeout(int timeout)
          Set timeout, default is 3000 ms.
 

Method Detail

getHost

java.lang.String getHost()
Get NTP host URL.

Returns:
the host

setHost

void setHost(java.lang.String host)
Set NTP host to test.

Parameters:
host - the host name to contact

getPort

int getPort()
Get NTP port, default is 123.

Returns:
the port used

setPort

void setPort(int port)
Set NTP port, default is 123.

Parameters:
port - the port to contact

getTimeout

int getTimeout()
Get timeout, default is 3000 ms.

Returns:
the timeout in milliseconds

setTimeout

void setTimeout(int timeout)
Set timeout, default is 3000 ms.

Parameters:
timeout - the timeout in milliseconds

getNtpVersion

int getNtpVersion()
Get NTP version, 3 or 4, default is 4.

Returns:
the NTP version

setNtpVersion

void setNtpVersion(int version)
Set NTP version, 3 or 4, default is 4.

Parameters:
version - the version to use

execute

Sntp.SntpResult execute()
Connect, send SNTP request and get response.

If there is no response from the NTP server or the hostname does not resolve to an IP an exception will be thrown.

Returns:
the result structure, can be logged during validation with test.log().

getBytesSent

int getBytesSent()
Number of bytes sent.

Returns:
the number of bytes sent

getBytesReceived

int getBytesReceived()
Number of bytes received.

Returns:
the number of bytes received

Copyright © 2020 Neustar, Inc. All Rights Reserved.