Block 5 Group Communication Jin Sa 5212021 Clientserver
Block 5 Group Communication Jin Sa 5/21/2021 Client-server programming 1
Outline • Part 1 Theory and principles – Multicast operations – Reliable multicast vs unreliable multicast – Classifications of multicasting mechanisms • Part 2 Java basic multicast implementation – Datagram recap – Java basic multicast API • IP multicast addresses • Basic operations – Setting time-to-live • Part 3 Program examples 5/21/2021 Client-server programming 2
Part 1 Theory and principles 5/21/2021 Client-server programming 3
Unicast vs. Multicast 5/21/2021 Client-server programming 4
Multicast applications Whereas the majority of network services and network applications use unicast for IPC, multicasting is useful for applications such as groupware, online conferences, interactive distance learning, and can be used for applications such as online auction. 5/21/2021 Client-server programming 5
Multicast group A set of processes form a group, called a multicast group. The processes can be on different hosts on different networks. Each process in a group can send and receive message. A message sent by any process in the group can be received by each participating process in the group. 5/21/2021 Client-server programming 6
Multicast operations Primitive operations: join, leave, send and receive • Join –allows a process to join a specific multicast group. A process that has joined a multicast group is a member of the group and will be in titled to receive all multicast addressed to the group. 5/21/2021 Client-server programming 7
Multicast operations • Leave –allows a process to stop participating in a multicast group. A process that has left a multicast group is not entitled to receive any multicast addressed to the group, • Send –allows a process to send a message to all processes currently participating in a multicast group. • Receive –allows a member process to receive messages sent to a multicast group. 5/21/2021 Client-server programming 8
Reliable Multicast vs. Unreliable Multicast When a multicast message is sent by a process, the runtime support of the multicast mechanism is responsible for delivering the message to each process currently in the multicast group. As each participating process may be on a separate host, due to factors such as failures of network links and/or network hosts, routing delays, and differences in software and hardware, the time between when a message is sent and when it is received may vary among the recipient processes. Moreover, a message may not be received by one or more of the processes at all. 5/21/2021 Client-server programming 9
Classification of multicasting mechanisms in terms of message delivery Unreliable multicast: The arrival of the correct message at each process is not guaranteed. Reliable multicast: Guarantees that each message is eventually delivered in a non-corrupted form to each process in the group. 5/21/2021 Client-server programming 10
Classification of multicasting mechanisms in terms of message delivery The definition of reliable multicast requires that each participating process receives exactly one copy of each message sent. It does not put any restriction of the order the messages delivered. Reliable multicast can be further classified based on the order of the delivery of the messages: unordered, FIFO, causal order, atomic order. 5/21/2021 Client-server programming 11
Classification of reliable multicast -unordered An unordered reliable multicast system guarantees the safe delivery of each message, but it provides no guarantee on the delivery order of the messages. Example: Processes P 1, P 2, and P 3 have formed a multicast group. Three messages, m 1, m 2, m 3 have been sent to the group. An unordered reliable multicast system may deliver the messages to each of the three processes in any of these: m 1 -m 2 -m 3, m 1 -m 3 -m 2, m 2 -m 1 -m 3, m 2 -m 3 -m 1, m 3 -m 1 -m 2, m 3 -m 2 -m 1 5/21/2021 Client-server programming 12
Classification of reliable multicast - FIFO If process P sent messages mi and mj, in that order, then each process in the multicast group will be delivered the messages mi and mj, in that order. Note that FIFO multicast places no restriction on the delivery order among messages sent by different processes. For example, P 1 sends messages m 11 then m 12, and P 2 sends messages m 21 then m 22. It is possible for different processes to receive any of the following orders: m 11 -m 12 -m 21 -m 22, m 11 -m 21 -m 12 -m 22, m 11 -m 22 -m 12, m 21 -m 12 -m 22 m 21 -m 11 -m 22 -m 12 m 21 -m 22 -m 11 -m 12. 5/21/2021 Client-server programming 13
Classification of reliable multicast – Causal order If message mi causes (results in) the occurrence of message mj, then mi will be delivered to each process prior to mj. Messages mi and mj are said to have a causal or happen-before relationship. For example, P 1 sends a message m 1, to which P 2 replies with a multicast message m 2. Since m 2 is triggered by m 1, the two messages share a causal relationship of m 1 -> m 2. A causal-order multicast message system ensures that these two messages will be delivered to each of the processes in the order of m 1 - m 2. 5/21/2021 Client-server programming 14
Classification of reliable multicast – Atomic order In an atomic-order multicast system, all messages are guaranteed to be delivered to each participant in the exact same order. Note that the delivery order does not have to be FIFO or causal, but must be identical for each process. Example: P 1 sends m 1, P 2 sends m 2, and P 3 sends m 3. An atomic system will guarantee that the messages will be delivered to each process in only one of the six orders: m 1 -m 2 - m 3, m 1 - m 3 - m 2, m 2 - m 1 -m 3, m 2 -m 3 -m 1, m 3 -m 1 - m 2, m 3 -m 2 -m 1. 5/21/2021 Client-server programming 15
Part 2 Java Basic Multicast Implementation 5/21/2021 Client-server programming 16
The Java Basic Multicast API At the transport layer, the basic multicast supported by Java is an extension of UDP (the User Datagram Protocol) For the basic multicast, Java provides a set of classes which are closely related to the datagram socket API classes 5/21/2021 Client-server programming 17
Datagram - recap 5/21/2021 Client-server programming 18
The Java Basic Multicast API - 2 1. 2. There are four major classes in the API, the first three of which we have already seen in the context of datagram sockets. Inet. Address: In the datagram socket API, this class represents the IP address of the sender or receiver. In multicasting, this class can be used to identify a multicast group. Datagram. Packet: As with datagram sockets, an object of this class represents an actual datagram; in multicast, a Datagram. Packet object represents a packet of data sent to all participants or received by each participant in a multicast group. 5/21/2021 Client-server programming 19
The Java Basic Multicast API - 3 3. 4. Datagram. Socket: In the datagram socket API, this class represents a socket through which a process may send or receive data. Multicast. Socket : A Multicast. Socket is a Datagram. Socket, with additional capabilities for joining and leaving a multicast group. An object of the multicast datagram socket class can be used for sending and receiving multicast packets. In the Java API, a Multicast. Socket object is bound to a port address, e. g. 3456, and methods of the object allows for the joining and leaving of a multicast address, e. g. 239. 1. 2. 3 5/21/2021 Client-server programming 20
IP Multicast addresses Instead of a single process, a multicast datagram is meant to be received by all the processes that are currently members of a specific multicast group. Hence each multicast datagram needs to be addressed to a multicast group instead of an individual process. A multicast address is the shared address of a group. The Java multicast API uses the Internet Protocol (IP) multicast addresses for identifying multicast groups. A multicast group is specified by (i) a class D IP address combined with (ii) a standard UDP port number. 5/21/2021 Client-server programming 21
IP Addresses -- recap 5/21/2021 Client-server programming 22
IP Multicast addresses - 2 Class D IP addresses are those with the prefix bit string of 1110, and hence these addresses are in the range of 224. 0. 0. 0 to 239. 255. The address 224. 0. 0. 0 is reserved and should not be used by any application. 5/21/2021 Client-server programming 23
Joining a multicast group To join a multicast group at IP address m and UDP port p, a Multicast. Socket object must be instantiated with p, then the object’s join. Group method can be invoked specifying the address m: // join a Multicast group at IP address // 239. 1. 2. 3 and port 3456 Inet. Address group = Inet. Address. get. By. Name("239. 1. 2. 3"); Multicast. Socket s = new Multicast. Socket(3456); s. join. Group(group); 5/21/2021 Client-server programming 24
Sending to a multicast group A multicast message can be sent using syntax similar with the datagram socket API. String msg = "a multicast message. "; Inet. Address group = Inet. Address. get. By. Name("239. 1. 2. 3"); Multicast. Socket s = new Multicast. Socket(3456); s. join. Group(group); // optional Datagram. Packet hi = new Datagram. Packet(msg. get. Bytes( ), msg. length( ), group, 3456); s. send(hi); 5/21/2021 Client-server programming 25
Receiving messages sent to a multicast group A process that has joined a multicast group may receive messages sent to the group using syntax similar to receiving data using a datagram socket API. byte[] buf = new byte[1000]; Inet. Address group = Inet. Address. get. By. Name("239. 1. 2. 3"); Multicast. Socket s = new Multicast. Socket(3456); s. join. Group(group); Datagram. Packet recv = new Datagram. Packet(buf, buf. length); s. receive(recv); 5/21/2021 Client-server programming 26
Leaving a multicast group A process may leave a multicast group by invoking the leave. Group method of a Multicast. Socket object, specifying the multicast address of the group. s. leave. Group(group); 5/21/2021 Client-server programming 27
Setting the “time-to-live” The runtime support needs to propagate a multicast message from a host to a neighboring host in an algorithm which, when executed properly, will eventually deliver the message to all the participants. Under some anomalous circumstances, however, it is possible that the algorithm which controls the propagation does not terminate properly, resulting in a packet circulating in the network indefinitely. 5/21/2021 Client-server programming 28
Setting the “time-to-live” - 2 • Indefinite message propagation causes unnecessary overhead on the systems and the network. • To avoid this occurrence, it is recommended that a “time to live” parameter be set with each multicast datagram. • The time-to-live (ttl) parameter, when set, limits the count of network links or hops that the packet will be forwarded on the network. 5/21/2021 Client-server programming 29
Setting the “time-to-live” - 3 The recommended ttl settings are: • 0 if the multicast is restricted to processes on the same host • 1 if the multicast is restricted to processes on the same subnet • 32 if the multicast is restricted to processes on the same site • 64 if the multicast is restricted to is processes on the same region • 128 is if the multicast is restricted to processes on the same continent • 255 is the multicast is unrestricted 5/21/2021 Client-server programming 30
Setting the “time-to-live” - 4 String msg = "Hello everyone!"; Inet. Address group = Inet. Address. get. By. Name("239. 1. 2. 3"); Multicast. Socket s = new Multicast. Socket(3456); s. set. Time. To. Live(1); // set time-to-live to 1 hop Datagram. Packet hi = new Datagram. Packet(msg. get. Bytes( ), msg. length( ), group, 3456); s. send(hi); The value specified for the ttl must be in the range 0 <= ttl <= 255; an Illegal. Argument. Exception will be thrown otherwise. 5/21/2021 Client-server programming 31
Part 3 Java examples 5/21/2021 Client-server programming 32
Multicast program examples • Example 1: – Example 1 Sender – Example 1 Receiver • Example 2 – Example 2 Sender. Receiver – Read. Thread 5/21/2021 Client-server programming 33
Example 1 • Example 1 Sender – – Set a multicast group address Create a multicast socket on a port Create a datagram packet to be sent to the group Send the datagram packet using the multicast socket • Example 1 Receiver – – – Set the same multicast group address Create a multicast socket with the same port number Joint the group Create a datagram packet as a placeholder Issue a receive method to receive a data packet. • To run: – run Example 1 Receiver more than once – Run Example 1 Sender – See all Example 1 Receiver receives the message “Hi! Everyone” 5/21/2021 Client-server programming 34
Example 2 • Example 2 Receiver – Create a separate thread (Read. Thread) to receive multicast messages repeatedly • Read. Thread – – – Set the same multicast group address Create a multicast socket with the same port number Joint the group Create a datagram packet as a placeholder Repeatedly issue a receive method to receive a few data packets. • To Run – Run Example 2 Receiver a few times to create a few receivers – Run sender a few times to see that all receivers receive the messages a few times. 5/21/2021 Client-server programming 35
Example 3 – Getting to know each other • Teacher, student 1, student 2, student 3 • Teacher: – Send a welcome message to all students asking for names – Receives names of all students • Student – Receive teacher’s welcome – Send his/her name – Also receives the names of all other students 5/21/2021 Client-server programming 36
Example 3 -- teacher • Create the multicast socket • Create a datagram addressed to the multicast group. The datagram contains teacher’s welcome to every student. • Using the multicast socket, the teacher sends the datagram to everyone in the group. • Start a thread to receive the names from all students 5/21/2021 Client-server programming 37
Example 3 -- student • Obtain student name via keyboard • Set up a Multicast socket and join the group in order to receive teacher’s message • Create a datagram packet as a placeholder • Receive teacher's message with the datagram packet as the parameter • Create a thread and ready to receive names from everyone else • Wait until most threads have started before sending its own name to the group. • Create a datagram packet containing the student’s name and addressed to the multicast group • Send the datagram packet 5/21/2021 Client-server programming 38
Summary - 1 • Unicast vs. multicast: unicast is one-to-one communication, while multicast is one-to-many communication. • An archetypal multicast API must provide operations for joining a multicast group, leaving a multicast group, sending to a group, and receiving multicast messages sent to a group. • Basic multicast is connectionless and unreliable; in an unreliable multicast system, messages are not guaranteed to be safely delivered to each participant. 5/21/2021 Client-server programming 39
Summary - 2 A reliable multicast system ensures that each message sent to a multicast group is delivered correctly to each participant. Reliable multicasts can be further categorized by the order of message delivery they support: Unordered multicast may deliver the messages to each participant in any order. FIFO multicast preserves the order of messages sent by each host. Causal multicast preserves causal relationships among the messages. Atomic multicast delivers the messages to each participant in the same order. 5/21/2021 Client-server programming 40
Summary - 3 • IP multicast addressing uses a combination of a Class D address and a UDP port number. • The Java basic multicast API provides unreliable multicast. • A Multicast. Socket is created with the specification of a port number. • The join. Group and leave. Group methods of the Multicast. Socket class can be invoked to join or leave a specific multicast group; and • the send and receive methods can be invoked to send and receive a multicast datagram. • The Datagram. Pakcet class is also needed to create the datagrams. 5/21/2021 Client-server programming 41
- Slides: 41