18
MULTICAST USING UDP SOCKETS

MULTICAST USING UDP SOCKETS. PRELIMINARIES *CAST Unicast Communication is strictly from one sender to another specified receiver eg: TCP on LAN Broadcast

Embed Size (px)

Citation preview

MULTICAST USING UDP SOCKETS

PRELIMINARIES

*CAST

UnicastCommunication is strictly from one sender to another specified receivereg: TCP on LAN

BroadcastCommunication is strictly from one sender to all other connected receiverseg: ARP on LAN

MulticastCommunication is from one or more senders to a set of connected clients who have elected to receive

○ Efficient if the routers do it (may use hardware capabilities)

○ When bandwidth savings are required (up to 1/N of the bandwidth compared to N separate unicast clients)

○ Used primarily in streaming media (surveillance, habitat monitoring, etc)

MULTICAST APPLICATIONS

○ IP MCAST packet is nearly identical to unicast packets

○ Uses a special class of destination address (class D) which denotes a specific mcast group□ Leading address bits = 1110 in IPv4 and

ff00 in IPv6○ TCP supports just unicast and hence mcast

must use UDP

MULTICAST PACKETS

PROCEDURE

○ Multicast clients receive a stream of packets only if they have previously elect to do so from a sender

○ This is realized through MCAST group memberships which are dynamic and controlled by receivers

○ Routers’ responsibility to learn which sub-networks have active clients with the objective of minimizing packets transmitted

○ Once the receivers join a particular IP multicast group, a multicast distribution tree is constructed for that group

MULTICAST GROUPS

- int getsockopt (int s, int level, int optname, void* optval, int* optlen);

- int setsockopt (int s, int level, int optname, const void* optval, int optlen);

○ s = socket (DGRAM/RAW + AF_INET)○ level = IPPROTO_IP○ optname = value passed/returned to/from

kernel

MULTICAST GROUPS REALIZATION

OPTNAME

IP_MULTICAST_TTLDictates time to live and is set to 1 by default to avoid mcast packets from moving beyond local networku_char ttl = 2;setsockopt(socket, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl));

IP_MULTICAST_IFSelect interface from which mcast packets are sentstruct in_addr interface_addr;setsockopt (socket, IPPROTO_IP, IP_MULTICAST_IF, &interface_addr, sizeof(interface_addr));

IP_DROP_MEMBERSHIPLeave an mcast groupstruct ip_mreq mreq;setsockopt (socket, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq));

IP_ADD_MEMBERSHIP fill a ip_mreq structure and inform kernel of your interest to join groupstruct ip_mreq mreq;setsockopt (socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));

IP_MULTICAST_LOOPDecide whether data sent must loopback - Needed if a process is listeningu_char loop = 0;setsockopt(socket, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop));

IOCTLS and CAVEATS

○ To select outgoing interfaces, ioctls might be useful:□ SIOCGIFADDR (to get an interface's

address)□ SIOCGIFCONF (to get the list of all the

interfaces)□ SIOCGIFFLAGS (to get an interface's flags

and determine if it is multicast capable [IFF_MULTICAST])

○ Alternatively, use ifconfig○ If the host has more than one interface and the

IP_MULTICAST_IF option is not set, multicast transmissions are sent from the default interface

MULTICAST METHODOLOGY

Socket Creationsock = socket(AF_INET, SOCK_DGRAM, 0);

Populate Sockaddr_inaddr.sin_family = AF_INET;addr.sin_addr.s_addr = htonl(INADDR_ANY);addr.sin_port = htons(MCAST_PORT);

Senderaddrs.sin_addr.s_addr = inet_addr(MCAST_GROUP);sendto(sock, message, sizeof(message), 0,&addr, addrlen);

Receiverecvfrom(sock, message, sizeof(message), 0, &addr, &addrlen);

Join MCAST groupmreq.imr_multiaddr.s_addr = inet_addr(MCAST_GROUP); mreq.imr_interface.s_addr = htonl(INADDR_ANY);setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP,&mreq, sizeof(mreq));

1 2

3 3 4

Experiment 1: One sender and one receiver

Experiment 2: Two senders and one receiver

Experiment 3: One sender and two receivers

○ One sender many receivers work if all on stdlinux

○ Many senders and many receivers work if all on stdlinux

○ One sender many receivers work if all on RI○ Many senders and many receivers work if all

on RI○ Mcast doesn’t work across these networks○ Changing ttl didn’t work○ Used “239.0.0.1” and port 6000 for mcast

program ○ Attempted different mcast group ips and ports○ Mostly port 22 packets are allowed

EXPERIMENTS CONCLUSIONS

ROUTING

○ Source address used to determine stream direction

○ Source of mcast traffic is considered upstream○ Router determines which downstream

interfaces are destinations for the mcast group

QUESTIONS

○ What happens when there are no receivers? Do packets get dropped at the router closest source?

○ What are the limits?○ How is security ensured? Didn’t see any

authentication mechanism to allow mcast membership join

○ Are there any restrictions on which IPs can be used for group identification? If not how do routers figure out where receivers lie? Is it brute force?