<s> """<STR_LIT>""" <EOL> import collections <EOL> import struct <EOL> OFPFW_IN_PORT = <NUM_LIT:1> << <NUM_LIT:0> <EOL> OFPFW_DL_VLAN = <NUM_LIT:1> << <NUM_LIT:1> <EOL> OFPFW_DL_SRC = <NUM_LIT:1> << <NUM_LIT:2> <EOL> OFPFW_DL_DST = <NUM_LIT:1> << <NUM_LIT:3> <EOL> OFPFW_DL_TYPE = <NUM_LIT:1> << <NUM_LIT:4> <EOL> OFPFW_NW_PROTO = <NUM_LIT:1> << <NUM_LIT:5> <EOL> OFPFW_TP_SRC = <NUM_LIT:1> << <NUM_LIT:6> <EOL> OFPFW_TP_DST = <NUM_LIT:1> << <NUM_LIT:7> <EOL> OFPFW_NW_SRC_SHIFT = <NUM_LIT:8> <EOL> OFPFW_NW_SRC_BITS = <NUM_LIT:6> <EOL> OFPFW_NW_SRC_MASK = ( ( <NUM_LIT:1> << OFPFW_NW_SRC_BITS ) - <NUM_LIT:1> ) << OFPFW_NW_SRC_SHIFT <EOL> OFPFW_NW_SRC_ALL = <NUM_LIT:32> << OFPFW_NW_SRC_SHIFT <EOL> OFPFW_NW_DST_SHIFT = <NUM_LIT> <EOL> OFPFW_NW_DST_BITS = <NUM_LIT:6> <EOL> OFPFW_NW_DST_MASK = ( ( <NUM_LIT:1> << OFPFW_NW_DST_BITS ) - <NUM_LIT:1> ) << OFPFW_NW_DST_SHIFT <EOL> OFPFW_NW_DST_ALL = <NUM_LIT:32> << OFPFW_NW_DST_SHIFT <EOL> OFPFW_DL_VLAN_PCP = <NUM_LIT:1> << <NUM_LIT:20> <EOL> OFPFW_NW_TOS = <NUM_LIT:1> << <NUM_LIT> <EOL> OFPFW_ALL = ( ( <NUM_LIT:1> << <NUM_LIT> ) - <NUM_LIT:1> ) <EOL> class Wildcards ( collections . namedtuple ( '<STR_LIT>' , ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) ) : <EOL> """<STR_LIT>""" <EOL> def serialize ( self ) : <EOL> """<STR_LIT>""" <EOL> wildcard_bits = ( ( OFPFW_IN_PORT if self . in_port else <NUM_LIT:0> ) <EOL> | ( OFPFW_DL_VLAN if self . dl_vlan else <NUM_LIT:0> ) <EOL> | ( OFPFW_DL_SRC if self . dl_src else <NUM_LIT:0> ) <EOL> | ( OFPFW_DL_DST if self . dl_dst else <NUM_LIT:0> ) <EOL> | ( OFPFW_DL_TYPE if self . dl_type else <NUM_LIT:0> ) <EOL> | ( OFPFW_NW_PROTO if self . nw_proto else <NUM_LIT:0> ) <EOL> | ( OFPFW_TP_SRC if self . tp_src else <NUM_LIT:0> ) <EOL> | ( OFPFW_TP_DST if self . tp_dst else <NUM_LIT:0> ) <EOL> | ( OFPFW_DL_VLAN_PCP if self . dl_vlan_pcp else <NUM_LIT:0> ) <EOL> | ( OFPFW_NW_TOS if self . nw_tos else <NUM_LIT:0> ) ) <EOL> if self . nw_src < <NUM_LIT:0> or self . nw_src > <NUM_LIT:32> : <EOL> raise ValueError ( '<STR_LIT>' , self . nw_src ) <EOL> wildcard_bits |= self . nw_src << OFPFW_NW_SRC_SHIFT <EOL> if self . nw_dst < <NUM_LIT:0> or self . nw_dst > <NUM_LIT:32> : <EOL> raise ValueError ( '<STR_LIT>' , self . nw_dst ) <EOL> wildcard_bits |= self . nw_dst << OFPFW_NW_DST_SHIFT <EOL> return wildcard_bits <EOL> @ classmethod <EOL> def deserialize ( cls , v ) : <EOL> """<STR_LIT>""" <EOL> nw_src = ( v & OFPFW_NW_SRC_MASK ) >> OFPFW_NW_SRC_SHIFT <EOL> nw_dst = ( v & OFPFW_NW_DST_MASK ) >> OFPFW_NW_DST_SHIFT <EOL> return Wildcards ( bool ( v & OFPFW_IN_PORT ) , <EOL> bool ( v & OFPFW_DL_SRC ) , <EOL> bool ( v & OFPFW_DL_DST ) , <EOL> bool ( v & OFPFW_DL_VLAN ) , <EOL> bool ( v & OFPFW_DL_VLAN_PCP ) , <EOL> bool ( v & OFPFW_DL_TYPE ) , <EOL> bool ( v & OFPFW_NW_TOS ) , <EOL> bool ( v & OFPFW_NW_PROTO ) , <EOL> nw_src , <EOL> nw_dst , <EOL> bool ( v & OFPFW_TP_SRC ) , <EOL> bool ( v & OFPFW_TP_DST ) ) <EOL> class Match ( collections . namedtuple ( '<STR_LIT>' , ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) ) : <EOL> """<STR_LIT>""" <EOL> FORMAT = '<STR_LIT>' <EOL> FORMAT_LENGTH = struct . calcsize ( FORMAT ) <EOL> @ classmethod <EOL> def create_wildcarded ( cls , in_port = None , dl_src = None , dl_dst = None , <EOL> dl_vlan = None , dl_vlan_pcp = None , dl_type = None , <EOL> nw_tos = None , nw_proto = None , nw_src = None , nw_dst = None , <EOL> tp_src = None , tp_dst = None ) : <EOL> """<STR_LIT>""" <EOL> return Match ( in_port = in_port , dl_src = dl_src , dl_dst = dl_dst , <EOL> dl_vlan = dl_vlan , dl_vlan_pcp = dl_vlan_pcp , dl_type = dl_type , <EOL> nw_tos = nw_tos , nw_proto = nw_proto , nw_src = nw_src , <EOL> nw_dst = nw_dst , tp_src = tp_src , tp_dst = tp_dst ) <EOL> @ property <EOL> def wildcards ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . nw_src is None : <EOL> wild_nw_src = <NUM_LIT:32> <EOL> else : <EOL> _ , prefix_length = self . nw_src <EOL> if prefix_length < <NUM_LIT:1> or prefix_length > <NUM_LIT:32> : <EOL> raise ValueError ( '<STR_LIT>' , prefix_length ) <EOL> wild_nw_src = <NUM_LIT:32> - prefix_length <EOL> if self . nw_dst is None : <EOL> wild_nw_dst = <NUM_LIT:32> <EOL> else : <EOL> _ , prefix_length = self . nw_dst <EOL> if prefix_length < <NUM_LIT:1> or prefix_length > <NUM_LIT:32> : <EOL> raise ValueError ( '<STR_LIT>' , prefix_length ) <EOL> wild_nw_dst = <NUM_LIT:32> - prefix_length <EOL> return Wildcards ( in_port = self . in_port is None , <EOL> dl_src = self . dl_src is None , <EOL> dl_dst = self . dl_dst is None , <EOL> dl_vlan = self . dl_vlan is None , <EOL> dl_vlan_pcp = self . dl_vlan_pcp is None , <EOL> dl_type = self . dl_type is None , <EOL> nw_tos = self . nw_tos is None , <EOL> nw_proto = self . nw_proto is None , <EOL> nw_src = wild_nw_src , <EOL> nw_dst = wild_nw_dst , <EOL> tp_src = self . tp_src is None , <EOL> tp_dst = self . tp_dst is None ) <EOL> def serialize ( self ) : <EOL> """<STR_LIT>""" <EOL> return struct . pack ( <EOL> self . FORMAT , self . wildcards . serialize ( ) , <EOL> self . in_port if self . in_port is not None else <NUM_LIT:0> , <EOL> self . dl_src if self . dl_src is not None else '<STR_LIT>' , <EOL> self . dl_dst if self . dl_dst is not None else '<STR_LIT>' , <EOL> self . dl_vlan if self . dl_vlan is not None else <NUM_LIT:0> , <EOL> self . dl_vlan_pcp if self . dl_vlan_pcp is not None else <NUM_LIT:0> , <EOL> self . dl_type if self . dl_type is not None else <NUM_LIT:0> , <EOL> self . nw_tos & <NUM_LIT> if self . nw_tos is not None else <NUM_LIT:0> , <EOL> self . nw_proto if self . nw_proto is not None else <NUM_LIT:0> , <EOL> self . nw_src [ <NUM_LIT:0> ] if self . nw_src is not None else '<STR_LIT>' , <EOL> self . nw_dst [ <NUM_LIT:0> ] if self . nw_dst is not None else '<STR_LIT>' , <EOL> self . tp_src if self . tp_src is not None else <NUM_LIT:0> , <EOL> self . tp_dst if self . tp_dst is not None else <NUM_LIT:0> ) <EOL> @ classmethod <EOL> def deserialize ( cls , buf ) : <EOL> """<STR_LIT>""" <EOL> ( wildcards_ser , in_port , dl_src , dl_dst , dl_vlan , dl_vlan_pcp , dl_type , <EOL> nw_tos , nw_proto , nw_src , nw_dst , tp_src , tp_dst ) = buf . unpack ( <EOL> cls . FORMAT ) <EOL> wildcards = Wildcards . deserialize ( wildcards_ser ) <EOL> if nw_tos & <NUM_LIT> : <EOL> nw_tos &= <NUM_LIT> <EOL> nw_src_prefix_length = <NUM_LIT:32> - wildcards . nw_src <EOL> nw_dst_prefix_length = <NUM_LIT:32> - wildcards . nw_dst <EOL> return Match ( <EOL> None if wildcards . in_port else in_port , <EOL> None if wildcards . dl_src else dl_src , <EOL> None if wildcards . dl_dst else dl_dst , <EOL> None if wildcards . dl_vlan else dl_vlan , <EOL> None if wildcards . dl_vlan_pcp else dl_vlan_pcp , <EOL> None if wildcards . dl_type else dl_type , <EOL> None if wildcards . nw_tos else nw_tos , <EOL> None if wildcards . nw_proto else nw_proto , <EOL> ( nw_src , nw_src_prefix_length ) if nw_src_prefix_length > <NUM_LIT:0> <EOL> else None , <EOL> ( nw_dst , nw_dst_prefix_length ) if nw_dst_prefix_length > <NUM_LIT:0> <EOL> else None , <EOL> None if wildcards . tp_src else tp_src , <EOL> None if wildcards . tp_dst else tp_dst ) </s>
