OSDN Git Service

fix parse method in OVSFlowDumpParser class
[ftg/ftg.git] / ftg.py
1 #!/usr/bin/env python
2 # vim: tabstop=4 shiftwidth=4 softtabstop=4
3 # -*- coding: utf-8 -*-
4 #
5 #   ftg.py : It is a tool that ,
6 #            you can capture and anlyze.
7 #
8
9 __version__ = "0.1"
10
11 import sys
12 import os
13 import re
14 from optparse import OptionParser, OptionGroup
15 from ftg.grapher import Grapher
16 from ftg.utils.common import CommonUtils
17 from ftg.formatter.graphviz_tb import GraphvizTBFormatter
18 from ftg.formatter.csv import CSVFormatter
19 from ftg.formatter.tsv import TSVFormatter
20
21
22 if __name__ == "__main__":
23     # init program options
24     p = OptionParser(version="ver: %s" % __version__)
25     p.add_option(
26         '-i', '--dump_file', dest='dump_file',
27         help="specify Open vSwitch dump-flows FILE", metavar="FILE")
28     p.add_option(
29         '-f', '--formatter', dest='formatter',
30         help="specify formatter (graphviz, csv, tsv)", default="graphviz")
31     p.add_option(
32         '-b', '--entries_per_block', dest='entries_per_block', type='int',
33         help="specify number of entries in priority block", default=10)
34     p.add_option(
35         '-v', '--verbose', dest='verbose', action="store_true", default=False,
36         help="verbose output")
37     p.add_option(
38         '-s', '--output_summary', dest='output_summary', action="store_true", default=False,
39         help="output summary informations")
40     p.add_option(
41         '-d', '--debug', dest='debug', action="store_true", default=False,
42         help="debug output")
43     g1 = OptionGroup(p, "Output Flags")
44     g1.add_option(
45         '--enable_resubmit_loop_output', dest='resubmit_loop_output',
46         action="store_true", default=True,
47         help="enable the output of the 'resubmit to start' that re-evaluate at the same table")
48     g1.add_option(
49         '--disable_resubmit_loop_output', dest='resubmit_loop_output',
50         action="store_false", default=True,
51         help="disable the output of the 'resubmit to start' that re-evaluate at the same table")
52     g1.add_option(
53         '--enable_note_output', dest='note_output',
54         action="store_true", default=True,
55         help="enable the output of the 'note action'")
56     g1.add_option(
57         '--disable_note_output', dest='note_output',
58         action="store_false", default=True,
59         help="disable the output of the 'note action'")
60     p.add_option_group(g1)
61     (opts, args) = p.parse_args()
62
63     util = CommonUtils(opts)
64
65     if  opts.formatter == "graphviz":
66         formatter = GraphvizTBFormatter(util)
67         formatter.set_entries_per_block(opts.entries_per_block)
68         formatter.set_output_summary(opts.output_summary)
69     elif  opts.formatter == "csv":
70         formatter = CSVFormatter(util)
71     elif  opts.formatter == "tsv":
72         formatter = TSVFormatter(util)
73     else:
74         util.error_out("specify valid formatter.")
75         sys.exit(1)
76
77     if opts.dump_file is not None and opts.dump_file != "":
78         grapher = Grapher(util, opts.dump_file, formatter)
79         grapher.run()
80     else:
81         util.error_out("specify Open vSwitch dump-flows file with -i option.")
82         sys.exit(1)
83         
84
85