netprog 2001 - rpc overview1 distributed program design n communication-oriented design –design...
TRANSCRIPT
Netprog 2001 - RPC Overview 1
Distributed Program DesignDistributed Program Design
Communication-Oriented DesignCommunication-Oriented Design– Design protocol first. Design protocol first. – Build programs that adhere to the protocol.Build programs that adhere to the protocol.
Application-Oriented DesignApplication-Oriented Design– Build application(s).Build application(s).– Divide programs up and add Divide programs up and add
communication protocols.communication protocols.
Typical Typical
SocketsSockets
Approach
Approach
RPCRPC
Netprog 2001 - RPC Overview 2
RPCRPCRemote Procedure CallRemote Procedure Call
Call a procedure (subroutine) that is Call a procedure (subroutine) that is running on another machine.running on another machine.
Issues:Issues:– identifying and accessing the remote identifying and accessing the remote
procedureprocedure– parametersparameters– return valuereturn value
Netprog 2001 - RPC Overview 3
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);}
ClientClient
ServerServer
protocol
Remote SubroutineRemote Subroutine
Netprog 2001 - RPC Overview 4
Sun RPCSun RPC
There are a number of popular RPC There are a number of popular RPC specifications.specifications.
Sun RPC (ONC RPC) is widely used.Sun RPC (ONC RPC) is widely used. NFS (Network File System) is RPC NFS (Network File System) is RPC
based.based. Rich set of support tools.Rich set of support tools.
Netprog 2001 - RPC Overview 5
Sun RPC OrganizationSun RPC Organization
Procedure 1Procedure 1 Procedure 2Procedure 2 Procedure 3Procedure 3
Shared Global DataShared Global Data
Remote ProgramRemote Program
Netprog 2001 - RPC Overview 6
Procedure ArgumentsProcedure Arguments To reduce the complexity of the interface To reduce the complexity of the interface
specification, Sun RPC includes support specification, Sun RPC includes support for a single argument to a remote for a single argument to a remote procedure.*procedure.*
Typically the single argument is a Typically the single argument is a structure that contains a number of structure that contains a number of values.values.
* * Newer versions can handle multiple args.Newer versions can handle multiple args.
Netprog 2001 - RPC Overview 7
Procedure IdentificationProcedure Identification
Each procedure is identified by:Each procedure is identified by:– Hostname (IP Address)Hostname (IP Address)– Program identifier (32 bit integer)Program identifier (32 bit integer)– Procedure identifier (32 bit integer)Procedure identifier (32 bit integer)
Netprog 2001 - RPC Overview 8
Procedure IdentificationProcedure Identification
Each procedure is identified by:Each procedure is identified by:– Hostname (IP Address)Hostname (IP Address)– Program identifier (32 bit integer)Program identifier (32 bit integer)– Procedure identifier (32 bit integer)Procedure identifier (32 bit integer)
– Program Version identifierProgram Version identifier» for testing and migration.for testing and migration.
Netprog 2001 - RPC Overview 9
Program IdentifiersProgram Identifiers
Each remote program has a unique ID.Each remote program has a unique ID. Sun divided up the IDs:Sun divided up the IDs:
0x00000000 - 0x1fffffff0x00000000 - 0x1fffffff
0x20000000 - 0x3fffffff0x20000000 - 0x3fffffff
0x40000000 - 0x5fffffff0x40000000 - 0x5fffffff
0x60000000 - 0xffffffff0x60000000 - 0xffffffff
SunSun
SysAdmin SysAdmin
TransientTransient
ReservedReserved
Netprog 2001 - RPC Overview 10
Procedure Identifiers &Procedure Identifiers &Program Version NumbersProgram Version Numbers
Procedure Identifiers usually start at 1 Procedure Identifiers usually start at 1 and are numbered sequentiallyand are numbered sequentially
Version Numbers typically start at 1 and Version Numbers typically start at 1 and are numbered sequentially.are numbered sequentially.
Netprog 2001 - RPC Overview 11
Iterative ServerIterative Server
Sun RPC specifies that at Sun RPC specifies that at mostmost one one remote procedure within a program can remote procedure within a program can be invoked at any given time.be invoked at any given time.
If a 2nd procedure is called, the call If a 2nd procedure is called, the call blocks until the 1st procedure has blocks until the 1st procedure has completed.completed.
Netprog 2001 - RPC Overview 12
Iterative can be goodIterative can be good
Having an iterative server is useful for Having an iterative server is useful for applications that may share data among applications that may share data among procedures.procedures.
Example: database - to avoid Example: database - to avoid insert/delete/modify collisions.insert/delete/modify collisions.
We can provide concurrency when We can provide concurrency when necessary...necessary...
Netprog 2001 - RPC Overview 13
Call SemanticsCall Semantics
What does it mean to call a local What does it mean to call a local procedure?procedure?– the procedure is run exactly one time.the procedure is run exactly one time.
What does it mean to call a remote What does it mean to call a remote procedure?procedure?– It might not mean "run exactly once"!It might not mean "run exactly once"!
Netprog 2001 - RPC Overview 14
Remote Call SemanticsRemote Call Semantics
To act like a local procedure (exactly To act like a local procedure (exactly one invocation per call) - a reliable one invocation per call) - a reliable transport (TCP) is necessary.transport (TCP) is necessary.
Sun RPC does not support reliable call Sun RPC does not support reliable call semantics. !semantics. !
At Least Once SemanticsAt Least Once Semantics Zero or More SemanticsZero or More Semantics
Netprog 2001 - RPC Overview 15
Sun RPC Call SemanticsSun RPC Call Semantics
At Least Once SemanticsAt Least Once Semantics– if we get a response (a return value)if we get a response (a return value)
Zero or More SemanticsZero or More Semantics– if we don't hear back from the remote if we don't hear back from the remote
subroutine.subroutine.
Netprog 2001 - RPC Overview 16
Remote Procedure deposit()Remote Procedure deposit()
deposit(DavesAccount,$100)deposit(DavesAccount,$100)
Always remember that you don't Always remember that you don't knowknow how many times the remote procedure how many times the remote procedure was run!was run!– The net can duplicate the request (UDP).The net can duplicate the request (UDP).
Netprog 2001 - RPC Overview 17
Network CommunicationNetwork Communication
The actual network communication is The actual network communication is nothing new - it's just TCP/IP.nothing new - it's just TCP/IP.
Many RPC implementations are built Many RPC implementations are built upon the sockets library.upon the sockets library.– the RPC library does all the work!the RPC library does all the work!
We are just using a different API, the We are just using a different API, the underlying stuff is the same!underlying stuff is the same!
Netprog 2001 - RPC Overview 18
Dynamic Port MappingDynamic Port Mapping
Servers typically do not use well known Servers typically do not use well known protocol ports!protocol ports!
Clients known the Program ID (and host Clients known the Program ID (and host IP address).IP address).
RPC includes support for looking up the RPC includes support for looking up the port number of a port number of a remote program.remote program.
Netprog 2001 - RPC Overview 19
Port Lookup ServicePort Lookup Service
A port lookup service runs on each host A port lookup service runs on each host that contains RPC servers.that contains RPC servers.
RPC servers register themselves with RPC servers register themselves with this service:this service:– "I'm program 17 and I'm looking for "I'm program 17 and I'm looking for
requests on port 1736"requests on port 1736"
Netprog 2001 - RPC Overview 20
The portmapperThe portmapper
Each system which will support RPC Each system which will support RPC servers runs a servers runs a port mapper port mapper server that server that provides a central registry for RPC provides a central registry for RPC services.services.
Servers tell the port mapper what Servers tell the port mapper what services they offer.services they offer.
Netprog 2001 - RPC Overview 21
More on the portmapperMore on the portmapper
Clients ask a remote port mapper for the Clients ask a remote port mapper for the port number corresponsing to Remote port number corresponsing to Remote Program ID.Program ID.
The portmapper is itself an RPC server!The portmapper is itself an RPC server!
The portmapper is available on a well-The portmapper is available on a well-known port (111).known port (111).
Netprog 2001 - RPC Overview 22
Sun RPC ProgrammingSun RPC Programming
The RPC library is a collection of tools The RPC library is a collection of tools for automating the creation of RPC for automating the creation of RPC clients and servers.clients and servers.
RPC clients are processes that call RPC clients are processes that call remote procedures.remote procedures.
RPC servers are processes that include RPC servers are processes that include procedure(s) that can be called by procedure(s) that can be called by clients.clients.
Netprog 2001 - RPC Overview 23
RPC ProgrammingRPC Programming
RPC libraryRPC library– XDR routinesXDR routines– RPC run time libraryRPC run time library
» call rpc servicecall rpc service» register with portmapperregister with portmapper» dispatch incoming request to correct proceduredispatch incoming request to correct procedure
– Program GeneratorProgram Generator
Netprog 2001 - RPC Overview 24
RPC Run-time LibraryRPC Run-time Library
High- and Low-level functions that can High- and Low-level functions that can be used by clients and servers.be used by clients and servers.
High-level functions provide simple High-level functions provide simple access to RPC services.access to RPC services.
Netprog 2001 - RPC Overview 25
High-level Client LibraryHigh-level Client Library
int callrpc( char *host,int callrpc( char *host,
u_long prognum,u_long prognum,
u_long versnum,u_long versnum,
u_long procnum,u_long procnum,
xdrproc_t inproc,xdrproc_t inproc,
char *in,char *in,
xdrproc_t outproc,xdrproc_t outproc,
char *out);char *out);
Netprog 2001 - RPC Overview 26
High-Level Server LibraryHigh-Level Server Library
int registerrpc(int registerrpc(
u_long prognum,u_long prognum,
u_long versnum,u_long versnum,
u_long procnum,u_long procnum,
char *(*procname)()char *(*procname)()
xdrproc_t inproc,xdrproc_t inproc,
xdrproc_t outproc);xdrproc_t outproc);
Netprog 2001 - RPC Overview 27
High-Level Server Library High-Level Server Library (cont.)(cont.)
void svc_run();void svc_run();
svc_run()svc_run() is a is a dispatcher. dispatcher. A dispatcher waits for incoming A dispatcher waits for incoming
connections and invokes the connections and invokes the appropriate function to handle each appropriate function to handle each incoming request.incoming request.
Netprog 2001 - RPC Overview 28
High-Level Library LimitationHigh-Level Library Limitation
The High-Level RPC library calls The High-Level RPC library calls support UDP only (no TCP).support UDP only (no TCP).
You must use lower-level RPC library You must use lower-level RPC library functions to use TCP.functions to use TCP.
The High-Level library calls do not The High-Level library calls do not support any kind of authentication.support any kind of authentication.
Netprog 2001 - RPC Overview 29
Low-level RPC LibraryLow-level RPC Library
Full control over all IPC optionsFull control over all IPC options– TCP & UDPTCP & UDP– Timeout valuesTimeout values– Asynchronous procedure callsAsynchronous procedure calls
Multi-tasking ServersMulti-tasking Servers BroadcastingBroadcasting
IPC is InterProcess Communication
Netprog 2001 - RPC Overview 30
RPCGENRPCGEN
There is a tool for automating the There is a tool for automating the creation of RPC clients and servers.creation of RPC clients and servers.
The program The program rpcgen rpcgen does most of the does most of the work for you.work for you.
The input to rpcgen is a The input to rpcgen is a protocol protocol definition definition in the form of a list of remote in the form of a list of remote procedures and parameter types.procedures and parameter types.
Netprog 2001 - RPC Overview 31
RPCGENRPCGEN
Input File
rpcgen
Client Stubs XDR filters header file Server skeleton
C Source CodeC Source Code
ProtocolProtocolDescriptionDescription
Netprog 2001 - RPC Overview 32
rpcgen Output Filesrpcgen Output Files
> rpcgen foo.x> rpcgen foo.x
foo_clnt.c (client stubs)foo_clnt.c (client stubs)
foo_svc.c (server main)foo_svc.c (server main)
foo_xdr.c (xdr filters)foo_xdr.c (xdr filters)
foo.h (shared header file)foo.h (shared header file)
Netprog 2001 - RPC Overview 33
Client CreationClient Creation
> gcc -o fooclient foomain.c foo_clnt.c > gcc -o fooclient foomain.c foo_clnt.c foo_xdr.cfoo_xdr.c
foomain.c is the client main() (and possibly foomain.c is the client main() (and possibly other function) that call rpc services via the other function) that call rpc services via the client stub functions in foo_clnt.cclient stub functions in foo_clnt.c
The client stubs use the xdr functions.The client stubs use the xdr functions.
Netprog 2001 - RPC Overview 34
Server CreationServer Creation
gcc -o fooserver fooservices.c foo_svc.c gcc -o fooserver fooservices.c foo_svc.c foo_xdr.cfoo_xdr.c
fooservices.c contains the definitions of the fooservices.c contains the definitions of the actual remote procedures.actual remote procedures.
Netprog 2001 - RPC Overview 35
Example Protocol DefinitionExample Protocol Definitionstruct twonums {struct twonums {
int a;int a;
int b;int b;
};};
program UIDPROG {program UIDPROG {
version UIDVERS {version UIDVERS {
int RGETUID(string<20>) = 1;int RGETUID(string<20>) = 1;
string RGETLOGIN( int ) = 2;string RGETLOGIN( int ) = 2;
int RADD(twonums) = 3;int RADD(twonums) = 3;
} = 1;} = 1;
} = 0x20000001;} = 0x20000001;