PIM-SM
CLI reference:/routing/pimsm/instance/routing/pimsm/interface-template/routing/pimsm/igmp-interface-template/routing/pimsm/static-rp/routing/pimsm/bsr/routing/pimsm/neighbor/routing/pimsm/interface/routing/pimsm/uib-g/routing/pimsm/uib-sg
IP multicast delivers the same data to many receivers. A sender transmits to a multicast group address, and receivers tell the network that they want the data sent to that group. The network delivers the data from the senders to the receivers.
When the sender and the receivers of a group are on the same network segment, no router is needed, and IGMP snooping switches limit the traffic to the ports with receivers. When they are on different network segments, a multicast routing protocol builds the path between them.
Protocol Independent Multicast - Sparse Mode (PIM-SM, RFC 7761) is the multicast routing protocol of RouterOS. Protocol Independent means that PIM does not depend on a particular unicast routing protocol: it uses the routes in the routing table, whichever protocol created them. Sparse Mode means that data is delivered only to the network segments with receivers that asked for it. To find the receivers on their directly connected networks, routers use the Internet Group Management Protocol (IGMP) for IPv4 and Multicast Listener Discovery (MLD) for IPv6.

PIM-SM is part of the main RouterOS package. It is not available on SMIPS devices (hAP lite, hAP lite TC and hAP mini).
The configuration has these parts, each in its own menu:
- Instance (
/routing/pimsm/instance): one per address family,afi=ip(the default) orafi=ipv6. - PIM interfaces (
/routing/pimsm/interface-template): the interfaces that exchange PIM messages with other routers and forward multicast. - IGMP and MLD queriers
(
/routing/pimsm/igmp-interface-template): the interfaces with receivers. The router sends IGMP (or MLD) queries there and learns the groups from the reports. - Rendezvous point (RP): the root of the shared tree for a group. Set it by hand in
/routing/pimsm/static-rp, or let a bootstrap router (BSR) distribute it (/routing/pimsm/bsr).
Route multicast between two networks on one router
A router with two networks forwards unicast between them through its connected routes. Multicast is not forwarded
until you configure multicast routing. In this example the sender is on ether2 and the client on ether3.
graph LR
S["<b>Sender</b><br/>ether2 192.168.10.10/24"]
R["<b>Router</b>"]
C["<b>Client</b><br/>ether2 192.168.20.10/24"]
S ---|"ether2<br/>192.168.10.1/24"| R
R ---|"ether3<br/>192.168.20.1/24"| C
Add the IP addresses, create a PIM instance with the default settings, enable PIM on the interface towards the sender, and run an IGMP querier on the interface towards the client, so that the router learns the groups the client joins:
/ip/address
add address=192.168.10.1/24 interface=ether2
add address=192.168.20.1/24 interface=ether3
/routing/pimsm/instance
add name=pimsm--1
/routing/pimsm/interface-template
add instance=pimsm--1 interfaces=ether2
/routing/pimsm/igmp-interface-template
add instance=pimsm--1 interfaces=ether3
To test the configuration, use RouterOS devices as the sender and the client. On the client, join the group 239.1.1.1 with the Group Management Protocol, and add a mangle rule that counts the packets that arrive for the group:
/ip/address
add address=192.168.20.10/24 interface=ether2
/routing/gmp
add groups=239.1.1.1 interfaces=ether2
/ip/firewall/mangle
add chain=prerouting action=passthrough \
dst-address=239.1.1.1 protocol=icmp
On the sender, add the address and a mangle rule that sets the time to live (TTL) of the packets to the group, then
send ICMP echo requests to the group. In the lab, RouterOS ping to a multicast group sent the packets with a TTL of
1, which routers do not forward. The mangle rule sets the TTL to 16:
/ip/address
add address=192.168.10.10/24 interface=ether2
/ip/firewall/mangle
add chain=output dst-address=239.1.1.1 action=change-ttl new-ttl=set:16
/ping 239.1.1.1 interface=ether2 count=5
You can also send a continuous stream with the
traffic generator on the sender. The traffic
generator works only when traffic-gen is enabled in device mode:
/tool/traffic-generator/packet-template
add interface=ether2 ip-dst=239.1.1.1 \
mac-dst=01:00:5E:01:01:01/FF:FF:FF:FF:FF:FF name=multicast
/tool/traffic-generator/quick tx-template=multicast mbps=10
On the client, the counter of the mangle rule shows that the five packets arrived. You can also use Torch or the Packet Sniffer on the client:
[admin@MikroTik] > /ip/firewall/mangle/print stats
Columns: CHAIN, ACTION, BYTES, PACKETS
# CHAIN ACTION BYTES PACKETS
0 prerouting passthrough 280 5
On the router, the PIM interfaces show what runs on each interface: P for PIM, G for the IGMP querier:
[admin@MikroTik] > /routing/pimsm/interface/print
Flags: D - DYNAMIC; P - PIM-ENABLED; G - GMP-ENABLED; R - DESIGNATED-ROUTER
J - JOIN-TRACKING
0 DP RJ instance=pimsm--1 interface=ether2 address=192.168.10.1
pim.priority=1 .propagation-delay=500ms .override-interval=2s500ms
1 D G instance=pimsm--1 interface=ether3 address=192.168.20.1
gmp.robustness=2 .query-interval=2m5s .query-response-interval=10s
.last-member-query-interval=1s .querier=yes gmp.state.robustness=2
.query-interval=2m5s
The groups the clients joined are in the (*,G) list, and the sources that send to them in the (S,G) list:
[admin@MikroTik] > /routing/pimsm/uib-g/print
Columns: INSTANCE, GROUP
# INSTANCE GROUP
0 pimsm--1 239.1.1.1
[admin@MikroTik] > /routing/pimsm/uib-sg/print
Flags: K - KEEPALIVE; S - SPT-BIT
Columns: INSTANCE, GROUP, SOURCE
# INSTANCE GROUP SOURCE
0 KS pimsm--1 239.1.1.1 192.168.10.10
Route multicast across several routers with a static RP
PIM-SM builds a shared tree for each group, rooted at a rendezvous point (RP). Receivers join the tree towards the RP, and the first router after the sender registers the source with the RP. All routers must map a group to the same RP. With a static RP you set the RP address on every router by hand. The next section shows how a bootstrap router distributes it instead.
In this example R1 is the RP, the sender is behind R2 and the client behind R3. OSPF provides the unicast routes, including the routes to the loopback address of R1, which is the RP address.
graph TB
R1["<b>R1 (RP)</b><br/>lo 10.0.0.1"]
R2["<b>R2</b><br/>lo 10.0.0.2"]
R3["<b>R3</b><br/>lo 10.0.0.3"]
S["<b>Sender</b><br/>192.168.20.10/24"]
C["<b>Client</b><br/>192.168.30.10/24"]
R1 ---|"ether2 - ether2<br/>10.0.1.0/24"| R2
R1 ---|"ether3 - ether2<br/>10.0.2.0/24"| R3
R2 ---|"ether3<br/>192.168.20.1/24"| S
R3 ---|"ether3<br/>192.168.30.1/24"| C
Configure the IP addresses and OSPF (see OSPF). The networks of the sender and the client are passive OSPF interfaces: OSPF advertises them, but does not look for neighbors there.
R1 (RP)
/ip/address
add address=10.0.0.1/32 interface=lo
add address=10.0.1.1/24 interface=ether2
add address=10.0.2.1/24 interface=ether3
/routing/ospf/instance
add name=ospf--1 router-id=10.0.0.1
/routing/ospf/area
add instance=ospf--1 name=ospf--1
/routing/ospf/interface-template
add area=ospf--1 interfaces=lo,ether2,ether3
R2
/ip/address
add address=10.0.0.2/32 interface=lo
add address=10.0.1.2/24 interface=ether2
add address=192.168.20.1/24 interface=ether3
/routing/ospf/instance
add name=ospf--1 router-id=10.0.0.2
/routing/ospf/area
add instance=ospf--1 name=ospf--1
/routing/ospf/interface-template
add area=ospf--1 interfaces=lo,ether2
add area=ospf--1 interfaces=ether3 passive
R3
/ip/address
add address=10.0.0.3/32 interface=lo
add address=10.0.2.3/24 interface=ether2
add address=192.168.30.1/24 interface=ether3
/routing/ospf/instance
add name=ospf--1 router-id=10.0.0.3
/routing/ospf/area
add instance=ospf--1 name=ospf--1
/routing/ospf/interface-template
add area=ospf--1 interfaces=lo,ether2
add area=ospf--1 interfaces=ether3 passive
Create the PIM instance and enable PIM on all interfaces, the loopback included. On R2 and R3, run an IGMP querier on the network of the sender and the client.
R1 (RP)
/routing/pimsm/instance
add name=pimsm--1
/routing/pimsm/interface-template
add instance=pimsm--1 interfaces=lo,ether2,ether3
R2 and R3
/routing/pimsm/instance
add name=pimsm--1
/routing/pimsm/interface-template
add instance=pimsm--1 interfaces=lo,ether2,ether3
/routing/pimsm/igmp-interface-template
add instance=pimsm--1 interfaces=ether3
Check the PIM neighbors. R1 has two neighbors, R2 and R3 one each. On each link, the router with the higher IP
address is the designated router (R), because all routers have the same priority:
R1
[admin@MikroTik] > /routing/pimsm/neighbor/print
Flags: R - DESIGNATED-ROUTER; J - JOIN-TRACKING
Columns: INSTANCE, ADDRESS, PRIORITY
# INSTANCE ADDRESS PRIORITY
0 RJ pimsm--1 10.0.1.2%ether2 1
1 RJ pimsm--1 10.0.2.3%ether3 1
R2
[admin@MikroTik] > /routing/pimsm/neighbor/print
Flags: J - JOIN-TRACKING
Columns: INSTANCE, ADDRESS, PRIORITY
# INSTANCE ADDRESS PRIORITY
0 J pimsm--1 10.0.1.1%ether2 1
R3
[admin@MikroTik] > /routing/pimsm/neighbor/print
Flags: J - JOIN-TRACKING
Columns: INSTANCE, ADDRESS, PRIORITY
# INSTANCE ADDRESS PRIORITY
0 J pimsm--1 10.0.2.1%ether2 1
Set the loopback address of R1 as the RP on all three routers. Without group, the RP serves all multicast groups.
Every router needs a route to the RP address.
R1, R2 and R3
/routing/pimsm/static-rp
add address=10.0.0.1 instance=pimsm--1
Configure the sender and the client as in the previous example, with the addresses 192.168.20.10/24 and 192.168.30.10/24, and the mangle rules. When the client joins 239.1.1.1, R3 shows the group with the RP and the reverse path forwarding (RPF) neighbor towards it:
R3
[admin@MikroTik] > /routing/pimsm/uib-g/print detail
0 instance=pimsm--1 group=239.1.1.1 rp=10.0.0.1 rpf=10.0.2.1%ether2
On R1, the R flag marks the groups for which the router is the RP:
R1
[admin@MikroTik] > /routing/pimsm/uib-g/print
Flags: R - RP-LOCAL
Columns: INSTANCE, GROUP
# INSTANCE GROUP
0 R pimsm--1 239.1.1.1
When the sender starts, R2, the designated router of the sender's network, creates the (S,G) entry and registers
the source with the RP: it sends the first packets to 10.0.0.1 in PIM Register messages. When the data reaches the RP
on the (S,G) tree, the RP stops the registration, and R2 shows register=prune. R1 (the RP) and R3 have (S,G)
entries with the reverse path towards the source, and the client counts the packets:
R2
[admin@MikroTik] > /routing/pimsm/uib-sg/print detail
Flags: K - KEEPALIVE; S - SPT-BIT
0 KS instance=pimsm--1 group=239.1.1.1 source=192.168.20.10
register=prune
R1
[admin@MikroTik] > /routing/pimsm/uib-sg/print detail
Flags: K - KEEPALIVE; S - SPT-BIT
0 KS instance=pimsm--1 group=239.1.1.1 source=192.168.20.10
rpf=10.0.1.2%ether2
R3
[admin@MikroTik] > /routing/pimsm/uib-sg/print detail
0 instance=pimsm--1 group=239.1.1.1 source=192.168.20.10
rpf=10.0.2.1%ether2
Client
[admin@MikroTik] > /ip/firewall/mangle/print stats where chain=prerouting
Columns: CHAIN, ACTION, BYTES, PACKETS
# CHAIN ACTION BYTES PACKETS
0 prerouting passthrough 280 5
Elect the RP with a bootstrap router
With the bootstrap router (BSR) mechanism, the routers learn the RP from the network instead of a static setting. Candidate BSRs elect one BSR. Candidate RPs announce themselves to it, and the BSR sends the set of RPs to all PIM routers.
In the previous example, replace the static RP with R1 as both the candidate BSR and the candidate RP. The address includes the interface, here the loopback:
R1
/routing/pimsm/static-rp
remove [find address=10.0.0.1]
/routing/pimsm/bsr/candidate
add address=10.0.0.1%lo instance=pimsm--1
/routing/pimsm/bsr/rp-candidate
add address=10.0.0.1%lo instance=pimsm--1
R2 and R3
/routing/pimsm/static-rp
remove [find address=10.0.0.1]
R1 becomes the elected BSR, and the other routers accept it:
R1
[admin@MikroTik] > /routing/pimsm/bsr/print
Flags: D - DYNAMIC
0 D instance=pimsm--1 scope4=224.0.0.0/4 address=10.0.0.1 priority=64
hash-mask-length=30 state=elected
R3
[admin@MikroTik] > /routing/pimsm/bsr/print
Flags: D - DYNAMIC
0 D instance=pimsm--1 scope4=224.0.0.0/4 address=10.0.0.1 priority=64
hash-mask-length=30 state=accept-preferred
The RP set on R3 holds the candidate RP for all multicast groups, and the group uses it:
R3
[admin@MikroTik] > /routing/pimsm/bsr/rp-set/print
0 instance=pimsm--1 group=224.0.0.0/4 rp.address=10.0.0.1
.priority=192 .timeout=2m6s
[admin@MikroTik] > /routing/pimsm/uib-g/print detail
0 instance=pimsm--1 group=239.1.1.1 rp=10.0.0.1 rpf=10.0.2.1%ether2
After the counters are reset, the next five packets from the sender reach the client through the RP that the BSR distributed:
Client
[admin@MikroTik] > /ip/firewall/mangle/print stats where chain=prerouting
Columns: CHAIN, ACTION, BYTES, PACKETS
# CHAIN ACTION BYTES PACKETS
0 prerouting passthrough 280 5
With several candidates:
- Candidate BSR: the one with the highest
prioritybecomes the BSR. The default priority is 64. - Candidate RP: for the same group range, the one with the lowest
priorityvalue is used. The default priority is 192.
Technical details
Designated router
On each network, the PIM routers elect a designated router (DR). The DR registers the senders of its network with the
RP and joins the groups for the receivers of its network. The router with the highest priority in
/routing/pimsm/interface-template wins (default 1). With equal priorities, the router with the highest IP address
wins. The R flag in /routing/pimsm/neighbor marks the neighbor that is the DR, and the R flag in
/routing/pimsm/interface the interfaces where this router is the DR.
Neighbors
The timeout of a neighbor in /routing/pimsm/neighbor shows the time left of the hold time from the neighbor's
last Hello message. RFC 7761 sets the default hold time of a Hello to 3.5 times the hello period: 1 minute 45 seconds with
the default hello period of 30 seconds.
IGMP and MLD queriers
An interface in /routing/pimsm/igmp-interface-template sends IGMPv3 queries in an IPv4 instance and MLDv2 queries
in an IPv6 instance, by default every 2 minutes 5 seconds (query-interval), with a maximum response time of
10 seconds. /routing/pimsm/interface shows the querier state of each interface (gmp.querier).
Log
PIM-SM logs under the pim topic. The route,pim,info messages show when instances, interfaces and groups are
created.
For all properties, see /routing/pimsm in the CLI reference.