69
69
qos_constants .RULE_TYPE_MINIMUM_BANDWIDTH : QOS_RULE_MINBW_1 }
70
70
}
71
71
72
+ QOS_RULES_5 = {
73
+ constants .EGRESS_DIRECTION : {
74
+ qos_constants .RULE_TYPE_BANDWIDTH_LIMIT : QOS_RULE_BW_1 ,
75
+ qos_constants .RULE_TYPE_DSCP_MARKING : QOS_RULE_DSCP_1 ,
76
+ qos_constants .RULE_TYPE_MINIMUM_BANDWIDTH : QOS_RULE_MINBW_1 },
77
+ }
78
+
72
79
73
80
class _TestOVNClientQosExtensionBase (base .TestOVNFunctionalBase ):
74
81
def setUp (self , maintenance_worker = False ):
@@ -78,7 +85,9 @@ def setUp(self, maintenance_worker=False):
78
85
def _check_rules_qos (self , rules , port_id , network_id , network_type ,
79
86
fip_id = None , ip_address = None , expected_ext_ids = None ):
80
87
qos_rules = copy .deepcopy (rules )
81
- if network_type in (constants .TYPE_VLAN , constants .TYPE_FLAT ):
88
+ min_bw = qos_rules .get (constants .EGRESS_DIRECTION , {}).get (
89
+ qos_constants .RULE_TYPE_MINIMUM_BANDWIDTH )
90
+ if network_type in constants .TYPE_PHYSICAL and min_bw :
82
91
# Remove the egress max-rate and min-rate rules, these are defined
83
92
# in the LSP.options field for a physical network.
84
93
try :
@@ -135,12 +144,13 @@ def _check_rules_qos(self, rules, port_id, network_id, network_type,
135
144
self .assertEqual (bandwidth , rule .bandwidth )
136
145
137
146
def _check_rules_lsp (self , rules , port_id , network_type ):
138
- if network_type not in (constants .TYPE_VLAN , constants .TYPE_FLAT ):
147
+ egress_rules = rules .get (constants .EGRESS_DIRECTION , {})
148
+ min_bw = egress_rules .get (qos_constants .RULE_TYPE_MINIMUM_BANDWIDTH )
149
+ if not (network_type in constants .TYPE_PHYSICAL and min_bw ):
139
150
return
140
151
141
152
# If there are no egress rules, it is checked that there are no
142
153
# QoS parameters in the LSP.options dictionary.
143
- egress_rules = rules .get (constants .EGRESS_DIRECTION , {})
144
154
qos_rule_lsp = self .qos_driver ._ovn_lsp_rule (egress_rules )
145
155
lsp = self .qos_driver .nb_idl .lsp_get (port_id ).execute (
146
156
check_error = True )
@@ -267,6 +277,62 @@ def test_update_policy(self):
267
277
constants .TYPE_VLAN )
268
278
self ._check_rules_lsp (_qos_rules , port ['id' ], constants .TYPE_VLAN )
269
279
280
+ def test_set_and_update_physical_network_qos (self ):
281
+ # The goal of this test is to check how the OVN QoS registers and
282
+ # LSP.options are set and deleted, depending on the QoS policy rules.
283
+ # Check LP#2115952 for more information.
284
+ port = uuidutils .generate_uuid ()
285
+ self ._add_logical_switch_port (port )
286
+
287
+ def _apply_rules (qos_rules ):
288
+ with self .nb_api .transaction (check_error = True ) as txn :
289
+ _qos_rules = copy .deepcopy (qos_rules )
290
+ for direction in constants .VALID_DIRECTIONS :
291
+ _qos_rules [direction ] = _qos_rules .get (direction , {})
292
+ self .mock_qos_rules .return_value = copy .deepcopy (_qos_rules )
293
+ self .qos_driver ._update_port_qos_rules (
294
+ txn , port , self .network_1 , constants .TYPE_VLAN , 'qos1' ,
295
+ None )
296
+
297
+ # Loop this test twice, to check that all the QoS registers and
298
+ # parameters are correctly created, set or removed, regardless of the
299
+ # previous state.
300
+ for _ in range (2 ):
301
+ # Apply QOS_RULES_5: egress with max-bw, min-bw and DSCP rules.
302
+ # * Check the OVN QoS rule created has only DSCP information.
303
+ # * Check the LSP.options have the correct fields.
304
+ _apply_rules (QOS_RULES_5 )
305
+ lsp = self .qos_driver .nb_idl .lsp_get (port ).execute (
306
+ check_error = True )
307
+ for _param in ('qos_max_rate' , 'qos_burst' , 'qos_min_rate' ):
308
+ self .assertIn (_param , lsp .options )
309
+ ls = self .qos_driver .nb_idl .lookup (
310
+ 'Logical_Switch' , ovn_utils .ovn_name (self .network_1 ))
311
+ self .assertEqual (1 , len (ls .qos_rules ))
312
+ rule = ls .qos_rules [0 ]
313
+ self .assertIn (port , rule .match )
314
+ self .assertEqual ({'dscp' : QOS_RULE_DSCP_1 ['dscp_mark' ]},
315
+ rule .action )
316
+ self .assertEqual ({}, rule .bandwidth )
317
+
318
+ # Apply QOS_RULES_3: egress with max-bw only rule.
319
+ # * Check the OVN QoS rule created has only max-bw information.
320
+ # * Check the LSP.options has no QoS information.
321
+ _apply_rules (QOS_RULES_3 )
322
+ lsp = self .qos_driver .nb_idl .lsp_get (port ).execute (
323
+ check_error = True )
324
+ for _param in ('qos_max_rate' , 'qos_burst' , 'qos_min_rate' ):
325
+ self .assertNotIn (_param , lsp .options )
326
+ ls = self .qos_driver .nb_idl .lookup (
327
+ 'Logical_Switch' , ovn_utils .ovn_name (self .network_1 ))
328
+ self .assertEqual (1 , len (ls .qos_rules ))
329
+ rule = ls .qos_rules [0 ]
330
+ self .assertIn (port , rule .match )
331
+ self .assertEqual ({}, rule .action )
332
+ self .assertEqual ({'burst' : QOS_RULE_BW_1 ['max_burst_kbps' ],
333
+ 'rate' : QOS_RULE_BW_1 ['max_kbps' ]},
334
+ rule .bandwidth )
335
+
270
336
271
337
class TestOVNClientQosExtensionEndToEnd (_TestOVNClientQosExtensionBase ):
272
338
0 commit comments