3 * The header file for the ntp discrete event simulator.
5 * Written By: Sachin Kamboj
6 * University of Delaware
16 #ifdef HAVE_SYS_SOCKET_H
17 #include <sys/socket.h>
19 #include <arpa/inet.h>
20 #include "ntp_syslog.h"
23 #include "ntp_select.h"
24 #include "ntp_malloc.h"
25 #include "ntp_refclock.h"
28 #include "ntp_stdlib.h"
29 #include "ntp_prio_q.h"
36 #define PI 3.1415926535 /* The world's most famous constant */
37 #define SIM_TIME 86400 /* end simulation time */
38 #define NET_DLY .001 /* network delay */
39 #define PROC_DLY .001 /* processing delay */
40 #define BEEP_DLY 3600 /* beep interval (s) */
43 /* Discrete Event Queue
44 * --------------------
45 * The NTP simulator is a discrete event simulator.
47 * Central to this simulator is an event queue which is a priority queue
48 * in which the "priority" is given by the time of arrival of the event.
50 * A discrete set of events can happen and are stored in the queue to arrive
51 * at a particular time.
54 /* Possible Discrete Events */
57 BEEP, /* Event to record simulator stats */
58 CLOCK, /* Event to advance the clock to the specified time */
59 TIMER, /* Event that designates a timer interrupt. */
60 PACKET /* Event that designates arrival of a packet */
64 /* Event information */
67 double time; /* Time at which event occurred */
68 funcTkn function; /* Type of event that occured */
71 struct recvbuf evnt_buf;
72 } buffer; /* Other data associated with the event */
73 #define ntp_pkt buffer.evnt_pkt
74 #define rcv_buf buffer.evnt_buf
78 /* Server Script Information */
79 typedef struct script_info_tag script_info;
80 struct script_info_tag {
90 typedef DECL_FIFO_ANCHOR(script_info) script_info_fifo;
93 /* Server Structures */
95 typedef struct server_info_tag server_info;
96 struct server_info_tag {
100 script_info_fifo * script;
101 script_info * curr_script;
104 typedef DECL_FIFO_ANCHOR(server_info) server_info_fifo;
107 /* Simulation control information */
109 typedef struct Sim_Info {
110 double sim_time; /* Time in the simulation */
111 double end_time; /* Time at which simulation needs to be ended */
112 double beep_delay; /* Delay between simulation "beeps" at which
113 simulation stats are recorded. */
114 int num_of_servers; /* Number of servers in the simulation */
115 server_info *servers; /* Pointer to array of servers */
119 /* Local Clock (Client) Variables */
121 typedef struct Local_Clock_Info {
122 double local_time; /* Client disciplined time */
123 double adj; /* Remaining time correction */
124 double slew; /* Correction Slew Rate */
125 double last_read_time; /* Last time the clock was read */
128 extern local_clock_info simclock; /* Local Clock Variables */
129 extern sim_info simulation; /* Simulation Control Variables */
131 /* Function Prototypes */
133 int ntpsim (int argc, char *argv[]);
134 Event *event (double t, funcTkn f);
135 void sim_event_timer (Event *e);
136 int simulate_server (sockaddr_u *serv_addr, endpt *inter,
138 void sim_update_clocks (Event *e);
139 void sim_event_recv_packet (Event *e);
140 void sim_event_beep (Event *e);
141 void abortsim (char *errmsg);
142 double gauss (double, double);
143 double poisson (double, double);
144 void create_server_associations(void);
146 #endif /* NTPSIM_H */