ROFL-pipeline  v0.6.0dev
of1x_instruction_pp.h
Go to the documentation of this file.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 #ifndef __OF1X_INSTRUCTION_PP_H__
6 #define __OF1X_INSTRUCTION_PP_H__
7 
8 #include <inttypes.h>
9 #include <stdbool.h>
10 #include "rofl.h"
11 #include "../../../util/pp_guard.h" //Never forget to include the guard
12 #include "of1x_instruction.h"
13 #include "of1x_action_pp.h"
14 
22 //C++ extern C
23 ROFL_BEGIN_DECLS
24 
25 static inline bool __of1x_process_instructions_must_replicate(const of1x_instruction_group_t* inst_grp){
26 
27  bool has_goto = inst_grp->instructions[OF1X_IT_GOTO_TABLE].type == OF1X_IT_GOTO_TABLE;
28  unsigned int n_out = inst_grp->num_of_outputs;
29 
30  return ( (n_out == 1) && (has_goto) ) || ( n_out > 1);
31 }
32 
33 /* Process instructions */
34 static inline unsigned int __of1x_process_instructions(const unsigned int tid, const struct of1x_switch* sw, const unsigned int table_id, datapacket_t *const pkt, const of1x_instruction_group_t* instructions){
35 
36  of1x_instruction_t* inst = (of1x_instruction_t*)&instructions->instructions[OF1X_IT_APPLY_ACTIONS];
37 
42  //Check all instructions in order
43  if(inst->type == OF1X_IT_APPLY_ACTIONS)
44  __of1x_process_apply_actions(tid, sw, table_id, pkt, inst->apply_actions, __of1x_process_instructions_must_replicate(instructions), NULL);
45 
46  //Next instruction
47  inst++;
48 
49  if(inst->type == OF1X_IT_CLEAR_ACTIONS)
50  __of1x_clear_write_actions(&pkt->write_actions.of1x);
51 
52  //Next instruction
53  inst++;
54 
55  if(inst->type == OF1X_IT_WRITE_ACTIONS)
56  __of1x_update_packet_write_actions(&pkt->write_actions.of1x, inst->write_actions);
57 
58  //Next instruction
59  inst++;
60 
61  if(inst->type == OF1X_IT_WRITE_METADATA){
62  pkt->__metadata = (pkt->__metadata & ~inst->write_metadata.metadata_mask) |
63  (inst->write_metadata.metadata & inst->write_metadata.metadata_mask);
64  }
65 
66  //Next instruction
67  inst++;
68 
69  if(inst->type == OF1X_IT_EXPERIMENTER){
70  //TODO:
71  }
72 
73  //Next instruction
74  inst++;
75 
76  if(inst->type == OF1X_IT_METER){
77  //TODO:
78  }
79 
80  //Next instruction (GOTO table)
81  inst++;
82 
83  //Will be 0 (NO go-to-table) due to memset() of isntruction group
84  return inst->go_to_table;
85 }
86 
87 //C++ extern C
88 ROFL_END_DECLS
89 
90 #endif //OF1X_INSTRUCTION_PP
OpenFlow-enabled v1.0, 1.2 and 1.3.2 switch abstraction.
Definition: of1x_switch.h:28
OpenFlow v1.X instructions.
OpenFlow v1.0, 1.2 and 1.3.2 action packet processing routines.
static unsigned int __of1x_process_instructions(const unsigned int tid, const struct of1x_switch *sw, const unsigned int table_id, datapacket_t *const pkt, const of1x_instruction_group_t *instructions)
Data packet abstraction.
Definition: datapacket.h:49