[erlang-questions] UDP multicast on Raspberry Pi

Rad Gruchalski radek@REDACTED
Fri May 15 22:21:09 CEST 2015


Hi everyone,  

I’m seem to be having issues setting up multicast on Raspberry Pi running latest available Raspbian (2015-05-05 Wheezy).
I have created a minimal viable example to make sure that all the complexity of my software is out of the way.

First, verifying that multicast is working - on RPi:

iperf -s -u -B 239.0.0.250 -i 1

and on my machine:

iperf -c 239.0.0.250 -u -T 32 -t 3 -i 1

My RPi displays:

Server listening on UDP port 5001
Binding to local address 239.0.0.250
Joining multicast group  239.0.0.250
Receiving 1470 byte datagrams
UDP buffer size:  160 KByte (default)
------------------------------------------------------------
[  3] local 239.0.0.250 port 5001 connected with 10.128.30.104 port 55840
[ ID] Interval       Transfer     Bandwidth        Jitter   Lost/Total Datagrams
[  3]  0.0- 1.0 sec  79.0 KBytes   647 Kbits/sec  12.543 ms    0/   55 (0%)
[  3]  1.0- 2.0 sec   169 KBytes  1.39 Mbits/sec  11.075 ms    0/  118 (0%)
[  3]  2.0- 3.0 sec  51.7 KBytes   423 Kbits/sec  15.568 ms    0/   36 (0%)
[  3]  3.0- 4.0 sec  83.3 KBytes   682 Kbits/sec  11.260 ms    0/   58 (0%)
[  3]  0.0- 4.3 sec   386 KBytes   728 Kbits/sec  54.013 ms    0/  268 (0%)
[  3]  0.0- 4.3 sec  1 datagrams received out-of-order


Suggesting that I can receive multicast. This works both ways.

Here is my Erlang UDP multicast server:

-module(udp_multicast).

-behaviour(gen_server).

-export([start_link/0, stop/0]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, code_change/3, terminate/2]).

start_link() ->
  gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

stop() -> gen_server:cast(?MODULE, stop).

init([]) ->
  Port = 6666,
  MulticastIp = {239,0,0,251},
  IfaceIp = {0,0,0,0},
  {ok, OverlaySocket} = gen_udp:open(Port, [ binary,
                                             {ip, MulticastIp},
                                             {multicast_ttl, 4},
                                             {multicast_loop, true},
                                             {broadcast, true},
                                             {add_membership, {MulticastIp, IfaceIp}} ] ),
  { ok, OverlaySocket }.

handle_info({udp, _ClientSocket, _ClientIp, _ClientPort, Msg}, State) ->
  error_logger:info_msg("Received multicast data: ~p", [ Msg ]),
  {noreply, State}.

handle_call( _, _From, State) ->
  { reply, ok, State }.

code_change(_OldVsn, State, _Extra) ->
  {ok, State}.

terminate(_, _) ->
  ok.

handle_cast(stop, LoopData) ->
  {noreply, LoopData}.


And this is the client I use to push multicast data:

-module(mcc).

-export([run/0]).

run() ->
  Port = 6666,
  MulticastIp = {239,0,0,251},
  IfaceIp = {0,0,0,0},
  {ok, OverlaySocket} = gen_udp:open(Port, [ binary,
                                             {ip, MulticastIp},
                                             {multicast_ttl, 4},
                                             {multicast_loop, true},
                                             {broadcast, true},
                                             {add_membership, {MulticastIp, IfaceIp}} ] ),
  gen_udp:send( OverlaySocket, MulticastIp, Port, <<"some random datas">> ),
  gen_udp:close( OverlaySocket ).


If I start the udp_multicast program on my development machine and run mcc from RPi, I receive the data. If I do it the other way around, udp_multicast listening on RPi and mcc run from development box, no data is received on RPi. There’s no firewall in between and the router puts no restriction on multicast.  
I’m baffled and looking for some ideas where could I start looking for possible cause. These tests have been done with OTP 17.4 and 17.5.

RPi system details:

pi@REDACTED ~ $ erl
Erlang/OTP 17 [erts-6.4] [source] [smp:4:4] [async-threads:10] [kernel-poll:false]

Eshell V6.4  (abort with ^G)
1> erlang:system_info(system_architecture).
"armv7l-unknown-linux-gnueabihf”


> uname -a
Linux raspberrypi 3.18.11-v7+ #781 SMP PREEMPT Tue Apr 21 18:07:59 BST 2015 armv7l GNU/Linux

Erlang built from sources using following instructions:
https://gist.github.com/radekg/93c1ca2c18c34830ac05










Kind regards,

Radek Gruchalski

radek@REDACTED (mailto:radek@REDACTED)
 (mailto:radek@REDACTED)
de.linkedin.com/in/radgruchalski/ (http://de.linkedin.com/in/radgruchalski/)

Confidentiality:
This communication is intended for the above-named person and may be confidential and/or legally privileged.
If it has come to you in error you must take no action based on it, nor must you copy or show it to anyone; please delete/destroy and inform the sender immediately.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150515/8b09d6a5/attachment.htm>


More information about the erlang-questions mailing list