Lecture 20 Remote Procedure Call eXternal Data Representation - PowerPoint PPT Presentation

lecture 20 remote procedure call external data representation n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Lecture 20 Remote Procedure Call eXternal Data Representation PowerPoint Presentation
Download Presentation
Lecture 20 Remote Procedure Call eXternal Data Representation

play fullscreen
1 / 77
Lecture 20 Remote Procedure Call eXternal Data Representation
141 Views
Download Presentation
ralph
Download Presentation

Lecture 20 Remote Procedure Call eXternal Data Representation

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Lecture 20Remote Procedure CalleXternal Data Representation CPE 401 / 601Computer Network Systems slides are modified from Dave Hollinger

  2. Distributed Program Design Typical Sockets Approach • 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 RPC RPC Overview

  3. RPC: Remote Procedure Call • Call a procedure (subroutine) that is running on another machine. • Issues: • identifying and accessing the remote procedure • parameters • return value RPC Overview

  4. 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); } protocol RPC Overview

  5. 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. RPC Overview

  6. Sun RPC Organization Remote Program Shared Global Data Procedure 1 Procedure 2 Procedure 3 RPC Overview

  7. 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. • Newer versions can handle multiple args RPC Overview

  8. Procedure Identification • Each procedure is identified by: • Hostname (IP Address) • Program identifier (32 bit integer) • Procedure identifier (32 bit integer) • usually start at 1 and are numbered sequentially • Program version identifies • for testing and migration • typically start at 1 and are numbered sequentially RPC Overview

  9. Program Identifiers • Each remote program has a unique ID. • Sun divided up the IDs: 0x00000000 - 0x1fffffff 0x20000000 - 0x3fffffff 0x40000000 - 0x5fffffff 0x60000000 - 0xffffffff Sun SysAdmin Transient Reserved RPC Overview

  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. • Having an iterative server is useful for applications that may share data among procedures. • Eg: database to avoid insert/delete/modify collisions RPC Overview

  11. 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"! RPC Overview

  12. 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 • if we get a response (a return value) • "Zero or More" Semantics • if we don't hear back from the remote subroutine RPC Overview

  13. 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). RPC Overview

  14. 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! RPC Overview

  15. 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. • A port lookup service runs on each host • RPC servers register • "I'm program 17 and I'm looking for requests on port 1736” RPC Overview

  16. The portmapper • Each system which will support RPC servers runs a port mapper server • provides a central registry for RPC services • Servers tell the port mapper what services they offer • Clients ask a remote port mapper for the port number corresponding to Remote Program ID • The portmapper is itself an RPC server! • is available on a well-known port (111) Netprog: RPC Overview

  17. RPC Programming • RPC library is a collection of tools for automating the creation of clients and servers • clients are processes that call remote procedures • servers are processes that include procedure(s) that can be called by clients • RPC library • XDR routines • RPC run time library • call rpc service • register with portmapper • dispatch incoming request to correct procedure • Program Generator RPC Overview

  18. 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 • High-Level RPC library calls support UDP only • must use lower-level RPC library functions to use TCP • High-Level library calls do not support any kind of authentication RPC Overview

  19. Low-level RPC Library • Full control over all Inter-Process Communication options • TCP & UDP • Timeout values • Asynchronous procedure calls • Multi-tasking Servers • Broadcasting RPC Overview

  20. 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 RPC Overview

  21. RPCGEN Protocol Description Input File rpcgen Server skeleton XDR filters header file Client Stubs C Source Code RPC Overview

  22. 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) RPC Overview

  23. 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 RPC Overview

  24. 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. RPC Overview

  25. 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; RPC Overview

  26. XDR: External Data Representation Process A Process A XDR Encode/Decode XDR Encode/Decode Transport Transport XDR

  27. XDR • Powerful paradigm for creation and transfer of complex data structures • XDR provides a service associated with the OSI Presentation Layer. • Common data representation • Library • not part of the O.S. • Easy to port to new architectures • Independence from transport layer XDR

  28. Data Conversion • Asymmetric Data Conversion • client always converts to the server’s data representation. • Symmetric Data Conversion • both client and server convert to/from some standard representation. XDR is Symmetric Data Conversion XDR

  29. Implicit vs. Explicit Typing • Explicit typing • each piece of data includes information about the type • Implicit typing • the sender and receiver must agree on the order and type of all data XDR uses Implicit Typing XDR

  30. XDR Data Types • enumeration • structure • string • fixed length array (1-D) • variable length array (1-D) • union • opaque data • boolean • char • short • int • long • float • double XDR

  31. XDR Programming • XDR libraries are based on a stream paradigm • The process of converting local data to XDR also puts the data in the XDR stream • When extracting an item from a stream, conversion is done to the local representation • Streams can be attached to a file, pipe, socket or memory • Individual data items are added to (removed from) the stream one at a time XDR

  32. Conversion Terminology • Converting from local representation to XDR representation is called Encoding. • Converting from XDR representation to local representation is called Decoding. Sender Receiver XDR ENCODE DECODE XDR

  33. XDR Stream Creation • There are a number of stream creation functions in the XDR library • xdrmem_create • destination for encoding -or- source for decoding is a chunk of memory • xdrstdio_create • destination for encoding -or- source for decoding is a file descriptor. XDR

  34. XDR filters • The XDR library includes an extensive set of filters that perform encoding/decoding operations • Each XDR stream includes an attribute that determines the specific operation to be performed by a filter • encoding or decoding XDR

  35. XDR Filters • The filter to encode/decode an integer is called xdr_int: bool_t xdr_int(XDR *xdrs, int *ip); • the return value indicates success. • xdrs is a pointer to an XDR stream • ip is a pointer to an integer. XDR

  36. xdr_int() encode vs. decode Source Encodes int count; xdr_int(xstream,&count); Destination decodes int count; xdr_int(xstream,&count); XDR

  37. Complex Data Filters • The XDR library includes a set of filters designed to • translate complex C data structures to and from XDR representation • Many of these filters use simpler filters to convert individual components • xdr_array() • for encoding/decoding a variable length array • xdr_string() • string conversion filter has a maximum size XDR

  38. xdr_array() (cont.) Source Array 0 1 2 3 elproc() Dest. Array 0 1 2 3 XDR

  39. XDR and RPC • RPC uses XDR, but the XDR filters are built for you automatically! • You define a complex data type • a code generator writes an XDR filter that can encode/decode your data type • Sometimes you need to understand XDR anyway... XDR

  40. RPC Programming with rpcgen Issues: • Protocol Definition File • Client Programming • Creating an "RPC Handle" to a server • Calling client stubs • Server Programming • Writing Remote Procedures RPC Programming

  41. Protocol Definition File • Description of the interface of the remote procedures. • Almost function prototypes • Definition of any data structures used in the calls (argument types & return types) • Can also include shared C code (shared by client and server). Netprog: RPC Programming

  42. XDR the language • XDR data types are not C data types! • There is a mapping from XDR types to C types • that's most of what rpcgen does. • Most of the XDR syntax is just like C • Arrays, strings are different. RPC Programming

  43. XDR Arrays • Fixed Length arrays look just like C code: int foo[100] • Variable Length arrays look like this: int foo<> or int foo<MAXSIZE> Implicit maximum size is 232-1 RPC Programming

  44. What gets sent on the network int x[n] . . . x0 x1 x2 xn-1 k is actual array size km int y<m> . . . k y0 y1 y2 yk RPC Programming

  45. s0 s1 s2 s3 XDR String Type • Look like variable length arrays: string s<100> • What is sent: length followed by sequence of ASCII chars: . . . n Sn-1 n is actual string length (sent as int) RPC Programming

  46. Linked Lists! struct foo { int x; foo *next; } • The generated XDR filter uses xdr_pointer() to encode/decode the stuff pointed to by a pointer rpcgen recognizes this as a linked list RPC Programming

  47. Declaring The Program programSIMP_PROG { versionSIMP_VERSION { type1 PROC1(operands1) = 1; type2 PROC2(operands2) = 2; } = 1; } = 40000000; Color Code: Keywords Generated Symbolic Constants Used to generate stub and procedure names RPC Programming

  48. Procedure Numbers • Procedure #0 is created for you automatically. • Start at procedure #1! • Procedure #0 is a dummy procedure that can help debug things • sort of an RPC ping server RPC Programming