Flowgrind
Advanced TCP traffic generator
trafgen.c File Reference

Routines used by the Flowgrind Daemon for advanced traffic generation. More...

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include <errno.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <syslog.h>
#include "daemon.h"
#include "debug.h"
#include "fg_math.h"
#include "trafgen.h"

Go to the source code of this file.

Macros

#define MAX_RUNS_PER_DISTRIBUTION   10
 

Functions

static double calculate (struct flow *flow, enum distribution_t type, double param_one, double param_two)
 
double next_interpacket_gap (struct flow *flow)
 
int next_request_block_size (struct flow *flow)
 
int next_response_block_size (struct flow *flow)
 

Detailed Description

Routines used by the Flowgrind Daemon for advanced traffic generation.

Definition in file trafgen.c.

Macro Definition Documentation

◆ MAX_RUNS_PER_DISTRIBUTION

#define MAX_RUNS_PER_DISTRIBUTION   10

Definition at line 48 of file trafgen.c.

Function Documentation

◆ calculate()

static double calculate ( struct flow flow,
enum distribution_t  type,
double  param_one,
double  param_two 
)
inlinestatic

Definition at line 50 of file trafgen.c.

50  {
51 
52  double val = 0;
53 
54  switch (type) {
55  case NORMAL:
56  val = dist_normal (flow, param_one, param_two );
57  DEBUG_MSG(LOG_DEBUG, "calculated normal distribution "
58  "value %f for parameters %f,%f", val,
59  param_one, param_two);
60  break;
61 
62  case UNIFORM:
63  val = dist_uniform (flow, param_one, param_two );
64  DEBUG_MSG(LOG_DEBUG, "calculated uniform distribution "
65  "value %f", val);
66  break;
67 
68  case WEIBULL:
69  val = dist_weibull (flow, param_one, param_two );
70  DEBUG_MSG(LOG_DEBUG, "calculated weibull distribution "
71  "value %f for parameters %f,%f", val,
72  param_one, param_two);
73  break;
74 
75  case EXPONENTIAL:
76  val = dist_exponential (flow, param_one);
77  DEBUG_MSG(LOG_DEBUG, "calculated exponential "
78  "distribution value %f for parameters %f",
79  val, param_one);
80  break;
81 
82  case PARETO:
83  val = dist_pareto (flow, param_one, param_two);
84  DEBUG_MSG(LOG_DEBUG, "calculated pareto distribution "
85  "value %f for parameters %f,%f", val,
86  param_one, param_two);
87  break;
88 
89  case LOGNORMAL:
90  val = dist_normal (flow, param_one, param_two );
91  DEBUG_MSG(LOG_DEBUG, "calculated lognormal "
92  "distribution value %f for parameters %f,%f",
93  val, param_one, param_two);
94  break;
95 
96  case CONSTANT:
97  /* constant is default */
98  default:
99  val = param_one;
100  DEBUG_MSG(LOG_DEBUG, "constant value %f", val);
101 
102  }
103 
104  return val;
105 
106 }

◆ next_interpacket_gap()

double next_interpacket_gap ( struct flow flow)

Definition at line 173 of file trafgen.c.

173  {
174 
175  double gap = 0.0;
176  if (flow->settings.write_rate)
178  else
179  gap = calculate(flow,
183  );
184 
185  if (gap)
186  DEBUG_MSG(LOG_NOTICE, "calculated next interpacket gap %.6fs "
187  "for flow %d", gap, flow->id);
188 
189  return gap;
190 }

◆ next_request_block_size()

int next_request_block_size ( struct flow flow)

Definition at line 107 of file trafgen.c.

108 {
109  int bs = 0;
110  int i = 0;
111  /* recalculate values to match prequisits, but at most 10 times */
112  while (( bs < MIN_BLOCK_SIZE || bs > flow->settings.maximum_block_size) && i < MAX_RUNS_PER_DISTRIBUTION) {
113 
114  bs = round(calculate(
115  flow,
119  ));
120  i++;
121  }
122 
123  /* sanity checks */
124  if (i >= MAX_RUNS_PER_DISTRIBUTION && bs < MIN_BLOCK_SIZE) {
125  bs = MIN_BLOCK_SIZE;
126  DEBUG_MSG(LOG_WARNING, "applied minimal request size limit %d "
127  "for flow %d", bs, flow->id);
128  }
129 
132  DEBUG_MSG(LOG_WARNING, "applied maximal request size limit %d "
133  "for flow %d", bs, flow->id);
134 
135  }
136 
137  DEBUG_MSG(LOG_NOTICE, "calculated request size %d for flow %d after %d "
138  "runs", bs, flow->id, i);
139 
140  return bs;
141 }

◆ next_response_block_size()

int next_response_block_size ( struct flow flow)

Definition at line 143 of file trafgen.c.

144 {
145  int bs = round(calculate(
146  flow,
150  ));
151 
152  /* sanity checks */
153  if (bs && bs < MIN_BLOCK_SIZE) {
154  bs = MIN_BLOCK_SIZE;
155  DEBUG_MSG(LOG_WARNING, "applied minimal response size limit "
156  "%d for flow %d", bs, flow->id);
157  }
158  if (bs > flow->settings.maximum_block_size) {
160  DEBUG_MSG(LOG_WARNING, "applied maximal response size limit "
161  "%d for flow %d", bs, flow->id);
162 
163  }
164 
165  if (bs)
166  DEBUG_MSG(LOG_NOTICE, "calculated response size %d for flow "
167  "%d", bs, flow->id);
168 
169  return bs;
170 
171 }
UNIFORM
@ UNIFORM
Uniform distribution.
Definition: common.h:138
DEBUG_MSG
#define DEBUG_MSG(LVL, MSG,...)
Print debug message to standard error.
Definition: debug.h:49
trafgen_options::distribution
enum distribution_t distribution
The stochastic distribution to draw values from.
Definition: common.h:168
flow
Definition: daemon.h:73
dist_normal
double dist_normal(struct flow *flow, const double mu, const double sigma_square)
Definition: fg_math.c:149
PARETO
@ PARETO
Pareto distribution.
Definition: common.h:142
trafgen_options::param_two
double param_two
Second mathematical parameter of the distribution, if required.
Definition: common.h:172
flow_settings::response_trafgen_options
struct trafgen_options response_trafgen_options
Stochastic traffic generation settings for the response size.
Definition: common.h:251
flow::settings
struct flow_settings settings
Definition: daemon.h:83
dist_weibull
double dist_weibull(struct flow *flow, const double alpha, const double beta)
Definition: fg_math.c:206
flow_settings::interpacket_gap_trafgen_options
struct trafgen_options interpacket_gap_trafgen_options
Stochastic traffic generation settings for the interpacket gap.
Definition: common.h:253
dist_uniform
double dist_uniform(struct flow *flow, const double minval, const double maxval)
Definition: fg_math.c:136
MAX_RUNS_PER_DISTRIBUTION
#define MAX_RUNS_PER_DISTRIBUTION
Definition: trafgen.c:48
flow_settings::maximum_block_size
int maximum_block_size
Application buffer size in bytes (option -U).
Definition: common.h:201
LOGNORMAL
@ LOGNORMAL
Log Normal distribution.
Definition: common.h:144
CONSTANT
@ CONSTANT
No stochastic distribution.
Definition: common.h:132
WEIBULL
@ WEIBULL
Weibull distribution.
Definition: common.h:136
MIN_BLOCK_SIZE
#define MIN_BLOCK_SIZE
Minium block (message) size we can send.
Definition: common.h:79
flow_settings::write_rate
int write_rate
The actual rate we should send.
Definition: common.h:220
EXPONENTIAL
@ EXPONENTIAL
Exponential distribution.
Definition: common.h:140
dist_exponential
double dist_exponential(struct flow *flow, const double mu)
Definition: fg_math.c:123
dist_pareto
double dist_pareto(struct flow *flow, const double k, const double x_min)
Definition: fg_math.c:190
flow::id
int id
Definition: daemon.h:75
calculate
static double calculate(struct flow *flow, enum distribution_t type, double param_one, double param_two)
Definition: trafgen.c:50
trafgen_options::param_one
double param_one
First mathemathical parameter of the distribution.
Definition: common.h:170
NORMAL
@ NORMAL
Normal distribution.
Definition: common.h:134
flow_settings::request_trafgen_options
struct trafgen_options request_trafgen_options
Stochastic traffic generation settings for the request size.
Definition: common.h:249