EEC484584 Computer Networks Lecture 13 Wenbing Zhao wenbingieee
EEC-484/584 Computer Networks Lecture 13 Wenbing Zhao wenbing@ieee. org (Part of the slides are based on Drs. Kurose & Ross’s slides for their Computer Networking book)
2 Outline • Discussion on Socket • UDP • TCP – Segment header structure – Connection management Spring Semester 2008 EEC-484/584: Computer Networks Wenbing Zhao
3 TCP Connection and Socket • “TCP demultiplexes incoming segments using all four values that comprise the local and foreign address” – TCP/IP Illustrated, Vol. 1 W. Richard Stevens, p. 255 Spring Semester 2008 EEC-484/584: Computer Networks Wenbing Zhao
4 UDP: User Datagram Protocol • “No frills, ” “bare bones” Internet transport protocol • “Best effort” service, UDP segments may be: – Lost – Delivered out of order to app • Connectionless: – No handshaking between UDP sender, receiver – Each UDP segment handled independently of others Spring Semester 2008 EEC-484/584: Computer Networks Wenbing Zhao
5 Why is There a UDP? • No connection establishment (which can add delay) • Simple: no connection state at sender and receiver • Small segment header • No congestion control: UDP can blast away as fast as desired Spring Semester 2008 EEC-484/584: Computer Networks Wenbing Zhao
6 UDP • Often used for streaming multimedia apps Length, in – Loss tolerant bytes of UDP segment, – Rate sensitive • Other UDP uses 32 bits source port # dest port # length checksum including header – DNS – SNMP • Reliable transfer over UDP: add reliability at application layer Spring Semester 2008 EEC-484/584: Computer Networks Application data (message) UDP segment format Wenbing Zhao
7 UDP Checksum Goal: detect “errors” (e. g. , flipped bits) in transmitted segment Sender: Receiver: • treat segment contents as • compute checksum of received segment sequence of 16 -bit integers • check if computed • checksum: addition (1’s checksum equals complement sum) of checksum field value: segment contents – NO - error detected • sender puts checksum – YES - no error detected. But value into UDP checksum maybe errors nonetheless? field Spring Semester 2008 EEC-484/584: Computer Networks Wenbing Zhao
Internet Checksum Example • When adding numbers, a carryout from the most significant bit needs to be added to the result • Example: add two 16 -bit integers 1 1 1 0 0 1 1 0 1 0 1 wraparound 1 1 0 1 1 sum checksum 1 0 1 1 0 0 0 1 0 0 1 1 To know more: http: //www. netfor 2. com/udpsum. htm http: //www. netfor 2. com/checksum. html Spring Semester 2008 EEC-484/584: Computer Networks Wenbing Zhao 8
9 TCP: Overview • Full duplex data: • Point-to-point: – One sender, one receiver • Reliable, in-order byte steam: – No “message boundaries” • Pipelined: – TCP congestion and flow control set window size • Send & receive buffers – Bi-directional data flow in same connection – MSS: maximum segment size • Connection-oriented: – Handshaking (exchange of control msgs) init’s sender, receiver state before data exchange • Flow controlled: – Sender will not overwhelm receiver Spring Semester 2008 EEC-484/584: Computer Networks Wenbing Zhao
10 TCP: Overview • TCP connection is byte stream, not message stream, no message boundaries • TCP may send immediately or buffer before sending • Receiver stores the received bytes in a buffer Spring Semester 2008 EEC-484/584: Computer Networks Wenbing Zhao
11 TCP Segment Structure 32 bits URG: urgent data (generally not used) ACK: ACK # valid PSH: push data now (generally not used) RST, SYN, FIN: connection estab (setup, teardown commands) Internet checksum (as in UDP) Spring Semester 2008 source port # dest port # sequence number acknowledgement number head not UA P R S F len used checksum Receive window Urg data pnter Options (variable length) application data (variable length) EEC-484/584: Computer Networks counting by bytes of data (not segments!) # bytes rcvr willing to accept A TCP segment must fit into an IP datagram! Wenbing Zhao
The TCP Segment Header • Source port and destination port: identify local end points of the connection – Source and destination end points together identify the connection • Sequence number: identify the byte in the stream of data that the first byte of data in this segment represents • Acknowledgement number: the next sequence number that the sender of the ack expects to receive – Ack # = Last received seq num + 1 – Ack is cumulative: an ack of 5 means 0 -4 bytes have been received • TCP header length – number of 32 -bit words in header Spring Semester 2008 EEC-484/584: Computer Networks Wenbing Zhao 12
The TCP Segment Header • URG – indicates urgent pointer field is set • Urgent pointer – points to the seq num of the last byte in a sequence of urgent data • ACK – acknowledgement number is valid • SYN – used to establish a connection – Connection request: ACK = 0, SYN = 1 – Connection confirm: ACK=1, SYN = 1 • FIN – release a connection, sender has no more data • RST – reset a connection that is confused • PSH – sender asked to send data immediately Spring Semester 2008 EEC-484/584: Computer Networks Wenbing Zhao 13
The TCP Segment Header • Receiver window size –number of bytes that may be sent beyond the byte acked • Checksum – add the header, the data, and the conceptual pseudoheader as 16 -bit words, take 1’s complement of sum – For more info: http: //www. netfor 2. com/tcpsum. htm http: //www. netfor 2. com/checksum. html • Options – provides a way to add extra facilities not covered by the regular header – E. g. , communicate buffer sizes during set up Spring Semester 2008 EEC-484/584: Computer Networks Wenbing Zhao 14
15 TCP Sequence Numbers and ACKs Host B Host A Sequence numbers: – byte stream “number” of first byte in segment’s data User types ‘C’ Seq=4 2, ACK = ACKs: 79, da ta ata = d , 3 4 K= – seq # of next byte expected from other side – cumulative ACK , AC q=79 Se host ACKs receipt of echoed ‘C’ = ‘C’ host ACKs receipt of ‘C’, echoes back ‘C’ Seq=4 3, ACK =80 simple telnet scenario Spring Semester 2008 EEC-484/584: Computer Networks time Wenbing Zhao
TCP Connection Management TCP sender, receiver establish “connection” before exchanging data segments • Initialize TCP variables: – Sequence numbers – Buffers, flow control info (e. g. Rcv. Window) • Client: connection initiator Socket client. Socket = new Socket("hostname", "port number"); • Server: contacted by client Socket connection. Socket = welcome. Socket. accept(); Spring Semester 2008 EEC-484/584: Computer Networks Wenbing Zhao 16
TCP Connection Management Three way handshake: Step 1: client host sends TCP SYN segment to server – specifies initial sequence number – no data Step 2: server host receives SYN, replies with SYN/ACK segment – server allocates buffers – specifies server initial sequence number Step 3: client receives SYN/ACK, replies with ACK segment, which may contain data Spring Semester 2008 EEC-484/584: Computer Networks Wenbing Zhao 17
18 TCP Connection Management Three way handshake: client connect • SYN segment is considered as 1 byte • SYN/ACK segment is also considered as 1 byte SYN ( seq=x EEC-484/584: Computer Networks accept ) x+1) CK ( YN/A K= y, AC seq= S ACK Spring Semester 2008 server (seq= x+1, A CK=y +1) Wenbing Zhao
19 TCP Connection Management client Closing a connection: client closes socket: close server FIN client. Socket. close(); Step 1: client end system sends ACK TCP FIN control segment to server replies with ACK. Closes connection, sends FIN timed wait Step 2: server receives FIN, close ACK closed Spring Semester 2008 EEC-484/584: Computer Networks Wenbing Zhao
20 TCP Connection Management client Step 3: client receives FIN, replies with ACK. closing – Enters “timed wait” - will respond with ACK to received FINs server FIN ACK closing FIN Step 4: server, receives ACK. Note: with small modification, can handle simultaneous FINs timed wait Connection closed. ACK closed Spring Semester 2008 EEC-484/584: Computer Networks Wenbing Zhao
21 TCP Reliable Data Transfer • TCP creates rdt service on top of IP’s unreliable service • Pipelined segments • Cumulative acks • TCP uses single retransmission timer Fall Semester 2007 • Retransmissions are triggered by: – timeout events – duplicate acks • Initially consider simplified TCP sender: – ignore duplicate acks – ignore flow control, congestion control EEC-484/584: Computer Networks Wenbing Zhao
22 TCP Sender Events: Data rcvd from app: Timeout: • Create segment with • retransmit segment that sequence number caused timeout • seq # is byte-stream • restart timer number of first data byte Ack rcvd: in segment • If acknowledges • start timer if not already previously unacked running (think of timer segments as for oldest unacked – update what is known to segment) be acked • expiration interval: – start timer if there are outstanding segment Time. Out. Interval Fall Semester 2007 EEC-484/584: Computer Networks Wenbing Zhao
TCP: Retransmission Scenarios Host A Host B tes da t X ACK a Seq=92 timeout 2, 8 by =100 loss Seq=9 2, 8 by tes da ta 0 K=10 Sendbase = 100 Send. Base = 120 AC Send. Base = 100 time lost ACK scenario Fall Semester 2007 Send. Base = 120 EEC-484/584: Computer Networks Host B Seq=9 2, 8 by tes da ta Seq= 100, 2 0 byte s data 0 10 = K 120 = C K A AC Seq=9 2, 8 by Seq=92 timeout Seq=9 Host A time tes da t a 20 K=1 AC premature timeout Wenbing Zhao 23
TCP Retransmission Scenarios Host A Host B Seq=9 timeout 2, 8 by t Send. Base = 120 es dat a =100 K C A 00, 20 bytes data Seq=1 X loss 120 = ACK time Cumulative ACK scenario Fall Semester 2007 EEC-484/584: Computer Networks Wenbing Zhao 24
25 TCP ACK Generation Event at Receiver TCP Receiver action Arrival of in-order segment with expected seq #. All data up to expected seq # already ACKed Delayed ACK. Wait up to 500 ms for next segment. If no next segment, send ACK Arrival of in-order segment with expected seq #. One other segment has ACK pending Immediately send single cumulative ACK, ACKing both in-order segments Arrival of out-of-order segment higher-than-expect seq. #. Gap detected Immediately send duplicate ACK, indicating seq. # of next expected byte Arrival of segment that partially or completely fills gap Immediate send ACK, provided that segment starts at lower end of gap Fall Semester 2007 EEC-484/584: Computer Networks Wenbing Zhao
26 Exercise • A process at host A wants to establish a TCP connection with another process at host B. Assuming that host A chooses to use 1628 as the initial sequence number, and host B chooses to use 3217 as the initial sequence number for this connection, show the segments involved with the connection establishment process. You must include the following information for each such segment: (1) sequence number, (2) acknowledgement number (if applicable), (3) the SYN flag bit status, and (4) the ACK flag bit status. Spring Semester 2008 EEC-484/584: Computer Networks Wenbing Zhao
- Slides: 26