Remote Procedure Calls (RPC) - Seminar Report


Remote Procedure Calls (RPC)
Introduction
RPC is a powerful technique for constructing distributed, client-server based applications. It is based on extending the notion of conventional, or local procedure calling, so that the called procedure need not exist in the same address space as the calling procedure. The two processes may be on the same system, or they may be on different systems with a network connecting them. By using RPC, programmers of distributed applications avoid the details of the interface with the network. The transport independence of RPC isolates the application from the physical and logical elements of the data communications mechanism and allows the application to use a variety of transports.
RPC makes the client/server model of computing more powerful and easier to program. When combined with the ONC RPCGEN protocol compiler clients transparently make remote calls through a local procedure interface.

Working
An RPC is analogous to a function call. Like a function call, when an RPC is made, the calling arguments are passed to the remote procedure and the caller waits for a response to be returned from the remote procedure. The figure shows the flow of activity that takes place during an RPC call between two networked systems. The client makes a procedure call that sends a request to the server and waits. The thread is blocked from processing until either a reply is received, or it times out. When the request arrives, the server calls a dispatch routine that performs the requested service, and sends the reply to the client. After the RPC call is completed, the client program continues. RPC specifically supports network applications.
  
Remote Procedure Calling Mechanism 
A remote procedure is uniquely identified by the triple: (program number, version number, procedure number) The program number identifies a group of related remote procedures, each of which has a unique procedure number. A program may consist of one or more versions. Each version consists of a collection of procedures which are available to be called remotely. Version numbers enable multiple versions of an RPC protocol to be available simultaneously. Each version contains a a number of procedures that can be called remotely. Each procedure has a procedure number.

RPC Application Development
Consider an example:
A client/server lookup in a personal database on a remote machine. Assuming that we cannot access the database from the local machine (via NFS).
We use UNIX to run a remote shell and execute the command this way. There are some problems with this method:
the command may be slow to execute.
You require an login account on the remote machine.
The RPC alternative is to
establish an server on the remote machine that can repond to queries.
Retrieve information by calling a query which will be quicker than previous approach.
To develop an RPC application the following steps are needed:
Specify the protocol for client server communication
Develop the client program
Develop the server program
The programs will be compiled seperately. The communication protocol is achieved by generated stubs and these stubs and rpc (and other libraries) will need to be linked in.
Defining Client and Server Application Code
We must now write the the client and application code. They must communicate via procedures and data types specified in the Protocol.
The service side will have to register the procedures that may be called by the client and receive and return any data required for processing.
The client application call the remote procedure pass any required data and will receive the retruned data.
There are several levels of application interfaces that may be used to develop RPC applications. We will briefly disuss these below before exapnading thhe most common of these in later chapters.

Overview of Interface Routines
RPC has multiple levels of application interface to its services. These levels provide different degrees of control balanced with different amounts of interface code to implement. In order of increasing control and complexity. This section gives a summary of the routines available at each level. Simplified Interface Routines
The simplified interfaces are used to make remote procedure calls to routines on other machines, and specify only the type of transport to use. The routines at this level are used for most applications. Descriptions and code samples can be found in the section, Simplified Interface @ 3-2

Simplified Level Routine Function
rpc_reg() -- Registers a procedure as an RPC program on all transports of the specified type.
rpc_call() -- Remote calls the specified procedure on the specified remote host.
rpc_broadcast() -- Broadcasts a call message across all transports of the specified type. Standard Interface Routines The standard interfaces are divided into top level, intermediate level, expert level, and bottom level. These interfaces give a developer much greater control over communication parameters such as the transport being used, how long to wait beforeresponding to errors and retransmitting requests, and so on.

Top Level Routines
At the top level, the interface is still simple, but the program has to create a client handle before making a call or create a server handle before receiving calls. If you want the application to run on all transports, use this interface. Use of these routines and code samples can be found in Top Level 

Interface
clnt_create() -- Generic client creation. The program tells clnt_create() where the server is located and the type of transport to use.
clnt_create_timed() Similar to clnt_create() but lets the programmer specify the maximum time allowed for each type of transport tried during the creation attempt.
svc_create() -- Creates server handles for all transports of the specified type. The program tells svc_create() which dispatch function to use.
clnt_call() -- Client calls a procedure to send a request to the server.
Intermediate Level Routines
The intermediate level interface of RPC lets you control details. Programs written at these lower levels are more complicated but run more efficiently. The intermediate level enables you to specify the transport to use.
clnt_tp_create() -- Creates a client handle for the specified transport.
clnt_tp_create_timed() -- Similar to clnt_tp_create() but lets the programmer specify the maximum time allowed. svc_tp_create() Creates a server handle for the specified transport.
clnt_call() -- Client calls a procedure to send a request to the server.

Expert Level Routines
The expert level contains a larger set of routines with which to specify transport-related parameters. Use of these routines
clnt_tli_create() -- Creates a client handle for the specified transport.
svc_tli_create() -- Creates a server handle for the specified transport.
rpcb_set() -- Calls rpcbind to set a map between an RPC service and a network address.
rpcb_unset() -- Deletes a mapping set by rpcb_set().
rpcb_getaddr() -- Calls rpcbind to get the transport addresses of specified RPC services.
svc_reg() -- Associates the specified program and version number pair with the specified dispatch routine.
svc_unreg() -- Deletes an association set by svc_reg().
clnt_call() -- Client calls a procedure to send a request to the server.

Bottom Level Routines
The bottom level contains routines used for full control of transport options.
clnt_dg_create() -- Creates an RPC client handle for the specified remote program, using a connectionless transport.
svc_dg_create() -- Creates an RPC server handle, using a connectionless transport.
clnt_vc_create() -- Creates an RPC client handle for the specified remote program, using a connection-oriented transport.
svc_vc_create() -- Creates an RPC server handle, using a connection-oriented transport.
clnt_call() -- Client calls a procedure to send a request to the server.
The Programmer's Interface to RPC
This section addresses the C interface to RPC and describes how to write network applications using RPC. For a complete specification of the routines in the RPC library, see the rpc and related man pages.

Simplified Interface
The simplified interface is the easiest level to use because it does not require the use of any other RPC routines. It also limits control of the underlying communications mechanisms. Program development at this level can be rapid, and is directly supported by the rpcgen compiler. For most applications, rpcgen and its facilities are sufficient. Some RPC services are not available as C functions, but they are available as RPC programs. The simplified interface library routines provide direct access to the RPC facilities for programs that do not require fine levels of control.
Routines such as rusers are in the RPC services library librpcsvc. rusers.c, below, is a program that displays the number of users on a remote host. It calls the RPC library routine,rusers.
Passing Arbitrary Data Types
Data types passed to and received from remote procedures can be any of a set of predefined types, or can be programmer-defined types. RPC handles arbitrary data structures, regardless of different machines' byte orders or structure layout conventions, by always converting them to a standard transfer format called external data representation (XDR) before sending them over the transport. The conversion from a machine representation to XDR is called serializing, and the reverse process is called deserializing. The translator arguments of rpc_call() andrpc_reg() can specify an XDR primitive procedure, like xdr_u_long(), or a programmer-supplied routine that processes a complete argument structure. Argument processing routines must take only two arguments: a pointer to the result and a pointer to the XDR handle.

Defining the protocol
We can can use simple NULL-terminated strings for passing and receivong the directory name and directory contents. Furthermore, we can embed the passing of these parameters directly in the client and server code.
We therefore need to specify the program, procedure and version numbers for client and servers. This can be done automatically using rpcgen or relying on prdefined macros in the simlified interface. Here we will specify them manually.
The server and client must agree ahead of time what logical adresses thney will use (The physical addresses do not matter they are hidden from the application developer)
Program numbers are defined in a standard way:
· 0x00000000 - 0x1FFFFFFF: Defined by Sun
· 0x20000000 - 0x3FFFFFFF: User Defined
· 0x40000000 - 0x5FFFFFFF: Transient
· 0x60000000 - 0xFFFFFFFF: Reserved
We will simply choose a user deifnined value for our program number. The version and procedure numbers are set according to standard practice.
We still have the DIR_SIZE definition required from the local version as the size of the directory buffer is rewquired by bith client and server programs.

No comments:

Post a Comment

leave your opinion