Distributed Program Design
Distributed Program Design
Communication-Oriented Design
Design protocol first. Build programs that adhere to the protocol.
Application-Oriented Design
Build application(s). Divide programs up and add communication protocols.
Netprog 2001 - RPC Overview 1
Remote Subroutine
Client
Server
blah, blah, blah
bar = foo(a,b); blah, blah, blah int foo(int x, int y ) { if (x>100) return(y-2); else if (x>10) return(y-x); else return(x+y); }
Sun RPC
There are a number of popular RPC specifications. Sun RPC (ONC RPC) is widely used. NFS (Network File System) is RPC based. Rich set of support tools.
Procedure 1
Procedure 2
Procedure 3
Procedure Arguments
To reduce the complexity of the interface specification, Sun RPC includes support for a single argument to a remote procedure.* Typically the single argument is a structure that contains a number of values.
Procedure Identification
Procedure Identification
Program Identifiers
Each remote program has a unique ID. Sun divided up the IDs: 0x00000000 - 0x1fffffff Sun 0x20000000 - 0x3fffffff SysAdmin 0x40000000 - 0x5fffffff Transient 0x60000000 - 0xffffffff Reserved
Procedure Identifiers usually start at 1 and are numbered sequentially Version Numbers typically start at 1 and are numbered sequentially.
10
Iterative Server
Sun RPC specifies that at most one remote procedure within a program can be invoked at any given time.
If a 2nd procedure is called, the call blocks until the 1st procedure has completed.
Netprog 2001 - RPC Overview 11
Call Semantics
13
15
Always remember that you don't know how many times the remote procedure was run!
The net can duplicate the request (UDP).
16
Network Communication
The actual network communication is nothing new - it's just TCP/IP. Many RPC implementations are built upon the sockets library.
We are just using a different API, the underlying stuff is the same!
Netprog 2001 - RPC Overview 17
Servers typically do not use well known protocol ports! Clients known the Program ID (and host IP address).
RPC includes support for looking up the port number of a remote program.
Netprog 2001 - RPC Overview 18
A port lookup service runs on each host that contains RPC servers. RPC servers register themselves with this service:
"I'm program 17 and I'm looking for requests on port 1736"
19
The portmapper
Each system which will support RPC servers runs a port mapper server that provides a central registry for RPC services. Servers tell the port mapper what services they offer.
20
Clients ask a remote port mapper for the port number corresponsing to Remote Program ID.
The portmapper is itself an RPC server! The portmapper is available on a wellknown port (111).
Netprog 2001 - RPC Overview 21
RPC Programming
RPC library
XDR routines RPC run time library
call rpc service register with portmapper dispatch incoming request to correct procedure
Program Generator
23
High- and Low-level functions that can be used by clients and servers. High-level functions provide simple access to RPC services.
24
26
svc_run() is a dispatcher.
A dispatcher waits for incoming connections and invokes the appropriate function to handle each incoming request.
Netprog 2001 - RPC Overview 27
28
RPCGEN
There is a tool for automating the creation of RPC clients and servers. The program rpcgen does most of the work for you. The input to rpcgen is a protocol definition in the form of a list of remote procedures and parameter types.
RPCGEN
Protocol Description
Input File
rpcgen
Client Stubs
Server skeleton
C Source Code
Netprog 2001 - RPC Overview 31
32
Client Creation
> gcc -o fooclient foomain.c foo_clnt.c foo_xdr.c foomain.c is the client main() (and possibly other function) that call rpc services via the client stub functions in foo_clnt.c The client stubs use the xdr functions.
Server Creation
gcc -o fooserver fooservices.c foo_svc.c foo_xdr.c
34