def __c_ofp_flow_info_serialization(self, resp): flag = 'static' if resp.flags & mul.C_FL_ENT_STATIC else 'dynamic' flag += ' clone' if resp.flags & mul.C_FL_ENT_CLONE else ' no-clone' flag += ' not-verified' if resp.flags & mul.C_FL_ENT_NOT_INST else ' verified' flag += ' local' if resp.flags & mul.C_FL_ENT_LOCAL else ' non-local' flag += ' stale' if resp.flags & mul.C_FL_ENT_STALE else ' clean' flag += ' residual' if resp.flags & mul.C_FL_ENT_RESIDUAL else '' stat = {} if resp.flags & mul.C_FL_ENT_GSTATS: stat = { 'bps': mul.nbapi_parse_bps_to_str(resp.bps), 'pps': mul.nbapi_parse_bps_to_str(resp.pps), 'pkt_count': resp.packet_count, 'byte_count': resp.byte_count, 'alive' : resp.duration_sec } ret = self.__flow_struct_serialization(resp.flow, resp.mask) ret.update({ 'dpid': '0x%lx' % resp.datapath_id, 'flags' : flag, 'priority' : resp.priority, 'stat' : stat }) return ret
def get_flow_stat(self, *args): ret = {} try: dpid = int(args[0], 16) version = mul.nbapi_get_switch_version_with_id( dpid) #int(dpid, 16)) if version == 0: raise Exception, 'no such switch' flow_id = str(args[1]) flow = None #flow = FlowHolder.getInstance().get(flow_id) ret.update({ "flow_id": flow_id, 'bps': mul.nbapi_parse_bps_to_str(flow.bps), 'pps': mul.nbapi_parse_bps_to_str(flow.pps), 'pkt_count': flow.packet_count, 'byte_count': flow.byte_count }) except KeyError: ret.update({ 'error_message': 'Failed to get flow stats', 'reason': 'No such flow_id' }) finally: self.finish(ret)
def __c_ofp_flow_info_serialization(self, resp): flag = 'static' if resp.flags & mul.C_FL_ENT_STATIC else 'dynamic' flag += ' clone' if resp.flags & mul.C_FL_ENT_CLONE else ' no-clone' flag += ' not-verified' if resp.flags & mul.C_FL_ENT_NOT_INST else ' verified' flag += ' local' if resp.flags & mul.C_FL_ENT_LOCAL else ' non-local' flag += ' stale' if resp.flags & mul.C_FL_ENT_STALE else ' clean' flag += ' residual' if resp.flags & mul.C_FL_ENT_RESIDUAL else '' stat = {} if resp.flags & mul.C_FL_ENT_GSTATS: stat = { 'bps': mul.nbapi_parse_bps_to_str(resp.bps), 'pps': mul.nbapi_parse_bps_to_str(resp.pps), 'pkt_count': resp.packet_count, 'byte_count': resp.byte_count, 'alive': resp.duration_sec } ret = self.__flow_struct_serialization(resp.flow, resp.mask) ret.update({ 'dpid': '0x%lx' % resp.datapath_id, 'flags': flag, 'priority': resp.priority, 'stat': stat }) return ret
def __get_switch_flow_stat_with_id(self, dpid, flow_id): ret = {} flow = mask = None try: dpid, flow, mask, prio = self.__flow_id_to_dpid_flow_mask_prio( flow_id) single_flow_list = mul.get_single_flow(int(dpid, 16), flow, mask, int(prio, 16)) if len(single_flow_list) != 1: raise Exception, 'no such flow' resp = single_flow_list[0] if resp.flags & mul.C_FL_ENT_GSTATS: ret = { "flow_id": flow_id, 'bps': mul.nbapi_parse_bps_to_str(resp.bps), 'pps': mul.nbapi_parse_bps_to_str(resp.pps), 'pkt_count': resp.packet_count, 'byte_count': resp.byte_count, 'alive': resp.duration_sec } else: raise Exception, 'this flow disabled' except Exception, e: ret = { 'error_message': 'failed to get flow stats', 'reason': str(e) }
def __get_switch_flow_stat_with_id(self, dpid, flow_id): ret = {} flow = mask = None try: dpid, flow, mask, prio = self.__flow_id_to_dpid_flow_mask_prio(flow_id) single_flow_list = mul.get_single_flow(int(dpid, 16), flow, mask, int(prio, 16)) if len(single_flow_list) != 1: raise Exception, 'no such flow' resp = single_flow_list[0] if resp.flags & mul.C_FL_ENT_GSTATS: ret = { "flow_id": flow_id, 'bps': mul.nbapi_parse_bps_to_str(resp.bps), 'pps': mul.nbapi_parse_bps_to_str(resp.pps), 'pkt_count': resp.packet_count, 'byte_count': resp.byte_count, 'alive' : resp.duration_sec } else: raise Exception, 'this flow disabled' except Exception, e: ret = {'error_message' : 'failed to get flow stats' , 'reason' : str(e)}
def get_flow_stat(self, *args): ret = {} try : dpid = int(args[0], 16) version = mul.nbapi_get_switch_version_with_id(dpid)#int(dpid, 16)) if version == 0: raise Exception, 'no such switch' flow_id = str(args[1]) flow = None #flow = FlowHolder.getInstance().get(flow_id) ret.update({ "flow_id": flow_id, 'bps': mul.nbapi_parse_bps_to_str(flow.bps), 'pps': mul.nbapi_parse_bps_to_str(flow.pps), 'pkt_count': flow.packet_count, 'byte_count': flow.byte_count }) except KeyError: ret.update({'error_message':'Failed to get flow stats', 'reason':'No such flow_id'}) finally: self.finish(ret)