Exercises: Multicast
Before asking questions regarding this exercise, please review the
lecture notes of Week #05 (and #06) as well as the documentation on the Erlang
web pages.
Multicast
Implement basic multicast, FIFO ordered multicast and Totally ordered
multicast in Erlang.
For each of these implement separate Erlang modules that provide the
following interface:
minit(NodeID, NodePid, Group)
called by every node to initialise the underlying multicast
implementation.
NodeID - a unique id for the node
NodePid - the node's Pid
Group - a list of Pids of all the nodes in the multicast group
msend(Group, Msg)
multicast the given message to the group
Group - a list of Pids of all the nodes in the multicast group
Msg - the message to send
mreceive()
wait to receive a multicast message. This will return a tuple
{From, Msg} with the next deliverable message that was multicast to
the group. The messages returned are ordered according to the
guarantees provided by the underlying implementation (e.g, no
ordering, FIFO, total ordering).
An example of using such a module follows (where bmcast.erl implements
basic multicast):
do_test(NodeID, Group) ->
% init the multicast library
bmcast:minit(NodeID, self(), Group),
% send some multicasts
bmcast:msend(Group, NodeID),
bmcast:msend(Group, NodeID+10),
bmcast:msend(Group, NodeID+20),
% receive multicasts from everyone else
do_receive().
% loop forever trying to receive multicast messages
do_receive() ->
{From, Msg} = bmcast:mreceive(),
io:format("received ~w (~w)~n", [Msg, From]),
do_receive().
You'll notice that Erlang communication is ordered, so in order to
really test your implementation you'll want to implement a send function
that reorders message sends, for example, by delaying them for a random
amount of time.
COMP9243,
School of Computer Science and Engineering,
University of New South Wales
CRICOS Provider Number: 00098G
This page is maintained by
cs9243@cse.unsw.edu.au
Last modified: Tuesday, 31-Jan-2012 17:58:46 EST
|