CSci 4061 Assignment 3: Message Passing solution

$24.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (4 votes)

1. Purpose:   In this assignment, you will become more familiar with the another type of IPC: message­passing via                                 message queue/mailbox and the use signals. In addition, you will also learn about interrupt­driven                             programming (via alarm and I/O signals). 
2. Background:  In this assignment, you will simulate the basic mechanism of TCP (TransmissionControlProtocol)protocol                               that is commonly used for sending data through the Internet. TCP enables two processes running on any                                   Internet­connected machines to exchange data. In this assignment we will only simulate the way the                               protocol is used to exchange data between different processes on a single machine. We will also only                                   implement a very simple version of TCP­style message­passing without many of its core features.     2.1. Packets  In general, the data that is sent through a packet­switched network is broken down into one or more                                     packet ​ (s) ​ depending on the data’s size and the packet’s size (the packet size is fixed). Each packet                                  consists of some header fields and data. The header fieldsmayconsistofinformationsuchasthesender’s                                     identity, packet number, length of data encapsulated in the packet, etc., while the data stored is theactual                                     content of the message. Figure 1 shows an example of a single packet.   
  In this specific example, the message is the top figure. Below this depicts a single packet (#5) of the                                       message. The maximum size ofdatathatcanbestoredinasinglepacketis32B.Thus,ifthetotalmessage                                           is 170B, the sender needs to send 6packetsintotal(5containing32Bofthemessageand1containingthe                                           last 10B of the message). On the receiving side, the receiver will also receive the message as a series of                                         packets and deliver the original message by combining each individual packet’s data in the correct order                                 (#1, #2, .. #6). In the Internet (and in our lab), the packets may arrive to the receiver in an arbitrary order!                                             While receiving each individual packet, the receiver needs to notify the sender that the packet has been                                   successfully received, which is called an​acknowledgement (​ACK​ )thatisalsoenclosedinapacket.Ifthe                                  sender does not receive an ACK foranyofthetransmittedpacketafteracertainamountoftime,thesender                                         will ​TIMEOUT and resend every packet whose ACK has not yet been received (i.e. acknowledged) by the                                   receiver. This mechanism is used to handle various issues in computer networks such as packet loss                                 (Figure 2a), corrupted data, etc.  1 
 
  2.2. Sliding Window  Sending a single packet at a time may result in a long total time to send the whole message if onepacket                                             must be acknowledged before the next is sent. Thus, it is desirable to send multiple (​ n) packets                                  simultaneously and wait for multiple ACKs at a time. A group of packets that is sent together is called a                                         window ​   ​ (of size n). Figure 2a has a window size = 1 and Figure 2b has a window size = 3.     While sending multiple packets at a time is desirable, this may lead to an issue where the receiver may                                       receive the packets unordered. This may happen since any of the packetsmaygetlostinthemiddleofthe                                         network or transferred via slower network path. Thus, the receiver has tobeabletoconstructthemessage                                     even if the packets come in a random order. In a​sliding window ​ protocol, the sender can send another                                      packet whenever it receives anACKforasentpacketinsteadofwaitingforallACKstoarrive.(InFigure2b,                                           the sender can send packet 4 right after it receives an ACK for an earlierpacket,e.g. packet1).Thus,the                                           sliding window protocol allows the sender to have at most​ n packets in transit (i.e. not acknowledged) ata                                      time. Initially when the window is empty,​ n packets will be sent together. After this, packets are sent when                                      ACKs arrive to maintain the window ​ n ​ .   3. Description:  In this assignment, you will implement several APIs (in​process.cand​process.h​ ) that willbecalledby                                  an application program to exchange messages using the protocol discussed in the previous section. This                               program can act as a receiver, sender process, or both. We have provided an application program,                                 application.c​ , that will use the APIs defined in ​process.c​ . ​ When we refer to sender or receiver                                process this istheapplicationprogramoperatingaseitherasenderorreceiveratthatpointintime.There                                       are 3 APIs/functions that will be called by the application program:  1. int init(char *process_name, key_t key, int wsize, int delay, int to, int                         drop);  The init API is the initialization function that needs to be called before calling​send_messageor                                 receive_message​ . API There aretwofunctionsperformedby​init​ .First,itwillcreateamessage                              2 
queue for the given key and save the application process’ information (pid, process’ name, and                               mailbox id) to a file that is shared totheotherprocessesthatmaywishtocommunicatewithit.The                                         pid will beusedtosendasignaltoanotherprocess,theprocessnamewillbeusedtonamethefile,                                           and the key will be used to get the process’ mailbox. The mailbox is the place where a sender                                       process sends packets and a receiver process retrieves packets. There is a mailbox created for                               each process that calls​init​ . Second,itwillsavethemessageconfiguration(​wsize​ :windowsize,                              delay​ : maximum delay, ​ to​ : timeout, and ​drop​ : drop rate) and set signal handlers (SIGIO and                              SIGALRM) that will be used throughout the program.  A SIGIO signal will be sent by the sender process using​killto indicate that a new packet has                                       been placed into the receiver’s mailbox. This willbehandledbythe​receive_packet(intsig)                             function.  ASIGALRMsignalisusedtoindicateaTIMEOUT.Wheneverthesenderprocesssendsapacketto                                   other process’ mailbox, the sender willsetaTIMEOUTandwaitforanACKfromthereceiver.Ifthe                                       ACK is not received before the TIMEOUT expires,thesenderwillresendanypacketswhoseACKs                                 have not yet been received (this is handled by the​ timeout_handler(int sig)​ function).  2.int send_message(char *receiver, char* content);  This API is used to send a message to another process. To send a message to another process:                                     the sender process first has to obtain the receiver’s information (pid, and mailbox key) from the                                 receiver’s file (named with the receiver’s name,​receiver​ ), break down the message (​content​ )                          into one or more packets, send each packet to the receiver’s mailbox, and send a SIGIO signalto                                     the receiver. The sender needs to set a TIMEOUT and wait for ACKs from the receiver toindicate                                     whether the packets have been successfully sent.  3.int receive_message(char *data);  This API is used to indicate that the program is ready to receive a message from any sender. If                                       there is more than one sender that triestosendamessage,onlythemessagefromthefirstsender                                       will be read. Any other senders will TIMEOUT and cancel sending the message. In this function,                                 your program should​pause​/block until a SIGIO message isreceived,indicatingthatthereisanew                                 packet in the mailbox. The program should save the content of thepacketandsendanACKtothe                                       sender. Once all packets are received, the message will be saved to the ​data ​and returned.     In this assignment,youaregiventheapplicationprogram(​application.c​ )whereitwillcallthe​initAPI,                                  and perform as a sender/receiver depending on the user’s input. A sender process will call the                                 send_message​ API whereas a receiver process will call the​receive_message​ API. All The tasks you                              need to implement are as follow: 
Part A (60 points)  1. Initialization  The application program ( ​application.c​  )​   ​ takes 6 inputs from the user:   1. Name: the process name (you can assume there is no other process with the same name)  2. Mailbox key: the key of the mailbox  3. Window size: the size of the window (you can set it to 1 for this part)  4. Max delay: maximum delay in sending an ACK (in seconds)  5. Timeout: maximum waiting time to resend a packet (in seconds)  6. Drop rate: the probability of a packet to be lost (in %)  When the program gets these parameters, it will pass these inputs to the ​init​ API which will save the                                      name, mailbox key and pid to a file and set the configuration of the messaging mechanism.   

The program provided in​application.cwaits for the user’s input via​scanf()​ toperformwhetherasa                                  sender or a receiver. A sender process requires two other inputs from the user: 1. the receiver’s name, 2.                                       the message. On the other hand, a receiver process will wait/block until it receives a new message in its                                       mailbox.    2. Sending a Message  A message that is provided by a usermayvaryinsize(   * X500:  */   4. Simplification:  ● You may assume that the process name for every process at a given time is unique.  ● You may assume that the message is a​ null terminated string​without any spaces atthesender                                  side. Therefore, the message must be ​null terminated​ when returned to the receiver.    5. Miscellaneous:  ● As in lab #2, we have given some complete functions, and some partial functions to help you. All                                     datatypeshavebeenprovided.Youarefreetoignoreorchangeoftheprovidedcodeifyouwish.In                                         particular feel free to optimize.  ● Useful functions: ​memcpy, sigprocmask, alarm, kill, msgrcv, msgsnd,msgget,                   signal/sigaction, pause, getpid  ● alarm(0) ​turns off any pending alarms  ● Be aware of race conditions: block signals to handle these cases as needed  ● Remember to reset any global state once message­passing is done to enable new messages as                               needed   
5. Test Cases:  All tests will be done in a CSE labs UNIX machines. So, you need to make sure that yourprogramcanbe                                             compiled and run using one of those machines. You may consider these following cases for testing: 

● Invalid process information.  ● Short/long message with small/large packet size.  ● Multiple processes that exchange data between them in a sequential order (e.g.:A→B,C→A,B                                       → A, B → C). In this scenario that application instance at runs A, B, C respectively can keep                                       running and change whether it is a sender or receiver based on user input.  ● Handle packet loss (both in sending DATA and ACK) and delay.  ● Handle unordered packets.  ● Handle duplicate packets (you should also consider the case where a duplicate packet isreceived                               when the message has already been completed). 
6. Deliverables:  1. Files containing your code   2. A README file (readme and c code should indicate this is assignment 3).     All files should becompressedintoasingletarfile,named​assignment3_group.tarand                             submitted through Moodle. This is your official submission that we will grade. We will only grade the most                                     recent and on­time submission. Failing to follow the submission instruction may result in a 5% deduction.  
7. Sample Snapshot:  The sample program below was run with a packet size = 4.    Sender:                            Receiver: