Upload
mahadevan-govindakrishnan
View
217
Download
4
Embed Size (px)
DESCRIPTION
Distributed computing
Citation preview
CSS490 Message PassingTextbook Ch2 - 3Instructor: Munehiro Fukuda
These slides were compiled from the course textbook, the reference books, and the instructors original materials.
CSS490 Message Passing
OSI 7 LayersSiteAApplicationPresentationSessionTransportNetworkData linkPhysicalSiteBApplicationPresentationSessionTransportNetworkData linkPhysicalApplication protocolPresentation protocolSession protocolTransport protocolNetwork protocolData link protocolPhysical protocol7654321NetworkEthernetIPUDP, TCPrsh, ftp, TelnetDialog control(rarely supported)Dealing with heterogeneity And cryptography IEEE802.2connection or connectionless
CSS490 Message Passing
Physical/Data Link LayerExample: CSMA/CD and Token RingIEEE802.3: CSMA/CD (Carrier sense multiple access with collision detection)Listening to the shared mediumTransmitting a data packetDetecting collision on the mediumDeferring and retransmitting a packet in 2ktime base collision windowIEEE802.5: Token RingReceiving a free token from my (left) neighborAttaching a data packet to the tokenForwarding the token to my (right) neighborDetaching a packet from the token if it is addressed here1 listen2 transmit3. detect1. Free token3. busy token2. Attach4. Detach
CSS490 Message Passing
Network LayerExample: IPDatagramfragmentationreassemblyBest-effort deliver semanticsTransportation layerData link layerClass D: for broadcasting
CSS490 Message Passing
Transport Layer:Example1: UDPUser Datagram ProtocolConnectionlessMay be lostNo FIFO orderMulticast featureUnix datagramExample: TFTP, rwhosocket()socket()bind()bind()sendto()recvfrom()recvfrom()sendto()clientserverBlocks until data receivedCreate a sock descriptorBind it to an IP address
CSS490 Message Passing
Transport Layer:Example2: TCPTransport Control ProtocolConnection-orientedReliableFIFO orderNo Multicast featureUnix stream socketExample: ftp, http, rsh all major applicationssocket()socket()connect()bind()read()liseten()write()wrte()clientserverBlocks until connection establishedCreate a sock descriptorBind it to an IP addressaccept()read()Connection establishedDeclare this is connection-orientedWait for a connection
CSS490 Message Passing
Application LayerExample: RSHinetdrshdshellCommandls -lshellCommandrsh ls- lTCP connectionrequestTCP connectionInherited all the wayTo a child ClientServer
CSS490 Message Passing
Socket Programming: Socket.h#include
extern "C"{#include // for sockets#include #include #include
#include // for gethostbyname( )#include // for close( )#include // for bzero( )}
#define NULL_FD -1#define MAXSIZE 20
class Socket { public: Socket( int ); ~Socket( ); int getClientSocket( char[] ); int getServerSocket( ); private: int port; int clientFd; int serverFd;};
CSS490 Message Passing
Socket Programming: Socket.cpp (Client)#include "Socket.h"
Socket::Socket( int port ) : port( port ), clientFd( NULL_FD ), serverFd( NULL_FD ) {}
Socket::~Socket( ) { if ( clientFd != NULL_FD ) close( clientFd ); if ( serverFd != NULL_FD ) close( serverFd );}
int Socket::getClientSocket( char ipName[] ) {
// Get the host entry corresponding to ipName struct hostent* host = gethostbyname( ipName ); if( host == NULL ) { cerr
Socket Programming: Socket.cpp (Server)int Socket::getServerSocket( ) { if ( serverFd == NULL_FD ) { // Server not ready sockaddr_in acceptSockAddr;
// Open a TCP socket (an internet stream socket). if( ( serverFd = socket( AF_INET, SOCK_STREAM, 0 ) ) < 0 ) { cerr
Socket Programming: Main#include "Socket.h"#define PORT 10000 // You are given a specific pot from the instructor
int main( int argc, char *argv[] ) { Socket sock( PORT ); int fd;
if ( argc == 1 ) { // I'm a server while ( true ) { if ( ( fd = sock.getServerSocket( ) ) == NULL_FD )return -1; char recvMessage[MAXSIZE]; read( fd, recvMessage, MAXSIZE ); cout
Blocking/Non-Blocking CommunicationBlocking communicationTCP, UDP, and other communication packagesClient: blocked only when the destination buffer is fullServer: blocked if no message has arrived from the client.RendezvousClient: blocked for a server to receive a messageServer: blocked if no message has arrived from the client.Non-blocking communicationServer does not want to be blocked whenIt may receive a message from a different client.It has another jobs to be done such as computation or message transmission.Some synchronization is necessary later.
CSS490 Message Passing
Synchronization in Non-Blocking CommunicationPollingPeriodically check if a socket is ready to read data:Example:sd = socket( AF_INET, SOCKET_STREAM, 0);set_fl(sd, O_NONBLOCK);// set the socket as non-blockingstruct pollfd pfd;pfd.fd = sd;poll( &pfd, 1, timeout )// poll the socket statusInterruptNotified from the system when a socket is ready to read data;Example:sd = socket(AF_INET, SOCKET_STREAM, 0);signal(SIGIO, sigio_func);// set a future interrupt to call sigio_func( )fcntl(sd, F_SETOWN, getpid( )); // ask OS to deliver this fd interrupt to mefcntl(sd, F_SETFL, FASYNC);// set this fd asynchronousint sigio_func( ) { // invoked upon an interrupt }
CSS490 Message Passing
BufferingNo BufferingA message remains on the sender until the receiver issues receive( ).RendezvousPerformance drawbackSingle Message BufferThe sender can send at most one message even if the receiver has not issued receive( ).Stop-and-wait protocolA message can be kept read in advance.What if the sender has multiple messages?Finite-Bound BufferUnsuccessful communication- Go-Back-N TechniqueFlow-controlled communication- sliding window in TCPSocket: capable of changing its buffer size with setsockopt( )messagemessagemessagemessagemessagemessage
CSS490 Message Passing
Process AddressingExplicit addressmachine id + local idExample: TCP/IP and UDP/IP use IP + portDemerit: No process migration allowedmachine id + local id + the last machine idProcess migration allowedMessages forwarded along links to the final destinationReceiver informing sender of its last machine idSender using this info from the following messagesImplicit addressingSystem-wide id (function name)Example: RPCName server required
CSS490 Message Passing
Failure HandlingLoss of request messageLoss of response messageUnsuccessful execution of requestDo we really need acknowledgment messages?
CSS490 Message Passing
IdempotencyA pair of request and response is enough to handle faultsIdempotency assumed:At-least one semanticsLast-one semantics
clientserverclientserverTimeoutTimeoutTimeoutrequestrequest 2request 3request 4responsereesponse 2requestresponse
CSS490 Message Passing
Exactly-One SemanticsWhat if errors in the banking systemNew semantics required:Exactly-one semanticsServer must keep track of the request sequenceWithdraw $100$1000-$100= $900Not receivedWithdraw $100$900-$100=$800!$100 receivedWithdraw995 $100$1000-$100= $900 for Trans995Not receivedWithdraw995 $100$100 receivedTrans995 completedNo subtraction
CSS490 Message Passing