コード例 #1
0
ファイル: flowtable.py プロジェクト: Carson220/openmul
 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
コード例 #2
0
ファイル: flowtable.py プロジェクト: iamyaw/openmul
 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
ファイル: flowtable.py プロジェクト: iamyaw/openmul
                #if new_flow_id == None:
                #    raise Exception, 'this flow is rejected by switch'
                if flow_id and flow_id!=new_flow_id:
                    ret = self.delete(None, flow_id)
                else:
                    ret = { 'flow_id' : str(new_flow_id) }
            else:
                raise Exception, 'flow already exist'

        except Exception, e:
            ret.update({"error_message" : "failed to add flow!", "reason" : str(e)})
        finally:
            if mdata != None:
                mul.nbapi_mdata_free(mdata)
            if flow != None:
                mul.nbapi_flow_free(flow)
            if mask != None:
                mul.nbapi_flow_free(mask)
            if flow_id:
                if 'error' not in str(ret):#delete success. now ret={flow_id:deleted_flow_id}
                    ret = {'flow_id' : str(new_flow_id)}#change to ret = {flow_id:added_flow_id}
            self.finish(ret)

    def put(self, dpid=None, flow_id=None):
        pass

    def delete(self, dpid=None, flow_id=None):
        ret = {}
        try:
            that_flow_id=None
            flow_list = mul.get_flow(int(dpid, 16))
コード例 #4
0
ファイル: flowtable.py プロジェクト: Carson220/openmul
                    '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)
            }
        finally:
            if flow != None:
                mul.nbapi_flow_free(flow)
            if mask != None:
                mul.nbapi_flow_free(mask)
            return 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 = {