Linux RPC Comer Chapter 21 (RPCgen Concept) RFC 1057 – RPC Spec. UNIX Network Programming - Stevens 1.

Slides:



Advertisements
Similar presentations
DISTRIBUTED OBJECTS AND REMOTE INVOCATION
Advertisements

1 Java Remote Method Invocation java.rmi.* java.rmi.registry.* java.rmi.server.*
CSE 486/586 Distributed Systems Remote Procedure Call
Remote Procedure Call Design issues Implementation RPC programming
Kernighan/Ritchie: Kelley/Pohl:
Remote Procedure Call and Remote Method Invocation
RPC Remote Procedure Call Dave Hollinger Rensselaer Polytechnic Institute Troy, NY.
Tam Vu Remote Procedure Call CISC 879 – Spring 03 Tam Vu March 06, 03.
Remote Procedure CallCS-4513, D-Term Remote Procedure Call CS-4513 Distributed Computing Systems (Slides include materials from Operating System.
CS6223: Distributed Systems Remote Procedure Call (RPC)
INF 123 SW ARCH, DIST SYS & INTEROP LECTURE 8 Prof. Crista Lopes.
CS490T Advanced Tablet Platform Applications Network Programming Evolution.
CSE 124 Networked Services Fall 2009 B. S. Manoj, Ph.D 10/15/20091CSE 124 Networked Services Fall 2009 Some.
Remote Procedure Call Chin-Chih Chang. Remote Procedure Call Remote Procedure Call (RPC) is a protocol that allows programs to call procedures located.
Jan 28, 2003CS475: Internetworking with UNIX TCP/IP1 XDR, RPC, NFS Internetworking with UNIX TCP/IP Winter
Client Server Model The client machine (or the client process) makes the request for some resource or service, and the server machine (the server process)
Practical Issues of RPCCS-4513, D-Term Remote Procedure Call Practical Issues CS-4513 Distributed Computing Systems (Slides include materials from.
Netprog RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol.
© Chinese University, CSE Dept. Distributed Systems / Distributed Systems Topic 4: RPCs vs. CORBA Dr. Michael R. Lyu Computer Science & Engineering.
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
Cs423-cotter1 Example Client Program Reference Comer & Stevens, Chapter 7.
Linux RPC Comer Chapter 21 (RPCgen Concept) RFC 1057 – RPC Spec. UNIX Network Programming - Stevens 1.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Remote Procedure Call Steve Ko Computer Sciences and Engineering University at Buffalo.
1 Chapter Client-Server Interaction. 2 Functionality  Transport layer and layers below  Basic communication  Reliability  Application layer.
Remote Procedure CallCS-502 Fall Remote Procedure Call CS-502, Operating Systems Fall 2007 (Slides include materials from Operating System Concepts,
Cli/Serv.: rpc/101 Client/Server Distributed Systems v Objectives –look at how to program with SunOS RPCs –use XDR and rpcgen –briefly look at.
CSE 486/586 CSE 486/586 Distributed Systems Remote Procedure Call Steve Ko Computer Sciences and Engineering University at Buffalo.
By Sidhant Garg.  C was developed between by Dennis Ritchie at Bell Laboratories for use with the Unix Operating System.  Unlike previously.
Remote Procedure Call Andrew Whitaker CSE451. Remote Procedure Call RPC exposes a programming interface across machines: interface PriceService { Price.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Introduction to Distributed Systems Slides for CSCI 3171 Lectures E. W. Grundke.
Sun RPC also called ONC (Open Network Computing) RPC originally designed for client-server communication for Sun Network File System (NFS) provides an.
Chapter 4: Interprocess Communication‏ Pages
1 XDR External Data Representation Process A XDR Encode/Decode Transport Process B XDR Encode/Decode Transport.
CSE Computer Networks Prof. Aaron Striegel Department of Computer Science & Engineering University of Notre Dame Lecture 14 – February 23, 2010.
CSE 451: Operating Systems Winter 2015 Module 22 Remote Procedure Call (RPC) Mark Zbikowski Allen Center 476 © 2013 Gribble, Lazowska,
Page 1 Remote Procedure Calls Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content of this presentation.
Netprog: RPC Programming1 RPC Programming with rpcgen Issues: –Protocol Definition File –Client Programming Creating an "RPC Handle" to a server Calling.
Netprog: RPC Programming1 RPC Programming with rpcgen Issues: –Protocol Definition File –Client Programming Creating an "RPC Handle" to a server Calling.
Distributed Processing Systems (InterProcess Communication) (Remote Procedure Call) Distributed Processing Systems (InterProcess Communication) (Remote.
B. Prabhakaran 1 RPC Execution Local call Return Query binding server Params packing Wait Unpack result Unpack Local call Pack results Execute procedure.
Remote Procedure Calls CS587x Lecture Department of Computer Science Iowa State University.
Remote Procedure CallCS-502 Fall Remote Procedure Call (continued) CS-502, Operating Systems Fall 2007 (Slides include materials from Operating System.
1 Java Remote Method Invocation java.rmi.* java.rmi.registry.* java.rmi.server.*
Remote Procedure Call RPC
Cs423-cotter1 Windows Operating Environment. cs423-cotter2 Windows Operating Environment 32 bit operating environment – Windows XP Microsoft Visual Studio.net,.net2005,
Computer Science Lecture 3, page 1 CS677: Distributed OS Last Class: Communication in Distributed Systems Structured or unstructured? Addressing? Blocking/non-blocking?
DISTRIBUTED OBJECTS AND REMOTE INVOCATION 1. 2 Topics  Middleware  Remote Method Invocation  Remote Procedure Call.
Remote Procedure Call (Introduction)
1 Remote Procedure Calls External Data Representation (Ch 19) RPC Concept (Ch 20)
RPC Part 3 More Linux RPC. Add RPC program Objectives: Pass multiple arguments from calling program to remote procedure Support multiple procedures within.
© Oxford University Press 2011 DISTRIBUTED COMPUTING Sunita Mahajan Sunita Mahajan, Principal, Institute of Computer Science, MET League of Colleges, Mumbai.
Chapter 7 Process Environment Chien-Chung Shen CIS/UD
A bit of C programming Lecture 3 Uli Raich.
CSE 486/586 Distributed Systems Remote Procedure Call
Multithreading SUN RPC is by default single threaded, it provides an iterative server rpcgen takes two options –M and –A M makes the server code thread.
Adv. Network Programming RPC (Remote Procedure Call)
DISTRIBUTED COMPUTING
פרטים נוספים בסילבוס של הקורס
Lecture 4: RPC Remote Procedure Call Coulouris et al: Chapter 5
Lecture 4: RPC Remote Procedure Call CDK: Chapter 5
Distributed Program Design
XDR External Data Representation
Distributed Computing
CSE 451: Operating Systems Spring 2012 Module 22 Remote Procedure Call (RPC) Ed Lazowska Allen Center
CS-502, Operating Systems Fall 2009 (EMC)
UNIX Network Programming - Stevens
Chapter 3 Socket API © Bobby Hoggard, Department of Computer Science, East Carolina University These slides may not be used or duplicated without permission.
Remote invocation (call)
Last Class: Communication in Distributed Systems
Presentation transcript:

Linux RPC Comer Chapter 21 (RPCgen Concept) RFC 1057 – RPC Spec. UNIX Network Programming - Stevens 1

Sockets API Limitations Must explicitly account for differences in systems – Byte order (big-endian / little-endian) Limited to sending characters (without tricking the system) – requires source and destination to implicitly understand the data transformation. 2

Client / Server Between Systems One 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). 3

XDR Data Types int32 bits unsigned int32 bits bool32 bits enum arbitrary hyper64 bits unsigned hyper64 bits float32 bits double64 bits opaque arbitrary String arbitrary fixed array arbitrary counted array arbitrary structure arbitrary discriminated union arbitrary. void0 symbolic constant arbitrary optional data arbitrary 4

XDR Data Conversion Objective: – Gather all parameter data into a buffer in XDR format Procedure: – Create a buffer (xdrmem_create) 5

XDR Data Conversion Objective: – Gather all parameter data into a buffer in XDR format Procedure: – Create a buffer (xdrmem_create) 6 #include #define BUFSIZE XDR * xdrs; char buf[BUFSIZE]; xdrmen_create(xdrs, buf, BUFSIZE, XDR_ENCODE);

XDR Data Conversion Routines 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 ( ); 7

XDR Data Conversion – Add data items in order to the buffer (after converting to XDR format) 8 int myInt;... myInt = 260; xdr_int(xdrs, &myInt);

RPC Programming Mechanisms ONC (Open Network Computing) XDR library routines for data conversion XDR library routines for complex data structures RPC run-time library routines Program generator tool 9

RPC Programming Process Dividing the program into local and remote procedures. 10 Proc A Client Stub Server Stub Proc B RPC

RPC Dispatching (Procedure Location) 11 Proc A1 Client Stub Server Stub Proc B1 Proc A2 Client Stub Proc B2 Server Stub Dispatcher RPC

RPC Interface Specification 12 Proc A Client comm Server Iface Proc B Server Comm Client Iface RPC

RPCgen Input and Output Input – Q.x Interface specification file Output – Q.hDeclarations header file – Q_xdr.cppXDR procedure calls used to marshal arguments – Q_clnt.cppClient-side communications stub – Q_svc.cppServer-side communications stub 13

RPC Process Flow 14 Q.x rpcgen Q_clnt.cpp Q.h Q_xdr.cpp Q_svc.cpp Client application Client interface Server interface Remote procedures Server Client compile

RPC General Build Procedure 15 Develop Interface Develop ClientDevelop Server

Developing the Interface 16 MyApp.x RPCgen MyApp_clnt.c Client Stub MyApp_svc.c Server Stub MyApp.h MyApp_xdr.c

Developing the Server 17 MyApp.x RPCgen MyApp_svc.c Server Stub MyApp.h MySrvr.cMyApp_xdr.c C Compiler Linker MySrvr.exe

Developing the Client 18 MyApp.x RPCgen MyApp_clnt.c Client Stub MyApp.h MyClnt.c C Compiler Linker MyClnt.exe MyApp_xdr.c

How the Server Prepares for a Connection (Be certain that Portmap is running) Create UDP service Register UDP service with Portmap Create TCP service Register TCP service with Portmap Run service... – Uses select( ) to monitor ports. 19

Start Portmap Portmap is included in all Linux distributions as a standard server. Under Red Hat / Fedora Open services applet, select portmap and start From command line (as root) /sbin/service portmap start Other distributions should be similar 20

Server concurrency mode RPC servers can be created in either single threaded or multi-threaded mode. Servers automatically create and (when done) destroy a thread for each incoming connection. 21

Register the Server Program svc_register(port#, SERV#, VER#, serv_func, proto#); port#: port on which the service is active SERV#: unique number for the service VER#: version for this particular service serv_func: name by which this function is called proto#: IPPROTO_UDP or IPPROTO_TCP 22

How the Client Establishes a Connection Make a Remote Procedure Call Find the Server Host Computer Find Server Process Port # (through Portmap) Create a (connection) to the Server Process 23

How the Client Establishes a Connection clnt_create(server, SERV#, VER#, proto#); remote procedure call... Clnt_destroy(CLIENT); 24

Example #1 Temperature Server (Fahrenheit to Centigrade) – Parameters passed as integers – TCP / IP port connection Source files: – temp.x – Tclient.c – tempServer.c 25

temp.x program TEMPSERV { version TEMPVERS { int TempConv(int) = 1; //procedure number } = 1; //version number } = 77; //program number 26

TClient.c #include,, #include #include "temp.h" #define YES 0 #define NO 1 void main (int argc, char *argv[]) { int tempconvert(int temp, char *srvr); int temperature, nuTemp; int loopFlag; char srvr[25]; CLIENT * cl; 27

TClient.c (cont) strcpy (srvr, argv[1]); cl = clnt_create(srvr, TEMPSERV, TEMPVERS, "tcp"); loopFlag = YES; while(loopFlag == YES) { printf("Enter temperature in Faherenheit (-999 to quit)"); scanf ("%d", &temperature); ans = tempconv_1(&temperature, cl); 28

TClient.c (cont) if (ans != NULL) nuTemp = * ans; if (temperature == -999 || temperature == -9999) { loopFlag = NO; printf ("Goodbye...\n"); continue; } printf("That’s %2d in centigrade\n", nuTemp); } clnt_destroy(cl); return 0; } 29

tempServer.c #include,, #include, "temp.h" static int count; static int nuTemp; int *tempconv_1_svc (int *val, struct svc_req * rqst) { int oldTemp; oldTemp = *val; 30

tempServer.c if (oldTemp == -9999) { printf("We're shutting down...\n"); exit (0); } printf("We got a temperature of %d, ", oldTemp); count++; nuTemp = (int)((5*(oldTemp -32)) / 9.0); printf("and we returned a value of %d\n", nuTemp); sleep(1); return (&nuTemp); } 31

Files created with rpcgen Input: – temp.x Output – temp.h – temp_xdr.c (NULL file) – temp_clnt.c – temp_svc.c 32

temp.h #include #ifdef __cplusplus extern "C" { #endif #define TEMPSERV 77 #define TEMPVERS 1 #if defined(__STDC__) || defined(__cplusplus) #define TempConv 1 extern int * tempconv_1(int *, CLIENT *); extern int * tempconv_1_svc(int *, struct svc_req *); extern int tempserv_1_freeresult (SVCXPRT *, xdrproc_t, caddr_t); #ifdef __cplusplus} #endif #endif /* !_TEMP_H_RPCGEN */ 33

temp_xdr.c #include #include "temp.h" 34

temp_clnt.c #include /* for memset */ #include "temp.h“ /* Default timeout can be changed using clnt_control() */ static struct timeval TIMEOUT = { 25, 0 }; int *tempconv_1(int *argp, CLIENT *clnt){ static int clnt_res; memset((char *)&clnt_res, 0, sizeof(clnt_res )); 35

temp_clnt.c (cont) if (clnt_call (clnt, TempConv, (xdrproc_t) xdr_int, (caddr_t) argp,(xdrproc_t) xdr_int, (caddr_t) &clnt_res,TIMEOUT) != RPC_SUCCESS) { return (NULL); } return (&clnt_res);} 36

temp_svc.c #include "temp.h“ #include #ifndef SIG_PF #define SIG_PF void(*)(int) #endif 37

temp_svc.c (cont) static void tempserv_1(struct svc_req *rqstp, register SVCXPRT *transp){ union { int tempconv_1_arg; } argument; char *result; xdrproc_t _xdr_argument, _xdr_result; char *(*local)(char *, struct svc_req *); switch (rqstp->rq_proc) { case NULLPROC: (void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL); return; case TempConv: _xdr_argument = (xdrproc_t) xdr_int; _xdr_result = (xdrproc_t) xdr_int; local = (char *(*)(char *, struct svc_req *)) tempconv_1_svc; break; default: svcerr_noproc (transp); return;} 38

temp_svc.c (cont) memset ((char *)&argument, 0, sizeof (argument)); if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) { svcerr_decode (transp); return; } result = (*local)((char *)&argument, rqstp); if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) { svcerr_systemerr (transp); } if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) { fprintf (stderr, "%s", "unable to free arguments"); exit (1); } return; } 39

temp_svc.c (cont) int main (int argc, char **argv){ register SVCXPRT *transp; pmap_unset (TEMPSERV, TEMPVERS); transp = svcudp_create(RPC_ANYSOCK); if (transp == NULL) { fprintf (stderr, "%s", "can’t create udp service.");exit(1); } if (!svc_register(transp, TEMPSERV, TEMPVERS, tempserv_1, IPPROTO_UDP)) { fprintf (stderr, "%s", "unable to register (TEMPSERV, TEMPVERS, udp)."); exit(1); } 40

temp_svc.c (cont) transp = svctcp_create(RPC_ANYSOCK, 0, 0); if (transp == NULL) { fprintf (stderr, "%s", "cannot create tcp service."); exit(1); } if (!svc_register(transp, TEMPSERV, TEMPVERS, tempserv_1, IPPROTO_TCP)) { fprintf (stderr, "%s", "unable to register (TEMPSERV, TEMPVERS, tcp)."); exit(1); } svc_run (); fprintf (stderr, "%s", "svc_run returned"); exit (1);/* NOTREACHED */} 41

Sample Client Output D:\data\RPC\onrpc_temp\client\Debug>client localhost Enter the temperature in Faherenheit (-999 to quit)32 That would be 0 in centigrade Enter the temperature in Faherenheit (-999 to quit)100 That would be 37 in centigrade Enter the temperature in Faherenheit (-999 to quit)212 That would be 100 in centigrade Enter the temperature in Faherenheit (-999 to quit)-9999 Goodbye... D:\data\RPC\onrpc_temp\client\Debug> 42

Sample Server Output D:\data\RPC\examples\onrpc_temp\server\Debug>server We got a temperature of 32, and we returned a value of 0 We got a temperature of 100, and we returned a value of 37 We got a temperature of 212, and we returned a value of 100 We're shutting down... D:\data\RPC\examples\onrpc_temp\server\Debug> 43

Summary Linux RPC Implementation models SUN ONCRPC functionality RPC specific programming limited to linking original applications code with rpcgen interface code. 44