In a multicast test, it is often required to have at least one multicast receiver and one multicast traffic sender. In Junos OS, the ping utility can be used to send multicast ICMP traffic. However, the type of traffic being sent by the "ping" utility is very limited.
A more powerful method is to run a Python script on an external server to emulate traffic sources. This allows users to change the script and send a variety of customized packets. KB36770 - [Contrail] How to use Scapy to generate TCP traffic [juniper.net] explains how to generate TCP syn flood with the Python Scapy module in a Contrail environment for testing purposes.
This article gives another useful example of generating UDP-based multicast traffic.
In this server, there are three interfaces:
root@server1:~# ip link 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qle n 1000 link/ether 00:50:56:85:68:09 brd ff:ff:ff:ff:ff:ff 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qle n 1000 link/ether 00:50:56:9e:da:41 brd ff:ff:ff:ff:ff:ff
In this example, we will:
Capture packets with tcpdump, which runs in the background, to view the packet details
Compose a template of multicast packets
Send out three multicast packets based on the template, through eth0 NIC of the server
To capture the packets on NIC eth1 in the background, run:
root@cont44:~# tcpdump -ni eth1 host 1.1.1.1 &
Start Python and load Scapy:
root@cont44:~# python from scapy.all import *
Compose a multicast packet template as follows:
payload = "test" * 10 mc_pkt = Ether(dst = "01:00:5e:01:01:01")/IP(src='1.1.1.1', dst='224.1.1.1')/UDP(dport=8888, sport=7777)
Send out three multicast packets out of NIC eth1:
sendp(mc_pkt, iface="eth1", count=3, verbose=True) ... Sent 3 packets.
The packet that is captured on the NIC is as follows:
09:04:45.988305 00:50:56:85:68:09 > 01:00:5e:01:01:01, ethertype IPv4 (0x0800), length 42: (tos 0x0, ttl 64, id 1, offset 0, flags [none], proto UDP (17), length 28) 1.1.1.1.7777 > 224.1.1.1.8888: [udp sum ok] UDP, length 0 09:04:45.989370 00:50:56:85:68:09 > 01:00:5e:01:01:01, ethertype IPv4 (0x0800), length 42: (tos 0x0, ttl 64, id 1, offset 0, flags [none], proto UDP (17), length 28) 1.1.1.1.7777 > 224.1.1.1.8888: [udp sum ok] UDP, length 0 09:04:45.990335 00:50:56:85:68:09 > 01:00:5e:01:01:01, ethertype IPv4 (0x0800), length 42: (tos 0x0, ttl 64, id 1, offset 0, flags [none], proto UDP (17), length 28) 1.1.1.1.7777 > 224.1.1.1.8888: [udp sum ok] UDP, length 0
As seen above, the packets are sent out and captured by tcpdump. The destination MAC address, and the source and destination IP addresses are exactly as what we specified in the Python code.