Broadcast and Multicast
Unicast Host 2Host 1
Broadcast Packet received by every host on network (including the sender!)
Multicast Packet received by a selected subset of hosts in the network Root Leaf
Broadcast Advantages –Reducing Network Traffic Network Time Protocol (NTP), Route Broadcasts –Resource Discovery ARP, BOOTP
Broadcast… Disadvantage –Everybody receives a packet, whether they want it or not. Receving a packet Interrupting your work and processing the packet.
Types of broadcast addresses IP Address can be broken down as {netid, subnetid, hostid} E.g Netid 224 subnet id 19 host id
Types of broadcast addresses… Subnet-directed broadcast {netid, subnetid, *} E.g Broadcasts to local subnet. Routers do not forward these types of broadcast.
Types of broadcast addresses… All-Subnet broadcast {netid, *, *} E.g Broadcasts to all subnets under netid Almost never used. May not be allowed for administrative reasons.
Types of broadcast addresses… Network directed broadcast {netid, *} For networks without sub-netting Doesn’t exist anymore
Types of broadcast addresses… Limited broadcast address {*, *, *} E.g Older form of Subnet-directed broadcast Broadcasts to local subnet Never forwarded across routers.
How broadcast works Sender UDP IPv4 Data Link Receiver UDP IPv4 Data Link UDP IPv4 Data Link X Dest IP = Dest Port = 9999 Dest Ethernet addr ff:ff:ff:ff:ff:ff Port 9999
Example Echo from Multiple Servers
int sockfd, on=1, len; char recvline[MAXLILNE]; struct sockaddr_in reply_addr, bcastaddr; sockfd = Socket(…); /* Enable broadcast on socket */ Setsockopt(sockfd, SOL_SOCKET,SO_BROADCAST, &on, sizeof(on)); /* Set a receive timeout on socket */ tv.tv_sec = 5; tv.tv_usec = 0; Setsockopt( sockfd, SOL_SOCKET, SO_RCVTIMEO, (void *)&tv, sizeof(tv)); Initialize bcastaddr with IP = and Port = 9999
/* Broadcast a Hello */ Sendto(sockfd, “Hello”, strlen(“Hello”), 0, (struct sockaddr *)&bcastaddr, sizeof(bcastaddr)); /* Receive Echos from servers*/ for(;;) { len = sizeof(reply_addr); n = recvfrom (sockfd, recvline, MAXLINE, 0, &reply_addr, &len); if( n < 0) { if (errno == EAGAIN) { printf(“Waited for 5 seconds - exiting\n”); } else { perror(“ERROR”); } exit(0); } recvline[n] = 0; printf(“%s\n”, recvline); }
Multicast
Multicast addresses Class D address : – to Low order 28 bits identify a multicast group id. Link Local addresses : – to –Reserved for network maintenance messages –Never forwarded by routers All-hosts group All-routers group
Multicast to Ethernet mapping e 28-bit group ID 01005e Low order 23 bits 32 IP multicast groups map to one Ethernet level multicast group
How multicast works Sender UDP IPv4 Data Link Receiver UDP IPv4 Data Link UDP IPv4 Data Link Dest IP = Dest Port = 9999 Dest Ethernet addr 01:00:5e:00:01:01 Port 9999 Join Receive 01:00:5e:00:01:01
Managing multicast membership Five Socket options –IP_ADD_MEMBERSHIP Join a multicast group –IP_DROP_MEMBERSHIP Leave a multicast group –IP_MULTICAST_IF Specify a default interface for outgoing multicast –IP_MULTICAST_TTL Specify TTL for outgoing multicast –IP_MULTICAST_LOOP Enable or disable loopback of outgoing multicast
WAN Multicast R1 R2 R3 Sender S1 S2 S3 S4 S – subnet R - Router - Receiver