Debian Codegraph @

neutron_lib/agent/common/utils.py

raw
1 # Copyright 2022
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16 from neutron_lib.agent.common import constants
17
18
19 def _replace_register(flow_params, register_number, register_value):
20 """Replace value from flows to given register number
21
22 'register_value' key in dictionary will be replaced by register number
23 given by 'register_number'
24
25 :param flow_params: Dictionary containing defined flows
26 :param register_number: The number of register where value will be stored
27 :param register_value: Key to be replaced by register number
28
29 """
30 try:
31 reg_port = flow_params[register_value]
32 del flow_params[register_value]
33 flow_params[f'reg{register_number:d}'] = reg_port
34 except KeyError:
35 pass
36
37
38 def create_reg_numbers(flow_params):
39 """Replace reg_(port|net) values with defined register numbers"""
40 _replace_register(flow_params, constants.REG_PORT, constants.PORT_REG_NAME)
41 _replace_register(flow_params, constants.REG_NET, constants.NET_REG_NAME)
42 _replace_register(flow_params,
43 constants.REG_REMOTE_GROUP,
44 constants.REMOTE_GROUP_REG_NAME)
45 _replace_register(flow_params,
46 constants.REG_MIN_BW,
47 constants.MIN_BW_REG_NAME)
48 _replace_register(flow_params,
49 constants.REG_INGRESS_BW_LIMIT,
50 constants.INGRESS_BW_LIMIT_REG_NAME)