def _parse_flow_stats(self, stats): """Parse flow stats reply message into tags/labels and byte/packet counts.""" packet_count = int(stats['packet_count']) byte_count = int(stats['byte_count']) instructions = stats['instructions'] tags = { 'dp_name': self.dp.name, 'dp_id': hex(self.dp.dp_id), 'table_id': int(stats['table_id']), 'priority': int(stats['priority']), 'inst_count': len(instructions), 'cookie': int(stats['cookie']), } oxm_matches = stats['match']['OFPMatch']['oxm_fields'] for oxm_match in oxm_matches: oxm_tlv = oxm_match['OXMTlv'] mask = oxm_tlv['mask'] val = oxm_tlv['value'] orig_field = oxm_tlv['field'] if mask is not None: val = '/'.join((str(val), str(mask))) field = OLD_MATCH_FIELDS.get(orig_field, orig_field) tags[field] = val if field == 'vlan_vid' and mask is None: tags['vlan'] = devid_present(int(val)) return ( ('flow_packet_count', tags, packet_count), ('flow_byte_count', tags, byte_count))
def _parse_flow_stats(self, stats): """Parse flow stats reply message into tags/labels and byte/packet counts.""" packet_count = int(stats['packet_count']) byte_count = int(stats['byte_count']) instructions = stats['instructions'] tags = { 'dp_name': self.dp.name, 'dp_id': hex(self.dp.dp_id), 'table_id': int(stats['table_id']), 'priority': int(stats['priority']), 'inst_count': len(instructions), 'cookie': int(stats['cookie']), } oxm_matches = stats['match']['OFPMatch']['oxm_fields'] for oxm_match in oxm_matches: oxm_tlv = oxm_match['OXMTlv'] mask = oxm_tlv['mask'] val = oxm_tlv['value'] orig_field = oxm_tlv['field'] if mask is not None: val = '/'.join((str(val), str(mask))) field = OLD_MATCH_FIELDS.get(orig_field, orig_field) tags[field] = val if field == 'vlan_vid' and mask is None: tags['vlan'] = devid_present(int(val)) return (('flow_packet_count', tags, packet_count), ('flow_byte_count', tags, byte_count))
def match_from_dict(match_dict): kwargs = {} for of_match, field in match_dict.items(): of_match = OLD_MATCH_FIELDS.get(of_match, of_match) test_config_condition(of_match not in MATCH_FIELDS, 'Unknown match field: %s' % of_match) try: encoded_field = MATCH_FIELDS[of_match](field) except TypeError: raise InvalidConfigError('%s cannot be type %s' % (of_match, type(field))) kwargs[of_match] = encoded_field return parser.OFPMatch(**kwargs)
def match_from_dict(match_dict): for old_match, new_match in list(OLD_MATCH_FIELDS.items()): if old_match in match_dict: match_dict[new_match] = match_dict[old_match] del match_dict[old_match] kwargs = {} for of_match, field in list(match_dict.items()): assert of_match in MATCH_FIELDS, 'Unknown match field: %s' % of_match try: encoded_field = MATCH_FIELDS[of_match](field) except TypeError: assert False, '%s cannot be type %s' % (of_match, type(field)) kwargs[of_match] = encoded_field return parser.OFPMatch(**kwargs)
def match_from_dict(match_dict): for old_match, new_match in list(OLD_MATCH_FIELDS.items()): if old_match in match_dict: match_dict[new_match] = match_dict[old_match] del match_dict[old_match] kwargs = {} for of_match, field in list(match_dict.items()): test_config_condition(of_match not in MATCH_FIELDS, 'Unknown match field: %s' % of_match) try: encoded_field = MATCH_FIELDS[of_match](field) except TypeError: raise InvalidConfigError('%s cannot be type %s' % (of_match, type(field))) kwargs[of_match] = encoded_field return parser.OFPMatch(**kwargs)