1 / 36

Transport Protocols Overview

Transport Protocols Overview. provide logical communication between app processes running on different hosts transport protocols run in end systems send side: breaks app messages into segments , passes to network layer rcv side: reassembles segments into messages, passes to app layer

Download Presentation

Transport Protocols Overview

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. Transport Protocols Overview

  2. provide logical communication between app processes running on different hosts transport protocols run in end systems send side: breaks app messages into segments, passes to network layer rcv side: reassembles segments into messages, passes to app layer more than one transport protocol available to apps Internet: TCP and UDP application transport network data link physical application transport network data link physical network data link physical network data link physical network data link physical network data link physical network data link physical logical end-end transport Transport services and protocols

  3. TCP connection-oriented reliable byte stream Application: typically concurrent server SMTP(Simple Mail Transfer Protocol) Telnet FTP HTTP NNTP(Network News TP) UDP connectionless unreliable datagram Applications: typically iterative server SNMP(Simple Network Management Protocol) TFTP(Trivial FTP) BOOTP(Bootstrap Protocol) DHCP(Bootstrap Protocol) TCP versus UDP

  4. full duplex data: MSS: maximum segment size connection-oriented: flow controlled: point-to-point: reliable, in-order byte steam: no “message boundaries” pipelined: TCP congestion and flow control set window size send & receive buffers TCP Overview send() recv() send() 란 send buffer에 썼다는 의미이지, 보냈다는 의미가 아니다.

  5. 32 bits source port # dest port # sequence number acknowledgement number head len not used Receive window U A P R S F checksum Urg data pnter Options (variable length) application data (variable length) TCP segment structure URG: urgent data (generally not used) counting by bytes of data (not segments!) ACK: ACK # valid PSH: push data now (generally not used) # bytes rcvr willing to accept RST, SYN, FIN: connection estab (setup, teardown commands) Internet checksum (as in UDP)

  6. application application application transport transport transport P4 P2 P1 P1 P3 network network network link link link physical physical physical Multiplexing at send host: Demultiplexing at rcv host: host 3 host 2 host 1 Multiplexing/demultiplexing delivering received segments to correct socket gathering data from multiple sockets, enveloping data with header (later used for demultiplexing) = socket = process

  7. P2 P1 P1 P3 SP: 9157 client IP: A DP: 6428 Client IP:B server IP: C SP: 5775 SP: 6428 SP: 6428 DP: 6428 DP: 9157 DP: 5775 Connectionless demux (cont) DatagramSocket serverSocket = new DatagramSocket(6428); SP provides “return address”

  8. SP: 5775 SP: 9157 P1 P1 P2 P4 P3 P6 P5 client IP: A DP: 80 DP: 80 Connection-oriented demux (cont) S-IP: B D-IP:C SP: 9157 DP: 80 Client IP:B server IP: C S-IP: A S-IP: B D-IP:C D-IP:C

  9. Sockets Introduction

  10. Protocols and their Implementation • Protocol Implementation • 보통 transport layer 이하 protocol들은 kernel (OS) 내에 상주한다. Why? • Link layer는 H/W와이를컴퓨터에 장착하기 위한 S/W (예: Ethernet driver)로 구현된다. • Application protocol은 user process (즉, application) 으로 구현된다. • Client-server model • Internet에서 많은 application protocol은 이 model을 가정하고 있다. • Server는 여러 client의 요청을 동시에 처리할 수 있어야 한다. • Peer-to-peer model • Peer내에 client와 server 모두 가지고 있는 model로 생각할 수 있다. S/W H/W Ethernet Adapter Ethernet Adapter

  11. Socket API • API: Application Program Interface • User process가 kernel사이의 interface를 API라고 한며, 흔히 system call이라고 부른다. • Function call vs. system call • Socket API is an API for communications • 가장 널리 쓰이는 Communication API • 여러 protocol suite에 대해 generic API 제공 • Transport, network, link layer의 서비스를 받을 수 있는 API도 제공

  12. What is a socket? • A handle (or descriptor) to a data structure • Not a pointer! The data structure lives in the kernel. • UNIX/LINUX에서는 socket도 file 처럼 사용 가능 • sockfd = socket(PF_INET, SOCK_STREAM, 0); • user-level library of functions • send(sockfd, ...), recv(sockfd, …), … • a single system call via trap (special instruction causing software interrrupt) • sys_socketcall(SEND, sockfd, …) File, device socket

  13. Data Structure in Kernel (BSD) UDP socket creation sockfd=socket(PF_INET, SOCK_DGRAM, 0); • 프로세스에서는 handle (descriptor)로 socket structure를 찾을 수 있다. • Socket (file)에 대해 read, write, select, close 등의 일반적인 file operation을 socket 특성에 맞게 실행할 수 있다. • Incoming packet의 header를 보고 해당되는 socket을 찾을 수 있다. • TCP: (local addr, local port, foreign addr, foreign port) • Connected UDP socket인 경우에도 해당 • UDP: (local addr, local port) sockfd

  14. Sending and Receiving via Socket Client App Server App Socket descriptor Socket API (Operations) Transport Protocol Transport Protocol Recv buffer Send buffer Recv buffer Send buffer A TCP connection

  15. Socket Address Structures

  16. IPv4 Socket Address Structure • IPv4 SA structure • Generic SA structure • SA structure의 pointer를 casting할 때만 사용 • SA structure itself are used only on a given host, not used for communication POSIX datatypes always set to 0

  17. Elementary Sockets API

  18. local local local local local local foreign foreign foreign foreign foreign foreign 12.106.32.254 0 ? 0 ? 206.168.112.219 206.168.112.219 ? ? ? ? 12.106.32.254 1500 21 21 ? ? 21 ? ? 1500 21 ? ? TCP Client-Server Procedure 12.106.32.254 192.168.42.1 INADDR_ANY Listening socket (=3) 206.168.112.219 203.253.70.44 Connected socket (=4) TCP segment FIN

  19. TCP socket socket(): Create a Socket #include <sys/socket.h> /* UNIX */ #include <winsock2.h> /* Windows */ SOCKET socket (int family, int type, int protocol); Returns: socket descriptor on success, -1 (UNIX) or INVALID_SOCKET (Windows) on failure • Socket descriptor is a file descriptor in UNIX systems, but is not a file descriptor in Windows

  20. connect(): Establish the Connection TCP socket - client • Kernel은 미사용 중인 port 번호를 택하고, forwarding table을 loopkup하여 peer로 전송할 interface의 IP address를 source(local) IP 주소로 결정한다. • 3-way handshake • Error가 발생한 이유 • extern int errno; /* UNIX */ • GetLastError(); /* Windows */ • No response to SYN:connection timeout (ETIMEDOUT) • 다시 3번 retry후, 총 75초 지나면 error return • Response is RST: no such server process (ECONNREFUSED) • Receive ICMP unreachable error message: host unreachable (EHOSTUNREACH or ENETUNREACH) • connection이 실패하면, socket은 더 이상 사용할 수 없으므로 close()해야 한다. #include <sys/socket.h> /* UNIX */ #include <winsock2.h> /* Windows */ int connect (SOCKET s, const struct sockaddr *peer, int peer_len); Returns: 0 on success, -1 (UNIX) or nonzero (Windows) on failure

  21. send(), recv(): TCP Data Transmission #include <sys/socket.h> /* UNIX */ #include <winsock2.h> /* Windows */ int recv (SOCKET s, void *buf, size_t bufsize, int flags); int read (SOCKET s, void *buf, size_t bufsize); /* UNIX */ Returns: # of bytes read (>0), 0 if received FIN and no more data, -1 on failure int send (SOCKET s, const void *buf, size_t len, int flags); int write (SOCKET s, const void *buf, size_t len); /* UNIX */ Returns: # of bytes transferred on success, -1 on failure • Send: Put the message (of length len in buf) into the TCP(socket) send buffer • Blocked if not enough space in TCP send buffer • Recv: Get a message(<= bufsize) from the TCP(socket) receive buffer • Blocked until TCP receive buffer becomes non-empty • n-byte message를 send()했다고 해서, 수신측에서 recv()할 때 n-byte를 받는 게 아니다. TCP socket - client TCP connected socket - server

  22. bind(): Set My Address #include <sys/socket.h> /* UNIX */ #include <winsock2.h> /* Windows */ int bind (SOCKET s, const struct sockaddr *myaddr, int addrlen); Returns: 0 on success, -1 (UNIX) or SOCKET_ERROR (Windows) on error • If port # = 0, the kernel chooses a port (ephemeral port) • If wildcard address(INADDR_ANY), the kernel chooses IP addr • Example: IPv4 struct sockaddr_in servaddr; sockfd = socket(AF_INET, SOCK_STREAM, 0); bzero(&servaddr, sizeof(servaddr)); seraddr.sin_family = AF_INET; seraddr.sin_addr.s_addr = htonl(INADDR_ANY);/* wild card */ seraddr.sin_port = htons(13); /* Daytime server */ bind(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)); • Example: IPv6 struct sockaddr_in6 servaddr; seraddr.sin6_addr.s_addr =in6addr_any; /* wild card */ TCP listening socket - server

  23. listen(): Convert to the Listening Socket #include <sys/socket.h> /* UNIX */ #include <winsock2.h> /* Windows */ int listen (SOCKET s, int backlog); Returns: 0 on success, -1 (UNIX) or SOCKET_ERROR (Windows) on error • Listening socket: connection request를 accept할 수 있는 socket • 동시에 여러 개의 3-way handshaking 할 수 있게 queue가 필요함 • Queue size는 backlog(보통 5)로 정의 • 참고: backlog의 수는 실제 queue size와 일치하지 않고, OS 마다 다르다. • Data를 송수신 할 수 없음 • TCP state transition: CLOSED  LISTEN TCP listening socket - server queue

  24. accept(): Accept a Connection Request and create the Connected Socket TCP listening socket - server #include <sys/socket.h> /* UNIX */ #include <winsock2.h> /* Windows */ SOCKET accept (SOCKET s, struct sockaddr *cliaddr, int *addrlen); Returns: a connected socket on success, -1 (UNIX) or INVALID_SOCKET (Windows) on failure TCP connected socket - server • blocked if the completed connection queue is empty • If the identity of client is not interested, use NULL pointer instead ofcliaddr, addrlen

  25. close(): close the socket and terminate the TCP connection if no more used • Socket send buffer에 data가 남아 있으면보낸다 • Reference_count-- • 만일, 이 socket을 다른 프로세스와 공유하고 있다면(if reference_count > 0), return • 독점 사용하고 있다면 (if reference_count == o), 정상적인 TCP connection termination (graceful termination) 이 이루어진다. 즉, FIN, ACK를 교환한다. • Close 되면, 더 이상 send/recv 불가능 #include <unistd.h> /* UNIX */ #include <winsock2.h> /* Windows */ int close (SOCKET s); /* UNIX */ int closesocket (SOCKET s); /* Windows */ Returns: 0 on success, -1 on error Client가 server에게 request를 모두 보냈다고 알리고 싶다. (즉, FIN을 보내고 싶다.) 그러나, server로 부터의 response는 계속 도착할 것이고, 이를 recv()해야 한다. 방법은?

  26. Close decrease reference count close the socket only if count == 0 terminates both directions of data transfer: reading and writing Cannot read after close Shutdown initiate TCP’s normal termination regardless of reference count terminates one direction (half of connection) SHUT_RD (SD_RECEIVE, Windows): read-half of the connection is closed Any data currently in socket receive buffer is discarded Any data received after this call is acknowledged and then silently discarded SHUT_WR (SD_SEND, Windows): write-half of the connection is closed(half-close) Any data currently in socket send buffer will be sent SHUT_RDWR (SD_BOTH, Windows): read-half and write-half of connection are both closed SHUT_RD + SHUT_WR close versus shutdown #include <sys/socket.h> /* UNIX */ #include <winsock2.h> /* Windows */ int shutdown (SOCKET s, int howto); Returns: 0 on success, -1 on error

  27. When is getsockname function required ? client가 connect후 자신의 IP addr/port #를 알고자 할 때 0인 port #로 bind한 후 assign된 local port #를 알고자 할 때 socket의 address family를 알고자 할 때 server가 wildcard IP addr를 bind하여 connection이 이루어진 후(accept가 return된 후) local IP addr를 알고자 할 때 When is getpeername function required ? server가 accept후 child process가 fork되고 exec되면 client를 알 수 없음 (예, inetd) Finding Protocol Addresses from sockets #include <sys/socket.h> /* UNIX */ #include <winsock2.h> /* Windows */ int getsockname (SOCKET s, struct sockaddr *localaddr, int *addrlen); int getpeername (SOCKET s, struct sockaddr *peeraddr, int *addrlen); Returns: 0on success, -1 on error

  28. UDP Datagram Transmission • No connection is needed. • Recvfrom: 메시지를 recv하고 송신자(from) 확인 • If 0 returns : datagram of length 0 (???) • If no interest in senders address • from : NULL, addrlen : NULL • Recv할 때 마다 송신자가 다를 수 있다. • Sendto: 메시지를 수신자(to)에게 send • Send할 때 마다 수신자가 다를 수 있다. #include <sys/socket.h> /* UNIX */ #include <winsock2.h> /* Windows */ int recvfrom (SOCKET s, void *buf, size_t bufsize, int flags, struct sockaddr *from, int *fromlen); int sendto (SOCKET s, const void *buf, size_t len, int flags, const struct sockaddr *to, int tolen); Returns: datagram length on success, -1 on failure

  29. May Lost via UDP Socket Comm. • Lost datagram due to • lost in network • socket receive buffer overflow • UDP has no flow control • Lost되지 않았다면, UDP를 통한 송수신시 message 경계가 유지된다. • 송신한 메시지는 크기가 유지된 채로 수신된다. • 예외적으로, 수신된 메지지가 짤릴 수 있다. (truncated) • 수신된 메시지에 비트에러가 있을 수 있다.

  30. Connected UDP Socket • Call connect only to communication with exactly one peer • Kernel just records IP address and port # of the peer • Connected UDP socket • No need to specify the destination IP addr and port # for output operation • write, send instead of sendto • No need to verify received response • read, recv instead of recvfrom • Asynchronous errors are returned • Connected UDP socket provides better performance • Unconnected UDP socket: make a temporary connection(1/3 overhead) • May connect multiple times for a UDP socket by specifying a new IP addr and port # 하나의 지정된 상대와 UDP 통신할 때는 TCP처럼 connect()하여 send(), recv() 하는 편이 좋다.

  31. Miscellaneous Functions

  32. Value-Result Arguments • SA structure are always passed by reference • process to kernel: bind, connect, sendto • kernel to process: accept, recvfrom, getsockname,getpeername struct sockaddr

  33. Byte Ordering 프로토콜에서 그대로 header에 싣을 수 있도록 Network address와 port는항상 network byte order로 저장되어야 한다. 그러나, 컴퓨터 종류에 따라 byte 저장 순서가 다를 수 있다. • Host Byte Order  Network Byte Order un.c[1] 0000 0001 0000 0010 un.c[0] 0000 0001 0000 0010 un.c[0] un.c[1]

  34. Byte Manipulation Functions • 4.3BSD • ANSI C: a = b; style !!

  35. IPv4 Address Conversion • Functions only for IPv4, not for IPv6 • Dotted decimal(a string)  32-bit IP address • What about 255.255.255.255? • 32-bit IP address  Dotted decimal • Not reentrant, not thread-safe • Function 내부에서 결과를 저장할 공간을 static memory로 잡아서, function call 때 마다 같은 영역을 쓰기 때문

  36. IPv4/IPv6 Address Conversion • Functions for IPv6: work with both IPv6 and IPv4

More Related