1. remote procedure call 2. remote method...

25
<1> <Network Programming> Part 5 확장된 확장된 Network Programming Network Programming 기술 기술 1. 1. Remote Procedure Call Remote Procedure Call 2. 2. Remote Method Invocation Remote Method Invocation 3. 3. Object Request Broker Object Request Broker

Upload: phamphuc

Post on 30-Aug-2018

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<1> <Network Programming>

Part 5

확장된확장된 Network Programming Network Programming 기술기술

1.1. Remote Procedure Call Remote Procedure Call 2.2. Remote Method InvocationRemote Method Invocation3.3. Object Request BrokerObject Request Broker

Page 2: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<2> <Network Programming>

1. RPC

Page 3: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<3> <Network Programming>

RPC 란 ?

• 하나의 client가 네트워크 상의 다른 컴퓨터나 server의procedure를 실행하는것

• 사용자 프로그래밍 툴

• socket interface보다 프로그래밍이 용이

• protocol compiler를 사용

– 통신 프로토콜 정의

• Distributed Computing Environment 하에서 분산 응용을개발하기 위한 toolkit

Page 4: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<4> <Network Programming>

Remote & Local Procedure Call

Clientcallingprocedure

Servercalledprocedure

arguments

resultsLocal Procedure CallLocal Procedure Call

Clientcallingprocedure

networktransport

Servercalledprocedure

networktransport

Network

requestmessages

Client Stubresults

Server Stub

arguments arguments

requestmessages

replymessages

replymessages

results

Remote Procedure CallRemote Procedure Call

Page 5: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<5> <Network Programming>

Remote Procedure Call(1)

• 개념

– Client-Server Model– stub – XDR(External Data Representation)

Page 6: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<6> <Network Programming>

Remote Procedure Call(2)

• Client-Server Model– request and reply 통신모델 이용

– client와 server는 두개의 stub에 의하여 통신

• stub– RPC 프로토콜을 구현하고, 메세지를 구성 및 교환하

는 방법을 지정한 통신 interface– stub를 생성하기 위해 protocol compiler 사용

• XDR(External Data Representation)– machine-independent data representation– client & server stub에서 데이타 전송시 사용

Page 7: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<7> <Network Programming>

RPC & IPC 특징

• IPC(InterProcess Communication)– 풍부한 library– 개발 및 디버깅이 어려움

– High-Performance– machine-dependent data representation

• byte-ordering 문제

• RPC– 개발 용이

– Low-Performance– machine-independent data representation

Page 8: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<8> <Network Programming>

How do RPCs work?

• RPC: distributed processing

• how to pass data between difference processes• data must actually be packaged and moved across the network

A processin site i

A processin site j

No RPC tool: packing & unpacking the data by programmer

RPC tool: automatically packing & unpacking the data during run-time

• No RPC tool– the programmer has to ensure the application-specific data structures are converted

into a sending form– the programmer has to program any translation between data formats– the programmer has to code the network transport protocols

Page 9: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<9> <Network Programming>

RPC run-time environments

Calling process/Called process

RPCRun-timeModule

• RPC run-time modules in Calling– reduce the data structure to be passed– convert the individual data elements to a format

understood by the called process– make calls to the network interface to co-ordinate the

sending of the packaged data to the called process– support multiple network protocol

• Multi-network environments– need to have a network gateway to transfer RPCs

Process A RPCMiddleware

RPCMiddleware

Process BNetwork

Page 10: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<10> <Network Programming>

RPC libraries and stubs

Applicationprogram

GeneratedCommunication

Code (Stub)

Libraries

Applicationprogram

GeneratedCommunication

Code (Stub)

Libraries

NetworkSoftware

Page 11: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<11> <Network Programming>

Remote Procedure Call model

clientroutines

clientStub

networkroutines

Client process

Local kernel

serverroutines

serverStub

networkroutines

Client process

Remote kernel

Page 12: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<12> <Network Programming>

RPC 응용을 개발하기 위한 단계

• 1 단계

– 프로토콜 정의

• protocol definition 규칙에 따라 client & server 사이의 interface를 정의

– service procedure, data type of parameter, return argument

• 정의된 프로토콜은 RPCGEN으로 compile– client와 server의 stub가 생성

• 2 단계

– client & server 프로그래밍

• client의 main 프로그램 작성

• server의 응용 프로그램 작성

Page 13: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<13> <Network Programming>

RPC Products

• Sun ONC(Open Network Computing) RPC– RPCGEN, RPC Runtime, XDR(External Data

Representation)

• Apollo NCS(Network Computing System) RPC– Object Oriented model– IDL(Interface Definition Language), RPC runtime,

NDR(Network Data Representation), ASN.1 BER

• OSF DCE RPC– based Apollo NCS RPC– added Security, Directory, Thread

Page 14: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<14> <Network Programming>

High-level RPC 응용 개발

• high-level function을 이용

– UDP transport protocol 사용

• client & server의 interface를 직접 구현

• protocol compiler를 사용하지 않고 프로그램 가능

• TCP를 사용하기 위해서는 low-level function을 사용

• 개발 과정

– 프로토콜 정의, client & server 프로그램 작성

Page 15: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<15> <Network Programming>

프로토콜 정의

• Data Types– ex) char, int, double etc.

• Program, Procedure, Version Numbers– ex)

#define DIR_SIZE 8192#define DIRPROG ((u_long) 0x20000000) /* server

program # */#define DIRVERS ((u_long) 1) /* program version

number */#define READDIR ((u_long) 1) /* procedure num for

look-up */

Page 16: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<16> <Network Programming>

High-level functions

• client– callrpc()

• int callproc(host, prognum, versnum, procnum, inproc, in, outproc, out)

• server– registerpc()

• #include <rpc/rpc.h>• int registerrpc(prognum, versum, procnum, proname,

inproc, outproc)– svc_run()

• void svc_run()

Page 17: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<17> <Network Programming>

High-level RPC

Server MachineServer Machine

Client MachineClient Machine

Server Program

Client Program

dispatch function

service pocedures

host, program, version,procedure, arguments

error or results

Portmapper

callrpc()

registerrpc()svc_run()

Page 18: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<18> <Network Programming>

Example Program

ClientClient rls.c

ServerServer

rls.hrls_xdr.c

rls_svc.cread_dir.c

Page 19: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<19> <Network Programming>

LowerLower--level RPC Programminglevel RPC Programming

user developed

clientclientexecutableexecutable

serverserverexecutableexecutable

RPC Compiler

RPC Specification

shared filters& header fileclient stub server stub

clientfunctions

RPC and datarepresentation

libraries

serverfunctions

compileandlink

compileandlink

Page 20: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<20> <Network Programming>

Low-level RPC 응용 프로그램

• 프로토콜 정의 프로그램(application.x)– RPCGEN으로 프로토콜 정의 프로그램 compile

• XDR routine 생성(application_xdr.c)• 프로토콜 정의에 대한 include file 생성

(application.h)• client stub 생성(application_clnt.c)• server stub 생성(application_svc.c)

• 서버 서비스 프로그램(application_svc_proc.c)– server stub의 dispatch 루틴에 의해서 호출될 함수

• 클라이언트 프로그램(application.c)

Page 21: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<21> <Network Programming>

Example of a RPC program by Using RPCGEN

test_proc.c

test.x

main_test.c

Server procedures

RPC specification file

Client main function

rpcgen

test_srv.c

test.h

test_clnt.c

cc

cc

RPCrun-timelibrary

test_srv

test

Server program

Clientprogram

Page 22: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<22> <Network Programming>

High-level & Low-level calls

high-level calls

low-level callstr

ansp

ort l

ibra

ry

tran

spor

t lib

rary

callrpc()

clnt_create()clnttcp_create()clntudp_create()clntraw_create()

clnt_destroy()

clnt_call()clnt_control()clnt_freeres()

registerrpc()svc_run()

svctcp_create()svcudp_create()svcraw_create()

svc_destroy()

svc_register()svc_unregister()

svc_getargs()svc_sendreply()svc_getreset()

NetworkNetwork

Page 23: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<23> <Network Programming>

RPC Library Routines (1)

• RPC client

– callrpc call remote procedure, given [prognum, versnum, procnum]– clnt_broacast() broadcast remote procedure call everywhere– clntraw_create() create toy RPC client for simulation– clnttcp_create() create RPC client using TCP transport– clntudp_create() create RPC client using UDP transport– rpc_createerrglobal variable indicating reason why client creation failed– clnt_pcreateerror() print message to stderr about why client handle creation failed– clnt_call call remote procedure associated with client handle– clnt_geterr() copy error information from client handle to error structure– clnt_perrno()print message to stderr corresponing to condition given– clnt_freeres() free data allocated by RPC/XDR system when decoding results– clnt_destroy() destroy client’s RPC handle

Page 24: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<24> <Network Programming>

RPC Library Routines (2)

• RPC Server– regiserrpc() register procedure with RPC service pakage– src_run() wait for RPC requests to arrive and call appropriate service– svcraw_create() creates a toy RPC service transport for testing– svctcp_create() creates an RPC service based on TCP transport– svcudp_create() creates an RPC service based on UDP transport– svc_fds global variable with RPC service file descriptor mask– svc_register() associates program and versnum with service dispatch procedure– svc_getreq() returns when all associated sockets have been serviced– svc_getargs() decodes the arguments of an RPC request– svc_getcaller() get the network address of the caller of a procedure– svc_sendreply() send back results of a remote procedure call– svc_freeards() free data allocated by RPC/XDR system when decoding arguemnts

Page 25: 1. Remote Procedure Call 2. Remote Method …mm.sookmyung.ac.kr/~yiyoon/Lecture/CDP_2010/PPT/Part_5-1... · 2010-11-29 · – the programmer has to ensure the application-specific

<25> <Network Programming>

RPC Library Routines (3)

• RPC Server (cont.)– svcerr_auth() called when refusing service because of authentication error– svcerr_decode() called when service cannot decode its parameters– svcerr_noproc() called when service hasn’t implemented the desired procedure– svcerr_noprog() called when program is not registered with RPC package– svcerr_progvers() called when version is not registered with RPC package– svcerr_systemerr() called when service detects system error– svcerr_weakauth() called when refusing service because of insufficient authentication– ssvc_unregister() remove mapping of [prognum, vernum] to dispathc routines– svc_destroy() destroy RPC service transport handle