Lecture 12 RPC RPC RPC. Writing an RPC Program. Sun RPC RPC. February 9+11, 2005

Similar documents
Remote Procedure Call

CSC 634: Networks Programming

RPC Paradigm. Lenuta Alboaie Andrei Panu

RPC Programming. Some knowledge of C & Unix A network with at least two connected machines.

Remote Procedure Calls (RPC)

Process Concept: views of a process Process Scheduling CSCI 6730/ 4730 Operating Systems

Chapter 3: Processes: Outline. Operating Systems. Remote Procedure Calls (RPC) Client-Server Remote Machine Communication Mechanisms

Distributed Program Design Typical Sockets Approach. Remote Procedure Call. Remote Subroutine

Last Class: RPCs. Today:

Desarrollo de Aplicaciones en Red. El modelo de comunicación. General concepts. Models of communication. Message Passing

Sun Remote Procedure Call Mechanism

Inter-process Communication: RPC

Remote Procedure Call Implementations

Distributed Systems 8. Remote Procedure Calls

Distributed Systems. How do regular procedure calls work in programming languages? Problems with sockets RPC. Regular procedure calls

RPC is a call to a procedure/function located on another machine

Remote Procedure Calls, TLI, STREAMS

C 1. Recap: Finger Table. CSE 486/586 Distributed Systems Remote Procedure Call. Chord: Node Joins and Leaves. Recall? Socket API

Operating Systems. 18. Remote Procedure Calls. Paul Krzyzanowski. Rutgers University. Spring /20/ Paul Krzyzanowski

External Data Representation (XDR)

CHAPTER - 4 REMOTE COMMUNICATION

Chapter 3: Client-Server Paradigm and Middleware

Today CSCI Communication. Communication in Distributed Systems. Communication in Distributed Systems. Remote Procedure Calls (RPC)

Remote Procedure Calls CS 707

Networking Operating Systems (CO32010)

Remote Procedure Call (RPC) and Transparency

XDR External Data Representation. XDR as a case study XDR

Distributed Objects and Remote Invocation. Programming Models for Distributed Applications

Lecture 8: February 17

MODELS OF DISTRIBUTED SYSTEMS

MODELS OF DISTRIBUTED SYSTEMS

NFS Design Goals. Network File System - NFS

Remote Procedure Call Part 2

COMMUNICATION IN DISTRIBUTED SYSTEMS

Remote Procedure Call

03 Remote invocation. Request-reply RPC. Coulouris 5 Birrel_Nelson_84.pdf RMI

System Models and Communication

6 Remote Procedure Call (RPC)

Distributed-Memory Programming Models IV

Message Passing vs. Distributed Objects. 5/15/2009 Distributed Computing, M. L. Liu 1

CS454/654 Midterm Exam Fall 2004

Lecture 5: Object Interaction: RMI and RPC

CSci Introduction to Distributed Systems. Communication: RPC

Internet Systems Programming

Distributed Systems. 03. Remote Procedure Calls. Paul Krzyzanowski. Rutgers University. Fall 2017

CS 417 9/18/17. Paul Krzyzanowski 1. Socket-based communication. Distributed Systems 03. Remote Procedure Calls. Sample SMTP Interaction


RPC flow. 4.3 Remote procedure calls IDL. RPC components. Procedure. Program. sum (j,k) int j,k; {return j+k;} i = sum (3,7); Local procedure call

Networks and Operating Systems Chapter 3: Remote Procedure Call (RPC)

APPLICATION BULLETIN ICS ICS. ELECTRONICS division of Systems West Inc. VXI-11 RPC Programming Guide for the 8065 AB80-3

The UNIVERSITY of EDINBURGH. SCHOOL of INFORMATICS. CS4/MSc. Distributed Systems. Björn Franke. Room 2414

Distributed Systems Principles and Paradigms. Distributed Object-Based Systems. Remote distributed objects. Remote distributed objects

Programming Using Sun TI-RPC to develop distributed applications

Chapter 5 Distributed Objects and Remote Invocation

RPC and RMI. 2501ICT Nathan

416 Distributed Systems. RPC Day 2 Jan 11, 2017

VXI-11 and HP E2050A

The RPC abstraction. Procedure calls well-understood mechanism. - Transfer control and data on single computer

RMI: Design & Implementation

03 Remote invoaction. Request-reply RPC. Coulouris 5 Birrel_Nelson_84.pdf RMI

Remote Invocation. To do. Request-reply, RPC, RMI. q Today q. q Next time: Indirect communication

Distributed Systems Theory 4. Remote Procedure Call. October 17, 2008

COS 318: Operating Systems. Message Passing. Kai Li and Andy Bavier Computer Science Department Princeton University

University of Pittsburgh Computer Science Department

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

Lecture 8: February 19

Remote Invocation. Today. Next time. l Overlay networks and P2P. l Request-reply, RPC, RMI

Configuring Inspection of Database and Directory Protocols

416 Distributed Systems. RPC Day 2 Jan 12, 2018

Remote Procedure Call

Chapter 4: Processes

Rx: Extended Remote Procedure Call

Project 2: Part 1: RPC and Locks

What s an API? Do we need standardization?

CSCI-1680 RPC and Data Representation John Jannotti

Distributed Systems Lecture 2 1. External Data Representation and Marshalling (Sec. 4.3) Request reply protocol (failure modes) (Sec. 4.

7 Distributed File Systems

Middleware. Adapted from Alonso, Casati, Kuno, Machiraju Web Services Springer 2004

REMOTE PROCEDURE CALLS EE324

IBD Intergiciels et Bases de Données

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 14

A Report on RMI and RPC Submitted by Sudharshan Reddy B

Programming in C. Pointers and Arrays

Communication in Distributed Systems Programming

Remote Invocation Vladimir Vlassov and Johan Montelius

CSE 660 Lab 2 Khoi Pham Thanh Ho April 27 th, 2015

Operating Systems and Networks Project 1: Reliable Transport

Remote Procedure Calls

Communication. Distributed Systems Santa Clara University 2016

Chapter 5: Remote Invocation. Copyright 2015 Prof. Amr El-Kadi

CSCE 455/855 Distributed Operating Systems

Outlook. Process Concept Process Scheduling Operations on Processes. IPC Examples

An Experience Like No Other. Stack Discipline Aug. 30, 2006

Outline. Interprocess Communication. Interprocess Communication. Communication Models: Message Passing and shared Memory.

Overview. Exercise 0: Implementing a Client. Setup and Preparation

Remote Invocation. Today. Next time. l Indirect communication. l Request-reply, RPC, RMI

Part Two - Process Management. Chapter 3: Processes

Programming refresher and intro to C programming

unsigned char memory[] STACK ¼ 0x xC of address space globals function KERNEL code local variables

xkcd.com End To End Protocols End to End Protocols This section is about Process to Process communications.

Transcription:

RPC Lecture 12 RPC February 9+11, 2005 Remote Procedure Call Follows application-oriented approach (emphasizes problem over communication) Design program and then divide it. RPC RPC There exists a way for processes to represent a task: procedure/function. main() stub(12); return 5; stub main() main() Request skeleton Reply func(12); return 5; func(12); return 5; func() func() func(12); return 5; func() Sun RPC Writing an RPC Program Widely used Remote Procedure Call system: client.c client.o Sun Microsystems, implemented in most Unix systems add_clnt.c add_clnt.o client NFS distributed file system is based on Sun RPC add.h Designed to call remote C procedures. Platform-independent. add.x add_xdr.c add_scv.c add_xdr.o add_svc.o server serverproc.c You write these files rpcgen generates these files serverproc.o You compile every C file You obtain a client & server 1

Terminology One computer can be server for multiple procedures: server may host several programs (identified by program number) each program may have several subsequent versions (version number) each version may contain one or more procedures (procedure number) Program numbers are 32-bit hexadecimal values (0x21212100) As user, you can choose any program number between 0x20000000 and 0x3FFFFFFF, but they have to be unique (not several programs with same number on same machine) Version and procedure numbers are integers (1,2,...) (prog, vers, proc) Sun RPC Program Numbers FROM TO VALUES ASSIGNED BY 0x00000000 0x1fffffff Sun Microsystems, Inc. 0x20000000 0x3fffffff System manager at a user s site 0x40000000 0x5fffffff Transient (temporary) 0x60000000 0x7fffffff Reserved 0x80000000 0x9fffffff Reserved 0xa0000000 0xbfffffff Reserved 0xc0000000 0xdfffffff Reserved 0xe0000000 0xffffffff Reserved Sun RPC Program Numbers NAME NUMBER DESCRIPTION portmap 100000 port mapper rstatd 100001 rstat, rup, perfmeter rusersd 100002 remote users nfs 100003 network file system ypserv 100004 yp (NIS) mountd 100005 mount, showmount dbxd 100006 DMXprog (debugger) ypbind 100007 NIS binder... Version Number (prog, vers, proc) Allows to change details of a program without obtaining a new program number. You can test a new version of a program while the old one still operates. Step 1: Write a specification file (add.x) struct add_in { /* Arguments of procedure */ long arg1; long arg2; ; typedef long add_out; /* Return value */ program ADD_PROG { version ADD_VERS { add_out ADD_PROC(add_in) = 1 /* Procedure# = 1 */ = 1; /* Version# = 1 */ = 0x3434000; /* Program# = 0x3434000 */ Contains specifications of: add_in (arguments) typedef add_out (return values) program ADD_PROG (0x3434000) 1 version ADD_VERS (1) 1 procedure ADD_PROC (1) Your procedures can only take ONE input argument and return ONE output return value (use structures for more): more readable (structure entries should have meaningful names) 2

Step 2: generate stubs rpcgen add.x add.h contains declarations: #define ADD_PROG 0x34340000 /* Program nb */ #define ADD_VERS 1 /* Version nb */ #define ADD_PROC 1 /* Procedure nb */ add_out * add_proc_1 (add_in *, CLIENT *); add_out * add_proc_1_svc (add_in *, struct svc_req *); add_proc_1 is the stub (called by client) add_proc_1_svc is the actual procedure that you will write and run at the server add_clnt.c : implementation of add_proc_1 add_svc.c : contains program which calls your procedure add_proc_1_svc when request received add_xdr.c : marshall/unmarshall routines Step 3: write server procedure: serverproc.c #include add.h add_out *add_proc_1_svc(add_in *in, struct svc_req *rqstp) { static add_out out; out = in->arg1 + in->arg2; return(&out); rqstp contains some information about the requester (IP address, etc.) Step 4: compile the server Need to compile together your procedure, the (generated) server program, the (generated) marshall/unmarshall procedures and the nsl library (contains the RPC runtime). $ gcc -c serverproc.c $ gcc -c add_svc.c $ gcc -c add_xdr.c $ gcc -o server serverproc.o add_svc.o add_xdr.o -lnsl To start the server:./server Step 5: write a client program client.c #include add.h int main(int argc, char **argv) { CLIENT *cl; add_in in; add_out *out; if (argc!=4) {printf( Usage:...\n ); return 1; cl = clnt_create(argv[1], ADD_PROG, ADD_VERS, tcp ); in.arg1 = atol(argv[2]); in.arg2 = atol(argv[3]); out = add_proc_1(&in, cl); if (out == NULL) {printf( Error: %s\n, clnt_sperror(cl, argv[1])); else { printf{ We received the result: %ld\n, * out); clnt_destroy(cl); return 0; Create a client structure with clnt_create #include <rpc/rpc.h> CLIENT *clnt_create(char *host, u_long prog, u_long vers, char *proto); host: name of server machine prog, vers: program/version number proto: transport protocol ( tcp or udp ) You can call add_proc_1 to send the RPC When finished, destroy client structure (client structure can be used multiple times without being destroyed and recreated). 3

Step 6: compile the client $ gcc -c client.c $ gcc -c add_clnt.c $ gcc -c add_xdr.c $ gcc -o client client.o add_clnt.o add_xdr.o -lnsl Step 7: try it out start your server:./server send a request:./client machine.cse.nd.edu 8 34 We received the result: 42 Mutual Exclusion Inside Sun RPC Sun RPC: at most one remote procedure in a remote program can be invoked at a given time. Automatic mutual exclusion among procedures within a given remote program. No synchronization needed. Some versions of rpcgen allow one to generate server code which implement one-thread-per-client (Solaris does, Linux doesn t). (un)marshalling routines client program client stub RPC runtime server procedure server stub RPC runtime (un)marshalling routines Low-Level RPC: Port Mapper Did you notice that we did not specify a port number for our add server? Could be done with well-known port number for RPCs But then we could not run multiple servers in the same machine simultaneously RPC: port mapper server running on port 111 when your server starts, it does not bind its socket to a specific port; instead it registers whatever port number it has been given by the system to the local port mapper when you create a client with clnt_create, you automatically contact the remote port mapper to ask for the port number of the server you want to contact Low-Level RPC: Port Mapper S5: Run procedure 1 with parameter: 0x18A6B332F0 S6: Result is 0x6464 S4: Portmap response: port 11293 S3: Portmap requested: on which port is program 0x3434000 version 1? Port mapper You can request the port mapper by hand: $ rpcinfo -p wizard.cse.nd.edu program vers proto port 100000 2 tcp 111 portmapper 100000 2 udp 111 portmapper 66443998 1 udp 32877 66443938 1 tcp 54211 S1: Create an unbound socket (assigned port=11293) S2: Register: program 0x3434000 version 1 running on port 11293 4

Low-Level RPC: Protocol Low-Level RPC: Transport Issues RPC runtime does not know anything about procedure names or prototypes. It manages requests containing: host name program number version number procedure number buffer with arguments Its response contains: buffer with return values RPC runtime does not know what procedures are doing or which kinds of arguments they take it only ships buffers RPC invocations can be with either TCP or UDP: UDP is lighter/faster what if message is lost? after timeout client system will resend (autom.) what if reply message got lost? server has been invoked twice RPC uses at-least-once semantics if you use UDP, your server must be idempotent otherwise use TCP Low-Level RPC: Transport Issues RPC has a simple retransmission mechanism: 1. send 2. start timer 3. wait for response 4. if timer expires: if retry limit reached stop, otherwise go back to step 1 Message Format Request: IP header UDP/TCP header transaction ID (XID) 4 call ID (0) 4 RPC version (2) 4 program number 4 version number 4 procedure number 4 credentials 8+<=400 verifier <=408 (secure RPC) parameters Message Format Response: XID of request 4 reply (1) 4 status (0=accepted) 4 verifier <=408 accept status (0=accepted) 4 procedure results Intermediate-Level RPC: (Un)Marshalling Parameters Parameters must be converted from variables into buffers (and vice-versa): lowest level only knows about buffers (containing parameters) user programs only know about parameters (C variables) the XDR layer (external data representations) is in charge of conversion XDR buffer representations must be architectureindependent e.g., to avoid problems when little-endian client sends requests to big-endian server... 5

Intermediate-Level RPC: (Un)Marshalling Parameters XDR library contains basic encoding/decoding functions : to (un)marshall an integer #include <rpc/xdr.h> bool_t xdr_int(xdr *xdrs, int *ip); xdrs: contains file descriptor of the socket where to read/write the buffers also contains a flag to indicate whether xdr_int must encode or decode the buffer Encode: convert *ip into a message buffer and write it to the socket Decode: read a message buffer from the socket and convert it to *ip Intermediate-Level RPC: (Un)Marshalling Parameters rpcgen generates functions to (un)marshall the input and output parameters of your RPC procedures: #include add.h bool_t xdr_add_in(xdr *xdrs, add_in *objp) { /* to convert add_in */ if (!xdr_long(xdrs, &objp->arg1)) return FALSE; if (!xdr_long(xdrs, &objp->arg2)) return FALSE; return TRUE; bool_t xdr_add_out(xdr *xdrs, add_out *objp) { /* to convert add_out */ if (!xdr_long(xdrs, objp)) return FALSE; return TRUE; High-Level RPC: Stub stub is in charge of providing a simple interface to client programs: calls XDR functions to marshall the parameters and unmarshall the return values ships them to the low-level RPC layers to be transferred to the server add_out *add_proc_1(add_in *argp, CLIENT *clnt) { static add_out clnt_res; memset((char *)&clnt_res, 0, sizeof(clnt_res)); if (clnt_call(clnt, ADD_PROC, (xdrproc_t) xdr_add_in, (caddr_t) argp, (xdrproc_t) xdr_add_out, (caddr_t) &clnt_res, TIMEOUT)!= RPC_SUCCESS) { return (NULL); return (&clnt_res); High-Level RPC: Stub stub: defines a function to reply to any request directed at it (same prog/vers number, any proc number) checks the procedure number calls appropriate function to unmarshall parameters calls user procedure marshalls the return values creates UDP/TCP server sockets and registers them to port mapper registers function (above) to RPC system: program/version numbers socket descriptors procedure to serve incoming requests waits for RPC requests Summary RPC relates client-server communication to conventional procedure calls. Each server implements one or more procedures, each procedure accepts parameters and returns one or more results. De facto standard: Sun RPC Components: stubs, skeletons, RPC runtime, port mapper, rpcgen RPC uses XDR (external data representation) for communication. 6