260 likes | 408 Vues
Presentation Formatting. application. application. data. data. Presentation. Presentation. Encoding. Decoding. . . . message. message. message. Overview. Marshalling (encoding) application data into messages Unmarshalling (decoding) messages into application data.
E N D
application application data data Presentation Presentation Encoding Decoding . . . message message message Overview • Marshalling (encoding) application data into messages • Unmarshalling (decoding) messages into application data
Data Types • Data types we consider: • integers • floating point numbers • character strings • arrays • structures • Types of data we do not consider (now): • images • video • multimedia documents
Difficulties • Representation of base types • floating point: IEEE 754 versus non-standard • integer: big-endian versus little-endian • Compiler layout of structures (0) (0) (0) (2) big endian 00000000 00000000 00000000 00000010 (2) (0) (0) (0) little endian 00000010 00000000 00000000 00000000 0 1 2 3 Low High Address address
Taxonomy • Data types • base types (e.g., ints, floats); must convert • flat types (e.g., structures, arrays); must pack • complex types (e.g., pointers); must linearize • Conversion Strategy • canonical intermediate form • receiver-makes-right (an N x N solution) • N machine architectures must be able to handle N representations
Marshalling Application Data Structure Argument Marshaller
INT 4 4byte integer Interface Descriptor for Call Procedure P P P Spec arguments arguments Code Code Client Stub Server Stub Compiler Stub marshalled marshalled arguments arguments RPC RPC message Tagged versus Untagged data • Stubs • compiled • interpreted • CORBA
Examples XDR: eXternal Data Representation • Defined by Sun for use with SunRPC • C type system (without function pointers) • Canonical intermediate form • Untagged (except array length) • Compiled stubs
#define MAXNAME 256; #define MAXLIST 100; struct item { int count; char name[MAXNAME]; int list[MAXLIST]; }; bool_t xdr_item(XDR *xdrs, struct item *ptr) { return(xdr_int(xdrs, &ptr->count) && xdr_string(xdrs, &ptr->name,MAXNAME) && xdr_array(xdrs, &ptr->list, &ptr->count, MAXLIST, sizeof(int), xdr_int)); }
count name 3 7 J O H N S O N list 3 497 8321 265 XDR 70MBps attainable on 175MHz Alpha
Abstract Syntax Notation ASN.1 • (tag-8 bits, length-8+bits, value) • Used by Simple Network Management Protocol (SNMP) • Canonical Intermediate form • Length=0x82 01 01=257 • Each call sends 3 bytes
Integer Char FloatRep Extension 1 Extension 2 Rep Rep NDR: Network Data Representation • Defined by DCE (CORBA) • Essentially the C type system • Receiver-makes-right (architecture tag) • Individual data items untagged • Compiled stubs from Interface Definition Language (IDL)
4-byte architecture definition tag • IntegrRep • 0 = big-endian • 1 = little-endian • CharRep • 0 = ASCII • 1 = EBCDIC • FloatRep • 0 = IEEE 754 • 1 = VAX • 2 = Cray • 3 = IBM
Client Server blocked request blocked computing reply blocked Overview
caller callee (client) (server) return return args args value value client server stub stub reply reply req req RPC RPC Protocol Protocol network Mechanics
Address Space for Procedures • Flat: unique id for each possible procedure • Hierarchical: program + procedure within program
SUNRPC UDP IP ETH SunRPC • UDP + SunRPC implement • UDP dispatches to program (ports bound to programs) • SunRPC dispatches to procedure w/in program
Implementation • Port Mapper program exists at well known UDP port (111) • The Port Mapper translates program numbers (32 bits) to UDP port numbers • The 32 bit procedure number is then used to make the remote call • NFS read procedure = 6
XID XID MsgType MsgType = CALL = REPLY RPCVersion Status = = 2 ACCEPTED Program Version Procedure Credentials (variable) Verifier (variable) SunRPC Header Format
RPC Lab • Write code to implement open, read and write commands to remote file • You pass off against your own code • The TA code is there to give you an example of how things might work • Can be implemented on top of IP if TCP isn’t complete
“file” “file” RPC_OPEN RPC_OPEN Call Response RPC_OPEN Handle Overview Server Client Main() calls rpc::open(“file”); RPC creates message and sends To TCP Pop decodes RPC_OPEN, calls fd=open(“file”);
len Handle RPC_READ Call Response RPC_READ tmpb data rval Overview Server Client Main() calls rpc::read(Handle, buf, len) RPC creates message and sends To TCP Waits on semaphore Pop decodes RPC_READ calls rval=read(fd,tmpb,len); rpc::pop copies data from message into buf, signals semaphore
buf data len Handle RPC_WRITE Call Response RPC_WRITE Server Client Overview Main() calls rpc::write(Handle, buf, len) RPC creates message and sends To TCP, waits on semaphore Pop decodes RPC_WRITE calls rval=write(fd,tmpb,len); rpc::pop signals semaphore
Details • Passoff • Open remote file • Read from within file • Read beyond end (you should only return amount actually available) • Write beyond end • Read total data • Copy new version of test file before each run.