Communication Distributed Systems Fall 2002 Communication Process Process Networks and protocols Sockets Remote Invocation Messages Streams 9/10/2001 DoCS 2002 2
Layered Protocols (1) Layers, interfaces, and protocols in the OSI model. 9/10/2001 DoCS 2002 3 Layered Protocols (2) 2-2 A typical message as it appears on the network. 9/10/2001 DoCS 2002 4
Middleware Protocols An adapted reference model for networked communication. 9/10/2001 DoCS 2002 5 The TCP/IP Layers Application mail, file transfer, web Application Transport Internet tcp, udp ip Internet Internet Transport Internet Media access Media access Media access Media access 9/10/2001 DoCS 2002 6
Layers, Protocols & Messages Application M M Transport H t M H t M Internet H i H t M H i H t M Media access H m H i H t M H m H i H t M 9/10/2001 DoCS 2002 7 Transport Protocols TCP Stream Reliable Sequenced UDP Message / datagram Unreliable 9/10/2001 DoCS 2002 8
TCP for Client / Server request response UDP TCP T/TCP 9/10/2001 DoCS 2002 9 The Application Layer ISO: session, presentation, application Internet: monolithic application Examples SSL - authentication, secure transmission SMTP - electronic messages FTP - bulk transfer HTTP - document retrieval 9/10/2001 DoCS 2002 10
The Middleware Layer Applications, services RMI and RPC This chapter request-reply protocol marshalling and external data representation Middleware layers UDP and TCP 9/10/2001 DoCS 2002 11 Sockets and Ports socket any port agreed port socket client Internet address = 138.37.94.248 message other ports server Internet address = 138.37.88.249 Client creates socket sends to addr/port Server creates socket binds to port advertises addr/port 9/10/2001 DoCS 2002 12
UDP Socket Structure host name port number Server process Client process server socket response request client socket 9/10/2001 DoCS 2002 13 C Client - create a socket #define DATA "The sea is calm tonight, the tide is full... main(argc, argv) int argc; char *argv[ ]; { int sock; struct sockaddr_in name; struct hostent *hp, *gethostbyname(); struct sockaddr_in { short sin_family; u_short sin_port; struct in_addr sin_addr; char sin_zero[8]; }; Internet socket UDP (datagram) /* Create socket on which to send. */ sock = socket(af_inet, SOCK_DGRAM, 0); if (sock < 0) { perror("opening datagram socket"); exit(1); } 9/10/2001 DoCS 2002 14
C Client - Send The Message } hp = gethostbyname(argv[1]); if (hp == 0) { fprintf(stderr, "%s: unknown host\n", argv[1]); exit(2); } bcopy(hp->h_addr, &name.sin_addr, hp->h_length); name.sin_family = AF_INET; name.sin_port = htons(atoi(argv[2])); /* Send message. */ port number if (sendto(sock, DATA, sizeof(data), 0, &name, sizeof(name)) < 0) perror("sending datagram message"); close(sock); server domain name 9/10/2001 DoCS 2002 15 C UDP Server - create socket main() { int sock, length; struct sockaddr_in name; char buf[1024]; /* Create socket from which to read. */ sock = socket(af_inet, SOCK_DGRAM, 0); if (sock < 0) { perror("opening datagram socket"); exit(1); } Internet socket UDP (datagram) 9/10/2001 DoCS 2002 16
C UDP Server - bind to port /* Create name with wildcards. */ name.sin_family = AF_INET; name.sin_addr.s_addr = INADDR_ANY; name.sin_port = 0; if (bind(sock, &name, sizeof(name))) { perror("binding datagram socket"); exit(1); } accept connections from assign default port number 9/10/2001 DoCS 2002 17 C UDP Server - Read the data /* Find assigned port value and print it out. */ length = sizeof(name); if (getsockname(sock, &name, &length)) { perror("getting socket name"); exit(1); } printf("socket has port #%d\en", ntohs(name.sin_port)); /* Read from the socket */ if (read(sock, buf, 1024) < 0) perror("receiving datagram packet"); printf("-->%s\en", buf); close(sock); } 9/10/2001 DoCS 2002 18
Remote Procedure Call Distributed Systems Fall 2002 History of RPC Birrell and Nelson - 1984 Provide communication transparency Overcome heterogeniety Firefly - Schroeder and Burrows, 1989 High performance Standardised Sun ONC, OSF DCE Object based Emerald, Choices, ANSA, Java 9/10/2001 DoCS 2002 20
Conventional Procedure Call The stack before the call to read(fd, buf, bytes) The stack while the called procedure is active 9/10/2001 DoCS 2002 21 Client and Server Stubs Principle of RPC between a client and server program. 9/10/2001 DoCS 2002 22
Implementation Components IPC IPC client stub runtime runtime stub Server invoke pack args send receive unpack args invoke work return unpack result receive send pack result return Interface Stub is proxy for other side Runtime listens for messages Must always be present Interface 9/10/2001 DoCS 2002 23 Questions How do we specify the interface? How we generate stubs? How are parameters passed? How does a client find/bind to a server? 9/10/2001 DoCS 2002 24
Steps of a Remote Procedure Call 1. Client procedure calls client stub in normal way 2. Client stub builds message, calls local OS 3. Client's OS sends message to remote OS 4. Remote OS gives message to server stub 5. Server stub unpacks parameters, calls server 6. Server does work, returns result to the stub 7. Server stub packs it in message, calls local OS 8. Server's OS sends message to client's OS 9. Client's OS gives message to client stub 10. Stub unpacks result, returns to client 9/10/2001 DoCS 2002 25 Passing Value Parameters Steps involved in doing remote computation through RPC 2-8 9/10/2001 DoCS 2002 26
Passing Value Parameters Original message on a Pentium Int val(5) String val( JILL ) The message after receipt on a SPARC The message after being inverted. The little numbers in boxes indicate the address of each byte 9/10/2001 DoCS 2002 27 Parameters and Stub Generation A procedure The corresponding message. 9/10/2001 DoCS 2002 28
Doors The principle of using doors as IPC mechanism. 9/10/2001 DoCS 2002 29 Component Generation client source interface definition IDL compiler server source client stub header server stub C compiler C compiler C compiler C compiler client object client stub object server stub object server object 9/10/2001 DoCS 2002 30
CORBA IDL Example // In file Person.idl struct Person { string name; string place; long year; } ; interface PersonList { readonly attribute string listname; void addperson(in Person p) ; void getperson(in string name, out Person p); long number(); }; 9/10/2001 DoCS 2002 31 Asynchronous RPC (1) a) The interconnection between client and server in a traditional RPC b) The interaction using asynchronous RPC 9/10/2001 DoCS 2002 32
Asynchronous RPC (2) A client and server interacting through two asynchronous RPCs 9/10/2001 DoCS 2002 33 Binding How do we locate a remote object? May be done at various times later -> more flexible earlier -> more efficient communication Usually done at run-time At initialisation - typical rpc, some object sytems At invocation - to support mobility Both can use the same paradigm locate on first contact and cache relocate if cache fails 9/10/2001 DoCS 2002 34
Remote Binding Problems Is server available? Are versions consistent? Solution - version number Reject or multiple servers Multiple Servers Load balancing First reply 9/10/2001 DoCS 2002 35 Remote Invocation Natural fit to familiar method invocation or procedure call Requires response = doop(request) Interface definition Inter-process communication Network Protocols request = receive() response = do(request) send(response) 9/10/2001 DoCS 2002 36
Linking the Client and Server Server exports an interface IDL assigns each procedure a signature within interface Also an instance or version number Name service provides port or host address Port - direct connection to interface Host - server side dispatcher provides port 9/10/2001 DoCS 2002 37 Binding a Client to a Server Client-to-server binding in DCE. 9/10/2001 DoCS 2002 38
Server Registration IPC runtime stub server Name Service add service record in table register interface export(name) export(name) return return 9/10/2001 DoCS 2002 39 RPC Protocols: Client Binding client stub IPC runtime Name Service IPC runtime ref=import(name) ref=import(name) request service lookup bind(name) lookup return record result 9/10/2001 DoCS 2002 40
Invocation Semantics Invocation semantics Maybe At-least-once At-most-once Retry request message No Yes Yes Delivery guarantees Duplicate filtering at server Not applicable No Yes Re-execute procedure or retransmit reply Not applicable Re-execute procedure Retransmit reply 9/10/2001 DoCS 2002 41