1 / 52

Remote Procedure Call (ONC RPC)

Remote Procedure Call (ONC RPC). From Bloomer, Power Programming with RPC , Chapter 1, and Comer and Stevens, Internetworking with TCP/IP, Volume III , Chapters 20-22. Remote procedure call. A remote procedure call makes a call to a remote service look like a local call

Download Presentation

Remote Procedure Call (ONC RPC)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.


Presentation Transcript

  1. Remote Procedure Call(ONC RPC) From Bloomer, Power Programming with RPC, Chapter 1, and Comer and Stevens, Internetworking with TCP/IP, Volume III, Chapters 20-22 Leon Jololian/George Blank/Jianghui Liu

  2. Remote procedure call • A remote procedure call makes a call to a remote service look like a local call • RPC makes transparent whether server is local or remote • RPC allows applications to become distributed transparently • RPC makes architecture of remote machine transparent Leon Jololian/George Blank/Jianghui Liu

  3. RPC Description • RPC is a widely used communications process for building distributed applications. • An RPC is really a process invocation, not a procedure call. An invoked program runs in another domain. • RPCs hide the intricacies of the network by using the procedure call mechanism familiar to programmers. • They make life easy for programmers, but hard for Network OS designers. Leon Jololian/George Blank/Jianghui Liu

  4. RPC vs. Local Procedure • 4 properties of distributed computing that make achieving transparency difficult: • Partial failures • Concurrency • Latency • Memory access Leon Jololian/George Blank/Jianghui Liu

  5. Partial failures • In local computing: • if machine fails, application fails • In distributed computing: • if a machine fails, part of application fails • one cannot tell the difference between a machine failure and network failure • How to make partial failures transparent to client? Leon Jololian/George Blank/Jianghui Liu

  6. Strawman solution • Make remote behavior identical to local behavior: • Every partial failure results in complete failure • You abort and reboot the whole system • You wait patiently until system is repaired • Problems with this solution: • Many catastrophic failures • Clients block for long periods • System might not be able to recover Leon Jololian/George Blank/Jianghui Liu

  7. Real solution: break transparency • Possible semantics for RPC: • Exactly-once • Impossible in practice • More than once: • Only for idempotent operations • At most once • Zero, don’t know, or once • Zero or once • Transactional semantics • At-most-once most practical • But different from LPC Leon Jololian/George Blank/Jianghui Liu

  8. Where RPC transparency breaks • True concurrency • Clients run truely concurrently client() { if (exists(file)) if (!remove(file)) abort(“remove failed??”); } • RPC latency is high • Orders of magnitude larger than LPC’s • Memory access • Pointers are local to an address space Leon Jololian/George Blank/Jianghui Liu

  9. Network OS Issues • How are server functions located and started? • How are parameters defined and passed between client and server? Better NOS’s usually offer an Interface Definition Language (IDL) with an IDL compiler. • How are failures handled? • How does RPC handle security? • How does client find its server? • How is data translated for different systems? (Big-endian vs little-endian, ASCII vs. others, etc.) Leon Jololian/George Blank/Jianghui Liu

  10. Synchronous RPC Call Client Application RPC Call Invoke Service Call Service Service Executes Client Computer Request Completed Return Answer Program Continues Return Reply Server Computer Leon Jololian/George Blank/Jianghui Liu

  11. Leon Jololian/George Blank/Jianghui Liu

  12. RPC • Remote Procedure Call allows a client to execute procedures on other computers. • ONC’s RPC forms the foundation for most of the distributed utilities used today, like NFS and NIS. • RPC simplifies the task of writing client/server programs. Leon Jololian/George Blank/Jianghui Liu

  13. Differences between RPC and Local Procedure Calls • Error handling: RPC programs must handle remote errors • Side Effects and Global Variables: Server does not access client address space, so hidden arguments cannot be passed. • Performance: RPC is usually much slower. • Authentication: RPC may operate over an unsecured network, so verification may need to be done by developer. Leon Jololian/George Blank/Jianghui Liu

  14. Client Server Client Procedure Called Procedure arguments results Client Stub Server Stub Network transport Network Transport Network RPC process Leon Jololian/George Blank/Jianghui Liu

  15. Developing an RPC Application • Specify the protocol for client/server communication • Develop the client and server programs Leon Jololian/George Blank/Jianghui Liu

  16. Developing the Application Protocol • Define the interface between the client and server. • identify the names of service procedures and the data types of parameters and return arguments. • Use the protocol compiler to generate the client and server stubs. Leon Jololian/George Blank/Jianghui Liu

  17. Different Types of Protocol Compilers for RPC • Netwise RPCTOOL • Sun Open Network Computing RPCGEN • NIDL OFS/NCS • Xerox Courier XNS SPP • Apollo Network Computing Architecture NCA Leon Jololian/George Blank/Jianghui Liu

  18. RPCL Protocol Definition File • The RPC Language definition file uses a .x extension • It contains the preprocessor directives, constant and structure definitions, program definitions and an identification number in a range established by ONC. • The protocol definition file is compiled with the rpcgen command to create a client stub, a server stub, and a header file for use in the client and server application programs. Leon Jololian/George Blank/Jianghui Liu

  19. ONC RPC Data Types • constant • enumeration • structure • union • typedef • program Leon Jololian/George Blank/Jianghui Liu

  20. External Data Representation • What’s XDR? • XDR is independent of any particular platform • Why XDR? Different internal representation of data: • Data size • Opaque (byte stream) • Typed (customized structure) • Byte order (big-endian or little-endian) Leon Jololian/George Blank/Jianghui Liu

  21. Some Basic XDR data elements • Integers • 4bytes, (0,1,2,3, big endian), 2’s compliment • Variable-length opaque data • Length n*(4bytes), data ended by NULL padded • Strings • Length n*(4bytes), data ended by NULL padded • Arrays • Size n*(4bytes), same type of data • Structures • Natural order Leon Jololian/George Blank/Jianghui Liu

  22. Example XDR Encoding Leon Jololian/George Blank/Jianghui Liu

  23. ONC RPC Program Numbers • 0x00000000 to 0x1FFFFFFF Defined by Sun • 0x20000000 to 0x3FFFFFFF User-Defined • 0x40000000 to 0x5FFFFFFF Transient • 0x60000000 to 0xFFFFFFFF Reserved • Sun Microsystems administers the first range, identical for all users, for internal use such as the Portmapper. The second group is assigned by application developers for their programs. The third group is reserved for programs that generate program numbers dynamically. Leon Jololian/George Blank/Jianghui Liu

  24. RPC Port Mapper • ONC Programs do not bind to specific protocol ports like several other technologies. Instead, they use a Portmapper, which dynamically allocates an arbitrary unused protocol port for a connection. An application does need to know what port to use to contact the Portmapper, but that is usually standardized in a company. Leon Jololian/George Blank/Jianghui Liu

  25. Compiling the Protocol Definition rpcgen file.x client stub: file_clnt.c server stub: file_svc.c XDR filters: file_xdr.c header file: file.h Leon Jololian/George Blank/Jianghui Liu

  26. RPC Specification RPC Compiler Shared Filters and Header Files Client Stub Server Skeleton Compile and Link Compile and Link RPC and Data Representation Libraries Client Functions Server Functions Server Executable Client Executable Leon Jololian/George Blank/Jianghui Liu

  27. How RPC Systems Work • When the server starts, it registers itself with the portmapper. It also registers the RPC program numbers, and versions. • Before the client can make an RPC call to the server, it consults the portmapper of the server to identify the port number. • The client and server open a communication path to execute remote procedures. Leon Jololian/George Blank/Jianghui Liu

  28. Server Machine Server Program Client Machine Portmapper 2 1 3 Client Program Leon Jololian/George Blank/Jianghui Liu

  29. Stateful Vs. Stateless Servers • What happens when a server crashes and how will it affect the client? • Stateful servers can be more efficient. • For stateful servers, recovery is more complicated. Leon Jololian/George Blank/Jianghui Liu

  30. RPC Example • This example program will shows you how to use a server program, a client program and an interface definition file to let the client program call the functions in the server program and get the results. • The client will send an integer to server; the server will calculate its square and then send the square value back to the client. Thanks to Jianghui Liu for providing this example. Leon Jololian/George Blank/Jianghui Liu

  31. The .X file for rpcgen RPC Example Leon Jololian/George Blank/Jianghui Liu

  32. RPC Example (.x file) • The Interface Definition file: square.x struct square_in { /* input argument */ long arg1; }; struct square_out { /* output result */ long res1; }; program SQUARE_PROG { version SQUARE_VERS { square_out SQUAREPROC(square_in) = 1; } = 1; } = 0x31234567; Leon Jololian/George Blank/Jianghui Liu

  33. rpcgen output RPC Example Leon Jololian/George Blank/Jianghui Liu

  34. RPC Example (rpcgen output) goode-8 RPC>: rpcgen -N -a square.x goode-9 RPC>: ls -al total 34 drwxr-xr-x 2 gblank 30 2048 Feb 14 09:11 ./ drwxrwxrwx 4 gblank root 2048 Feb 14 09:09 ../ -rw-r--r-- 1 gblank 30 1108 Feb 14 09:11 makefile.square -rw-r--r-- 1 gblank 30 563 Feb 14 09:11 square.h -rw-r--r-- 1 gblank 30 190 Feb 14 09:09 square.x -rw-r--r-- 1 gblank 30 882 Feb 14 09:11 square_client.c -rw-r--r-- 1 gblank 30 648 Feb 14 09:11 square_clnt.c -rw-r--r-- 1 gblank 30 423 Feb 14 09:11 square_server.c -rw-r--r-- 1 gblank 30 4322 Feb 14 09:11 square_svc.c -rw-r--r-- 1 gblank 30 579 Feb 14 09:11 square_xdr.c Leon Jololian/George Blank/Jianghui Liu

  35. XDR File Generated RPC Example Leon Jololian/George Blank/Jianghui Liu

  36. RPC Example (header file-1) #ifndef _SQUARE_H_RPCGEN #define _SQUARE_H_RPCGEN #include <rpc/rpc.h> struct square_in { long arg1; }; typedef struct square_in square_in; struct square_out { long res1; }; Leon Jololian/George Blank/Jianghui Liu

  37. RPC Example (header file-2) typedef struct square_out square_out; #define SQUARE_PROG 0x31234567 #define SQUARE_VERS 1 #define SQUAREPROC 1 extern square_out * squareproc_1(); extern int square_prog_1_freeresult(); /* the xdr functions */ extern bool_t xdr_square_in(); extern bool_t xdr_square_out(); #endif /* !_SQUARE_H_RPCGEN */ Leon Jololian/George Blank/Jianghui Liu

  38. RPC Example (square_xdr.c-1) #include "square.h" bool_t xdr_square_in(xdrs, objp) register XDR *xdrs; square_in *objp; { #if defined(_LP64) || defined(_KERNEL) register int *buf; #else register long *buf; #endif Leon Jololian/George Blank/Jianghui Liu

  39. RPC Example (square_xdr.c-2) if (!xdr_long(xdrs, &objp->arg1)) return (FALSE); return (TRUE); } bool_t xdr_square_out(xdrs, objp) register XDR *xdrs; square_out *objp; { Leon Jololian/George Blank/Jianghui Liu

  40. RPC Example (square_xdr.c-3) #if defined(_LP64) || defined(_KERNEL) register int *buf; #else register long *buf; #endif if (!xdr_long(xdrs, &objp->res1)) return (FALSE); return (TRUE); } Leon Jololian/George Blank/Jianghui Liu

  41. Client Stub File Generated RPC Example (server stub not shown) Leon Jololian/George Blank/Jianghui Liu

  42. RPC Example (square_clnt.c-1) /* * Please do not edit this file. * It was generated using rpcgen. */ #include "square.h" #ifndef _KERNEL #include <stdio.h> #include <stdlib.h> /* getenv, exit */ #endif /* !_KERNEL */ /* Default timeout can be changed using clnt_control() */ static struct timeval TIMEOUT = { 25, 0 }; Leon Jololian/George Blank/Jianghui Liu

  43. RPC Example (square_clnt.c-2) square_out * squareproc_1(arg1, clnt) square_in arg1; CLIENT *clnt; { static square_out clnt_res; memset((char *)&clnt_res, 0, sizeof (clnt_res)); if (clnt_call(clnt, SQUAREPROC, (xdrproc_t) xdr_square_in, (caddr_t) &arg1, (xdrproc_t) xdr_square_out, (caddr_t) &clnt_res, TIMEOUT) != RPC_SUCCESS) { return (NULL); } return (&clnt_res); } Leon Jololian/George Blank/Jianghui Liu

  44. RPC Example (client.c) • rpcgen can generate template code for your client and server programs. An example begins below. (The program on the next page is different.) • /* • * This is sample code generated by rpcgen. • * These are only templates and you can use them • * as a guideline for developing your own functions. • */ • #include "square.h" • #include <stdio.h> • #include <stdlib.h> /* getenv, exit */ Leon Jololian/George Blank/Jianghui Liu

  45. Actual Client RPC Example Code simplified for clarity Leon Jololian/George Blank/Jianghui Liu

  46. RPC Example (continued) • The client file: client.c Leon Jololian/George Blank/Jianghui Liu

  47. Actual Server RPC Example Code simplified for clarity Includes compiler instructions Leon Jololian/George Blank/Jianghui Liu

  48. Example For RPC(continued) • The server file: server.c • To compile and run the example: Leon Jololian/George Blank/Jianghui Liu

  49. Shutting Down the Server • Your server will run until NJIT stops it unless you tell it to stop. • Please be polite and shut it down. The command is rpcinfo –d [program number] [version number] • Show this command on your screen shot for the server. Leon Jololian/George Blank/Jianghui Liu

  50. Hints • Need -lnsl switch on AFS gnu C++ compiler to obtain networking functions • gnu compiler does not recognize // comments, you have to substitute /* */ • RPC uses string for array of char • rpcgen -N -a is needed to generate client and server files as well • If you are mising rpc/rpc.h, include rpc/pmap_prot.h • Types not defined in RPC can be passed inside a struct Leon Jololian/George Blank/Jianghui Liu

More Related