<s> import struct <EOL> from . import packet_base <EOL> from ryu . lib import addrconv <EOL> SLOW_PROTOCOL_MULTICAST = '<STR_LIT>' <EOL> SLOW_SUBTYPE_LACP = <NUM_LIT> <EOL> SLOW_SUBTYPE_MARKER = <NUM_LIT> <EOL> SLOW_SUBTYPE_OAM = <NUM_LIT> <EOL> SLOW_SUBTYPE_OSSP = <NUM_LIT> <EOL> class slow ( packet_base . PacketBase ) : <EOL> """<STR_LIT>""" <EOL> _PACK_STR = '<STR_LIT>' <EOL> @ classmethod <EOL> def parser ( cls , buf ) : <EOL> ( subtype , ) = struct . unpack_from ( cls . _PACK_STR , buf ) <EOL> switch = { <EOL> SLOW_SUBTYPE_LACP : lacp , <EOL> SLOW_SUBTYPE_MARKER : None , <EOL> SLOW_SUBTYPE_OAM : None , <EOL> SLOW_SUBTYPE_OSSP : None , <EOL> } <EOL> cls_ = switch . get ( subtype ) <EOL> if cls_ : <EOL> return cls_ . parser ( buf ) <EOL> else : <EOL> return None , None , buf <EOL> class lacp ( packet_base . PacketBase ) : <EOL> """<STR_LIT>""" <EOL> LACP_VERSION_NUMBER = <NUM_LIT:1> <EOL> LACP_TLV_TYPE_ACTOR = <NUM_LIT:1> <EOL> LACP_TLV_TYPE_PARTNER = <NUM_LIT:2> <EOL> LACP_TLV_TYPE_COLLECTOR = <NUM_LIT:3> <EOL> LACP_TLV_TYPE_TERMINATOR = <NUM_LIT:0> <EOL> LACP_STATE_ACTIVE = <NUM_LIT:1> <EOL> LACP_STATE_PASSIVE = <NUM_LIT:0> <EOL> LACP_STATE_SHORT_TIMEOUT = <NUM_LIT:1> <EOL> LACP_STATE_LONG_TIMEOUT = <NUM_LIT:0> <EOL> LACP_STATE_AGGREGATEABLE = <NUM_LIT:1> <EOL> LACP_STATE_INDIVIDUAL = <NUM_LIT:0> <EOL> LACP_STATE_IN_SYNC = <NUM_LIT:1> <EOL> LACP_STATE_OUT_OF_SYNC = <NUM_LIT:0> <EOL> LACP_STATE_COLLECTING_ENABLED = <NUM_LIT:1> <EOL> LACP_STATE_COLELCTING_DISABLED = <NUM_LIT:0> <EOL> LACP_STATE_DISTRIBUTING_ENABLED = <NUM_LIT:1> <EOL> LACP_STATE_DISTRIBUTING_DISABLED = <NUM_LIT:0> <EOL> LACP_STATE_DEFAULED_PARTNER = <NUM_LIT:1> <EOL> LACP_STATE_OPERATIONAL_PARTNER = <NUM_LIT:0> <EOL> LACP_STATE_EXPIRED = <NUM_LIT:1> <EOL> LACP_STATE_NOT_EXPIRED = <NUM_LIT:0> <EOL> FAST_PERIODIC_TIME = <NUM_LIT:1> <EOL> SLOW_PERIODIC_TIME = <NUM_LIT:30> <EOL> SHORT_TIMEOUT_TIME = <NUM_LIT:3> * FAST_PERIODIC_TIME <EOL> LONG_TIMEOUT_TIME = <NUM_LIT:3> * SLOW_PERIODIC_TIME <EOL> _HLEN_PACK_STR = '<STR_LIT>' <EOL> _HLEN_PACK_LEN = struct . calcsize ( _HLEN_PACK_STR ) <EOL> _ACTPRT_INFO_PACK_STR = '<STR_LIT>' <EOL> _ACTPRT_INFO_PACK_LEN = struct . calcsize ( _ACTPRT_INFO_PACK_STR ) <EOL> _COL_INFO_PACK_STR = '<STR_LIT>' <EOL> _COL_INFO_PACK_LEN = struct . calcsize ( _COL_INFO_PACK_STR ) <EOL> _TRM_PACK_STR = '<STR_LIT>' <EOL> _TRM_PACK_LEN = struct . calcsize ( _TRM_PACK_STR ) <EOL> _ALL_PACK_LEN = _HLEN_PACK_LEN + _ACTPRT_INFO_PACK_LEN * <NUM_LIT:2> + _COL_INFO_PACK_LEN + _TRM_PACK_LEN <EOL> _MIN_LEN = _ALL_PACK_LEN <EOL> _TYPE = { <EOL> '<STR_LIT:ascii>' : [ <EOL> '<STR_LIT>' , '<STR_LIT>' <EOL> ] <EOL> } <EOL> def __init__ ( self , version = LACP_VERSION_NUMBER , <EOL> actor_system_priority = <NUM_LIT:0> , <EOL> actor_system = '<STR_LIT>' , <EOL> actor_key = <NUM_LIT:0> , actor_port_priority = <NUM_LIT:0> , actor_port = <NUM_LIT:0> , <EOL> actor_state_activity = <NUM_LIT:0> , actor_state_timeout = <NUM_LIT:0> , <EOL> actor_state_aggregation = <NUM_LIT:0> , <EOL> actor_state_synchronization = <NUM_LIT:0> , <EOL> actor_state_collecting = <NUM_LIT:0> , actor_state_distributing = <NUM_LIT:0> , <EOL> actor_state_defaulted = <NUM_LIT:0> , actor_state_expired = <NUM_LIT:0> , <EOL> partner_system_priority = <NUM_LIT:0> , <EOL> partner_system = '<STR_LIT>' , <EOL> partner_key = <NUM_LIT:0> , partner_port_priority = <NUM_LIT:0> , partner_port = <NUM_LIT:0> , <EOL> partner_state_activity = <NUM_LIT:0> , partner_state_timeout = <NUM_LIT:0> , <EOL> partner_state_aggregation = <NUM_LIT:0> , <EOL> partner_state_synchronization = <NUM_LIT:0> , <EOL> partner_state_collecting = <NUM_LIT:0> , <EOL> partner_state_distributing = <NUM_LIT:0> , <EOL> partner_state_defaulted = <NUM_LIT:0> , partner_state_expired = <NUM_LIT:0> , <EOL> collector_max_delay = <NUM_LIT:0> ) : <EOL> super ( lacp , self ) . __init__ ( ) <EOL> assert ( <NUM_LIT:1> == actor_state_activity | <NUM_LIT:1> ) <EOL> assert ( <NUM_LIT:1> == actor_state_timeout | <NUM_LIT:1> ) <EOL> assert ( <NUM_LIT:1> == actor_state_aggregation | <NUM_LIT:1> ) <EOL> assert ( <NUM_LIT:1> == actor_state_synchronization | <NUM_LIT:1> ) <EOL> assert ( <NUM_LIT:1> == actor_state_collecting | <NUM_LIT:1> ) <EOL> assert ( <NUM_LIT:1> == actor_state_distributing | <NUM_LIT:1> ) <EOL> assert ( <NUM_LIT:1> == actor_state_defaulted | <NUM_LIT:1> ) <EOL> assert ( <NUM_LIT:1> == actor_state_expired | <NUM_LIT:1> ) <EOL> assert ( <NUM_LIT:1> == partner_state_activity | <NUM_LIT:1> ) <EOL> assert ( <NUM_LIT:1> == partner_state_timeout | <NUM_LIT:1> ) <EOL> assert ( <NUM_LIT:1> == partner_state_aggregation | <NUM_LIT:1> ) <EOL> assert ( <NUM_LIT:1> == partner_state_synchronization | <NUM_LIT:1> ) <EOL> assert ( <NUM_LIT:1> == partner_state_collecting | <NUM_LIT:1> ) <EOL> assert ( <NUM_LIT:1> == partner_state_distributing | <NUM_LIT:1> ) <EOL> assert ( <NUM_LIT:1> == partner_state_defaulted | <NUM_LIT:1> ) <EOL> assert ( <NUM_LIT:1> == partner_state_expired | <NUM_LIT:1> ) <EOL> self . _subtype = SLOW_SUBTYPE_LACP <EOL> self . version = version <EOL> self . _actor_tag = self . LACP_TLV_TYPE_ACTOR <EOL> self . _actor_length = self . _ACTPRT_INFO_PACK_LEN <EOL> self . actor_system_priority = actor_system_priority <EOL> self . actor_system = actor_system <EOL> self . actor_key = actor_key <EOL> self . actor_port_priority = actor_port_priority <EOL> self . actor_port = actor_port <EOL> self . actor_state_activity = actor_state_activity <EOL> self . actor_state_timeout = actor_state_timeout <EOL> self . actor_state_aggregation = actor_state_aggregation <EOL> self . actor_state_synchronization = actor_state_synchronization <EOL> self . actor_state_collecting = actor_state_collecting <EOL> self . actor_state_distributing = actor_state_distributing <EOL> self . actor_state_defaulted = actor_state_defaulted <EOL> self . actor_state_expired = actor_state_expired <EOL> self . _actor_state = ( <EOL> ( self . actor_state_activity << <NUM_LIT:0> ) | <EOL> ( self . actor_state_timeout << <NUM_LIT:1> ) | <EOL> ( self . actor_state_aggregation << <NUM_LIT:2> ) | <EOL> ( self . actor_state_synchronization << <NUM_LIT:3> ) | <EOL> ( self . actor_state_collecting << <NUM_LIT:4> ) | <EOL> ( self . actor_state_distributing << <NUM_LIT:5> ) | <EOL> ( self . actor_state_defaulted << <NUM_LIT:6> ) | <EOL> ( self . actor_state_expired << <NUM_LIT:7> ) ) <EOL> self . _partner_tag = self . LACP_TLV_TYPE_PARTNER <EOL> self . _partner_length = self . _ACTPRT_INFO_PACK_LEN <EOL> self . partner_system_priority = partner_system_priority <EOL> self . partner_system = partner_system <EOL> self . partner_key = partner_key <EOL> self . partner_port_priority = partner_port_priority <EOL> self . partner_port = partner_port <EOL> self . partner_state_activity = partner_state_activity <EOL> self . partner_state_timeout = partner_state_timeout <EOL> self . partner_state_aggregation = partner_state_aggregation <EOL> self . partner_state_synchronization = partner_state_synchronization <EOL> self . partner_state_collecting = partner_state_collecting <EOL> self . partner_state_distributing = partner_state_distributing <EOL> self . partner_state_defaulted = partner_state_defaulted <EOL> self . partner_state_expired = partner_state_expired <EOL> self . _partner_state = ( <EOL> ( self . partner_state_activity << <NUM_LIT:0> ) | <EOL> ( self . partner_state_timeout << <NUM_LIT:1> ) | <EOL> ( self . partner_state_aggregation << <NUM_LIT:2> ) | <EOL> ( self . partner_state_synchronization << <NUM_LIT:3> ) | <EOL> ( self . partner_state_collecting << <NUM_LIT:4> ) | <EOL> ( self . partner_state_distributing << <NUM_LIT:5> ) | <EOL> ( self . partner_state_defaulted << <NUM_LIT:6> ) | <EOL> ( self . partner_state_expired << <NUM_LIT:7> ) ) <EOL> self . _collector_tag = self . LACP_TLV_TYPE_COLLECTOR <EOL> self . _collector_length = self . _COL_INFO_PACK_LEN <EOL> self . collector_max_delay = collector_max_delay <EOL> self . _terminator_tag = self . LACP_TLV_TYPE_TERMINATOR <EOL> self . _terminator_length = <NUM_LIT:0> <EOL> @ classmethod <EOL> def parser ( cls , buf ) : <EOL> assert cls . _ALL_PACK_LEN == len ( buf ) <EOL> offset = <NUM_LIT:0> <EOL> ( subtype , version <EOL> ) = struct . unpack_from ( cls . _HLEN_PACK_STR , buf , offset ) <EOL> assert SLOW_SUBTYPE_LACP == subtype <EOL> assert cls . LACP_VERSION_NUMBER == version <EOL> offset += cls . _HLEN_PACK_LEN <EOL> ( actor_tag , actor_length , actor_system_priority , actor_system , <EOL> actor_key , actor_port_priority , actor_port , actor_state <EOL> ) = struct . unpack_from ( cls . _ACTPRT_INFO_PACK_STR , buf , offset ) <EOL> assert cls . LACP_TLV_TYPE_ACTOR == actor_tag <EOL> assert cls . _ACTPRT_INFO_PACK_LEN == actor_length <EOL> offset += cls . _ACTPRT_INFO_PACK_LEN <EOL> actor_state_activity = ( actor_state >> <NUM_LIT:0> ) & <NUM_LIT:1> <EOL> actor_state_timeout = ( actor_state >> <NUM_LIT:1> ) & <NUM_LIT:1> <EOL> actor_state_aggregation = ( actor_state >> <NUM_LIT:2> ) & <NUM_LIT:1> <EOL> actor_state_synchronization = ( actor_state >> <NUM_LIT:3> ) & <NUM_LIT:1> <EOL> actor_state_collecting = ( actor_state >> <NUM_LIT:4> ) & <NUM_LIT:1> <EOL> actor_state_distributing = ( actor_state >> <NUM_LIT:5> ) & <NUM_LIT:1> <EOL> actor_state_defaulted = ( actor_state >> <NUM_LIT:6> ) & <NUM_LIT:1> <EOL> actor_state_expired = ( actor_state >> <NUM_LIT:7> ) & <NUM_LIT:1> <EOL> ( partner_tag , partner_length , partner_system_priority , <EOL> partner_system , partner_key , partner_port_priority , <EOL> partner_port , partner_state <EOL> ) = struct . unpack_from ( cls . _ACTPRT_INFO_PACK_STR , buf , offset ) <EOL> assert cls . LACP_TLV_TYPE_PARTNER == partner_tag <EOL> assert cls . _ACTPRT_INFO_PACK_LEN == partner_length <EOL> offset += cls . _ACTPRT_INFO_PACK_LEN <EOL> partner_state_activity = ( partner_state >> <NUM_LIT:0> ) & <NUM_LIT:1> <EOL> partner_state_timeout = ( partner_state >> <NUM_LIT:1> ) & <NUM_LIT:1> <EOL> partner_state_aggregation = ( partner_state >> <NUM_LIT:2> ) & <NUM_LIT:1> <EOL> partner_state_synchronization = ( partner_state >> <NUM_LIT:3> ) & <NUM_LIT:1> <EOL> partner_state_collecting = ( partner_state >> <NUM_LIT:4> ) & <NUM_LIT:1> <EOL> partner_state_distributing = ( partner_state >> <NUM_LIT:5> ) & <NUM_LIT:1> <EOL> partner_state_defaulted = ( partner_state >> <NUM_LIT:6> ) & <NUM_LIT:1> <EOL> partner_state_expired = ( partner_state >> <NUM_LIT:7> ) & <NUM_LIT:1> <EOL> ( collector_tag , collector_length , collector_max_delay <EOL> ) = struct . unpack_from ( cls . _COL_INFO_PACK_STR , buf , offset ) <EOL> assert cls . LACP_TLV_TYPE_COLLECTOR == collector_tag <EOL> assert cls . _COL_INFO_PACK_LEN == collector_length <EOL> offset += cls . _COL_INFO_PACK_LEN <EOL> ( terminator_tag , terminator_length <EOL> ) = struct . unpack_from ( cls . _TRM_PACK_STR , buf , offset ) <EOL> assert cls . LACP_TLV_TYPE_TERMINATOR == terminator_tag <EOL> assert <NUM_LIT:0> == terminator_length <EOL> return cls ( version , <EOL> actor_system_priority , <EOL> addrconv . mac . bin_to_text ( actor_system ) , <EOL> actor_key , actor_port_priority , <EOL> actor_port , actor_state_activity , <EOL> actor_state_timeout , actor_state_aggregation , <EOL> actor_state_synchronization , actor_state_collecting , <EOL> actor_state_distributing , actor_state_defaulted , <EOL> actor_state_expired , partner_system_priority , <EOL> addrconv . mac . bin_to_text ( partner_system ) , <EOL> partner_key , partner_port_priority , <EOL> partner_port , partner_state_activity , <EOL> partner_state_timeout , partner_state_aggregation , <EOL> partner_state_synchronization , <EOL> partner_state_collecting , partner_state_distributing , <EOL> partner_state_defaulted , partner_state_expired , <EOL> collector_max_delay ) , None , buf [ lacp . _ALL_PACK_LEN : ] <EOL> def serialize ( self , payload , prev ) : <EOL> header = struct . pack ( self . _HLEN_PACK_STR , self . _subtype , <EOL> self . version ) <EOL> actor = struct . pack ( self . _ACTPRT_INFO_PACK_STR , <EOL> self . _actor_tag , self . _actor_length , <EOL> self . actor_system_priority , <EOL> addrconv . mac . text_to_bin ( self . actor_system ) , <EOL> self . actor_key , <EOL> self . actor_port_priority , self . actor_port , <EOL> self . _actor_state ) <EOL> partner = struct . pack ( self . _ACTPRT_INFO_PACK_STR , <EOL> self . _partner_tag , self . _partner_length , <EOL> self . partner_system_priority , <EOL> addrconv . mac . text_to_bin ( self . partner_system ) , <EOL> self . partner_key , <EOL> self . partner_port_priority , <EOL> self . partner_port , self . _partner_state ) <EOL> collector = struct . pack ( self . _COL_INFO_PACK_STR , <EOL> self . _collector_tag , <EOL> self . _collector_length , <EOL> self . collector_max_delay ) <EOL> terminator = struct . pack ( self . _TRM_PACK_STR , <EOL> self . _terminator_tag , <EOL> self . _terminator_length ) <EOL> return header + actor + partner + collector + terminator </s>
