/
common.h
148 lines (102 loc) · 3.46 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#ifndef _COMMON_H
#define _COMMON_H
#define _GNU_SOURCE
//Used to turn on the checking of the microseconds
//#define CHECK_TIMES 100000
#include "netlib.h"
#include <signal.h> // for SIGRTMIN
// The number of cores this machine has
extern const unsigned int max_cores; // TODO get the real number!
struct stats {
// The cores these stats were recorded from
unsigned int cores;
// The number of bytes received
unsigned long long bytes_received;
// The number of recv() handled
unsigned long long pkts_received;
// The duration packets were inside the network
unsigned long long pkts_time;
// Number of timestamps received
unsigned long long timestamps;
// The duration over which these stats were recorded
unsigned long long duration;
#ifdef CHECK_TIMES
//Temp buffer for the recv time values used to plot a histogram
float processing_times[CHECK_TIMES];
int processed_something;
#endif
};
struct test {
unsigned int clientcores; // The cores the client may run on
unsigned int servercores; // The cores the servers may run on
unsigned int connections; // The number of connections
struct sockaddr_storage addr;
socklen_t addr_len;
};
// Settings
struct settings {
unsigned int duration;
int type;
int protocol;
unsigned int daemon :1;
unsigned int verbose :1;
unsigned int dirty :1;
unsigned int timestamp :1;
unsigned int disable_nagles :1;
unsigned int reverse :1;
unsigned int quiet :1;
double confidence_lvl;
double confidence_int;
unsigned int min_iterations;
unsigned int max_iterations;
unsigned int message_size;
unsigned int socket_size;
unsigned int rate; // Sends per second
const char *server_host;
unsigned short port;
// An array of each test
unsigned int tests;
struct test *test;
// Helper members, so we don't have to recalc all the time
unsigned int clientcores;
unsigned int servercores;
unsigned int threaded_model;
};
// Works out how many cores the client will use
unsigned int count_client_cores( const struct test *test, const unsigned int tests );
// Works out how many cores the server will use
unsigned int count_server_cores( const struct test *test, const unsigned int tests );
void stats_add(struct stats *dest, const struct stats *src);
// Move all the elements after arr down one
void move_down ( SOCKET *arr, SOCKET *arr_end );
unsigned long long get_microseconds();
unsigned long long get_nanoseconds();
void get_timespec_now(struct timespec *ts);
void add_timespec(struct timespec *ts, time_t tv_sec, long tv_nsec);
void stop_all();
double calc_confidence(double confidence_lvl, double mean, double variance, unsigned int n, int verbose);
#ifdef WIN32
// Sleep for a number of microseconds
int usleep(unsigned int useconds);
#endif
// Returns the highest socket in the set
SOCKET highest_socket(SOCKET *s, size_t len);
// Malloc a 2D array
void **malloc_2D(size_t element_size, size_t x, size_t y);
void free_2D(void **data, size_t x);
#define BUFFER_FILL 0x41
// How long do control sockets wait for connections (in milliseconds)
#define CONTROL_TIMEOUT 30000
// How long to wait for IPC socket calls
#define IPC_TIMEOUT 5000
// How long the server waits for a connection (in milliseconds)
#define TRANSFER_TIMEOUT 1000
#define SIGNUM ( SIGRTMIN + 5 )
#define SIGNAL_READY_TO_ACCEPT 1
#define SIGNAL_READY_TO_GO 2
#define SIGNAL_GO 3
#define SIGNAL_STOP 4
#define MODEL_THREADED 0
#define MODEL_PROCESS 1
#define IPC_SOCK_NAME "resultspipe"
#endif