rpc remote procedure call dave hollinger rensselaer polytechnic institute troy, ny
TRANSCRIPT
![Page 1: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/1.jpg)
RPCRemote Procedure Call
Dave Hollinger
Rensselaer Polytechnic Institute
Troy, NY
![Page 2: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/2.jpg)
Y Kermarrec Netprog: RPC Overview2
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.
Typical
Sockets
Approach
RPC
![Page 3: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/3.jpg)
Y Kermarrec Netprog: RPC Overview3
RPCRemote Procedure Call
Call a procedure (subroutine) that is running on another machine.
Issues:• identifying and accessing the remote procedure• parameters• return value
![Page 4: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/4.jpg)
Y Kermarrec Netprog: RPC Overview4
blah, blah, blah
bar = foo(a,b);
blah, blah, blah
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);}
int foo(int x, int y ) { if (x>100)
return(y-2); else if (x>10)
return(y-x); else
return(x+y);}
Client
Server
protocol
Remote Subroutine
![Page 5: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/5.jpg)
Y Kermarrec Netprog: RPC Overview5
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.
![Page 6: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/6.jpg)
Y Kermarrec Netprog: RPC Overview6
Sun RPC Organization
Procedure 1 Procedure 2 Procedure 3
Shared Global Data
Remote Program
![Page 7: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/7.jpg)
Y Kermarrec Netprog: RPC Overview7
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 (the parameters).
* Newer versions can handle multiple args.
![Page 8: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/8.jpg)
Y Kermarrec Netprog: RPC Overview8
Procedure Identification
Each procedure is identified by:• Hostname (IP Address)• Program identifier (32 bit integer)• Procedure identifier (32 bit integer)
– Program Version identifier» for testing and migration » Used also to detect out dated version of a server
![Page 9: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/9.jpg)
Y Kermarrec Netprog: RPC Overview9
Program Identifiers
Each remote program has a unique ID. Sun divided up the IDs:
0x00000000 - 0x1fffffff0x20000000 - 0x3fffffff0x40000000 - 0x5fffffff0x60000000 - 0xffffffff
Sun
SysAdmin
Transient
Reserved
![Page 10: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/10.jpg)
Y Kermarrec Netprog: RPC Overview10
Procedure Identifiers &Program Version Numbers
Procedure Identifiers usually start at 1 and are numbered sequentially
Version Numbers typically start at 1 and are numbered sequentially.
![Page 11: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/11.jpg)
Y Kermarrec Netprog: RPC Overview11
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.
![Page 12: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/12.jpg)
Y Kermarrec Netprog: RPC Overview12
Iterative can be good
Having an iterative server is useful for applications that may share data among procedures.
Example: database - to avoid insert/delete/modify collisions.
We can provide concurrency when necessary...
![Page 13: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/13.jpg)
Y Kermarrec Netprog: RPC Overview13
Call Semantics
What does it mean to call a local procedure?• the procedure is run exactly one time.
What does it mean to call a remote procedure?• It might not mean "run exactly once"!
![Page 14: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/14.jpg)
Y Kermarrec Netprog: RPC Overview14
Remote Call Semantics
To act like a local procedure (exactly one invocation per call) - a reliable transport (TCP) is necessary.
Sun RPC does not support reliable call semantics.
"At Least Once" Semantics "Zero or More" Semantics
![Page 15: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/15.jpg)
Y Kermarrec Netprog: RPC Overview15
Sun RPC Call Semantics
At Least Once Semantics• if we get a response (a return value)
Zero or More Semantics• if we don't hear back from the remote subroutine.
![Page 16: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/16.jpg)
Y Kermarrec Netprog: RPC Overview16
Remote Procedure deposit()
deposit(DavesAccount,$100)
Always remember that you don't know how many times the remote procedure was run!• The net can duplicate the request (UDP).
![Page 17: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/17.jpg)
Y Kermarrec Netprog: RPC Overview17
Network Communication
The actual network communication is nothing new - it's just TCP/IP.
Many RPC implementations are built upon the sockets library.• the RPC library does all the work!
We are just using a different API, the underlying stuff is the same!
![Page 18: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/18.jpg)
Y Kermarrec Netprog: RPC Overview18
Dynamic Port Mapping
Servers typically do not use well known protocol ports!
Clients know the Program ID (and host IP address).
RPC includes support for looking up the port number of a remote program.
![Page 19: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/19.jpg)
Y Kermarrec Netprog: RPC Overview19
Port Lookup Service
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"
![Page 20: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/20.jpg)
Y Kermarrec Netprog: RPC Overview20
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.
![Page 21: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/21.jpg)
Y Kermarrec Netprog: RPC Overview21
More on the portmapper
Clients ask a remote port mapper for the port number corresponding to Remote Program ID.
The portmapper is itself an RPC server!
The portmapper is available on a well-known port (111).
![Page 22: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/22.jpg)
Y Kermarrec Netprog: RPC Overview22
Sun RPC Programming
The RPC library is a collection of tools for automating the creation of RPC clients and servers.
RPC clients are processes that call remote procedures.
RPC servers are processes that include procedure(s) that can be called by clients.
![Page 23: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/23.jpg)
Y Kermarrec Netprog: RPC Overview23
RPC Programming
RPC library• XDR routines• RPC run time library
- call rpc service
- register with portmapper
- dispatch incoming request to correct procedure
• Program Generator
![Page 24: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/24.jpg)
Y Kermarrec Netprog: RPC Overview24
RPC Run-time Library
High- and Low-level functions that can be used by clients and servers.
High-level functions provide simple access to RPC services.
![Page 25: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/25.jpg)
Y Kermarrec Netprog: RPC Overview25
High-level Client Library
int callrpc( char *host,u_long prognum,u_long versnum,u_long procnum,xdrproc_t inproc,char *in,xdrproc_t outproc,char *out);
![Page 26: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/26.jpg)
Y Kermarrec Netprog: RPC Overview26
High-Level Server Library
int registerrpc(u_long prognum,u_long versnum,u_long procnum,char *(*procname)()xdrproc_t inproc,xdrproc_t outproc);
![Page 27: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/27.jpg)
Y Kermarrec Netprog: RPC Overview27
High-Level Server Library (cont.)
void svc_run();
svc_run() is a dispatcher. A dispatcher waits for incoming connections and
invokes the appropriate function to handle each incoming request.
![Page 28: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/28.jpg)
Y Kermarrec Netprog: RPC Overview28
High-Level Library Limitation
The High-Level RPC library calls support UDP only (no TCP).
You must use lower-level RPC library functions to use TCP.
The High-Level library calls do not support any kind of authentication.
![Page 29: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/29.jpg)
Y Kermarrec Netprog: RPC Overview29
Low-level RPC Library
Full control over all IPC options• TCP & UDP• Timeout values• Asynchronous procedure calls
Multi-tasking Servers Broadcasting
IPC is InterProcess Communication
![Page 30: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/30.jpg)
Y Kermarrec Netprog: RPC Overview30
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.
![Page 31: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/31.jpg)
Y Kermarrec Netprog: RPC Overview31
RPCGEN
Input FileInput File
rpcgen
Client Stubs XDR filters header file Server skeleton
C Source Code
ProtocolDescription
![Page 32: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/32.jpg)
Y Kermarrec Netprog: RPC Overview32
rpcgen Output Files
> rpcgen –C foo.x
foo_clnt.c (client stubs)
foo_svc.c (server main)
foo_xdr.c (xdr filters)
foo.h (shared header file)
![Page 33: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/33.jpg)
Y Kermarrec Netprog: RPC Overview33
Client Creation
> gcc -o fooclient foomain.c foo_clnt.c foo_xdr.c -lnsl
foomain.c is the client main() (and possibly other functions) that call rpc services via the client stub functions in foo_clnt.c
The client stubs use the xdr functions.
![Page 34: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/34.jpg)
Y Kermarrec Netprog: RPC Overview34
Server Creation
gcc -o fooserver fooservices.c foo_svc.c foo_xdr.c –lrpcsvc -lnsl
fooservices.c contains the definitions of the actual remote procedures.
![Page 35: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/35.jpg)
Y Kermarrec Netprog: RPC Overview35
Example Protocol Definition
struct twonums {int a;int b;
};program UIDPROG {version UIDVERS {
int RGETUID(string<20>) = 1;string RGETLOGIN( int ) = 2;int RADD(twonums) = 3;
} = 1;} = 0x20000001;
![Page 36: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/36.jpg)
Y Kermarrec
Information for the labs
You are going to experiment :• how to go from a classic procedure call to an RPC• How to run a server and activate clients calls• What is the magic (the work of rpcgen) behind the
scene in terms of socket management, connections, errors and fault detection.
• Get the initial insights for all the other paradigms (distributed object, Java RMI, web services…) work and are handled
![Page 37: RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY](https://reader036.vdocuments.us/reader036/viewer/2022062318/55162554550346a2308b5b81/html5/thumbnails/37.jpg)
Y Kermarrec
Survey
RPC is a powerful way to program distributed system quite easily
It was initialy an OS feature that has been moved to the programmer’s world
Numerous benefits in terms of transparencies and above all fault tolerance