5. RPC Fundamentals

 

Introduction

MultiNet RPC Services must be used with the HP C Socket Library.

This chapter is for RPC programmers. It provides basic information you need to know before using RPC Services to write distributed applications, including:

  What RPC Services are

  What components are in RPC Services

  How RPC clients and servers communicate

  Important RPC concepts and terms

 

What Are RPC Services?

RPC Services are a set of software development tools that allow you to build distributed applications on OpenVMS systems.

 

MultiNet Implementation

RPC Services are based on the Open Network Computing Remote Procedure Call (RPC) protocols developed by Sun Microsystems, Inc. These protocols are defined in the following Requests for Comments (RFCs):

  RPC: Remote Procedure Call Protocol Specification, Version 2 (RFC 1057)

  XDR: External Data Representation Standard (RFC 1014)

 

Distributed Applications

A distributed application executes different parts of its programs on different hosts in a network. Computers on the network share the processing workload, with each computer performing the tasks for which it is best equipped.

For example, a distributed database application might consist of a central database running on a VAX server and numerous client workstations. The workstations send requests to the server. The server carries out the requests and sends the results back to the workstations. The workstations use the results in other modules of the application.

RPCs allow programs to invoke procedures on remote hosts as if the procedures were local. RPC Services hides the networking details from the application.

RPC Services facilitates distributed processing because it relieves the application programmer of performing low-level network tasks such as establishing connections, addressing sockets, and converting data from one machine's format to another.

 

Components of RPC Services   

RPC Services comprises the following components:

Run-Time Libraries (RTLs)

RPCGEN Compiler

 

Port Mapper

 

RPC Information

 

Run-Time Libraries (RTLs)

RPC Services provides a single shareable RTL. The library contains:

  RPC client and server routines

  XDR routines

The RPC RTL Management Routines, Chapter 10, and the chapters that follow it describe the RTLs in detail.

 

RPCGEN Compiler

RPCGEN is a compiler that creates the network interface portion of a distributed application. It effectively hides from the programmer the details of writing and debugging low-level network interface code. The RPCGEN Compiler, Chapter 8 , describes how to use RPCGEN.

 

Port Mapper

The Port Mapper helps RPC client programs connect to ports that are being used by RPC servers. A Port Mapper runs on each host that implements RPC Services. These steps summarize how the Port Mapper works:

1   RPC servers register with the Port Mapper by telling it which ports they are using.

When an RPC client needs to reach a particular server, it supplies the Port Mapper with the numbers of the remote program and program version it wants to reach. The client also specifies a transport protocol (UDP or TCP). ( provides details on these numbers.)

3   The Port Mapper provides the correct port number for the requested service. This process is called binding.

Once binding has taken place, the client does not have to call the Port Mapper for subsequent calls to the same server. A service can register for different ports on different hosts. For example, a server can register for port 800 on Host A and port 1000 on Host B. The Port Mapper is itself an RPC server and uses the RPC RTL. The Port Mapper plays an important role in disseminating messages for broadcast RPC. The Port Mapper is part of the Master Server Process. See the  section for details.

 

RPC Information

Use the RPC information command to:

  Request a listing of all programs that are registered with the Port Mapper

You enter this command at the DCL prompt. (See RPC Information in Chapter 12, Building Distributed Applications, for details.)

 

Client-Server Relationship

In RPC, the terms client and server do not describe particular hosts or software entities. Rather, they describe the roles of particular programs in a given transaction. Every RPC transaction has a client and a server. The client is the program that calls a remote procedure; the server is the program that executes the procedure on behalf of the caller.

A program can be a client or a server at different times. The program's role merely depends on whether it is making the call or servicing the call.

 

External Data Representation (XDR)

External Data Representation (XDR) is a standard that solves the problem of converting data from one machine's format to another.

RPC Services uses the XDR data description language to describe and encode data. Although similar to C language, XDR is not a programming language. It merely describes the format of data, using implicit typing. XDR: External Data Representation Standard (RFC 1014) defines the XDR language.

 

RPC Processing Flow

Remote and local procedure calls share some similarities. In both cases, a calling process makes arguments available to a procedure. The procedure uses the arguments to compute a result, then returns the result to the caller. The caller uses the results of the procedure and resumes execution.

Figure 5-1    

 shows the underlying processing that makes a remote procedure call different from a local call.

The following steps describe the processing flow during a remote procedure call:

1   The client program passes arguments to the client stub procedure. (See Chapter 7, RPCGEN Compiler, for details on how to create stubs.)

2   The client stub marshals the data by:

     Calling the XDR routines to convert the arguments from the local representation to XDR

     Placing the results in a packet

Using RPC RTL calls, the client stub sends the packet to the UDP or TCP layer for transmission to the server.

3   The packet travels on the network to the server, up through the layers to the server stub.

4   The server stub un-marshals the packet by converting the arguments from XDR to the local representation. Then it passes the arguments to the server procedure.

Figure 5-1     RPC Processing Flow

Local Calls Versus Remote Calls      

This section describes some of the ways in which local and remote procedure calls handle system crashes, errors, and call semantics.

 

Handling System Crashes

Local procedure calls involve programs that reside on the same host. Therefore, the called procedure cannot crash independently of the calling program.

Remote procedure calls involve programs that reside on different hosts. Therefore, the client program does not necessarily know when the remote host has crashed.

 

Handling Errors

If a local procedure call encounters a condition that prevents the call from executing, the local operating system usually tells the calling procedure what happened.

If a remote procedure call cannot be executed for some reason (e.g., errors occur on the network or remote host), the client might not be informed of what happened. You may want to build a signaling or condition-handling mechanism into the application to inform the client of such errors.

RPC returns certain types of errors to the client, such as those that occur when it cannot decode arguments. The RPC server must be able to return processing-related errors, such as those that occur when arguments are invalid, to the client. However, the RPC server may not return errors during batch processing or broadcast RPC.

 

Call Semantics

Call semantics determine how many times a procedure executes.

Local procedures are guaranteed to execute once and only once.

Remote procedures have different guarantees, depending on which transport protocol is used.

The TCP transport guarantees execution once and only once as long as the server does not crash. The UDP transport guarantees execution at least once. It relies on the XID cache to prevent a remote procedure from executing multiple times.

See     for details on the XID cache.

 

Programming Interface

The RPC RTL is the programming interface to RPC. You may think of this interface as containing multiple levels.

The RPC RTL reference chapters describe each routine.

 

High-Level Routines

The higher-level RPC routines provide the simplest RPC programming interface. These routines call lower-level RPC routines using default arguments, effectively hiding the networking details from the application programmer.

When you use high-level routines, you sacrifice control over such tasks as client authentication, port registration, and socket manipulation, but you gain the benefits of using a simpler programming interface. Programmers using high-level routines can usually develop applications faster than they can using low-level RPC routines.

You can use the RPCGEN compiler only when you use the highest-level RPC programming interface.

 

Mid-Level Routines

The mid-level routines provide the most commonly used RPC interface. They give the programmer some control over networking tasks, but not as much control as the low-level routines permit.

For example, you can control memory allocation, authentication, ports, and sockets using mid-level routines.

The mid-level routines require you to know procedure, program, and version numbers, as well as input and output types. Output data is available for future use. You can use the registerrpc and callrpc routines.

 

Low-Level Routines

The low-level routines provide the most complicated RPC interface, but they also give you the most control over networking tasks such as client authentication, port registration, and socket manipulation. These routines are used for the most sophisticated distributed applications.

 

Transport Protocols

RPC Services uses the transport protocols listed in RPC Transport Protocols. The RPC client and server must use the same transport protocol for a given transaction.

Table 5-1     RPC Transport Protocols

Protocols

Characteristics

UDP

Unreliable datagram service

 

Connectionless

 

Used for broadcast RPC

 

Maximum broadcast message size in either direction on an Ethernet line: 1500

 

Execution is guaranteed at least once (see   )

 

Calls cannot be processed in batch

TCP

Reliable

 

Connection-oriented

 

Can send an unlimited number of bytes per RPC call

 

Execution is guaranteed once and only once

 

Calls can be processed in batch

 

No broadcasting

 

Note!     You must use the HP C Socket Library with RPC Services.

 

XID Cache       

The XID cache stores responses the server has sent. When the XID cache is enabled, the server does not have to recreate every response to every request. Instead, the server can use the responses in the cache. Thus, the XID cache saves computing resources and improves the performance of the server.

Only the UDP transports can use the XID cache. The reliability of the TCP transport generally makes the XID cache unnecessary. UDP is inherently unreliable.

XID Cache Differences  shows how the XID caches differ for the UDP and UDPA/TCPA transports.

Table 5-2     XID Cache Differences 

UDP Transport

UDPA/TCPA Transports

Places every response in the XID cache

Allows the server to specify which responses are to be cached, using the svcudp_enablecache and svctcpa_enablecache routines

XID cache cannot be disabled

Requires you to disable the XID cache after use

 

Cache Entries

Each entry in the XID cache contains:

  The encoded response that was sent over the network

  The internet address of the client that sent the request

  The transaction ID that the client assigned to the request

 

Cache Size

You determine the size of the XID cache. Consider these factors:

  How many clients are using the server.

  Approximately how long the cache should save the responses.

  How much memory you can allocate. Each entry requires about 8Kbytes.

The more active the server is, the less time the responses remain in the cache.

 

Execution Guarantees

As explained earlier in    , remote procedures have different execution guarantees, depending on which transport protocol is used. The XID cache affects the execution guarantee.

The TCP transport guarantees execution once and only once as long as the server does not crash. The UDP transport guarantees execution at least once. If the XID cache is enabled, a UDP procedure is unlikely to execute more than once.

 

Enabling XID Cache

Use the svcudp_enablecache routine to enable the XID cache. This routine is described in the RPC RTL reference chapters.

Not enabling the XID cache saves memory.

 

Broadcast RPC

Broadcast RPC allows the client to send a broadcast call to all Port Mappers on the network and wait for multiple replies from RPC servers.

For example, a host might use a broadcast RPC message to inform all hosts on a network of a system shutdown.

Normal RPC vs Broadcast RPC  shows the differences between normal RPC and broadcast RPC.

Table 5-3     Normal RPC vs Broadcast RPC 

Normal RPC

Broadcast RPC

Client expects one answer

Client expects many answers

Can use TCP or UDP

Requires UDP

Server always responds to errors

Server does not respond to errors;
Client does not know when errors occur

Port Mapper is desirable, but not required if you use fixed port numbers

Requires Port Mapper services

Broadcast RPC sends messages to only one port — the Port Mapper port — on every host in the network. On each host, the Port Mappers pass the messages to the target RPC server. The servers compute the results and send them back to the client.

 

Identifying Remote Programs and Procedures

The RPC client must uniquely identify the remote procedure it wants to reach. Therefore, all remote procedure calls must contain these three fields:

  A remote program number

  The version number of the remote program

  A remote procedure number

 

Remote Program Numbers

A remote program is a program that implements at least one remote procedure. Remote programs are identified by numbers that you assign during application development. Use Remote Program Numbers  to determine which program numbers are available. The numbers are in groups of hexadecimal 20000000.

Table 5-4     Remote Program Numbers 

Range

Purpose

0 to 1FFFFFFF

Defined and administered by Sun Microsystems. Should be identical for all sites. Use only for applications of general interest to the Internet community.

20000000 to 3FFFFFFF

Defined by the client application program. Site-specific. Use primarily for new programs.

40000000 to 5FFFFFFF

Use for applications that generate program numbers dynamically.

60000000 to FFFFFFFF

Reserved for the future. Do not use.

 

Remote Version Numbers

Multiple versions of the same program may exist on a host or network. Version numbers distinguish one version of a program from another. Each time you alter a program, remember to increment its version number.

 

Remote Procedure Numbers

A remote program may contain many remote procedures. Remote procedures are identified by numbers that you assign during application development. Follow these guidelines when assigning procedure numbers:

  Use 1 for the first procedure in a program. (Procedure 0 should do nothing and require no authentication to the server.)

  For each additional procedure in a program, increment the procedure number by one.

Additional Terms

Before writing RPC applications, you should be familiar with the terms in Additional Terms .

 

Table 5-5     Additional Terms 

Term

Definition

Channel

An OpenVMS term referring to a logical path that connects a process to a physical device, allowing the process to communicate with that device. A process requests OpenVMS to assign a channel to a device. Refer to Hewlett-Packard’s documentation for more information on channels.

Client handle

Information that uniquely identifies the server to which the client is sending the request. Consists of the server's host name, program number, program version number, and transport protocol.

See the following routines in the RPC RTL Client Routines:

authnone_create                          clnt_create                 clnt_perror / clnt_sperror
authunix_create                           clnttcp_create
authunix_create_default               clntudp_create / clntudp_bufcreate

Port

An abstract point through which a datagram passes from the host layer to the application layer protocols.

Server handle

Information that uniquely identifies the server. Content varies according to the transport being used. See the following routines in RPC RTL Server Routines:

svcudp_create /            svctcp_create            svc_destroy
svc_freeargs                 svc_getargs
svc_register                   svc_sendreply

Socket

An abstract point through which a process gains access to the Internet. A process must open a socket and bind it to a specific destination. Note: The HP C Socket Library must be used with RPC Services.