1 # vim: tabstop=4 shiftwidth=4 softtabstop=4
2 # -*- coding: utf-8 -*-
6 from ftg.utils.common import CommonUtils
7 from ftg.flow_table import FlowTable
8 from ftg.flow_priority import FlowPriority
9 from ftg.flow_entry import FlowEntry
13 DEFAULT_PRIORITY = "32768"
15 def __init__(self, util, dump_file):
17 self.dump_file = dump_file
20 def regist_flow(self, table_no, priority_no, match_exp, instructions, counter=""):
24 if not table_no in self.tables:
26 exist_priority = False
27 elif not priority_no in self.tables[table_no].get_priorities():
28 exist_priority = False
30 if exist_table and exist_priority:
31 entry = FlowEntry(match_exp, instructions)
32 self.tables[table_no].get_priority(
33 priority_no).add_flow_entries(entry)
34 elif exist_table and exist_priority == False:
35 priority = FlowPriority(priority_no)
36 entry = FlowEntry(match_exp, instructions)
37 priority.add_flow_entries(entry)
38 self.tables[table_no].add_priorities({str(priority_no): priority})
40 entry = FlowEntry(match_exp, instructions)
41 priority = FlowPriority(priority_no)
42 table = FlowTable(table_no)
43 priority.add_flow_entries(entry)
44 table.add_priorities({str(priority_no): priority})
45 self.tables.update({str(table_no): table})
50 def _parse_actions_with_bracket(self, instruction, actions):
51 if self.util.d_push(re.match(r'(.*),(.*?\(.*?\))(.*)', instruction)) is not None:
52 match = self.util.d_pop()
53 if match.group(1).find("(") != -1:
54 self._parse_actions_with_bracket(match.group(1), actions)
56 actions.extend(self._split_action(match.group(1)))
58 actions.append(match.group(2))
59 if match.group(3).strip() != "":
60 actions.extend(self._split_action(match.group(3)))
61 elif self.util.d_push(re.match(r'(?<!,)(.*?\(.*?\))(.*)', instruction)) is not None:
62 match = self.util.d_pop()
63 if match.group(1).strip() != "":
64 actions.append(match.group(1))
66 if match.group(2).strip() != "":
67 if match.group(2).find("(") != -1:
68 self._parse_actions_with_bracket(match.group(2), actions)
70 actions.extend(self._split_action(match.group(2)))
72 actions.extend(self._split_action(instruction))
76 def _split_action(self, action):
77 action = re.sub(r'^,', '', action)
78 actions = action.split(',')