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 
77  enum flow_state_t state;
78  enum endpoint_t endpoint;
79 
80  int fd;
82 
83  struct flow_settings settings;
84  struct flow_source_settings source_settings;
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 
157  struct fg_tcp_info tcp_info;
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 
197  struct flow_settings settings;
198 
199  /* The request reply */
200  int flow_id;
204 };
205 
207 {
208  struct request r;
209 
210  struct flow_settings settings;
211  struct flow_source_settings source_settings;
212 
213  /* The request reply */
214  int flow_id;
215  char cc_alg[TCP_CA_NAME_MAX];
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 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 /* FIXME: shouldn't be global? */
273 char *dump_dir;
274 
275 void *daemon_main(void* ptr);
276 void add_report(struct report* report);
277 void flow_error(struct flow *flow, const char *fmt, ...);
278 void request_error(struct request *request, const char *fmt, ...);
279 int set_flow_tcp_options(struct flow *flow);
280 
283  int dispatch_request(struct request *request, int type);
284 
295  void get_uuid_string(char *uuid_str);
296 #endif /* _DAEMON_H_ */
int has_tcp_info
Definition: daemon.h:156
double delay_sum
Accumulated one-way delay.
Definition: daemon.h:148
structure for getting the UUID.
Definition: daemon.h:240
unsigned request_blocks_read
Definition: daemon.h:130
int pmtu
Definition: daemon.h:114
unsigned current_read_block_size
Definition: daemon.h:101
char * dump_prefix
Definition: daemon.h:272
struct pcap_dumper_t * pcap_dumper
Definition: daemon.h:163
struct request * requests
Definition: daemon.c:90
char connect_called
Definition: daemon.h:111
unsigned request_blocks_written
Definition: daemon.h:131
#define TCP_CA_NAME_MAX
Max size of the congestion control algorithm specifier string.
Definition: common.h:75
char destination_host[256]
Definition: daemon.h:65
int set_flow_tcp_options(struct flow *flow)
Definition: daemon.c:1420
void get_uuid_string(char *uuid_str)
To generate daemon UUID.
Definition: daemon.c:1532
struct report * reports_last
Definition: daemon.c:96
gsl_rng * r
Definition: daemon.h:167
Definition: common.h:286
struct request * next
Definition: daemon.h:189
pthread_t daemon_thread
Definition: daemon.h:255
struct linked_list flows
Definition: daemon.c:99
char type
Definition: daemon.h:181
unsigned current_block_bytes_read
Definition: daemon.h:103
char * read_block
Definition: daemon.h:97
struct report * get_reports(int *has_more)
Definition: daemon.c:849
double iat_min
Minimum interarrival time.
Definition: daemon.h:138
Definition: daemon.h:60
char * error
Definition: daemon.h:187
endpoint_t
Flow endpoint types.
Definition: common.h:96
unsigned congestion_counter
Definition: daemon.h:116
char * write_block
Definition: daemon.h:98
unsigned current_write_block_size
Definition: daemon.h:100
double iat_sum
Accumulated interarrival time.
Definition: daemon.h:142
char * error
Definition: daemon.h:170
double rtt_min
Minimum round-trip time.
Definition: daemon.h:150
unsigned response_blocks_read
Definition: daemon.h:132
pthread_mutex_t mutex
Definition: daemon.c:89
int listenfd_data
Definition: daemon.h:81
unsigned real_listen_receive_buffer_size
Definition: daemon.h:109
flow_state_t
Definition: daemon.h:53
char * dump_dir
Definition: daemon.h:273
enum report_t type
Report type - either INTERVAL or FINAL report.
Definition: common.h:291
struct sockaddr * addr
Definition: daemon.h:119
void request_error(struct request *request, const char *fmt,...)
Definition: daemon.c:128
double delay_max
Maximum one-way delay.
Definition: daemon.h:146
unsigned short requested_server_test_port
Definition: daemon.h:106
unsigned response_blocks_written
Definition: daemon.h:133
int dispatch_request(struct request *request, int type)
Dispatch a request to daemon loop.
Definition: daemon.c:1485
int daemon_pipe[2]
Definition: daemon.c:87
unsigned real_listen_send_buffer_size
Definition: daemon.h:108
pthread_cond_t * condition
Definition: daemon.h:185
char started
Definition: daemon.c:101
unsigned long long bytes_written
Definition: daemon.h:125
double iat_max
Maximum interarrival time.
Definition: daemon.h:140
socklen_t addr_len
Definition: daemon.h:120
int fd
Definition: daemon.h:80
struct report * reports
Definition: daemon.c:95
Data structures used by the Flowgrind daemon and controller.
unsigned pending_reports
Definition: daemon.c:97
double rtt_sum
Accumulated round-trip time.
Definition: daemon.h:154
void flow_error(struct flow *flow, const char *fmt,...)
Definition: daemon.c:115
pthread_t pcap_thread
Definition: daemon.h:161
pthread_cond_t * add_source_condition
Definition: daemon.h:70
Generic doubly linked list implementation.
double delay_min
Minimum one-way delay.
Definition: daemon.h:144
Definition: daemon.h:73
A doubly linked list.
Definition: fg_list.h:46
void add_report(struct report *report)
Definition: daemon.c:823
unsigned current_block_bytes_written
Definition: daemon.h:104
int id
Definition: daemon.h:75
double rtt_max
Maximum round-trip time.
Definition: daemon.h:152
Settings that describe a flow between from a endpoint&#39;s perspective.
Definition: common.h:181
unsigned long long bytes_read
Definition: daemon.h:124
struct request * requests_last
Definition: daemon.c:90
struct pcap_t * pcap_handle
Definition: daemon.h:162
void * daemon_main(void *ptr)