| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
The module file for sonic_fbs_classifiers |
| 9 |
""" |
| 10 |
|
| 11 |
from __future__ import absolute_import, division, print_function |
| 12 |
__metaclass__ = type |
| 13 |
|
| 14 |
DOCUMENTATION = """ |
| 15 |
--- |
| 16 |
module: sonic_fbs_classifiers |
| 17 |
version_added: 3.1.0 |
| 18 |
notes: |
| 19 |
- Tested against Enterprise SONiC Distribution by Dell Technologies. |
| 20 |
- Supports C(check_mode). |
| 21 |
short_description: Manage flow based services (FBS) classifiers configuration on SONiC |
| 22 |
description: |
| 23 |
- This module provides configuration management of FBS classifiers for devices running SONiC |
| 24 |
author: "S. Talabi (@stalabi1)" |
| 25 |
options: |
| 26 |
config: |
| 27 |
description: |
| 28 |
- FBS classifiers configuration |
| 29 |
- I(match_acl) and I(match_hdr_fields) are mutually exclusive. |
| 30 |
type: list |
| 31 |
elements: dict |
| 32 |
suboptions: |
| 33 |
class_name: |
| 34 |
description: |
| 35 |
- Name of classifier |
| 36 |
type: str |
| 37 |
required: true |
| 38 |
class_description: |
| 39 |
description: |
| 40 |
- Description of classifier |
| 41 |
type: str |
| 42 |
match_type: |
| 43 |
description: |
| 44 |
- Classifier match type |
| 45 |
- The classifier match type is required for classifier creation and corresponds to either 'match_acl' or 'match_hdr_fields' configuration. |
| 46 |
type: str |
| 47 |
choices: ['acl', 'fields'] |
| 48 |
match_acl: |
| 49 |
description: |
| 50 |
- Match ACL configuration |
| 51 |
type: dict |
| 52 |
suboptions: |
| 53 |
acl_name: |
| 54 |
description: |
| 55 |
- Name of ACL to be used as match criteria |
| 56 |
type: str |
| 57 |
required: true |
| 58 |
acl_type: |
| 59 |
description: |
| 60 |
- Type of ACL to be used as match criteria |
| 61 |
type: str |
| 62 |
choices: ['ip', 'ipv6', 'mac'] |
| 63 |
required: true |
| 64 |
match_hdr_fields: |
| 65 |
description: |
| 66 |
- Match header fields configuration |
| 67 |
- I(ipv4) and I(ipv6) are mutually exclusive. |
| 68 |
type: dict |
| 69 |
suboptions: |
| 70 |
ip: |
| 71 |
description: |
| 72 |
- IP field configuration |
| 73 |
type: dict |
| 74 |
suboptions: |
| 75 |
dscp: |
| 76 |
description: |
| 77 |
- Value of diffserv code point, range 0-63 |
| 78 |
type: int |
| 79 |
protocol: |
| 80 |
description: |
| 81 |
- IP protocol |
| 82 |
type: str |
| 83 |
choices: ['auth', 'gre', 'icmp', 'icmpv6', 'igmp', 'l2tp', 'pim', 'rsvp', 'tcp', 'udp'] |
| 84 |
ipv4: |
| 85 |
description: |
| 86 |
- IPv4 field configuration |
| 87 |
type: dict |
| 88 |
suboptions: |
| 89 |
source_address: |
| 90 |
description: |
| 91 |
- Source IPv4 address prefix |
| 92 |
type: str |
| 93 |
destination_address: |
| 94 |
description: |
| 95 |
- Destination IPv4 address prefix |
| 96 |
type: str |
| 97 |
ipv6: |
| 98 |
description: |
| 99 |
- IPv6 field configuration |
| 100 |
type: dict |
| 101 |
suboptions: |
| 102 |
source_address: |
| 103 |
description: |
| 104 |
- Source IPv6 address prefix |
| 105 |
type: str |
| 106 |
destination_address: |
| 107 |
description: |
| 108 |
- Destination IPv6 address prefix |
| 109 |
type: str |
| 110 |
l2: |
| 111 |
description: |
| 112 |
- Ethernet field configuration |
| 113 |
type: dict |
| 114 |
suboptions: |
| 115 |
source_mac: |
| 116 |
description: |
| 117 |
- Source MAC address |
| 118 |
type: str |
| 119 |
source_mac_mask: |
| 120 |
description: |
| 121 |
- Source MAC address mask |
| 122 |
type: str |
| 123 |
destination_mac: |
| 124 |
description: |
| 125 |
- Destination MAC address |
| 126 |
type: str |
| 127 |
destination_mac_mask: |
| 128 |
description: |
| 129 |
- Destination MAC address mask |
| 130 |
type: str |
| 131 |
dei: |
| 132 |
description: |
| 133 |
- Drop eligible indicator, range 0-1 |
| 134 |
type: int |
| 135 |
ethertype: |
| 136 |
description: |
| 137 |
- Ethertype field to match in ethernet packets |
| 138 |
type: str |
| 139 |
choices: ['arp', 'ipv4', 'ipv6', 'lldp', 'mpls', 'roce', 'vlan'] |
| 140 |
pcp: |
| 141 |
description: |
| 142 |
- Priority code point, range 0-7 |
| 143 |
type: int |
| 144 |
vlanid: |
| 145 |
description: |
| 146 |
- VLAN ID, range 1-4094 |
| 147 |
type: int |
| 148 |
transport: |
| 149 |
description: |
| 150 |
- Transport field configuration |
| 151 |
type: dict |
| 152 |
suboptions: |
| 153 |
source_port: |
| 154 |
description: |
| 155 |
- Source port or range |
| 156 |
- For specifying a range use '..' as a delimeter, e.g. '1..3'. |
| 157 |
type: str |
| 158 |
destination_port: |
| 159 |
description: |
| 160 |
- Destination port or range |
| 161 |
- For specifying a range use '..' as a delimeter, e.g. '1..3'. |
| 162 |
type: str |
| 163 |
icmp_code: |
| 164 |
description: |
| 165 |
- ICMP or ICMPv6 code, range 0-255 |
| 166 |
type: int |
| 167 |
icmp_type: |
| 168 |
description: |
| 169 |
- ICMP or ICMPv6 type, range 0-255 |
| 170 |
type: int |
| 171 |
tcp_flags: |
| 172 |
description: |
| 173 |
- List of TCP flags to match |
| 174 |
type: list |
| 175 |
elements: str |
| 176 |
choices: ['ack', 'fin', 'psh', 'rst', 'syn', 'urg'] |
| 177 |
state: |
| 178 |
description: |
| 179 |
- The state of the configuration after module completion |
| 180 |
type: str |
| 181 |
choices: ['merged', 'deleted', 'replaced', 'overridden'] |
| 182 |
default: merged |
| 183 |
""" |
| 184 |
|
| 185 |
EXAMPLES = """ |
| 186 |
# Using "merged" state |
| 187 |
# |
| 188 |
# Before state: |
| 189 |
# ------------- |
| 190 |
# |
| 191 |
# sonic# show class-map |
| 192 |
# (No 'class-map' configuration present) |
| 193 |
|
| 194 |
- name: Merge FBS classifiers configuration |
| 195 |
dellemc.enterprise_sonic.sonic_fbs_classifiers: |
| 196 |
config: |
| 197 |
- class_name: class1 |
| 198 |
class_description: xyz |
| 199 |
match_type: fields |
| 200 |
match_hdr_fields: |
| 201 |
ip: |
| 202 |
dscp: 0 |
| 203 |
protocol: tcp |
| 204 |
ipv4: |
| 205 |
source_address: 1.1.1.1/1 |
| 206 |
destination_address: 2.2.2.2/2 |
| 207 |
l2: |
| 208 |
source_mac: 1a:2b:3c:4d:5e:6f |
| 209 |
source_mac_mask: 6a:5b:4c:3d:2e:1f |
| 210 |
destination_mac: 2a:4b:6c:8d:10:20 |
| 211 |
destination_mac_mask: 20:10:8d:6c:4b:2a |
| 212 |
dei: 0 |
| 213 |
ethertype: ipv4 |
| 214 |
pcp: 0 |
| 215 |
vlanid: 1 |
| 216 |
transport: |
| 217 |
source_port: 1..3 |
| 218 |
destination_port: 4..6 |
| 219 |
tcp_flags: |
| 220 |
- ack |
| 221 |
- fin |
| 222 |
- psh |
| 223 |
state: merged |
| 224 |
|
| 225 |
# After state: |
| 226 |
# ------------ |
| 227 |
# |
| 228 |
# sonic# show class-map |
| 229 |
# Class-map class1 match-type fields |
| 230 |
# Description: xyz |
| 231 |
# Match: |
| 232 |
# ethertype ip |
| 233 |
# src-mac 1a:2b:3c:4d:5e:6f/6a:5b:4c:3d:2e:1f |
| 234 |
# dst-mac 2a:4b:6c:8d:10:20/20:10:8d:6c:4b:2a |
| 235 |
# vlan 1 |
| 236 |
# pcp be |
| 237 |
# dei 0 |
| 238 |
# ip protocol tcp |
| 239 |
# src-ip 1.1.1.1/1 |
| 240 |
# dst-ip 2.2.2.2/2 |
| 241 |
# dscp default |
| 242 |
# src-port 1-3 |
| 243 |
# dst-port 4-6 |
| 244 |
# tcp-flags fin psh ack |
| 245 |
# Referenced in flows: |
| 246 |
|
| 247 |
|
| 248 |
# Using "replaced" state |
| 249 |
# |
| 250 |
# Before state: |
| 251 |
# ------------- |
| 252 |
# |
| 253 |
# sonic# show class-map |
| 254 |
# Class-map class1 match-type fields |
| 255 |
# Description: xyz |
| 256 |
# Match: |
| 257 |
# ethertype ip |
| 258 |
# src-mac 1a:2b:3c:4d:5e:6f/6a:5b:4c:3d:2e:1f |
| 259 |
# dst-mac 2a:4b:6c:8d:10:20/20:10:8d:6c:4b:2a |
| 260 |
# vlan 1 |
| 261 |
# pcp be |
| 262 |
# dei 0 |
| 263 |
# ip protocol tcp |
| 264 |
# src-ip 1.1.1.1/1 |
| 265 |
# dst-ip 2.2.2.2/2 |
| 266 |
# dscp default |
| 267 |
# src-port 1-3 |
| 268 |
# dst-port 4-6 |
| 269 |
# tcp-flags fin psh ack |
| 270 |
# Referenced in flows: |
| 271 |
# |
| 272 |
# Class-map class2 match-type acl |
| 273 |
# Description: abc |
| 274 |
# Match: |
| 275 |
# ip access-group acl1 |
| 276 |
# Referenced in flows: |
| 277 |
|
| 278 |
- name: Replace FBS classifiers configuration |
| 279 |
dellemc.enterprise_sonic.sonic_fbs_classifiers: |
| 280 |
config: |
| 281 |
- class_name: class1 |
| 282 |
match_hdr_fields: |
| 283 |
l2: |
| 284 |
source_mac: 9a:8b:7c:6d:5e:4f |
| 285 |
source_mac_mask: 2a:4b:1c:9b:1e:0f |
| 286 |
destination_mac: 1a:6c:3c:4f:40:22 |
| 287 |
destination_mac_mask: 26:44:8c:9d:4b:6f |
| 288 |
ethertype: vlan |
| 289 |
pcp: 6 |
| 290 |
vlanid: 2 |
| 291 |
state: replaced |
| 292 |
|
| 293 |
# After state: |
| 294 |
# ------------ |
| 295 |
# |
| 296 |
# sonic# show class-map |
| 297 |
# Class-map class1 match-type fields |
| 298 |
# Description: xyz |
| 299 |
# Match: |
| 300 |
# ethertype 0x8100 |
| 301 |
# src-mac 9a:8b:7c:6d:5e:4f/2a:4b:1c:9b:1e:0f |
| 302 |
# dst-mac 1a:6c:3c:4f:40:22/26:44:8c:9d:4b:6f |
| 303 |
# vlan 2 |
| 304 |
# pcp ic |
| 305 |
# Referenced in flows: |
| 306 |
# |
| 307 |
# Class-map class2 match-type acl |
| 308 |
# Description: abc |
| 309 |
# Match: |
| 310 |
# ip access-group acl1 |
| 311 |
# Referenced in flows: |
| 312 |
|
| 313 |
|
| 314 |
# Using "overridden" state |
| 315 |
# |
| 316 |
# Before state: |
| 317 |
# ------------- |
| 318 |
# |
| 319 |
# sonic# show class-map |
| 320 |
# Class-map class1 match-type fields |
| 321 |
# Description: xyz |
| 322 |
# Match: |
| 323 |
# ethertype 0x8100 |
| 324 |
# src-mac 9a:8b:7c:6d:5e:4f/2a:4b:1c:9b:1e:0f |
| 325 |
# dst-mac 1a:6c:3c:4f:40:22/26:44:8c:9d:4b:6f |
| 326 |
# vlan 2 |
| 327 |
# pcp ic |
| 328 |
# Referenced in flows: |
| 329 |
|
| 330 |
- name: Override FBS classifiers configuration |
| 331 |
dellemc.enterprise_sonic.sonic_fbs_classifiers: |
| 332 |
config: |
| 333 |
- class_name: class2 |
| 334 |
class_description: abc |
| 335 |
match_type: acl |
| 336 |
match_acl: |
| 337 |
acl_name: acl1 |
| 338 |
acl_type: ip |
| 339 |
|
| 340 |
# After state: |
| 341 |
# ------------ |
| 342 |
# |
| 343 |
# sonic# show class-map |
| 344 |
# Class-map class2 match-type acl |
| 345 |
# Description: abc |
| 346 |
# Match: |
| 347 |
# ip access-group acl1 |
| 348 |
# Referenced in flows: |
| 349 |
|
| 350 |
|
| 351 |
# Using "deleted" state |
| 352 |
# |
| 353 |
# Before state: |
| 354 |
# ------------- |
| 355 |
# |
| 356 |
# sonic# show class-map |
| 357 |
# Class-map class1 match-type fields |
| 358 |
# Description: xyz |
| 359 |
# Match: |
| 360 |
# ethertype 0x8100 |
| 361 |
# src-mac 9a:8b:7c:6d:5e:4f/2a:4b:1c:9b:1e:0f |
| 362 |
# dst-mac 1a:6c:3c:4f:40:22/26:44:8c:9d:4b:6f |
| 363 |
# vlan 2 |
| 364 |
# pcp ic |
| 365 |
# Referenced in flows: |
| 366 |
# |
| 367 |
# Class-map class2 match-type acl |
| 368 |
# Description: abc |
| 369 |
# Match: |
| 370 |
# ip access-group acl1 |
| 371 |
# Referenced in flows: |
| 372 |
|
| 373 |
- name: Delete FBS classifiers configuration |
| 374 |
dellemc.enterprise_sonic.sonic_fbs_classifiers: |
| 375 |
config: |
| 376 |
- class_name: class1 |
| 377 |
class_description: xyz |
| 378 |
match_hdr_fields: |
| 379 |
l2: |
| 380 |
source_mac: 9a:8b:7c:6d:5e:4f |
| 381 |
source_mac_mask: 2a:4b:1c:9b:1e:0f |
| 382 |
destination_mac: 1a:6c:3c:4f:40:22 |
| 383 |
destination_mac_mask: 26:44:8c:9d:4b:6f |
| 384 |
ethertype: vlan |
| 385 |
pcp: 6 |
| 386 |
vlanid: 2 |
| 387 |
- class_name: class2 |
| 388 |
state: deleted |
| 389 |
|
| 390 |
# After state: |
| 391 |
# ------------ |
| 392 |
# |
| 393 |
# sonic# show class-map |
| 394 |
# Class-map class1 match-type fields |
| 395 |
# Description: |
| 396 |
# Match: |
| 397 |
# Referenced in flows: |
| 398 |
|
| 399 |
|
| 400 |
# Using "deleted" state |
| 401 |
# |
| 402 |
# Before state: |
| 403 |
# ------------- |
| 404 |
# |
| 405 |
# sonic# show class-map |
| 406 |
# Class-map class1 match-type fields |
| 407 |
# Description: xyz |
| 408 |
# Match: |
| 409 |
# ethertype 0x8100 |
| 410 |
# src-mac 9a:8b:7c:6d:5e:4f/2a:4b:1c:9b:1e:0f |
| 411 |
# dst-mac 1a:6c:3c:4f:40:22/26:44:8c:9d:4b:6f |
| 412 |
# vlan 2 |
| 413 |
# pcp ic |
| 414 |
# Referenced in flows: |
| 415 |
# |
| 416 |
# Class-map class2 match-type acl |
| 417 |
# Description: abc |
| 418 |
# Match: |
| 419 |
# ip access-group acl1 |
| 420 |
# Referenced in flows: |
| 421 |
|
| 422 |
- name: Delete all FBS classifiers configuration |
| 423 |
dellemc.enterprise_sonic.sonic_fbs_classifiers: |
| 424 |
config: |
| 425 |
state: deleted |
| 426 |
|
| 427 |
# After state: |
| 428 |
# ------------ |
| 429 |
# |
| 430 |
# sonic# show class-map |
| 431 |
# (No 'class-map' configuration present) |
| 432 |
""" |
| 433 |
|
| 434 |
RETURN = """ |
| 435 |
before: |
| 436 |
description: The configuration prior to the module invocation. |
| 437 |
returned: always |
| 438 |
type: list |
| 439 |
after: |
| 440 |
description: The resulting configuration module invocation. |
| 441 |
returned: when changed |
| 442 |
type: list |
| 443 |
after_generated: |
| 444 |
description: The generated configuration from module invocation. |
| 445 |
returned: when C(check_mode) |
| 446 |
type: list |
| 447 |
commands: |
| 448 |
description: The set of commands pushed to the remote device. |
| 449 |
returned: always |
| 450 |
type: list |
| 451 |
sample: ['command 1', 'command 2', 'command 3'] |
| 452 |
""" |
| 453 |
|
| 454 |
|
| 455 |
from ansible.module_utils.basic import AnsibleModule |
| 456 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.fbs_classifiers.fbs_classifiers import Fbs_classifiersArgs |
| 457 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.fbs_classifiers.fbs_classifiers import Fbs_classifiers |
| 458 |
|
| 459 |
|
| 460 |
def main(): |
| 461 |
""" |
| 462 |
Main entry point for module execution |
| 463 |
|
| 464 |
:returns: the result form module invocation |
| 465 |
""" |
| 466 |
module = AnsibleModule(argument_spec=Fbs_classifiersArgs.argument_spec, |
| 467 |
supports_check_mode=True) |
| 468 |
|
| 469 |
result = Fbs_classifiers(module).execute_module() |
| 470 |
module.exit_json(**result) |
| 471 |
|
| 472 |
|
| 473 |
if __name__ == '__main__': |
| 474 |
main() |