 |
Flowgrind
Advanced TCP traffic generator
|
Flowgrindd rpcserver implementation.
More...
#include "config.h"
#include <sys/utsname.h>
#include <syslog.h>
#include "common.h"
#include "daemon.h"
#include "fg_log.h"
#include "fg_error.h"
#include "fg_definitions.h"
#include "debug.h"
#include "fg_rpc_server.h"
Go to the source code of this file.
|
static xmlrpc_value * | add_flow_destination (xmlrpc_env *const env, xmlrpc_value *const param_array, void *const user_data) |
| Prepare data connection for destination endpoint. More...
|
|
static xmlrpc_value * | add_flow_source (xmlrpc_env *const env, xmlrpc_value *const param_array, void *const user_data) |
| Prepare data connection for source endpoint. More...
|
|
static int | bind_rpc_server (char *bind_addr, unsigned port) |
|
void | init_rpc_server (struct fg_rpc_server *server, char *rpc_bind_addr, unsigned port) |
| Initializes the xmlrpc server. More...
|
|
static xmlrpc_value * | method_get_reports (xmlrpc_env *const env, xmlrpc_value *const param_array, void *const user_data) |
| To get the reports from the daemon. More...
|
|
static xmlrpc_value * | method_get_status (xmlrpc_env *const env, xmlrpc_value *const param_array, void *const user_data) |
|
static xmlrpc_value * | method_get_uuid (xmlrpc_env *const env, xmlrpc_value *const param_array, void *const user_data) |
| To get the daemons UUID. More...
|
|
static xmlrpc_value * | method_get_version (xmlrpc_env *const env, xmlrpc_value *const param_array, void *const user_data) |
|
static xmlrpc_value * | method_stop_flow (xmlrpc_env *const env, xmlrpc_value *const param_array, void *const user_data) |
|
void | run_rpc_server (struct fg_rpc_server *server) |
| Enters the xmlrpc server mainloop. More...
|
|
static xmlrpc_value * | start_flows (xmlrpc_env *const env, xmlrpc_value *const param_array, void *const user_data) |
|
Flowgrindd rpcserver implementation.
Definition in file fg_rpc_server.c.
◆ add_flow_destination()
static xmlrpc_value* add_flow_destination |
( |
xmlrpc_env *const |
env, |
|
|
xmlrpc_value *const |
param_array, |
|
|
void *const |
user_data |
|
) |
| |
|
static |
Prepare data connection for destination endpoint.
Flowgrind rpc server decode the information from the controller XML-RPC and construct the request data structure to add flow in the destination daemon. The request is dispatched to destination daemon. The destination daemon execute the request and send back the executed result in the request reply to the flowgrind rpc server. Flowgrind rpc server then encode the request reply information from the daemon and send back the data to the flowgrind controller through XML-RPC connection
- Parameters
-
[in,out] | env | XML-RPC environment object |
[in,out] | param_array | XML-RPC value |
[in,out] | user_data | unused arg return xmlrpc_value XML-RPC value |
Definition at line 277 of file fg_rpc_server.c.
284 xmlrpc_value *ret = 0;
286 char* bind_address = 0;
287 xmlrpc_value* extra_options = 0;
293 DEBUG_MSG(LOG_WARNING,
"method add_flow_destination called");
296 xmlrpc_decompose_value(env, param_array,
300 "{s:d,s:d,s:d,s:d,s:d,*}"
303 "{s:b,s:b,s:b,s:b,s:b,*}"
308 "{s:b,s:b,s:i,s:i,*}"
310 "{s:i,s:i,s:i,s:i,s:i,*}"
316 "bind_address", &bind_address,
366 "extra_socket_options", &extra_options);
368 if (env->fault_occurred)
373 XMLRPC_FAIL(env, XMLRPC_TYPE_ERROR,
"Daemon was asked to dump traffic, but wasn't compiled with libpcap support");
386 XMLRPC_FAIL(env, XMLRPC_TYPE_ERROR,
"Flow settings incorrect");
392 const unsigned char* buffer = 0;
394 xmlrpc_value *option, *level = 0, *optname = 0, *value = 0;
395 xmlrpc_array_read_item(env, extra_options, i, &option);
397 if (!env->fault_occurred)
398 xmlrpc_struct_read_value(env, option,
"level", &level);
399 if (!env->fault_occurred)
400 xmlrpc_struct_read_value(env, option,
"optname", &optname);
401 if (!env->fault_occurred)
402 xmlrpc_struct_read_value(env, option,
"value", &value);
403 if (!env->fault_occurred)
405 if (!env->fault_occurred)
407 if (!env->fault_occurred)
408 xmlrpc_read_base64(env, value, &len, &buffer);
410 xmlrpc_DECREF(level);
412 xmlrpc_DECREF(optname);
414 xmlrpc_DECREF(value);
415 if (!env->fault_occurred) {
417 free((
void *)buffer);
418 XMLRPC_FAIL(env, XMLRPC_TYPE_ERROR,
"Too long extra socket option length");
422 free((
void *)buffer);
424 if (env->fault_occurred)
430 DEBUG_MSG(LOG_WARNING,
"bind_address=%s", bind_address);
436 XMLRPC_FAIL(env, XMLRPC_INTERNAL_ERROR,
request->r.
error);
439 ret = xmlrpc_build_value(env,
"{s:i,s:i,s:i,s:i}",
441 "listen_data_port",
request->listen_data_port,
442 "real_listen_send_buffer_size",
request->real_listen_send_buffer_size,
443 "real_listen_read_buffer_size",
request->real_listen_read_buffer_size);
451 xmlrpc_DECREF(extra_options);
453 if (env->fault_occurred)
454 logging(LOG_WARNING,
"method add_flow_destination failed: %s",
457 DEBUG_MSG(LOG_WARNING,
"method add_flow_destination successful");
◆ add_flow_source()
static xmlrpc_value* add_flow_source |
( |
xmlrpc_env *const |
env, |
|
|
xmlrpc_value *const |
param_array, |
|
|
void *const |
user_data |
|
) |
| |
|
static |
Prepare data connection for source endpoint.
Flowgrind rpc server decode the information from the controller XML-RPC and construct the request data structure to add flow in the source daemon. The request is dispatched to source daemon. The source daemon execute the request and send back the executed result in the request reply to the flowgrind rpc server. Flowgrind rpc server then encode the request reply information from the daemon and send back the data to the flowgrind controller through XML-RPC connection
- Parameters
-
[in,out] | env | XML-RPC environment object |
[in,out] | param_array | XML-RPC value |
[in,out] | user_data | unused arg return xmlrpc_value XML-RPC value |
Definition at line 62 of file fg_rpc_server.c.
69 xmlrpc_value *ret = 0;
70 char* destination_host = 0;
72 char* bind_address = 0;
73 xmlrpc_value* extra_options = 0;
80 DEBUG_MSG(LOG_WARNING,
"method add_flow_source called");
83 xmlrpc_decompose_value(env, param_array,
87 "{s:d,s:d,s:d,s:d,s:d,*}"
90 "{s:b,s:b,s:b,s:b,s:b,*}"
97 "{s:i,s:i,s:i,s:i,s:i,*}"
104 "bind_address", &bind_address,
154 "extra_socket_options", &extra_options,
157 "destination_address", &destination_host,
161 if (env->fault_occurred)
166 XMLRPC_FAIL(env, XMLRPC_TYPE_ERROR,
"Daemon was asked to dump traffic, but wasn't compiled with libpcap support");
183 XMLRPC_FAIL(env, XMLRPC_TYPE_ERROR,
"Flow settings incorrect");
189 const unsigned char* buffer = 0;
191 xmlrpc_value *option, *level = 0, *optname = 0, *value = 0;
192 xmlrpc_array_read_item(env, extra_options, i, &option);
194 if (!env->fault_occurred)
195 xmlrpc_struct_read_value(env, option,
"level", &level);
196 if (!env->fault_occurred)
197 xmlrpc_struct_read_value(env, option,
"optname", &optname);
198 if (!env->fault_occurred)
199 xmlrpc_struct_read_value(env, option,
"value", &value);
200 if (!env->fault_occurred)
202 if (!env->fault_occurred)
204 if (!env->fault_occurred)
205 xmlrpc_read_base64(env, value, &len, &buffer);
207 xmlrpc_DECREF(level);
209 xmlrpc_DECREF(optname);
211 xmlrpc_DECREF(value);
212 if (!env->fault_occurred) {
214 free((
void *)buffer);
215 XMLRPC_FAIL(env, XMLRPC_TYPE_ERROR,
"Too long extra socket option length");
219 free((
void *)buffer);
221 if (env->fault_occurred)
235 XMLRPC_FAIL(env, XMLRPC_INTERNAL_ERROR,
request->r.
error);
238 ret = xmlrpc_build_value(env,
"{s:i,s:s,s:i,s:i}",
241 "real_send_buffer_size",
request->real_send_buffer_size,
242 "real_read_buffer_size",
request->real_read_buffer_size);
250 xmlrpc_DECREF(extra_options);
252 if (env->fault_occurred)
253 logging(LOG_WARNING,
"method add_flow_source failed: %s",
256 DEBUG_MSG(LOG_WARNING,
"method add_flow_source successful");
◆ bind_rpc_server()
static int bind_rpc_server |
( |
char * |
bind_addr, |
|
|
unsigned |
port |
|
) |
| |
|
static |
Definition at line 784 of file fg_rpc_server.c.
788 struct addrinfo hints, *res, *ressave;
791 bzero(&hints,
sizeof(
struct addrinfo));
792 hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV;
793 hints.ai_family = AF_UNSPEC;
794 hints.ai_socktype = SOCK_STREAM;
795 sprintf(tmp_port,
"%u",
port);
797 if ((rc = getaddrinfo(bind_addr, tmp_port,
798 &hints, &res)) != 0) {
799 critx(
"Failed to find address to bind rpc_server: %s\n",
809 fd = socket(res->ai_family, res->ai_socktype,
815 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &optval,
sizeof(optval));
817 setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &optval,
sizeof(optval));
819 if (bind(fd, res->ai_addr, res->ai_addrlen) == 0)
823 }
while ((res = res->ai_next) != NULL);
826 crit(
"failed to bind RPC listen socket");
827 freeaddrinfo(ressave);
◆ init_rpc_server()
void init_rpc_server |
( |
struct fg_rpc_server * |
server, |
|
|
char * |
rpc_bind_addr, |
|
|
unsigned |
port |
|
) |
| |
Initializes the xmlrpc server.
This function initializes the xmlrpc environment, registers exported methods and binds to the control port.
Definition at line 835 of file fg_rpc_server.c.
837 xmlrpc_registry * registryP;
838 xmlrpc_env *env = &(server->
env);
839 memset(&(server->
parms), 0,
sizeof(server->
parms));
841 xmlrpc_env_init(env);
842 registryP = xmlrpc_registry_new(env);
844 xmlrpc_registry_add_method(env, registryP, NULL,
"add_flow_destination", &
add_flow_destination, NULL);
845 xmlrpc_registry_add_method(env, registryP, NULL,
"add_flow_source", &
add_flow_source, NULL);
846 xmlrpc_registry_add_method(env, registryP, NULL,
"start_flows", &
start_flows, NULL);
847 xmlrpc_registry_add_method(env, registryP, NULL,
"get_reports", &
method_get_reports, NULL);
848 xmlrpc_registry_add_method(env, registryP, NULL,
"stop_flow", &
method_stop_flow, NULL);
849 xmlrpc_registry_add_method(env, registryP, NULL,
"get_version", &
method_get_version, NULL);
850 xmlrpc_registry_add_method(env, registryP, NULL,
"get_status", &
method_get_status, NULL);
851 xmlrpc_registry_add_method(env, registryP, NULL,
"get_uuid", &
method_get_uuid, NULL);
857 server->
parms.config_file_name = NULL;
858 server->
parms.registryP = registryP;
859 server->
parms.socket_bound = 1;
860 server->
parms.log_file_name = NULL;
865 server->
parms.keepalive_timeout = 60;
866 server->
parms.keepalive_max_conn = 1000;
869 server->
parms.dont_advertise = 1;
871 logging(LOG_NOTICE,
"running XML-RPC server on port %u",
port);
872 printf(
"Running XML-RPC server...\n");
◆ method_get_reports()
static xmlrpc_value* method_get_reports |
( |
xmlrpc_env *const |
env, |
|
|
xmlrpc_value *const |
param_array, |
|
|
void *const |
user_data |
|
) |
| |
|
static |
To get the reports from the daemon.
Flowgrind rpc server get the reports from the daemon and encode the information and send the report data to the controller through XML-RPC connection
- Parameters
-
[in,out] | env | XML-RPC environment object |
[in,out] | param_array | unused arg |
[in,out] | user_data | unused arg return xmlrpc_value XML-RPC value |
Definition at line 518 of file fg_rpc_server.c.
523 xmlrpc_value *ret = 0, *item = 0;
528 DEBUG_MSG(LOG_NOTICE,
"method get_reports called");
532 ret = xmlrpc_array_new(env);
535 item = xmlrpc_int_new(env, has_more);
536 xmlrpc_array_append_item(env, ret, item);
540 xmlrpc_value *rv = xmlrpc_build_value(env,
542 "{s:i,s:i,s:i,s:i,s:i,s:i,s:i}"
545 "{s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:d,s:d}"
547 "{s:i,s:i,s:i,s:i,s:i}"
548 "{s:i,s:i,s:i,s:i,s:i}"
549 "{s:i,s:i,s:i,s:i,s:i}"
605 xmlrpc_array_append_item(env, ret, rv);
614 if (env->fault_occurred)
615 logging(LOG_WARNING,
"method get_reports failed: %s",
618 DEBUG_MSG(LOG_WARNING,
"method get_reports successful");
◆ method_get_status()
static xmlrpc_value* method_get_status |
( |
xmlrpc_env *const |
env, |
|
|
xmlrpc_value *const |
param_array, |
|
|
void *const |
user_data |
|
) |
| |
|
static |
Definition at line 702 of file fg_rpc_server.c.
710 xmlrpc_value *ret = 0;
713 DEBUG_MSG(LOG_WARNING,
"method get_status called");
719 XMLRPC_FAIL(env, XMLRPC_INTERNAL_ERROR,
request->r.
error);
722 ret = xmlrpc_build_value(env,
"{s:i,s:i}",
724 "num_flows",
request->num_flows);
730 if (env->fault_occurred)
731 logging(LOG_WARNING,
"method get_status failed: %s",
734 DEBUG_MSG(LOG_WARNING,
"method get_status successful");
◆ method_get_uuid()
static xmlrpc_value* method_get_uuid |
( |
xmlrpc_env *const |
env, |
|
|
xmlrpc_value *const |
param_array, |
|
|
void *const |
user_data |
|
) |
| |
|
static |
To get the daemons UUID.
Flowgrind rpc server dispatch the request to get the daemon UUID based on the randomness. After getting these information flowgrind rpc server encode the information and send back the details to the controller through the XML-RPC connection.
- Parameters
-
[in,out] | env | XML-RPC environment object |
| [in.out] | param_array unused arg |
[in,out] | user_data | unused arg return xmlrpc_value XML-RPC value |
Definition at line 752 of file fg_rpc_server.c.
759 DEBUG_MSG(LOG_WARNING,
"Method get_uuid called");
761 xmlrpc_value *ret = 0;
766 XMLRPC_FAIL(env, XMLRPC_INTERNAL_ERROR,
request->r.
error);
769 ret = xmlrpc_build_value(env,
"{s:s}",
"server_uuid",
request->server_uuid);
775 if (env->fault_occurred)
776 logging(LOG_WARNING,
"Method get_uuid failed: %s", env->fault_string);
778 DEBUG_MSG(LOG_WARNING,
"Method get_uuid successful");
◆ method_get_version()
static xmlrpc_value* method_get_version |
( |
xmlrpc_env *const |
env, |
|
|
xmlrpc_value *const |
param_array, |
|
|
void *const |
user_data |
|
) |
| |
|
static |
Definition at line 669 of file fg_rpc_server.c.
677 xmlrpc_value *ret = 0;
679 DEBUG_MSG(LOG_WARNING,
"method get_version called");
682 logging(LOG_WARNING,
"uname() failed %s", strerror(errno));
686 ret = xmlrpc_build_value(env,
"{s:s,s:i,s:s,s:s}",
689 "os_name", buf.sysname,
690 "os_release", buf.release);
692 if (env->fault_occurred)
693 logging(LOG_WARNING,
"method get_version failed: %s",
696 DEBUG_MSG(LOG_WARNING,
"method get_version successful");
◆ method_stop_flow()
static xmlrpc_value* method_stop_flow |
( |
xmlrpc_env *const |
env, |
|
|
xmlrpc_value *const |
param_array, |
|
|
void *const |
user_data |
|
) |
| |
|
static |
Definition at line 623 of file fg_rpc_server.c.
630 xmlrpc_value *ret = 0;
634 DEBUG_MSG(LOG_WARNING,
"method stop_flow called");
637 xmlrpc_decompose_value(env, param_array,
"({s:i,*})",
642 if (env->fault_occurred)
650 XMLRPC_FAIL(env, XMLRPC_INTERNAL_ERROR,
request->r.
error);
653 ret = xmlrpc_build_value(env,
"()");
659 if (env->fault_occurred)
660 logging(LOG_WARNING,
"method stop_flow failed: %s",
663 DEBUG_MSG(LOG_WARNING,
"method stop_flow successful");
◆ run_rpc_server()
Enters the xmlrpc server mainloop.
Definition at line 878 of file fg_rpc_server.c.
880 xmlrpc_env *env = &(server->
env);
881 xmlrpc_server_abyss(env, &(server->
parms), XMLRPC_APSIZE(socket_handle));
883 if (env->fault_occurred)
884 logging(LOG_ALERT,
"XML-RPC Fault: %s (%d)", env->fault_string,
◆ start_flows()
static xmlrpc_value* start_flows |
( |
xmlrpc_env *const |
env, |
|
|
xmlrpc_value *const |
param_array, |
|
|
void *const |
user_data |
|
) |
| |
|
static |
Definition at line 462 of file fg_rpc_server.c.
469 xmlrpc_value *ret = 0;
473 DEBUG_MSG(LOG_WARNING,
"method start_flows called");
476 xmlrpc_decompose_value(env, param_array,
"({s:i,*})",
481 if (env->fault_occurred)
489 XMLRPC_FAIL(env, XMLRPC_INTERNAL_ERROR,
request->r.
error);
492 ret = xmlrpc_build_value(env,
"i", 0);
498 if (env->fault_occurred)
499 logging(LOG_WARNING,
"method start_flows failed: %s",
502 DEBUG_MSG(LOG_WARNING,
"method start_flows successful");
#define DEBUG_MSG(LVL, MSG,...)
Print debug message to standard error.
#define REQUEST_STOP_FLOW
enum distribution_t distribution
The stochastic distribution to draw values from.
#define MAX_EXTRA_SOCKET_OPTIONS
Max number of arbitrary extra socket options which may sent to the deamon.
struct flow_source_settings source_settings
unsigned random_seed
Random seed to use (default: read /dev/urandom) (option -J).
double rtt_max
Maximum round-trip time.
static xmlrpc_value * add_flow_source(xmlrpc_env *const env, xmlrpc_value *const param_array, void *const user_data)
Prepare data connection for source endpoint.
double rtt_sum
Accumulated round-trip time.
#define MAX_EXTRA_SOCKET_OPTION_VALUE_LENGTH
Ensures extra options are limited in length on both controller and deamon.
#define crit(...)
To report an critical error w/ the corresponding system error message.
struct report * get_reports(int *has_more)
int dscp
DSCP value for TOS byte (option -D).
struct flow_settings settings
int requested_read_buffer_size
Request receiver buffer, advertised window in bytes (option -W).
char destination_host[256]
double delay_max
Maximum one-way delay.
unsigned request_blocks_written
void logging(int priority, const char *fmt,...)
unsigned long long bytes_read
struct flow_settings settings
char cc_alg[TCP_CA_NAME_MAX]
static xmlrpc_value * method_get_uuid(xmlrpc_env *const env, xmlrpc_value *const param_array, void *const user_data)
To get the daemons UUID.
double iat_sum
Accumulated inter-arrival time.
struct flow_settings::extra_socket_options extra_socket_options[MAX_EXTRA_SOCKET_OPTIONS]
#define UNUSED_ARGUMENT(x)
Suppress warning for unused argument.
double duration[2]
Duration of flow in seconds (option -T).
int cork
Sets SO_DEBUG on test socket (option -O).
double delay_min
Minimum one-way delay.
double param_two
Second mathematical parameter of the distribution, if required.
int byte_counting
Enumerate bytes in payload instead of sending zeros (option -E).
char cc_alg[TCP_CA_NAME_MAX]
Set congestion control algorithm ALG on test socket (option -O).
struct trafgen_options response_trafgen_options
Stochastic traffic generation settings for the response size.
struct trafgen_options interpacket_gap_trafgen_options
Stochastic traffic generation settings for the interpacket gap.
static char * rpc_bind_addr
int traffic_dump
Dump traffic using libpcap (option -M).
static xmlrpc_value * method_get_status(xmlrpc_env *const env, xmlrpc_value *const param_array, void *const user_data)
int dispatch_request(struct request *request, int type)
Dispatch a request to daemon loop.
int ipmtudiscover
Set IP_MTU_DISCOVER on test socket (option -O).
int maximum_block_size
Application buffer size in bytes (option -U).
int flow_control
Stop flow if it is experiencing local congestion (option -C).
static xmlrpc_value * method_get_version(xmlrpc_env *const env, xmlrpc_value *const param_array, void *const user_data)
int flow_id
Flow ID maintained by controller.
xmlrpc_env env
Environment used by the Abyss server.
double iat_max
Maximum inter-arrival time.
int num_extra_socket_options
int pushy
Do not iterate through select() to continue sending in case block size did not suffice to fill sendin...
#define critx(...)
To report an critical error w/o a system error message.
int nonagle
Disable nagle algorithm on test socket (option -O).
static xmlrpc_value * method_get_reports(xmlrpc_env *const env, xmlrpc_value *const param_array, void *const user_data)
To get the reports from the daemon.
#define MIN_BLOCK_SIZE
Minium block (message) size we can send.
unsigned long long bytes_written
double reporting_interval
Interval to report flow on screen (option -i).
int write_rate
The actual rate we should send.
int elcn
Set TCP_ELCN (20) on test socket (option -O).
static xmlrpc_value * add_flow_destination(xmlrpc_env *const env, xmlrpc_value *const param_array, void *const user_data)
Prepare data connection for destination endpoint.
#define FLOWGRIND_VERSION
Flowgrind version number.
static int bind_rpc_server(char *bind_addr, unsigned port)
unsigned pmtu
Discovered Path MTU.
double delay[2]
Delay of flow in seconds (option -Y).
#define REQUEST_GET_STATUS
int lcd
Set TCP_LCD (21) on test socket (option -O).
#define free_all(...)
To free() an arbitrary number of variables.
double delay_sum
Accumulated one-way delay.
structure for getting the UUID.
unsigned response_blocks_written
enum report_t type
Report type - either INTERVAL or FINAL report.
int shutdown
Shutdown socket after test flow (option -N).
static xmlrpc_value * method_stop_flow(xmlrpc_env *const env, xmlrpc_value *const param_array, void *const user_data)
enum endpoint_t endpoint
Daemon endpoint - either source or destination.
unsigned imtu
Interface MTU.
static xmlrpc_value * start_flows(xmlrpc_env *const env, xmlrpc_value *const param_array, void *const user_data)
#define TCP_CA_NAME_MAX
Max size of the congestion control algorithm specifier string.
struct fg_tcp_info tcp_info
#define REQUEST_START_FLOWS
unsigned request_blocks_read
int mtcp
Set TCP_MTCP (15) on test socket (option -O).
double rtt_min
Minimum round-trip time.
double param_one
First mathemathical parameter of the distribution.
struct trafgen_options request_trafgen_options
Stochastic traffic generation settings for the request size.
char bind_address[1000]
The interface address for the flow (used by daemon).
xmlrpc_server_abyss_parms parms
Parameters of the XMLrpc server.
#define REQUEST_ADD_SOURCE
#define REQUEST_ADD_DESTINATION
int so_debug
Sets SO_DEBUG on test socket (option -O).
#define FLOWGRIND_API_VERSION
XML-RPC API version in integer representation.
double iat_min
Minimum inter-arrival time.
int requested_send_buffer_size
Request sender buffer in bytes (option -B).
unsigned response_blocks_read
int route_record
Sets ROUTE_RECORD on test socket (option -O).
Settings that describe a flow between from a endpoint's perspective.