예제 #1
0
파일: feature.py 프로젝트: ashang/openmul
 def get_switch_group(self, *args):
     ret = {}
     try:
         dpid = int(args[0], 16 )
         version = mul.nbapi_get_switch_version_with_id(dpid)
         if version == 0:
             raise Exception, 'no such switch'
         elif version == 1:
              raise Exception, 'Not supported switch OFP version'
         res = mul.get_switch_group(dpid)
         if res is None:
             raise Exception, 'cannot get group feature'
         else:
             ret.update({
                 "groups": self.__get_supported_group(res.types),
                 "capability": self.__get_group_capabilities(res.capabilities),
                 "group_all_actions": self.__get_act_type(mul.get_group_act_type(res.actions, mul.OFPGT_ALL)),
                 "group_select_actions": self.__get_act_type(mul.get_group_act_type(res.actions, mul.OFPGT_SELECT)),
                 "group_indirect_actions": self.__get_act_type(mul.get_group_act_type(res.actions, mul.OFPGT_INDIRECT)),
                 "gruop_ff_actions": self.__get_act_type(mul.get_group_act_type(res.actions, mul.OFPGT_FF)),
                 "max_group":    [
                                     {"all": str(int(mul.get_max_group(res.max_groups, mul.OFPGT_ALL)))},
                                     {"select": str(int(mul.get_max_group(res.max_groups,mul.OFPGT_SELECT)))},
                                     {"indirect": str(int(mul.get_max_group(res.max_groups,mul.OFPGT_INDIRECT)))},
                                     {"fast-failover": str(int(mul.get_max_group(res.max_groups,mul.OFPGT_FF)))}
                                 ]
             })
     except Exception, e:
         ret.update({'error_message':'Failed to get group feature','reason':str(e)})
예제 #2
0
 def post(self, dpid=None, group_id=None):
     logger.debug("requst url - %s", self.get_request_uri())
     logger.debug("requst params - dpid : %s, group_id: %s", dpid, group_id)
     ret = {}
     body = None
     group = None
     mdata_list = []
     act_len = 0
     try:
         version = mul.nbapi_get_switch_version_with_id(int(dpid, 16))
         if version == 0:
             raise Exception, 'no such switch'
         elif version == 1:
             raise Exception, 'Not supported switch OFP version'
         body = GroupSchema().deserialize(json.loads(self.request.body))
         group = mul.prepare_add_group(str(body['group_id']), str(body['type']))
         for action_bucket in body['action_buckets']:
             mdata = mul.nbapi_group_mdata_alloc(int(dpid, 16))
             if mdata is None:
                 raise Exception, 'failed to set mdata'
             mdata_list.append(mdata)
             for action in action_bucket['actions']:
                 check = mul.nbapi_action_to_mdata(mdata, str(action['action']), str(action['value']))
                 if check is not 0:
                     raise Exception, 'Malformed action data '+str(action['action'])+" : "+str(action['value'])
             mul.nbapi_group_action_add(act_len, group, mdata, str(action_bucket['weight']), str(action_bucket['ff_port']), str(action_bucket['ff_group']))
             act_len +=1
         check = mul.nbapi_group_add(act_len, int(dpid, 16), group)
         if check == 0:
             ret.update({"group_id" : str(body['group_id'])})
         else:
             raise Exception, 'failed to add group'
     except Exception, e:
         ret.update({"error_message" : "failed to add group", "reason" : str(e)})
예제 #3
0
 def post(self, dpid=None, group_id=None):
     logger.debug("requst url - %s", self.get_request_uri())
     logger.debug("requst params - dpid : %s, group_id: %s", dpid, group_id)
     ret = {}
     body = None
     group = None
     mdata_list = []
     act_len = 0
     try:
         version = mul.nbapi_get_switch_version_with_id(int(dpid, 16))
         if version == 0:
             raise Exception, 'no such switch'
         elif version == 1:
             raise Exception, 'Not supported switch OFP version'
         body = GroupSchema().deserialize(json.loads(self.request.body))
         group = mul.prepare_add_group(str(body['group_id']), str(body['type']))
         for action_bucket in body['action_buckets']:
             mdata = mul.nbapi_group_mdata_alloc(int(dpid, 16))
             if mdata is None:
                 raise Exception, 'failed to set mdata'
             mdata_list.append(mdata)
             for action in action_bucket['actions']:
                 check = mul.nbapi_action_to_mdata(mdata, str(action['action']), str(action['value']))
                 if check is not 0:
                     raise Exception, 'Malformed action data '+str(action['action'])+" : "+str(action['value'])
             mul.nbapi_group_action_add(act_len, group, mdata, str(action_bucket['weight']), str(action_bucket['ff_port']), str(action_bucket['ff_group']))
             act_len +=1
         check = mul.nbapi_group_add(act_len, int(dpid, 16), group)
         if check == 0:
             ret.update({"group_id" : str(body['group_id'])})
         else:
             raise Exception, 'failed to add group'
     except Exception, e:
         ret.update({"error_message" : "failed to add group", "reason" : str(e)})
예제 #4
0
 def __get_port_stat(self, dpid, port_no):
     ret = {}
     version = mul.nbapi_get_switch_version_with_id(dpid)
     if version == 0:
         raise Exception, 'no such switch'
     elif version == 0x1:
         port_stat = mul.show_port_stats(dpid, port_no)
         ret = self.__port_serialization(port_stat)
     elif version == 0x4:
         port_stat = mul.show_port_stats131(dpid, port_no)
         ret = self.__port_serialization131(port_stat)
     elif version == 0x5:
         port_stat = mul.show_port_stats140(dpid, port_no)
         ret = self.__port_serialization140(port_stat)
         prop_type = mul.get_ofp140_port_stats_prop_type(port_stat)
         if prop_type == -1:  #no
             pass
         elif prop_type == mul.OFPPSPT_ETHERNET:  #0
             eth_prop = mul.show_ofp_port_stats_prop_ethernet(port_stat)
             ret.update(self.__port_eth_prop_serialization(eth_prop))
         elif prop_type == OFPPSPT_OPTICAL:  #1
             opt_prop = mul.show_ofp_port_stats_prop_optical(port_stat)
             ret.update(self.__port_opt_prop_serialization(opt_prop))
         else:
             pass
     if ret is None:
         raise Exception, 'No such port on switch'
     return ret
예제 #5
0
    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)
예제 #6
0
파일: stats.py 프로젝트: ashang/openmul
 def __get_port_stat(self, dpid, port_no):
     ret = {}
     version = mul.nbapi_get_switch_version_with_id(dpid)
     if version == 0:
         raise Exception, 'no such switch'
     elif version == 0x1:
         port_stat = mul.show_port_stats(dpid, port_no)
         ret = self.__port_serialization(port_stat)
     elif version == 0x4:
         port_stat = mul.show_port_stats131(dpid, port_no)
         ret = self.__port_serialization131(port_stat)
     elif version == 0x5:
         port_stat = mul.show_port_stats140(dpid, port_no)
         ret = self.__port_serialization140(port_stat)
         prop_type = mul.get_ofp140_port_stats_prop_type(port_stat)
         if prop_type == -1:#no
             pass
         elif prop_type == mul.OFPPSPT_ETHERNET:#0
             eth_prop = mul.show_ofp_port_stats_prop_ethernet(port_stat)
             ret.update(self.__port_eth_prop_serialization(eth_prop))
         elif prop_type == OFPPSPT_OPTICAL:#1
             opt_prop = mul.show_ofp_port_stats_prop_optical(port_stat)
             ret.update(self.__port_opt_prop_serialization(opt_prop))
         else:
             pass
     if ret is None:
         raise Exception, 'No such port on switch'
     return ret
예제 #7
0
 def get_switch_meter(self, *args):
     ret = {}
     try:
         dpid = int(args[0], 16)
         version = mul.nbapi_get_switch_version_with_id(dpid)
         if version == 0:
             raise Exception, 'no such switch'
         if version == 1:
             raise Exception, 'Not supported switch OFP version'
         res = mul.get_switch_meter(dpid)
         if res:
             #bands = mul.get_band_type(res.band_types)
             #flags = mul.get_band_flag(res.capabilities)
             ret.update({
                 "max-meter": res.max_meter,
                 "bands": self.__get_band_type(res.band_types),
                 "flags": self.__get_band_flag(res.capabilities),
                 "max-bands": res.max_bands,
                 "max-color": res.max_color
             })
         else:
             raise Exception, 'cannot get meter feature'
     except Exception, e:
         ret.update({
             'error_message': 'failed to get meter feature',
             'reason': str(e)
         })
예제 #8
0
파일: stats.py 프로젝트: iamyaw/openmul
    def get_port_stat(self, *args):
        ret = {}
        try:
            dpid = args[0]
            version = mul.nbapi_get_switch_version_with_id(int(dpid, 16))
            if version == 0:
                raise Exception, 'no such switch'
            port_no = int(args[1])
            port_stat = mul.show_port_stats(int(dpid,16), port_no)

            if port_stat:
                ret.update({
                    'port_no':       port_stat.port_no,
                    'rx_packets':    port_stat.rx_packets,
                    'tx_packets':    port_stat.tx_packets,
                    'rx_bytes':      port_stat.rx_bytes,
                    'tx_bytes':      port_stat.tx_bytes,
                    'rx_dropped':    port_stat.rx_dropped,
                    'tx_dropped':    port_stat.tx_dropped,
                    'rx_errors':     port_stat.rx_errors,
                    'tx_errors':     port_stat.tx_errors,
                    'rx_frame_err':  port_stat.rx_frame_err,
                    'rx_over_err':   port_stat.rx_over_err,
                    'rx_crc_err':    port_stat.rx_crc_err,
                    'collisions':    port_stat.collisions,
                    'duration_sec':  port_stat.duration_sec,
                    'duration_nsec': port_stat.duration_nsec
                })
            else:
                raise Exception, 'No such port on switch'
        except Exception, e:
            ret.update({'error_message' : 'Failed to get port stat', 'reason' : str(e)})
예제 #9
0
파일: feature.py 프로젝트: ashang/openmul
    def get_switch_table(self, *args):
        ret = {}
        try:
            dpid = int(args[0], 16)
            version = mul.nbapi_get_switch_version_with_id(dpid)
            if version == 0:
                raise Exception, 'no such switch'
            table_no = int(args[1], 0)
            table = mul.get_switch_table(dpid, table_no)
            if table:
                ret.update({
                    "tables" : {
                        "match" : self.__get_beem_match(),
                        "instruction": self.__get_table_bminstruction(table.bm_inst),
                        "instruction_miss": self.__get_table_bminstruction(table.bm_inst_miss),
                        "next_table": self.__get_table_next_tables(table.bm_next_tables),
                        "next_table_miss": self.__get_table_next_tables(table.bm_next_tables_miss),
                        "WRITE_ACTIONS": self.__get_act_type(table.bm_wr_actions)+self.__get_beem_general_action(),
                        "WRITE_ACTIONS_miss": self.__get_act_type(table.bm_wr_actions_miss),
                        "APPLY_ACTIONS": self.__get_act_type(table.bm_app_actions)+self.__get_beem_general_action(),
                        "APPLY_ACTIONS_miss": self.__get_act_type(table.bm_app_actions_miss),
                        "set_field": self.__get_table_set_field(table.bm_wr_set_field),
                        "set_field_miss": self.__get_table_set_field(table.bm_wr_set_field_miss),
                        "apply_set_field": self.__get_table_set_field(table.bm_app_set_field),
                        "apply_set_field_miss": self.__get_table_set_field(table.bm_app_set_field_miss)
                }
            })
            else:
                #raise Exception, 'cannot get table feature' if no table feature, suppose as mininet
                ret.update({
                    "tables" : {
                        "match" : self.__get_beem_match(),
                        "instruction": self.__get_table_bminstruction(62),
                        "instruction_miss": [],#self.__get_table_bminstruction(0),
                        "next_table": ['%d' %(i+table_no) for i in range(255-table_no)],#self.__get_table_next_tables(table.bm_next_tables),
                        "next_table_miss": [],#self.__get_table_next_tables(table.bm_next_tables_miss),
                        "WRITE_ACTIONS": self.__get_act_type(234854401)+self.__get_beem_general_action(),
                        "WRITE_ACTIONS_miss": [],#self.__get_act_type(table.bm_wr_actions_miss),
                        "APPLY_ACTIONS": self.__get_act_type(234854401)+self.__get_beem_general_action(),
                        "APPLY_ACTIONS_miss": [],#self.__get_act_type(table.bm_app_actions_miss),
                        "set_field": [],#self.__get_table_set_field(table.bm_wr_set_field),
                        "set_field_miss": [],#self.__get_table_set_field(table.bm_wr_set_field_miss),
                        "apply_set_field": [],#self.__get_table_set_field(table.bm_app_set_field),
                        "apply_set_field_miss": []#self.__get_table_set_field(table.bm_app_set_field_miss)
                }

                })
        except Exception, e:
            ret.update({'error_message':'Falied to get table feature','reason':str(e)})
예제 #10
0
    def post(self, dpid=None, meter_id=None):
        logger.debug("request url - %s", self.get_request_uri())
        logger.debug("request params - dpid: %s, meter_id: %s",dpid, meter_id)
        body = None
        m_parms = None
        act_len = 0
        mdata_arr = []
        ret = {}
        try:
            version = mul.nbapi_get_switch_version_with_id(int(dpid, 16))
            if version == 0:
                raise Exception, 'no such switch'
            elif version == 1:
                raise Exception, 'Not supported switch OFP version'

            body = MeterSchema().deserialize(json.loads(self.request.body))
            logger.debug(str(body))

            m_parms = mul.prepare_add_meter(str(body["meter_id"]),
                                            str(body["type"]),
                                             str(body["burst"]),
                                            str(body["stats"]))
            if m_parms == None:
                raise Exception, 'malfomed input data'
            for meter_band in body["meter_bands"]:
                mdata = mul.nbapi_meter_band_add(int(dpid, 16),
                                                 act_len,
                                                 m_parms,
                                                 str(meter_band['band_type']),
                                                 str(meter_band['rate']),
                                                 str(meter_band['burst_size']),
                                                 str(meter_band['prec_level']))
                if mdata == None:
                    raise Exception, 'Malfomed meter band data'                    
                else:
                    mdata_arr.append(mdata)
                    act_len += 1

            check = mul.nbapi_meter_add(act_len,
                                    int(dpid, 16),
                                    m_parms)

            if check == 0:
                ret.update({ "meter_id" : body['meter_id'] })
            else:
                raise Exception, 'meter already exist'
        except Exception, e:
            ret.update({'error_message' : 'Failed to add meter', 'reason' : str(e)})
예제 #11
0
 def __get_switch_meter(self, dpid):
     ret = {}
     res = []
     try:
         version = mul.nbapi_get_switch_version_with_id(int(dpid, 16))
         if version == 0:
             raise Exception, 'no such switch'
         if version == 1:
             raise Exception, 'Not supported switch OPF version'
         try:
             meters = mul.get_meter(int(dpid, 16))
         except:
             meters = []
         for meter in meters:
             m_dict = self.__c_ofp_meter_mod_serialization(meter)
             res.append(m_dict)
         ret.update({'meters' : res})
     except Exception, e:
         ret.update({'error_message' : 'Failed to get meter', 'reason':str(e)})
예제 #12
0
 def __get_switch_group(self, dpid):
     ret = {}
     try :
         version = mul.nbapi_get_switch_version_with_id(int(dpid,16))
         if version == 1:
             raise Exception, 'Not supported switch OFP version'
         elif version == 0:
             raise Exception, 'no such switch'
         ret = {}
         try:
             groups = mul.get_group(int(dpid, 16))
         except:
             groups = []
         g_list = []
         for group in groups:
             g_dict = self.__c_ofp_group_mod_serialization(group)
             g_list.append(g_dict)
         ret = {"groups" : g_list }
     except Exception, e:
         ret = {'error_message' : 'Failed to get group', 'reason' : str(e)}
예제 #13
0
 def __get_switch_group(self, dpid):
     ret = {}
     try :
         version = mul.nbapi_get_switch_version_with_id(int(dpid,16))
         if version == 1:
             raise Exception, 'Not supported switch OFP version'
         elif version == 0:
             raise Exception, 'no such switch'
         ret = {}
         try:
             groups = mul.get_group(int(dpid, 16))
         except:
             groups = []
         g_list = []
         for group in groups:
             g_dict = self.__c_ofp_group_mod_serialization(group)
             g_list.append(g_dict)
         ret = {"groups" : g_list }
     except Exception, e:
         ret = {'error_message' : 'Failed to get group', 'reason' : str(e)}
예제 #14
0
파일: stats.py 프로젝트: ashang/openmul
    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)
예제 #15
0
파일: feature.py 프로젝트: ashang/openmul
 def get_switch_meter(self, *args):
     ret = {}
     try:
         dpid = int(args[0], 16)
         version = mul.nbapi_get_switch_version_with_id(dpid)
         if version == 0:
             raise Exception, 'no such switch'
         if version == 1:
             raise Exception, 'Not supported switch OFP version'
         res = mul.get_switch_meter(dpid)
         if res:
             #bands = mul.get_band_type(res.band_types)
             #flags = mul.get_band_flag(res.capabilities)
             ret.update({
                 "max-meter" : res.max_meter,
                 "bands"     : self.__get_band_type(res.band_types),    
                 "flags"     : self.__get_band_flag(res.capabilities),
                 "max-bands" : res.max_bands,
                 "max-color" : res.max_color
             })
         else:
             raise Exception, 'cannot get meter feature'
     except Exception, e:
         ret.update({'error_message' : 'failed to get meter feature', 'reason' : str(e)})
예제 #16
0
파일: flowtable.py 프로젝트: iamyaw/openmul
    def post(self, dpid, flow_id=None):
        logger.debug("requset url - %s", self.get_request_uri())
        logger.debug("request params - dpid: %s, flow_id: %s", dpid, flow_id)
        ret = {} 
        flow = mask = mdata = None
        new_flow_id = None
        try:
            body = FlowSchema().deserialize(json.loads(self.request.body))
            logger.debug(str(body))
            version = int(mul.nbapi_get_switch_version_with_id(int(dpid,16)))
            if int(version)==0:
                raise Exception, 'switch does not exist'
            self.__match_check(version, body)
            self.__inst_action_check(version, body) 
            nw_src = str(body['nw_src']) if int(body['dl_type'], 16) != 0x86dd else str(body['nw_src6'])
            nw_dst = str(body['nw_dst']) if int(body['dl_type'], 16) != 0x86dd else str(body['nw_dst6'])
            flow = mul.nbapi_make_flow(str(body['dl_src']) , 
                                       str(body['dl_dst']) ,
                                       str(body['dl_type']) ,
                                       str(body['dl_vlan']) ,
                                       str(body['dl_vlan_pcp']),
                                       str(body['mpls_label']),
                                       str(body['mpls_tc']) ,
                                       str(body['mpls_bos']) ,
                                       nw_dst,
                                       nw_src,
                                       str(body['nw_proto']), 
                                       str(body['nw_tos']) ,
                                       str(body['tp_dst']) ,
                                       str(body['tp_src']) ,
                                       str(body['in_port']) ,
                                       str(body['table_id']) )
            if flow == None:
                raise Exception, 'flow failed to alloc'
            mask = mul.nbapi_make_mask( str(body['dl_src']),
                                        str(body['dl_dst']), 
                                        str(body['dl_type']),
                                        str(body['dl_vlan']), 
                                        str(body['dl_vlan_pcp']), 
                                        str(body['mpls_label']), 
                                        str(body['mpls_tc']),
                                        str(body['mpls_bos']),
                                        nw_dst,
                                        nw_src,
                                        str(body['nw_proto']),
                                        str(body['nw_tos']),
                                        str(body['tp_dst']),
                                        str(body['tp_src']),
                                        str(body['in_port']))
            if mask == None:
                raise Exception, 'mask failed to alloc'
            mdata = mul.nbapi_mdata_alloc(int(dpid, 16))
            if mdata == None:
                raise Exception, 'cannot set mdata'
            drop = check = 0
            for instruction in body['instructions']:
                if instruction['instruction'] == 'APPLY_ACTIONS':
                    if version != 1:
                        check = mul.nbapi_mdata_inst_apply(mdata)
                elif instruction['instruction'] == 'WRITE_ACTIONS':
                    check = mul.nbapi_mdata_inst_write(mdata)
                elif instruction['instruction'] == 'METER':
                    check = mul.nbapi_mdata_inst_meter(mdata, int(instruction['value']))
                elif instruction['instruction'] == 'GOTO_TABLE':
                    check = mul.nbapi_mdata_inst_goto(mdata, int(instruction['value']))

                if check != 0:
                    raise Exception, 'failed to set'+str(instruction['instruction'])

                check = -1
                for action in instruction['actions']:
                    if 'DROP' == str(action['action']):
                        drop = 1
                        check = 0
                    else:
                        check = mul.nbapi_action_to_mdata(mdata, str(action['action']), str(action['value']))
                if check != 0:
                    raise Exception, 'Malformed action data'+action['action']+' : '+action['value']+str(check)

            flags = mul.C_FL_ENT_STATIC
            if str(body['barrier']) != 'disable':
                flags |= mul.C_FL_ENT_BARRIER

            if str(body['stat']) != 'disable':
                flags |= mul.C_FL_ENT_GSTATS

            check = mul.add_static_flow(int(dpid, 16),
                                        flow,
                                        mask,
                                        int(body['priority']),
                                        mdata,
                                        flags,
                                        drop)
            if check == 0:
                sleep(0.5)
                new_flow_id = self.__make_flow_id(int(dpid,16), flow, mask, int(body['priority']))
                #new_flow_id = self.__check_flow_realy_in_switch(int(dpid, 16), flow, mask, int(body['priority']))
                #new_flow_id = FlowHolder.getInstance().save(int(dpid,16) , flow, mask, int(body['priority']))
                #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)})
예제 #17
0
 def get_switch_group(self, *args):
     ret = {}
     try:
         dpid = int(args[0], 16)
         version = mul.nbapi_get_switch_version_with_id(dpid)
         if version == 0:
             raise Exception, 'no such switch'
         elif version == 1:
             raise Exception, 'Not supported switch OFP version'
         res = mul.get_switch_group(dpid)
         if res is None:
             raise Exception, 'cannot get group feature'
         else:
             ret.update({
                 "groups":
                 self.__get_supported_group(res.types),
                 "capability":
                 self.__get_group_capabilities(res.capabilities),
                 "group_all_actions":
                 self.__get_act_type(
                     mul.get_group_act_type(res.actions, mul.OFPGT_ALL)),
                 "group_select_actions":
                 self.__get_act_type(
                     mul.get_group_act_type(res.actions, mul.OFPGT_SELECT)),
                 "group_indirect_actions":
                 self.__get_act_type(
                     mul.get_group_act_type(res.actions,
                                            mul.OFPGT_INDIRECT)),
                 "gruop_ff_actions":
                 self.__get_act_type(
                     mul.get_group_act_type(res.actions, mul.OFPGT_FF)),
                 "max_group": [{
                     "all":
                     str(
                         int(
                             mul.get_max_group(res.max_groups,
                                               mul.OFPGT_ALL)))
                 }, {
                     "select":
                     str(
                         int(
                             mul.get_max_group(res.max_groups,
                                               mul.OFPGT_SELECT)))
                 }, {
                     "indirect":
                     str(
                         int(
                             mul.get_max_group(res.max_groups,
                                               mul.OFPGT_INDIRECT)))
                 }, {
                     "fast-failover":
                     str(
                         int(mul.get_max_group(res.max_groups,
                                               mul.OFPGT_FF)))
                 }]
             })
     except Exception, e:
         ret.update({
             'error_message': 'Failed to get group feature',
             'reason': str(e)
         })
예제 #18
0
 def get_switch_table(self, *args):
     ret = {}
     try:
         dpid = int(args[0], 16)
         version = mul.nbapi_get_switch_version_with_id(dpid)
         if version == 0:
             raise Exception, 'no such switch'
         table_no = int(args[1], 0)
         table = mul.get_switch_table(dpid, table_no)
         if table:
             ret.update({
                 "tables": {
                     "match":
                     self.__get_beem_match(),
                     "instruction":
                     self.__get_table_bminstruction(table.bm_inst),
                     "instruction_miss":
                     self.__get_table_bminstruction(table.bm_inst_miss),
                     "next_table":
                     self.__get_table_next_tables(table.bm_next_tables),
                     "next_table_miss":
                     self.__get_table_next_tables(
                         table.bm_next_tables_miss),
                     "WRITE_ACTIONS":
                     self.__get_act_type(table.bm_wr_actions) +
                     self.__get_beem_general_action(),
                     "WRITE_ACTIONS_miss":
                     self.__get_act_type(table.bm_wr_actions_miss),
                     "APPLY_ACTIONS":
                     self.__get_act_type(table.bm_app_actions) +
                     self.__get_beem_general_action(),
                     "APPLY_ACTIONS_miss":
                     self.__get_act_type(table.bm_app_actions_miss),
                     "set_field":
                     self.__get_table_set_field(table.bm_wr_set_field),
                     "set_field_miss":
                     self.__get_table_set_field(table.bm_wr_set_field_miss),
                     "apply_set_field":
                     self.__get_table_set_field(table.bm_app_set_field),
                     "apply_set_field_miss":
                     self.__get_table_set_field(table.bm_app_set_field_miss)
                 }
             })
         else:
             #raise Exception, 'cannot get table feature' if no table feature, suppose as mininet
             ret.update({
                 "tables": {
                     "match":
                     self.__get_beem_match(),
                     "instruction":
                     self.__get_table_bminstruction(62),
                     "instruction_miss":
                     [],  #self.__get_table_bminstruction(0),
                     "next_table": [
                         '%d' % (i + table_no)
                         for i in range(255 - table_no)
                     ],  #self.__get_table_next_tables(table.bm_next_tables),
                     "next_table_miss":
                     [],  #self.__get_table_next_tables(table.bm_next_tables_miss),
                     "WRITE_ACTIONS":
                     self.__get_act_type(234854401) +
                     self.__get_beem_general_action(),
                     "WRITE_ACTIONS_miss":
                     [],  #self.__get_act_type(table.bm_wr_actions_miss),
                     "APPLY_ACTIONS":
                     self.__get_act_type(234854401) +
                     self.__get_beem_general_action(),
                     "APPLY_ACTIONS_miss":
                     [],  #self.__get_act_type(table.bm_app_actions_miss),
                     "set_field":
                     [],  #self.__get_table_set_field(table.bm_wr_set_field),
                     "set_field_miss":
                     [],  #self.__get_table_set_field(table.bm_wr_set_field_miss),
                     "apply_set_field":
                     [],  #self.__get_table_set_field(table.bm_app_set_field),
                     "apply_set_field_miss": [
                     ]  #self.__get_table_set_field(table.bm_app_set_field_miss)
                 }
             })
     except Exception, e:
         ret.update({
             'error_message': 'Falied to get table feature',
             'reason': str(e)
         })