xref: /netbsd-src/external/bsd/ntp/dist/include/ntpsim.h (revision 7788a0781fe6ff2cce37368b4578a7ade0850cb1)
1 /*	$NetBSD: ntpsim.h,v 1.1.1.2 2012/01/31 21:23:23 kardel Exp $	*/
2 
3 /* ntpsim.h
4  *
5  * The header file for the ntp discrete event simulator.
6  *
7  * Written By:	Sachin Kamboj
8  *		University of Delaware
9  *		Newark, DE 19711
10  * Copyright (c) 2006
11  */
12 
13 #ifndef NTPSIM_H
14 #define NTPSIM_H
15 
16 #include <stdio.h>
17 #include <math.h>
18 #ifdef HAVE_SYS_SOCKET_H
19 #include <sys/socket.h>
20 #endif
21 #include <arpa/inet.h>
22 #include "ntp_syslog.h"
23 #include "ntp_fp.h"
24 #include "ntp.h"
25 #include "ntp_select.h"
26 #include "ntp_malloc.h"
27 #include "ntp_refclock.h"
28 #include "recvbuff.h"
29 #include "ntp_io.h"
30 #include "ntp_stdlib.h"
31 
32 #include "ntp_data_structures.h"
33 
34 /* CONSTANTS */
35 
36 #ifdef PI
37 # undef PI
38 #endif
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 
45 
46 /* Discrete Event Queue
47  * --------------------
48  * The NTP simulator is a discrete event simulator.
49  *
50  * Central to this simulator is an event queue which is a priority queue
51  * in which the "priority" is given by the time of arrival of the event.
52  *
53  * A discrete set of events can happen and are stored in the queue to arrive
54  * at a particular time.
55  */
56 
57 /* Possible Discrete Events */
58 
59 typedef enum {
60     BEEP,          /* Event to record simulator stats */
61     CLOCK,         /* Event to advance the clock to the specified time */
62     TIMER,         /* Event that designates a timer interrupt. */
63     PACKET         /* Event that designates arrival of a packet */
64 } funcTkn;
65 
66 
67 /* Event information */
68 
69 typedef struct {
70     double time;       /* Time at which event occurred */
71     funcTkn function;  /* Type of event that occured */
72     union {
73         struct pkt evnt_pkt;
74         struct recvbuf evnt_buf;
75     } buffer;          /* Other data associated with the event */
76 #define ntp_pkt buffer.evnt_pkt
77 #define rcv_buf buffer.evnt_buf
78 } Event;
79 
80 
81 /* Server Script Information */
82 
83 typedef struct {
84     double duration;
85     double freq_offset;
86     double wander;
87     double jitter;
88     double prop_delay;
89     double proc_delay;
90 } script_info;
91 
92 
93 
94 /* Server Structures */
95 
96 typedef struct {
97     double server_time;             /* Server time */
98     sockaddr_u *addr;  		    /* Server Address */
99     queue *script;                  /* Server Script */
100     script_info *curr_script;       /* Current Script */
101 } server_info;
102 
103 
104 /* Simulation control information */
105 
106 typedef struct Sim_Info {
107     double sim_time;      /* Time in the simulation */
108     double end_time;      /* Time at which simulation needs to be ended */
109     double beep_delay;    /* Delay between simulation "beeps" at which
110                              simulation  stats are recorded. */
111     int num_of_servers;   /* Number of servers in the simulation */
112     server_info *servers; /* Pointer to array of servers */
113 } sim_info;
114 
115 
116 /* Local Clock (Client) Variables */
117 
118 typedef struct Local_Clock_Info {
119     double local_time;     /* Client disciplined time */
120     double adj;            /* Remaining time correction */
121     double slew;           /* Correction Slew Rate */
122     double last_read_time; /* Last time the clock was read */
123 } local_clock_info;
124 
125 extern local_clock_info simclock;   /* Local Clock Variables */
126 extern sim_info simulation;         /* Simulation Control Variables */
127 
128 /* Function Prototypes */
129 
130 int	 ntpsim			 (int argc, char *argv[]);
131 Event    *event                  (double t, funcTkn f);
132 void     sim_event_timer         (Event *e);
133 int      simulate_server         (sockaddr_u *serv_addr,
134 				  struct interface *inter,
135 				  struct pkt *rpkt);
136 void     sim_update_clocks       (Event *e);
137 void     sim_event_recv_packet   (Event *e);
138 void     sim_event_beep          (Event *e);
139 void     abortsim                (char *errmsg);
140 double	 gauss		         (double, double);
141 double	 poisson		 (double, double);
142 int      yyparse                 (void);
143 void     create_server_associations (void);
144 
145 #endif	/* NTPSIM_H */
146