Пример #1
0
 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)
         }
Пример #2
0
 def __get_switch_flow_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
         for resp in single_flow_list:
             #resp = single_flow_list[0]
             ret = {'flow_id': flow_id}
             ret.update(self.__c_ofp_flow_info_serialization(resp))
             ret.update(self.__nbapi_action_serialization(resp))
     except Exception:
         ret = {
             'error_message': 'failed to get flow',
             'reason': 'no such flow'
         }
     finally:
         if flow != None:
             mul.nbapi_flow_free(flow)
         if mask != None:
             mul.nbapi_flow_free(mask)
         return ret
Пример #3
0
 def __get_switch_flow_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
         for resp in single_flow_list:
             #resp = single_flow_list[0]
             ret = {'flow_id' : flow_id}
             ret.update(self.__c_ofp_flow_info_serialization(resp))
             ret.update(self.__nbapi_action_serialization(resp))
     except Exception:
         ret = {'error_message' : 'failed to get flow', 'reason' : 'no such flow'}
     finally:
         if flow != None:
             mul.nbapi_flow_free(flow)
         if mask != None:
             mul.nbapi_flow_free(mask)
         return ret
Пример #4
0
 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)}