Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSS434 Networking1 Textbook Ch3 Professor: Munehiro Fukuda.

Similar presentations


Presentation on theme: "CSS434 Networking1 Textbook Ch3 Professor: Munehiro Fukuda."— Presentation transcript:

1 CSS434 Networking1 Textbook Ch3 Professor: Munehiro Fukuda

2 CSS434 Networking2 Outline OSI 7 layers Physical/data link layers (layer 1 & 2) Network layer – IP (layer 3) Transport layer – TCP UDP (layer 4) Application layer – RSH (layer 7) Socket examples

3 CSS434 Networking3 OSI 7 Layers Site A Application Presentation Session Transport Network Data link Physical Site B Application Presentation Session Transport Network Data link Physical Application protocol Presentation protocol Session protocol Transport protocol Network protocol Data link protocol Physical protocol 7 6 5 4 3 2 1 Network Ethernet IP UDP, TCP rsh, ftp, Telnet Dialog control (rarely supported) Dealing with heterogeneity And cryptography IEEE802.2 connection or connectionless

4 CSS434 Networking4 OSI Protocol Summary LayerDescriptionExamples ApplicationProtocols that are designed to meet the communication requirements of specific applications, often defining the interface to a service. HTTP, FTP,SMTP, CORBA IIOP PresentationProtocols at this level transmit data in a network representation that is independent of the representations used in individual computers, which may differ. Encryption is also performed in this layer, if required. Secure Sockets (SSL),CORBA Data Rep. SessionAt this level reliability and adaptation are performed, such as detection of failures and automatic recovery. TransportThis is the lowest level at which messages (rather than packets) are handled. Messages are addressed to communication ports attached to processes, Protocols in this layer may be connection-oriented or connectionless. TCP,UDP NetworkTransfers data packets between computers in a specific network. In a WAN or an internetwork this involves the generation of a route passing through routers. In a single LAN no routing is required. IP,ATM virtual circuits Data linkResponsible for transmission of packets between nodes that are directly connected by a physical link. In a WAN transmission is between pairs of routers or between routers and hosts. In a LAN it is between any pair of hosts. Ethernet MAC, ATM cell transfer, PPP PhysicalThe circuits and hardware that drive the network. It transmits sequences of binary data by analogue signalling, using amplitude or frequency modulation of electrical signals (on cable circuits), light signals (on fibre optic circuits) or other electromagnetic signals (on radio and microwave circuits). Ethernet base- band signalling,ISDN

5 CSS434 Networking5 Physical/Data Link Layer Example: CSMA/CD and Token Ring IEEE802.3: CSMA/CD (Carrier sense multiple access with collision detection) 1. Listening to the shared medium 2. Transmitting a data packet 3. Detecting collision on the medium 4. Deferring and retransmitting a packet in 2 k – time base collision window IEEE802.5: Token Ring 1. Receiving a free token from my (left) neighbor 2. Attaching a data packet to the token 3. Forwarding the token to my (right) neighbor 4. Detaching a packet from the token if it is addressed here 1 listen 2 transmit 3. detect Ⅹ 1. Free token 3. busy token 2. Attach 4. Detach

6 CSS434 Networking6 Network Layer Example: IP Datagram LDS Source IP address Destination IP address IP packet ID and size LDS Source IP address Destination IP address IP packet ID and size fragmentation reassembly Best-effort deliver semantics Transportation layer Data link layer Class A Net #Host #0 Octet 1 0-127 Octet 2 – 4 (1,677,716) Net #Host # 10 Class B Octet 1 128-191 Octet 2 Octet 3 – 4 (65,536) Net #Host#110 Class C Octet 1 128-191 Octet 2 – 3 Octet 4 (256) Class D: for broadcasting

7 CSS434 Networking7 Transport Layer: Example1: UDP User Datagram Protocol Connectionless May be lost No FIFO order Multicast feature Unix datagram Example: TFTP, rwho socket() bind() sendto() recvfrom() sendto() client server Blocks until data received Create a sock descriptor Bind it to an IP address

8 CSS434 Networking8 Transport Layer: Example2: TCP Transport Control Protocol Connection-oriented Reliable FIFO order No Multicast feature Unix stream socket Example: ftp, http, rsh all major applications socket() connect() bind() read() liseten() write() wrte() clientserver Blocks until connection established Create a sock descriptor Bind it to an IP address accept() read() Connection established Declare this is connection-oriented Wait for a connection

9 CSS434 Networking9 Application Layer Example: RSH inetd rshd shell Command ls -l shell Command rsh ls- l TCP connection request TCP connection Inherited all the way To a child ClientServer

10 CSS434 Networking10 Summary of TCP/IP Layers Messages (UDP) or Streams (TCP) Application Transport Internet UDP or TCP packets IP datagrams Network-specific frames Message Layers Underlying network Network interface

11 CSS434 Networking11 Socket Programming: Socket.h #include extern "C" { #include // for sockets #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; };

12 CSS434 Networking12 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 << "Cannot find hostname." << endl; return NULL_FD; } // Fill in the structure "sendSockAddr" with the server address. sockaddr_in sendSockAddr; bzero( (char*)&sendSockAddr, sizeof( sendSockAddr ) ); sendSockAddr.sin_family = AF_INET; //Address Family Internet sendSockAddr.sin_addr.s_addr = inet_addr( inet_ntoa( *(struct in_addr*)*host->h_addr_list ) ); sendSockAddr.sin_port = htons( port ); // Open a TCP socket (an Internet strem socket). if( ( clientFd = socket( AF_INET, SOCK_STREAM, 0 ) ) < 0 ) { cerr << "Cannot open a client TCP socket." << endl; return NULL_FD; } // Connect to the server. while ( connect( clientFd, (sockaddr*)&sendSockAddr, sizeof( sendSockAddr ) ) < 0 ); // Connected return clientFd; }

13 CSS434 Networking13 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 << "Cannot open a server TCP socket." << endl; return NULL_FD; } // Bind our local address so that the client can send to us bzero( (char*)&acceptSockAddr, sizeof( acceptSockAddr ) ); acceptSockAddr.sin_family = AF_INET; // Address Family Internet acceptSockAddr.sin_addr.s_addr = htonl( INADDR_ANY ); acceptSockAddr.sin_port = htons( port ); if( bind( serverFd, (sockaddr*)&acceptSockAddr, sizeof( acceptSockAddr ) ) < 0 ) { cerr << "Cannot bind the local address to the server socket." << endl; return NULL_FD; } listen( serverFd, 5 ); } // Read to accept new requests int newFd = NULL_FD; sockaddr_in newSockAddr; socklen_t newSockAddrSize = sizeof( newSockAddr ); if( ( newFd = accept( serverFd, (sockaddr*)&newSockAddr, &newSockAddrSize ) ) < 0 ) { cerr << "Cannot accept from another host." << endl; return NULL_FD; } return newFd; }

14 CSS434 Networking14 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 << recvMessage << endl; close( fd ); } if ( argc == 2 ) { // I'm a client if ( ( fd = sock.getClientSocket( argv[1] ) ) == NULL_FD ) return -1; char sendMessage[MAXSIZE]; cin >> sendMessage; write( fd, sendMessage, MAXSIZE ); } return 0; }

15 CSS434 Networking15 Exercises (No turn-in) 1. Why do we need layered network protocols? 2. When implementing TCP with datagram, what do we have to take care of? 3. Compare UDP and TCP for the implementation of each of the following application-level or presentation-level protocols (textbook p142, Q3.7): 1. Telnet 2. FTP 3. Rwho, finger 4. HTTP 5. RPC or RMI


Download ppt "CSS434 Networking1 Textbook Ch3 Professor: Munehiro Fukuda."

Similar presentations


Ads by Google