abw_conf.h 6.49 KB
Newer Older
's avatar
committed
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
/*
 * Copyright (c) 2006, CESNET
 * All rights reserved.
 *
 * LICENSE TERMS
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the company nor the names of its contributors 
 *       may be used to endorse or promote products derived from this 
 *       software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
 * THE COMPANY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $Id$
 *
 */

34
35
36
#ifndef __ABW_CONF_H
#define __ABW_CONF_H

's avatar
committed
37
38
39
#define _GNU_SOURCE
#include <getopt.h>

's avatar
   
committed
40
#define ABW_CONST_CFG "/usr/local/abw/etc/abw_const.cfg"
's avatar
committed
41

42
43
44
45
46
47
48
49
50
51
/* 
 * Leading colon ":" makes getopt() to return colon ":" rather than
 * a question mark "?" when option argument is missing (and it returns
 * "?" for unknown option). In this way we can distinquish between
 * options with optional arguments and unknown options.
 *
 * But getopt() also allows to specify directly an option without argument
 * as not followed by ":" and an option with an optional argument as
 * followed by "::".
 */
52
#define ARGS ":n:d:m:r:w:f:i:l:D::hq"
's avatar
committed
53
54
55

/* Long option codes */
enum {
56
	LO_HOSTNAME, LO_INTERFACE, LO_PORT,
57
58
59
60
61
	LO_LINK_MBPS, LO_MPLS,
	LO_SAU_MODE, LO_SAU_THRESHOLD, LO_PAYLOAD_STRING, LO_INTERVAL,
	LO_PROTOCOLS,
	LO_CONF_FILENAME, LO_NO_MEASURE, LO_NO_STDOUT, LO_STDOUT_SIMPLE,
	LO_DEBUG };
's avatar
committed
62
63
64
65

/* Long option names and argument types */
static const struct option long_options[] = {
	{ "hostname",			required_argument,	0,	LO_HOSTNAME },
's avatar
committed
66
	{ "interface",			required_argument,	0, LO_INTERFACE },
67
	{ "port",				required_argument,	0, LO_PORT },
68
69
	{ "mpls",				no_argument,			0, LO_MPLS },
	{ "link_mbps",			required_argument,	0,	LO_LINK_MBPS },
's avatar
committed
70
71
72
73
	{ "sau_mode",			required_argument,	0,	LO_SAU_MODE },
	{ "sau_threshold",	required_argument, 	0,	LO_SAU_THRESHOLD },
	{ "payload_string",	required_argument,	0,	LO_PAYLOAD_STRING },
	{ "interval",			required_argument,	0,	LO_INTERVAL },
74
	{ "protocols",			required_argument,	0, LO_PROTOCOLS },
's avatar
committed
75
76
77
	{ "conf_filename",	required_argument,	0,	LO_CONF_FILENAME },
	{ "no_measure",		no_argument,			0, LO_NO_MEASURE },
	{ "no_stdout",			no_argument,			0,	LO_NO_STDOUT },
78
	{ "stdout_simple",	no_argument,			0,	LO_STDOUT_SIMPLE },
79
	{ "debug",				optional_argument,	0,	LO_DEBUG },
's avatar
committed
80
81
	{ 0, 0, 0, 0 }
};
82

83
84
85
86
87
88
89
90
91
92
93
94
95
96
#define DEFAULT_HOSTNAME "localhost"
#define DEFAULT_INTERFACE "eth0"
#define DEFAULT_LINK_MBPS 1000
#define DEFAULT_PROTOCOLS "all"

#define MAX_HOSTNAME			128
#define MAX_HEADER_FILTER 	256
#define MAX_PAYLOAD_STRING	 16   /* max. characters of payload string */
#define MAX_PAYLOAD_STRINGS 16   /* max. number of payload strings */
#define MAX_STRING         256	/* max. characters of various strings */
#define MAX_PROTOCOLS_STRING 		256
#define MAX_PROTOCOLS 	 	 32
#define MAX_SUBJECTS			 32
#define MAX_FLOWS			 	128	/* scopes * protocols */
97

98
99
100
101
102
103
typedef enum {
        COMBO6_DETERMINISTIC,
        COMBO6_LENGTH_DETERMINISTIC,
        COMBO6_PROBABILISTIC
} sau_modes_t;

104
105
106
107
typedef struct subject_struct {
  int id;
  char *hostname;
  char *interface;
108
  int port;
109
110
  int mpls;
  int link_mbps;
111
112
113
  char *label;
  char *description;
  int out;
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
149
150
151
152
153
154
155
156
157
158
159
160
161

  struct subject_struct *next;
} subject_t;

typedef struct scope_struct {
  int id;
  char *subject_ids;
  subject_t *subject[MAX_SUBJECTS];

  /* Alternative representation, conversion done in check_conf() */
  char *subject_array[MAX_SUBJECTS];
  int subject_no;

  struct scope_struct *next;
} scope_t;

typedef struct parameters_struct {
  int id;
  char *header_filter;
  char sau_mode;
  double sau_threshold;
  char *payload_strings[MAX_PAYLOAD_STRINGS];
  struct timeval interval;

  /* Alternative representations, conversion done in check_conf() */
  int sau_mode_encoded;
  /* int sau_packet_threshold;
  int sau_byte_threshold;
  float sau_pass_probability; */

  struct parameters_struct *next;
} parameters_t;

typedef struct measurement_struct {
  int id;
  int scope_id;
  int parameters_id;
  scope_t *scope;
  parameters_t *parameters;
  char *protocols;

  /* Alternative representation, conversion done by split_strings() */
  char *protocols_array[MAX_PROTOCOLS];

  struct measurement_struct *next;
} measurement_t;

typedef struct global_struct {
's avatar
committed
162
  char *hostname;				/* local hostname including domain name */
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
  char *conf_filename;		/* read configuration from this file */
  int no_measure;				/* if non-zero do not do measurements 
                              (only process configuration) */
  int no_stdout;				/* if non-zero do not print results to stdout */
  int stdout_simple;			/* if non-zero print results as numbers only */

} global_t;

typedef struct configuration_struct {
	subject_t *subject;
	scope_t *scope;
	parameters_t *parameters;
	measurement_t *measurement;
	global_t *global;
} configuration_t;

subject_t *new_subject(void);

scope_t *new_scope(void);

parameters_t *new_parameters(void);

measurement_t *new_measurement(void);

187
188
void usage();

189
int read_command_line(int argc, char *argv[], configuration_t *configuration);
190

191
int read_conf_file(configuration_t *configuration);
192

193
int read_const_conf_file(configuration_t *configuration);
's avatar
committed
194

195
/* int read_password(configuration_t *configuration); */
's avatar
committed
196

197
int check_conf(configuration_t *configuration);
198

199
int print_conf(configuration_t *configuration);
200

201
202
int read_header_filter(int argc, char *argv[], char **p);

203
204
205
int split_strings(char *input_string, int max_strings, char *string_array[]);

int concat_strings(char **output_string, int max_strings, char *string_array[]);
206

207
208
int compstr(const void *str1, const void *str2);

209
#endif