Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_ecmp_load_share.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2025 Dell Inc. or its subsidiaries. All Rights Reserved.
4 # GNU General Public License v3.0+
5 # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 """
8 The module file for sonic_ecmp_load_share
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_ecmp_load_share
17 version_added: 3.1.0
18 author: M. Zhang (@mingjunzhang2019)
19 notes:
20 - Tested against Enterprise SONiC Distribution by Dell Technologies.
21 - Supports C(check_mode).
22 short_description: IP ECMP load share mode configuration handling for SONiC.
23 description:
24 - This module provides configuration management for IP ECMP load share mode on
25 - devices running SONiC.
26 options:
27 config:
28 description:
29 - IP ECMP load share mode configuration.
30 type: dict
31 suboptions:
32 hash_algorithm:
33 description:
34 - Load share hash algorithm.
35 type: str
36 choices:
37 - CRC
38 - XOR
39 - CRC_32LO
40 - CRC_32HI
41 - CRC_CCITT
42 - CRC_XOR
43 - JENKINS_HASH_LO
44 - JENKINS_HASH_HI
45 hash_ingress_port:
46 description:
47 - Include the ingress port in the load share hash calculation.
48 type: bool
49 hash_offset:
50 description:
51 - Load share hash offset.
52 type: dict
53 suboptions:
54 offset:
55 description:
56 - IP ECMP hash offset value.
57 - The range of values is from 0 to 15.
58 type: int
59 flow_based:
60 description:
61 - Enable flow-based IP ECMP hashing.
62 - If this option is set to true, the configured 'offset' value is ignored.
63 type: bool
64 hash_roce_qpn:
65 description:
66 - Include the ROCE Queue-Pair Number in the load share hash calculation.
67 type: bool
68 hash_seed:
69 description:
70 - IP ECMP hash seed value.
71 - The range of values is from 0 to 16777215.
72 type: int
73 ipv4:
74 description:
75 - IPv4 ECMP Load share hash parameters.
76 type: dict
77 suboptions:
78 ipv4_dst_ip:
79 description:
80 - Include the IPv4 destination IP address in the load share hash calculation.
81 type: bool
82 ipv4_src_ip:
83 description:
84 - Include the IPv4 source IP address in the load share hash calculation.
85 type: bool
86 ipv4_ip_proto:
87 description:
88 - Include the IPv4 protocol value in the load share hash calculation.
89 type: bool
90 ipv4_l4_dst_port:
91 description:
92 - Include the IPv4 L4 source port in the load share hash calculation.
93 type: bool
94 ipv4_l4_src_port:
95 description:
96 - IPv4 L4 source port.
97 type: bool
98 ipv4_symmetric:
99 description:
100 - IPv4 symmetric hash mode.
101 type: bool
102 ipv6:
103 description:
104 - IPv6 ECMP Load share hash parameters.
105 type: dict
106 suboptions:
107 ipv6_dst_ip:
108 description:
109 - Include the IPv6 destination IP address in the load share hash calculation.
110 type: bool
111 ipv6_src_ip:
112 description:
113 - Include the IPv6 source IP address in the load share hash calculation.
114 type: bool
115 ipv6_next_hdr:
116 description:
117 - Include the IPv6 "next header" value (usually the Transport Layer protocol type) in the
118 - load share hash calculation.
119 type: bool
120 ipv6_l4_dst_port:
121 description:
122 - Include the IPv6 L4 destination port in the load share hash calculation.
123 type: bool
124 ipv6_l4_src_port:
125 description:
126 - Include the IPv6 L4 source port in the load share hash calculation.
127 type: bool
128 ipv6_symmetric:
129 description:
130 - IPv6 symmetric hash mode.
131 type: bool
132 state:
133 description:
134 - The state of the configuration after module completion.
135 type: str
136 choices:
137 - merged
138 - deleted
139 - replaced
140 - overridden
141 default: merged
142 """
143
144 EXAMPLES = """
145 # Using "deleted" state
146 #
147 # Before state:
148 # -------------
149 #
150 # sonic# show running-configuration | grep load-share
151 # ip load-share hash offset flow-based
152 # ip load-share hash seed 8888
153 # ip load-share hash ipv4 ipv4-dst-ip
154 # ip load-share hash ipv4 ipv4-src-ip
155 # ip load-share hash ipv4 ipv4-ip-proto
156 # ip load-share hash ipv4 ipv4-l4-src-port
157 # ip load-share hash ipv4 ipv4-l4-dst-port
158 # ip load-share hash algorithm CRC
159 # ip load-share hash ingress-port
160 # ip load-share hash roce qpn
161
162 - name: Delete some configuration
163 sonic_ecmp_load_share:
164 config:
165 hash_algorithm: CRC
166 hash_offset:
167 flow_based: true
168 hash_roce_qpn: true
169 hash_seed: 8888
170 ipv4:
171 ipv4_l4_dst_port: true
172 ipv4_l4_src_port: true
173 state: deleted
174
175 # After state:
176 # ------------
177 #
178 # sonic# show running-configuration | grep load-share
179 # ip load-share hash ipv4 ipv4-dst-ip
180 # ip load-share hash ipv4 ipv4-src-ip
181 # ip load-share hash ipv4 ipv4-ip-proto
182 # ip load-share hash ingress-port
183
184
185 # Using "merged" state
186 #
187 # Before state:
188 # -------------
189 #
190 # sonic# show running-configuration | grep load-share
191 # ip load-share hash seed 8888
192 # ip load-share hash ipv4 ipv4-dst-ip
193 # ip load-share hash algorithm CRC
194
195 - name: Merge some configuration
196 sonic_ecmp_load_share:
197 config:
198 hash_algorithm: CRC_32LO
199 hash_ingress_port: true
200 hash_offset:
201 offset: 12
202 flow_based: true
203 hash_roce_qpn: true
204 hash_seed: 9999
205 ipv4:
206 ipv4_src_ip: true
207 ipv4_ip_proto: true
208 ipv4_l4_dst_port: true
209 ipv4_l4_src_port: true
210 state: merged
211
212 # After state:
213 # ------------
214 #
215 # sonic# show running-configuration | grep load-share
216 # ip load-share hash seed 9999
217 # ip load-share hash ipv4 ipv4-dst-ip
218 # ip load-share hash ipv4 ipv4-src-ip
219 # ip load-share hash ipv4 ipv4-ip-proto
220 # ip load-share hash ipv4 ipv4-l4-src-port
221 # ip load-share hash ipv4 ipv4-l4-dst-port
222 # ip load-share hash algorithm CRC_32LO
223 # ip load-share hash ingress-port
224
225
226 # Using "replaced" state
227 #
228 # Before state:
229 # -------------
230 #
231 # sonic# show running-configuration | grep load-share
232 # ip load-share hash offset flow-based
233 # ip load-share hash seed 8888
234 # ip load-share hash ipv4 ipv4-dst-ip
235 # ip load-share hash ipv4 ipv4-src-ip
236 # ip load-share hash algorithm CRC
237 # ip load-share hash ingress-port
238
239 - name: Replace some configuration
240 sonic_ecmp_load_share:
241 config:
242 hash_algorithm: XOR
243 hash_ingress_port: true
244 hash_offset:
245 flow_based: true
246 hash_seed: 7777
247 ipv4:
248 ipv4_src_ip: true
249 state: replaced
250
251 # After state:
252 # ------------
253 #
254 # sonic# show running-configuration | grep load-share
255 # ip load-share hash offset flow-based
256 # ip load-share hash seed 7777
257 # ip load-share hash ipv4 ipv4-src-ip
258 # ip load-share hash algorithm XOR
259 # ip load-share hash ingress-port
260
261
262 # Using overridden
263 #
264 # Before state:
265 # -------------
266 #
267 # sonic# show running-configuration | grep load-share
268 # ip load-share hash offset flow-based
269 # ip load-share hash seed 9999
270 # ip load-share hash ipv4 ipv4-src-ip
271 # ip load-share hash ipv4 ipv4-ip-proto
272 # ip load-share hash ipv4 ipv4-l4-src-port
273 # ip load-share hash ipv4 ipv4-l4-dst-port
274 # ip load-share hash algorithm XOR
275 # ip load-share hash ingress-port
276
277 - name: Override some configuration
278 sonic_ecmp_load_share:
279 config:
280 hash_algorithm: CRC_32LO
281 hash_ingress_port: true
282 hash_offset:
283 flow_based: true
284 hash_seed: 1234
285 ipv4:
286 ipv4_l4_dst_port: true
287 ipv4_l4_src_port: true
288 state: overridden
289
290 # After state:
291 # ------------
292 #
293 # sonic# show running-configuration | grep load-share
294 # ip load-share hash offset flow-based
295 # ip load-share hash seed 1234
296 # ip load-share hash ipv4 ipv4-l4-src-port
297 # ip load-share hash ipv4 ipv4-l4-dst-port
298 # ip load-share hash algorithm CRC_32LO
299 # ip load-share hash ingress-port
300 """
301
302 RETURN = """
303 before:
304 description: The configuration prior to the module invocation.
305 returned: always
306 type: dict
307 after:
308 description: The configuration resulting from module invocation.
309 returned: when changed
310 type: dict
311 after_generated:
312 description: The configuration that would result from non-check-mode module invocation.
313 returned: when C(check_mode)
314 type: dict
315 commands:
316 description: The set of commands pushed to the remote device. In C(check_mode) the needed commands are displayed, but not pushed to the device.
317 returned: always
318 type: list
319 sample: ['command 1', 'command 2', 'command 3']
320 """
321
322
323 from ansible.module_utils.basic import AnsibleModule
324 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.ecmp_load_share.ecmp_load_share import Ecmp_load_shareArgs
325 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.ecmp_load_share.ecmp_load_share import Ecmp_load_share
326
327
328 def main():
329 """
330 Main entry point for module execution
331
332 :returns: the result form module invocation
333 """
334 module = AnsibleModule(argument_spec=Ecmp_load_shareArgs.argument_spec,
335 supports_check_mode=True)
336
337 result = Ecmp_load_share(module).execute_module()
338 module.exit_json(**result)
339
340
341 if __name__ == '__main__':
342 main()