1
1
import click
2
+ import os
2
3
3
4
from ovs_dbg .ofp import OFPFlowFactory
4
- from ovs_dbg .ofparse .ofp_logic import LogicFlowProcessor
5
+ from ovs_dbg .ofparse .ofp_logic import LogicFlowProcessor , CookieProcessor
5
6
from ovs_dbg .ofparse .main import maincli
6
7
from ovs_dbg .ofparse .process import (
7
8
FlowProcessor ,
10
11
)
11
12
from ovs_dbg .ofparse .html import HTMLBuffer , HTMLFormatter , HTMLStyle
12
13
13
-
14
14
factory = OFPFlowFactory ()
15
15
16
16
@@ -49,7 +49,58 @@ def pretty(opts, heat_map):
49
49
proc .print ()
50
50
51
51
52
+ def ovn_detrace_callback (ctx , param , value ):
53
+ """click callback to add detrace information to config object and
54
+ set general ovn-detrace flag to True
55
+ """
56
+ ctx .obj [param .name ] = value
57
+ if value != param .default :
58
+ ctx .obj ["ovn_detrace_flag" ] = True
59
+ return value
60
+
61
+
52
62
@openflow .command ()
63
+ @click .option (
64
+ "-d" ,
65
+ "--ovn-detrace" ,
66
+ "ovn_detrace_flag" ,
67
+ is_flag = True ,
68
+ show_default = True ,
69
+ help = "Use ovn-detrace to extract cookie information (implies '-c')" ,
70
+ )
71
+ @click .option (
72
+ "--ovn-detrace-path" ,
73
+ default = "/usr/bin" ,
74
+ type = click .Path (),
75
+ help = "Use an alternative path to where ovn_detrace.py is located. "
76
+ "Instead of using this option you can just set PYTHONPATH accordingly" ,
77
+ show_default = True ,
78
+ callback = ovn_detrace_callback ,
79
+ )
80
+ @click .option (
81
+ "--ovnnb-db" ,
82
+ default = os .getenv ("OVN_NB_DB" ) or "unix:/var/run/ovn/ovnnb_db.sock" ,
83
+ help = "Specify the OVN NB database string (implies -d). "
84
+ "If the OVN_NB_DB environment variable is set, it's used as default. "
85
+ "Otherwise, the default is unix:/var/run/ovn/ovnnb_db.sock" ,
86
+ callback = ovn_detrace_callback ,
87
+ )
88
+ @click .option (
89
+ "--ovnsb-db" ,
90
+ default = os .getenv ("OVN_SB_DB" ) or "unix:/var/run/ovn/ovnsb_db.sock" ,
91
+ help = "Specify the OVN NB database string (implies -d). "
92
+ "If the OVN_NB_DB environment variable is set, it's used as default. "
93
+ "Otherwise, the default is unix:/var/run/ovn/ovnnb_db.sock" ,
94
+ callback = ovn_detrace_callback ,
95
+ )
96
+ @click .option (
97
+ "-o" ,
98
+ "--ovn-filter" ,
99
+ help = "Specify a filter to be run on ovn-detrace information (implied -d). "
100
+ "Format: python regular expression "
101
+ "(see https://docs.python.org/3/library/re.html)" ,
102
+ callback = ovn_detrace_callback ,
103
+ )
53
104
@click .option (
54
105
"-s" ,
55
106
"--show-flows" ,
@@ -76,7 +127,17 @@ def pretty(opts, heat_map):
76
127
help = "Create heat-map with packet and byte counters (when -s is used)" ,
77
128
)
78
129
@click .pass_obj
79
- def logic (opts , show_flows , cookie_flag , heat_map ):
130
+ def logic (
131
+ opts ,
132
+ ovn_detrace_flag ,
133
+ ovn_detrace_path ,
134
+ ovnnb_db ,
135
+ ovnsb_db ,
136
+ ovn_filter ,
137
+ show_flows ,
138
+ cookie_flag ,
139
+ heat_map ,
140
+ ):
80
141
"""
81
142
Print the logical structure of the flows.
82
143
@@ -88,6 +149,11 @@ def logic(opts, show_flows, cookie_flag, heat_map):
88
149
Optionally, the cookie can also be considered to be part of the logical
89
150
flow.
90
151
"""
152
+ if ovn_detrace_flag :
153
+ opts ["ovn_detrace_flag" ] = True
154
+ if opts .get ("ovn_detrace_flag" ):
155
+ cookie_flag = True
156
+
91
157
processor = LogicFlowProcessor (opts , factory , cookie_flag )
92
158
processor .process ()
93
159
processor .print (show_flows , heat_map )
@@ -159,3 +225,58 @@ def html(opts):
159
225
processor = HTMLProcessor (opts , factory )
160
226
processor .process ()
161
227
print (processor .html ())
228
+
229
+
230
+ @openflow .command ()
231
+ @click .option (
232
+ "-d" ,
233
+ "--ovn-detrace" ,
234
+ "ovn_detrace_flag" ,
235
+ is_flag = True ,
236
+ show_default = True ,
237
+ help = "Use ovn-detrace to extract cookie information" ,
238
+ )
239
+ @click .option (
240
+ "--ovn-detrace-path" ,
241
+ default = "/usr/bin" ,
242
+ type = click .Path (),
243
+ help = "Use an alternative path to where ovn_detrace.py is located. "
244
+ "Instead of using this option you can just set PYTHONPATH accordingly" ,
245
+ show_default = True ,
246
+ callback = ovn_detrace_callback ,
247
+ )
248
+ @click .option (
249
+ "--ovnnb-db" ,
250
+ default = os .getenv ("OVN_NB_DB" ) or "unix:/var/run/ovn/ovnnb_db.sock" ,
251
+ help = "Specify the OVN NB database string (implies -d). "
252
+ "If the OVN_NB_DB environment variable is set, it's used as default. "
253
+ "Otherwise, the default is unix:/var/run/ovn/ovnnb_db.sock" ,
254
+ callback = ovn_detrace_callback ,
255
+ )
256
+ @click .option (
257
+ "--ovnsb-db" ,
258
+ default = os .getenv ("OVN_SB_DB" ) or "unix:/var/run/ovn/ovnsb_db.sock" ,
259
+ help = "Specify the OVN NB database string (implies -d). "
260
+ "If the OVN_NB_DB environment variable is set, it's used as default. "
261
+ "Otherwise, the default is unix:/var/run/ovn/ovnnb_db.sock" ,
262
+ callback = ovn_detrace_callback ,
263
+ )
264
+ @click .option (
265
+ "-o" ,
266
+ "--ovn-filter" ,
267
+ help = "Specify a filter to be run on ovn-detrace information (implied -d). "
268
+ "Format: python regular expression "
269
+ "(see https://docs.python.org/3/library/re.html)" ,
270
+ callback = ovn_detrace_callback ,
271
+ )
272
+ @click .pass_obj
273
+ def cookie (
274
+ opts , ovn_detrace_flag , ovn_detrace_path , ovnnb_db , ovnsb_db , ovn_filter
275
+ ):
276
+ """Print the flow tables sorted by cookie"""
277
+ if ovn_detrace_flag :
278
+ opts ["ovn_detrace_flag" ] = True
279
+
280
+ processor = CookieProcessor (opts , factory )
281
+ processor .process ()
282
+ processor .print ()
0 commit comments