Adv network programming rpc remote procedure call
Download
1 / 23

Adv. Network Programming RPC (Remote Procedure Call) - PowerPoint PPT Presentation


  • 154 Views
  • Uploaded on

Adv. Network Programming RPC (Remote Procedure Call). Kubilay Akgül. 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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Adv. Network Programming RPC (Remote Procedure Call)' - parker


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Adv network programming rpc remote procedure call

Adv. Network ProgrammingRPC (Remote Procedure Call)

Kubilay Akgül


Rpc remote procedure call
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

ADVANCED NETWORK PROGRAMING -- RPC


Two paradigms
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.

ADVANCED NETWORK PROGRAMING -- RPC


Two paradigms1
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

ADVANCED NETWORK PROGRAMING -- RPC


Conventional programs and rpc
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)

ADVANCED NETWORK PROGRAMING -- RPC


Conventional programs and rpc1
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...

ADVANCED NETWORK PROGRAMING -- RPC


Sun microsystems rpc definition
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

ADVANCED NETWORK PROGRAMING -- RPC


Remote program and procedure identification
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)

ADVANCED NETWORK PROGRAMING -- RPC


Rpc mapping
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

ADVANCED NETWORK PROGRAMING -- RPC


Port mapper rpcbind
PORT MAPPER, RPCBIND

  • Uses a database of dynamic port mapping. (TCP/UDP port = 111)

  • Starts in multiuser mode.

  • Server’s 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.

ADVANCED NETWORK PROGRAMING -- RPC


Port mapper rpcbind1
PORT MAPPER, RPCBIND

V2  historical (just TCP UDP)

v3,4  newer protocols

Uses /etc/rpc

Solaris % rpcinfo -p

program vers proto port service

100000 4 tcp 111 rpcbind

100000 3 tcp 111 rpcbind

100000 2 tcp 111 rpcbind

100000 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.

ADVANCED NETWORK PROGRAMING -- RPC


Rpc inetd
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.

ADVANCED NETWORK PROGRAMING -- RPC


Call semantics
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

ADVANCED NETWORK PROGRAMING -- RPC


Call semantics scenarios
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

ADVANCED NETWORK PROGRAMING -- RPC


Stub procedure consept rpcgen
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

ADVANCED NETWORK PROGRAMING -- RPC


Stub procedures
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

ADVANCED NETWORK PROGRAMING -- RPC


Rpcgen
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.

ADVANCED NETWORK PROGRAMING -- RPC


Rpc example
RPC Example

ADVANCED NETWORK PROGRAMING -- RPC


Rpc example1
RPC Example

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 */

  • Specification file

ADVANCED NETWORK PROGRAMING -- RPC


Rpc example2
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 <hostname> <integer-value>");

cl = clnt_create(argv[1], SQUARE_PROG, SQUARE_VERS, "tcp");

in.arg1 = atol(argv[2]);

if ( (outp = squareproc_1(&in, cl)) == NULL)

err_quit("%s", clnt_sperror(cl, argv[1]));

printf("result: %ld\n", outp->res1);

exit(0);

}

Client handle

ADVANCED NETWORK PROGRAMING -- RPC


Rpc example3
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->arg1 * inp->arg1;

return(&out);

}

ADVANCED NETWORK PROGRAMING -- RPC


Rpc example4
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

ADVANCED NETWORK PROGRAMING -- RPC


Rpc example5
RPC Example

ADVANCED NETWORK PROGRAMING -- RPC