<s> from ryu . ofproto . oxx_fields import ( <EOL> _from_user , <EOL> _from_user_header , <EOL> _to_user , <EOL> _to_user_header , <EOL> _field_desc , <EOL> _normalize_user , <EOL> _parse , <EOL> _parse_header , <EOL> _serialize , <EOL> _serialize_header ) <EOL> from ryu . ofproto import ofproto_common <EOL> OFPXMC_NXM_0 = <NUM_LIT:0> <EOL> OFPXMC_NXM_1 = <NUM_LIT:1> <EOL> OFPXMC_OPENFLOW_BASIC = <NUM_LIT> <EOL> OFPXMC_PACKET_REGS = <NUM_LIT> <EOL> OFPXMC_EXPERIMENTER = <NUM_LIT> <EOL> class _OxmClass ( object ) : <EOL> def __init__ ( self , name , num , type_ ) : <EOL> self . name = name <EOL> self . oxm_field = num <EOL> self . oxm_type = num | ( self . _class << <NUM_LIT:7> ) <EOL> self . num = self . oxm_type <EOL> self . type = type_ <EOL> class OpenFlowBasic ( _OxmClass ) : <EOL> _class = OFPXMC_OPENFLOW_BASIC <EOL> class PacketRegs ( _OxmClass ) : <EOL> _class = OFPXMC_PACKET_REGS <EOL> class _Experimenter ( _OxmClass ) : <EOL> _class = OFPXMC_EXPERIMENTER <EOL> def __init__ ( self , name , num , type_ ) : <EOL> super ( _Experimenter , self ) . __init__ ( name , num , type_ ) <EOL> self . num = ( self . experimenter_id , self . oxm_type ) <EOL> self . exp_type = self . oxm_field <EOL> class ONFExperimenter ( _Experimenter ) : <EOL> experimenter_id = ofproto_common . ONF_EXPERIMENTER_ID <EOL> class OldONFExperimenter ( _Experimenter ) : <EOL> experimenter_id = ofproto_common . ONF_EXPERIMENTER_ID <EOL> def __init__ ( self , name , num , type_ ) : <EOL> super ( OldONFExperimenter , self ) . __init__ ( name , <NUM_LIT:0> , type_ ) <EOL> self . num = ( self . experimenter_id , num ) <EOL> self . exp_type = <NUM_LIT> <EOL> class NiciraExperimenter ( _Experimenter ) : <EOL> experimenter_id = ofproto_common . NX_EXPERIMENTER_ID <EOL> class NiciraExtended0 ( _OxmClass ) : <EOL> """<STR_LIT>""" <EOL> _class = OFPXMC_NXM_0 <EOL> class NiciraExtended1 ( _OxmClass ) : <EOL> """<STR_LIT>""" <EOL> _class = OFPXMC_NXM_1 <EOL> def generate ( modname ) : <EOL> import sys <EOL> import functools <EOL> mod = sys . modules [ modname ] <EOL> def add_attr ( k , v ) : <EOL> setattr ( mod , k , v ) <EOL> for i in mod . oxm_types : <EOL> if isinstance ( i . num , tuple ) : <EOL> continue <EOL> if i . _class != OFPXMC_OPENFLOW_BASIC : <EOL> continue <EOL> uk = i . name . upper ( ) <EOL> ofpxmt = i . oxm_field <EOL> td = i . type <EOL> add_attr ( '<STR_LIT>' + uk , ofpxmt ) <EOL> add_attr ( '<STR_LIT>' + uk , mod . oxm_tlv_header ( ofpxmt , td . size ) ) <EOL> add_attr ( '<STR_LIT>' + uk + '<STR_LIT>' , mod . oxm_tlv_header_w ( ofpxmt , td . size ) ) <EOL> oxx = '<STR_LIT>' <EOL> name_to_field = dict ( ( f . name , f ) for f in mod . oxm_types ) <EOL> num_to_field = dict ( ( f . num , f ) for f in mod . oxm_types ) <EOL> add_attr ( '<STR_LIT>' , <EOL> functools . partial ( _from_user , oxx , name_to_field ) ) <EOL> add_attr ( '<STR_LIT>' , <EOL> functools . partial ( _from_user_header , oxx , name_to_field ) ) <EOL> add_attr ( '<STR_LIT>' , <EOL> functools . partial ( _to_user , oxx , num_to_field ) ) <EOL> add_attr ( '<STR_LIT>' , <EOL> functools . partial ( _to_user_header , oxx , num_to_field ) ) <EOL> add_attr ( '<STR_LIT>' , <EOL> functools . partial ( _field_desc , num_to_field ) ) <EOL> add_attr ( '<STR_LIT>' , <EOL> functools . partial ( _normalize_user , oxx , mod ) ) <EOL> add_attr ( '<STR_LIT>' , <EOL> functools . partial ( _parse , mod ) ) <EOL> add_attr ( '<STR_LIT>' , <EOL> functools . partial ( _parse_header , mod ) ) <EOL> add_attr ( '<STR_LIT>' , <EOL> functools . partial ( _serialize , oxx , mod ) ) <EOL> add_attr ( '<STR_LIT>' , <EOL> functools . partial ( _serialize_header , oxx , mod ) ) <EOL> add_attr ( '<STR_LIT>' , _to_jsondict ) <EOL> add_attr ( '<STR_LIT>' , _from_jsondict ) <EOL> def _to_jsondict ( k , uv ) : <EOL> if isinstance ( uv , tuple ) : <EOL> ( value , mask ) = uv <EOL> else : <EOL> value = uv <EOL> mask = None <EOL> return { "<STR_LIT>" : { "<STR_LIT>" : k , "<STR_LIT:value>" : value , "<STR_LIT>" : mask } } <EOL> def _from_jsondict ( j ) : <EOL> tlv = j [ '<STR_LIT>' ] <EOL> field = tlv [ '<STR_LIT>' ] <EOL> value = tlv [ '<STR_LIT:value>' ] <EOL> mask = tlv . get ( '<STR_LIT>' ) <EOL> if mask is None : <EOL> uv = value <EOL> else : <EOL> uv = ( value , mask ) <EOL> return ( field , uv ) </s>
