5 * The header file for the ntp discrete event simulator.
7 * Written By: Sachin Kamboj
8 * University of Delaware
18 #ifdef HAVE_SYS_SOCKET_H
19 #include <sys/socket.h>
21 #include <arpa/inet.h>
22 #include "ntp_syslog.h"
25 #include "ntp_select.h"
26 #include "ntp_malloc.h"
27 #include "ntp_refclock.h"
30 #include "ntp_stdlib.h"
32 #include "ntp_data_structures.h"
39 #define PI 3.1415926535 /* The world's most famous constant */
40 #define SIM_TIME 86400 /* end simulation time */
41 #define NET_DLY .001 /* network delay */
42 #define PROC_DLY .001 /* processing delay */
43 #define BEEP_DLY 3600 /* beep interval (s) */
44 #define SLEW 500e-6 /* correction rate (PPM) */
47 /* Discrete Event Queue
48 * --------------------
49 * The NTP simulator is a discrete event simulator.
51 * Central to this simulator is an event queue which is a priority queue
52 * in which the "priority" is given by the time of arrival of the event.
54 * A discrete set of events can happen and are stored in the queue to arrive
55 * at a particular time.
58 /* Possible Discrete Events */
61 BEEP
, /* Event to record simulator stats */
62 CLOCK
, /* Event to advance the clock to the specified time */
63 TIMER
, /* Event that designates a timer interrupt. */
64 PACKET
/* Event that designates arrival of a packet */
68 /* Event information */
71 double time
; /* Time at which event occurred */
72 funcTkn function
; /* Type of event that occured */
75 struct recvbuf evnt_buf
;
76 } buffer
; /* Other data associated with the event */
77 #define ntp_pkt buffer.evnt_pkt
78 #define rcv_buf buffer.evnt_buf
82 /* Server Script Information */
95 /* Server Structures */
98 double server_time
; /* Server time */
99 sockaddr_u
*addr
; /* Server Address */
100 queue
*script
; /* Server Script */
101 script_info
*curr_script
; /* Current Script */
105 /* Simulation control information */
107 typedef struct Sim_Info
{
108 double sim_time
; /* Time in the simulation */
109 double end_time
; /* Time at which simulation needs to be ended */
110 double beep_delay
; /* Delay between simulation "beeps" at which
111 simulation stats are recorded. */
112 int num_of_servers
; /* Number of servers in the simulation */
113 server_info
*servers
; /* Pointer to array of servers */
117 /* Local Clock (Client) Variables */
119 typedef struct Local_Clock_Info
{
120 double local_time
; /* Client disciplined time */
121 double adj
; /* Remaining time correction */
122 double slew
; /* Correction Slew Rate */
123 double last_read_time
; /* Last time the clock was read */
126 extern local_clock_info simclock
; /* Local Clock Variables */
127 extern sim_info simulation
; /* Simulation Control Variables */
129 /* Function Prototypes */
131 int ntpsim (int argc
, char *argv
[]);
132 Event
*event (double t
, funcTkn f
);
133 void sim_event_timer (Event
*e
);
134 int simulate_server (sockaddr_u
*serv_addr
,
135 struct interface
*inter
,
137 void sim_update_clocks (Event
*e
);
138 void sim_event_recv_packet (Event
*e
);
139 void sim_event_beep (Event
*e
);
140 void abortsim (char *errmsg
);
141 double gauss (double, double);
142 double poisson (double, double);
144 void create_server_associations (void);
146 #endif /* NTPSIM_H */