Exemplo n.º 1
0
 def parse_flow(self, line):
     """
     Return a Flow or None, converted from a given line of original flow.
     """
     line = line.strip()
     table, packet, priority, match, actions = 0, 0, 0, '', ''
     if line.startswith('cookie='):
         table = get_num_after(line, 'table=')
         packet = get_num_after(line, 'n_packets=')
         if table is None or packet is None:
             return None
         for field in line.split():
             if field.startswith('priority='): #priority of priority+match
                 priority = get_num_after(field, 'priority=')
                 if priority is None:
                     return None
                 match = field.replace('priority=%u' % priority, '').lstrip(',').strip()
                 if not match:
                     match = r'*'
             elif field.startswith('actions='):
                 actions = field.replace('actions=', '').rstrip('\n')
         if priority is None:  # There is no priority= field
             match = line.split()[len(line.split()) - 2]
         if len(match)>=30:
             match.replace('vlan_tci','vlan')
             match = re.compile('0x0{1,}').sub('0x',match)
         return Flow(self.bridge, table, packet, priority, match, actions)
     else:
         return None
Exemplo n.º 2
0
 def parse_flow(self, line):
     """
     Return a Flow or None, converted from a given line of original flow.
     """
     line = line.strip()
     table, packet, priority, match, actions = 0, 0, 0, '', ''
     if line.startswith('cookie='):
         table = get_num_after(line, 'table=')
         packet = get_num_after(line, 'n_packets=')
         if table is None or packet is None:
             return None
         for field in line.split():
             if field.startswith('priority='):  #priority of priority+match
                 priority = get_num_after(field, 'priority=')
                 if priority is None:
                     return None
                 match = field.replace('priority=%u' % priority,
                                       '').lstrip(',').strip()
                 if not match:
                     match = r'*'
             elif field.startswith('actions='):
                 actions = field.replace('actions=', '').rstrip('\n')
         if priority is None:  # There is no priority= field
             match = line.split()[len(line.split()) - 2]
         if len(match) >= 30:
             match.replace('vlan_tci', 'vlan')
             match = re.compile('0x0{1,}').sub('0x', match)
         return Flow(self.bridge, table, packet, priority, match, actions)
     else:
         return None
Exemplo n.º 3
0
 def _parse_flow(self, line):
     """
     Return a Flow or None, converted from a given line of original flow.
     """
     line = line.strip()
     table, packet, priority, match, actions = 0, 0, 0, '', ''
     if line.startswith('cookie='):
         table = get_num_after(line, 'table=')
         packet = get_num_after(line, 'n_packets=')
         if table is None or packet is None:
             return None
         for field in line.split():
             if field.startswith('priority='):  # match starts with pri
                 priority = get_num_after(field, 'priority=')
                 if priority is None:
                     error('No priority field found in flow\n')
                     return None
                 match = \
                     field.replace('priority=%u'
                                   % priority, '').lstrip(',').strip()
                 if not match:
                     match = r'*'
                 port_no = get_num_after(field, 'in_port=')
                 if isinstance(port_no, int):
                     intf = self._get_port_intf(port_no)
                     if intf:
                         match = \
                             match.replace('in_port=%u'
                                           % port_no, 'in_port=%s' % intf)
             elif field.startswith('actions='):
                 actions = field.replace('actions=', '').rstrip('\n')
         if priority is None:  # There is no priority= field
             match = line.split()[len(line.split()) - 2]
         if len(match) >= 30:
             match.replace('vlan_tci', 'vlan')
             match = re.compile('0x0{1,}').sub('0x', match)
         return Flow(self.bridge, table, packet, priority, match, actions)
     else:
         return None
Exemplo n.º 4
0
 def _parse_flow(self, line):
     """
     Return a Flow or None, converted from a given line of original flow.
     """
     line = line.strip()
     table, packet, priority, match, actions = 0, 0, 0, '', ''
     if line.startswith('cookie='):
         table = get_num_after(line, 'table=')
         packet = get_num_after(line, 'n_packets=')
         if table is None or packet is None:
             return None
         for field in line.split():
             if field.startswith('priority='):  # match starts with pri
                 priority = get_num_after(field, 'priority=')
                 if priority is None:
                     error('No priority field found in flow\n')
                     return None
                 match = \
                     field.replace('priority=%u'
                                   % priority, '').lstrip(',').strip()
                 if not match:
                     match = r'*'
                 port_no = get_num_after(field, 'in_port=')
                 if isinstance(port_no, int):
                     intf = self._get_port_intf(port_no)
                     if intf:
                         match = \
                             match.replace('in_port=%u'
                                           % port_no, 'in_port=%s' % intf)
             elif field.startswith('actions='):
                 actions = self._process_actions(field)
         if priority is None:  # There is no priority= field
             match = line.split()[len(line.split()) - 2]
         if len(match) >= 30:
             match.replace('vlan_tci', 'vlan')
             match = re.compile('0x0{1,}').sub('0x', match)
         return Flow(self.bridge, table, packet, priority, match, actions)
     else:
         return None
Exemplo n.º 5
0
 def _process_actions(self, actions_str):
     """
     Process the actions fields to make it more readable
     :param actions_str: input action string
     :return: The converted string.
     """
     actions = actions_str.replace('actions=', '').rstrip('\n')
     for act in actions_str.split(','):
         if act.startswith('output:'):
             port_no = get_num_after(act, 'output:')
             if isinstance(port_no, int):
                 intf = self._get_port_intf(port_no)
                 if intf:
                     actions = \
                         actions.replace('output:%u'
                                         % port_no, 'output:%s' % intf)
     return actions