<s> import unittest <EOL> import logging <EOL> import six <EOL> import socket <EOL> from struct import * <EOL> from nose . tools import * <EOL> from ryu . ofproto . ofproto_v1_3_parser import * <EOL> from ryu . ofproto import ofproto_v1_3_parser <EOL> from ryu . ofproto import ofproto_v1_3 <EOL> from ryu . ofproto import ofproto_protocol <EOL> from ryu . ofproto import ether <EOL> from ryu . ofproto . ofproto_parser import MsgBase <EOL> from ryu import utils <EOL> from ryu . lib import addrconv <EOL> LOG = logging . getLogger ( '<STR_LIT>' ) <EOL> _Datapath = ofproto_protocol . ProtocolDesc ( version = ofproto_v1_3 . OFP_VERSION ) <EOL> class TestOFPMatch ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_init ( self ) : <EOL> res = OFPMatch ( ) <EOL> eq_ ( res . _wc . vlan_vid_mask , <NUM_LIT:0> ) <EOL> eq_ ( res . _flow . vlan_vid , <NUM_LIT:0> ) <EOL> def _test_serialize_and_parser ( self , match , header , value , mask = None ) : <EOL> cls_ = OFPMatchField . _FIELDS_HEADERS . get ( header ) <EOL> pack_str = cls_ . pack_str . replace ( '<STR_LIT:!>' , '<STR_LIT>' ) <EOL> fmt = '<STR_LIT>' + pack_str <EOL> buf = bytearray ( ) <EOL> length = match . serialize ( buf , <NUM_LIT:0> ) <EOL> eq_ ( length , len ( buf ) ) <EOL> if mask and len ( buf ) > calcsize ( fmt ) : <EOL> fmt += pack_str <EOL> res = list ( unpack_from ( fmt , six . binary_type ( buf ) , <NUM_LIT:0> ) [ <NUM_LIT:3> : ] ) <EOL> if type ( value ) is list : <EOL> res_value = res [ : calcsize ( pack_str ) // <NUM_LIT:2> ] <EOL> eq_ ( res_value , value ) <EOL> if mask : <EOL> res_mask = res [ calcsize ( pack_str ) // <NUM_LIT:2> : ] <EOL> eq_ ( res_mask , mask ) <EOL> else : <EOL> res_value = res . pop ( <NUM_LIT:0> ) <EOL> if cls_ . __name__ == '<STR_LIT>' : <EOL> eq_ ( res_value , value | ofproto . OFPVID_PRESENT ) <EOL> else : <EOL> eq_ ( res_value , value ) <EOL> if mask and res and res [ <NUM_LIT:0> ] : <EOL> res_mask = res [ <NUM_LIT:0> ] <EOL> eq_ ( res_mask , mask ) <EOL> res = match . parser ( six . binary_type ( buf ) , <NUM_LIT:0> ) <EOL> eq_ ( res . type , ofproto . OFPMT_OXM ) <EOL> eq_ ( res . fields [ <NUM_LIT:0> ] . header , header ) <EOL> eq_ ( res . fields [ <NUM_LIT:0> ] . value , value ) <EOL> if mask and res . fields [ <NUM_LIT:0> ] . mask is not None : <EOL> eq_ ( res . fields [ <NUM_LIT:0> ] . mask , mask ) <EOL> jsondict = match . to_jsondict ( ) <EOL> match2 = match . from_jsondict ( jsondict [ "<STR_LIT>" ] ) <EOL> buf2 = bytearray ( ) <EOL> match2 . serialize ( buf2 , <NUM_LIT:0> ) <EOL> eq_ ( str ( match ) , str ( match2 ) ) <EOL> eq_ ( buf , buf2 ) <EOL> def _test_set_vlan_vid ( self , vid , mask = None ) : <EOL> header = ofproto . OXM_OF_VLAN_VID <EOL> match = OFPMatch ( ) <EOL> if mask is None : <EOL> match . set_vlan_vid ( vid ) <EOL> else : <EOL> header = ofproto . OXM_OF_VLAN_VID_W <EOL> match . set_vlan_vid_masked ( vid , mask ) <EOL> self . _test_serialize_and_parser ( match , header , vid , mask ) <EOL> def _test_set_vlan_vid_none ( self ) : <EOL> header = ofproto . OXM_OF_VLAN_VID <EOL> match = OFPMatch ( ) <EOL> match . set_vlan_vid_none ( ) <EOL> value = ofproto . OFPVID_NONE <EOL> cls_ = OFPMatchField . _FIELDS_HEADERS . get ( header ) <EOL> pack_str = cls_ . pack_str . replace ( '<STR_LIT:!>' , '<STR_LIT>' ) <EOL> fmt = '<STR_LIT>' + pack_str <EOL> buf = bytearray ( ) <EOL> length = match . serialize ( buf , <NUM_LIT:0> ) <EOL> eq_ ( length , len ( buf ) ) <EOL> res = list ( unpack_from ( fmt , six . binary_type ( buf ) , <NUM_LIT:0> ) [ <NUM_LIT:3> : ] ) <EOL> res_value = res . pop ( <NUM_LIT:0> ) <EOL> eq_ ( res_value , value ) <EOL> res = match . parser ( six . binary_type ( buf ) , <NUM_LIT:0> ) <EOL> eq_ ( res . type , ofproto . OFPMT_OXM ) <EOL> eq_ ( res . fields [ <NUM_LIT:0> ] . header , header ) <EOL> eq_ ( res . fields [ <NUM_LIT:0> ] . value , value ) <EOL> jsondict = match . to_jsondict ( ) <EOL> match2 = match . from_jsondict ( jsondict [ "<STR_LIT>" ] ) <EOL> buf2 = bytearray ( ) <EOL> match2 . serialize ( buf2 , <NUM_LIT:0> ) <EOL> eq_ ( str ( match ) , str ( match2 ) ) <EOL> eq_ ( buf , buf2 ) <EOL> def test_set_vlan_vid_mid ( self ) : <EOL> self . _test_set_vlan_vid ( <NUM_LIT> ) <EOL> def test_set_vlan_vid_max ( self ) : <EOL> self . _test_set_vlan_vid ( <NUM_LIT> ) <EOL> def test_set_vlan_vid_min ( self ) : <EOL> self . _test_set_vlan_vid ( <NUM_LIT:0> ) <EOL> def test_set_vlan_vid_masked_mid ( self ) : <EOL> self . _test_set_vlan_vid ( <NUM_LIT> , <NUM_LIT> ) <EOL> def test_set_vlan_vid_masked_max ( self ) : <EOL> self . _test_set_vlan_vid ( <NUM_LIT> , <NUM_LIT> ) <EOL> def test_set_vlan_vid_masked_min ( self ) : <EOL> self . _test_set_vlan_vid ( <NUM_LIT> , <NUM_LIT:0> ) <EOL> def test_set_vlan_vid_none ( self ) : <EOL> self . _test_set_vlan_vid_none ( ) </s>
