-
Notifications
You must be signed in to change notification settings - Fork 2
/
oflops.c
91 lines (76 loc) · 2.68 KB
/
oflops.c
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <pthread.h>
#include <pcap.h>
#include "oflops.h"
#include "usage.h"
#include "control.h"
#include "context.h"
#include "module_run.h"
#include "log.h"
#include "signal.h"
#include "traffic_generator.h"
void *
run_module(void *param) {
struct run_module_param* tmp = (struct run_module_param *)param;
return (void *)run_test_module(tmp->ctx, tmp->ix_mod);
}
void *
start_traffic_thread(void *param) {
struct run_module_param* tmp = (struct run_module_param *)param;
return (void *)run_traffic_generation(tmp->ctx, tmp->ix_mod);
}
int main(int argc, char * argv[])
{
int i, j;
struct pcap_stat ps;
pthread_t *thread, event_thread, traffic_gen;
struct run_module_param *param = malloc_and_check(sizeof(struct run_module_param));
char msg[1024];
struct timeval now;
// create the default context
oflops_context * ctx = oflops_default_context();
param->ctx = ctx;
parse_args(ctx, argc, argv);
if(ctx->n_tests == 0 )
usage("Need to specify at least one module to run\n",NULL);
oflops_log_init(ctx->log);
setup_control_channel(ctx);
fprintf(stderr, "Running %d Test%s\n", ctx->n_tests, ctx->n_tests>1?"s":"");
for(i=0;i<ctx->n_tests;i++)
{
fprintf(stderr, "-----------------------------------------------\n");
fprintf(stderr, "------------ TEST %s ----------\n", (*(ctx->tests[i]->name))());
fprintf(stderr, "-----------------------------------------------\n");
reset_context(ctx);
ctx->curr_test = ctx->tests[i];
param->ix_mod = i;
setup_test_module(ctx,i);
thread = malloc_and_check(sizeof(pthread_t));
pthread_create(thread, NULL, run_module, (void *)param);
pthread_create(&traffic_gen, NULL, start_traffic_thread, (void *)param);
pthread_create(&event_thread, NULL, event_loop, (void *)param);
pthread_join(*thread, NULL);
pthread_join(event_thread, NULL);
pthread_cancel(traffic_gen);
free(thread);
gettimeofday(&now, NULL);
for(j = 0 ; j < ctx->n_channels;j++) {
if(ctx->channels[j].pcap_handle == NULL) continue;
pcap_stats(ctx->channels[j].pcap_handle, &ps);
snprintf(msg, 1024, "%s:%u:%u",ctx->channels[j].dev, ps.ps_recv, ps.ps_drop);
oflops_log(now, PCAP_MSG, msg);
printf("%s\n", msg);
}
oflops_log(now, PKTGEN_MSG, report_traffic_generator(ctx));
printf("%s\n", report_traffic_generator(ctx));
}
oflops_log_close();
fprintf(stderr, "-----------------------------------------------\n");
fprintf(stderr, "--------------- Finished -----------------\n");
fprintf(stderr, "-----------------------------------------------\n");
return 0;
}