The Remote Procedure Call model
Remote Procedure Call implementation
The rpcgen Compiler
Remote Procedure Call
Giovanni Agosta
Piattaforme Software per la Rete Modulo 2
G. Agosta Remote Procedure Call
The Remote Procedure Call model
Remote Procedure Call implementation
The rpcgen Compiler
Outline
1 The Remote Procedure Call model
2 Remote Procedure Call implementation
3 The rpcgen Compiler
Overview
Declarations and Definitions
Using the rpcgen Compiler
G. Agosta Remote Procedure Call
The Remote Procedure Call model
Remote Procedure Call implementation
The rpcgen Compiler
Introduction
Designing Distributed Programs
Communication-Oriented Design
Application-Oriented Design
Remote Procedure Call model
Support the Client-Server model
Allow Application-Oriented Design
Divide the program at procedure boundaries into local and
remote parts
G. Agosta Remote Procedure Call
The Remote Procedure Call model
Remote Procedure Call implementation
The rpcgen Compiler
Remote Procedure Call model
computer_1
main
proc_1 proc_2 proc_3 proc_4
proc_5 proc_6 proc_7
A typical program, divided into a set of procedures (static
view)
G. Agosta Remote Procedure Call
The Remote Procedure Call model
Remote Procedure Call implementation
The rpcgen Compiler
Remote Procedure Call model
computer_1 computer_2
main
proc_1 proc_2 proc_3 proc_4
proc_5 proc_6 proc_7
The same program, partitioned between two machines using
the RPC model
A communication protocol is needed between main and
proc 4
G. Agosta Remote Procedure Call
The Remote Procedure Call model
Remote Procedure Call implementation
The rpcgen Compiler
Remote Procedure Call model
main proc_4 main proc_4
on computer 1 on computer 1 on computer 1 on computer 2
(caller) (callee) (client) (server)
remote
procedure procedure
call call
return return
from from
procedure remote
procedure
However, remote calls are much slower
Remote calls also do not happen in the same address space!
And have no access to the environment (e.g., files)
G. Agosta Remote Procedure Call
The Remote Procedure Call model
Remote Procedure Call implementation
The rpcgen Compiler
Remote Procedure Call Addressing
Derived from Sun Open Network Computing (ONC)
Requires a tuple of (program, version, procedure) to work
Uses unique, registered identifiers (integers) to identify remote
programs (i.e., servers)
RPC identifiers are mapped to IP ports
The portmapper service is used to register programs to ports
and obtain the port for a given program
rpcinfo -p
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
G. Agosta Remote Procedure Call
The Remote Procedure Call model
Remote Procedure Call implementation
The rpcgen Compiler
Remote Procedure Call Semantics
Semantics provided by Sun-style RPC
Guaranteed mutual exclusion (at most one remote procedure
active at any time in any server program)
Only the weakest possible assumptions, based on the
underlying protocols
UDP if the procedure returns, assume at least once
execution
UDP if the procedure does not returns, assume zero
or more execution
What to do?
No need to worry about mutual exclusion
When using UPD, remote procedures need to be idempotent
G. Agosta Remote Procedure Call
The Remote Procedure Call model
Remote Procedure Call implementation
The rpcgen Compiler
Remote Procedure Call Messages
Message Format
Not fixed
Uses External Data Representation (XDR) to provide a
machine-independent data representation
External Data Representation (XDR)
A symmetric data conversion solution:
Avoid having one conversion procedure for each server machine
However, double computational overhead
XDR data structures are similar to C data structures
G. Agosta Remote Procedure Call
The Remote Procedure Call model
Remote Procedure Call implementation
The rpcgen Compiler
XDR Data types (1)
Type Size Description
int 32 32-bit integer
unsigned int 32 32-bit unsigned integer
bool 32 0 or 1
hyper 64 64-bit integer
unsigned hyper 64 64-bit unsigned integer
float 32 single precision float
double 64 double precision float
enum arb enumeration
string arb ASCII string
opaque arb raw data
G. Agosta Remote Procedure Call
The Remote Procedure Call model
Remote Procedure Call implementation
The rpcgen Compiler
XDR Data types (2)
Type Size Description
fixed array arb fixed-size array
counted array arb max-sized array
structure arb C struct
union arb Pascal variant records
void 0 no data
constant arb symbolic constant
optional data arb 0 or 1 occurences of other type
optional data used to represent pointers
union uses type tags
G. Agosta Remote Procedure Call
The Remote Procedure Call model
Remote Procedure Call implementation
The rpcgen Compiler
Remote Procedure Call Mechanism
decode XDR filter rpc result XDR filter encode
network
Client Client Server Server
Data code code Data
encode decode
XDR filter rpc call XDR filter
Data flow through XDR filters in both directions
G. Agosta Remote Procedure Call
The Remote Procedure Call model
Remote Procedure Call implementation
The rpcgen Compiler
Remote Procedure Call Mechanism
A rather cumbersome mechanism...
1 Remote program registers to portmap
2 Caller program gets port from portmap
3 Caller program encodes input parameters
4 Caller program passes the data to remote host
5 Remote callee decodes the input parameters
6 Remote callee operates
7 Remote callee encodes results
8 Remote host returns the results to caller program
9 Caller program decodes the results and resumes execution
G. Agosta Remote Procedure Call
The Remote Procedure Call model Overview
Remote Procedure Call implementation Declarations and Definitions
The rpcgen Compiler Using the rpcgen Compiler
The rpcgen Compiler
Overview
Writing calls to the XDR library directly is cumbersome
Use a domain specific language for both XDR and RPC
Use rpcgen compiler to compile XDR and RPC program
specification
G. Agosta Remote Procedure Call
The Remote Procedure Call model Overview
Remote Procedure Call implementation Declarations and Definitions
The rpcgen Compiler Using the rpcgen Compiler
The rpcgen Compiler
Structures
Sample XDR Declaration C translation
struct coord { struct coord {
int x ; int x ;
int y ; int y ;
}; };
typedef s t r u c t coord coord ;
G. Agosta Remote Procedure Call
The Remote Procedure Call model Overview
Remote Procedure Call implementation Declarations and Definitions
The rpcgen Compiler Using the rpcgen Compiler
The rpcgen Compiler
Discriminated Union
Sample XDR Declaration C translation
union f o o s w i t c h ( i n t n ) struct foo {
{ int n ;
case 0 : union {
opaque d a t a [ 1 0 2 4 ] ; char d a t a [ 1 0 2 4 ] ;
default : } foo u ;
void ; };
}; typedef s t r u c t foo foo ;
G. Agosta Remote Procedure Call
The Remote Procedure Call model Overview
Remote Procedure Call implementation Declarations and Definitions
The rpcgen Compiler Using the rpcgen Compiler
The rpcgen Compiler
Constant, array, typedef and string
Sample XDR Declaration C translation
const DOZEN = 1 2 ; #d e f i n e DOZEN 12
t y p e d e f s t r i n g s <24>; t y p e d e f char s ;
int palette [ 8 ] ; int palette [ 8 ] ;
i n t h e i g h t s <12>; struct {
u int heights len ;
int heights val ;
} heights ;
G. Agosta Remote Procedure Call
The Remote Procedure Call model Overview
Remote Procedure Call implementation Declarations and Definitions
The rpcgen Compiler Using the rpcgen Compiler
The rpcgen Compiler
Booleans, pointers and raw data
Boolean type typedef int bool t ;
Pointers are represented as optional data
Sample XDR Declaration C translation
bool married ; bool t married ;
l i s t i t e m next ; l i s t i t e m next ;
opaque d i s k b l o c k [ 5 1 2 ] ; char d i s k b l o c k [ 5 1 2 ] ;
opaque f i l e d a t a <1024>; struct {
u int filedata len ;
char f i l e d a t a v a l ;
} filedata ;
G. Agosta Remote Procedure Call
The Remote Procedure Call model Overview
Remote Procedure Call implementation Declarations and Definitions
The rpcgen Compiler Using the rpcgen Compiler
The rpcgen Compiler
Defining remote procedures
Sample rpcgen Declaration C translation
program TIMEPROG { #d e f i n e TIMEPROG 44
v e r s i o n TIMEVERS { #d e f i n e TIMEVERS 1
unsigned i n t TIMEGET( v#d o i de)f i=
n e 1 TIMEGET
; 1
v o i d TIMESET( unsigned ) #d
= e2f ;i n e TIMESET 2
} = 1;
} = 44;
G. Agosta Remote Procedure Call
The Remote Procedure Call model Overview
Remote Procedure Call implementation Declarations and Definitions
The rpcgen Compiler Using the rpcgen Compiler
Using the rpcgen Compiler
Write an rpcgen source file (e.g., avg.x)
Compile it: rpcgen avg.x
1 avg.h generated header file
2 avg clnt.c generated client stub
3 avg svc.c generated server stub
4 avg xdr.c common xdr routines
Write server and client logic
Compile server and client programs
G. Agosta Remote Procedure Call