1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
# Copyright VyOS maintainers and contributors <maintainers@vyos.io>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.
#
# Rename `vpp settings logging default-log-level` to
# `vpp settings logging default-level` (T8255)
#
# Move 'vpp nat44' and 'vpp settings nat44' to 'vpp nat nat44'.
# Drop settings for nat workers (T8254)
#
# Delete 'ipsec' node and all settings and replace it with single 'ipsec-acceleration' flag (T8262)
#
# Unify CPU settings into a single 'cpu-cores' node under 'resource-allocation' (T8268)
#
# Convert `vpp settings interface <name> rx-mode` and `vpp kernel-interfaces <name> rx-mode`
# to `vpp settings interfaces-rx-mode` by choose the worst value from all nodes (T8266)
#
# Get rid of 'dpdk-options' section for 'num-*' parameters:
# - `vpp settings interface <ethN> dpdk-options num-*`
# - `vpp settings interface <ethN> num-*`
# and delete `vpp settings interface <ethN> dpdk-options promisc` (T8274)
#
# Migrate all resource settings into 'resource-allocation' section (T8261)
#
from vyos.configtree import ConfigTree
def _migrate_vpp_unix_settings(config: ConfigTree) -> None:
base_path = ['vpp', 'settings']
old_base_path = base_path + ['unix']
old_path = old_base_path + ['poll-sleep-usec']
new_path = base_path + ['poll-sleep-usec']
if config.exists(old_path):
poll_sleep_usec = config.return_value(old_path)
config.set(new_path, value=poll_sleep_usec)
config.delete(old_base_path)
def _migrate_vpp_log(config: ConfigTree) -> None:
base = ['vpp', 'settings', 'logging']
if config.exists(base + ['default-log-level']):
config.rename(base + ['default-log-level'], 'default-level')
def _migrate_vpp_nat44(config: ConfigTree) -> None:
base_path = ['vpp', 'nat44']
new_base_path = ['vpp', 'nat', 'nat44']
settings_path = ['vpp', 'settings', 'nat44']
if not config.exists(base_path):
# Nothing to do
return
if not config.exists(['vpp', 'nat']):
config.set(['vpp', 'nat'])
# copy "vpp nat44" to "vpp nat nat44"
config.copy(base_path, new_base_path)
config.delete(base_path)
# move 'vpp settings nat44' to 'vpp nat nat44'
if config.exists(settings_path):
if config.exists(settings_path + ['session-limit']):
session_limit = config.return_value(settings_path + ['session-limit'])
config.set(new_base_path + ['session-limit'], value=session_limit)
if config.exists(settings_path + ['timeout']):
config.copy(settings_path + ['timeout'], new_base_path + ['timeout'])
config.delete(settings_path)
def _migrate_vpp_ipsec(config: ConfigTree) -> None:
base = ['vpp', 'settings']
if config.exists(base + ['ipsec']):
config.set(base + ['ipsec-acceleration'])
config.delete(base + ['ipsec'])
def _migrate_vpp_cpu(config: ConfigTree) -> None:
settings_path = ['vpp', 'settings']
cpu_path = settings_path + ['cpu']
if not config.exists(cpu_path):
# Nothing to do
return
# get number of configured workers
workers = 0
if config.exists(cpu_path + ['workers']):
workers += int(config.return_value(cpu_path + ['workers']))
# add main-core to total workers
workers += 1
if config.exists(cpu_path + ['corelist-workers']):
def _count_range(item: str) -> int:
if '-' in item:
start, end = map(int, item.split('-'))
return end - start + 1
return 1
tmp = config.return_values(cpu_path + ['corelist-workers'])
workers = sum(_count_range(item) for item in tmp) + 1 # + main core
# set 'resource-allocation cpu-cores'
if workers:
config.set(settings_path + ['resource-allocation', 'cpu-cores'], value=str(workers))
config.delete(cpu_path)
def _migrate_vpp_interface_rx_mode(config: ConfigTree) -> None:
# Per-interface rx-mode commands
external_interface_path = ['vpp', 'settings', 'interface']
kernel_interface_path = ['vpp', 'kernel-interfaces']
# New global interface rx-mode command
new_rx_mode_path = ['vpp', 'settings', 'interface-rx-mode']
def _iter_by_rx_modes(base_path: list):
if config.exists(base_path):
for iface_name in config.list_nodes(base_path):
rx_mode_path = base_path + [iface_name, 'rx-mode']
if config.exists(rx_mode_path):
rx_mode = config.return_value(rx_mode_path)
yield rx_mode, rx_mode_path
rx_modes = set()
def _collect_rx_modes(base_path: list):
for rx_mode, _ in _iter_by_rx_modes(base_path):
rx_modes.add(rx_mode)
_collect_rx_modes(external_interface_path)
_collect_rx_modes(kernel_interface_path)
if not rx_modes:
return
if 'interrupt' in rx_modes:
rx_mode = 'interrupt'
elif 'adaptive' in rx_modes:
rx_mode = 'adaptive'
else:
rx_mode = 'polling'
config.set(new_rx_mode_path, value=rx_mode)
def _delete_rx_modes(base_path: list):
for _, rx_mode_path in _iter_by_rx_modes(base_path):
config.delete(rx_mode_path)
_delete_rx_modes(external_interface_path)
_delete_rx_modes(kernel_interface_path)
def _migrate_vpp_dpdk_options(config: ConfigTree) -> None:
base_path = ['vpp', 'settings', 'interface']
params = ['num-rx-desc', 'num-rx-queues', 'num-tx-desc', 'num-tx-queues']
if not config.exists(base_path):
return
for iface_name in config.list_nodes(base_path):
iface_path = base_path + [iface_name]
dpdk_path = iface_path + ['dpdk-options']
if config.exists(dpdk_path):
for param in params:
param_path = dpdk_path + [param]
new_param_path = iface_path + [param]
if config.exists(param_path):
# Move `vpp settings interface <iface_name> dpdk-options num-*`
# to `vpp settings interface <iface_name> num-*`
config.copy(param_path, new_param_path)
config.delete(param_path)
# Delete `vpp settings interface <iface_name> dpdk-options promisc`
promisc_path = dpdk_path + ['promisc']
if config.exists(promisc_path):
config.delete(promisc_path)
def _migrate_vpp_resources(config: ConfigTree) -> None:
base = ['vpp', 'settings']
new_base = ['vpp', 'settings', 'resource-allocation']
if not config.exists(new_base):
config.set(new_base)
if config.exists(base + ['buffers']):
# copy "settings buffers" to "settings resource-allocation buffers"
config.copy(base + ['buffers'], new_base + ['buffers'])
config.delete(base + ['buffers'])
if config.exists(base + ['memory']):
# copy "settings memory" to "settings resource-allocation memory"
config.copy(base + ['memory'], new_base + ['memory'])
config.delete(base + ['memory'])
if config.exists(base + ['statseg']):
# copy "settings statseg" to "settings resource-allocation memory stats"
if not config.exists(new_base + ['memory']):
config.set(new_base + ['memory'])
config.copy(base + ['statseg'], new_base + ['memory', 'stats'])
config.delete(base + ['statseg'])
if config.exists(base + ['ipv6']):
# copy "settings ipv6" to "settings resource-allocation ipv6"
config.copy(base + ['ipv6'], new_base + ['ipv6'])
config.delete(base + ['ipv6'])
if config.exists(base + ['lcp']):
# move "settings lcp ignore-kernel-routes" to "settings resource-allocation ignore-kernel-routes"
# and remove "settings lcp netlink" node
if config.exists(base + ['lcp', 'ignore-kernel-routes']):
config.set(new_base + ['ignore-kernel-routes'])
config.delete(base + ['lcp'])
if config.exists(base + ['l2learn']):
# move "settings l2learn limit" to "settings resource-allocation mac-limit"
if config.exists(base + ['l2learn', 'limit']):
tmp = config.return_value(base + ['l2learn', 'limit'])
config.set(new_base + ['mac-limit'], value=tmp)
config.delete(base + ['l2learn'])
if config.exists(base + ['physmem']):
# move "settings physmem max-size" to "settings resource-allocation memory physmem-max-size"
if config.exists(base + ['physmem', 'max-size']):
tmp = config.return_value(base + ['physmem', 'max-size'])
config.set(new_base + ['memory', 'physmem-max-size'], value=tmp)
config.delete(base + ['physmem'])
if len(config.list_nodes(new_base)) == 0:
config.delete(new_base)
def migrate(config: ConfigTree) -> None:
if not config.exists(['vpp']):
# Nothing to do
return
_migrate_vpp_unix_settings(config)
_migrate_vpp_log(config)
_migrate_vpp_nat44(config)
_migrate_vpp_ipsec(config)
_migrate_vpp_cpu(config)
_migrate_vpp_interface_rx_mode(config)
_migrate_vpp_dpdk_options(config)
_migrate_vpp_resources(config)
|