1 /* $NetBSD: ntpsim.h,v 1.1.1.1 2009/12/13 16:54:54 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 #define SLEW 500e-6 /* correction rate (PPM) */ 45 46 47 /* Discrete Event Queue 48 * -------------------- 49 * The NTP simulator is a discrete event simulator. 50 * 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. 53 * 54 * A discrete set of events can happen and are stored in the queue to arrive 55 * at a particular time. 56 */ 57 58 /* Possible Discrete Events */ 59 60 typedef enum { 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 */ 65 } funcTkn; 66 67 68 /* Event information */ 69 70 typedef struct { 71 double time; /* Time at which event occurred */ 72 funcTkn function; /* Type of event that occured */ 73 union { 74 struct pkt evnt_pkt; 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 79 } Event; 80 81 82 /* Server Script Information */ 83 84 typedef struct { 85 double duration; 86 double freq_offset; 87 double wander; 88 double jitter; 89 double prop_delay; 90 double proc_delay; 91 } script_info; 92 93 94 95 /* Server Structures */ 96 97 typedef struct { 98 double server_time; /* Server time */ 99 sockaddr_u *addr; /* Server Address */ 100 queue *script; /* Server Script */ 101 script_info *curr_script; /* Current Script */ 102 } server_info; 103 104 105 /* Simulation control information */ 106 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 */ 114 } sim_info; 115 116 117 /* Local Clock (Client) Variables */ 118 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 */ 124 } local_clock_info; 125 126 extern local_clock_info simclock; /* Local Clock Variables */ 127 extern sim_info simulation; /* Simulation Control Variables */ 128 129 /* Function Prototypes */ 130 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, 136 struct pkt *rpkt); 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); 143 int yyparse (void); 144 void create_server_associations (void); 145 146 #endif /* NTPSIM_H */ 147