Flowgrind
Advanced TCP traffic generator
daemon.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright (C) 2010-2013 Christian Samsel <christian.samsel@rwth-aachen.de>
8  * Copyright (C) 2009 Tim Kosse <tim.kosse@gmx.de>
9  * Copyright (C) 2007-2008 Daniel Schaffrath <daniel.schaffrath@mac.com>
10  *
11  * This file is part of Flowgrind.
12  *
13  * Flowgrind is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation, either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * Flowgrind is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with Flowgrind. If not, see <http://www.gnu.org/licenses/>.
25  *
26  */
27 
28 #ifndef _DAEMON_H_
29 #define _DAEMON_H_
30 
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif /* HAVE_CONFIG_H */
34 
35 #include <sys/types.h>
36 #include <sys/socket.h>
37 
38 #ifdef HAVE_LIBGSL
39 #include <gsl/gsl_rng.h>
40 #endif /* HAVE_LIBGSL */
41 
42 #include "common.h"
43 #include "fg_list.h"
44 
45 #include <xmlrpc-c/base.h>
46 #include <xmlrpc-c/server.h>
47 #include <xmlrpc-c/server_abyss.h>
48 #include <xmlrpc-c/util.h>
49 
51 #define DEFAULT_SELECT_TIMEOUT 10000000
52 
54 {
55  /* SOURCE */
57  /* DESTINATION */
59  /* RUN */
61 };
62 
64 {
65  char destination_host[256];
67 
69 
70  pthread_cond_t* add_source_condition;
71 };
72 
73 struct flow
74 {
75  int id;
76 
79 
80  int fd;
82 
85 
86  struct timespec start_timestamp[2];
87  struct timespec stop_timestamp[2];
88  struct timespec last_block_read;
89  struct timespec last_block_written;
90 
91  struct timespec first_report_time;
92  struct timespec last_report_time;
93  struct timespec next_report_time;
94 
95  struct timespec next_write_block_timestamp;
96 
97  char *read_block;
98  char *write_block;
99 
102 
105 
107 
110 
112  char finished[2];
113 
114  int pmtu;
115 
117 
118  /* Used for do_connect for source flows */
119  struct sockaddr *addr;
120  socklen_t addr_len;
121 
122  struct statistics {
123 #ifdef HAVE_UNSIGNED_LONG_LONG_INT
124  unsigned long long bytes_read;
125  unsigned long long bytes_written;
126 #else /* HAVE_UNSIGNED_LONG_LONG_INT */
127  long bytes_read;
128  long bytes_written;
129 #endif /* HAVE_UNSIGNED_LONG_LONG_INT */
134 
135  /* TODO Create an array for IAT / RTT and delay */
136 
138  double iat_min;
140  double iat_max;
142  double iat_sum;
144  double delay_min;
146  double delay_max;
148  double delay_sum;
150  double rtt_min;
152  double rtt_max;
154  double rtt_sum;
155 
158  } statistics[2];
159 
160 #ifdef HAVE_LIBPCAP
161  pthread_t pcap_thread;
162  struct pcap_t *pcap_handle;
163  struct pcap_dumper_t *pcap_dumper;
164 #endif /* HAVE_LIBPCAP */
165 
166 #ifdef HAVE_LIBGSL
167  gsl_rng * r;
168 #endif /* HAVE_LIBGSL */
169 
170  char* error;
171 };
172 
173 #define REQUEST_ADD_DESTINATION 0
174 #define REQUEST_ADD_SOURCE 1
175 #define REQUEST_START_FLOWS 2
176 #define REQUEST_STOP_FLOW 3
177 #define REQUEST_GET_STATUS 4
178 #define REQUEST_GET_UUID 5
179 struct request
180 {
181  char type;
182 
183  /* We signal this condition once the daemon thread
184  * has processed the request */
185  pthread_cond_t* condition;
186 
187  char* error;
188 
189  struct request *next;
190 };
191 extern struct request *requests, *requests_last;
192 
194 {
195  struct request r;
196 
198 
199  /* The request reply */
200  int flow_id;
204 };
205 
207 {
208  struct request r;
209 
212 
213  /* The request reply */
214  int flow_id;
218 };
219 
221 {
222  struct request r;
223 
225 };
226 
228 {
229  struct request r;
230 
231  int flow_id;
232 };
233 
241 {
242  struct request r;
244  char server_uuid[38];
245 };
246 
248 {
249  struct request r;
250 
251  int started;
253 };
254 
255 extern pthread_t daemon_thread;
256 
257 /* Through this pipe we wakeup the thread from select */
258 extern int daemon_pipe[2];
259 
260 extern char started;
261 extern pthread_mutex_t mutex;
262 extern struct linked_list flows;
263 extern struct report* reports;
264 extern struct report* reports_last;
265 extern unsigned pending_reports;
266 
267 /* Gets 50 reports. There may be more pending but there's a limit on how
268  * large a reply can get */
269 struct report* get_reports(int *has_more);
270 
271 extern char *dump_prefix;
272 extern char *dump_dir;
273 
274 void *daemon_main(void* ptr);
275 void add_report(struct report* report);
276 void flow_error(struct flow *flow, const char *fmt, ...);
277 void request_error(struct request *request, const char *fmt, ...);
278 int set_flow_tcp_options(struct flow *flow);
279 
282  int dispatch_request(struct request *request, int type);
283 
294  void get_uuid_string(char *uuid_str);
295 #endif /* _DAEMON_H_ */
flow::statistics::response_blocks_read
unsigned response_blocks_read
Definition: daemon.h:132
flow_source_settings::add_source_condition
pthread_cond_t * add_source_condition
Definition: daemon.h:70
request_get_status::num_flows
int num_flows
Definition: daemon.h:252
flow::statistics::delay_sum
double delay_sum
Accumulated one-way delay.
Definition: daemon.h:148
request_stop_flow::flow_id
int flow_id
Definition: daemon.h:231
flow::current_read_block_size
unsigned current_read_block_size
Definition: daemon.h:101
started
char started
Definition: daemon.c:105
request_add_flow_source::source_settings
struct flow_source_settings source_settings
Definition: daemon.h:211
request_get_status
Definition: daemon.h:247
flow::statistics::iat_min
double iat_min
Minimum interarrival time.
Definition: daemon.h:138
request_stop_flow::r
struct request r
Definition: daemon.h:229
request_add_flow_source::flow_id
int flow_id
Definition: daemon.h:214
get_reports
struct report * get_reports(int *has_more)
Definition: daemon.c:853
flow::connect_called
char connect_called
Definition: daemon.h:111
request_add_flow_source::real_send_buffer_size
int real_send_buffer_size
Definition: daemon.h:216
flow
Definition: daemon.h:73
request_add_flow_destination::real_listen_read_buffer_size
int real_listen_read_buffer_size
Definition: daemon.h:203
request_add_flow_destination::settings
struct flow_settings settings
Definition: daemon.h:197
flow_source_settings::destination_host
char destination_host[256]
Definition: daemon.h:65
request_add_flow_source::real_read_buffer_size
int real_read_buffer_size
Definition: daemon.h:217
flow::statistics::rtt_sum
double rtt_sum
Accumulated round-trip time.
Definition: daemon.h:154
add_report
void add_report(struct report *report)
Definition: daemon.c:827
request_add_flow_source::settings
struct flow_settings settings
Definition: daemon.h:210
request_add_flow_source::cc_alg
char cc_alg[TCP_CA_NAME_MAX]
Definition: daemon.h:215
request_add_flow_destination::real_listen_send_buffer_size
int real_listen_send_buffer_size
Definition: daemon.h:202
flow::statistics::tcp_info
struct fg_tcp_info tcp_info
Definition: daemon.h:157
flow::statistics
Definition: daemon.h:122
flow::statistics::delay_max
double delay_max
Maximum one-way delay.
Definition: daemon.h:146
flow::source_settings
struct flow_source_settings source_settings
Definition: daemon.h:84
flow::pmtu
int pmtu
Definition: daemon.h:114
GRIND
@ GRIND
Definition: daemon.h:60
flows
struct linked_list flows
Definition: daemon.c:103
requests
struct request * requests
Definition: daemon.c:94
flow::next_write_block_timestamp
struct timespec next_write_block_timestamp
Definition: daemon.h:95
request_start_flows::start_timestamp
int start_timestamp
Definition: daemon.h:224
flow::statistics::delay_min
double delay_min
Minimum one-way delay.
Definition: daemon.h:144
flow::settings
struct flow_settings settings
Definition: daemon.h:83
flow::pcap_dumper
struct pcap_dumper_t * pcap_dumper
Definition: daemon.h:163
flow_source_settings
Definition: daemon.h:63
flow::last_report_time
struct timespec last_report_time
Definition: daemon.h:92
flow::read_block
char * read_block
Definition: daemon.h:97
flow::r
gsl_rng * r
Definition: daemon.h:167
request_stop_flow
Definition: daemon.h:227
set_flow_tcp_options
int set_flow_tcp_options(struct flow *flow)
Definition: daemon.c:1424
request_add_flow_destination
Definition: daemon.h:193
request_start_flows
Definition: daemon.h:220
flow::statistics::bytes_written
unsigned long long bytes_written
Definition: daemon.h:125
dump_prefix
char * dump_prefix
Definition: daemon.c:90
request_start_flows::r
struct request r
Definition: daemon.h:222
flow::statistics::rtt_max
double rtt_max
Maximum round-trip time.
Definition: daemon.h:152
report
Definition: common.h:286
request::type
char type
Definition: daemon.h:181
flow::current_block_bytes_read
unsigned current_block_bytes_read
Definition: daemon.h:103
flow_source_settings::late_connect
int late_connect
Definition: daemon.h:68
flow::statistics::response_blocks_written
unsigned response_blocks_written
Definition: daemon.h:133
reports
struct report * reports
Definition: daemon.c:99
request_add_flow_source
Definition: daemon.h:206
request
Definition: daemon.h:179
flow::error
char * error
Definition: daemon.h:170
request::next
struct request * next
Definition: daemon.h:189
flow::current_write_block_size
unsigned current_write_block_size
Definition: daemon.h:100
GRIND_WAIT_CONNECT
@ GRIND_WAIT_CONNECT
Definition: daemon.h:56
GRIND_WAIT_ACCEPT
@ GRIND_WAIT_ACCEPT
Definition: daemon.h:58
flow_state_t
flow_state_t
Definition: daemon.h:53
flow_error
void flow_error(struct flow *flow, const char *fmt,...)
Definition: daemon.c:119
flow::endpoint
enum endpoint_t endpoint
Definition: daemon.h:78
request::error
char * error
Definition: daemon.h:187
endpoint_t
endpoint_t
Flow endpoint types.
Definition: common.h:96
flow::listenfd_data
int listenfd_data
Definition: daemon.h:81
flow::real_listen_receive_buffer_size
unsigned real_listen_receive_buffer_size
Definition: daemon.h:109
daemon_pipe
int daemon_pipe[2]
Definition: daemon.c:87
request_add_flow_destination::r
struct request r
Definition: daemon.h:195
get_uuid_string
void get_uuid_string(char *uuid_str)
To generate daemon UUID.
Definition: daemon.c:1536
flow::statistics::has_tcp_info
int has_tcp_info
Definition: daemon.h:156
flow::statistics::request_blocks_read
unsigned request_blocks_read
Definition: daemon.h:130
mutex
pthread_mutex_t mutex
Definition: daemon.c:93
flow::addr_len
socklen_t addr_len
Definition: daemon.h:120
fg_list.h
Generic doubly linked list implementation.
flow::fd
int fd
Definition: daemon.h:80
flow::real_listen_send_buffer_size
unsigned real_listen_send_buffer_size
Definition: daemon.h:108
flow::finished
char finished[2]
Definition: daemon.h:112
dump_dir
char * dump_dir
Definition: daemon.c:91
flow::last_block_read
struct timespec last_block_read
Definition: daemon.h:88
flow::congestion_counter
unsigned congestion_counter
Definition: daemon.h:116
pending_reports
unsigned pending_reports
Definition: daemon.c:101
flow::addr
struct sockaddr * addr
Definition: daemon.h:119
flow::write_block
char * write_block
Definition: daemon.h:98
request_add_flow_destination::listen_data_port
int listen_data_port
Definition: daemon.h:201
request::condition
pthread_cond_t * condition
Definition: daemon.h:185
request_get_uuid
structure for getting the UUID.
Definition: daemon.h:240
common.h
Data structures used by the Flowgrind daemon and controller.
flow::last_block_written
struct timespec last_block_written
Definition: daemon.h:89
requests_last
struct request * requests_last
Definition: daemon.h:191
daemon_thread
pthread_t daemon_thread
Definition: daemon.c:89
daemon_main
void * daemon_main(void *ptr)
flow::state
enum flow_state_t state
Definition: daemon.h:77
request_get_uuid::r
struct request r
Daemon thread process the request r.
Definition: daemon.h:242
flow::stop_timestamp
struct timespec stop_timestamp[2]
Definition: daemon.h:87
flow::statistics::bytes_read
unsigned long long bytes_read
Definition: daemon.h:124
flow::start_timestamp
struct timespec start_timestamp[2]
Definition: daemon.h:86
request_add_flow_source::r
struct request r
Definition: daemon.h:208
flow::next_report_time
struct timespec next_report_time
Definition: daemon.h:93
report::type
enum report_t type
Report type - either INTERVAL or FINAL report.
Definition: common.h:291
flow::statistics::request_blocks_written
unsigned request_blocks_written
Definition: daemon.h:131
flow::statistics::iat_max
double iat_max
Maximum interarrival time.
Definition: daemon.h:140
flow::statistics::rtt_min
double rtt_min
Minimum round-trip time.
Definition: daemon.h:150
flow::requested_server_test_port
unsigned short requested_server_test_port
Definition: daemon.h:106
dispatch_request
int dispatch_request(struct request *request, int type)
Dispatch a request to daemon loop.
Definition: daemon.c:1489
flow::first_report_time
struct timespec first_report_time
Definition: daemon.h:91
fg_tcp_info
Definition: common.h:267
linked_list
A doubly linked list.
Definition: fg_list.h:46
config.h
flow::id
int id
Definition: daemon.h:75
TCP_CA_NAME_MAX
#define TCP_CA_NAME_MAX
Max size of the congestion control algorithm specifier string.
Definition: common.h:75
request_add_flow_destination::flow_id
int flow_id
Definition: daemon.h:200
flow::pcap_handle
struct pcap_t * pcap_handle
Definition: daemon.h:162
flow::current_block_bytes_written
unsigned current_block_bytes_written
Definition: daemon.h:104
request_error
void request_error(struct request *request, const char *fmt,...)
Definition: daemon.c:132
flow_source_settings::destination_port
int destination_port
Definition: daemon.h:66
flow::statistics::iat_sum
double iat_sum
Accumulated interarrival time.
Definition: daemon.h:142
flow::pcap_thread
pthread_t pcap_thread
Definition: daemon.h:161
request_get_uuid::server_uuid
char server_uuid[38]
UUID from the daemon.
Definition: daemon.h:244
request_get_status::r
struct request r
Definition: daemon.h:249
reports_last
struct report * reports_last
Definition: daemon.c:100
request_get_status::started
int started
Definition: daemon.h:251
flow_settings
Settings that describe a flow between from a endpoint's perspective.
Definition: common.h:181