<s> """<STR_LIT>""" <EOL> import collections <EOL> import struct <EOL> from openfaucet import ofmatch <EOL> class DescriptionStats ( collections . namedtuple ( '<STR_LIT>' , ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) ) : <EOL> """<STR_LIT>""" <EOL> FORMAT = '<STR_LIT>' <EOL> FORMAT_LENGTH = struct . calcsize ( FORMAT ) <EOL> def serialize ( self ) : <EOL> """<STR_LIT>""" <EOL> return struct . pack ( self . FORMAT , self . mfr_desc , self . hw_desc , <EOL> self . sw_desc , self . serial_num , self . dp_desc ) <EOL> @ classmethod <EOL> def deserialize ( cls , buf ) : <EOL> """<STR_LIT>""" <EOL> return DescriptionStats ( * [ s . rstrip ( '<STR_LIT:\x00>' ) <EOL> for s in buf . unpack ( cls . FORMAT ) ] ) <EOL> class FlowStats ( collections . namedtuple ( '<STR_LIT>' , ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) ) : <EOL> """<STR_LIT>""" <EOL> FORMAT1 = '<STR_LIT>' <EOL> FORMAT1_LENGTH = struct . calcsize ( FORMAT1 ) <EOL> FORMAT2 = '<STR_LIT>' <EOL> FORMAT2_LENGTH = struct . calcsize ( FORMAT2 ) <EOL> def serialize ( self , serialize_action ) : <EOL> """<STR_LIT>""" <EOL> all_data = [ <EOL> self . match . serialize ( ) , <EOL> struct . pack ( self . FORMAT2 , self . duration_sec , self . duration_nsec , <EOL> self . priority , self . idle_timeout , self . hard_timeout , <EOL> self . cookie , self . packet_count , self . byte_count ) ] <EOL> for a in self . actions : <EOL> all_data . extend ( serialize_action ( a ) ) <EOL> length = self . FORMAT1_LENGTH + sum ( len ( d ) for d in all_data ) <EOL> all_data . insert ( <NUM_LIT:0> , struct . pack ( self . FORMAT1 , length , self . table_id ) ) <EOL> return all_data <EOL> @ classmethod <EOL> def deserialize ( cls , buf , deserialize_action ) : <EOL> """<STR_LIT>""" <EOL> length , table_id = buf . unpack ( cls . FORMAT1 ) <EOL> if length < <NUM_LIT> : <EOL> raise ValueError ( '<STR_LIT>' , length ) <EOL> until_bytes_left = buf . message_bytes_left + cls . FORMAT1_LENGTH - length <EOL> match = ofmatch . Match . deserialize ( buf ) <EOL> ( duration_sec , duration_nsec , priority , idle_timeout , hard_timeout , <EOL> cookie , packet_count , byte_count ) = buf . unpack ( cls . FORMAT2 ) <EOL> actions = [ ] <EOL> while buf . message_bytes_left > until_bytes_left : <EOL> actions . append ( deserialize_action ( buf ) ) <EOL> if buf . message_bytes_left != until_bytes_left : <EOL> raise ValueError ( '<STR_LIT>' , length ) <EOL> actions = tuple ( actions ) <EOL> return FlowStats ( <EOL> table_id , match , duration_sec , duration_nsec , priority , <EOL> idle_timeout , hard_timeout , cookie , packet_count , byte_count , <EOL> actions ) <EOL> class TableStats ( collections . namedtuple ( '<STR_LIT>' , ( <EOL> '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) ) : <EOL> """<STR_LIT>""" <EOL> FORMAT = '<STR_LIT>' <EOL> FORMAT_LENGTH = struct . calcsize ( FORMAT ) <EOL> def serialize ( self ) : <EOL> """<STR_LIT>""" <EOL> return struct . pack ( <EOL> self . FORMAT , self . table_id , self . name , self . wildcards . serialize ( ) , <EOL> self . max_entries , self . active_count , self . lookup_count , <EOL> self . matched_count ) <EOL> @ classmethod <EOL> def deserialize ( cls , buf ) : <EOL> """<STR_LIT>""" <EOL> ( table_id , name , wildcards_ser , max_entries , active_count , <EOL> lookup_count , matched_count ) = buf . unpack ( cls . FORMAT ) <EOL> return TableStats ( <EOL> table_id , name . rstrip ( '<STR_LIT:\x00>' ) , <EOL> ofmatch . Wildcards . deserialize ( wildcards_ser ) , max_entries , <EOL> active_count , lookup_count , matched_count ) <EOL> class PortStats ( collections . namedtuple ( '<STR_LIT>' , ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) ) : <EOL> """<STR_LIT>""" <EOL> FORMAT = '<STR_LIT>' <EOL> FORMAT_LENGTH = struct . calcsize ( FORMAT ) <EOL> _UNAVAILABLE = <NUM_LIT> <EOL> def serialize ( self ) : <EOL> """<STR_LIT>""" <EOL> return struct . pack ( <EOL> self . FORMAT , self . port_no , <EOL> self . _UNAVAILABLE if self . rx_packets is None <EOL> else self . rx_packets , <EOL> self . _UNAVAILABLE if self . tx_packets is None <EOL> else self . tx_packets , <EOL> self . _UNAVAILABLE if self . rx_bytes is None <EOL> else self . rx_bytes , <EOL> self . _UNAVAILABLE if self . tx_bytes is None <EOL> else self . tx_bytes , <EOL> self . _UNAVAILABLE if self . rx_dropped is None <EOL> else self . rx_dropped , <EOL> self . _UNAVAILABLE if self . tx_dropped is None <EOL> else self . tx_dropped , <EOL> self . _UNAVAILABLE if self . rx_errors is None <EOL> else self . rx_errors , <EOL> self . _UNAVAILABLE if self . tx_errors is None <EOL> else self . tx_errors , <EOL> self . _UNAVAILABLE if self . rx_frame_err is None <EOL> else self . rx_frame_err , <EOL> self . _UNAVAILABLE if self . rx_over_err is None <EOL> else self . rx_over_err , <EOL> self . _UNAVAILABLE if self . rx_crc_err is None <EOL> else self . rx_crc_err , <EOL> self . _UNAVAILABLE if self . collisions is None <EOL> else self . collisions ) <EOL> @ classmethod <EOL> def deserialize ( cls , buf ) : <EOL> """<STR_LIT>""" <EOL> ( port_no , rx_packets , tx_packets , rx_bytes , tx_bytes , rx_dropped , <EOL> tx_dropped , rx_errors , tx_errors , rx_frame_err , rx_over_err , <EOL> rx_crc_err , collisions ) = buf . unpack ( cls . FORMAT ) <EOL> return PortStats ( <EOL> port_no , <EOL> None if rx_packets == cls . _UNAVAILABLE else rx_packets , <EOL> None if tx_packets == cls . _UNAVAILABLE else tx_packets , <EOL> None if rx_bytes == cls . _UNAVAILABLE else rx_bytes , <EOL> None if tx_bytes == cls . _UNAVAILABLE else tx_bytes , <EOL> None if rx_dropped == cls . _UNAVAILABLE else rx_dropped , <EOL> None if tx_dropped == cls . _UNAVAILABLE else tx_dropped , <EOL> None if rx_errors == cls . _UNAVAILABLE else rx_errors , <EOL> None if tx_errors == cls . _UNAVAILABLE else tx_errors , <EOL> None if rx_frame_err == cls . _UNAVAILABLE else rx_frame_err , <EOL> None if rx_over_err == cls . _UNAVAILABLE else rx_over_err , <EOL> None if rx_crc_err == cls . _UNAVAILABLE else rx_crc_err , <EOL> None if collisions == cls . _UNAVAILABLE else collisions ) <EOL> class QueueStats ( collections . namedtuple ( '<STR_LIT>' , ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) ) : <EOL> """<STR_LIT>""" <EOL> FORMAT = '<STR_LIT>' <EOL> FORMAT_LENGTH = struct . calcsize ( FORMAT ) <EOL> def serialize ( self ) : <EOL> """<STR_LIT>""" <EOL> return struct . pack ( <EOL> self . FORMAT , self . port_no , self . queue_id , self . tx_bytes , <EOL> self . tx_packets , self . tx_errors ) <EOL> @ classmethod <EOL> def deserialize ( cls , buf ) : <EOL> """<STR_LIT>""" <EOL> return QueueStats ( * buf . unpack ( cls . FORMAT ) ) </s>
