Lecture 1 2
To achieve the global connectivity, ideally we
have a virtual global network to which every
machine can connect to.
However, in the real world, we do not have such
Many different networks with different technologies
and protocols are existed all over the world.
We called they are heterogeneous networks.
Lecture 1 3
We establish physical links and routers to connect
we apply the same higher level communication
protocol for each machine such that receivers can
understand the content of packets sent from senders.
Lecture 1 4
TCP/IP = Transmission
Developed in 1970s by
the US Department of
Lecture 1 5
Physical (Chapter 4)
Link (Chapter 5)
Internet (IP = Internet Protocol)
specify the format of the packets sent across the
Internet and the mechanisms used to forward packets
from a station through one or more routers to the
Lecture 1 6
Transport (TCP = Transmission Control
specify an end-to-end protocol for the reliable transfer
of data between two programs.
specify how one application uses an Internet.
Lecture 1 7
H-to-N Data HT
Lecture 1 8
Hierarchical addressing: IP address are 32 bits in
length and are used in the source and destination
address fields of the IP datagram.
Connectionless routing: each data packet is an
individual datagram to do the routing.
Lecture 1 9
Dotted Decimal Notation
It is difficult for human being to read 32-bit IP
addresses in technical documents or through
Thus IP addresses are written as four decimal
integers separated by decimal points, where each
integer gives the value of one octet of the IP address
(1 octet = 8 bits).
Lecture 1 10
10000000 00001010 00000010 00011110
is written as 184.108.40.206
220.127.116.11 is written as
10010101 00001000 00001100 00101000
Lecture 1 11
Two components: network id. and host id.
Network id.: identifies the network;
Host id.: identifies the station (or host computer) on
that network (as identified by the network id.).
Network id. Host id.
Lecture 1 12
Trade off between the size of the network id.
field and that of the host id. field.
Larger network id. ⇒ larger possible number of
networks (in the Internet) with each network having
smaller number of hosts.
Larger host id. ⇒ larger number of hosts in a
network but the possible number of networks is
To accommodate networks of different sizes, we
classified networks into 5 categories: A, B, C, D and
Lecture 1 13
0 Network Host
10 Network Host
110 Network Host
1110 Multicast address
11110 Reserved for future use
Lecture 1 14
126 networks (7-bit network id. − 2 special cases);
All 0s (0.0.0.0): allow only at system startup and never be a
valid destination address. Once a machine learns its correct
IP address, all 0s will not be used.
All 1s (127.xx.yy.zz): reserved for loop back test (testing the
TCP/IP on a local machine, send a packet from its output
port and receive it from its own input port).
16.8 million hosts (24-bit host id. − 2 special cases);
All 0s (xx.0.0.0): network.
All 1s (xx.255.255.255): broadcast within the network.
Lecture 1 15
16,382 networks (14-bit network id. − 2);
65534 hosts (16-bit host id. − 2);
2 million networks (21-bit network id. − 2);
254 hosts (8-bit host id. − 2);
28 bits to specify a multicast group;
can be used only as destination address;
Lecture 1 16
Version IHL Type of service Total length
F Fragment offset
Time to live Protocol Header checksum
Options (0 or more words)
Lecture 1 17
Total length: the total length of the datagram
Datagram = IP-PDU, packet routed in IP layer;
Maximum: 65,535 bytes (1 byte = 8 bits);
How to handle a message if its size is larger than the
maximum packet size of a physical network?
Solution: fragmentation and reassembling.
Lecture 1 18
IP Header: Fragmentation
Fragmentation of IP datagram is allowed
This feature facilitates building an Internet with
components networks accommodating different
maximum packet sizes.
Frame Data Area
Lecture 1 19
IP Header: Fragmentation
When an IP datagram is encapsulated by a physical
network frame (e.g. Ethernet frame), since the size of
a frame is limited (e.g. for fairness), the size of an IP
datagram is also limited. Thus we need to apply
fragmentation for the transmitted message longer
than the limited size.
Packet too long may suffer long transmission delay
and even cause network congestion. Thus short
packet is preferred.
Lecture 1 20
IP Header: Fragmentation
When the size of a datagram is larger than the
maximum one, a router breaks the datagram up
into a number of small fragments.
The destination host's IP layer can then
reassemble the fragments back to the complete
datagram before passing it up to upper layer
protocol (say TCP) entity.
Lecture 1 21
IP Header: Fragmentation
Identifier: When a large datagram needs to be
fragmented, all its fragments carry the same
value in the identifier field.
The destination host can determine which datagram
the current fragment belongs to and reassemble the
DF: when it sets to 1, it tells the Internet (router)
not to fragment the datagram.
Lecture 1 22
IP Header: Fragmentation
MF: when it sets to 1, it stands for 'more
All fragments of a datagram except the last one have
this bit set.
Fragment offset: it tells where in the containing
datagram this fragment belongs.
To reassemble, the destination host must obtain all
fragments starting with the fragment that has offset 0
through the fragment with the highest offset.
Lecture 1 23
Time to live: it specifies how long, in seconds,
the datagram is allowed to remain in the internet
Protocol: it tells the network access layer in the
destination host, which upper protocol process
to give the datagram to.
Usually it will be TCP or UDP.
Lecture 1 24
Header checksum: a checksum verifying the
Lecture 1 25
Lecture 1 26
Consider H1 would like to send a packet to H3.
H1 is the end station of the network NetA, and H2, H3
and H4 are the end stations of the network NetD.
H1 communicates with other stations by using the
native protocol of the network NetA (say PrA, e.g.
Similarly, H2, H3 and H4 communicate with each
other with the native protocol of NetD (say PrD, e.g.
Lecture 1 27
It is possible that PrA, PrB , PrC and PrD are not the
H1 does so by using IP protocol which H1, R(ABD)
and H3 all understand and agree upon.
H1 puts H3's IP address in the destination address
and its own IP address in the source address.
H1 also puts the destination address of R(ABD) in the
destination address field of the header of PrA-PDU.
Lecture 1 28
When the PrA-PDU is routed by NetA to the
destination R(ABD), R(ABD) will extract the IP
datagram from the PrA-PDU and look at the
destination address and decide that the destination is
So R(ABD) sends the IP datagram to station H3, this
time embedding the datagram in a PrD-PDU.
When H3 receives the PrD-PDU, it will extract the IP
datagram and obtain the data.
Lecture 1 29
ET = Ethernet Tail
TT = Token Ring Tail
Px(y) = Physical address of y in x
Token Ring Header
Network NetA Network NetD
Lecture 1 30
How does the router make a suitable decision to
route the packet to H3? Solution: Routing table.
A network on the Internet is usually designated
by the network prefix of its IP address followed
by appending 0's to the suffix.
Example: the network 144.214 in the next slide is
usually designated 18.104.22.168.
Lecture 1 31
A router is connected to more than one network.
Hence it has multiple IP addresses.
Example: the router below has two IP addresses:
22.214.171.124 and 126.96.36.199.
Lecture 1 32
NetB NetC NetD
Routing table at R2
Destination Next hop
NetC direct deliver
NetD direct deliver
Lecture 1 33
In practice, the networks are identified by its IP
The router uses a network-id mask (also called
a subnet mask) to extract the network id from a
(destination station) IP address and search the
routing table for a match.
Lecture 1 35
Routing table at R2 would look like
Destination Mask Next hop
188.8.131.52 255.0.0.0 184.108.40.206
220.127.116.11 255.0.0.0 18.104.22.168
22.214.171.124 255.255.0.0 direct deliver
126.96.36.199 255.255.255.0 direct deliver
188.8.131.52 255.255.0.0 184.108.40.206
Lecture 1 36
Datagram P arrive at R2 with destination address
For each entry in the routing table, the corresponding
mask is “anded” with the destination address and the
result (220.127.116.11) is compared to the destination
If a match is found, it will be sent to the address at
the next hop field (18.104.22.168).
Lecture 1 37
Companion IP Protocols
The core IP protocol is for the sending of
datagrams between stations across the Internet.
There are a number of companion protocols to
handle other functions.
Two important protocols will be described: ICMP
(Internet Control Message Protocol) and ARP
(Address Resolution Protocol).
Lecture 1 38
It is used to communicate control messages
between host and router, among routers and
ICMP messages are embedded in the data field
of a datagram and the protocol type is set to 1.
IP header IP data field
IP datagramICMP message
Protocol = 1
Lecture 1 39
Most ICMP messages are for signaling error or
Messages between routers and hosts:
'can't reach destination'
'slow down - congestion'
'there is a better route to send data', …, etc.
Lecture 1 40
Messages between hosts:
'can't read application'
'reassembly time expired'
'slow down - congestion'
'echo reply', …, etc.
Lecture 1 41
When an IP datagram arrives at a destination
router, the router will send the datagram to the
destination host over the destination network.
Since the format of the physical network
address (e.g. Ethernet address) is different from
that of the IP address, usually the router has a
table to map the destination IP address to its
corresponding physical network address.
Lecture 1 42
The router then sends the datagram to the
destination by encapsulating the datagram in
the corresponding physical network address.
However, if the router does not know it, how
does the router send the datagram?
The router may not know the mapping if the
configuration of the physical network is changed, or
the station is just joined the network.
Lecture 1 43
destination address Ap
Lecture 1 44
An IP datagram with destination address Ap (e.g.
22.214.171.124) arrives at the (destination) router
The router wants to know the Ethernet address
of the station with IP address Ap. R broadcasts a
request: “Who owns IP address Ap?” on the
destination LAN (e.g. 126.96.36.199).
Lecture 1 45
Only the destination with the IP address Ap will
response, giving its physical network address to
R (e.g. Ethernet address E).
Then R updates its table and send the datagram
to the destination.
Note that a source station can use ARP to find
the local network address of the router if
Lecture 1 46
Transmission Control Protocol
To provide a point-to-point reliable connection
oriented service for upper (application) layer entities.
To provide for multiplexing of multiple transport
connections over a single network.
Lecture 1 47
TCP PDUs are called segments.
Fixed size header (20 bytes);
The data field can be up to 216
− 40 bytes (TCP
and IP headers), i.e. 65,495 bytes.
Lecture 1 48
Options (0 or more 32-bit words)
Lecture 1 49
Source port and destination port: TCP port
numbers that identify the application programs
at the ends of the connection.
A port number plus an IP address form an unique
transport service access point (TSAP).
Sequence number (SEQ): identify the position in
the sender’s byte stream of the data in the
Lecture 1 50
Acknowledgement number (ACKN): identifies
the number of the octet that the source expects
to receive next.
TCP header length: TCP segment’s header (in
units of 32-bit words);
Lecture 1 51
When it sets to 1, the urgent pointer is in use.
The pointer is used to specify the position in the
segment where urgent data ends.
This is used to draw attention of the receiver.
When it sets to 1, the field of the acknowledgement
number (ACKN) is valid.
Lecture 1 52
When it sets to 1, it indicates to the receiver that it
should deliver the data (and any already buffered) to
the application program.
Otherwise, the receiver may buffer (and only deliver
when buffer is full) for efficiency.
When it sets to 1, reset the connection.
Lecture 1 53
Used for connection set-up;
SYN = 1, ACK = 0 ⇒ connection set-up request;
SYN = 1, ACK = 1 ⇒ connection set-up accept;
Used for connection release;
When it sets to 1, the sender has reached end of its
Lecture 1 54
SYN(SEQ = x)
SYN(SEQ = y, ACKN = x + 1)
SYN(SEQ = x + 1, ACKN = y + 1)
Lecture 1 55
The advantage of three-way handshake is that it still
works even the TCP segment containing the
connection-accept segment is lost.
Note that a new set of starting sequence numbers is
used on connection set-up. This is to avoid any
segment from a previous connection session
between the same processes from confusing the
Lecture 1 56
Lecture 1 57
Damaged and lost segments are handled by a
positive acknowledgement time-out retransmission
Duplicated and out of order segments are detected
by use of the sequence number field.
Lecture 1 58
It is affected by a window mechanism.
The send window size can be dynamically changed
by the receiver (based on its buffer condition).
Window advertisement (the window size field in the
TCP header) specifies how many octets (1 octet = 8
bits) of data that the receiver is prepared to accept.
Example : maximum segment size of the sender is
1000 octets and maximum window advertisement is
Lecture 1 59
advertise window = 2500
send data octets 1 - 1000
send data octets 1001 - 2000
send data octets 2001 - 2500
ack up to 1000, window = 1500
ack up to 2000, window = 500
ack up to 2500, window = 0
receive ack for 1000
receive ack for 2000
receive ack for 2500 application reads 2000 octets
ack up to 2500, window = 2000
ack up to 3500, window = 1000
ack up to 4500, window = 0
application reads 1000 octets
ack up to 4500, window = 1000
send data octets 2501 - 3500
send data octets 3501 - 4500
receive ack for 4500
receive ack for 3500
receive ack for 4500
Lecture 1 60
Congestion control: slow-start algorithm
TCP (sender) maintains two windows, a send window
Ws which is set by receiver’s window advertisement,
and a congestion window Wc.
The sender uses the smaller of the two for actual
A threshold, T, is an integer such that the congestion
window will increase exponentially before reaching
Usually T will be initially set to 64k bytes.
Lecture 1 61
1. Wc = 1.
2. When (i) a window is sent, (ii) there is no time-out, and
(iii) Wc is smaller than the threshold,
Wc = min(2 × Wc, threshold)
(growth rate is exponential).
3. When (i) a window is sent, (ii) there is no time-out, and
(iii) Wc is not smaller than the threshold,
Wc = Wc + 1 (growth rate is linear).
4. When a time-out occurs, T = Wc / 2 and Wc = 1.
Lecture 1 64
A host use an unique IP address to
communicate through the Internet.
Within that machine, there may be multiple
application programs requiring remote
The TCP layer implements multiple transport
connections over a single network interface.
Lecture 1 65
Host A Host B
Lecture 1 66
User Data Protocol
Connectionless transport protocol
suitable for applications requiring short
packet is up to 64 kbytes.
Destination portSource port
Lecture 1 67
1. When an IP datagram is to be routed through a network
whose maximum packet size is smaller than that of the
datagram, it is fragmented into smaller datagrams.
Where do you think is better to reassemble the
datagram? At the next router or at the destination host
(IP layer)? Explain.
Lecture 1 68
2. Most IP datagram reassembly algorithms have a timer to
avoid having a lost fragment tie up reassembly buffers
forever. Suppose a datagram is fragmented into 4
fragments. The first 3 fragments arrive, but the last one
is delayed. Eventually the timer goes off and the three
fragments in the receiver’s memory are discarded. A
little later, the last fragment stumbles in. What should be
done with it?
Lecture 1 69
3. How many responses a router expects to get when it
broadcasts an ARP request? Why?
4. You have just explained the ARP protocol to a friend.
When you are all done, he says: “I have got it. ARP
provides a service to the network layer, so it is part of
the data link layer.” What do you say to him?
Lecture 1 70
5. Write out the following IP address in dotted decimal
10010000 11001000 00100101 01000001
6. Is the IP address space efficiently utilized? Explain.
Suppose that instead of using 16 bits for the network
part of a class B address, 20 bits has been used. How
many class B networks would there have been?
Lecture 1 71
7. What is the size of the port number space for TCP?
What is the maximum size of a TCP segment? Under
what condition is this maximum size achievable?
8. Consider a TCP connection over the Internet. When a
time-out occurs on the sending of a segment, which is
by far most likely the cause: (i) congestion, (ii) error:
damaged or lost IP datagram (which encapsulates the
TCP segment). Explain.
Lecture 1 72
9. Consider the slow start flow control algorithm used in
TCP. Suppose the maximum segment size is 1 Kbytes.
Suppose the congestion window Wc just before a time-
out was 32 Kbytes. What are the congestion window
sizes for the first 8 transmissions after the time-out?
Assume that there are no time-outs during these 8