Presentation is loading. Please wait.

Presentation is loading. Please wait.

EEC-484/584 Computer Networks Lecture 15 Wenbing Zhao (Part of the slides are based on Drs. Kurose & Ross ’ s slides for their Computer.

Similar presentations


Presentation on theme: "EEC-484/584 Computer Networks Lecture 15 Wenbing Zhao (Part of the slides are based on Drs. Kurose & Ross ’ s slides for their Computer."— Presentation transcript:

1 EEC-484/584 Computer Networks Lecture 15 Wenbing Zhao wenbing@ieee.org (Part of the slides are based on Drs. Kurose & Ross ’ s slides for their Computer Networking book, and on materials supplied by Dr. Louise Moser at UCSB and Prentice-Hall)

2 2 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao Outline UDP TCP –Segment header structure –Connection management –Reliable data transfer –Flow control –TCP transmission policy

3 3 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao 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

4 4 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao Why is There a UDP? No connection establishment (which can add delay) Simple: no connection state at sender receiver Small segment header No congestion control: UDP can blast away as fast as desired

5 5 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao UDP Often used for streaming multimedia apps –Loss tolerant –Rate sensitive Other UDP uses –DNS –SNMP Reliable transfer over UDP: add reliability at application layer source port # dest port # 32 bits Application data (message) UDP segment format length checksum Length, in bytes of UDP segment, including header

6 6 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao UDP Checksum Sender: treat segment contents as sequence of 16-bit integers checksum: addition (1’s complement sum) of segment contents sender puts checksum value into UDP checksum field Receiver: compute checksum of received segment check if computed checksum equals checksum field value: –NO - error detected –YES - no error detected. But maybe errors nonetheless? Goal: detect “errors” (e.g., flipped bits) in transmitted segment

7 7 Spring Semester 2006EEC-484/584: Computer NetworksWenbing 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 1 0 0 1 1 0 0 1 1 0 0 1 1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1 wraparound sum checksum To know more: http://www.netfor2.com/udpsum.htm http://www.netfor2.com/checksum.html

8 8 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao TCP: Overview Full duplex data: –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 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

9 9 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao TCP: Overview TCP connection is byte stream, not message stream, no message boundaries TCP may send immediately or buffer before sending

10 10 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao 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) A TCP segment must fit into an IP datagram!

11 11 Spring Semester 2006EEC-484/584: Computer NetworksWenbing 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 accumulative: an ack of 5 means 0-4 bytes have been received TCP header length – number of 32-bit words in header

12 12 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao 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

13 13 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao 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.netfor2.com/tcpsum.htm http://www.netfor2.com/checksum.htmlhttp://www.netfor2.com/tcpsum.htm http://www.netfor2.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

14 14 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao TCP Sequence Numbers and ACKs Sequence numbers: –byte stream “number” of first byte in segment’s data ACKs: –seq # of next byte expected from other side –cumulative ACK Host A Host B Seq=42, ACK=79, data = ‘C’ Seq=79, ACK=43, data = ‘C’ Seq=43, ACK=80 User types ‘C’ host ACKs receipt of echoed ‘C’ host ACKs receipt of ‘C’, echoes back ‘C’ time simple telnet scenario

15 15 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao TCP Connection Management TCP sender, receiver establish “connection” before exchanging data segments Initialize TCP variables: –Sequence numbers –Buffers, flow control info (e.g. RcvWindow ) Client: connection initiator Socket clientSocket = new Socket("hostname","port number"); Server: contacted by client Socket connectionSocket = welcomeSocket.accept();

16 16 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao 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

17 17 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao TCP Connection Management Three way handshake: SYN segment is considered as 1 byte SYN/ACK segment is also considered as 1 byte client SYN (seq=x) server SYN/ACK (seq=y, ACK=x+1) ACK (seq=x+1, ACK=y+1) connect accept

18 18 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao TCP Connection Management 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. Closes connection, sends FIN. client FIN server ACK FIN close closed timed wait

19 19 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao TCP Connection Management 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. Note: with small modification, can handle simultaneous FINs client FIN server ACK FIN closing closed timed wait closed

20 20 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao TCP Reliable Data Transfer TCP creates rdt service on top of IP’s unreliable service Pipelined segments Cumulative acks TCP uses single retransmission timer Retransmissions are triggered by: –timeout events –duplicate acks Initially consider simplified TCP sender: – ignore duplicate acks –ignore flow control, congestion control

21 21 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao TCP Sender Events: Data rcvd from app: Create segment with sequence number seq # is byte-stream number of first data byte in segment start timer if not already running (think of timer as for oldest unacked segment) expiration interval: TimeOutInterval Timeout: retransmit segment that caused timeout restart timer Ack rcvd: If acknowledges previously unacked segments –update what is known to be acked –start timer if there are outstanding segment

22 22 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao TCP: Retransmission Scenarios Host A Seq=100, 20 bytes data ACK=100 time premature timeout Host B Seq=92, 8 bytes data ACK=120 Seq=92, 8 bytes data Seq=92 timeout ACK=120 Host A Seq=92, 8 bytes data ACK=100 loss timeout lost ACK scenario Host B X Seq=92, 8 bytes data ACK=100 time Seq=92 timeout SendBase = 100 SendBase = 120 SendBase = 120 Sendbase = 100

23 23 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao TCP Retransmission Scenarios Host A Seq=92, 8 bytes data ACK=100 loss timeout Cumulative ACK scenario Host B X Seq=100, 20 bytes data ACK=120 time SendBase = 120

24 24 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao TCP ACK Generation Event at Receiver Arrival of in-order segment with expected seq #. All data up to expected seq # already ACKed Arrival of in-order segment with expected seq #. One other segment has ACK pending Arrival of out-of-order segment higher-than-expect seq. #. Gap detected Arrival of segment that partially or completely fills gap TCP Receiver action Delayed ACK. Wait up to 500ms for next segment. If no next segment, send ACK Immediately send single cumulative ACK, ACKing both in-order segments Immediately send duplicate ACK, indicating seq. # of next expected byte Immediate send ACK, provided that segment starts at lower end of gap

25 25 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao TCP Flow Control Receive side of TCP connection has a receive buffer: Speed-matching service: matching the send rate to the receiving app’s drain rate App process may be slow at reading from buffer Flow control: sender won’t overflow receiver’s buffer by transmitting too much, too fast

26 26 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao TCP Flow Control (Suppose TCP receiver discards out-of-order segments) Spare room in buffer = RcvWindow = RcvBuffer-[LastByteRcvd - LastByteRead] Rcvr advertises spare room by including value of RcvWindow in segments Sender limits unACKed data to RcvWindow –guarantees receive buffer doesn’t overflow

27 27 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao TCP Transmission Policy Window management not directly tied to ACKs –The sender can send new segments only if the receiver has room to receive them What if the receiver’s window drops to 0 ? –Sender may not normally send segments with two exceptions –Exception 1: urgent data may be sent, e.g., to allow user to kill process running on the remote machine –Exception 2: sender may send a 1-byte segment to make the receiver re-announce the next byte expected and window size

28 28 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao TCP Transmission Policy Window management not directly tied to ACKs

29 29 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao TCP Transmission Policy Nagle ’ s algorithm –To address the 1-byte-at-a-time sender problem Clark ’ s algorithm –To address the 1-byte-at-a-time receiver problem

30 30 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao 1-byte-at-a-time Sender Problem Sender sends 1 byte (e.g., typed one character in an editor) A segment of 1 byte is sent to the remote machine (41-byte IP packet) Remote machine acks immediately (40-byte IP packet) Editor (in remote machine) program reads the received 1 byte, a windows update segment is sent to user (40-byte IP packet) Editor program echoes the 1 byte received to the user terminal (41-byte IP packet) In all, 162 bytes of bandwidth used, 4 segments are sent for each character typed

31 31 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao Nagle ’ s Algorithm When sender application passes data to TCP one byte at a time –Send first byte –Buffer the rest until first byte ACKed –Then send all buffered bytes in one TCP segment –Start buffering again until all ACKed Implemented widely in TCP, can be disabled/enabled by using socket options For some application, it is necessary to disable the Nagle’s algorithm, e.g., X Windows program over Internet, to avoid erratic mouse movement, etc.

32 32 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao Silly Window Syndrome When receiver application accepts data from TCP 1 byte at a time

33 33 Spring Semester 2006EEC-484/584: Computer NetworksWenbing Zhao Clark ’ s Algorithm Receiver should not send window update until –It can handle max segment size it advertised when connection established, or, –Its buffer is half empty, whichever is smaller Sender should wait until –It has accumulated enough space in window to send full segment, or, –One containing at least half of receiver ’ s buffer size Nagle ’ s algorithm and Clark ’ s algorithm are complementary


Download ppt "EEC-484/584 Computer Networks Lecture 15 Wenbing Zhao (Part of the slides are based on Drs. Kurose & Ross ’ s slides for their Computer."

Similar presentations


Ads by Google