EEC-484/584 Computer Networks Lecture 7 Wenbing Zhao [email protected] (Part of the slides are based...
-
date post
20-Dec-2015 -
Category
Documents
-
view
214 -
download
0
Transcript of EEC-484/584 Computer Networks Lecture 7 Wenbing Zhao [email protected] (Part of the slides are based...
EEC-484/584EEC-484/584Computer NetworksComputer Networks
Lecture 7Lecture 7
Wenbing ZhaoWenbing Zhao
[email protected]@ieee.org(Part of the slides are based on Drs. Kurose & (Part of the slides are based on Drs. Kurose &
RossRoss’’s slides for their s slides for their Computer Networking Computer Networking book)book)
22
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
OutlineOutline
• Sliding window protocols
• UDP
• TCP– Segment header structure– Connection management
33
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
Sliding Window ProtocolsSliding Window Protocols
• Full-duplex: Use same connection for data in both directions (AB and BA)
• Interleave data and ack packets– B piggybacks its ack for A’s packet onto B’s next packet– Savings of header in separate ack packet
• If B sends data infrequently, use timeout to determine when B should send ack in separate ack packet
• Each packet contains sequence number in ranges 0..2n-1 (for n-bit sequence numbers)
44
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
Sending WindowSending Window• Start from empty and grow to a maximum size• Within sending window, packets sent but not acked
– Sender must keep those packets for possible retransmission– If max window size = w, need w buffers
0 1 2 3 4 5 6 7
1st outstanding packet
Last packetsent
0 1 2 3 4 5 6 7
A new packet sent (if send window allows)
Sent window enlarges when more packet is sent
When new packet arrives from application layer, it is given
next highest sequence number, and upper edge of
window is incremented
55
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
Sending WindowSending Window
0 1 2 3 4 5 6 7
3ack
0 1 2 3 4 5 6 7
Sent window shrinks when the ack corresponding to the 1st outstanding packet Is received
When ack arrives from receiver, lower edge of window is incremented
In general, ack is cumulative
66
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
Receiving WindowReceiving Window
• List of consecutive sequence numbers of packets that receiver is permitted to accept
• When packet with (seq num = lower edge of window) arrives– Packet is passed to higher layer– Ack is generated– Window slid down by 1 (remains same size as was initially)
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
3
77
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
Reliable Data Transfer:Reliable Data Transfer:Sliding Window ProtocolsSliding Window Protocols
• A One-Bit Sliding Window Protocol• A Protocol Using Go Back n• A Protocol Using Selective Repeat
88
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
One-Bit Sliding Window ProtocolOne-Bit Sliding Window ProtocolA sliding window of size 1, with a 3-bit sequence number
Initially After first packet sent
After first packet received
After first ack received
99
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
Sliding Window Protocols: PipeliningSliding Window Protocols: Pipelining
• Problem of one-bit sliding window protocol:– Sender blocks till receives acks
• Solution: pipelining– Allow sender to send up to w packets before blocking
• With pipelining, if packet in middle is lost or damaged, what to do with the packets following it ?
• Solution: two strategies– Go Back n - all the packets following it are discarded– Selective repeat – nack the lost/damaged packet and
retransmit that packet
1010
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
Pipelining and Error RecoveryPipelining and Error Recovery
Go back n: Effective receiver window size is 1
Packets discarded
1111
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
Pipelining and Error RecoveryPipelining and Error Recovery
Selective repeat
Can you think of an alternative to go-back-n and selective-repeat?
Packets buffered
1212
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
Go Back Go Back nn
• Sender– Stores all packets in output buffer– Must get acks in order in which packets are sent
• Receiver– Discards all packets following lost or damaged one
• Works well – If transmission errors rare and few retransmissions– If lot of traffic in both directions
1313
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
Selective RepeatSelective Repeat
• Receiver accepts and buffers packets following lost or damaged packets
• Both sender and receiver maintain windows– Sender’s window starts at 0, grows to MAX SEQ– Receiver’s window fixed at MAX SEQ
• Receiver has buffer reserved for each seq num in its window
0 1 2 3 4 5 6 7
1414
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
Selective RepeatSelective Repeat• When packet arrives, receiver checks if seq num in
window• If so and if not already received, this packet is accepted
and stored• If all lower numbered packets delivered, this packet is
delivered as well
0 1 2 3 4 5 6 7
5
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
3
1515
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
Selective RepeatSelective Repeat
• If no reverse traffic before timer goes off, separate ack is sent
• When receiver suspects error, sends NAK back to sender (request for retransmission)
• Two circumstances that trigger NAK– Damaged packet arrives– Packet other than expected one arrives, suspect expected one is
lost
• Receiver sends only one NAK for packet expected
1616
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
UDP: User Datagram ProtocolUDP: 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
1717
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
Why is There a UDP?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
1818
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
UDPUDP• 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
Applicationdata
(message)
UDP segment format
length checksumLength, in
bytes of UDPsegment,
includingheader
1919
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
UDP ChecksumUDP 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
2020
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
Internet Checksum ExampleInternet 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 0 1 1 0 0 1 1 0 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
sumchecksum
To know more: http://www.netfor2.com/udpsum.htmhttp://www.netfor2.com/checksum.html
2121
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
TCP: OverviewTCP: 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
2222
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
TCP: OverviewTCP: 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
2323
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
TCP Segment StructureTCP Segment Structure
source port # dest port #
32 bits
applicationdata
(variable length)
sequence number
acknowledgement numberReceive window
Urg data pnterchecksum
FSRPAUheadlen
notused
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 willingto accept
countingby bytes of data(not segments!)
Internetchecksum
(as in UDP)
A TCP segment must fit into an IP datagram!
2424
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
The TCP Segment HeaderThe 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
2525
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
The TCP Segment HeaderThe 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
2626
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
The TCP Segment HeaderThe 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.html
• Options – provides a way to add extra facilities not covered by the regular header– E.g., communicate buffer sizes during set up
2727
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
TCP Sequence Numbers and ACKsTCP 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
Usertypes
‘C’
host ACKsreceipt
of echoed‘C’
host ACKsreceipt of
‘C’, echoesback ‘C’
timesimple telnet/ssh scenario
2828
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
TCP Connection ManagementTCP 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();
2929
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
TCP Connection ManagementTCP 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
3030
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
TCP Connection ManagementTCP 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
3131
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
TCP Connection ManagementTCP 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
ACK
FIN
close
close
closed
tim
ed w
ait
3232
Spring Semester 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao
TCP Connection ManagementTCP 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
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
3333
ExerciseExercise
• 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 2009Spring Semester 2009 EEC-484/584: Computer NetworksEEC-484/584: Computer Networks Wenbing ZhaoWenbing Zhao