netprog 2001 - rpc overview1 distributed program design n communication-oriented design –design...

35
Netprog 2001 - RPC Over view 1 Distributed Program Distributed Program Design Design Communication-Oriented Design Communication-Oriented Design Design protocol first. Design protocol first. Build programs that adhere to the Build programs that adhere to the protocol. protocol. Application-Oriented Design Application-Oriented Design Build application(s). Build application(s). Divide programs up and add Divide programs up and add communication protocols. communication protocols. Typical Typical Sockets Sockets App roach App roach RPC RPC

Upload: lee-rogers

Post on 21-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 1

Distributed Program DesignDistributed Program Design

Communication-Oriented DesignCommunication-Oriented Design– Design protocol first. Design protocol first. – Build programs that adhere to the protocol.Build programs that adhere to the protocol.

Application-Oriented DesignApplication-Oriented Design– Build application(s).Build application(s).– Divide programs up and add Divide programs up and add

communication protocols.communication protocols.

Typical Typical

SocketsSockets

Approach

Approach

RPCRPC

Page 2: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 2

RPCRPCRemote Procedure CallRemote Procedure Call

Call a procedure (subroutine) that is Call a procedure (subroutine) that is running on another machine.running on another machine.

Issues:Issues:– identifying and accessing the remote identifying and accessing the remote

procedureprocedure– parametersparameters– return valuereturn value

Page 3: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 3

blah, blah, blah

bar = foo(a,b);

blah, blah, blah

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);}

int foo(int x, int y ) { if (x>100)

return(y-2); else if (x>10)

return(y-x); else

return(x+y);}

ClientClient

ServerServer

protocol

Remote SubroutineRemote Subroutine

Page 4: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 4

Sun RPCSun RPC

There are a number of popular RPC There are a number of popular RPC specifications.specifications.

Sun RPC (ONC RPC) is widely used.Sun RPC (ONC RPC) is widely used. NFS (Network File System) is RPC NFS (Network File System) is RPC

based.based. Rich set of support tools.Rich set of support tools.

Page 5: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 5

Sun RPC OrganizationSun RPC Organization

Procedure 1Procedure 1 Procedure 2Procedure 2 Procedure 3Procedure 3

Shared Global DataShared Global Data

Remote ProgramRemote Program

Page 6: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 6

Procedure ArgumentsProcedure Arguments To reduce the complexity of the interface To reduce the complexity of the interface

specification, Sun RPC includes support specification, Sun RPC includes support for a single argument to a remote for a single argument to a remote procedure.*procedure.*

Typically the single argument is a Typically the single argument is a structure that contains a number of structure that contains a number of values.values.

* * Newer versions can handle multiple args.Newer versions can handle multiple args.

Page 7: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 7

Procedure IdentificationProcedure Identification

Each procedure is identified by:Each procedure is identified by:– Hostname (IP Address)Hostname (IP Address)– Program identifier (32 bit integer)Program identifier (32 bit integer)– Procedure identifier (32 bit integer)Procedure identifier (32 bit integer)

Page 8: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 8

Procedure IdentificationProcedure Identification

Each procedure is identified by:Each procedure is identified by:– Hostname (IP Address)Hostname (IP Address)– Program identifier (32 bit integer)Program identifier (32 bit integer)– Procedure identifier (32 bit integer)Procedure identifier (32 bit integer)

– Program Version identifierProgram Version identifier» for testing and migration.for testing and migration.

Page 9: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 9

Program IdentifiersProgram Identifiers

Each remote program has a unique ID.Each remote program has a unique ID. Sun divided up the IDs:Sun divided up the IDs:

0x00000000 - 0x1fffffff0x00000000 - 0x1fffffff

0x20000000 - 0x3fffffff0x20000000 - 0x3fffffff

0x40000000 - 0x5fffffff0x40000000 - 0x5fffffff

0x60000000 - 0xffffffff0x60000000 - 0xffffffff

SunSun

SysAdmin SysAdmin

TransientTransient

ReservedReserved

Page 10: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 10

Procedure Identifiers &Procedure Identifiers &Program Version NumbersProgram Version Numbers

Procedure Identifiers usually start at 1 Procedure Identifiers usually start at 1 and are numbered sequentiallyand are numbered sequentially

Version Numbers typically start at 1 and Version Numbers typically start at 1 and are numbered sequentially.are numbered sequentially.

Page 11: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 11

Iterative ServerIterative Server

Sun RPC specifies that at Sun RPC specifies that at mostmost one one remote procedure within a program can remote procedure within a program can be invoked at any given time.be invoked at any given time.

If a 2nd procedure is called, the call If a 2nd procedure is called, the call blocks until the 1st procedure has blocks until the 1st procedure has completed.completed.

Page 12: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 12

Iterative can be goodIterative can be good

Having an iterative server is useful for Having an iterative server is useful for applications that may share data among applications that may share data among procedures.procedures.

Example: database - to avoid Example: database - to avoid insert/delete/modify collisions.insert/delete/modify collisions.

We can provide concurrency when We can provide concurrency when necessary...necessary...

Page 13: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 13

Call SemanticsCall Semantics

What does it mean to call a local What does it mean to call a local procedure?procedure?– the procedure is run exactly one time.the procedure is run exactly one time.

What does it mean to call a remote What does it mean to call a remote procedure?procedure?– It might not mean "run exactly once"!It might not mean "run exactly once"!

Page 14: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 14

Remote Call SemanticsRemote Call Semantics

To act like a local procedure (exactly To act like a local procedure (exactly one invocation per call) - a reliable one invocation per call) - a reliable transport (TCP) is necessary.transport (TCP) is necessary.

Sun RPC does not support reliable call Sun RPC does not support reliable call semantics. !semantics. !

At Least Once SemanticsAt Least Once Semantics Zero or More SemanticsZero or More Semantics

Page 15: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 15

Sun RPC Call SemanticsSun RPC Call Semantics

At Least Once SemanticsAt Least Once Semantics– if we get a response (a return value)if we get a response (a return value)

Zero or More SemanticsZero or More Semantics– if we don't hear back from the remote if we don't hear back from the remote

subroutine.subroutine.

Page 16: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 16

Remote Procedure deposit()Remote Procedure deposit()

deposit(DavesAccount,$100)deposit(DavesAccount,$100)

Always remember that you don't Always remember that you don't knowknow how many times the remote procedure how many times the remote procedure was run!was run!– The net can duplicate the request (UDP).The net can duplicate the request (UDP).

Page 17: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 17

Network CommunicationNetwork Communication

The actual network communication is The actual network communication is nothing new - it's just TCP/IP.nothing new - it's just TCP/IP.

Many RPC implementations are built Many RPC implementations are built upon the sockets library.upon the sockets library.– the RPC library does all the work!the RPC library does all the work!

We are just using a different API, the We are just using a different API, the underlying stuff is the same!underlying stuff is the same!

Page 18: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 18

Dynamic Port MappingDynamic Port Mapping

Servers typically do not use well known Servers typically do not use well known protocol ports!protocol ports!

Clients known the Program ID (and host Clients known the Program ID (and host IP address).IP address).

RPC includes support for looking up the RPC includes support for looking up the port number of a port number of a remote program.remote program.

Page 19: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 19

Port Lookup ServicePort Lookup Service

A port lookup service runs on each host A port lookup service runs on each host that contains RPC servers.that contains RPC servers.

RPC servers register themselves with RPC servers register themselves with this service:this service:– "I'm program 17 and I'm looking for "I'm program 17 and I'm looking for

requests on port 1736"requests on port 1736"

Page 20: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 20

The portmapperThe portmapper

Each system which will support RPC Each system which will support RPC servers runs a servers runs a port mapper port mapper server that server that provides a central registry for RPC provides a central registry for RPC services.services.

Servers tell the port mapper what Servers tell the port mapper what services they offer.services they offer.

Page 21: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 21

More on the portmapperMore on the portmapper

Clients ask a remote port mapper for the Clients ask a remote port mapper for the port number corresponsing to Remote port number corresponsing to Remote Program ID.Program ID.

The portmapper is itself an RPC server!The portmapper is itself an RPC server!

The portmapper is available on a well-The portmapper is available on a well-known port (111).known port (111).

Page 22: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 22

Sun RPC ProgrammingSun RPC Programming

The RPC library is a collection of tools The RPC library is a collection of tools for automating the creation of RPC for automating the creation of RPC clients and servers.clients and servers.

RPC clients are processes that call RPC clients are processes that call remote procedures.remote procedures.

RPC servers are processes that include RPC servers are processes that include procedure(s) that can be called by procedure(s) that can be called by clients.clients.

Page 23: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 23

RPC ProgrammingRPC Programming

RPC libraryRPC library– XDR routinesXDR routines– RPC run time libraryRPC run time library

» call rpc servicecall rpc service» register with portmapperregister with portmapper» dispatch incoming request to correct proceduredispatch incoming request to correct procedure

– Program GeneratorProgram Generator

Page 24: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 24

RPC Run-time LibraryRPC Run-time Library

High- and Low-level functions that can High- and Low-level functions that can be used by clients and servers.be used by clients and servers.

High-level functions provide simple High-level functions provide simple access to RPC services.access to RPC services.

Page 25: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 25

High-level Client LibraryHigh-level Client Library

int callrpc( char *host,int callrpc( char *host,

u_long prognum,u_long prognum,

u_long versnum,u_long versnum,

u_long procnum,u_long procnum,

xdrproc_t inproc,xdrproc_t inproc,

char *in,char *in,

xdrproc_t outproc,xdrproc_t outproc,

char *out);char *out);

Page 26: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 26

High-Level Server LibraryHigh-Level Server Library

int registerrpc(int registerrpc(

u_long prognum,u_long prognum,

u_long versnum,u_long versnum,

u_long procnum,u_long procnum,

char *(*procname)()char *(*procname)()

xdrproc_t inproc,xdrproc_t inproc,

xdrproc_t outproc);xdrproc_t outproc);

Page 27: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 27

High-Level Server Library High-Level Server Library (cont.)(cont.)

void svc_run();void svc_run();

svc_run()svc_run() is a is a dispatcher. dispatcher. A dispatcher waits for incoming A dispatcher waits for incoming

connections and invokes the connections and invokes the appropriate function to handle each appropriate function to handle each incoming request.incoming request.

Page 28: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 28

High-Level Library LimitationHigh-Level Library Limitation

The High-Level RPC library calls The High-Level RPC library calls support UDP only (no TCP).support UDP only (no TCP).

You must use lower-level RPC library You must use lower-level RPC library functions to use TCP.functions to use TCP.

The High-Level library calls do not The High-Level library calls do not support any kind of authentication.support any kind of authentication.

Page 29: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 29

Low-level RPC LibraryLow-level RPC Library

Full control over all IPC optionsFull control over all IPC options– TCP & UDPTCP & UDP– Timeout valuesTimeout values– Asynchronous procedure callsAsynchronous procedure calls

Multi-tasking ServersMulti-tasking Servers BroadcastingBroadcasting

IPC is InterProcess Communication

Page 30: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 30

RPCGENRPCGEN

There is a tool for automating the There is a tool for automating the creation of RPC clients and servers.creation of RPC clients and servers.

The program The program rpcgen rpcgen does most of the does most of the work for you.work for you.

The input to rpcgen is a The input to rpcgen is a protocol protocol definition definition in the form of a list of remote in the form of a list of remote procedures and parameter types.procedures and parameter types.

Page 31: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 31

RPCGENRPCGEN

Input File

rpcgen

Client Stubs XDR filters header file Server skeleton

C Source CodeC Source Code

ProtocolProtocolDescriptionDescription

Page 32: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 32

rpcgen Output Filesrpcgen Output Files

> rpcgen foo.x> rpcgen foo.x

foo_clnt.c (client stubs)foo_clnt.c (client stubs)

foo_svc.c (server main)foo_svc.c (server main)

foo_xdr.c (xdr filters)foo_xdr.c (xdr filters)

foo.h (shared header file)foo.h (shared header file)

Page 33: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 33

Client CreationClient Creation

> gcc -o fooclient foomain.c foo_clnt.c > gcc -o fooclient foomain.c foo_clnt.c foo_xdr.cfoo_xdr.c

foomain.c is the client main() (and possibly foomain.c is the client main() (and possibly other function) that call rpc services via the other function) that call rpc services via the client stub functions in foo_clnt.cclient stub functions in foo_clnt.c

The client stubs use the xdr functions.The client stubs use the xdr functions.

Page 34: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 34

Server CreationServer Creation

gcc -o fooserver fooservices.c foo_svc.c gcc -o fooserver fooservices.c foo_svc.c foo_xdr.cfoo_xdr.c

fooservices.c contains the definitions of the fooservices.c contains the definitions of the actual remote procedures.actual remote procedures.

Page 35: Netprog 2001 - RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol

Netprog 2001 - RPC Overview 35

Example Protocol DefinitionExample Protocol Definitionstruct twonums {struct twonums {

int a;int a;

int b;int b;

};};

program UIDPROG {program UIDPROG {

version UIDVERS {version UIDVERS {

int RGETUID(string<20>) = 1;int RGETUID(string<20>) = 1;

string RGETLOGIN( int ) = 2;string RGETLOGIN( int ) = 2;

int RADD(twonums) = 3;int RADD(twonums) = 3;

} = 1;} = 1;

} = 0x20000001;} = 0x20000001;