修改Openvswitch代码添加自定义action.docx
- 文档编号:23999342
- 上传时间:2023-05-23
- 格式:DOCX
- 页数:20
- 大小:21.41KB
修改Openvswitch代码添加自定义action.docx
《修改Openvswitch代码添加自定义action.docx》由会员分享,可在线阅读,更多相关《修改Openvswitch代码添加自定义action.docx(20页珍藏版)》请在冰豆网上搜索。
修改Openvswitch代码添加自定义action
有时候我们需要自定义一些自己的action,根据包头里面的信息,做一些自己的操作。
例如添加一个action名为handle_example
第一、修改ofp-actions.c文件
首先在ofp-actions.c里面添加Openflow各个版本的这个action
1.static const struct ofpact_map*
2.get_ofpact_map(enum ofp_versionversion)
3.{
4. /*OpenFlow1.0actions.*/
5. static const struct ofpact_mapof10[]={
6. {OFPACT_OUTPUT,0},
7. {OFPACT_SET_VLAN_VID,1},
8. {OFPACT_SET_VLAN_PCP,2},
9. {OFPACT_STRIP_VLAN,3},
10. {OFPACT_SET_ETH_SRC,4},
11. {OFPACT_SET_ETH_DST,5},
12. {OFPACT_SET_IPV4_SRC,6},
13. {OFPACT_SET_IPV4_DST,7},
14. {OFPACT_SET_IP_DSCP,8},
15. {OFPACT_SET_L4_SRC_PORT,9},
16. {OFPACT_SET_L4_DST_PORT,10},
17. {OFPACT_ENQUEUE,11},
18. {OFPACT_HANDLE_EXAMPLE,28},
19. {0,-1},
20. };
21.
22. /*OpenFlow1.1actions.*/
23. static const struct ofpact_mapof11[]={
24. {OFPACT_OUTPUT,0},
25. {OFPACT_SET_VLAN_VID,1},
26. {OFPACT_SET_VLAN_PCP,2},
27. {OFPACT_SET_ETH_SRC,3},
28. {OFPACT_SET_ETH_DST,4},
29. {OFPACT_SET_IPV4_SRC,5},
30. {OFPACT_SET_IPV4_DST,6},
31. {OFPACT_SET_IP_DSCP,7},
32. {OFPACT_SET_IP_ECN,8},
33. {OFPACT_SET_L4_SRC_PORT,9},
34. {OFPACT_SET_L4_DST_PORT,10},
35. /*OFPAT_COPY_TTL_OUT(11)notsupported.*/
36. /*OFPAT_COPY_TTL_IN(12)notsupported.*/
37. {OFPACT_SET_MPLS_LABEL,13},
38. {OFPACT_SET_MPLS_TC,14},
39. {OFPACT_SET_MPLS_TTL,15},
40. {OFPACT_DEC_MPLS_TTL,16},
41. {OFPACT_PUSH_VLAN,17},
42. {OFPACT_STRIP_VLAN,18},
43. {OFPACT_PUSH_MPLS,19},
44. {OFPACT_POP_MPLS,20},
45. {OFPACT_SET_QUEUE,21},
46. {OFPACT_GROUP,22},
47. {OFPACT_SET_IP_TTL,23},
48. {OFPACT_DEC_TTL,24},
49. {OFPACT_HANDLE_EXAMPLE,28},
50. {0,-1},
51. };
52.
53. /*OpenFlow1.2,1.3,and1.4actions.*/
54. static const struct ofpact_mapof12[]={
55. {OFPACT_OUTPUT,0},
56. /*OFPAT_COPY_TTL_OUT(11)notsupported.*/
57. /*OFPAT_COPY_TTL_IN(12)notsupported.*/
58. {OFPACT_SET_MPLS_TTL,15},
59. {OFPACT_DEC_MPLS_TTL,16},
60. {OFPACT_PUSH_VLAN,17},
61. {OFPACT_STRIP_VLAN,18},
62. {OFPACT_PUSH_MPLS,19},
63. {OFPACT_POP_MPLS,20},
64. {OFPACT_SET_QUEUE,21},
65. {OFPACT_GROUP,22},
66. {OFPACT_SET_IP_TTL,23},
67. {OFPACT_DEC_TTL,24},
68. {OFPACT_SET_FIELD,25},
69. /*OF1.3+OFPAT_PUSH_PBB(26)notsupported.*/
70. /*OF1.3+OFPAT_POP_PBB(27)notsupported.*/
71. {OFPACT_HANDLE_EXAMPLE,28},
72. {0,-1},
73. };
74.
75. switch (version){
76. case OFP10_VERSION:
77. return of10;
78.
79. case OFP11_VERSION:
80. return of11;
81.
82. case OFP12_VERSION:
83. case OFP13_VERSION:
84. case OFP14_VERSION:
85. case OFP15_VERSION:
86. default:
87. return of12;
88. }
89.}
其次添加rawactiontype
1.enum ofp_raw_action_type{
2./*##-----------------##*/
3./*##Standardactions.##*/
4./*##-----------------##*/
5.
6. /*OF1.0(0):
structofp10_action_output.*/
7. OFPAT_RAW10_OUTPUT,
8. /*OF1.1+(0):
structofp11_action_output.*/
9. OFPAT_RAW11_OUTPUT,
10.
11. /*OF1.0
(1):
uint16_t.*/
12. OFPAT_RAW10_SET_VLAN_VID,
13. /*OF1.0
(2):
uint8_t.*/
14. OFPAT_RAW10_SET_VLAN_PCP,
15.
16. /*OF1.1
(1),OF1.2+
(1)isdeprecated(useSet-Field):
uint16_t.
17. *
18. *[Semanticsdifferslightlybetweenthe1.0and1.1versionsoftheVLAN
19. *modificationactions:
the1.0versionspushaVLANheaderifnoneis
20. *present,butthe1.1versionsdonot.Thatistheonlyreasonthatwe
21. *distinguishtheirrawactiontypes.]*/
22. OFPAT_RAW11_SET_VLAN_VID,
23. /*OF1.1
(2),OF1.2+
(2)isdeprecated(useSet-Field):
uint8_t.*/
24. OFPAT_RAW11_SET_VLAN_PCP,
25.
26. /*OF1.1+(17):
ovs_be16.
27. *
28. *[TheargumentistheEthertype,e.g.ETH_TYPE_VLAN_8021Q,nottheVIDor
29. *TCI.]*/
30. OFPAT_RAW11_PUSH_VLAN,
31.
32. /*OF1.0(3):
void.*/
33. OFPAT_RAW10_STRIP_VLAN,
34. /*OF1.1+(18):
void.*/
35. OFPAT_RAW11_POP_VLAN,
36.
37. /*OF1.0(4),OF1.1(3),OF1.2+(3)isdeprecated(useSet-Field):
struct
38. *ofp_action_dl_addr.*/
39. OFPAT_RAW_SET_DL_SRC,
40.
41. /*OF1.0(5),OF1.1(4),OF1.2+(4)isdeprecated(useSet-Field):
struct
42. *ofp_action_dl_addr.*/
43. OFPAT_RAW_SET_DL_DST,
44.
45. /*OF1.0(6),OF1.1(5),OF1.2+(5)isdeprecated(useSet-Field):
46. *ovs_be32.*/
47. OFPAT_RAW_SET_NW_SRC,
48.
49. /*OF1.0(7),OF1.1(6),OF1.2+(6)isdeprecated(useSet-Field):
50. *ovs_be32.*/
51. OFPAT_RAW_SET_NW_DST,
52.
53. /*OF1.0(8),OF1.1(7),OF1.2+(7)isdeprecated(useSet-Field):
uint8_t.*/
54. OFPAT_RAW_SET_NW_TOS,
55.
56. /*OF1.1(8),OF1.2+(8)isdeprecated(useSet-Field):
uint8_t.*/
57. OFPAT_RAW11_SET_NW_ECN,
58.
59. /*OF1.0(9),OF1.1(9),OF1.2+(9)isdeprecated(useSet-Field):
60. *ovs_be16.*/
61. OFPAT_RAW_SET_TP_SRC,
62.
63. /*OF1.0(10),OF1.1(10),OF1.2+(10)isdeprecated(useSet-Field):
64. *ovs_be16.*/
65. OFPAT_RAW_SET_TP_DST,
66.
67. /*OF1.0(11):
structofp10_action_enqueue.*/
68. OFPAT_RAW10_ENQUEUE,
69.
70. /*NX1.0(30),OF1.1(13),OF1.2+(13)isdeprecated(useSet-Field):
71. *ovs_be32.*/
72. OFPAT_RAW_SET_MPLS_LABEL,
73.
74. /*NX1.0(31),OF1.1(14),OF1.2+(14)isdeprecated(useSet-Field):
75. *uint8_t.*/
76. OFPAT_RAW_SET_MPLS_TC,
77.
78. /*NX1.0(25),OF1.1(15),OF1.2+(15)isdeprecated(useSet-Field):
79. *uint8_t.*/
80. OFPAT_RAW_SET_MPLS_TTL,
81.
82. /*NX1.0(26),OF1.1+(16):
void.*/
83. OFPAT_RAW_DEC_MPLS_TTL,
84.
85. /*NX1.0(23),OF1.1+(19):
ovs_be16.
86. *
87. *[TheargumentistheEthertype,e.g.ETH_TYPE_MPLS,notthelabel.]*/
88. OFPAT_RAW_PUSH_MPLS,
89.
90. /*NX1.0(24),OF1.1+(20):
ovs_be16.
91. *
92. *[TheargumentistheEthertype,e.g.ETH_TYPE_IPV4ifatBoSor
93. *ETH_TYPE_MPLSotherwise,notthelabel.]*/
94. OFPAT_RAW_POP_MPLS,
95.
96. /*NX1.0(4),OF1.1+(21):
uint32_t.*/
97. OFPAT_RAW_SET_QUEUE,
98.
99. /*OF1.1+(22):
uint32_t.*/
100. OFPAT_RAW11_GROUP,
101.
102. /*OF1.1+(23):
uint8_t.*/
103. OFPAT_RAW11_SET_NW_TTL,
104.
105. /*NX1.0(18),OF1.1+(24):
void.*/
106. OFPAT_RAW_DEC_NW_TTL,
107. /*NX1.0+(21):
structnx_action_cnt_ids,...*/
108. NXAST_RAW_DEC_TTL_CNT_IDS,
109.
110. /*OF1.2-1.4(25):
structofp12_action_set_field,...*/
111. OFPAT_RAW12_SET_FIELD,
112. /*OF1.5+(25):
structofp12_action_set_field,...*/
113. OFPAT_RAW15_SET_FIELD,
114.
115. /*OF1.0(28):
void.*/
116. OFPAT_RAW10_HANDLE_EXAMPLE,
117.
118. /*OF1.1(28):
void.*/
119. OFPAT_RAW11_HANDLE_EXAMPLE,
120.
121. /*OF1.2-1.4(28):
void.*/
122. OFPAT_RAW12_HANDLE_EXAMPLE,
123.
124. /*NX1.0-1.4(7):
structnx_action_reg_load.
125. *
126. *[InOpenFlow1.5,set_fieldisasupersetofreg_loadfunctionality,so
127. *wedropreg_load.]*/
128. NXAST_RAW_REG_LOAD,
129. /*NX1.0-1.4(33):
structnx_action_reg_load2,...
130. *
131. *[InOpenFlow1.5,set_fieldisasupersetofreg_load2functionality,so
132. *wedropreg_load2.]*/
133. NXAST_RAW_REG_LOAD2,
134.
135. /*OF1.5+(28):
structofp15_action_copy_field,...*/
136. OFPAT_RAW15_COPY_FIELD,
137. /*ONF1.3-1.4(3200):
structonf_action_copy_field,...*/
138. ONFACT_RAW13_COPY_FIELD,
139. /*NX1.0-1.4(6):
structnx_action_reg_move,...*/
140. NXAST_RAW_REG_MOVE,
141.
142./*##-------------------------##*/
143./*##Niciraextensionactions.##*/
144./*##-------------------------##*/
145.
146./*Actionssimilartostandardactionsarelistedwiththestandardactions.*/
147.
148. /*NX1.0+
(1):
uint16_t.*/
149. NXAST_RAW_RESUBMIT,
150. /*NX1.0+(14):
structnx_action_resubmit.*/
151. NXAST_RAW_RESUBMIT_TABLE,
152.
153. /*NX1.0+
(2):
uint32_t.*/
154. NXAST_RAW_SET_TUNNEL,
155. /*NX1.0+(9):
uint64_t.*/
156. NXAST_RAW_SET_TUNNEL64,
157.
158. /*NX1.0+(5):
void.*/
159. NXAST_RAW_POP_QUEUE,
160.
161. /*NX1.0+(8):
structnx_action_note,...*/
162. NXAST_RAW_NOTE,
163.
164. /*NX1.0+(10):
structnx_action_multipath.*/
165. NXAST_RAW_MULTIPATH,
166.
167. /*NX1.0+(12):
structnx_action_bundle,...*/
168. NXAST_RAW_BUNDLE,
169. /*NX1.0+(13):
structnx_action_bundle,...*/
170. NXAST_RAW_BUNDLE_LOAD,
171.
172. /*NX1.0+(15):
structnx_action_output_reg.*/
173. NXAST_RAW_OUTPUT_REG,
174. /*NX1.0+(32):
structnx_action_output_reg2.*/
175. NXAST_RAW_OUTPUT_REG2,
176.
177. /*NX1.0+(16):
structnx_action_learn,...*/
178. NXAST_RAW_LEARN,
179.
180. /*NX1.0+(17):
void.*/
181. NXAST_RAW_EXIT,
182.
183. /*NX1.0+(19):
structnx_action_fin_timeout.*/
184. NXAST_RAW_FIN_TIMEOUT,
185.
186. /*NX1.0+(20):
structnx_action_controller.*/
187. NXAST_RAW_CONTROLLER,
188.
189. /*NX1.0+(22):
structnx_action_write_metadata.*/
190. NXAST_RA
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 修改 Openvswitch 代码 添加 自定义 action