Title: External Data Representation XDR
1Lecture 11
- External Data Representation (XDR)
2Overview
- Data Representation
- N-Squared Conversion Problem
- Network Standard Byte Order
- De Facto XDR Standard
- XDR Data Types
- XDR Library Routines
- Building XDR Messages
- Summary
3Data Representation
- Each computer architecture provides its own
representation of data - LSB at the lowest memory address
- MSB at the lowest memory address
- Client/Server applications must contend with data
representation
decreasing memory address
increasing memory address
0
0
1
4
4
1
0
0
4N-Squared Conversion Problem
- The underlying issue of data representation is
software portability - Asymmetric Data Conversion
- Converts directly from the clients
representation into the servers implementation - Must write a client-server pair for each pair of
architectures - The programming effort is proportional to the
square of the number of different data
representations (N2 N) / 2
5N-Squared Conversion Problem (Cont)
If client-server software is designed to convert
from the clients native data representation
directly to the servers native data
representation asymmetrically, the number of
versions of the software grows as the square of
the number of architectures
6N-Squared Conversion Problem (Cont)
- Solving the N-squared conversion problem
- Develop client/server software so that it can be
compiled and executed on a variety of machines - Results in a highly portable program
- Makes accessing services easier
7Network Standard Byte Order
- Solves the data representation problem by
converting the native byte order to a network
standard byte order - TCP/IP protocol software uses symmetric data
conversion - Both ends perform the required conversion
- Only one version of the protocol is needed
- Both client and server perform a data conversion
- Data is represented in a standard
machine-independent format - The standard format is known as external data
representation (XDR) - Advantage of symmetric conversion
- Added flexibility neither the client nor the
server needs to understand the architecture of
the other - Disadvantage of symmetric conversion
- Computational overhead using an intermediate
format introduces additional computation
8Network Standard Byte Order (Cont)
- Converting between heterogeneous representations
requires extra CPU cycles - Conversion my result in a larger stream of bytes
- Symmetric conversion is still advantageous
- Simplifies programmer
- Reduces errors
- Increases interoperability
- Network management and debugging is easier
9De Facto XDR Standard
- Sun Microsystems devised an external data format
called eXternal Data Representation (XDR) - XDR is a standard for the description and
encoding of data - XDR specifies data formats for most data types
that clients/servers exchange - XDR specifies that 32-bit binary numbers should
be represented in big endian order - Client/Servers using XDR must agree on the exact
format of messages exchanged - XDR uses a language to describe data formats. The
language can only be used only to describe data
it is not a programming language. - This language allows one to describe intricate
data formats in a concise manner.
10XDR Data Types
- The XDR standard defines various basic data types
and allows for the definition of compound data
types (structs), fixed-size and variable-size
arrays as well as unions. - XDR provides representations for most C
programming structures
11Implicit Types
- Client/Servers using XDR must agree on the exact
format - Encoding does not identify its type or length
- XDR message cannot be decoded unless it knows the
exact format and types of all data fields
12Software Support for XDR
- Data must be converted from native format to the
XDR representation before sending across the
network - Data must be converted from XDR representation to
native format when receiving data from the
network - XDR conversion libraries are used to eliminate
potential conversion errors - Converting floating point representation to the
XDR standard
13XDR Library Routines
- XDR routines can convert data items from the
machines native format to the XDR format and
vice-versa - Most XDR implementations use a buffer paradigm
- Uses a program to allocate a buffer large enough
to hold the external format of a message - The application calls XDR conversion routines for
each data item in the message - After encoding each data item and placing it in
the XDR stream the application can send the
message
14Building an XDR Message
- The XDR buffer paradigm uses a buffer to hold the
external representation of the message - Need an XDR Pointer
- XDR xdrs
- Buffer to hold the data
- Using functions you can create and add to the
buffer, and get data from the buffer - xdrmem_create(xdrs, buf, BUFSIZE, XDR_ENCODE)
- xdr_int(xdrs, i)
15XDR Stream Buffer
stream header
0
1
2
3
4
5
6
An XDR stream that has been initialized for
ENCODE and already contains 7 bytes of data
stream header
0
1
2
3
4
5
6
0
0
1
4
XDR stream after a call to xdr_int appends a
32-bit integer with value 260
16XDR Streams, I/O, TCP UDP
- Method 1 Build entire message, then write
- Method 2 Open Standard I/O stream (FILE object)
and create using xdrstdio_create() - now each read/write will convert on the fly
- Method 3 Open UDP datagram interface
- use xdrrec_create() and send data in datagrams
17Summary
- Client/Server programs must contend with data
representation problems - Asymmetric conversion
- The client or server converts from its native
format to the remote machines native format - N-Squared Conversion Problem
- Symmetric Conversion
- Uses a standard network representation
- Requires both the client/server programs convert
between the standard format and native format - Increased flexibility but added computational
overhead