OSDN Git Service

initial commit
[ftg/ftg.git] / ftg / formatter / csv.py
1 # vim: tabstop=4 shiftwidth=4 softtabstop=4
2 # -*- coding: utf-8 -*-
3 #
4
5
6 import re
7 from ftg.flow_table import FlowTable
8 from ftg.flow_priority import FlowPriority
9 from ftg.flow_entry import FlowEntry
10 from ftg.formatter.base_formatter import BaseFormatter
11
12
13 class CSVFormatter(BaseFormatter):
14     formatter_name = "csv"
15
16 # "0-10000","in_port=1,dl_dst=xx:xx:xx:12:50:c8","output=5"
17
18     HEADER_FORMAT = "\"Table-Priority\",\"Match\",\"Instruction\""
19     FOOTER_FORMAT = ""
20
21     def format(self):
22         formatted_flow = []
23         formatted_flow.append(self.get_header())
24
25         for t_no in sorted(self._tables.keys(), key=lambda x: int(x)):
26             for p_no in sorted(self._tables[t_no].get_priorities(), key=lambda x: int(x), reverse=True):
27                 for ent in self._tables[t_no].get_priority(p_no).get_flow_entries():
28                     formatted_flow.append(
29                         "\"" + t_no + "-" + p_no + "\"," + str(ent))
30
31         formatted_flow.append(self.get_footer())
32         return formatted_flow