def fix_parsed(m): """ Translate parsed packet data to dicts and stuff """ if m is None: return {"type": "raw", "data": []} if isinstance(m, basestring): return {"type": "raw", "data": [ord(b) for b in m]} assert isinstance(m, packet_base) if not m.parsed: u = fix_parsed(m.raw) u['unparsed_type'] = m.__class__.__name__ return u r = {} for k, v in fields_of(m, primitives_only=False).iteritems(): if is_scalar(v): r[k] = v elif isinstance(v, (IPAddr, EthAddr)): r[k] = str(v) if hasattr(m, "payload"): r['payload'] = fix_parsed(m.payload) if 'raw' in r: #r['raw'] = [ord(b) for b in m['raw']] del r['raw'] if 'next' in r: del r['next'] r['type'] = m.__class__.__name__ return r
def fix_parsed (m): """ Translate parsed packet data to dicts and stuff """ if m is None: return {"type":"raw","data":[]} if isinstance(m, basestring): return {"type":"raw","data":[ord(b) for b in m]} assert isinstance(m, packet_base) if not m.parsed: u = fix_parsed(m.raw) u['unparsed_type'] = m.__class__.__name__ return u r = {} for k,v in fields_of(m, primitives_only = False).iteritems(): if is_scalar(v): r[k] = v elif isinstance(v, (IPAddr, EthAddr)): r[k] = str(v) if hasattr(m, "payload"): r['payload'] = fix_parsed(m.payload) if 'raw' in r: #r['raw'] = [ord(b) for b in m['raw']] del r['raw'] if 'next' in r: del r['next'] r['type'] = m.__class__.__name__ return r
def fix_parsed (m): """ Translate parsed packet data to dicts and stuff """ if m is None: return {"type":"raw","data":[]} if isinstance(m, basestring): """ Dada uma cadeia de comprimento um, retornar um inteiro representando o ponto de código Unicode do caractere quando o argumento é um objeto unicode, ou o valor do byte quando o argumento é uma string de 8 bits. """ return {"type":"raw","data":[ord(b) for b in m]} assert isinstance(m, packet_base) if not m.parsed: u = fix_parsed(m.raw) u['unparsed_type'] = m.__class__.__name__ return u r = {} for k,v in fields_of(m, primitives_only = False).iteritems(): if is_scalar(v): r[k] = v elif isinstance(v, (IPAddr, EthAddr)): r[k] = str(v) if hasattr(m, "payload"): r['payload'] = fix_parsed(m.payload) if 'raw' in r: #r['raw'] = [ord(b) for b in m['raw']] del r['raw'] if 'next' in r: del r['next'] r['type'] = m.__class__.__name__ return r
def action_to_dict(a): d = {} d['type'] = of.ofp_action_type_map.get(a.type, a.type) for k, v in fields_of(a).iteritems(): if k in ['type', 'length']: continue if k == "port": v = of.ofp_port_map.get(v, v) d[k] = v return d
def action_to_dict (a): d = {} d['type'] = of.ofp_action_type_map.get(a.type, a.type) for k,v in fields_of(a).iteritems(): if k in ['type','length']: continue if k == "port": v = of.ofp_port_map.get(v,v) d[k] = v return d
def action_to_dict (a): d = {} "ofp_action_type: A máscara de bits usa os valores de ofp_action_type como o número de bits a deslocar esquerda para uma ação associada ." d['type'] = of.ofp_action_type_map.get(a.type, a.type) for k,v in fields_of(a).iteritems(): if k in ['type','length']: continue if k == "port": v = of.ofp_port_map.get(v,v) d[k] = v return d
def flow_stats_to_list(flowstats): """ Takes a list of flow stats """ stats = [] for stat in flowstats: s = {} stats.append(s) for k, v in fields_of(stat).iteritems(): if k == 'length': continue if k.startswith('pad'): continue if k == 'match': v = match_to_dict(v) elif k == 'actions': v = [action_to_dict(a) for a in v] s[k] = v return stats
def flow_stats_to_list (flowstats): """ Takes a list of flow stats """ stats = [] for stat in flowstats: s = {} stats.append(s) for k,v in fields_of(stat).iteritems(): if k == 'length': continue if k.startswith('pad'): continue if k == 'match': v = match_to_dict(v) elif k == 'actions': v = [action_to_dict(a) for a in v] s[k] = v return stats