Distributed Computing, Liu Chapter 2 Instructor’s Manual w/ Solutions Chapter 2 Interprocess Communications Presentation Suggestions        This chapter is the foundation for distributed computing. For students who have never been exposed to programming involving more than one process, this chapter can be challenging. Use inter-human communication as an analogy (see exercise 1) to get the students motivated: they must appreciate the need for the primitive operations (send, receive), for event synchronization, data representation and encoding, and protocols. Explain that in interprocess communications, “synchronous” means “blocking” while “asynchronous” means no blocking The idea of blocking is not intuitive to most beginning students: again, use inter-person communication as an analogy in your explanation for the need of blocking. Tell them that they will see blocking in the concrete in Chapter 4, when the socket APIs are introduced. Be sure to clarify the difference between the time-event diagram (which shows blocking) and the sequence diagram (which does not show blocking). The demo illustrated in Figure 2.18 is is very effective for allowing the students to see the actual exchange of data between two independent processes. During the demo, you may want point out where blocking occurs, and point out clearly the source of the data being displayed on screen. Be sure to make clear to students that using telnet to interact with a text-based server is not the normal way to conduct a protocol session. For interactive learning, it is a good idea to go over the first six exercises in class during your presentation. For example, invite the class to solve problem 1 after you have presented the idea of interprocess communications; problem 2 after you introduced the terms synchronous and asynchronous; and so forth. Do encourage your students to look up the Internet Request for Comments (RFC) (see the references): they may not understand the writing, but it’s a good idea to get them to start thinking about specifying protocols and why protocols are needed. How This Chapter Fits In this chapter, students are introduced to the concepts for interprocess communications, the foundation for distributed computing. For students who have never been exposed to programming involving more than one process, this chapter can be challenging. Solutions to Chapter Exercises (Answers are in red except in diagrams) 1. Consider inter-human communications. a. Classify each of the followings in terms of unicast and multicast: i.A student speaking to a friend on a wireless phone. This is supposed to be a unicast, although wireless data transfer is notoriously vulnerable to eavesdropping. ScholarStock 1 Distributed Computing, Liu Chapter 2 Instructor’s Manual w/ Solutions ii.An executive speaking on a conference-phone with managers in different cities. multicast iii.A teacher lecturing in a classroom. multicast iv.A child playing with another child using a “walkie-talkie”. unicast that’s, again, subject to eavesdropping. v.The president addressing the nation on television. multicast b. How are events synchronization and data representation handled during a session of face-to-face conversation, such as when you speak to someone seated next to you? Event synchronization is effected using pauses, eye contact, gesture, or explicit words (“hello”,“your turn”, “I AM talking”). A session is initiated when two persons come in contact, and one or both signal to each other his/her desire to converse (‘hello, how’s it going?’) The conversation takes turns between the participants. A change in turn may be signaled by a pause, eye contact, gesture, or explicit words (“what do you think?”). It is imprecise, however, as people do sometimes talk at the same time, or awkward pauses may occur in the midst of a conversation. Data representation: a common language (possibly sign language) will have to be spoken, or a language translater will be needed. The sound is carried by air to all within earshot or sight of the speakers. Additionally, data can be encoded using body language, tone, facial expression, and gestures. c. How are events synchronization and data representation handled during a session of remote conversation, such as when you speak to someone over the phone? A session is initiated when the phone rings and is picked up at the receiving end. A “hello” from the callee typically starts the conversation, followed by the caller identifying herself/himself. The two sides then take turns to speak, using pauses or explicit words to signify a new turn. Data representation: a common language (possibly sign language) will have to be spoken. The sound wave is converted to electric signals transmitted over the phone line, and decoded at the other end. 2. Process A sends a single message to process B using connectionless IPC. To do so, A issues a send operation (specifying the message as argument) sometime during its execution, and B issues a receive operation. Suppose the send operation is blocking and the receive operation is non-blocking. Draw an event diagram (not sequence diagram) for each of the following scenario: a. Process A issues its send operation prior to process B issues its receive operation. Answer: ScholarStock 2 Distributed Computing, Liu Chapter 2 process A Instructor’s Manual w/ Solutions process B The data requested by the receive operation has already arrived, the data is delivered to process B and an acknowledgement from host 2’s IPC facility will unblock process A subsequently. b. Process B issues its receive operation prior to process A issues its send operation. Answer: There are two possible scenarios: (i) The data requested by the receive operation has not yet arrived, no data is delivered to the process. It is the receiving process’ responsibility to ascertain that it has indeed received the data and, if necessary, repeat the receive operation until the data has arrived. Process 1 is blocked indefinitely until process 2 reissues a receive request and an acknowledgement eventually arrives from host 2’s IPC facility. process A (ii) process B The data requested by the receive operation has not yet arrived. The IPC facility of host 2 will notify process 2 when the data it requested has arrived, at which point process 2 may proceed to process the data. This scenario requires that process 2 provides a listener or event handler which can be invoked by the IPC facility to notify the process of the arrival of the requested data. ScholarStock 3 Distributed Computing, Liu Chapter 2 Instructor’s Manual w/ Solutions process A process B 3. Repeat the last question. This time both operations (send, receive) are blocking. Answer: a. Process A issues its send operation prior to process B issues its receive operation process A process B procss A will block until B has issued the receive operation and the message is delivered to B, at which time both processes will be unblocked. b. Process B issues its receive operation prior to process A issues its send operation. process A process B process B will block until the message from process A arrives, at which time both processes will be unblocked. ScholarStock 4 Distributed Computing, Liu Chapter 2 Instructor’s Manual w/ Solutions 7. In a distributed system three processes P1, P2, P3 are engaged in interprocess communication. Suppose the following sequence of events occurred: At time 1, P3 issues a receive from P2. At time 2, P1 sends m1 to P2. At time 3, P2 issues a receive from P1. At time 4, P2 receives m1. At time 5, P2 sends message m1 to P3. At time 6, P3 receives m1; P1 issues receive from P2. At time 7, P2 issues a receive from P3. At time 8, P3 sends m2 to P2. At time 9, P2 receives m2. At time 10, P2 sends m2 to P1. At time 11, P1 recieves m2. a. Draw a time event diagram each to show the sequence of events and the blocking and unblocking of each process: i. on a communication system which provides blocking send operation and blocking receive operation. ScholarStock 5 Distributed Computing, Liu Chapter 2 Instructor’s Manual w/ Solutions P1 P2 P3 t=1 t=2 m1 receive operation t=3 send operation t=4 t=5 m1 t=6 t=7 t=8 m2 t=9 t=10 m2 t=11 ii. on a communication system which provides nonnblocking send operation and blocking receive operation. ScholarStock 6 Distributed Computing, Liu Chapter 2 Instructor’s Manual w/ Solutions P1 P2 P3 t=1 t=2 m1 receive operation t=3 send operation t=4 t=5 m1 t=6 t=7 t=8 m2 t=9 t=10 m2 t=11 b. Draw a sequence diagram to document the interprocess communication between P1, P2, and P3. m1 m1 m2 m2 8. This is an exercise on data marshalling. a. In the context of IPC: i. What is meant by data marshaling? (There are two components to data marshalling; name and describe each.) Why is it necessary? Answer: The two components of data marshaling are: ScholarStock 7 Distributed Computing, Liu Chapter 2 Instructor’s Manual w/ Solutions 1. Data structures used in programming need to be flattened or serialized, since data transmitted over the network must be serialized. 2. The data needs to be converted to an external representation so that it may be interpreted correctly by the receiver, which then maps the external representation to its local representation. ii. What is meant by object serialization? It is the “flattening” of an object so that an object may be transmitted over the network. iii. How does the two components of data marshalling apply to (i) an array of integers, and (ii) an object? (Describe in general terms what needs to be flattened and encoded in each case.) (i) for an array: each component will need to be flattened and encoded; the components are then appended one after another, with a count of the components and the type of each component specified in a header. (ii) For an object: the data, the method, and the state of execution will need to be represented in a binary stream, in such a way that, once transmitted, the object can be reconstituted at the receiver’s. Note that each data item in an object must be marshaled, and references and pointers, if any, must be mapped appropriately by the receiver. 8b. Process A sends to process B a single data item, a date. Process A uses the American date format: <month>/<day>/<year> (for example: 01/31/2001. Process B uses the European date format: <day>/<month>/<year>(for example:31/01/2001.) i. Suppose no external data representation has been agreed upon. i. How can A send the date to B so that A does not have to do any conversion? Answer: A sends the date in American format. When B receives the data item, the date is mapped to the European format. ii. How can A send the date to B so that B does not have to do any conversion? Answer: A converts the date to Eurpoean format before sending it. ii. Suppose the same date has to be communicated to Process C, which uses a date format of <year>-<month>-<date>(for example; 2001-01-31). i. How can A send the date to B so that A does not have to do any conversion? Answer: A sends the date in American format. B will have to convert the date to its local format upon receiving the date. ii. How can A send the date to both B and C so that A does not have to do any conversion? ScholarStock 8 Distributed Computing, Liu Chapter 2 Instructor’s Manual w/ Solutions Answer: A sends the date in American format. B and C will have to convert the date to its local format upon receiving the date. iii. Describe an external representation of the date so that any sending process may convert a date of its local representation to the external representation prior to sending, and any receiving process may convert the date received from this representation to its native representation. An example of such a representation is <year>,<month>,<date> (for example, 2001, 12, 31). It may be of interest for you to read reference [11]. 9. Use telnet to interact with a daytime4 server process on a machine that you have access to. Daytime server processes reside on port 13 of an IP host. (From a console screen on a UNIX or Windows system, enter: telnet<space> <domain name or IP address of the machine><space>13 Answer: A sample session is shown below -9:20pm falcon ~>telnet polylog1 13 Trying 129.65.60.104... Connected to polylog1.cpunix.calpoly.edu. Escape character is '^]'. Fri Oct 12 21:21:21 2001 Connection closed by foreign host. Note that no message needs to be sent from the client; a timestamp is immediately sent from the TCP daytime server running on port 13 on the host polylog1. (The UDP daytime server does require a message from the client; the contents of the message is immaterial.) 10. Draw a sequence diagram for the daytime protocol. Answer: TCP server TCP client timestamp UDP server UDP client timestamp 11. Is it possible for a daytime client to be blocked indefinitely? Explain. Answer: Yes, if after it issues a blocking receive operation (i) the server, perhaps due to a failure, does not respond, and (ii) there is no timeout in effect with the operation. ScholarStock 9 Distributed Computing, Liu Chapter 2 Instructor’s Manual w/ Solutions 12. Consider the Simple Mail Transfer Protocol (SMTP)4.An excerpt from the RFC for this protocol provides the following sample session. R: 220 USC-ISI.ARPA Simple Mail Transfer Service Ready S: HELO LBL-UNIX.ARPA R: 250 USC-ISI.ARPA S: MAIL FROM:<[email protected]> R: 250 OK S: RCPT TO:<[email protected]> R: OK S: R: S: S: S: R: DATA 354 Start mail input; end with <CRLF>.<CRLF> Blah blah blah... ...etc. etc. etc. . 250 OK S: QUIT R: 221 USC-ISI.ARPA Service closing transmission channel a. Use a sequence diagram to describe the interactions among the participating processes. Answer: Server Client 220 USC-ISI.ARPA Simple Mail Transfer Service Ready server identifies itself to client after client connects to it HELO LBL-UNIX.ARPA client identifies itself server send status code 250 and re-identifies itself 250 USC-ISI.ARPA MAIL FROM:<[email protected]> 250 OK client identifies email sender's address server says okay RCPT TO:<[email protected]> OK client identifies email receiver's address server says okay client send keyword "DATA: to signify the beginning of the email body DATA 354 Start mail input; end with <CRLF>.<CRLF> server sends status code 354 and instruction for how to end the data (two newlines) client send as many lines as needed for the body of the email, ending with a blank line. 250 OK server returns with status OK client indicates that there is no QUIT more email that it wants to send (it could send another at this point) 221 USC-ISI.ARPA Service closing transmission channel server signs off. Blah blah blah... ... b. What is the format of each request? ScholarStock 10 Distributed Computing, Liu Chapter 2 Instructor’s Manual w/ Solutions Answer: The format of each request is <a keyword or keywords> <data>. c. What is the format of each response? Answer: The format of each response is <a status code> <a keyword or keywords> <data>. The status code is sometimes omitted. d. Use telnet to connect to a system on which you have an SMTP email account, then send yourself an email. Log onto the system and check that the email indeed arrived. Answer: It can be done. However, please do not entertain the idea of using this technique to forge email - many mail servers will track the originating IP address of the client host and unauthorized email can be traced. ScholarStock 11
© Copyright 2025 Paperzz