def ofp_flow_stats_to_loxi_flow_stats(pb): kw = pb2dict(pb) def make_loxi_instruction(inst): type = inst['type'] if type == pb2.OFPIT_APPLY_ACTIONS: return of13.instruction.apply_actions(actions=[ make_loxi_action(a) for a in inst['actions']['actions'] ]) elif type == pb2.OFPIT_CLEAR_ACTIONS: return of13.instruction.clear_actions() elif type == pb2.OFPIT_GOTO_TABLE: return of13.instruction.goto_table( table_id=inst['goto_table']['table_id']) elif type == pb2.OFPIT_WRITE_ACTIONS: return of13.instruction.write_actions(actions=[ make_loxi_action(a) for a in inst['actions']['actions'] ]) elif type == pb2.OFPIT_WRITE_METADATA: return of13.instruction.write_metadata( metadata=inst['write_metadata']['metadata']) elif type == pb2.OFPIT_METER: return of13.instruction.meter(meter_id=inst['meter']['meter_id']) else: raise NotImplementedError('Instruction type %d' % type) kw['match'] = make_loxi_match(kw['match']) # if the flow action is drop, then the instruction is not found in the dict if 'instructions' in kw: kw['instructions'] = [ make_loxi_instruction(i) for i in kw['instructions'] ] del kw['id'] return of13.flow_stats_entry(**kw)
def flow_stats_entry_from_flow_mod_message(fmm): assert isinstance(fmm, ofp.message.flow_mod) # extract a flow stats entry from a flow_mod message kw = fmm.__dict__ # drop these from the object for k in ('xid', 'cookie_mask', 'out_port', 'buffer_id', 'out_group'): del kw[k] flow = ofp.flow_stats_entry(duration_sec=0, duration_nsec=0, packet_count=0, byte_count=0, **kw) return flow
def flow_stats_entry_from_flow_mod_message(fmm): assert isinstance(fmm, ofp.message.flow_mod) # extract a flow stats entry from a flow_mod message kw = fmm.__dict__ # drop these from the object for k in ('xid', 'cookie_mask', 'out_port', 'buffer_id', 'out_group'): del kw[k] flow = ofp.flow_stats_entry( duration_sec=0, duration_nsec=0, packet_count=0, byte_count=0, **kw ) return flow
def ofp_flow_stats_to_loxi_flow_stats(pb): kw = pb2dict(pb) def make_loxi_instruction(inst): type = inst['type'] if type == pb2.OFPIT_APPLY_ACTIONS: return of13.instruction.apply_actions( actions=[make_loxi_action(a) for a in inst['actions']['actions']]) elif type == pb2.OFPIT_GOTO_TABLE: return of13.instruction.goto_table( table_id=inst['goto_table']['table_id']) else: raise NotImplementedError('Instruction type %d' % type) kw['match'] = make_loxi_match(kw['match']) kw['instructions'] = [make_loxi_instruction(i) for i in kw['instructions']] del kw['id'] return of13.flow_stats_entry(**kw)