| 1 |
|
| 2 |
|
| 3 |
. |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
The module file for sonic_mirroring |
| 9 |
""" |
| 10 |
|
| 11 |
from __future__ import absolute_import, division, print_function |
| 12 |
__metaclass__ = type |
| 13 |
|
| 14 |
DOCUMENTATION = """ |
| 15 |
--- |
| 16 |
module: sonic_mirroring |
| 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: Manage port mirroring configuration on SONiC. |
| 23 |
description: |
| 24 |
- This module provides configuration management for port mirroring on devices running SONiC. |
| 25 |
options: |
| 26 |
config: |
| 27 |
description: |
| 28 |
- Specifies port mirroring configuration. |
| 29 |
type: dict |
| 30 |
suboptions: |
| 31 |
span: |
| 32 |
description: |
| 33 |
- SPAN mirroring sessions. |
| 34 |
type: list |
| 35 |
elements: dict |
| 36 |
suboptions: |
| 37 |
name: |
| 38 |
description: |
| 39 |
- SPAN mirroring session name. |
| 40 |
required: true |
| 41 |
type: str |
| 42 |
dst_port: |
| 43 |
description: |
| 44 |
- Mirror session destination interface. |
| 45 |
- It may be CPU or an Ethernet interface. |
| 46 |
type: str |
| 47 |
source: |
| 48 |
description: |
| 49 |
- Mirror session source interface. |
| 50 |
- It may be an Ethernet interface or a PortChannel interface. |
| 51 |
type: str |
| 52 |
direction: |
| 53 |
description: |
| 54 |
- Mirror session direction. |
| 55 |
type: str |
| 56 |
choices: |
| 57 |
- rx |
| 58 |
- tx |
| 59 |
- both |
| 60 |
erspan: |
| 61 |
description: |
| 62 |
- ERSPAN mirroring sessions. |
| 63 |
type: list |
| 64 |
elements: dict |
| 65 |
suboptions: |
| 66 |
name: |
| 67 |
description: |
| 68 |
- ERSPAN mirroring session name. |
| 69 |
required: true |
| 70 |
type: str |
| 71 |
dst_ip: |
| 72 |
description: |
| 73 |
- ERSPAN destination IP address. |
| 74 |
type: str |
| 75 |
src_ip: |
| 76 |
description: |
| 77 |
- ERSPAN source IP address. |
| 78 |
type: str |
| 79 |
source: |
| 80 |
description: |
| 81 |
- Mirror session source interface. |
| 82 |
- It may be an Ethernet interface or a PortChannel interface. |
| 83 |
type: str |
| 84 |
direction: |
| 85 |
description: |
| 86 |
- Mirror session direction. |
| 87 |
type: str |
| 88 |
choices: |
| 89 |
- rx |
| 90 |
- tx |
| 91 |
- both |
| 92 |
dscp: |
| 93 |
description: |
| 94 |
- ERSPAN destination DSCP. |
| 95 |
- The range of values is from 0 to 63. |
| 96 |
type: int |
| 97 |
gre: |
| 98 |
description: |
| 99 |
- ERSPAN destination GRE type. |
| 100 |
- A hexadecimal string of the form 0xabcd. |
| 101 |
type: str |
| 102 |
ttl: |
| 103 |
description: |
| 104 |
- ERSPAN destination TTL |
| 105 |
- The range of values is from 0 to 63. |
| 106 |
type: int |
| 107 |
queue: |
| 108 |
description: |
| 109 |
- ERSPAN destination queue number. |
| 110 |
- The range of values is from 0 to 63. |
| 111 |
- Only queue 0 is supported. |
| 112 |
type: int |
| 113 |
state: |
| 114 |
description: |
| 115 |
- Specifies the operation to be performed on the mirroring configured on the device. |
| 116 |
- In case of merged, the input configuration will be merged with the existing configuration on the device. |
| 117 |
- In case of deleted, the input configuration will be removed from the device. |
| 118 |
- In case of overridden, all existing mirroring configuration will be deleted and the specified input configuration will be added. |
| 119 |
- In case of replaced, the existing mirroring configuration on the device will be replaced by the new specified configuration for |
| 120 |
each affected mirroring session. |
| 121 |
type: str |
| 122 |
choices: |
| 123 |
- merged |
| 124 |
- deleted |
| 125 |
- replaced |
| 126 |
- overridden |
| 127 |
default: merged |
| 128 |
""" |
| 129 |
|
| 130 |
EXAMPLES = """ |
| 131 |
# Using "deleted" state |
| 132 |
# |
| 133 |
# Before state: |
| 134 |
# ------------- |
| 135 |
# |
| 136 |
# sonic# show mirror-session |
| 137 |
# ERSPAN Sessions |
| 138 |
# ----------------------------------------------------------------------------------------------------------------------------------------- |
| 139 |
# Name Status SRC-IP DST-IP GRE DSCP TTL Queue Policer SRC-Port Direction |
| 140 |
# ----------------------------------------------------------------------------------------------------------------------------------------- |
| 141 |
# dell-2 inactive 200.22.22.22 100.11.11.11 0 Ethernet28 both |
| 142 |
# SPAN Sessions |
| 143 |
# ------------------------------------------------------------------------------- |
| 144 |
# Name Status DST-Port SRC-Port Direction |
| 145 |
# ------------------------------------------------------------------------------- |
| 146 |
# dell-1 active CPU Ethernet24 both |
| 147 |
# dell-3 active CPU |
| 148 |
|
| 149 |
- name: Delete mirroring configuration |
| 150 |
dellemc.enterprise_sonic.sonic_mirroring: |
| 151 |
config: |
| 152 |
span: |
| 153 |
- name: dell-3 |
| 154 |
erspan: |
| 155 |
- name: dell-2 |
| 156 |
state: deleted |
| 157 |
|
| 158 |
# After state: |
| 159 |
# ------------ |
| 160 |
# |
| 161 |
# sonic# show mirror-session |
| 162 |
# SPAN Sessions |
| 163 |
# ------------------------------------------------------------------------------- |
| 164 |
# Name Status DST-Port SRC-Port Direction |
| 165 |
# ------------------------------------------------------------------------------- |
| 166 |
# dell-1 active CPU Ethernet24 both |
| 167 |
|
| 168 |
|
| 169 |
# Using "merged" state |
| 170 |
# |
| 171 |
# Before state: |
| 172 |
# ------------- |
| 173 |
# |
| 174 |
# sonic# show mirror-session |
| 175 |
# No sessions configured |
| 176 |
|
| 177 |
- name: Merge mirroring configuration |
| 178 |
dellemc.enterprise_sonic.sonic_mirroring: |
| 179 |
config: |
| 180 |
span: |
| 181 |
- name: dell-1 |
| 182 |
dst_port: CPU |
| 183 |
source: Ethernet24 |
| 184 |
direction: both |
| 185 |
erspan: |
| 186 |
- name: dell-2 |
| 187 |
dst_ip: 100.11.11.11 |
| 188 |
src_ip: 200.22.22.22 |
| 189 |
source: Ethernet28 |
| 190 |
direction: both |
| 191 |
queue: 0 |
| 192 |
state: merged |
| 193 |
|
| 194 |
# After state: |
| 195 |
# ------------ |
| 196 |
# |
| 197 |
# sonic# show mirror-session |
| 198 |
# ERSPAN Sessions |
| 199 |
# ----------------------------------------------------------------------------------------------------------------------------------------- |
| 200 |
# Name Status SRC-IP DST-IP GRE DSCP TTL Queue Policer SRC-Port Direction |
| 201 |
# ----------------------------------------------------------------------------------------------------------------------------------------- |
| 202 |
# dell-2 inactive 200.22.22.22 100.11.11.11 0 Ethernet28 both |
| 203 |
# SPAN Sessions |
| 204 |
# ------------------------------------------------------------------------------- |
| 205 |
# Name Status DST-Port SRC-Port Direction |
| 206 |
# ------------------------------------------------------------------------------- |
| 207 |
# dell-1 active CPU Ethernet24 both |
| 208 |
|
| 209 |
|
| 210 |
# Using "merged" state |
| 211 |
# |
| 212 |
# Before state: |
| 213 |
# ------------- |
| 214 |
# |
| 215 |
# sonic# show mirror-session |
| 216 |
# SPAN Sessions |
| 217 |
# ------------------------------------------------------------------------------- |
| 218 |
# Name Status DST-Port SRC-Port Direction |
| 219 |
# ------------------------------------------------------------------------------- |
| 220 |
# dell-1 active CPU Ethernet24 both |
| 221 |
|
| 222 |
- name: Modify existing mirroring configuration |
| 223 |
dellemc.enterprise_sonic.sonic_mirroring: |
| 224 |
config: |
| 225 |
span: |
| 226 |
- name: dell-1 |
| 227 |
dst_port: Ethernet32 |
| 228 |
source: Ethernet4 |
| 229 |
direction: rx |
| 230 |
|
| 231 |
# After state: |
| 232 |
# ------------ |
| 233 |
# |
| 234 |
# sonic# show mirror-session |
| 235 |
# SPAN Sessions |
| 236 |
# ------------------------------------------------------------------------------- |
| 237 |
# Name Status DST-Port SRC-Port Direction |
| 238 |
# ------------------------------------------------------------------------------- |
| 239 |
# dell-1 active Ethernet32 Ethernet4 rx |
| 240 |
|
| 241 |
|
| 242 |
# Using "replaced" state |
| 243 |
# |
| 244 |
# Before state: |
| 245 |
# ------------- |
| 246 |
# |
| 247 |
# sonic# show mirror-session |
| 248 |
# ERSPAN Sessions |
| 249 |
# ----------------------------------------------------------------------------------------------------------------------------------------- |
| 250 |
# Name Status SRC-IP DST-IP GRE DSCP TTL Queue Policer SRC-Port Direction |
| 251 |
# ----------------------------------------------------------------------------------------------------------------------------------------- |
| 252 |
# dell-2 inactive 200.22.22.22 100.11.11.11 0 Ethernet28 both |
| 253 |
# SPAN Sessions |
| 254 |
# ------------------------------------------------------------------------------- |
| 255 |
# Name Status DST-Port SRC-Port Direction |
| 256 |
# ------------------------------------------------------------------------------- |
| 257 |
# dell-1 active CPU Ethernet24 both |
| 258 |
# dell-3 active CPU |
| 259 |
|
| 260 |
- name: Replace mirroring configuration |
| 261 |
dellemc.enterprise_sonic.sonic_mirroring: |
| 262 |
config: |
| 263 |
erspan: |
| 264 |
- name: dell-2 |
| 265 |
dst_ip: 32.22.22.12 |
| 266 |
src_ip: 31.21.21.12 |
| 267 |
source: Ethernet28 |
| 268 |
dscp: 6 |
| 269 |
gre: "0x6689" |
| 270 |
ttl: 9 |
| 271 |
queue: 0 |
| 272 |
direction: rx |
| 273 |
- name: dell-3 |
| 274 |
dst_ip: 22.22.22.12 |
| 275 |
src_ip: 21.21.21.12 |
| 276 |
source: Ethernet28 |
| 277 |
direction: rx |
| 278 |
span: |
| 279 |
- name: dell-1 |
| 280 |
dst_port: Ethernet4 |
| 281 |
source: Ethernet24 |
| 282 |
direction: tx |
| 283 |
state: replaced |
| 284 |
|
| 285 |
# After state: |
| 286 |
# ------------ |
| 287 |
# |
| 288 |
# sonic# show mirror-session |
| 289 |
# ERSPAN Sessions |
| 290 |
# ----------------------------------------------------------------------------------------------------------------------------------------- |
| 291 |
# Name Status SRC-IP DST-IP GRE DSCP TTL Queue Policer SRC-Port Direction |
| 292 |
# ----------------------------------------------------------------------------------------------------------------------------------------- |
| 293 |
# dell-2 inactive 32.22.22.22 31.11.11.11 0x6689 6 9 0 Ethernet28 rx |
| 294 |
# dell-3 inactive 21.21.21.12 22.22.22.12 Ethernet28 rx |
| 295 |
# SPAN Sessions |
| 296 |
# ------------------------------------------------------------------------------- |
| 297 |
# Name Status DST-Port SRC-Port Direction |
| 298 |
# ------------------------------------------------------------------------------- |
| 299 |
# dell-1 active Ethertnet4 Ethernet24 tx |
| 300 |
|
| 301 |
|
| 302 |
# Using "overridden" state |
| 303 |
# |
| 304 |
# Before state: |
| 305 |
# ------------- |
| 306 |
# |
| 307 |
# sonic# show mirror-session |
| 308 |
# ERSPAN Sessions |
| 309 |
# ----------------------------------------------------------------------------------------------------------------------------------------- |
| 310 |
# Name Status SRC-IP DST-IP GRE DSCP TTL Queue Policer SRC-Port Direction |
| 311 |
# ----------------------------------------------------------------------------------------------------------------------------------------- |
| 312 |
# dell-2 inactive 200.22.22.22 100.11.11.11 0 Ethernet28 both |
| 313 |
# SPAN Sessions |
| 314 |
# ------------------------------------------------------------------------------- |
| 315 |
# Name Status DST-Port SRC-Port Direction |
| 316 |
# ------------------------------------------------------------------------------- |
| 317 |
# dell-1 active CPU Ethernet24 both |
| 318 |
# dell-3 active CPU |
| 319 |
|
| 320 |
- name: Override mirroring configuration |
| 321 |
dellemc.enterprise_sonic.sonic_mirroring: |
| 322 |
config: |
| 323 |
erspan: |
| 324 |
- name: dell-2 |
| 325 |
dst_ip: 32.22.22.12 |
| 326 |
src_ip: 31.21.21.12 |
| 327 |
source: Ethernet28 |
| 328 |
gre: "0x6689" |
| 329 |
dscp: 6 |
| 330 |
ttl: 9 |
| 331 |
queue: 0 |
| 332 |
direction: rx |
| 333 |
- name: dell-1 |
| 334 |
dst_ip: 22.22.22.12 |
| 335 |
src_ip: 21.21.21.12 |
| 336 |
source: Ethernet28 |
| 337 |
direction: rx |
| 338 |
span: |
| 339 |
- name: dell-6 |
| 340 |
dst_port: CPU |
| 341 |
source: Ethernet24 |
| 342 |
direction: tx |
| 343 |
state: overridden |
| 344 |
|
| 345 |
# After state: |
| 346 |
# ------------ |
| 347 |
# |
| 348 |
# sonic# show mirror-session |
| 349 |
# ERSPAN Sessions |
| 350 |
# ----------------------------------------------------------------------------------------------------------------------------------------- |
| 351 |
# Name Status SRC-IP DST-IP GRE DSCP TTL Queue Policer SRC-Port Direction |
| 352 |
# ----------------------------------------------------------------------------------------------------------------------------------------- |
| 353 |
# dell-1 inactive 21.21.21.12 22.22.22.12 Ethernet28 rx |
| 354 |
# dell-2 inactive 31.21.21.12 32.22.22.12 0x6689 6 9 0 Ethernet28 rx |
| 355 |
# SPAN Sessions |
| 356 |
# ------------------------------------------------------------------------------- |
| 357 |
# Name Status DST-Port SRC-Port Direction |
| 358 |
# ------------------------------------------------------------------------------- |
| 359 |
# dell-6 active Ethertnet4 Ethernet24 tx |
| 360 |
""" |
| 361 |
|
| 362 |
RETURN = """ |
| 363 |
before: |
| 364 |
description: The configuration prior to the module invocation. |
| 365 |
returned: always |
| 366 |
type: dict |
| 367 |
after: |
| 368 |
description: The configuration resulting from module invocation. |
| 369 |
returned: when changed |
| 370 |
type: dict |
| 371 |
after_generated: |
| 372 |
description: The configuration that would result from non-check-mode module invocation. |
| 373 |
returned: when C(check_mode) |
| 374 |
type: dict |
| 375 |
commands: |
| 376 |
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. |
| 377 |
returned: always |
| 378 |
type: list |
| 379 |
sample: ['command 1', 'command 2', 'command 3'] |
| 380 |
""" |
| 381 |
|
| 382 |
|
| 383 |
from ansible.module_utils.basic import AnsibleModule |
| 384 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.mirroring.mirroring import MirroringArgs |
| 385 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.mirroring.mirroring import Mirroring |
| 386 |
|
| 387 |
|
| 388 |
def main(): |
| 389 |
""" |
| 390 |
Main entry point for module execution |
| 391 |
|
| 392 |
:returns: the result form module invocation |
| 393 |
""" |
| 394 |
module = AnsibleModule(argument_spec=MirroringArgs.argument_spec, |
| 395 |
supports_check_mode=True) |
| 396 |
|
| 397 |
result = Mirroring(module).execute_module() |
| 398 |
module.exit_json(**result) |
| 399 |
|
| 400 |
|
| 401 |
if __name__ == '__main__': |
| 402 |
main() |