-
Notifications
You must be signed in to change notification settings - Fork 2
/
context.c
63 lines (46 loc) · 1.5 KB
/
context.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
#include <string.h>
#include <dlfcn.h>
#include "context.h"
#include "timer_event.h"
#include "utils.h"
#include "log.h"
#include <pcap.h>
#include <openflow/openflow.h>
// Create a default context
oflops_context * oflops_default_context(void)
{
oflops_context * ctx = malloc_and_check(sizeof(oflops_context));
bzero(ctx, sizeof(*ctx));
ctx->max_tests = 10 ;
ctx->tests = malloc_and_check(ctx->max_tests * sizeof(test_module *));
ctx->listen_port = OFP_TCP_PORT; // listen on default port
ctx->listen_fd = -1;
ctx->snaplen = 100; //65535;
ctx->n_channels=1;
ctx->max_channels=10;
ctx->channels = malloc_and_check(sizeof(struct channel_info)* ctx->max_channels);
ctx->control_outgoing = msgbuf_new(4096); // dynamically sized
ctx->snmp_channel_info = malloc_and_check(sizeof(struct snmp_channel));
ctx->snmp_channel_info->hostname = NULL;
ctx->snmp_channel_info->community_string = NULL;
ctx->channels[OFLOPS_CONTROL].raw_sock = -1;
// initalize other channels later
ctx->log = malloc(sizeof(DEFAULT_LOG_FILE));
strcpy(ctx->log, DEFAULT_LOG_FILE);
ctx->trafficGen = PKTGEN;
ctx->dump_controller = 0;
ctx->cpuOID_len = MAX_OID_LEN;
return ctx;
}
// Reset any counters in the context
// run me between tests
int reset_context(oflops_context * ctx)
{
// reset any state between experiments
//timer_init(ctx);
// clean up after test (each test does its own cleanup, except for the
// stuff oflops allocated)
if(ctx->curr_test)
dlclose(ctx->curr_test->symbol_handle);
return 0;
}