Transmission Control Protocol (TCP). TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581 r reliable, in-order byte steam: m no “message boundaries” r send.

Slides:



Advertisements
Similar presentations
Transportation Layer (2). TCP full duplex data: – bi-directional data flow in same connection – MSS: maximum segment size connection-oriented: – handshaking.
Advertisements

TCP - Part I Relates to Lab 5. First module on TCP which covers packet format, data transfer, and connection management.
Transportation Layer. Very similar to the data link layer. – two hosts connected by a link or two hosts connected by a network differences: – When two.
TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581 point-to-point:
Transport Layer3-1 TCP. Transport Layer3-2 TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581 r full duplex data: m bi-directional data flow in same connection.
1 Chapter 3 Transport Layer Computer Networking: A Top Down Approach 4 th edition. Jim Kurose, Keith Ross Addison-Wesley, July A note on the use.
3-1 TCP Protocol r point-to-point: m one sender, one receiver r reliable, in-order byte steam: m no “message boundaries” r pipelined: m TCP congestion.
Data Communications and Computer Networks Chapter 3 CS 3830 Lecture 16 Omar Meqdadi Department of Computer Science and Software Engineering University.
1 Chapter 3 Transport Layer. 2 Chapter 3 outline 3.1 Transport-layer services 3.2 Multiplexing and demultiplexing 3.3 Connectionless transport: UDP 3.4.
1 Transport Layer Lecture 9 Imran Ahmed University of Management & Technology.
CS 471/571 Transport Layer 5 Slides from Kurose and Ross.
CSE551: Computer Network Review r Network Layers r TCP/UDP r IP.
1 TCP - Part I Relates to Lab 5. First module on TCP which covers packet format, data transfer, and connection management.
Transport Layer3-1 Summary of Reliable Data Transfer Checksums help us detect errors ACKs and NAKs help us deal with errors If ACK/NAK has errors sender.
1 CS 4396 Computer Networks Lab Transmission Control Protocol (TCP) Part I.
Week 9 TCP9-1 Week 9 TCP 3 outline r 3.5 Connection-oriented transport: TCP m segment structure m reliable data transfer m flow control m connection management.
CSci4211: Transport Layer:Part I1 Transport Layer: Part I  Transport Layer Services  connection-oriented vs. connectionless  multiplexing and demultplexing.
Computer Networks 2 Lecture 2 TCP – I - Transport Protocols: TCP Segments, Flow control and Connection Setup.
TCP segment structure source port # dest port # 32 bits application data (variable length) sequence number acknowledgement number rcvr window size ptr.
Elementary TCP Sockets Computer Networks Computer Networks Term B10 UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
EEC-484/584 Computer Networks Lecture 15 Wenbing Zhao (Part of the slides are based on Drs. Kurose & Ross ’ s slides for their Computer.
Transport Layer 3-1 Transport Layer r To learn about transport layer protocols in the Internet: m TCP: connection-oriented protocol m Reliability protocol.
EEC-484/584 Computer Networks Lecture 7 Wenbing Zhao (Part of the slides are based on Drs. Kurose & Ross ’ s slides for their Computer.
CSE 461: Transport Layer Connections. Naming Processes/Services  Process here is an abstract term for your Web browser (HTTP), servers (SMTP),
Transport Layer Transport Layer: TCP. Transport Layer 3-2 TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581 r full duplex data: m bi-directional.
Transport Layer 3-1 Transport Layer r To learn about transport layer protocols in the Internet: m TCP: connection-oriented protocol m Reliability protocol.
UDP: User Datagram Protocol. UDP: User Datagram Protocol [RFC 768] r “bare bones”, “best effort” transport protocol r connectionless: m no handshaking.
1 Announcement r Project 2 out m Much harder than project 1, start early! r Homework 2 due next Tuesday.
Chapter 3 Transport Layer
Transport Layer3-1 Data Communication and Networks Lecture 7 Transport Protocols: TCP October 21, 2004.
TCP/IP Sockets in C: Practical Guide for Programmers Michael J. Donahoo Kenneth L. Calvert.
EEC-484/584 Computer Networks Lecture 13 Wenbing Zhao (Part of the slides are based on Drs. Kurose & Ross ’ s slides for their Computer.
1 Ch. 7 : Internet Transport Protocols. Transport Layer Our goals: r understand principles behind transport layer services: m Multiplexing / demultiplexing.
EEC-484/584 Computer Networks Lecture 13 Wenbing Zhao (Part of the slides are based on Drs. Kurose & Ross ’ s slides for their Computer.
Transport Layer1 Reliable Transfer Ram Dantu (compiled from various text books)
Transport Layer 3-1 Chapter 3 Transport Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012 All.
3: Transport Layer3b-1 TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581 r full duplex data: m bi-directional data flow in same connection m MSS: maximum.
2: Transport Layer 21 Transport Layer 2. 2: Transport Layer 22 TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581 r full duplex data: m bi-directional data.
TCOM 509 – Internet Protocols (TCP/IP) Lecture 04_b Transport Protocols - TCP Instructor: Dr. Li-Chuan Chen Date: 09/22/2003 Based in part upon slides.
TCP : Transmission Control Protocol Computer Network System Sirak Kaewjamnong.
1 Writing Network Applications using the TCP/IP Protocol Stack: Socket Programming.
Fall 2005 By: H. Veisi Computer networks course Olum-fonoon Babol Chapter 6 The Transport Layer.
Transport Layer3-1 Chapter 3: Transport Layer Our goals: r understand principles behind transport layer services: m multiplexing/demultipl exing m reliable.
The Pocket Guide to TCP/IP Sockets: C Version Michael J. Donahoo Kenneth L. Calvert.
Elementary TCP Sockets UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
Transport Layer3-1 Transport Layer Our lives begin to end, the day we become silent about things that matter.
September 26 th, 2013 CS1652 The slides are adapted from the publisher’s material All material copyright J.F Kurose and K.W. Ross, All Rights.
7: TCP Last Modified: 4/26/2017 1:52:15 PM 3: Transport Layer.
Transport Layer3-1 Chapter 3 Transport Layer Computer Networking: A Top Down Approach 5 th edition. Jim Kurose, Keith Ross Addison-Wesley, April 2009.
Transport Layer3-1 Chapter 3 outline r 3.1 Transport-layer services r 3.2 Multiplexing and demultiplexing r 3.3 Connectionless transport: UDP r 3.4 Principles.
Transport Layer3-1 Transport Layer If you are going through Hell Keep going.
CSEN 404 Transport Layer II Amr El Mougy Lamia AlBadrawy.
1 Transmission Control Protocol (TCP) RFC: Introduction The TCP is intended to provide a reliable process-to-process communication service in a.
DMET 602: Networks and Media Lab Amr El Mougy Yasmeen EssamAlaa Tarek.
3. END-TO-END PROTOCOLS (PART 1) Rocky K. C. Chang Department of Computing The Hong Kong Polytechnic University 22 March
09-Transport Layer: TCP Transport Layer.
Chapter 3 outline 3.1 Transport-layer services
DMET 602: Networks and Media Lab
5. End-to-end protocols (part 1)
The Pocket Guide to TCP/IP Sockets: C Version
Review: UDP demultiplexing TCP demultiplexing Multiplexing?
TCP/IP Sockets in C: Practical Guide for Programmers
Socket Programming in C
TCP/IP Sockets in C: Practical Guide for Programmers
TCP/IP Sockets in C: Practical Guide for Programmers
7: TCP Last Modified: 4/10/ :16:43 AM 3: Transport Layer.
Transportation Layer.
TCP - Part I Relates to Lab 5. First module on TCP which covers packet format, data transfer, and connection management.
TCP/IP Sockets in C: Practical Guide for Programmers
TCP Connection Management
Presentation transcript:

Transmission Control Protocol (TCP)

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

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

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

TCP Demultiplexing Example Client IP:B P client IP: A P1P server IP: C SP: 80 DP: 9157 SP: 9157 DP: 80 SP: 80 DP: 5775 SP: 5775 DP: 80 PP

Connection Termination Reliable, In-Order Data Exchange Connection Establishment Typical TCP Transaction Client Server time r A TCP Transaction consists of 3 Phases 1. Connection Establishment mHandshaking between client and server 2. Reliable, In-Order Data Exchange mRecover any lost data through retransmissions and ACKs 3. Connection Termination mClosing the connection

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

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

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

TCP Starting Sequence Number Selection r Why a random starting sequence #? Why not simply choose 0? m To protect against two incarnations of the same connection reusing the same sequence numbers too soon m 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 r How? m Client machine seq #0, initiates connection to server with seq #0. m Client sends one byte and client machine crashes m Client reboots and initiates connection again m Server thinks new incarnation is the same as old connection

TCP Connection Termination 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. client FIN server ACK FIN close Data write closed timed wait close ACK DATA

TCP Connection Termination Step 3: client receives FIN, replies with ACK. m Enters “timed wait” - will respond with ACK to received FINs Step 4: server, receives ACK. Connection closed. r Why wait before closing the connection? m 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 FIN server ACK FIN closing closed timed wait closed

CLOSED LISTEN SYN_RCVDSYN_SENT ESTABLISHED CLOSE_WAIT LAST_ACKCLOSING TIME_WAIT FIN_WAIT_2 FIN_WAIT_1 Passive openClose Send/SYN SYN/SYN + ACK SYN + ACK/ACK SYN/SYN + ACK ACK Close/FIN FIN/ACKClose/FIN FIN/ACK ACK + FIN/ACK Timeout after two segment lifetimes FIN/ACK ACK Close/FIN Close CLOSED Active open/SYN TCP State-Transition Diagram

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

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

Socket Creation FamilyType Protocol TCP PF_INET SOCK_STREAMIPPROTO_TCP UDPSOCK_DGRAMIPPROTO_UDP r mySock = socket(family, type, protocol); r UDP/TCP/IP-specific sockets r Socket reference m File (socket) descriptor in UNIX m Socket handle in WinSock

TCP Client/Server Interaction Client 1. Create a TCP socket 2. Establish connection 3. Communicate 4. Close the connection Server 1. Create a TCP socket 2. Assign a port to socket 3. Set socket to listen 4. Repeatedly: a. Accept new connection b. Communicate c. Close the connection Server starts by getting ready to receive client connections…

TCP Client/Server Interaction Client 1. Create a TCP socket 2. Establish connection 3. Communicate 4. Close the connection Server 1. Create a TCP socket 2. Bind socket to a port 3. Set socket to listen 4. Repeatedly: a. Accept new connection b. Communicate c. Close the connection /* Create socket for incoming connections */ if ((servSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) DieWithError("socket() failed");

TCP Client/Server Interaction Client 1. Create a TCP socket 2. Establish connection 3. Communicate 4. Close the connection Server 1. Create a TCP socket 2. Bind socket to a port 3. Set socket to listen 4. Repeatedly: a. Accept new connection b. Communicate c. Close the connection 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");

TCP Client/Server Interaction Client 1. Create a TCP socket 2. Establish connection 3. Communicate 4. Close the connection Server 1. Create a TCP socket 2. Bind socket to a port 3. Set socket to listen 4. Repeatedly: a. Accept new connection b. Communicate c. Close the connection /* Mark the socket so it will listen for incoming connections */ if (listen(servSock, MAXPENDING) < 0) DieWithError("listen() failed");

TCP Client/Server Interaction Client 1. Create a TCP socket 2. Establish connection 3. Communicate 4. Close the connection Server 1. Create a TCP socket 2. Bind socket to a port 3. Set socket to listen 4. Repeatedly: a. Accept new connection b. Communicate c. Close the connection for (;;) /* Run forever */ { clntLen = sizeof(echoClntAddr); if ((clntSock=accept(servSock,(struct sockaddr *)&echoClntAddr,&clntLen)) < 0) DieWithError("accept() failed");

TCP Client/Server Interaction Client 1. Create a TCP socket 2. Establish connection 3. Communicate 4. Close the connection Server 1. Create a TCP socket 2. Bind socket to a port 3. Set socket to listen 4. Repeatedly: a. Accept new connection b. Communicate c. Close the connection Server is now blocked waiting for connection from a client

TCP Client/Server Interaction Client 1. Create a TCP socket 2. Establish connection 3. Communicate 4. Close the connection Server 1. Create a TCP socket 2. Bind socket to a port 3. Set socket to listen 4. Repeatedly: a. Accept new connection b. Communicate c. Close the connection Later, a client decides to talk to the server…

TCP Client/Server Interaction Client 1. Create a TCP socket 2. Establish connection 3. Communicate 4. Close the connection Server 1. Create a TCP socket 2. Bind socket to a port 3. Set socket to listen 4. Repeatedly: a. Accept new connection b. Communicate c. Close the connection /* Create a reliable, stream socket using TCP */ if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) DieWithError("socket() failed");

TCP Client/Server Interaction Client 1. Create a TCP socket 2. Establish connection 3. Communicate 4. Close the connection Server 1. Create a TCP socket 2. Bind socket to a port 3. Set socket to listen 4. Repeatedly: a. Accept new connection b. Communicate c. Close the connection 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");

TCP Client/Server Interaction Client 1. Create a TCP socket 2. Establish connection 3. Communicate 4. Close the connection Server 1. Create a TCP socket 2. Bind socket to a port 3. Set socket to listen 4. Repeatedly: a. Accept new connection b. Communicate c. Close the connection 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");

TCP Client/Server Interaction Client 1. Create a TCP socket 2. Establish connection 3. Communicate 4. Close the connection Server 1. Create a TCP socket 2. Bind socket to a port 3. Set socket to listen 4. Repeatedly: a. Accept new connection b. Communicate c. Close the connection /* Receive message from client */ if ((recvMsgSize = recv(clntSocket, echoBuffer, RCVBUFSIZE, 0)) < 0) DieWithError("recv() failed");

TCP Client/Server Interaction Client 1. Create a TCP socket 2. Establish connection 3. Communicate 4. Close the connection Server 1. Create a TCP socket 2. Bind socket to a port 3. Set socket to listen 4. Repeatedly: a. Accept new connection b. Communicate c. Close the connection close(sock); close(clntSocket)

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