Python – Multicast UDP not working

multicastnetworkingpythonudp

Multicast UDP on raspberry pi

I haven't narrowed things down enough to know if my issue is because of debian, raspbian specifically, or if I am just missing a something completely.

I have a python application that uses multicast UDP to let other devices on the network know that my application is up and running and available at a specific IP address.

The UDP multicast group is 239.255.250.250 and port is 9131. If I run tcpdump, I can see that the packet I am trying to send is actualy sending out data, but I never see anything come through on other machines on the network.

There are other devices that uses this same kind of "beacon" with same multicast group and port and I can see those packets come through on other machines. The router has no firewall, and I am really kind of out of options at this point.

Below is the basic diagnostics I know how to run. The bad udp chksum looks like it's probably not helpful, but I don't really know anything about that.

Output of ifconfig

eth0      Link encap:Ethernet  HWaddr b8:27:eb:b2:79:12  
          inet addr:192.168.2.7  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1682 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1686 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:119105 (116.3 KiB)  TX bytes:169570 (165.5 KiB)

Output of tcpdump while app is running

    tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
03:29:15.722653 IP (tos 0x0, ttl 1, id 0, offset 0, flags [DF], proto UDP (17), length 221)
    192.168.2.7.33335 > 239.255.250.250.9131: [bad udp cksum 0xae84 -> 0xaabe!] UDP, length 193
    0x0000:  4500 00dd 0000 4000 0111 cb66 c0a8 0207  E.....@....f....
    0x0010:  efff fafa 8237 23ab 00c9 ae84 414d 5842  .....7#.....AMXB
    0x0020:  3c4d 4143 2d41 4444 523d 6238 3a32 373a  <MAC-ADDR=b8:27:
    0x0030:  6562 3a62 323a 3739 3a31 323e 3c2d 5555  eb:b2:79:12><-UU
    0x0040:  4944 3d32 3032 3438 3135 3937 3537 3734  ID=2024815975774
    0x0050:  3930 3e3c 2d53 444b 436c 6173 733d 5574  90><-SDKClass=Ut
    0x0060:  696c 6974 793e 3c2d 4d61 6b65 3d69 5275  ility><-Make=iRu
    0x0070:  6c65 426f 783e 3c2d 4d6f 6465 6c3d 5265  leBox><-Model=Re
    0x0080:  6d6f 7465 426f 783e 3c2d 5265 7669 7369  moteBox><-Revisi
    0x0090:  6f6e 3d30 2e31 3e3c 2d50 6b67 5f4c 6576  on=0.1><-Pkg_Lev
    0x00a0:  656c 3d47 4350 4b30 3032 3e3c 2d43 6f6e  el=GCPK002><-Con
    0x00b0:  6669 672d 5552 4c3d 6874 7470 3a2f 2f31  fig-URL=http://1
    0x00c0:  3932 2e31 3638 2e32 2e37 3a38 303e 3c2d  92.168.2.7:80><-
    0x00d0:  5374 6174 7573 3d52 6561 6479 3e         Status=Ready>
^C
1 packet captured
1 packet received by filter
0 packets dropped by kernel

Output of netstat while program is running

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
udp        0      0 0.0.0.0:31144           0.0.0.0:*                           1510/dhclient   
udp        0      0 0.0.0.0:33335           0.0.0.0:*                           2089/python     
udp        0      0 0.0.0.0:68              0.0.0.0:*                           1510/dhclient   
udp        0      0 192.168.2.7:123         0.0.0.0:*                           1911/ntpd       
udp        0      0 0.0.0.0:123             0.0.0.0:*                           1911/ntpd  

Best Answer

I understand that your host, 192.168.2.7 is sending multicast packet to group 239.255.250.250 on port 9131

NOTE: I assume however that servers are listening on port 9131. you didn't provide any info on this.

From ifconfig output, I can see that MULTICAST is enabled and the tcpdump confirm this.

First make sure that the host running the servers (the one receiving the multicast packet) have joined the multicast group.

On each server host type :

netstat -gn

If you see your multicast address, it has joined the group. If not, then either something is wrong with your server program or possibly kernel settings.

If the server has joined the group but you don't see any packet incoming from client, then check on your router that you have enabled igmp ( your router must be igmp capable)

For example,on cisco router

enable
conf t
ip multicast-routing
For each interface involved.
int <NIC>
ip pim sparse-dense-mode

If igmp is enabled on router, look for debug features to track the packets.

On server side, start a packet capture :

tcpdump -i <NIC> host 239.255.250.250

If you don't see any packet coming in, then the multicast packet are not forwarded (assuming that

Then on client send a multicast packet (use the script in link below to troubleshoot)

NOTE: the UDP packet seems malformed so not sure if servers will be able to read it. You can use the script in link below to confirm whether or not the message in tcpdump are displaying as malformed or not ( they are not in my case)

Example of python code using multicast :

https://stackoverflow.com/questions/603852/multicast-in-python

NOTE: I used this script on a debian raspi ( not raspbian and server received packets through router - as setup above - fine)

Linux guide : http://stlinux.com/howto/network/short-guide

Cisco : http://www.cisco.com/c/en/us/td/docs/switches/lan/catalyst3750/software/release/12-2_52_se/configuration/guide/3750scg/swmcast.html#wp1024278

Related Question