Networks
Networks
reference model
-Defines what operations should occur at different layers of a network
Application: Supporting network applications
Presentation (How the data is presented on a specific device/application): Allow
applications to interpret the “meaning” of data (e.g. encryption, compression, machine-
specific conventions)
Session (Tracks progress of data exchange): Synchronization, check-pointing, recovery
of data exchange
Transport (specific process running): Process-process data transfer
Network (moving data from source to next switch/hop to end point in most efficient
way): Routing of datagrams from source to destination
Link(Only worried about one device to next device): Transfer between neighbouring
network elements
Physical (how data is encoded on physical medium): Encoded bits “on the wire”
Internet protocol stack is the presentation and session layers, if these services are needed, they
must be implemented in the application layer
Encapsulation
At the application layer a message is generated by the application being used on the
source device
The application layer passes the message down to the transport layer
Transport layer receives the message and encapsulates (puts the message into a transport
layer envelope) it in its own header(adds required information such as port number etc)
now referred to as a segment
The segment is passed down to the network layer which encapsulates it further by adding
another header (required information e.g. IP addresses [source and destination]) now
referred to as a datagram/packet
Datagram is passed down to link layer, encapsulates it further, adds a header (physical
address such as a specific router or interface), now called a frame
Frame passed down to physical layer which sends it to a switch
Frame is passed up to link layer to determine next device to receive message
Pushed back down to physical and hits next link (e.g. router)
Message is pushed up to network layer, back down to physical layer and is sent to
destination device
Destination device decapsulates the frame to return it back to a message by going up the
layers
What’s a protocol?
Rules for specific messages sent
Rules for specific actions taken when message received or other events
Protocols define the format, order of messages sent and received among network entities and
actions take on message transmission receipt
Network protocols:
Internet structure:
Network edge:
Hosts: Clients and servers (in homes, businesses, data centers for servers)
Network core:
Interconnected routers
Network of networks
Routing algorithms (and routing overall) to figure out the best path before starting
delivery
Forwarding aka “switching”, a local action to move arriving packets from router’s input
link to appropriate router output link (the destination address is in the arriving packet’s
header), creates a forwarding table where the header value relates to an output link
Routing is a global action which determines the source-destination path taking by packets
Processing delay (time it takes a router to read a packet’s header information and look in
the forwarding table for which output queue it should be in)
Transmission delay: time taken for packet to be taken from queue and pushed out on link
= (L/R)
Queuing delay: How long a packet stays in queue
Propagation delay: How long it takes for data to move from source router to receiving
router = d/s (d = distance, s = propagation speed)
Packet delay:
d(nodal) = d(proc) + d(queue) + d(trans) + d(prop)
Traceroute program: provides delay measurement from source to router along end-end
internet path towards destination. For all i:
-Sends three packets that will reach router i on path towards destination (with time to
live field value of i, each router decrements the time-to-live value by 1)
-Router i will return packets to sender
-Sender measures time interval between transmission and reply
Throughput:
Throughput: rate (bits/time unit) at which bits are sent from sender to receiver
-Instantaneous: rate at given point in time
-Average rate over longer period of time
Bottleneck link – Link that puts a constraint on end-end throughput (the link with a
lower throughput)
In reality if there are multiple connections: end-end throughput the minimum of all the
throughputs over the number of connections
In practice R (source to link) or R(receiver link) is the bottleneck
Application Layer:
Client-Server Paradigm:
Server:
Always-on host
Permanent IP address
Often in data centers for scaling
Clients:
Peer-Peer architecture:
No always-on server
Arbitrary end systems directly communicate
Peers request service from other peers, provide service in return to other peers (self
scalability = new peers bring new service capacity as well as new service demands)
Peers are intermittently connected and change IP addresses (have complex management)
E.g. P2P file sharing
Process Communicating:
Within same host, two processes communicate via inter-process communication (defined
by OS)
Processes in different hosts communicate by exchanging messages
Client process = process that initiates contact
Server process = process that waits to be contacted
P2P programs have client processes and server processes
Sockets
A process sends/receives messages to/from its socket
Socket is similar to a door:
-Sending process shoves message out of door
-Sending process relies on transport infrastructure
-Two sockets are involved, one on each end
Addressing processes:
To receive messages, process must have an identifier
Host device has a unique 32 bit IP address
Many processes can be running on one host
Identifiers include both IP address and port number associated with the process on the
host
Socket Programming:
Two socket types for two transport systems:
-UDP: Unreliable datagram
-TCP: Reliable, byte stream-oriented
HTTP Overview
HTTP = Hyper text transfer protocol
Web’s application layer protocol
Client/server model:
-Client: Browser that requests, receives (using HTTP protocol) and displays web object
-Server: Web server sends (using HTTP protocol) objects in response to requests
HTTP uses TCP:
Client initiates TCP connection(creates socket) to server, port 80
Server accepts TCP connection from client
HTTP messages (application layer protocol message) exchanged between browser
(HTTP client) and Web server
TCP connection closes
HTTP is stateless: server maintains no information about past client requests
Protocols that maintain “state” are complex:
-History must be maintained
-if server/client crashes their views of “state” may be inconsistent and must be fixed
Persistent HTTP:
Persistent HTTP:
Non-persistent HTTP issues:
-Requires 2 RTTs per object
-OS overheads for each TCP connection
-Browsers often open multiple parallel TCP connections to fetch referenced objects in
parallel
Persistent HTTP:
-Server leaves connection open after sending response
-Subsequent HTTP messages between same client/server are sent via open connection
-Client sends requests as soon as it encounters a referenced object
-As little as one RTT for all the referenced objects
Authorization
Shopping carts
Recommendations
User session state (web emails)
Web Caches:
Goal: Satisfy client requests without involving origin server
DNS:
Hostname-to-IP-Address translation
Host aliasing (canonical, alias names)
Mail server aliasing
Load distribution (replicated web servers: Many ip addresses correspond to one name)
DNS Hierarchy:
1. Root
2. Top Level Domain
3. Authoritative
DNS Records
DNS: Distributed database storing resource records(RR)
RR format: (name, value, type, ttl)
Type=A
-name is hostname
-value is IP address
Type = CNAME
-name is alias name for some canonical (real) name
-e.g. www.ibm.com is really servereast.backup2.ibm.com
-value is canonical name
Type = NS
-name is domain (e.g. foo.com)
-value is hostname of authoritative name server for this domain
Type=MX
-value is name of SMTP mail server associated with name
RDT 1.0:
The sending side of reliable data transfer (rdt) accepts data from the upper layer via
rdt_send(data) event, creates a packet containing the data via (make_pkt(data)) and sends
the packet into the channel
In practice the rdt_send(data) event would result from a procedure call (for example, to
rdt_send()) by the upper layer application
On the receiving side, rdt receives a packet from the underlying channel via
rdt_rcv(packet) event and removes data from the packet via the extract(packet,data)
action, and passes data up to the upper layer
In this simple protocol there is no different between a unit of data and a packet
All packet flow is from sender to receiver with a perfectly reliable channel there is no
need for the receiver side to provide any feedback to the sender
RDT 2.0:
Error detection: A mechanism is needed to allow the receiver to detect when bit errors
have occurred (e.g. the internet checkmsum field is used by UDP). These techniques
require extra bits be sent from the sender to the receiver to be gathered into the checksum
field
Receiver feedback: Receiver provides explicit feedback to the sender. The positive
(ACK) and negative (NAK) acknowledgement replies in the message dictation scenario
are examples of feedback
Retransmission: A packet received in error at the receiver will be retransmitted by the
sender
The sender knows that the most recently transmitted packet has been received correctly
and thus the protocol returns to the state of waiting for data from the upper layer
If a NAK is received, the protocol retransmits the last packet and waits for an ACK or
NAK to be returned by the receiver in response to the retransmitted data packet
It is important to note that when the sender is in the wait-for-ACK-or-NAK state it cannot
get more data from the upper layer
The sender will not send a new piece of data until it is sure that the receiver has correctly
received the current packet, as a result protocols such as RTD2.0 are known as stop-and-
wait protocols
The receiver-side for RDT.20 still has a single state
The receiver replies with either an ACK or NAK depending on whether the received
packet is corrupted
RDT2.0 has a flaw, we haven’t accounted for if the ACK and NAK packet are corrupted
If ACK/NAK packet is corrupted the sender won’t know if the receiver has correctly
received last piece of data transmitted
Receiver would repeat the reply with “What did you say” packet
Add enough checksum bits to allow the sender to detect and recover from bit errors
Sender resends the current data packet when it receives a garbled ACK/NAK packet, this
introduces duplicate packets, receiver however then doesn’t know whether the ACK or
NAK it last sent was received properly
Simple solution: Add a new field to the data packet and have the sender number its data
packets by putting a sequence number into this field
For our simple case of stop-and-wait, a 1-bit sequence number will suffice to let the
receiver know whether the sender is resending the previously transmitted packet or anew
packet
RDT2.1 uses both positive and negative acknowledge from the receiver to the sender
When an out of order packet is received the receiver sends a positive acknowledgement
for the packet it has received
When a corrupted packet is received the receiver sends a negative acknowledgement
Sender that receives two ACKs for the same packet (receives duplicate ACKs) knows
that the receiver did not correctly receive the packet following the packet that is being
ACKed twice
Receiver must now include the sequence number of the packet being acknowledged by
the ACK message
Sender must now check the sequence number of the packet being acknowledged by a
received ACK message
How to detect packet loss and what to do when packet loss occurs:
Use of checksumming, sequence numbers, ACK packets and retransmissions will allow
us to answer the latter concern
The protocol should ideally recover from packet loss as soon as possible; waiting for a
worst case delay could mean a long wait until recovery is initiated
The approach adopted is for the sender to judiciously choose a time value such that
packet loss is likely although not guaranteed to have happened
If an ACK is not received within this time the packet is retransmitted
If a packet experiences a particularly large delay the sender may retransmit the packet
even though neither the packet nor its ACK have been lost
This introduces the possibility of duplicate data packets in the sender-to-receiver channel
The sender does not know whether a data packet was lost, an ACK was lost or if the
packet or ACK was simply delayed
In all cases the action is the same, retransmit. Implementing a time-based retransmission
machnism requires a countdown timer that can interrupt the sender after a given amount
of time
The sender will need to be able to start the timer each time a packet is sent
Respond to a timer interrupting
Stop the timer
The receive time for a packet is necessarily later than the send time for a packet as a
result of transmission and propagation delays
Because pattern sequence numbers alternate between 0 and 1, RDT 3.0 is sometimes
known as alternating protocol
The solution to this performance problem is for the sender to send multiple packets
without waiting for acknowledgements
Since the many-in transit sender to receiver packets can be visualized as filling a pipeline
this technique is called pipelining and has the following consequences:
-Range of sequence numbers must increase
-Sender and receiver may have to buffer more than one packet
-Range of sequence numbers needed and buffering requirements depend on the manner in
which a data transfer protocol responds to lost, corrupted and overly delayed packets, the
two basic approaches being “Go-Back-N” and “Selective repeat”
Go-Back-N(GBN):
The sender is allowed to transmit multiple packets (when available) without waiting for
acknowledgment but is constrained to some maximum allowable number, N, for
unacknowledged packets in the pipeline
“base” = number of the oldest unacknowledged packet and “next seqnum”= smallest
unused sequence number (that is, the sequence number of the next packet to be sent),
then four intervals in the range of sequence numbers can be identified
The range of permissible sequence numbers for transmitted but not yet acknowledged
packets can be viewed as a window of size N over the range of sequence numbers
N is often referred to as the window size and the GBN protocol itself is as a sliding
window protocol
A packet’s sequence number is carried in a fixed length field in the packet header
RDT3.0 had a 1 bit sequence number and a range of [0,1]
TCP has a 32 bit sequence number field where TCP sequence numbers count bytes in the
byte stream rather than packets
The GBN sender must respond with three types of events:
-Invocation from above: When rdt_send() is called from above the sender first checks to
see if the window is full, if the window is not full a packet is created and sent and the
variables are appropriately updated, if the window is full the sender simply returns the
data back to the upper layer, an implicit indication that the window is full
-Receipt of an ACK: In our GBN protocol an acknowledgement for a packet with
sequence number n will be taken to be a cumulative acknowledgement
-A timeout event: The protocol’s name “Go-Back-N” is derived from the senders
behaviour in the presence of lost or delayed packets, as in the stop and wait protocol a
timer will again be used to recover from lost data or acknowledgement packets, if a
timeout occurs the sender resends all packets that have been previously sent but not yet
acknowledged
Receiver’s actions in GBN are simple, if a packet with a sequence number n is received
correctly and is in order, the receiver sends an ACK for packet n and delivers the data
portion of the packet to the upper layer, in all other cases the receiver discards the packet
and resends an ACK for the most recently received in order packet
Since packets are delivered one at a time, if packet k is delivered and acknowledged then
all packets with a sequence number lower than k have been delivered
Suppose that packet n is expected but packet n+1 arrives, because data must be delivered
in order the receiver could buffer (save) packet n+1 and then deliver this packet to the
upper layer after receiving packet n
However if packet n is lost, both it and packet n+1 will be retransmitted as a result of the
retransmission rule at the sender
Therefore the receiver can simply discard packet n+1
Advantage of this approach is simplicity of receiver buffering, the receiver need not
buffer any out of order packets
While the sender must maintain the upper and lower bounds of its window and its
position of nextseqnum, the only piece of information the receiver must maintain is the
sequence number of the next in order packet
The disadvantage of throwing away a correctly received packet is that the subsequent
retransmission may be lost or garbled and more retransmissions would be required
The implementation would be in the form of various procedures that implement the
actions to be taken in response to the various events that occur
In event-based programming the various procedures are called either by other procedures
in the protocol stack or as the result of an interrupt
In the sender, these events would be:
-Call from upper layer entity to invoke rdt_send()
-A timer interrupt
-A call from the lower layer to invoke rdt_rcv() when a packet arrives
Selective Repeat(SR):
The GBN protocol allows the sender to fill the pipeline with packets, thus avoiding
channel utilization problems we noted in the stop and wait protocols
GBN itself suffers from performance problems, in particular when the window size and
bandwidth delay product are both large, many packets can be in the pipeline
A single packet error can thus cause GBN to retransmit a large number of packets
unnecessarily
As the probability of channel errors increases, the pipeline can become filled with these
unnecessary transmissions
Selective repeat protocols avoid unnecessary retransmissions by having the sender
retransmit only those packets that it suspects were received in error (that is, were lost or
corrupted) at the receiver
A window size of N will again be used to limit the number of outstanding
unacknowledged packets in the pipeline
However unlike GBN, the sender will have already received ACKs for some of the
packets in the window
The SR receiver will acknowledge a correctly received packet whether it is in order or
not
Out of order packets are buffered until any missing packets (that is packets with lower
sequence numbers) are received at which point a batch of packets are delivered to the
upper layer
In step 2 figure 3.25 the receiver acknowledges the already received packets with certain
sequence numbers below the current window base
When the “channel” connecting the two is a network, packet reordering can occur
One manifestation of packet reordering is that old copies of a packet with a sequence or
acknowledgement number of x can appear, even though neither the sender’s nor
receiver’s window contains x
Because sequence numbers may be reused, some care must be taken to guard against
such duplicate packets
The approach taken in practice is to ensure that a sequence number is not reused until the
sender is “sure” that any previously sent packets with sequence number x are no longer in
the network
This is done by assuming that a packet cannot “live” in the network for longer than some
fixed maximum amount of time
A maximum packet lifetime of approx 3 minutes is assumed in the TCP extensions high
speed networks
TCP connection:
TCP is said to be connection-oriented because before one application process can begin
to send data, the two processes must first “handshake” that is they must send some
preliminary segments to eachother to establish the parameters of the ensuing data transfer
The TCP connection is an not end-to-end, TDM or FDM circuit as in a circuit-switched
network
Instead the connection is a logical one with common state residing only in the TCPs in
the two communicating end systems
Recall that because the TCP protocol only runs in the end systems and not intermediate
network elements (routers and link layer switches) the intermediate network elements do
not maintain TCP connection state
A TCP connection provides a full-duplex service: If there is a TCP connection between
process A on one host and process B on another host, then the application layer data can
flow from process A to process B at the same time as application layer data flows from
process B to process A
A TCP connection is always point-to-point, between a single sender and single receiver
Recall that the process that is initiating the connection is called the client process while
the other is called the server process
The client application process first informs the client transport layer that it wants to
establish connection to a process in the server
TCP in the client then proceeds to establish a TCP connection with TCP in the server
Client first sends a special TCP segment; the server responds with a second special TCP
segment; finally the client responds again with a third special segment
The first two special segments carry no payload (no application layer data), the third of
these segments may carry a payload
Because three segments are sent between the two hosts, this connection establishment
procedure is often referred to as a “three-way handshake”
Once a TCP connection is established, the two application processes can send data to
eachother
The client process passes a stream of data through the socket
TCP directs this data to the connections send buffer which is one of the buffers that is set
aside during the initial three way handshake
From time to time TCP will grab chunks of data from the send buffer and pass the data to
the network layer
The maximum amount of data that can be grabbed and placed in a segment is limited by
the maximum segment size (MSS)
The MSS is typically set by first determining the length of the largest link-layer frame
that can be sent by the local sending host (the so called maximum transmission unit
(MTU))
Typical value of MSS = 1460 bytes
The MSS is the maximum amount of application layer data in the segment, not the
maximum size of the TCP segment including headers
TCP pairs each chunk of client data with a TCP header thereby forming TCP segments
Segments are passed down to the network layer where they are separately encapsulated
within the network layer IP datagrams
The datagrams are sent into the network
When TCP receives a segment at the other end the segments data is placed in the TCP
connection receive buffer
The application reads the stream of data from this buffer
TCP connection consists of buffers, variables and a socket connection a process in one
host and another set of buffers, variables and a socket connection to a process in another
host
Two of the most important fields in the TCP segment header are the sequence number
field and the acknowledgement number field
TCP views data as an unstructured but ordered stream of bytes
TCP’s use of sequence numbers reflects his view in that the sequence numbers are over
the stream of transmitted bytes and not over the series of transmitted segments
The sequence number for a segment is therefore the byte stream number of the first byte
in the segment
The TCP in host A will implicitly number each byte in the data stream
TCP constructs segments out of the data stream, the first segments gets assigned
sequence number 0
Each sequence number is inserted in the sequence umber field in the header of the
appropriate TCP segment
Recall that TCP is full-duplex so that host A may be receiving data from Host B while it
sends data to host B (as part of the same connection)
Each of the segments that arrive from host B has a sequence number for the data flowing
from B to A
The acknowledgement number that host A puts in its segment is the sequence number of
the next byte Host A is expecting from host B
Because TCP only acknowledges bytes up to the first missing byte in the stream, TCP is
said to provide cumulative acknowledgements
What does a host do when it receives out of order segments in a TCP connection?:
1. The receiver immediately discards out of order segments
2. Or the receiver keeps the out of order bytes and waits for the missing bytes to fill the
gaps
Both sides of a TCP connection randomly choose an initial sequence number
This is done to minimize the possibility that a segment that is still present in the network
from an earlier, already terminated connection is mistaken for a valid segment in a later
connection between two of the same hosts
Sequence number of a segment is the sequence number of the first byte in the data field
Acknowledgement number is the sequence number of the next byte of data that the host
is waiting for
Flow Control:
If the application is relatively slow at reading data, the sender can very easily overflow
the connection’s receive buffer
TCP provides a flow control service to eliminate the possibility of the sender overflowing
the receiver’s buffer
Flow control is a speed matching service, matching the rate at which the sender is
sending against the reading rate of the receiving application
TCP provides flow control by having the sender maintain a variable called the receive
window
This is used to give the sender an idea of how much free buffer space is available at the
receiver
Due to TCP being full-duplex, the sender at each side maintains a distinct receive
window
Receive window (rwnd) is set to the amount of spare room in buffer
Rwnd is dynamic
There is one minor technical problem with this scheme. To see this, suppose Host B’s receive
buffer becomes full so that rwnd = 0. After advertising rwnd = 0 to Host A, also suppose that B
has nothing to send to A. Now consider what happens. As the application process at B empties
the buffer, TCP does not send new segments with new rwnd values to Host A
To counter this TCP specification requires Host A to continue to send segments with one data
byte when B’s receive window is zero.
1. Client side TCP first sends a special TCP segment to the server side TCP, this contains
no data but one of the flag bits in the segment’s header, the SYN bit is set to 1, client
randomly chooses an initial sequence number, this segment is encapsulated within an ip
datagram and sent to the server
2. Once the datagram arrives containing the TCP SYN segment, the server extracts the TCP
SYN segment, allocates the TCP buffers and variables to the connection and sends a
connection granted segment to client TCP, This connection granted segment also contains
no data but does contain the SYN bit set to 1, the acknowledgement field is set to
client_isn+1 and the server chooses its own random initial sequence number (this is a
synack segment)
3. Upon receiving SYNACK segment, the client allocates buffers and variables to
connection and sends the server another segment acknowledging the connection granted
segment (done via the value: server_isn+1) in the acknowledgement field of the TCP
segment header
Once this is done the client and server hosts can send eachother data, in each of these
future segments being sent SYN will be set to 0
Either participants can end the connection, when a connection ends the resources (buffers
and variables) in the hosts are deallocated
Client application process issues a close command, this causes the client TCP to send a special
TCP segment to server process with flag bit in segment header for FIN bit being set to 1
Once the server receives this is sends the client an acknowledgement segment in return
The server then sends its own shutdown segment which has the FIN bit set to 1, client
acknowledges shutdown segment
Established state = data sending state