networking
DESCRIPTION
Networking. Transport Layer. Networking – Transport Layer. The Transport Layer is part of the Internet Protocol stack The Transport Layer sits between the Application Layer and the Network Layer The Transport Layer provides communication services to the application processes in a network. - PowerPoint PPT PresentationTRANSCRIPT
Networking
Transport Layer
Networking – Transport Layer
• The Transport Layer is part of the Internet Protocol stack
• The Transport Layer sits between the Application Layer and the Network Layer
• The Transport Layer provides communication services to the application processes in a network
Networking – Transport Layer
• Main properties of Transport Layer– Provides logical (not physical) connection
between processes– Implemented in end system (processes), not in
e.g. routers– The data unit at the Transport Layer level is a
segment, not a full message– Two common Transport layer protocls are TCP
and UDP
Networking – Transport Layer
• Transport Layer vs. Network Layer– Transport Layer transports data
between processes running of different hosts
– Network Layer transports data between hosts
– A Transport Layer protocol can offer services that the underlying Network Layer protocol does not offer
Networking – Transport Layer
• Multiplexing/demultiplexing
Network Layer
Transport Layer
Networking – Transport Layer
• Multiplexing/demultiplexing• How does it work in the letter analogy?
Jim CarpenterHigh Road 1122209 Smallville
Sue MillerSchool Street 2078865 Silvertown
A stamp
…
Source person
Destinationperson
Source location
Destinationlocation
Networking – Transport Layer
• Multiplexing/demultiplexing• Remember– A host is specified by its IP address– A process is specified by its port number
Transport Layer segment
Networking – Transport Layer
• Client side process– ”I run on port 55”– ”I wish to talk to a server running on port 23”
• Remember IP address of client host is also included in the segment (at IP level)
55 23
Networking – Transport Layer
• Server side process– ”I run on port 23”– ”I wish to reply to the client running on port 55”
23 55
Networking – Transport Layer
• What if two different clients – running on different hosts – use the same port number (for different processes)?
• No problem, since the two hosts will have different IP addresses!
• It is the combination of IP address and port number that must be unique (just as name and address for a plain letter…)
Networking – Transport Layer
• Specific Transport Layer protocols – UDP• UDP – User Datagram Protocol• In the context of the Internet Protocol Stack, it
is built on top the IP Network Protocol• Adds just two ”services” to the IP protocol– Multiplexing/demultiplexing– Lightweight data validation
Networking – Transport Layer
Networking – Transport Layer
• Multiplexing/demultiplexing is done using the source and destination port numbers, as explained previously
• Length field specifies the length (in bytes) of the actual data
• Checksum field is used for data validation
Networking – Transport Layer
• Data validation uses a so-called checksum calculation
• Data is binary – consists of 0s and 1s (bits)
• Binary numbers can be added together, just as decimal numbers
Networking – Transport Layer
• Adding two 16-bit binary numbers also produces a 16-bit binary number
• All the 16-bit ”words” in the data fields are added together, producing a single 16-bit binary number
• The 16-bit binary number in the checksum field is now chosen in a clever way…
Networking – Transport Layer
0100101011011101
1111111111111111
+(16-bit checksum)
Networking – Transport Layer
• This is 1-complement checksum• If we add…– All the 16-words of the data field, plus– The 16-bit checksum
• …we always get 1111111111111111
Networking – Transport Layer
• Server side– Given the data,
calculate the corresponding checksum
– Put the checksum in the checksum field
– Send to client
• Client side– Receive from server– Add up all data and
the chekcsum– If the result is not
1111111111111111, we have discovered an error!
Networking – Transport Layer
• How does UDP handle a data error…?– Some UDP implementations simply throw away
damaged segments– Other deliver them to the application, with an
indicating that the data is damaged• Higher-level error handling must be done by
the receiving application!
Networking – Transport Layer
• Specific Transport Layer protocols – TCP• TCP – Transmission Control Protocol• In the context of the Internet Protocol Stack, it
is built on top the IP Network Protocol• TCP adds significant non-trivial services to the
IP protocol!
Networking – Transport Layer
• Main TCP features– Reliable data transfer – data is guaranteed to
arrive without errors, and in the correct order– Flow control – match the transmission speed of
sender and receiver– Congestion control – makes sure that no single
connection is allowed to flood the network with data traffic (a benefit for the Internet as a whole, not so much for the individual connection…)
Networking – Transport Layer
• How can you implement ”reliable data transfer”?
• A complex task!• Not only at the Transport
Layer level, but also at the ”deeper” levels
• We will explore the problem in general
Networking – Transport Layer
• Abstract look at data transfer:
Sender Receiver
Data
Reliable channel
ApplicationLayer
TransportLayer
Reliable!
Networking – Transport Layer
• Data transfer seen from the Transport Layer:
Sender Receiver
Data
Unreliable channel
TransportLayer
NetworkLayer
Reliable!
Networking – Transport Layer
• Levels of unreliability– Level 0 - perfect reliability (no loss of data
packets, no errors in data packets)– Level 1 - partial reliability (no loss of data packets,
possible errors in data packets)– Level 2 – no reliability (possible loss of data
packets, possible errors in data packets)
Networking – Transport Layer
• Level 0 – perfect reliability– Essentially trivial to implement– Data from the Application Layer is
divided into segments, headers are added, and data is sent
– Similarly, data is extracted on the server side, and handed to the Application Layer
Networking – Transport Layer
• Level 1 – Partial reliability– Packets are guaranteed to
arrive at their destination…– …but the content of a packets
may be damaged– We need a mechanism for
retransmission of a damaged packet
Networking – Transport Layer
• Main steps involved– Checking whether or not (the data in) a packet is
damaged– Informing the sender of the packet whether or not
the received packet was intact– Known as an ARQ protocol (Automatic Repeat
reQuest)
Networking – Transport Layer
• Error detection– We already saw an example (1-complement
checksum)– More sophisticated techniques exist (error
detection and correction)– Exact technique not important here– All techniques require sending extra data
Networking – Transport Layer
• Receiver feedback– Receiver must provide explicit feedback to the
sender, about the successful/failed outcome of receiving a packet
– Receiver sends a packet back to sender– ACK (acknowledge) packet – all went well– NAK (not acknowledge) packet - failure
Networking – Transport Layer
• Step 1: Send data packet n from Sender to Receiver
Sender Receiver
Data (n)
Networking – Transport Layer
• Step 2a: Receiver finds data to be OK
Sender Receiver
Data (n)
Networking – Transport Layer
• Step 3a: Receiver sends ACK packet to Sender
Sender Receiver
ACK
Networking – Transport Layer
• Step 4a: Receiver gets ACK packet
Sender Receiver
ACK
Networking – Transport Layer
• Step 1 (again): Send next piece of data from Sender to Receiver
Sender Receiver
Data (n+1)
Networking – Transport Layer
• Step 2b: Receiver finds data to be damaged
Sender Receiver
Data (n)
Networking – Transport Layer
• Step 3b: Receiver sends NAK packet to Sender
Sender Receiver
NAK
Networking – Transport Layer
• Step 4b: Receiver gets NAK packet
Sender Receiver
NAK
Networking – Transport Layer
• Step 1 (again): Send same piece of data from Sender to Receiver
Sender Receiver
Data (n)
Networking – Transport Layer
• Packets are sent in order • Next packet is not sent
before the current packet has been correctly received (a stop-and-wait protocol)
• Sender thus always knows which data a ACK/NAK packet refers to
Networking – Transport Layer
• Can anything go wrong…?• Data packet keeps getting
damaged…at some point we must give up (timeout)
• The ACK/NAK packets themselves could also become damaged!
Networking – Transport Layer
• Possible solutions– Introduce ”acknowledge to acknowledge” packets
– hard to decide when to stop…– Better error correction – can only partially solve
the problem– Assume the worst – only consider a correctly
received ACK packet as meaning ”acknowledge”. Everything else is interpreted as NAK
Networking – Transport Layer
• Problematic scenario– Receiver receives data, and confirms it to be OK– Receiver sends ACK to Sender– Sender receives a damaged packet, and interprets
this as a NAK (”assume the worst”)– Sender thus decides to to resend data– Receiver gets data. Data is OK, BUT is it• Resent data, or• New data?
Networking – Transport Layer
• To resolve the problem, we intro-duce a data packet sequence number
• All data packets are marked with an incremental sequence number
• Receiver keeps track of the sequence number of the last correctly received package
Networking – Transport Layer
• Step 1: Send data packet n from Sender to Receiver
Sender Receiver
Data (n)
Networking – Transport Layer
• Step 2: Receiver finds data to be OK
Sender Receiver
Data (n)
Networking – Transport Layer
• Step 3: Receiver sends ACK packet to Sender, and remembers sequence number
Sender Receiver
ACK
n
Networking – Transport Layer
• Step 4: Receiver gets damaged ACK packet
Sender Receiver
!C¤
n
Networking – Transport Layer
• Step 5: Resend data packet n from Sender to Receiver
Sender Receiver
Data (n)
n
Networking – Transport Layer
• Step 6: Receiver looks at sequence number, and discovers that this is resent data
Sender Receiver
Data (n)
n
Networking – Transport Layer
• Step 7: Receiver sends ACK packet to Sender (again), and can discard data…
Sender Receiver
ACK
n
Networking – Transport Layer
• Step 8: Receiver gets correct ACK packet (hopefully…)
Sender Receiver
ACK
n
Networking – Transport Layer
• Further optimisations• The sequence number
only needs to be a single bit (why…?)
• We only need ACKs, not NAKs (how…?)
Networking – Transport Layer
• Level 2 – No reliability– The content of a packet may
be damaged– Packets may be entirely lost– Fully realistic: A router will
throw away packets if traffic gets too intense
Networking – Transport Layer
• Step 1: Send data packet n from Sender to Receiver
Sender Receiver
Data (n)
Networking – Transport Layer
• Step 2: Receiver finds data to be OK
Sender Receiver
Data (n)
Networking – Transport Layer
• Step 3: Receiver sends ACK packet to Sender, and remembers sequence number
Sender Receiver
ACK
n
Networking – Transport Layer
• Step 4: The ACK packet is lost!
Sender Receivern
Networking – Transport Layer
• Obvious problem – how can the sender detect that something went wrong…?
• If the Sender does not receive an ACK within a certain time, the transmission has failed, and data must be resent
• Reasons for failure: Data packet lost, or ACK was lost
• How long is ”a certain time”…?
Networking – Transport Layer
• Choosing a proper timeout time is not easy!• A compromise between allowing reasonable
time for a transmission to complete, and slowing down the entire transmission
• No matter the value, using a timeout introduces a risk of duplicate data packets
• Is already handled in level 1 protocol
Networking – Transport Layer
• The Sender must thus– Reset and start the timer
whenever a data packet is sent
– Stop the timer when an ACK is received
– Respond to a timer timeout by resending the previous data packet
Networking – Transport Layer
• It also becomes necessary to extend the ACK with the sequence number of the data packet that is being acknowledged (why…?)
Networking – Transport Layer
• With the outlined extensions, the described protocol can implement reliable data transfer on top of an unrealiable network
• Protocol is the stop-and-wait type• Performance is poor, due to the need for a full
round-trip per packet• No pipelining!
Networking – Transport Layer
Networking – Transport Layer
• In order to achieve acceptable performance, pipelining must be included in the protocol
• Sender is allowed to send data packets without waiting for acknowledgements
• Consequences– Longer data packet sequence numbers– Sender-side buffering of data packets
Networking – Transport Layer
• The Go-Back-N protocol (GBN)• Pipelining is allowed, BUT at most N unacknow-
ledged packets must be in the pipeline
Networking – Transport Layer
• GBN Sender-side actions– Data received from upper layer– If fewer than N packets are in the pipeline, then
create a packet and send it– Else (i.e. N packets are in the pipeline) inform
caller that data cannot be sent– Caller must handle this rejection appropriately
Networking – Transport Layer
• GBN Sender-side actions– ACK received from Receiver– The ACK will contain a sequence number– If ACK contains sequence number n, then all data
packets up to and including this sequence number are consider to be correctly received
– Also called a cumulative acknowledgement
Networking – Transport Layer
• GBN Sender-side actions– Timeout event– No ACK has been received within the set time limit– Resend all packets for which an ACK has not been
received (up to N packets)– Hence the name ”Go back N”…
Networking – Transport Layer
• GBN Receiver-side actions– Orderly data reception– Receiver receives data packet with sequence
number n– The previously received data packet had sequence
number (n -1)– All is in order; send ACK for data packet n– Deliver packet to upper layer
Networking – Transport Layer
• GBN Receiver-side actions– Non-orderly data reception– Covers all other cases than ”orderly”– Resend ACK for most recently, orderly received
data packet k– Hence an ACK with sequence number k will
indicate: all data packets up to and including k have been properly received
– Data packet itself is discarded
Networking – Transport Layer
Example: N = 4
Networking – Transport Layer
• Go-Back N (GBN) implements pipelining, thereby greatly improving performance
• Still potential weaknesses for large values of N (say, N > 1000)
• One single error can provoke retransmission of thousands of data packets
Networking – Transport Layer
• An alternative approach is a Selective Repeat (SR) protocol
• Main principle: only resend those specific data packets that Sender suspects were not correctly received by the Receiver
Networking – Transport Layer
• Main principles of Selective Repeat– Receiver must individually acknowledge any
correctly received data packet– Out-of-order packets are buffered at the Receiver,
not discarded– Each packet must have its own (logical) timer at
the Sender– In general: SP is somewhat more complex, but
increases the effective bandwidth
Networking – Transport Layer
• Recall the main TCP features– Reliable data transfer – data is guaranteed to
arrive without errors, and in the correct order (we know how to do that now…)
Networking – Transport Layer
• Recall the main TCP features– Flow control – try to dynamically match the
transmission speed of the sender side with the processing speed of the receiver side (we will get back to that part…)
Networking – Transport Layer
• Recall the main TCP features– Congestion control – makes sure that no
single connection is allowed to flood the network with an excessive amount of data (we will get back to that part…)
The Internet (IP)
Networking – Transport Layer
Host Host
Data
TCP TCP
Networking – Transport Layer
• TCP Connection• Before two hosts start to exchange data, they
will establish a (logical) connection• Initiator is called client, other side server• Needed information– Host address (IP address)– Port number
Networking – Transport Layer
• TCP Connection• Note that the ”connection” only exists in the
end hosts – IP has no concept of connection!• TCP uses three-way handshake procedure to
establish a connection• Both sides will maintain a number of TCP
state variables and a data buffer during the connection
The Internet (IP)
Networking – Transport Layer
Host Host
Data buffer
TCP (state)
Data buffer
TCP (state)
Networking – Transport Layer
• Sending data in TCP• Connection is full-duplex; both parties can
send data at the same time• Data sent from a Sender will end up in the
Receivers data buffer• In the host processes, TCP will – from time to
time – take data (a segment) from the buffer and hand it to the application
Networking – Transport Layer
Networking – Transport Layer
Just like in UDP header
Networking – Transport Layer
For reliable data transfer
Networking – Transport Layer
Total length of the header
Networking – Transport Layer
Various options for dynamic adjustments, e.g window size
Networking – Transport Layer
Flag fields, e.g. acknowledge
Networking – Transport Layer
Checksum for error detection
Networking – Transport Layer
The amount of data the receiver will accept
Networking – Transport Layer
• TCP provides realiable data transfer, using sequence numbers and acknowledgements
• Sequence number counts bytes, not segments (the number of the next byte the Receiver expect to receive)
• TCP uses pipelining of data, and selective retransmissions
Networking – Transport Layer
• TCP offers flow control – matching the speed of Sender and Receiver
• Flow control is similar to – but not identical to – congestion control
• Prevents buffer overflow at the Receiver side
Networking – Transport Layer
Networking – Transport Layer
• Sender ”pumps” data in the Receiver buffer• Receiver consumes data when the application
process takes data from the buffer• In any segment sent, the size of the spare
room (RcvWindow) is placed in the ”rcvr window size” field
Networking – Transport Layer
• Sender-side reasoning:– I have sent s bytes that are unacknowledged…– I know the Receiver has r bytes left…– …so, I must make sure that r > s
• If (r > s) keep sending data
else pause
Networking – Transport Layer
• Note – this scheme has a problem (what?)
• Fortunately, the problem can be fixed (how?)
Networking – Transport Layer
• TCP uses timeouts to decide if data needs to be retransmitted
• How to select a proper timeout value…?• Too low: many duplicate segments will be
sent, causing more bandwidth usage• Too high: available bandwidth is not utilised
Networking – Transport Layer
• Lower limit for timeout is the round-trip time (RTT) – the time it takes to send data and get an acknowledge back
• A Sender can measure the RTT for each data segment is sends
• Problem: the RTT changes over time…
Networking – Transport Layer
RTT Sample 1 2 3 4 5
RTT Value 27 32 40 22 28
Networking – Transport Layer
• Strategy 1: Just calculate average over all available values
RTT Sample 1 2 3 4 5
RTT Value 27 33 40 62 38
RTT Average 27 30 33 41 40
Networking – Transport Layer
• Problems with Strategy 1• All values are given the same ”weight”, both
very old and brand new values• Historic values should become less and less
important, since the current state of the connection is more important
Networking – Transport Layer
• Strategy 2: Only use the last n RTT values (e.g. n = 3)
RTT Sample 1 2 3 4 5
RTT Value 27 33 40 62 38
RTT Average 27 30 33 45 47
Networking – Transport Layer
• Problems with Strategy 2• Are the historic RTT values completely
unimportant?• Current conditions might be ”extreme”• What is a proper value for n?
Networking – Transport Layer
• A compromise: exponential weighted moving average (EWMA)
• Formula (RTTA : RTT Average) :
RTTAnew = (1-w) RTTA∙ old + w RTT, w < 1∙
Networking – Transport Layer
• EWMA in human language…– Historical RTT values are never ”forgotten”…– …but get less and less weight in the RTT average
• Example, w = 0.1– Weight of newest RTT value: 10 %– Weight of value before that: 9 %– Weight of value before that: 8.1 %– Weight of value before that: 7.3 %– …
Networking – Transport Layer
• Strategy 3: Use EWMA, with w = 0.2
RTT Sample 1 2 3 4 5
RTT Value 27 33 40 62 38
RTT Average 27 28 30 36 36
Networking – Transport Layer
• Given we can properly estimate the average RTT, what is then a proper timeout value?
• Timeout = RTT average + ”a margin”• TCP can also track the average deviation d
from the average RTT (also uses EWMA)• Timeout = RTT average + 4d
Networking – Transport Layer
• Congestion control – adjusting the speed of data transmission
• Not as such a benefit for the individual connection, but for ”the Internet as a whole”
Networking – Transport Layer
• Why not just ”blast way”…?• Network only has a limited – and uneven –
capacity• Data packets will ”pile up” at routers• Routers can only buffer a finite number of
data packets – when buffers are full, data packets will be thrown away and lost
Networking – Transport Layer
• The possible costs of congestion– When data arrives at a link at a rate close to the
link capacity, queueing delays increase rapidly– Sender must perform retransmissions when
routers start to drop packets– When a packet is dropped along a path of links,
the bandwidth used at previous links is wasted
Networking – Transport Layer
• How can an end system detect congestion?• Network-assisted congestion control – the
underlying layers provide explicit feedback about network congestion state
• End-end congestion control – the end system themselves must detect congestion based on local observations (packet losses and delays)
• TCP is based on end-end congestion control
Networking – Transport Layer
• Recall basic flow control– Receiver includes the current data window size in
data acknowledgements– Sender may not have more unacknowledged data
outstanding than the size of the data window• BUT should the sender always utilise this to
the limit…?
Networking – Transport Layer
• Basic congestion control– Start out with a small data window (congestion
window) of size w– w is much smaller than ”allowed” by flow control– Sender may only have up to w bytes of
unacknowledged data outstanding– As long as Sender does not experience loss of
data, w can be increased
Networking – Transport Layer
• Exactly how does w increase?• Sender maintains a so-called threshold value t,
where t is larger than the initial value of w– While w < t, the size of w doubles after each
successful transmission– While w >= t, the size of w is increased by one after
each successful transmission (segment size unit)– If a timeout is experienced: t = w/2, w = 1
Networking – Transport Layer
Networking – Transport Layer
• Final question – what is a proper initial value for the threshold?
• Common choice is the current value of the data window size, as defined by flow control
• Allows sending of data segments up to full buffer size, if possible
Networking – Transport Layer
• Variants of TCP congestion control– Tahoe – as described above– Reno – includes mechanisms for fast
retransmission and fast recovery– Vegas – more sophisticated management of
window sizes and threshold
Networking – Transport Layer
• Does TCP congestion control achieve the desired goal – global fairness of bandwidth use?
• Yes, seems to work in practice. Theory is somewhat complicated…
• Big joker is UDP-based applications!
Networking – Transport Layer