forked from OFLOPS-Turbo/oflops-turbo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module_default.c
129 lines (108 loc) · 3.57 KB
/
module_default.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <string.h>
#include "module_default.h"
#include "pcap_track.h"
// Set of default operations for modules; just NOOPs except for OFLOPS_CONTROL which we keep timestamps for
int default_module_init(struct oflops_context *ctx, char * init)
{
return 0;
}
int default_module_destroy(struct oflops_context *ctx)
{
return 0;
}
int default_module_get_pcap_filter(struct oflops_context *ctx, oflops_channel_name ofc, char * filter, int buflen)
{
return 0;
}
int default_module_start(struct oflops_context * ctx) {
return 0;
}
int default_module_handle_pcap_event(struct oflops_context *ctx, struct pcap_event * pe, oflops_channel_name ch)
{
return 0;
if( ch != OFLOPS_CONTROL)
return 0;
if(!ctx->channels[OFLOPS_CONTROL].timestamps)
ctx->channels[OFLOPS_CONTROL].timestamps = ptrack_new();
// add this packet to the list of timestamps
return ptrack_add_of_entry(ctx->channels[OFLOPS_CONTROL].timestamps, pe->data, pe->pcaphdr.caplen, pe->pcaphdr);
}
int default_module_of_event_packet_in(struct oflops_context *ctx, const struct ofp_packet_in * pktin)
{
return 0;
}
#ifdef HAVE_OFP_FLOW_EXPIRED
int default_module_of_event_flow_removed(struct oflops_context *ctx, const struct ofp_flow_expired * ofph)
#elif defined(HAVE_OFP_FLOW_REMOVED)
int default_module_of_event_flow_removed(struct oflops_context *ctx, const struct ofp_flow_removed * ofph)
#else
#error "Unknown version of openflow"
#endif
{
return 0;
}
int default_module_of_event_echo_request(struct oflops_context *ctx, const struct ofp_header * ofph)
{
struct ofp_header resp;
memcpy(&resp,ofph,sizeof(resp));
resp.type = OFPT_ECHO_REPLY;
oflops_send_of_mesg(ctx, &resp);
return 0;
}
int default_module_of_event_port_status(struct oflops_context * ctx, const struct ofp_port_status * ofph)
{
return 0;
}
int default_module_of_event_other(struct oflops_context * ctx, const struct ofp_header * ofph)
{
return 0;
}
int default_module_handle_timer_event(struct oflops_context * ctx, struct timer_event * te)
{
return 0;
}
int default_module_handle_snmp_event(struct oflops_context * ctx, struct snmp_event * se)
{
return 0;
}
int default_module_handle_traffic_generation(struct oflops_context * ctx)
{
return 0;
}
void default_module_of_message(struct oflops_context *ctx, uint8_t of_version, uint8_t type, void *data, size_t len)
{
switch(type)
{
case OFPT_PACKET_IN:
ctx->curr_test->of_event_packet_in(ctx, (struct ofp_packet_in *)data);
break;
case OFPT_FLOW_EXPIRED:
#ifdef HAVE_OFP_FLOW_EXPIRED
ctx->curr_test->of_event_flow_removed(ctx, (struct ofp_flow_expired *)data);
#elif defined(HAVE_OFP_FLOW_REMOVED)
ctx->curr_test->of_event_flow_removed(ctx, (struct ofp_flow_removed *)data);
#else
# error "Unknown version of openflow"
#endif
break;
case OFPT_PORT_STATUS:
ctx->curr_test->of_event_port_status(ctx, (struct ofp_port_status *)data);
break;
case OFPT_ECHO_REQUEST:
ctx->curr_test->of_event_echo_request(ctx, (struct ofp_header *)data);
break;
default:
if (type > OFPT_BARRIER_REPLY) // FIXME: update for new openflow versions
{
fprintf(stderr, "%s:%d :: Data buffer probably trashed : unknown openflow type %d\n",
__FILE__, __LINE__, type);
abort();
}
ctx->curr_test->of_event_other(ctx, (struct ofp_header * ) data);
break;
}
}
const uint8_t *default_module_get_openflow_versions() {
static uint8_t versions[] = {0x1,0x0};
return versions;
}