<s> from oslo_config import cfg <EOL> from oslo_log import log as logging <EOL> from neutron . agent . l2 . extensions import qos <EOL> from neutron . plugins . ml2 . drivers . openvswitch . mech_driver import ( <EOL> mech_openvswitch ) <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class QosOVSAgentDriver ( qos . QosAgentDriver ) : <EOL> SUPPORTED_RULES = ( <EOL> mech_openvswitch . OpenvswitchMechanismDriver . supported_qos_rule_types ) <EOL> def __init__ ( self ) : <EOL> super ( QosOVSAgentDriver , self ) . __init__ ( ) <EOL> self . br_int_name = cfg . CONF . OVS . integration_bridge <EOL> self . br_int = None <EOL> self . agent_api = None <EOL> def consume_api ( self , agent_api ) : <EOL> self . agent_api = agent_api <EOL> def initialize ( self ) : <EOL> self . br_int = self . agent_api . request_int_br ( ) <EOL> self . cookie = self . br_int . default_cookie <EOL> def create_bandwidth_limit ( self , port , rule ) : <EOL> self . update_bandwidth_limit ( port , rule ) <EOL> def update_bandwidth_limit ( self , port , rule ) : <EOL> vif_port = port . get ( '<STR_LIT>' ) <EOL> if not vif_port : <EOL> port_id = port . get ( '<STR_LIT>' , None ) <EOL> LOG . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , port_id ) <EOL> return <EOL> max_kbps = rule . max_kbps <EOL> max_burst_kbps = rule . max_burst_kbps <EOL> self . br_int . create_egress_bw_limit_for_port ( vif_port . port_name , <EOL> max_kbps , <EOL> max_burst_kbps ) <EOL> def delete_bandwidth_limit ( self , port ) : <EOL> vif_port = port . get ( '<STR_LIT>' ) <EOL> if not vif_port : <EOL> port_id = port . get ( '<STR_LIT>' , None ) <EOL> LOG . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , port_id ) <EOL> return <EOL> self . br_int . delete_egress_bw_limit_for_port ( vif_port . port_name ) <EOL> def create_dscp_marking ( self , port , rule ) : <EOL> self . update_dscp_marking ( port , rule ) <EOL> def update_dscp_marking ( self , port , rule ) : <EOL> port_name = port [ '<STR_LIT>' ] . port_name <EOL> port = self . br_int . get_port_ofport ( port_name ) <EOL> mark = rule . dscp_mark <EOL> mark = str ( mark << <NUM_LIT:2> ) <EOL> flows = self . br_int . dump_flows_for ( cookie = self . cookie , table = <NUM_LIT:0> , <EOL> in_port = port , reg2 = <NUM_LIT:0> ) <EOL> if not flows : <EOL> actions = ( "<STR_LIT>" + mark + "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> self . br_int . add_flow ( in_port = port , table = <NUM_LIT:0> , priority = <NUM_LIT> , <EOL> reg2 = <NUM_LIT:0> , actions = actions ) <EOL> else : <EOL> for flow in flows : <EOL> actions = str ( flow ) . partition ( "<STR_LIT>" ) [ <NUM_LIT:2> ] <EOL> acts = actions . split ( '<STR_LIT:U+002C>' ) <EOL> actions = "<STR_LIT>" + mark + "<STR_LIT:U+002C>" <EOL> actions += '<STR_LIT:U+002C>' . join ( [ act for act in acts <EOL> if "<STR_LIT>" not in act ] ) <EOL> self . br_int . mod_flow ( reg2 = <NUM_LIT:0> , in_port = port , table = <NUM_LIT:0> , <EOL> actions = actions ) <EOL> def delete_dscp_marking ( self , port ) : <EOL> port_name = port [ '<STR_LIT>' ] . port_name <EOL> port = self . br_int . get_port_ofport ( port_name ) <EOL> self . br_int . delete_flows ( in_port = port , table = <NUM_LIT:0> , reg2 = <NUM_LIT:0> ) </s>
