Commit d420ebcb authored by 's avatar
Browse files

More precise scheduling with mysql_time and some bugs corrected



git-svn-id: file:///home/svn/mapi/trunk@335 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent cb35e033
......@@ -5,6 +5,7 @@
#define __USE_XOPEN
#include <time.h>
#include <sys/time.h>
#include <math.h>
#include <mysql/mysql.h>
......@@ -12,6 +13,7 @@
#include "../../stdlib/sample.h"
#include "abw.h"
#include "abw_mysql.h"
#include "abw_time.h"
flow_spec_t *flow_spec[MAX_FLOWS];
global_spec_t global_spec;
......@@ -61,7 +63,8 @@ flow_spec_t *new_flow_spec(void) {
p->sau_byte_threshold=3000;
p->sau_pass_probability=0.5;
p->payload_strings_no=0;
p->interval=1;
p->interval.tv_sec=1;
p->interval.tv_usec=0;
p->start_time_string=DEFAULT_START_TIME_STRING;
p->end_time_string=DEFAULT_END_TIME_STRING;
p->link_mbps=DEFAULT_LINK_MBPS;
......@@ -205,7 +208,8 @@ void print_conf(flow_spec_t **flow_spec) {
printf("\n");
}
printf("interval: %f\n", p->interval);
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",
......@@ -222,12 +226,13 @@ int main(int argc, char *argv[])
int opt;
struct timeval tm;
struct timezone tz;
int payload_strings_no;
/* int payload_strings_no; */
int direct_flow;
flow_spec_t **pp;
flow_spec_t *p;
flow_run_t **qq;
flow_run_t *q;
struct timeval next, wait;
/* Set initial values */
global_spec.conf_filename=NULL;
......@@ -261,7 +266,7 @@ int main(int argc, char *argv[])
exit(-1);
}
payload_strings_no=0;
/* payload_strings_no=0; */
direct_flow=0;
while ((opt=getopt(argc, argv, ARGS)) != -1) {
......@@ -297,7 +302,7 @@ int main(int argc, char *argv[])
break;
case 'p':
direct_flow=1;
if (payload_strings_no >= MAX_PAYLOAD_STRINGS) {
if (flow_spec[0]->payload_strings_no >= MAX_PAYLOAD_STRINGS) {
fprintf(stderr, "%s: max. %d strings can be searched in payload\n", __func__, MAX_PAYLOAD_STRINGS);
exit(-1);
}
......@@ -305,20 +310,27 @@ int main(int argc, char *argv[])
fprintf(stderr, "%s: max. %d characters long strings can be searched in payload\n", __func__, MAX_PAYLOAD_STRING);
exit(-1);
}
if ((flow_spec[0]->payload_strings[payload_strings_no]=malloc(strlen(optarg)+1))==NULL) {
if ((flow_spec[0]->payload_strings[flow_spec[0]->payload_strings_no]=
malloc(strlen(optarg)+1))==NULL) {
fprintf(stderr, "%s: malloc() failed\n", __func__);
exit(-1);
}
strcpy(flow_spec[0]->payload_strings[payload_strings_no], optarg);
payload_strings_no++;
strcpy(flow_spec[0]->payload_strings[flow_spec[0]->payload_strings_no],
optarg);
flow_spec[0]->payload_strings_no++;
break;
case 'i':
{ double interval;
direct_flow=1;
flow_spec[0]->interval=atof(optarg);
if (flow_spec[0]->interval<=0) {
interval=atof(optarg);
if (interval<=0) {
fprintf(stderr, "%s: interval must be positive\n", __func__);
exit(-1);
}
flow_spec[0]->interval.tv_sec=floor(interval);
flow_spec[0]->interval.tv_usec=
(suseconds_t)floor((interval - flow_spec[0]->interval.tv_sec)*1000000);
}
break;
case 's':
direct_flow=1;
......@@ -374,9 +386,6 @@ int main(int argc, char *argv[])
exit(-1);
}
printf("%s: no_stdout: %d, no_mysql: %d\n", __func__,
global_spec.no_stdout, global_spec.no_mysql);
/* Remaining command-line arguments form a header filter string */
for (i=optind; i<argc; i++) {
......@@ -468,16 +477,16 @@ int main(int argc, char *argv[])
if (p->sau_mode == 'd' && p->sau_packet_threshold != 1) {
if ((q->sample_fid=
mapi_apply_function(q->fd, "SAMPLE", PERIODIC,
p->sau_packet_threshold))<0) {
mapi_apply_function(q->fd, "SAMPLE", p->sau_packet_threshold),
PERIODIC)<0) {
fprintf(stderr, "%s: SAMPLE for flow %d failed\n", __func__, i);
exit(-1);
}
}
else if (p->sau_mode == 'p' && p->sau_pass_probability != 1) {
if ((q->sample_fid=
mapi_apply_function(q->fd, "SAMPLE", PROBABILISTIC,
(p->sau_pass_probability)*100))<0) {
mapi_apply_function(q->fd, "SAMPLE", (p->sau_pass_probability)*100),
PROBABILISTIC)<0) {
fprintf(stderr, "%s: SAMPLE for flow %d failed\n", __func__, i);
exit(-1);
}
......@@ -524,6 +533,7 @@ int main(int argc, char *argv[])
exit(-1);
}
if (!global_spec.no_stdout)
printf("%u.%u", (unsigned int)(tm.tv_sec), (unsigned int)(tm.tv_usec));
pp=flow_spec;
......@@ -578,12 +588,19 @@ int main(int argc, char *argv[])
i++;
} /* while (p) */
if (!global_spec.no_stdout)
printf("\n");
/* TODO: wait until next checkpoint (not a fixed delay) of
the flow whose checkpoint is earliest */
usleep((flow_spec[0]->interval)*1000000);
abw_next_timestamp(&(flow_spec[0]->interval), &next, &wait);
printf("next.tv_sec: %d, next.tv_usec: %d, wait.tv_sec: %d, wait.tv_usec: %d\n", (int)(next.tv_sec), (int)(next.tv_usec), (int)(wait.tv_sec), (int)(wait.tv_usec));
usleep(wait.tv_sec * 1000000 + wait.tv_usec);
/* usleep((flow_spec[0]->interval)*1000000); */
} /* while (1) */
/* TODO: this is never reached, move to interrupt handler */
......
......@@ -115,12 +115,17 @@ int abw_mysql_get_parameters_id(global_spec_t *global_spec,
return -1;
}
sprintf(query, "SELECT * FROM tParameters WHERE sau_mode='%c' AND sau_threshold='%d' AND interval_sec='%f'",
p->sau_mode, p->sau_threshold, p->interval);
sprintf(query, "SELECT * FROM tParameters WHERE sau_mode='%c' AND sau_threshold='%d' AND interval_sec='%d' AND interval_usec='%d'",
p->sau_mode, p->sau_threshold, (int)(p->interval.tv_sec),
(int)(p->interval.tv_usec));
if (strlen(p->header_filter))
sprintf(query+strlen(query), " AND header_filter='%s'", p->header_filter);
else
sprintf(query+strlen(query), " AND header_filter=''");
if (p->payload_strings_no)
sprintf(query+strlen(query), " AND payload_string='%s'", p->payload_strings[0]);
else
sprintf(query+strlen(query), " AND payload_string=''");
printf("%s: query: %s\n", __func__, query);
if (mysql_query(global_spec->mysql, query)) {
......@@ -162,17 +167,17 @@ int abw_mysql_get_parameters_id(global_spec_t *global_spec,
}
else { /* parameters are not in tParameters */
printf("%s: parameters are not in tParameters\n", __func__);
strcpy(query, "INSERT INTO tParameters (sau_mode, sau_threshold, interval_sec, link_mbps");
if (p->header_filter)
strcat(query, ", header_filter");
if (p->payload_strings_no)
strcat(query, ", payload_string");
sprintf(query+strlen(query), ") VALUES ('%c', '%d', '%f', '%d'",
p->sau_mode, p->sau_threshold, p->interval, p->link_mbps);
if (p->header_filter)
sprintf(query, "INSERT INTO tParameters (sau_mode, sau_threshold, interval_sec, interval_usec, link_mbps, header_filter, payload_string) VALUES ('%c', '%d', '%d', '%d', '%d'",
p->sau_mode, p->sau_threshold, (int)(p->interval.tv_sec),
(int)(p->interval.tv_usec), p->link_mbps);
if (strlen(p->header_filter))
sprintf(query+strlen(query), ", '%s'", p->header_filter);
else
sprintf(query+strlen(query), ", ''");
if (p->payload_strings_no)
sprintf(query+strlen(query), ", '%s'", p->payload_strings[0]);
else
sprintf(query+strlen(query), ", ''");
strcat(query, ");");
printf("%s: query: %s\n", __func__, query);
......@@ -219,7 +224,7 @@ int abw_mysql_insert_value(global_spec_t *global_spec, flow_run_t *q,
sprintf(query+strlen(query), ", '%s'", value_varchar);
strcat(query, ");");
printf("%s: query: %s\n", __func__, query);
/* printf("%s: query: %s\n", __func__, query); */
if (mysql_query(global_spec->mysql, query)) {
fprintf(stderr, "%s: mysql_query(%s) failed\n", __func__, query);
return -1;
......
......@@ -19,7 +19,8 @@ CREATE TABLE tParameters (
sau_mode varchar(1),
sau_threshold int,
payload_string varchar(128),
interval_sec float,
interval_sec int,
interval_usec int,
link_mbps int,
PRIMARY KEY (id)
);
......
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