1 / 55

Monday, 04 2008

Monday, 04 2008. "If you give someone a program, you will frustrate them for a day; if you teach them how to program, you will frustrate them for a lifetime.“  - Mitch Ratcliffe. Advanced Distributed Computing. Lecture 03 Distributed System Models. Lecture Objectives .

maree
Télécharger la présentation

Monday, 04 2008

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Monday, 04 2008 "If you give someone a program, you will frustrate them for a day; if you teach them how to program, you will frustrate them for a lifetime.“  - Mitch Ratcliffe

  2. Advanced Distributed Computing Lecture 03 Distributed System Models

  3. Lecture Objectives • Conclude Chapter 2 • Failure Model • Omission failures. • Arbitrary failures. • Timing failures. • Socket Programming

  4. Revision • Architectural Model • Goal • Reliability • Manageability • Adaptability • Cost-effectiveness • Service Layers • Platform • Middleware • System Architecture • Client/Server • Proxy • Peer to Peer • Variations on Client/Server • Mobile code and mobile agent • Design requirements for distributed systems

  5. Failure models - Types • Omission failures. • Arbitrary failures. • Timing failures.

  6. Failure model - omission failures (1) • A process or communication channel fails to perform actions that it is supposed to do. • Process omission failures: • Crash (and clean crash) • Use timeouts. • Process crash is called Fail-stop • If other processes can detect certainly that Process has been crashed. (fail to respond) • Can be produced in synchronous systems only where message delivery is guaranteed.

  7. process process p q send m receive Communication channel Outgoing message buffer Incoming message buffer Failure model – omission failure (2) • Communication omission failures: • Communication primitives aresend and receive. • Send-omission failures. • Receive-omission failures. • Channel-omission failures. • Also known as dropping message • Generally caused by • Lack of buffer space at receiving end or intervening gateway • Network transmission error, detected by a checksum

  8. Failure model – Arbitrary failure • Arbitrary or Byzantine failures • Described as the worst possible failure semantics, in which any type of error may occur • Process/channel exhibits arbitrary behavior • Process may return a wrong value in response to an invocation • Arbitrary Process failure • Process may omit a step/s or Perform uninterested step/s • Arbitrary Communication Failure • Messages contents can be corrupted, a duplicate message can be sent or message can be lost on its way • Rare and can be detected by checksum or message numbering

  9. Affects Description Class of failure Process Process halts and remains halted. Other processes may Crash not be able to detect this state. Fail-stop Process Process halts and remains halted. Other processes may detect this state. Omission Channel A message inserted in an outgoing message buffer never arrives at the other end’s incoming message buffer. Send-omission Process A process completes a but the message is not put in its outgoing message buffer. A message is put in a process’s incoming message Receive-omission Process buffer, but that process does not receive it. Arbitrary Process/channel exhibits arbitrary behaviour: it may Process or (Byzantine) send/transmit arbitrary messages at arbitrary times, channel commit omissions; a process may stop or take an incorrect step. Failure model – overview of omission failures

  10. Failure model - remedies • Masking failures: • A knowledge of the failure characteristic of a component can enable us to develop a reliable service which use such components which can fail. • Converting failure, checksum, retransmit message, replication, restoring information (convert arbitrary failure to omission failure) • A service masks a failure, either by hiding it altogether or by converting it into a more acceptable type of failure. • Reliability of one-to-one communication: • Correct message delivery in presence of failure • Validity: Any message in the outgoing message buffer is eventually delivered to the incoming message buffer. • Integrity:The message received is identical to one sent, and no messages are delivered twice. • Threats: Malicious Users and Protocols

  11. Class Affects Description Process exceeds the bounds on the interval Performance Process between two steps. Channel Performance A message’s transmission takes longer than the stated bound. Process’s local clock exceeds the bounds on its Clock Process rate of drift from real time. Failure model - timing failures • Applicable in synchronous distributed systems. • Time limits • Process execution time • Message delivery time • Clock drift rate • Real Time Operating System • Provides timing guarantee • Multimedia

  12. Security model - basics • The security of a distributed system: • securing the processes and the channels • protecting the objects against unauthorized access. • Protecting objects. • Access rights: • Who is allowed to perform operation • Principal: • Authority associated with each invocation and each result – The behalf on which it is issued

  13. Socket Programming

  14. Socket • A socket is an abstract representation of a communication endpoint. • Sockets (obviously) have special needs: • establishing a connection • specifying communication endpoint addresses

  15. Application Network API Protocol A Protocol B Protocol C

  16. Computer Chat • How do we make computers talk? • How are they interconnected? Internet Protocol (IP)

  17. Internet Protocol (IP) • Datagram (packet) protocol • Best-effort service • Loss • Reordering • Duplication • Delay • Host-to-host delivery (not application-to-application)

  18. IP Address • 32-bit identifier • Dotted-quad: 192.118.56.25 • www.vitalfact.net -> 167.208.101.28 192.18.22.13 209.134.16.123

  19. Transport Protocols Best-effort not sufficient! • Add services on top of IP • User Datagram Protocol (UDP) • Data checksum • Best-effort • Transmission Control Protocol (TCP) • Data checksum • Reliable byte-stream delivery • Flow and congestion control

  20. Ports Identifying the ultimate destination • IP addresses identify hosts • Host has many applications • Ports (16-bit identifier) Application http E-mail Telnet Port 80 25 23 FTP 21 192.18.22.13

  21. TCP/IP Byte Transport • TCP/IP protocols transports bytes • Application protocol provides semantics Application Application byte stream byte stream Here are some bytes. I don’t know what they mean. I’ll pass these to the app. It knows what to do. TCP/IP TCP/IP

  22. Socket • Applications servicing outside machines are called servers. Server applications listen for clients by initializing one or more listening sockets. • When a client connects to one of these listening sockets, the server receives a notification from Winsock, accepts the connection, and begins to dispatch and intercept messages to and from the new client. How does one speak TCP/IP? • Sockets provides interface to TCP/IP • Generic interface for many protocols

  23. Sockets • Identified by protocol and local/remote address/port • Applications may refer to many sockets • Sockets accessed by many applications

  24. TCP/IP Sockets • mySock = socket(family, type, protocol); • TCP/IP-specific sockets • SOCK_STREAM type sockets have the ability to queue incoming connection requests, which is a lot like having "call waiting" for your telephone • Socket reference • Socket handle in WinSock

  25. Methods in Sockets • Server side programs: • Initialize WSA – WSAStartup(). • Create a socket – socket(). • Bind the socket – bind(). • Listen on the socket – listen(). • Accept a connection – accept(), connect(). • Send and receive data – recv(), send(), recvfrom(), sendto(). • Disconnect – closesocket(). • Client side programs: • Initialize WSA – WSAStartup(). • Create a socket – socket(). • Connect to the server – connect(). • Send and receive data – recv(), send(), recvfrom(), sendto(). • Disconnect – closesocket().

  26. Writing Sockets --installing phone WSADATA info; /*The WSADATA structure contains information about the Windows Sockets implementation.*/ • At the start of every program that uses sockets you must call the WinSock function WSAStartup() WSAStartup(MAKEWORD(1,1), &info) • The first argument is the version number of the WinSock library. Similarly you must call the WSACleanup() function before your program exits to properly shut down the library

  27. Writing Sockets (Contd..) • After creating a socket, we must give the socket an address to listen to, just as you get a telephone number so that you can receive calls. • The bind() function is used to do this (it binds a socket to an address, hence the name) • An internet socket address is specified using the sockaddr_in structure, it contains fields that specify the address family, address, and port number for a socket • A pointer to this structure is passed to functions like bind() which need an address

  28. Generic • struct sockaddr { unsigned short sa_family; /* Address family (e.g., AF_INET) */ char sa_data[14]; /* Protocol-specific address information */ }; • struct sockaddr_in { unsigned short sin_family; /* Internet protocol (AF_INET) */ unsigned short sin_port; /* Port (16-bits) */ struct in_addr sin_addr; /* Internet address (32-bits) */ char sin_zero[8]; /* Not used */ }; struct in_addr { unsigned long s_addr; /* Internet address (32-bits) */ }; IP Specific Blob Family sockaddr 8 bytes 4 bytes 2 bytes 2 bytes Family Port Internet address Not used sockaddr_in

  29. Writing Sockets (Contd..2) • The listen() function is used to set the maximum number of requests (maximum five) • After you create a socket to get calls, you must wait for calls to that socket. The accept() function is used to do this. • Calling accept() is analogous to picking up the telephone if it's ringing. accept() returns a new socket which is connected to the caller. • The send() and recv() functions are used to send data between sockets

  30. Network Byte Order Functions ‘h’ : host byte order ‘n’ : network byte order ‘s’ : short (16bit) ‘l’ : long (32bit) uint16_t htons(uint16_t); uint16_t ntohs(uint_16_t); uint32_t htonl(uint32_t); uint32_t ntohl(uint32_t); i = htonl(i);

  31. Important Concepts • WSADATA: This structure is used to query the operating system for the version of Winsock our code requires. An application calls WSAStartup() to initialize the correct Winsock DLL. • SOCKET: An object (in fact, it's defined as a u_int, unsigned integer, in winsock.h---used by applications to store a socket handle. • SOCKADDR_IN: An application utilizes this structure to specify how a socket should operate. SOCKADDR_IN contains fields for an IP address and port number:

  32. First Socket (listening server) #include <windows.h> #include <winsock.h> WORD sockVersion; WSADATA wsaData; int nret; SOCKET listeningSocket; sockVersion = MAKEWORD(1, 1); WSAStartup(sockVersion, &wsaData); listeningSocket = socket(AF_INET,SOCK_STREAM, IPPROTO_TCP); if (listeningSocket == INVALID_SOCKET) { WSACleanup(); return; } SOCKADDR_IN serverInfo; serverInfo.sin_family = AF_INET; serverInfo.sin_addr.s_addr = INADDR_ANY; serverInfo.sin_port = htons(8888);

  33. First Socket (listening server) contd. nret = bind(listeningSocket, (LPSOCKADDR)&serverInfo, sizeof(struct sockaddr)); if (nret == SOCKET_ERROR) { //return; //deal with error } nret = listen(listeningSocket, 10); SOCKET theClient; theClient = accept(listeningSocket, NULL, NULL); closesocket(theClient); closesocket(listeningSocket); WSACleanup(); } //end of program

  34. Making Your Own Connections • Creating a socket to connect to someone else uses most of the same functions, with the exception of the HOSTENT struct: • HOSTENT: A structure used to tell the socket to which computer and port to connect. These structures commonly appear as LPHOSTENT variables, which are merely pointers to HOSTENT structures. • As you code for Windows, you'll generally find that any data type preceded by LP denotes that the type is actually a pointer to a "base" type (for example, LPCSTR is a pointer to a C string, also known as char *

  35. First Socket (Client Side) WORD sockVersion; WSADATA wsaData; int nret; sockVersion = MAKEWORD(1, 1); WSAStartup(sockVersion, &wsaData); LPHOSTENT hostEntry; hostEntry = gethostbyname("www.yahoo.com"); if (!hostEntry) { //handle the error here} SOCKET theSocket; theSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (theSocket == INVALID_SOCKET) { //return}

  36. First Socket (Client Side) contd. SOCKADDR_IN serverInfo; serverInfo.sin_family = AF_INET; serverInfo.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list); serverInfo.sin_port = htons(80); nret = connect(theSocket,(LPSOCKADDR)&serverInfo, sizeof(struct sockaddr)); if (nret == SOCKET_ERROR) {WSACleanup(); //return} // Successfully connected! // Send/receive, then cleanup: closesocket(theSocket); WSACleanup(); } //end of program

  37. Some Key points • Creating a socket to connect to someone else uses most of the same functions, with the exception of the HOSTENT struct: • HOSTENT: A structure used to tell the socket to which computer and port to connect. These structures commonly appear as LPHOSTENT variables, which are merely pointers to HOSTENT structures. • As you code for Windows, you'll generally find that any data type preceded by LP denotes that the type is actually a pointer to a "base" type (for example, LPCSTR is a pointer to a C string, also known as char *

  38. Some Key points clientsock=accept( serversocket, NULL , NULL ); //The second argument is optional, // it should be the address of a SOCKADDR_IN struct //The third argument is optional, it can be the address of variable //containing sizeof ( struct SOCKADDR_IN ) #pragma comment(lib, "wsock32.lib") // This embeds a reference to the library wsock32.lib into the object file, so that the linker will search that library to resolve any undefined constants/ variables bind(listeningSocket, (LPSOCKADDR)&serverInfo, sizeof(struct sockaddr)); //can also be written as bind (serversocket , (SOCKADDR*)(&serveraddr) , sizeof(serveraddr)) ;

  39. Client Create a TCP socket Establish connection Communicate Close the connection Server Create a TCP socket Assign a port to socket Set socket to listen Repeatedly: Accept new connection Communicate Close the connection TCP Client/Server Interaction WSAStartup(MAKEWORD(1,1),&WsaDat); //Server starts by getting ready to receive client connections…

  40. Client Create a TCP socket Establish connection Communicate Close the connection Server Create a TCP socket Bind socket to a port Set socket to listen Repeatedly: Accept new connection Communicate Close the connection TCP Client/Server Interaction serversocket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);

  41. Client Create a TCP socket Establish connection Communicate Close the connection Server Create a TCP socket Bind socket to a port Set socket to listen Repeatedly: Accept new connection Communicate Close the connection TCP Client/Server Interaction • SOCKADDR_IN serveraddr; • serveraddr.sin_family = AF_INET; • serveraddr.sin_port = htons(5555); • serveraddr.sin_addr.s_addr = INADDR_ANY; • bind (serversocket , (SOCKADDR*)(&serveraddr) , sizeof(serveraddr)) ;

  42. Client Create a TCP socket Establish connection Communicate Close the connection Server Create a TCP socket Bind socket to a port Set socket to listen Repeatedly: Accept new connection Communicate Close the connection TCP Client/Server Interaction listen (serversocket,3)

  43. Client Create a TCP socket Establish connection Communicate Close the connection Server Create a TCP socket Bind socket to a port Set socket to listen Repeatedly: Accept new connection Communicate Close the connection TCP Client/Server Interaction clientsock=accept( serversocket, NULL , NULL );

  44. Client Create a TCP socket Establish connection Communicate Close the connection Server Create a TCP socket Bind socket to a port Set socket to listen Repeatedly: Accept new connection Communicate Close the connection TCP Client/Server Interaction Server is now blocked waiting for connection from a client Later, a client decides to talk to the server…

  45. Client Create a TCP socket Establish connection Communicate Close the connection Server Create a TCP socket Bind socket to a port Set socket to listen Repeatedly: Accept new connection Communicate Close the connection TCP Client/Server Interaction WSAStartup(MAKEWORD(1,1),&WsaDat); mysocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );

  46. Client Create a TCP socket Establish connection Communicate Close the connection Server Create a TCP socket Bind socket to a port Set socket to listen Repeatedly: Accept new connection Communicate Close the connection TCP Client/Server Interaction serveraddr.sin_family=AF_INET; serveraddr.sin_port= htons(5555); serveraddr.sin_addr.s_addr= inet_addr("127.0.0.1"); connect (mysocket , (SOCKADDR*)(&serveraddr),sizeof(serveraddr) );

  47. Client Create a TCP socket Establish connection Communicate Close the connection Server Create a TCP socket Bind socket to a port Set socket to listen Repeatedly: Accept new connection Communicate Close the connection TCP Client/Server Interaction clientsock=accept( serversocket, NULL , NULL );

  48. Client Create a TCP socket Establish connection Communicate Close the connection Server Create a TCP socket Bind socket to a port Set socket to listen Repeatedly: Accept new connection Communicate Close the connection TCP Client/Server Interaction Length = strlen(msg); /* Determine input length */ /* Send the string to the server */ send(mysocket,msg,length,0);

  49. Client Create a TCP socket Establish connection Communicate Close the connection Server Create a TCP socket Bind socket to a port Set socket to listen Repeatedly: Accept new connection Communicate Close the connection TCP Client/Server Interaction /* Receive message from client */ recv( clientsock , msg , sizeof(msg), 0 );

More Related