Adv' Network Programming RPC Remote Procedure Call - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Adv' Network Programming RPC Remote Procedure Call

Description:

Build, compile and test it. - Devide the program into pieces. ( Procedure level) ... input is a xti endpoint (no need to re-register) ... – PowerPoint PPT presentation

Number of Views:72
Avg rating:3.0/5.0
Slides: 24
Provided by: KUBI4
Category:

less

Transcript and Presenter's Notes

Title: Adv' Network Programming RPC Remote Procedure Call


1
Adv. Network ProgrammingRPC (Remote Procedure
Call)
  • Kubilay Akgül

2
RPC (Remote Procedure Call)
  • Two Paradigms for Distributed Programs.
  • Smilarities and Differences Conventional
    Procedure Calls and RPC
  • SUN RPC
  • Remote Program Identification
  • RPC Mapping, Inet.d
  • Call Semantics
  • RPCGEN

3
Two Paradigms
  • A programmer can use one of two approaches
  • Communication Oriented Design
  • - Focus on communication program. (Message
    format and syntax)
  • - Design client server components. (Reactions to
    messages)
  • May miss important subtitles.
  • Fundemental errors under stress.
  • Few programmers have experience with protocol
    design
  • Concentration on communication.
  • Resulting programs will be difficult to
    understand.

4
Two Paradigms
  • Application Oriented Design
  • - Focus on application.
  • - Design a conventional program that works
    correctly.
  • - Build, compile and test it.
  • - Devide the program into pieces. (Procedure
    level)
  • - Communication level and data representation is
    transparent.

? RPC
5
Conventional Programs and RPC
  • Smilarities
  • CALL
  • Caller transfers control to called procedure.
  • Caller suspends.
  • Only one thread of execution continues at any
    given time.
  • Values in all variables are frozen.
  • RESPONSE
  • Control flows back to the caller
  • A called procedure may call another procedure.
    (Server becomes a client)

6
Conventional Programs and RPC
  • Differences
  • Server Procedures
  • - RPC procedures must exist and be waiting to
    compute a response.
  • Data Flow
  • - RPC may accept or return arbitrary amount of
    data.
  • Network Delays
  • - Protocol, lost packets, data representation.
  • Adress Space
  • - Conventional programs can pass pointers as
    argument.
  • Environment
  • - RPC does not have direct access to callers I/O
    descriptors, OS functions...

7
SUN Microsystems RPC Definition
  • SUN defined specific form of RPC ? SUNRPC
  • Wide acceptance, many applications. (NFS)
  • Defines format of messages and arguments.
  • Protocol ? TCP , UDP.
  • Data Representation ? XDR.
  • Uses structure instead of multiple arguments.
  • At most one remote procedure in a remote program
    can be invoked at a given time ? Automatic Mutual
    Exclusion
  • A complier tool helps programmers to build
    distributed programs automatically ? RPCGEN

8
Remote Program and Procedure Identification
Program no Description 0x00000000 -
0x1fffffff defined by SUN 0x20000000 -
0x3fffffff defined by system mng. 0x40000000 -
0x5fffffff customer written appl. 0x60000000 -
0xffffffff reserved
  • Program Number
  • - Each program must be assigned a unique 32 -
    bit integer
  • Procedure Number
  • - Each procedure in a remote program must have
    an integer. (1,2,3...)
  • Version number
  • - Multiple versions may run at the same time.
  • You can change details with same version
    number.
  • Easy to migrate.
  • (prog, ver, proc)

9
RPC Mapping
  • UDP and TCP ? 16 bit protocol port numbers.
  • RCP ? 32 bit program numbers.
  • Servers uses well known ports.
  • RPC servers use ephemeral ports. They takes
    different ports after each time they restart.
  • Machine address Program no ? ? ? correct
    server port

10
PORT MAPPER, RPCBIND
  • Uses a database of dynamic port mapping. (TCP/UDP
    port 111)
  • Starts in multiuser mode.
  • Servers main function calls svc_create
  • - Determines protocols supported by clients
  • - Creates end-points, Binds port to TCP and UDP.
  • - Contacts RPCBIND and registers itself (port,
    prog, ver).
  • - Goes to sleep.
  • Client calls clnt_create (server_IP, prog_no,
    ver, protocol)
  • - Usually makes a UDP connection to RPCBIND on
    servers machine.

11
PORT MAPPER, RPCBIND
V2 ? historical (just TCP UDP) v3,4 ? newer
protocols
Uses /etc/rpc
Solaris rpcinfo -p program vers proto port se
rvice 100000 4 tcp 111 rpcbind 100000
3 tcp 111 rpcbind 100000 2 tcp 111 rpcbind 1000
00 4 udp 111 rpcbind 100000 3 udp 111 rpcbind
100000 2 udp 111 rpcbind .... 824377344
1 udp 42972 server 824377344 1 tcp 40849 server
Solaris rpcinfo -d sprayd 1 ... unregisters
sprayd demon. Solaris pkill -HUP inetd ...
inetd reads the /etc/inetd.conf file and
registers sprayd again.
12
RPC - Inetd
  • RPCgen created servers may be invoked by inetd.
  • /etc/inetd.conf file needs ti be updated.
  • ...
  • Rstatd/2-4 tli rpc/datagram_V wait root
    /usr/.../rpc.rstatd rpc.rstatd
  • ...
  • Inetd
  • - creates endpoint, registers to RPCBIND.
  • - listens for ports, fork, exec, waits until
    server terminates.
  • Server
  • - std. input is a xti endpoint (no need to
    re-register).
  • - waits for 2 minutes before terminate ( to
    prevent new fork and exec)
  • - generates SIGCHLD to inetd.

13
Call Semantics
  • Procedure calls can be placed into one of these
    categories
  • 1. Exactly once
  • 2. At most once
  • 3. At least once
  • 4. Zero or more

14
Call Semantics - Scenarios
  • TCP
  • Reply received Exactly Once
  • No reply At most once (server may have
    crashed)
  • UDP without server cash
  • Reply received at least once
  • No reply zero or more
  • UDP with server cash
  • Reply received Exactly Once
  • No reply At most once

15
Stub Procedure Consept RPCGEN
  • Sun RPC specifications are extensive and
    complicated without a software tool.
  • Assistance
  • 1. XDR library routines internal data items ?
    XDR standard
  • 2. RPC untime library correctly make call,
    receive call, registration...
  • 3. RPCgen A program generater

16
Stub Procedures
  • Additional procedures added to program to
    implement RPC.
  • Client Side Stub They replaces the called
    procedure.
  • Server Side Stub They replaces the caller
    procedure.

Computer 1
Computer 2
PROC A
Server Stub
Client Stub
Proc B
17
RPCGEN
  • Rpcgen reads an input file that contains a
    specification of remote program.
  • IT produces four output (source code) files.
  • If specification file has name Q.x all output
    files will begin with Q.
  • - Q.h Declarations of constants and types
    used in the code generated for both client
    and server.
  • - Q_xdr.c XDR procedure calls used in the
    client and server to marshal arg.
  • - Q_clnt.c Client side stub procedure.
  • - Q_svc.c Server side stub procedure.

18
RPC Example
19
RPC Example
  • Specification file
  • 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 /
    procedure number 1 /
  • 1 / version number /
  • 0x31230000 / program number /

20
RPC Example
Client.c (Client main function)
  • include "unpipc.h" / our header /
  • include "square.h" / generated by rpcgen /
  • int main(int argc, char argv)
  • CLIENT cl
  • square_in in
  • square_out outp
  • if (argc ! 3)
  • err_quit("usage client lthostnamegt
    ltinteger-valuegt")
  • cl clnt_create(argv1, SQUARE_PROG,
    SQUARE_VERS, "tcp")
  • in.arg1 atol(argv2)
  • if ( (outp squareproc_1(in, cl)) NULL)
  • err_quit("s", clnt_sperror(cl, argv1))
  • printf("result ld\n", outp-gtres1)
  • exit(0)

Client handle
21
RPC Example
Server Procedure
  • include "unpipc.h"
  • include "square.h"
  • square_out
  • squareproc_1_svc(square_in inp, struct svc_req
    rqstp)
  • static square_out out
  • out.res1 inp-gtarg1 inp-gtarg1
  • return(out)

22
RPC Example
Client executable
  • Solaris rpcgen -C square.x
  • Solaris cc -c client.c -o client.o
  • Solaris cc -c square_clnt.c -o square_clnt.o
  • Solaris cc -c square_xdr.c -o square_xdr.o
  • Solaris cc -o client client.o square_clnt.o
    square_xdr.o libunpipc.a -lnsl

Server executable
Solaris cc -c server.c -o server.o Solaris
cc -c square_svc.c -o square.svc.o Solaris cc
-o server server.o square_svc.o square_xdr.o
libunpipc.a -lnsl
23
RPC Example
Write a Comment
User Comments (0)
About PowerShow.com