1 / 70

Transmission Control Protocol (TCP)

Transmission Control Protocol (TCP). Telnet. FTP. DNS. Uygulama. Uygulama. Sunum. Oturum. TCP. UDP. Taşıma. Taşıma. IP. ICMP. ARP. Ağ. Ağ. Veri İletim. SLIP ve PPP. L AN. W AN. Fiziksel. Fiziksel. OSI. TCP /IP. OSI vs. TCP/IP. Uygulama Katmanı (Application Layer)

keegan-noel
Download Presentation

Transmission Control Protocol (TCP)

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. Transmission Control Protocol (TCP)

  2. Telnet FTP DNS Uygulama Uygulama Sunum Oturum TCP UDP Taşıma Taşıma IP ICMP ARP Ağ Ağ Veri İletim SLIP ve PPP LAN WAN Fiziksel Fiziksel OSI TCP/IP OSI vs. TCP/IP • Uygulama Katmanı (Application Layer) • Taşıma Katmanı (Transport Layer) • Ağ Katmanı (Network Layer/Internet Layer/Internetwork Layer) • Fiziksel Katman (Network Access Layer/Link and Physical Layer)

  3. reliable, in-order byte steam: no “message boundaries” send & receive buffers buffer incoming & outgoing data flow controlled: sender will not overwhelm receiver congestion controlled: sender will not overwhelm network point-to-point (unicast): one sender, one receiver connection-oriented: handshaking (exchange of control msgs) init’s sender, receiver state before data exchange State resides only at the END systems – Not a virtual circuit! full duplex data: bi-directional data flow in same connection (A->B & B->A in the same connection) MSS: maximum segment size TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581

  4. 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)

  5. TCP socket identified by 4-tuple: source IP address source port number dest IP address dest port number receiving host uses all four values to direct segment to appropriate socket TCP Connection-oriented demux

  6. P P P1 P P SP: 5775 SP: 80 SP: 80 DP: 9157 DP: 80 DP: 5775 TCP Demultiplexing Example SP: 9157 client IP: A Client IP:B server IP: C DP: 80

  7. A TCP Transaction consists of 3 Phases Connection Establishment Handshaking between client and server Reliable, In-Order Data Exchange Recover any lost data through retransmissions and ACKs Connection Termination Closing the connection time time Typical TCP Transaction Server Client Connection Establishment Reliable, In-Order Data Exchange Connection Termination

  8. TCP sender, receiver establish “connection” before exchanging data segments initialize TCP variables: seq. #s buffers, flow control info (e.g. RcvWindow) client: connection initiator Socket clientSocket = new Socket("hostname", port#); server: contacted by client Socket connectionSocket = welcomeSocket.accept(); TCP Connection Establishment

  9. Three way handshake: Step 1:client host sends TCP SYN segment to server specifies a random initial seq # no data Step 2:server host receives SYN, replies with SYNACK segment server allocates buffers specifies server initial seq. # Step 3: client receives SYNACK, replies with ACK segment, which may contain data time time Connection Establishment (cont) Host B Host A Connection request SYN, Seq=42 host ACKs and selects its own initial seq # SYN+ACK, Seq=79, ACK=43 host ACKs ACK, Seq=43, ACK=80 Three-way handshake

  10. Seq. #’s: byte stream “number” of first byte in segment’s data ACKs: seq # of next byte expected from other side cumulative ACK time time Connection Establishment (cont) Host B Host A Connection request SYN, Seq=42 host ACKs and selects its own initial seq # SYN+ACK, Seq=79, ACK=43 host ACKs ACK, Seq=43, ACK=80 Three-way handshake

  11. TCP Starting Sequence Number Selection • Why a random starting sequence #? Why not simply choose 0? • To protect against two incarnations of the same connection reusing the same sequence numbers too soon • That is, while there is still a chance that a segment from an earlier incarnation of a connection will interfere with a later incarnation of the connection • How? • Client machine seq #0, initiates connection to server with seq #0. • Client sends one byte and client machine crashes • Client reboots and initiates connection again • Server thinks new incarnation is the same as old connection

  12. Closing a connection: client closes socket:clientSocket.close(); Step 1:client end system sends TCP FIN control segment to server Step 2:server receives FIN, replies with ACK. Server might send some buffered but not sent data before closing the connection. Server then sends FIN and moves to Closing state. TCP Connection Termination client server close FIN ACK Data write DATA ACK FIN close timed wait ACK closed

  13. Step 3:client receives FIN, replies with ACK. Enters “timed wait” - will respond with ACK to received FINs Step 4:server, receives ACK. Connection closed. Why wait before closing the connection? If the connection were allowed to move to CLOSED state, then another pair of application processes might come along and open the same connection (use the same port #s) and a delayed FIN from an earlier incarnation would terminate the connection. client server closing FIN ACK closing FIN ACK timed wait closed closed TCP Connection Termination

  14. CLOSED Active open /SYN Passive open Close Close LISTEN SYN/SYN + ACK Send/ SYN SYN/SYN + ACK SYN_RCVD SYN_SENT ACK SYN + ACK/ACK Close /FIN ESTABLISHED Close /FIN FIN/ACK FIN_WAIT_1 CLOSE_WAIT FIN/ACK ACK Close /FIN ACK + FIN/ACK FIN_WAIT_2 CLOSING LAST_ACK Timeout after two ACK ACK segment lifetimes FIN/ACK TIME_WAIT CLOSED TCP State-Transition Diagram

  15. Typical TCP Client/Server Transitions TCP server lifecycle TCP client lifecycle

  16. TCP UDP IP LL PL TCP UDP IP LL PL TCP UDP IP LL PL Socket Layer Socket Layer Socket Layer How to program using the TCP? • Socket Layer: • Programmer’s API to the protocol stack • Typical network app has two pieces: client and server • Server: Passive entity.Provides service to clients • e.g., Web server responds with the requested Web page • Client: initiates contact with server (“speaks first”) • typically requests service from server, e.g., Web Browser

  17. Socket Creation • mySock = socket(family, type, protocol); • UDP/TCP/IP-specific sockets • Socket reference • File (socket) descriptor in UNIX • Socket handle in WinSock

  18. 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 Server starts by getting ready to receive client connections…

  19. 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 /* Create socket for incoming connections */ if ((servSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) DieWithError("socket() failed");

  20. 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 echoServAddr.sin_family = AF_INET; /* Internet address family */ echoServAddr.sin_addr.s_addr = htonl(INADDR_ANY);/* Any incoming interface */ echoServAddr.sin_port = htons(echoServPort); /* Local port */ if (bind(servSock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0) DieWithError("bind() failed");

  21. 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 /* Mark the socket so it will listen for incoming connections */ if (listen(servSock, MAXPENDING) < 0) DieWithError("listen() failed");

  22. 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 for (;;) /* Run forever */ { clntLen = sizeof(echoClntAddr); if ((clntSock=accept(servSock,(struct sockaddr *)&echoClntAddr,&clntLen)) < 0) DieWithError("accept() failed");

  23. 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

  24. 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 Later, a client decides to talk to the server…

  25. 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 /* Create a reliable, stream socket using TCP */ if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) DieWithError("socket() failed");

  26. 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 echoServAddr.sin_family = AF_INET; /* Internet address family */ echoServAddr.sin_addr.s_addr = inet_addr(servIP); /* Server IP address */ echoServAddr.sin_port = htons(echoServPort); /* Server port */ if (connect(sock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0) DieWithError("connect() failed");

  27. 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 echoStringLen = strlen(echoString); /* Determine input length */ /* Send the string to the server */ if (send(sock, echoString, echoStringLen, 0) != echoStringLen) DieWithError("send() sent a different number of bytes than expected");

  28. 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 */ if ((recvMsgSize = recv(clntSocket, echoBuffer, RCVBUFSIZE, 0)) < 0) DieWithError("recv() failed");

  29. 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 close(sock); close(clntSocket)

  30. Client send(“Hello Bob”) recv() -> “Hi Jane” Server recv() -> “Hello ” recv() -> “Bob” send(“Hi ”) send(“Jane”) TCP Tidbits • Client knows server address and port • No correlation between send() and recv()

  31. Uygulama Katmanı Protokolleri • DNS (Domain Name System-Alan Adı Sistemi) • Alan adı verilen isimler (www.gazi.edu.tr) ile IP adreslerini (194.27.16.10) birbirine bağlayan sistemdir. • Paylaştırılmış bir veritabanı olarak çalışır. • HTTP (HyperText Transfer Protocol-Hiper Metin Gönderme Protokolü) • HTML sayfaları göndermek vb… • HTTPS (Secure HTTP-Güvenli HTTP) • HTTP'nin RSA (İki anahtarlı şifreleme veya asimetrik anahtarlı şifreleme) şifrelemesi ile güçlendirilmiş halidir. Örneğin bankaların internet siteleri. • FTP (File Transfer Protocol) • SFTP veya FTPS (Secure FTP), • FTP'nin RSA ile güçlendirilmiş halidir.

  32. Uygulama Katmanı Protokolleri • DHCP (Dynamic Host Configuration Protocol) • Terminallere otomatik ip adresi dağıtır. • SNMP (Simple Network Managment Protocol- Basit Ağ Yönetimi Protokolü) • Ağlar büyüdükçe bu ağlar üzerindeki birimleri denetlemek amacıyla tasarlanmıştır. • PC’ye bağlı kullanıcılar, internet bağlantı hızı, sistem çalışma süresi vb. bilgiler tutulur. • NFS (Network File System-Ağ Dosya Sistemi) • Ağdaki paylaştırılmış dosyalara ulaşmayı sağlar • LPD (Line Printer Daemon) • Ağdaki yazıcının kullanılmasını sağlar.

  33. Uygulama Katmanı Protokolleri • SMTP (Simple Mail Transfer Protocol, - Basit Posta Gönderme Protokolü) • E-posta göndermek için kullanılır. • POP3 (Post Office Protocol 3) • E-posta almak için kullanılır. • Telnet (Telecommunication Network) • Çok kullanıcılı bir makineye uzaktaki başka bir makineden bağlanmak için kullanılır.

  34. Fiziksel Katman Protokolleri • SLIP (Serial Line Internet Protocol) • IP verilerinin, seri iletişim teknikleri ile iletimini sağlayan protokoldür. Dial-up veya kiralık hat bağlantılarında kullanılır. Veriler seri iletişim teknikleri kullanılarak iletilir. • PPP (Point-to-Point Protocol) • SLIP’e benzer, yine dial-up bağlantıda kullanılır. Ancak PPP; • Verileri sıkıştırır • Bir çok donanım çoğunlukla destekler • Hata düzeltme ve belirleme algoritmaları kullanır.

  35. Taşıma Katmanı Protokolleri • TCP (Transmission Control Protocol-Transfer Kontrol Protokolü) • Veri aktarımı yapılacak iki bilgisayar arasındaki bağlantıyı kurar • Hata denetimi yapar. Paketler gitmediyse bir daha gönderir. • UDP (User Datagram Protocol) • TCP gibi ağ üzerinden paketi gönderir ama bu protokol paketin gidip gitmediğini takip etmez ve paketin yerine ulaşıp ulaşmayacağını garantilemez. Daha çok küçük paketlerin tüm PC’lere gönderilmesinde kullanılır.

  36. TCP Başlığı (TCP Header)

  37. UDP Başlığı

  38. Ağ Katmanı Protokolleri • ICMP (Internet Control Message Protocol): • Paketin gönderilmesi sırasında hata oluştuğunda mesaj veya rapor gönderir. • Ping komutu • ARP (Address Resolution Protocol) • Yerel ağdaki adresleri veya donanım adreslerini (MAC adres) ön bellekler. • MAC adresi ağ adresine ve ağ adresini de MAC adresine çevirir. • IGMP (Internet Group Management Protocol) • Belli bir gruptaki hostları, multicast (Bir gönderici ile ağ üzerinde birden fazla alıcı arasında kurulan iletişimbir grup) router’a bildirir.

  39. Ağ Katmanı Protokolleri • IP (Internet Protocol) • IP adresi bir ağa bağlı bilgisayarların ağ üzerinden birbirlerine veri yollamak için kullandıkları adrestir. • IP Başlığı:

  40. IP (Internet Protocol) • Yaygın olarak IPv4 adresler kullanılıyor. • Toplam 32 bit ve noktalarla ayrılmış 4 adet 8 bitlik sayı. • Örnek bir IP adresi: • 10000000 10011100 00001110 00000111 • w.x.y.z • 128.156.14.7 • Ip adresleri dünyada 232 = 4 milyardır. • Dinamik ip adresleri : Evden modem ile bağlanma • Statik ip adresleri: IIS

  41. IPv4 Adresleme • D sınıfı 224-239 ve ağ 28 bit ile gösterilir. • 240 ve üzeri E sınıfı • 127 ile başlayan adresler : Bir makinenin kendisi ile konuşması (loopback) • Localhost: 127.0.0.1 • İlk oktet 0 veya 255 olamaz.

  42. Ayrılmış IP Adresler • Bazı IP adresleri bazı kullanımlar için ayrılmıştır. Yerel ağlar için ayrılmış adresler: • 10.0.0.0 - 10.255.255.255 • 172.16.0.0 - 172.31.255.255 • 192.168.0.0 - 192.168.255.255 • 169.254.0.0 - 169.254.255.255 • 0  bir ağı göstermektedir • 255  broadcast adres; bir ağ içerisindeki tüm PC’ler

  43. Ağ ve Broadcast Numaraları • C sınıfı 129.23.123.2 adres için; • Ağ numarası: 129.23.123.0 • Bu ağdaki tüm PC’lere mesaj göndermek isteyen bir cihaz şu adrese mesajı atacaktır; • 129.23.123.255 • B sınıfı 124.50.120.2 adres için; • Ağ numarası: 124.50.0.0 • Bu ağdaki tüm PC’lere mesaj göndermek isteyen bir cihaz şu adrese mesajı atacaktır; • 124.50.255.255

  44. Alt Ağ Maskesi (Subnet Mask) • Ağdaki iki bilgisayarın veya cihazın aynı ağda olduklarını anlamalarını sağlar. 255.0.0.0  (11111111.00000000.00000000.00000000 255.255.0.0  (11111111. 11111111.00000000.00000000 255.255.255.0  (11111111. 11111111. 11111111.00000000

  45. 32-bit 18.26.0.1 Host (Pc veya cihaz) ağ ağhost 824 bit A Sınıfı (1-126) IP adres: 18.26.0.1 Ağ adresi: 18.0.0.0 Alt Ağ maskesi: 255.0.0.0 Broadcast adres: 18.255.255.255

  46. ağhost 1616 bit 32-bit 181.26.0.1 Host (Pc veya cihaz) ağ B Sınıfı (128-191) IP adres: 181.26.0.1 Ağ adresi: 181.26.0.0 Alt Ağ maskesi: 255.255.0.0 Broadcast adres: 181.26.255.255

  47. C Sınıfı (192-223) IP adres: 194.26.5.1 Ağ adresi: 194.26.5.0 Alt Ağ maskesi: 255.255.255.0 Broadcast adres: 194.26.5.255 ağhost 248 bit 32-bit 194.26.5.1 Host (Pc veya cihaz) ağ

  48. Alıştırma • 131.107.20.4 • 208.234.23.4 • 108.15.45.4 • Yukarıdaki adreslerin • IP sınıfını • Alt ağ maske numarasını • Bağlı olduğu ağ numarasını • Broadcast adreslerini yazınız.

More Related