Commit e69ac16a authored by 's avatar
Browse files

Configuration file with multiple flow specifications is now processed


git-svn-id: file:///home/svn/mapi/trunk@338 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent f77736e8
......@@ -9,8 +9,9 @@ LIB_DIRS=
RLIB_DIRS=
INCLUDE_DIRS=
TARGETS=abw abw_dummy test_abw_time
OBJS=abw.o abw_mysql.o abw_time.o abw_dummy.o test_abw_time.o
TARGETS=abw abw_dummy test_abw_time test_config
OBJS=abw.o abw_mysql.o abw_time.o abw_dummy.o test_abw_time.o test_config.o \
abw_conf.o
all: $(TARGETS)
......@@ -21,8 +22,8 @@ all: $(TARGETS)
# $(AR) rv $@ $(LIBSCAMPI_OBJS)
# $(RANLIB) $@
abw: abw.o abw_mysql.o abw_time.o
$(LD) -o $@ abw.o abw_mysql.o abw_time.o $(LIB_DIRS) $(LIBS) -Wl,-rpath,$(RLIB_DIRS)
abw: abw.o abw_mysql.o abw_time.o abw_conf.o
$(LD) -o $@ abw.o abw_mysql.o abw_time.o abw_conf.o $(LIB_DIRS) $(LIBS) -Wl,-rpath,$(RLIB_DIRS)
abw_dummy: abw_dummy.o
$(LD) -o $@ abw_dummy.o $(LIB_DIRS) $(LIBS) -Wl,-rpath,$(RLIB_DIRS)
......@@ -30,6 +31,9 @@ abw_dummy: abw_dummy.o
test_abw_time: test_abw_time.o abw_time.o
$(LD) -o $@ test_abw_time.o abw_time.o $(LIB_DIRS) $(LIBS) -Wl,-rpath,$(RLIB_DIRS)
test_config: test_config.o ../../parseconf.o
$(LD) -o $@ test_config.o ../../parseconf.o
clean:
rm -f *.o *.a $(TARGETS)
rm -f *.out core
......@@ -14,6 +14,7 @@
#include "abw.h"
#include "abw_mysql.h"
#include "abw_time.h"
#include "abw_conf.h"
flow_spec_t *flow_spec[MAX_FLOWS];
global_spec_t global_spec;
......@@ -33,8 +34,9 @@ void usage() {
fprintf(stderr, " number of packets for d mode (default 1)\n");
fprintf(stderr, " number of bytes for b mode (default 3000)\n");
fprintf(stderr, " pass probability for p mode (default 0.5)\n");
fprintf(stderr, " -p string string to be searched in payload, multiple -p argument\n");
fprintf(stderr, " -p string string to be searched in payload, multiple -p arguments\n");
fprintf(stderr, " can be specified, packet passes when at least one match\n");
fprintf(stderr, " -c characteristics comma-separated list of characteristics (default all)\n");
fprintf(stderr, " -f filename file to read multi-flow specification (e.g., abw.cfg)\n");
fprintf(stderr, " -i interval seconds between measurements (default 1)\n");
fprintf(stderr, " -s DD.MM.YYYY-HH:MM:SS start time (default %s)\n", DEFAULT_START_TIME_STRING);
......@@ -63,6 +65,7 @@ flow_spec_t *new_flow_spec(void) {
p->sau_byte_threshold=3000;
p->sau_pass_probability=0.5;
p->payload_strings_no=0;
p->characteristics=NULL;
p->interval.tv_sec=1;
p->interval.tv_usec=0;
p->start_time_string=DEFAULT_START_TIME_STRING;
......@@ -85,141 +88,6 @@ flow_run_t *new_flow_run(void) {
return p;
} /* new_flow_run() */
int read_conf_file(char *filename, flow_spec_t **flow_spec)
{
return 0;
} /* read_conf_file() */
int check_conf(flow_spec_t **flow_spec) {
flow_spec_t **pp;
flow_spec_t *p;
int i;
if (flow_spec==NULL)
return 0;
pp=flow_spec;
p=*pp; i=0;
while (p) {
if (p->sau_mode!='d' && p->sau_mode!='b' && p->sau_mode!='p') {
fprintf(stderr, "%s: flow[%d]: sampling mode must be d, b or p\n",
__func__, i);
return -1;
}
if (p->sau_mode=='p') {
if (p->sau_pass_probability<0 || p->sau_pass_probability>1) {
fprintf(stderr, "%s: flow[%d]: probability must be between 0 and 1\n", __func__, i);
return -1;
}
p->sau_threshold=0xFFFFFFFF * (1 - p->sau_pass_probability);
p->sau_mode_encoded=COMBO6_PROBABILISTIC;
}
else if (p->sau_mode=='b') {
if (p->sau_byte_threshold<0) {
fprintf(stderr, "%s: flow[%d]: byte threshold cannot be negative\n",
__func__, i);
return -1;
}
p->sau_threshold=p->sau_byte_threshold;
p->sau_mode_encoded=COMBO6_LENGTH_DETERMINISTIC;
}
else {
if (p->sau_packet_threshold<0) {
fprintf(stderr, "%s: flow[%d]: packet threshold cannot be negative\n", __func__, i);
return -1;
}
p->sau_threshold=p->sau_packet_threshold;
p->sau_mode_encoded=COMBO6_DETERMINISTIC;
}
if (strptime(p->start_time_string, "%d.%m.%Y-%H:%M:%S",
&(p->start_time_tm))==NULL) {
fprintf(stderr, "%s: flow[%d]: cannot parse start time %s\n",
__func__, i, p->start_time_string);
return -1;
}
if ((p->start_time_timestamp=mktime(&p->start_time_tm))<0) {
fprintf(stderr, "%s: flow[%d]: cannot convert start time %s to timestamp\n",
__func__, i, p->start_time_string);
return -1;
}
if (strptime(p->end_time_string, "%d.%m.%Y-%H:%M:%S",
&(p->end_time_tm))==NULL) {
fprintf(stderr, "%s: flow[%d]: cannot parse end time %s\n",
__func__, i, p->end_time_string);
return -1;
}
if ((p->end_time_timestamp=mktime(&p->end_time_tm))<0) {
fprintf(stderr, "%s: flow[%d]: cannot convert end time %s to timestamp\n",
__func__, i, p->end_time_string);
return -1;
}
/* TODO: remove these limits */
if (p->sau_mode=='b') {
fprintf(stderr, "%s: byte probabilistic sampling is not supported\n",
__func__);
return -1;
}
if (p->payload_strings[1]) {
fprintf(stderr, "%s: payload searching for multiple strings is not supported\n", __func__);
return -1;
}
pp++; p=*pp; i++;
} /* while (p) */
return 0;
} /* check_conf() */
void print_conf(flow_spec_t **flow_spec) {
flow_spec_t **pp;
flow_spec_t *p;
char **rr;
char *r;
int i, j;
if (flow_spec==NULL)
return;
pp=flow_spec;
p=*pp; i=0;
while (p) {
printf("flow[%d]:\n", i);
printf("header_filter: %s\n", p->header_filter);
printf("device: %s\n", p->device);
printf("sau_mode: %c, sau_threshold: %u\n", p->sau_mode, p->sau_threshold);
rr=p->payload_strings;
r=*rr; j=0;
if (r) {
printf("payload_strings:");
while (r) {
if (j>0)
printf(",");
printf(" |%s|", r);
rr++; r=*rr; j++;
}
printf("\n");
}
printf("interval.tv_sec: %d, interval.tv_usec: %d\n",
(int)(p->interval.tv_sec), (int)(p->interval.tv_usec));
printf("start_time_string: %s, start_time_timestamp: %u\n",
p->start_time_string, (unsigned int)(p->start_time_timestamp));
printf("end_time_string: %s, end_time_timestamp: %u\n",
p->end_time_string, (unsigned int)(p->end_time_timestamp));
printf("link_mbps: %d\n", p->link_mbps);
pp++; p=*pp; i++;
}
} /* print_conf() */
int main(int argc, char *argv[])
{
int i;
......@@ -319,6 +187,14 @@ int main(int argc, char *argv[])
optarg);
flow_spec[0]->payload_strings_no++;
break;
case 'c':
direct_flow=1;
if ((flow_spec[0]->characteristics=malloc(strlen(optarg)+1))==NULL) {
fprintf(stderr, "%s: malloc() failed\n", __func__);
return -1;
}
strcpy(flow_spec[0]->characteristics, optarg);
break;
case 'i':
{ double interval;
direct_flow=1;
......
# Example of name/value pairs in empty category
name1=value1
name2=value2
# Named categories follow
[node]
id=1
hostname=jra1-1.cesnet.cz
device=/dev/dag0
[node]
id=2
hostname=jra1-1.cesnet.cz
device=eth0
[parameters]
id=1
node_ids=1
header_filter=ip src net 195.113.0.0/16 and ip dst 0.0.0.0/0
sampling_type=deterministic
sampling_threshold=1
# payload_filter=virus
node_id=1
header_filter=src net 195.113.0.0/16
sau_mode=d
sau_threshold=1
# payload_string=virus
characteristics=all,tcp,udp,ipv6,multicast
interval=0.1
start=01.01.2005-00:00:00
end=31.12.2099-23:59:59
interval_sec=1
#interval_usec=100000
start_time_string=01.01.2005-00:00:00
end_time_string=31.12.2037-23:59:59
[parameters]
id=2
node_id=2
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define __USE_XOPEN
#include <time.h>
#include "../../parseconf.h"
#include "abw.h"
#include "abw_conf.h"
extern conf_category_t *conf;
int read_conf_file(char *filename, flow_spec_t **flow_spec)
{
conf_category_t *cat, *node, *searched_node;
conf_parameter_t *param, *param2;
flow_spec_t *p, **pp;
int i;
int node_id;
if (filename==NULL || flow_spec==NULL) {
fprintf(stderr, "%s: some of the required arguments were not specified\n",
__func__);
return -1;
}
if (pc_load(filename)!=1) {
fprintf(stderr, "%s: pc_load() did not load file %s\n", __func__,
filename);
return -1;
}
cat=conf;
pp=flow_spec;
p=*pp; i=0;
while (cat) {
if (!strcmp(cat->category, "parameters")) {
if (i>=MAX_FLOWS) {
fprintf(stderr, "%s: maximum number of %d flows exceeded\n",
__func__, MAX_FLOWS);
return -1;
}
if (p==NULL) {
if ((*pp=new_flow_spec())==NULL) {
fprintf(stderr, "%s: malloc() failed\n", __func__);
return -1;
}
p=*pp;
}
node_id=-1;
param=cat->params;
while (param) {
if (!strcmp(param->name, "node_id"))
node_id=atoi(param->value);
else if (!strcmp(param->name, "header_filter")) {
if (strlen(param->value)>=MAX_HEADER_FILTER) {
fprintf(stderr, "%s: header filter string must not be longer than %d characters\n", __func__, MAX_HEADER_FILTER);
return -1;
}
strcpy(p->header_filter, param->value);
}
else if (!strcmp(param->name, "sau_mode"))
p->sau_mode=param->value[0];
else if (!strcmp(param->name, "sau_threshold"))
p->sau_threshold=atoi(param->value);
else if (!strcmp(param->name, "payload_filter")) {
if (p->payload_strings_no >= MAX_PAYLOAD_STRINGS) {
fprintf(stderr, "%s: max. %d strings can be searched in payload\n", __func__, MAX_PAYLOAD_STRINGS);
return -1;
}
if (strlen(param->value) > MAX_PAYLOAD_STRING) {
fprintf(stderr, "%s: max. %d characters long strings can be searched in payload\n", __func__, MAX_PAYLOAD_STRING);
return -1;
}
if ((p->payload_strings[p->payload_strings_no]=
malloc(strlen(param->value)+1))==NULL) {
fprintf(stderr, "%s: malloc() failed\n", __func__);
return -1;
}
strcpy(p->payload_strings[p->payload_strings_no], param->value);
p->payload_strings_no++;
}
else if (!strcmp(param->name, "characteristics")) {
if (p->characteristics) {
fprintf(stderr, "%s: only one characteristics string can be specified\n", __func__);
return -1;
}
if (strlen(param->value) > MAX_CHARACTERISTICS_STRING) {
fprintf(stderr, "%s: max. %d characters long characteristics string can be specified\n", __func__, MAX_CHARACTERISTICS_STRING);
return -1;
}
if ((p->characteristics=malloc(strlen(param->value)+1))==NULL) {
fprintf(stderr, "%s: malloc() failed\n", __func__);
return -1;
}
strcpy(p->characteristics, param->value);
}
else if (!strcmp(param->name, "interval_sec"))
p->interval.tv_sec=atoi(param->value);
else if (!strcmp(param->name, "interval_usec"))
p->interval.tv_usec=atoi(param->value);
else if (!strcmp(param->name, "start_time_string")) {
if (strlen(param->value) > MAX_TIME_STRING) {
fprintf(stderr, "%s: max. %d characters long start_time string can be specified\n", __func__, MAX_TIME_STRING);
return -1;
}
if ((p->start_time_string=malloc(strlen(param->value)+1))==NULL) {
fprintf(stderr, "%s: malloc() failed\n", __func__);
return -1;
}
strcpy(p->start_time_string, param->value);
}
else if (!strcmp(param->name, "end_time_string")) {
if (strlen(param->value) > MAX_TIME_STRING) {
fprintf(stderr, "%s: max. %d characters long end_time string can be specified\n", __func__, MAX_TIME_STRING);
return -1;
}
if ((p->end_time_string=malloc(strlen(param->value)+1))==NULL) {
fprintf(stderr, "%s: malloc() failed\n", __func__);
return -1;
}
strcpy(p->end_time_string, param->value);
}
else if (!strcmp(param->name, "link_mbps"))
p->link_mbps=atoi(param->value);
param=param->next;
}
if (node_id<0) {
fprintf(stderr, "%s: missing node_id\n", __func__);
return -1;
}
node=conf;
searched_node=NULL;
while (node) {
if (!strcmp(node->category, "node")) {
param2=node->params;
while (param2) {
if (!strcmp(param2->name, "id")) {
if (node_id==atoi(param2->value)) {
searched_node=node;
break;
}
}
param2=param2->next;
}
if (searched_node) {
param2=searched_node->params;
while (param2) {
if (!strcmp(param2->name, "device")) {
if ((p->device=malloc(strlen(param2->value)+1))==NULL) {
fprintf(stderr, "%s: malloc() failed\n", __func__);
return -1;
}
strcpy(p->device, param2->value);
break;
}
param2=param2->next;
}
break;
}
}
node=node->next;
}
if (p->device==NULL) {
fprintf(stderr, "%s: device not specified\n", __func__);
return -1;
}
pp++; p=*pp; i++;
} /* if (!strcmp(cat->category, "parameters")) */
cat=cat->next;
} /* while (cat) */
return 0;
} /* read_conf_file() */
int check_conf(flow_spec_t **flow_spec) {
flow_spec_t **pp;
flow_spec_t *p;
int i;
if (flow_spec==NULL)
return 0;
pp=flow_spec;
p=*pp; i=0;
while (p) {
if (p->sau_mode!='d' && p->sau_mode!='b' && p->sau_mode!='p') {
fprintf(stderr, "%s: flow[%d]: sampling mode must be d, b or p\n",
__func__, i);
return -1;
}
if (p->sau_mode=='p') {
if (p->sau_pass_probability<0 || p->sau_pass_probability>1) {
fprintf(stderr, "%s: flow[%d]: probability must be between 0 and 1\n", __func__, i);
return -1;
}
p->sau_threshold=0xFFFFFFFF * (1 - p->sau_pass_probability);
p->sau_mode_encoded=COMBO6_PROBABILISTIC;
}
else if (p->sau_mode=='b') {
if (p->sau_byte_threshold<0) {
fprintf(stderr, "%s: flow[%d]: byte threshold cannot be negative\n",
__func__, i);
return -1;
}
p->sau_threshold=p->sau_byte_threshold;
p->sau_mode_encoded=COMBO6_LENGTH_DETERMINISTIC;
}
else {
if (p->sau_packet_threshold<0) {
fprintf(stderr, "%s: flow[%d]: packet threshold cannot be negative\n", __func__, i);
return -1;
}
p->sau_threshold=p->sau_packet_threshold;
p->sau_mode_encoded=COMBO6_DETERMINISTIC;
}
if (strptime(p->start_time_string, "%d.%m.%Y-%H:%M:%S",
&(p->start_time_tm))==NULL) {
fprintf(stderr, "%s: flow[%d]: cannot parse start time %s\n",
__func__, i, p->start_time_string);
return -1;
}
if ((p->start_time_timestamp=mktime(&p->start_time_tm))<0) {
fprintf(stderr, "%s: flow[%d]: cannot convert start time %s to timestamp\n",
__func__, i, p->start_time_string);
return -1;
}
if (strptime(p->end_time_string, "%d.%m.%Y-%H:%M:%S",
&(p->end_time_tm))==NULL) {
fprintf(stderr, "%s: flow[%d]: cannot parse end time %s\n",
__func__, i, p->end_time_string);
return -1;
}
if ((p->end_time_timestamp=mktime(&p->end_time_tm))<0) {
fprintf(stderr, "%s: flow[%d]: cannot convert end time %s to timestamp\n",
__func__, i, p->end_time_string);
return -1;
}
/* TODO: remove these limits */
if (p->sau_mode=='b') {
fprintf(stderr, "%s: byte probabilistic sampling is not supported in this version\n",
__func__);
return -1;
}
if (p->payload_strings[1]) {
fprintf(stderr, "%s: payload searching for multiple strings is not supported in this version\n", __func__);
return -1;
}
pp++; p=*pp; i++;
} /* while (p) */
return 0;
} /* check_conf() */
void print_conf(flow_spec_t **flow_spec) {
flow_spec_t **pp;
flow_spec_t *p;
char **rr;
char *r;
int i, j;
if (flow_spec==NULL)
return;
pp=flow_spec;
p=*pp; i=0;
while (p) {
printf("flow[%d]:\n", i);
printf("header_filter: %s\n", p->header_filter);
printf("device: %s\n", p->device);
printf("sau_mode: %c, sau_threshold: %u\n", p->sau_mode, p->sau_threshold);
rr=p->payload_strings;
r=*rr; j=0;
if (r) {
printf("payload_strings:");
while (r) {
if (j>0)
printf(",");
printf(" |%s|", r);
rr++; r=*rr; j++;
}
printf("\n");
}
if (p->characteristics)
printf("characteristics: %s\n", p->characteristics);
printf("interval.tv_sec: %d, interval.tv_usec: %d\n",
(int)(p->interval.tv_sec), (int)(p->interval.tv_usec));
printf("start_time_string: %s, start_time_timestamp: %u\n",
p->start_time_string, (unsigned int)(p->start_time_timestamp));
printf("end_time_string: %s, end_time_timestamp: %u\n",
p->end_time_string, (unsigned int)(p->end_time_timestamp));
printf("link_mbps: %d\n", p->link_mbps);
pp++; p=*pp; i++;
}
} /* print_conf() */
#include "abw.h"
#define MAX_CHARACTERISTICS_STRING 128
#define MAX_TIME_STRING 20
int read_conf_file(char *filename, flow_spec_t **flow_spec);
int check_conf(flow_spec_t **flow_spec);
void print_conf(flow_spec_t **flow_spec);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment