DMIRror

Manage directed port mirroring

DMIRror

Shortest form: dmir.

Set up per-port mirroring (“directed mirroring”): copy packets received and/or sent on some ports to a destination port or trunk.

dmirror <ports>                              show mirroring of <ports>
dmirror SHow                                 show every port that mirrors
dmirror <ports> Mode=<OFF|ON|Ingress|Egress|All>
        [DestPort=<port>] [DestModule=<modid>] [DestTrunk=<tgid>]
        [MirrorTagProtocolID=<tpid>] [MirrorVlanID=<vid>]

<ports> is a port list such as xe0, ce1,ce2 or all (see pbmp). The CPU port (cpu0) can be a destination. Ingress mirrors received packets, Egress sent packets, and All both.

The shell behaves differently from the built-in help in these ways:

  • The help shows Mode as optional. In fact it is required whenever any option is given; otherwise the shell prints must specify a mode.

  • The help says “DestTrunk overrides DestModule/DestPort”. In fact giving both DestPort and DestTrunk is refused (cannot specify both DestPort and DestTrunk). Any mode other than OFF needs one of them (missing DestPort or DestTrunk).

  • dmirror show works but is not in the help.

  • The mirror TPID and VLAN are applied only when both are given and the destination is a local port, not a trunk.

Warning

Mode=OFF removes every mirror destination on those ports, both ingress and egress, including mirror sessions (SPAN/ERSPAN) that SONiC configured. Setting a mirror uses the same hardware mirror resources as SONiC’s mirror sessions. Neither change is visible to SONiC.

Seeing mirrored traffic with tcpdump: Capture port traffic with tcpdump.

Unvalidated — Copy everything received on xe0 to the CPU (prints nothing on success)

drivshell> dmirror xe0 mode=ingress destport=cpu0

Unvalidated — Stop mirroring on xe0 (also removes any other mirror on xe0)

drivshell> dmirror xe0 mode=off

Hardware-validated — Show the mirror state of one port

drivshell> dmirror xe0
 xe0: -

With a port list and no options, dmirror prints one line per port, for example xe0: Mirror ingress to local port cpu0, or xe0: - when the port does not mirror. A trunk destination shows as to trunk group <n>, and a configured mirror VLAN is appended as (TPID=…, VLAN=…).

dmirror SHow

Show every port that mirrors, one line per port in the format above. If no port mirrors, it prints DMIRror: No mirror ports configured (the prefix is the command’s table name, not what you typed). A SONiC switch without mirror sessions prints this line. Safe.

Hardware-validated

drivshell> dmirror show
DMIRror: No mirror ports configured

Built-in help

Parameters: <ports> [Mode=<Off|On|Ingress|Egress|All>]
    [DestPort=<port>] [DestModule=<modid>] [DestTrunk=<tgid>]
    [MirrorTagProtocolID=<tpid>] [MirrorVlanID=<vid>
    DestTrunk overrides DestModule/DestPort.
    TPID and VLAN are set only if DestPort is a local port.

Further reading

bcmsh.md (published as https://kamelnetworks.github.io/sonic/bcmsh.html), BCM_SDK命令.