Download Broadcast and Multicast Using Sockets

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Broadcast and Multicast
Unicast
Host 1
Host 2
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
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. 130.245.224.19
130.245  Netid
224  subnet id
19  host id
Types of broadcast addresses…
• Subnet-directed broadcast
{netid, subnetid, *}
E.g. 130.245.224.255
• Broadcasts to local subnet.
• Routers do not forward these types of
broadcast.
Types of broadcast addresses…
• All-Subnet broadcast
{netid, *, *}
E.g. 130.245.255.255
• 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. 255.255.255.255
• Older form of Subnet-directed broadcast
• Broadcasts to local subnet
• Never forwarded across routers.
How broadcast works
Sender
Dest IP = 130.245.224.255
Dest Port = 9999
Receiver
Port 9999
UDP
UDP
IPv4
IPv4
IPv4
Data Link
Data Link
Data Link
UDP
X
Dest Ethernet addr
ff:ff:ff:ff:ff:ff
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 = 130.245.224.255 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 :
– 224.0.0.0 to 239.255.255.255
• Low order 28 bits identify a multicast group id.
• Link Local addresses :
– 224.0.0.0 to 224.0.0.255
– Reserved for network maintenance messages
– Never forwarded by routers
• All-hosts group - 224.0.0.1
• All-routers group - 224.0.0.2
Multicast to Ethernet mapping
28-bit group ID
e
01
00
5e
Low order 23 bits
32 IP multicast groups map to one Ethernet level multicast group
How multicast works
Sender
Join
224.0.1.1
Dest IP = 224.0.1.1
Dest Port = 9999
Receiver
Port 9999
UDP
UDP
UDP
IPv4
IPv4
IPv4
Data Link
Data Link
Data Link
Receive
01:00:5e:00:01:01
Dest Ethernet addr
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
Sender
R3
S1
S4
R1
S2
R2
S – subnet
R - Router
- Receiver
S3
Related documents