27-05-2014, 12:47 PM
(ECS-751) DISTRIBUTED SYSTEMS LAB MANUAL
DISTRIBUTED SYSTEMS.doc (Size: 56 KB / Downloads: 32)
1. Simulate the functioning of Lamport’s Logical Clock in ‘C’.
1. [IR1] Clock Ci must be incremented
2. between any two successive events
3. in process Pi :
4. Ci := Ci + 1
5. [IR2] If event a is the event of sending
6. a message m in process Pi ,
7. then message m is assigned a
8. timestamp tm =Ci (a)
9. When that same message m is received by a different
10. process Pk, Ck is set to a value greater than curent value
11. of the counter and the timestamp carried by the
12. message (note that Singhal describes it slightly
13. differently)
14. Ck := max(Ck , tm)+1
2. Simulate the Distributed Mutual Exclusion in ‘C’.
1.The Ricart-Agrawala algorithm assumes the communication channels are
FIFO. The algorithm uses two types of messages: REQUEST and REPLY.
2.A process sends a REQUEST message to all other processes to request their permission to enter the critical section. A process sends a REPLY message to a process to give its permission to that process.
3.Processes use Lamport-style logical clocks to assign a timestamp to critical section requests and timestamps are used to decide the priority of requests.
4.Each process pi maintains the Request-Deferred array, RDi , the size of which is the same as the number of processes in the system.
5.Initially, ∀i ∀j : RDi [j]=0. Whenever pi defer the request sent by pj , it sets RDi [j]=1 and after it has sent a REPLY message to pj , it sets RDi [j]=0.
3. Implement a Distributed Chat Server using TCP Sockets in ‘C’.
1) Accept a new client socket connection if there is any,
(2) Read the client name with readUTF( ),
(3) Add this connection into the list of existing client connections.
(4) For each connection of the list,
(a) Receive a new message with readUTF( ) if there is any,
(b) Add the client name in front of the message received.
© Write this message to all clients through all connections of the list. Use
writeUTF( ).
(d) Check if any errors have occurred when reading and writing a message. If so,
remove this connection from the list.
4. Implement RPC mechanism for a file transfer across a network in ‘C’
Note that the declaration of the remote procedure printmessage_1 differs from that of the local procedure printmessage in four ways:
It takes a pointer to the character array instead of the pointer itself. This is true of all remote procedures when the '-' N option is not used: They always take pointers to their arguments rather than the arguments themselves. Without the '-' N option, remote procedures are always called with a single argument. If more than one argument is required the arguments must be passed in a struct.
It is called with two arguments. The second argument contains information on the context of an invocation: the program, version, and procedure numbers, raw and canonical credentials, and an SVCXPRT structure pointer (the SVCXPRT structure contains transport information). This information is made available in case the invoked procedure requires it to perform the request.
It returns a pointer to an integer instead of the integer itself. This is also true of remote procedures when the '-' N option is not used: They return pointers to the result. The result should be declared static unless the '-' M (multithread) or '-' A (Auto mode) options are used. Ordinarily, if the result is declared local to the remote procedure, references to it by the server stub are invalid after the remote procedure returns. In the case of '-' M and '-' A options, a pointer to the result is passed as a third argument to the procedure, so the result is not declared in the procedure.