310 likes | 457 Views
Remote Procedure Calls. External Data Representation (Ch 19) RPC Concept (Ch 20). Client / Server Between Systems The Problem:. Transfer of data between systems depends on local data representation. This can vary on at least 4 parameters: Data Size : integer may be 16 bits or 32 bits
E N D
Remote Procedure Calls External Data Representation (Ch 19) RPC Concept (Ch 20)
Client / Server Between SystemsThe Problem: • Transfer of data between systems depends on local data representation. This can vary on at least 4 parameters: • Data Size : integer may be 16 bits or 32 bits • Byte Ordering: Big endian vs. little endian
Client / Server Between SystemsThe Problem: • Transfer of data between systems depends on local data representation. This can vary on at least 4 parameters: • Data Size : integer may be 16 bits or 32 bits • Byte Ordering: Big endian vs. little endian • Data Representation: Strings null terminated vs. length + value • Alignment: May align on full word boundaries (16 or 32 or 64, etc.)
Client / Server Between SystemsThe Problem: • If each program has to accommodate multiple serving platforms, complexity goes up. N2 problem!! As the number of platforms goes up, the number of combinations becomes: (N)(N-1) 2
Client / Server Between SystemsOne Solution: • eXternal Data Representation (XDR) • Developed by Sun Microsystems • A standard for representing data over the network. • Includes a set of library routines for converting data between local format and XDR format (either direction).
int 32 bits unsigned int 32 bits bool 32 bits enum arbitrary hyper 64 bits unsigned hyper 64 bits float 32 bits double 64 bits opaque arbitrary String arbitrary fixed array arbitrary counted array arbitrary structure arbitrary discriminated union arbitrary. void 0 symbolic constant arbitrary optional data arbitrary XDR Data Types
XDR Data Conversion • Objective: • Gather all parameter data into a buffer in XDR format • Procedure: • Create a buffer (xdrmem_create)
XDR Data Conversion • Objective: • Gather all parameter data into a buffer in XDR format • Procedure: • Create a buffer (xdrmem_create) #include <rpc/xdr.h> #define BUFSIZE 4000 ... XDR * xdrs; char buf[BUFSIZE]; xdrmen_create(xdrs, buf, BUFSIZE, XDR_ENCODE);
xdr_bool (xdrs, ptrBool); xdr_bytes (xdrs,str,strSize,maxsize); xdr_char (xdrs, ptrChar); xdr_double(xdrs, prtDouble); xdr_enum(xdrs, ptrInt); xdr_float(xdrs, ptrFloat); xdr_int (xdrs, ptrInt); xdr_long (xdrs, ptrLong); xdr_opaque (xdrs, ptrChar, count); xdr_pointer (xdrs, ptrObj,pbjSize, xdrObj); xdrs_short (xdrs, ptrShort); xdrs_u_char (xdrs, ptrUchar); xdrs_u_int (xdrs, ptrUint); xdrs_u_long (xdrs, ptrUlong); xdrs_u_short (xdrs, ptrUshort); xdr_union (xdrs, ptrDiscrim, ptrUnion, choiceFcn, default); xdr_vector (xdrs, ptrArray, size, elemSize, elemProc); xdr_void ( ); XDR Data Conversion Routines
XDR Data Conversion • Add data items in order to the buffer (after converting to XDR format) int myInt; ... myInt = 260; xdr_int(xdrs, &myInt);
XDR Data Example • Query on remote user. Return logon time, void, or error code.
XDR Data Example • Query on remote user. Return logon time, void, or error code. const MAX_TIME_BUF = 30; union time_results switch (int status) { case 0: char timeval [MAX_TIME_BUF]; case 1: void; case 2: int reason; };
Distributed Programming2 Approaches • Communications Oriented Design • Start with a protocol for distributed communication • Develop Program around that protocol
Distributed Programming2 Approaches • Communications Oriented Design • Start with a protocol for distributed communication • Develop Program around that protocol • Application Oriented Design • Start with a working Application • Split the program and add a protocol that communicates between segments
Main proc1 proc2 proc3 proc4 proc5 proc6 proc7 Applications Conceptual Model
Main proc1 proc2 proc3 proc5 proc6 Applications Conceptual Model proc4 proc7
Procedural Model1 machine Main A B call B call A
Procedural Model1 machine / multiple machines Main A B call B call A
Remote Procedure Arguments • Programming languages use positional notation to identify arguments (1st argument, 2nd argument, etc.) • Overhead associated with collecting and managing multiple arguments can be reduced by aggregating the needed procedure arguments into a single passed parameter (e.g. a C language struct). • While multiple arguments are allowed with RPC, good programming suggests using only 1.
Remote Procedure CallProgram Identification • Program Name • 32 bit value to identify program • 0x00000000 - 0x1fffffff Sun Microsystems • 0x20000000 - 0x3fffffff Local procedures • 0x40000000 - 0x5fffffff transient • rest reserved • Program version number • Procedure Number
RPC Communications • Communications Semantics • May be specified using UDP or TCP • RPC semantics defined in terms of the underlying protocol. Reliability not enforced by RPC, but by the underlying transport protocol.
RPC Retransmission • RPC library includes a simple timer and retransmission capability. • A response is characterized as “the remote procedure has been executed at least once”. • No response is characterized as “the remote procedure was executes 0 or more times”.
RPC Retransmission • RPC library includes a simple timer and retransmission capability. • A response is characterized as “the remote procedure has been executed at least once”. • No response is characterized as “the remote procedure was executes 0 or more times”. • This implies that procedures that use UDP must be “idempotent”. (Multiple executions do not change the result.)
RPC Procedure Location • RPC identifies procedures with a 32 bit number. • Allows for far more services than ports available • Typically only a few services running at any time. • Need some sort of “directory service” that can correlate desired procedure with a protocol port number. • This directory service is called the Portmapper server.
RPC Port Identification • RPC portmapper at “well known port” 111 • Programs register with the portmapper • Stores data pairs of the form • (RPC program #, version #): protocol port #
Procedure Registration and Use 6 RPC service RPC client 5 4 2 Port Mapper 3 1
RPC Message Passing • All data parameters are passed as a single “struct” • struct rpc_msg { enum msg_type { unsigned int mesgid; CALL = 0; union switch (msg_type mesgt) REPLY = 1; { }; case CALL: call_body cbody; case REPLY: rply_body rbody; } body; };
RPC Message Passing struct call_body { unsigned int rpcvers; unsigned int rprog; unsigned int rprogvers; unsigned int rproc; opaque_auth cred; opaque_auth verf; /* args */ };
RPC Message Authentication • Two parts to authentication • credentials (what info is provided) • verifier (who vouches for that info) • 4 levels of authentication • none • UNIX • short form • secure (DES)
Example RPC Message • Call to NFS to get attributes for a file Message ID Message type (0 for call) RPC Version Number (2) Remote Program (0x186a3 for NFS) Remote Program Version (2) Remote Procedure (1 for GETATTR) UNIX Authentication Arguments (if any)
Summary • Remote Procedure Call communications method developed by Sun to facilitate inter-machine / interprocess communications • XDR used to manage inter-platform data transfer • RPC uses application oriented design approach • Portmapper used to locate remote procedures • RPC messages structured to maximize data reuse