-
Notifications
You must be signed in to change notification settings - Fork 192
/
pipeline.c
663 lines (564 loc) · 23.2 KB
/
pipeline.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
/* Copyright (c) 2011, TrafficLab, Ericsson Research, Hungary
* Copyright (c) 2012, CPqD, Brazil
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Ericsson Research nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <sys/types.h>
#include <stdbool.h>
#include <stdlib.h>
#include "action_set.h"
#include "compiler.h"
#include "dp_actions.h"
#include "dp_buffers.h"
#include "dp_exp.h"
#include "dp_ports.h"
#include "datapath.h"
#include "packet.h"
#include "pipeline.h"
#include "flow_table.h"
#include "flow_entry.h"
#include "meter_table.h"
#include "oflib/ofl.h"
#include "oflib/ofl-structs.h"
#include "util.h"
#include "hash.h"
#include "oflib/oxm-match.h"
#include "vlog.h"
#define LOG_MODULE VLM_pipeline
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(60, 60);
static void
execute_entry(struct pipeline *pl, struct flow_entry *entry,
struct flow_table **table, struct packet **pkt);
struct pipeline *
pipeline_create(struct datapath *dp) {
struct pipeline *pl;
int i;
pl = xmalloc(sizeof(struct pipeline));
for (i=0; i<PIPELINE_TABLES; i++) {
pl->tables[i] = flow_table_create(dp, i);
}
pl->dp = dp;
nblink_initialize();
return pl;
}
static bool
is_table_miss(struct flow_entry *entry){
return ((entry->stats->priority) == 0 && (entry->match->length <= 4));
}
/* Sends a packet to the controller in a packet_in message */
static void
send_packet_to_controller(struct pipeline *pl, struct packet *pkt, uint8_t table_id, uint8_t reason) {
struct ofl_msg_packet_in msg;
struct ofl_match *m;
msg.header.type = OFPT_PACKET_IN;
msg.total_len = pkt->buffer->size;
msg.reason = reason;
msg.table_id = table_id;
msg.cookie = 0xffffffffffffffff;
msg.data = pkt->buffer->data;
/* A max_len of OFPCML_NO_BUFFER means that the complete
packet should be sent, and it should not be buffered.*/
if (pl->dp->config.miss_send_len != OFPCML_NO_BUFFER){
dp_buffers_save(pl->dp->buffers, pkt);
msg.buffer_id = pkt->buffer_id;
msg.data_length = MIN(pl->dp->config.miss_send_len, pkt->buffer->size);
}else {
msg.buffer_id = OFP_NO_BUFFER;
msg.data_length = pkt->buffer->size;
}
m = &pkt->handle_std->match;
/* In this implementation the fields in_port and in_phy_port
always will be the same, because we are not considering logical
ports */
msg.match = (struct ofl_match_header*)m;
dp_send_message(pl->dp, (struct ofl_msg_header *)&msg, NULL);
}
/* Pass the packet through the flow tables.
* This function takes ownership of the packet and will destroy it. */
void
pipeline_process_packet(struct pipeline *pl, struct packet *pkt) {
struct flow_table *table, *next_table;
if (VLOG_IS_DBG_ENABLED(LOG_MODULE)) {
char *pkt_str = packet_to_string(pkt);
VLOG_DBG_RL(LOG_MODULE, &rl, "processing packet: %s", pkt_str);
free(pkt_str);
}
if (!packet_handle_std_is_ttl_valid(pkt->handle_std)) {
send_packet_to_controller(pl, pkt, 0/*table_id*/, OFPR_INVALID_TTL);
packet_destroy(pkt);
return;
}
next_table = pl->tables[0];
while (next_table != NULL) {
struct flow_entry *entry;
VLOG_DBG_RL(LOG_MODULE, &rl, "trying table %u.", next_table->stats->table_id);
pkt->table_id = next_table->stats->table_id;
table = next_table;
next_table = NULL;
// EEDBEH: additional printout to debug table lookup
if (VLOG_IS_DBG_ENABLED(LOG_MODULE)) {
char *m = ofl_structs_match_to_string((struct ofl_match_header*)&(pkt->handle_std->match), pkt->dp->exp);
VLOG_DBG_RL(LOG_MODULE, &rl, "searching table entry for packet match: %s.", m);
free(m);
}
entry = flow_table_lookup(table, pkt);
if (entry != NULL) {
if (VLOG_IS_DBG_ENABLED(LOG_MODULE)) {
char *m = ofl_structs_flow_stats_to_string(entry->stats, pkt->dp->exp);
VLOG_DBG_RL(LOG_MODULE, &rl, "found matching entry: %s.", m);
free(m);
}
pkt->handle_std->table_miss = is_table_miss(entry);
execute_entry(pl, entry, &next_table, &pkt);
/* Packet could be destroyed by a meter instruction */
if (!pkt)
return;
if (next_table == NULL) {
/* Cookie field is set 0xffffffffffffffff
because we cannot associate it to any
particular flow */
action_set_execute(pkt->action_set, pkt, 0xffffffffffffffff);
return;
}
} else {
/* OpenFlow 1.3 default behavior on a table miss */
VLOG_DBG_RL(LOG_MODULE, &rl, "No matching entry found. Dropping packet.");
packet_destroy(pkt);
return;
}
}
VLOG_WARN_RL(LOG_MODULE, &rl, "Reached outside of pipeline processing cycle.");
}
static
int inst_compare(const void *inst1, const void *inst2){
struct ofl_instruction_header * i1 = *(struct ofl_instruction_header **) inst1;
struct ofl_instruction_header * i2 = *(struct ofl_instruction_header **) inst2;
if ((i1->type == OFPIT_APPLY_ACTIONS && i2->type == OFPIT_CLEAR_ACTIONS) ||
(i1->type == OFPIT_CLEAR_ACTIONS && i2->type == OFPIT_APPLY_ACTIONS))
return i1->type > i2->type;
return i1->type < i2->type;
}
ofl_err
pipeline_handle_flow_mod(struct pipeline *pl, struct ofl_msg_flow_mod *msg,
const struct sender *sender) {
/* Note: the result of using table_id = 0xff is undefined in the spec.
* for now it is accepted for delete commands, meaning to delete
* from all tables */
ofl_err error;
size_t i;
bool match_kept,insts_kept;
if(sender->remote->role == OFPCR_ROLE_SLAVE)
return ofl_error(OFPET_BAD_REQUEST, OFPBRC_IS_SLAVE);
match_kept = false;
insts_kept = false;
/*Sort by execution oder*/
qsort(msg->instructions, msg->instructions_num,
sizeof(struct ofl_instruction_header *), inst_compare);
// Validate actions in flow_mod
for (i=0; i< msg->instructions_num; i++) {
if (msg->instructions[i]->type == OFPIT_APPLY_ACTIONS ||
msg->instructions[i]->type == OFPIT_WRITE_ACTIONS) {
struct ofl_instruction_actions *ia = (struct ofl_instruction_actions *)msg->instructions[i];
error = dp_actions_validate(pl->dp, ia->actions_num, ia->actions);
if (error) {
return error;
}
error = dp_actions_check_set_field_req(msg, ia->actions_num, ia->actions);
if (error) {
return error;
}
}
/* Reject goto in the last table. */
if ((msg->table_id == (PIPELINE_TABLES - 1))
&& (msg->instructions[i]->type == OFPIT_GOTO_TABLE))
return ofl_error(OFPET_BAD_INSTRUCTION, OFPBIC_UNSUP_INST);
}
if (msg->table_id == 0xff) {
if (msg->command == OFPFC_DELETE || msg->command == OFPFC_DELETE_STRICT) {
size_t i;
error = 0;
for (i=0; i < PIPELINE_TABLES; i++) {
error = flow_table_flow_mod(pl->tables[i], msg, &match_kept, &insts_kept);
if (error) {
break;
}
}
if (error) {
return error;
} else {
ofl_msg_free_flow_mod(msg, !match_kept, !insts_kept, pl->dp->exp);
return 0;
}
} else {
return ofl_error(OFPET_FLOW_MOD_FAILED, OFPFMFC_BAD_TABLE_ID);
}
} else {
error = flow_table_flow_mod(pl->tables[msg->table_id], msg, &match_kept, &insts_kept);
if (error) {
return error;
}
if ((msg->command == OFPFC_ADD || msg->command == OFPFC_MODIFY || msg->command == OFPFC_MODIFY_STRICT) &&
msg->buffer_id != NO_BUFFER) {
/* run buffered message through pipeline */
struct packet *pkt;
pkt = dp_buffers_retrieve(pl->dp->buffers, msg->buffer_id);
if (pkt != NULL) {
pipeline_process_packet(pl, pkt);
} else {
VLOG_WARN_RL(LOG_MODULE, &rl, "The buffer flow_mod referred to was empty (%u).", msg->buffer_id);
}
}
ofl_msg_free_flow_mod(msg, !match_kept, !insts_kept, pl->dp->exp);
return 0;
}
}
ofl_err
pipeline_handle_table_mod(struct pipeline *pl,
struct ofl_msg_table_mod *msg,
const struct sender *sender) {
if(sender->remote->role == OFPCR_ROLE_SLAVE)
return ofl_error(OFPET_BAD_REQUEST, OFPBRC_IS_SLAVE);
if (msg->table_id == 0xff) {
size_t i;
for (i=0; i<PIPELINE_TABLES; i++) {
pl->tables[i]->features->config = msg->config;
}
} else {
pl->tables[msg->table_id]->features->config = msg->config;
}
ofl_msg_free((struct ofl_msg_header *)msg, pl->dp->exp);
return 0;
}
ofl_err
pipeline_handle_stats_request_flow(struct pipeline *pl,
struct ofl_msg_multipart_request_flow *msg,
const struct sender *sender) {
struct ofl_flow_stats **stats = xmalloc(sizeof(struct ofl_flow_stats *));
size_t stats_size = 1;
size_t stats_num = 0;
if (msg->table_id == 0xff) {
size_t i;
for (i=0; i<PIPELINE_TABLES; i++) {
flow_table_stats(pl->tables[i], msg, &stats, &stats_size, &stats_num);
}
} else {
flow_table_stats(pl->tables[msg->table_id], msg, &stats, &stats_size, &stats_num);
}
{
struct ofl_msg_multipart_reply_flow reply =
{{{.type = OFPT_MULTIPART_REPLY},
.type = OFPMP_FLOW, .flags = 0x0000},
.stats = stats,
.stats_num = stats_num
};
dp_send_message(pl->dp, (struct ofl_msg_header *)&reply, sender);
}
free(stats);
ofl_msg_free((struct ofl_msg_header *)msg, pl->dp->exp);
return 0;
}
ofl_err
pipeline_handle_stats_request_table(struct pipeline *pl,
struct ofl_msg_multipart_request_header *msg UNUSED,
const struct sender *sender) {
struct ofl_table_stats **stats;
size_t i;
stats = xmalloc(sizeof(struct ofl_table_stats *) * PIPELINE_TABLES);
for (i=0; i<PIPELINE_TABLES; i++) {
stats[i] = pl->tables[i]->stats;
}
{
struct ofl_msg_multipart_reply_table reply =
{{{.type = OFPT_MULTIPART_REPLY},
.type = OFPMP_TABLE, .flags = 0x0000},
.stats = stats,
.stats_num = PIPELINE_TABLES};
dp_send_message(pl->dp, (struct ofl_msg_header *)&reply, sender);
}
free(stats);
ofl_msg_free((struct ofl_msg_header *)msg, pl->dp->exp);
return 0;
}
ofl_err
pipeline_handle_stats_request_table_features_request(struct pipeline *pl,
struct ofl_msg_multipart_request_header *msg,
const struct sender *sender) {
struct ofl_table_features **features;
struct ofl_msg_multipart_request_table_features *feat =
(struct ofl_msg_multipart_request_table_features *) msg;
int i; /* Feature index in feature array. Jean II */
int table_id;
ofl_err error = 0;
/* Further validation of request not done in
* ofl_structs_table_features_unpack(). Jean II */
if(feat->table_features != NULL) {
for(i = 0; i < feat->tables_num; i++){
if(feat->table_features[i]->table_id >= PIPELINE_TABLES)
return ofl_error(OFPET_TABLE_FEATURES_FAILED, OFPTFFC_BAD_TABLE);
/* We may want to validate things like config, max_entries,
* metadata... */
}
}
/* Check if we already received fragments of a multipart request. */
if(sender->remote->mp_req_msg != NULL) {
bool nomore;
/* We can only merge requests having the same XID. */
if(sender->xid != sender->remote->mp_req_xid)
{
VLOG_ERR(LOG_MODULE, "multipart request: wrong xid (0x%X != 0x%X)", sender->xid, sender->remote->mp_req_xid);
/* Technically, as our buffer can only hold one pending request,
* this is a buffer overflow ! Jean II */
/* Return error. */
return ofl_error(OFPET_BAD_REQUEST, OFPBRC_MULTIPART_BUFFER_OVERFLOW);
}
VLOG_DBG(LOG_MODULE, "multipart request: merging with previous fragments (%zu+%zu)", ((struct ofl_msg_multipart_request_table_features *) sender->remote->mp_req_msg)->tables_num, feat->tables_num);
/* Merge the request with previous fragments. */
nomore = ofl_msg_merge_multipart_request_table_features((struct ofl_msg_multipart_request_table_features *) sender->remote->mp_req_msg, feat);
/* Check if incomplete. */
if(!nomore)
return 0;
VLOG_DBG(LOG_MODULE, "multipart request: reassembly complete (%zu)", ((struct ofl_msg_multipart_request_table_features *) sender->remote->mp_req_msg)->tables_num);
/* Use the complete request. */
feat = (struct ofl_msg_multipart_request_table_features *) sender->remote->mp_req_msg;
#if 0
{
char *str;
str = ofl_msg_to_string((struct ofl_msg_header *) feat, pl->dp->exp);
VLOG_DBG(LOG_MODULE, "\nMerged request:\n%s\n\n", str);
free(str);
}
#endif
} else {
/* Check if the request is an initial fragment. */
if(msg->flags & OFPMPF_REQ_MORE) {
struct ofl_msg_multipart_request_table_features* saved_msg;
VLOG_DBG(LOG_MODULE, "multipart request: create reassembly buffer (%zu)", feat->tables_num);
/* Create a buffer the do reassembly. */
saved_msg = (struct ofl_msg_multipart_request_table_features*) malloc(sizeof(struct ofl_msg_multipart_request_table_features));
saved_msg->header.header.type = OFPT_MULTIPART_REQUEST;
saved_msg->header.type = OFPMP_TABLE_FEATURES;
saved_msg->header.flags = 0;
saved_msg->tables_num = 0;
saved_msg->table_features = NULL;
/* Save the fragment for later use. */
ofl_msg_merge_multipart_request_table_features(saved_msg, feat);
sender->remote->mp_req_msg = (struct ofl_msg_multipart_request_header *) saved_msg;
sender->remote->mp_req_xid = sender->xid;
return 0;
}
/* Non fragmented request. Nothing to do... */
VLOG_DBG(LOG_MODULE, "multipart request: non-fragmented request (%zu)", feat->tables_num);
}
/*Check to see if the body is empty.*/
/* Should check merge->tables_num instead. Jean II */
if(feat->table_features != NULL){
int last_table_id = 0;
/* Check that the table features make sense. */
for(i = 0; i < feat->tables_num; i++){
/* Table-IDs must be in ascending order. */
table_id = feat->table_features[i]->table_id;
if(table_id < last_table_id) {
error = ofl_error(OFPET_TABLE_FEATURES_FAILED, OFPTFFC_BAD_TABLE);
break;
}
/* Can't go over out internal max-entries. */
if (feat->table_features[i]->max_entries > FLOW_TABLE_MAX_ENTRIES) {
error = ofl_error(OFPET_TABLE_FEATURES_FAILED, OFPTFFC_BAD_ARGUMENT);
break;
}
}
if (error == 0) {
/* Disable all tables, they will be selectively re-enabled. */
for(table_id = 0; table_id < PIPELINE_TABLES; table_id++){
pl->tables[table_id]->disabled = true;
}
/* Change tables configuration
TODO: Remove flows*/
VLOG_DBG(LOG_MODULE, "pipeline_handle_stats_request_table_features_request: updating features");
for(i = 0; i < feat->tables_num; i++){
table_id = feat->table_features[i]->table_id;
/* Replace whole table feature. */
ofl_structs_free_table_features(pl->tables[table_id]->features, pl->dp->exp);
pl->tables[table_id]->features = feat->table_features[i];
feat->table_features[i] = NULL;
/* Re-enable table. */
pl->tables[table_id]->disabled = false;
}
}
}
/* Cleanup request. */
if(sender->remote->mp_req_msg != NULL) {
ofl_msg_free((struct ofl_msg_header *) sender->remote->mp_req_msg, pl->dp->exp);
sender->remote->mp_req_msg = NULL;
sender->remote->mp_req_xid = 0; /* Currently not needed. Jean II. */
}
if (error) {
return error;
}
table_id = 0;
/* Query for table capabilities */
loop: ;
features = (struct ofl_table_features**) xmalloc(sizeof(struct ofl_table_features *) * 8);
/* Return 8 tables per reply segment. */
for (i = 0; i < 8; i++){
/* Skip disabled tables. */
while((table_id < PIPELINE_TABLES) && (pl->tables[table_id]->disabled == true))
table_id++;
/* Stop at the last table. */
if(table_id >= PIPELINE_TABLES)
break;
/* Use that table in the reply. */
features[i] = pl->tables[table_id]->features;
table_id++;
}
VLOG_DBG(LOG_MODULE, "multipart reply: returning %d tables, next table-id %d", i, table_id);
{
struct ofl_msg_multipart_reply_table_features reply =
{{{.type = OFPT_MULTIPART_REPLY},
.type = OFPMP_TABLE_FEATURES,
.flags = (table_id == PIPELINE_TABLES ? 0x00000000 : OFPMPF_REPLY_MORE) },
.table_features = features,
.tables_num = i };
dp_send_message(pl->dp, (struct ofl_msg_header *)&reply, sender);
}
if (table_id < PIPELINE_TABLES){
goto loop;
}
free(features);
return 0;
}
ofl_err
pipeline_handle_stats_request_aggregate(struct pipeline *pl,
struct ofl_msg_multipart_request_flow *msg,
const struct sender *sender) {
struct ofl_msg_multipart_reply_aggregate reply =
{{{.type = OFPT_MULTIPART_REPLY},
.type = OFPMP_AGGREGATE, .flags = 0x0000},
.packet_count = 0,
.byte_count = 0,
.flow_count = 0};
if (msg->table_id == 0xff) {
size_t i;
for (i=0; i<PIPELINE_TABLES; i++) {
flow_table_aggregate_stats(pl->tables[i], msg,
&reply.packet_count, &reply.byte_count, &reply.flow_count);
}
} else {
flow_table_aggregate_stats(pl->tables[msg->table_id], msg,
&reply.packet_count, &reply.byte_count, &reply.flow_count);
}
dp_send_message(pl->dp, (struct ofl_msg_header *)&reply, sender);
ofl_msg_free((struct ofl_msg_header *)msg, pl->dp->exp);
return 0;
}
void
pipeline_destroy(struct pipeline *pl) {
struct flow_table *table;
int i;
for (i=0; i<PIPELINE_TABLES; i++) {
table = pl->tables[i];
if (table != NULL) {
flow_table_destroy(table);
}
}
free(pl);
}
void
pipeline_timeout(struct pipeline *pl) {
int i;
for (i = 0; i < PIPELINE_TABLES; i++) {
flow_table_timeout(pl->tables[i]);
}
}
/* Executes the instructions associated with a flow entry */
static void
execute_entry(struct pipeline *pl, struct flow_entry *entry,
struct flow_table **next_table, struct packet **pkt) {
/* NOTE: instructions, when present, will be executed in
the following order:
Meter
Apply-Actions
Clear-Actions
Write-Actions
Write-Metadata
Goto-Table
*/
size_t i;
struct ofl_instruction_header *inst;
for (i=0; i < entry->stats->instructions_num; i++) {
/*Packet was dropped by some instruction or action*/
if(!(*pkt)){
return;
}
inst = entry->stats->instructions[i];
switch (inst->type) {
case OFPIT_GOTO_TABLE: {
struct ofl_instruction_goto_table *gi = (struct ofl_instruction_goto_table *)inst;
*next_table = pl->tables[gi->table_id];
break;
}
case OFPIT_WRITE_METADATA: {
struct ofl_instruction_write_metadata *wi = (struct ofl_instruction_write_metadata *)inst;
struct ofl_match_tlv *f;
/* NOTE: Hackish solution. If packet had multiple handles, metadata
* should be updated in all. */
packet_handle_std_validate((*pkt)->handle_std);
/* Search field on the description of the packet. */
HMAP_FOR_EACH_WITH_HASH(f, struct ofl_match_tlv,
hmap_node, hash_int(OXM_OF_METADATA,0), &(*pkt)->handle_std->match.match_fields){
uint64_t *metadata = (uint64_t*) f->value;
*metadata = (*metadata & ~wi->metadata_mask) | (wi->metadata & wi->metadata_mask);
VLOG_DBG_RL(LOG_MODULE, &rl, "Executing write metadata: 0x%"PRIx64"", *metadata);
}
break;
}
case OFPIT_WRITE_ACTIONS: {
struct ofl_instruction_actions *wa = (struct ofl_instruction_actions *)inst;
action_set_write_actions((*pkt)->action_set, wa->actions_num, wa->actions);
break;
}
case OFPIT_APPLY_ACTIONS: {
struct ofl_instruction_actions *ia = (struct ofl_instruction_actions *)inst;
dp_execute_action_list((*pkt), ia->actions_num, ia->actions, entry->stats->cookie);
break;
}
case OFPIT_CLEAR_ACTIONS: {
action_set_clear_actions((*pkt)->action_set);
break;
}
case OFPIT_METER: {
struct ofl_instruction_meter *im = (struct ofl_instruction_meter *)inst;
meter_table_apply(pl->dp->meters, pkt , im->meter_id);
break;
}
case OFPIT_EXPERIMENTER: {
dp_exp_inst((*pkt), (struct ofl_instruction_experimenter *)inst);
break;
}
}
}
}