The Network Layer
The Network Layer
&
Computer networks
Lecture 6: The Network Layer
Network layer
transport segment from
sending to receiving host
on sending side
encapsulates segments into
datagrams
on rcving side, delivers
segments to transport layer
network layer protocols in
every host, router
Router examines header
fields in all IP datagrams
passing through it
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
application
transport
network
data link
physical
application
transport
network
data link
physical
Key Network-Layer Functions
forwarding: move packets from routers input to
appropriate router output
routing: determine route taken by packets from source to
dest.
Routing algorithms
1
2
3
0111
value in arriving
packets header
routing algorithm
local forwarding table
header value output link
0100
0101
0111
1001
3
2
2
1
Interplay between routing and forwarding
Connection setup
3
rd
important function in some network architectures:
ATM, frame relay, X.25
Before datagrams flow, two hosts and intervening routers establish
virtual connection
Routers get involved
Network and transport layer cnctn service:
Network: between two hosts
Transport: between two processes
Network service model
Q: What service model for channel transporting
datagrams from sender to rcvr?
Example services for
individual datagrams:
guaranteed delivery
Guaranteed delivery
with less than 40 msec
delay
Example services for a
flow of datagrams:
In-order datagram
delivery
Guaranteed minimum
bandwidth to flow
Restrictions on changes
in inter-packet spacing
Network layer service models:
Network
Architecture
Internet
ATM
ATM
ATM
Service
Model
best effort
CBR
VBR
ABR
Bandwidth
none
constant
rate
guaranteed
rate
guaranteed
minimum
Loss
no
yes
yes
no
Order
no
yes
yes
yes
Timing
no
yes
yes
no
Congestion
feedback
no (inferred
via loss)
no
congestion
no
congestion
yes
Guarantees ?
IP datagram format
ver
length
32 bits
data
(variable length,
typically a TCP
or UDP segment)
16-bit identifier
Internet
checksum
time to
live
32 bit source IP address
IP protocol version
number
header length
(bytes)
max number
remaining hops
(decremented at
each router)
for
fragmentation/
reassembly
total datagram
length (bytes)
upper layer protocol
to deliver payload to
head.
len
type of
service
type of data
flgs
fragment
offset
upper
layer
32 bit destination IP address
Options (if any)
E.g. timestamp,
record route
taken, specify
list of routers
to visit.
how much overhead
with TCP?
20 bytes of TCP
20 bytes of IP
= 40 bytes + app
layer overhead
IP Fragmentation & Reassembly
network links have MTU
(max.transfer size) - largest
possible link-level frame.
different link types, different
MTUs
large IP datagram divided
(fragmented) within net
one datagram becomes
several datagrams
reassembled only at final
destination
IP header bits used to
identify, order related
fragments
fragmentation:
in: one large datagram
out: 3 smaller datagrams
reassembly
IP Fragmentation and Reassembly
ID
=x
offset
=0
fragflag
=0
length
=4000
ID
=x
offset
=0
fragflag
=1
length
=1500
ID
=x
offset
=185
fragflag
=1
length
=1500
ID
=x
offset
=370
fragflag
=0
length
=1040
One large datagram becomes
several smaller datagrams
Example
4000 byte datagram
MTU = 1500 bytes
1480 bytes in
data field
offset =
1480/8
IP Addressing: introduction
IP address: 32-bit
identifier for host,
router interface
interface: connection
between host/router
and physical link
routers typically have
multiple interfaces
host typically has one
interface
IP addresses associated
with each interface
223.1.1.1
223.1.1.2
223.1.1.3
223.1.1.4 223.1.2.9
223.1.2.2
223.1.2.1
223.1.3.2
223.1.3.1
223.1.3.27
223.1.1.1 = 11011111 00000001 00000001 00000001
223 1 1 1
Peter Smith 13
IP Address Classes
IP addresses are divided into 5 classes, each of which is designated
with the alphabetic letters A to E.
Class D addresses are used for multicasting.
Class E addresses are reserved for testing & some mysterious future
use.
Peter Smith 14
IP Address Classes (Cont.)
The 5 IP classes are split up based on the value in the 1
st
octet:
Peter Smith 15
IP Address Classes (Cont.)
Using the ranges, you can determine the class of an address from its
1
st
octet value.
An address beginning with 120 is a Class A address, 155 is a Class B
address & 220 is a Class C address.
Peter Smith 16
Are You the Host or the Network?
The 32 bits of the IP address are divided
into Network & Host portions, with the octets
assigned as a part of one or the other.
Network & Host Representation
By IP Address Class
Class
Octet1
Octet2
Octet3
Octet4
Class A
Network
Host
Host
Host
Class B
Network
Network
Host
Host
Class C
Network
Network
Network
Host
Peter Smith 17
Are You the Host or the Network?
(Cont.)
Each Network is assigned a network address & every device or
interface (such as a router port) on the network is assigned a host
address.
There are only 2 specific rules that govern the value of the address.
Peter Smith 18
Are You the Host or the Network?
(Cont.)
A host address cannot be designated by all zeros or all ones.
These are special addresses that are reserved for special purposes.
Peter Smith 19
Class A Addresses
Class A IP addresses use the 1
st
8 bits (1
st
Octet) to designate the
Network address.
The 1
st
bit which is always a 0, is used to indicate the address as a
Class A address & the remaining 7 bits are used to designate the
Network.
The other 3 octets contain the Host address.
Peter Smith 20
Class A Addresses (Cont.)
There are 128 Class A Network Addresses, but because addresses
with all zeros arent used & address 127 is a special purpose
address, 126 Class A Networks are available.
Peter Smith 21
Class A Addresses (Cont.)
There are 16,777,214 Host addresses available
in a Class A address.
Rather than remembering this number exactly,
you can use the following formula to compute the
number of hosts available in any of the class
addresses, where
n
represents the number of
bits in the host portion:
(2
n
2) = Number of available hosts
Peter Smith 22
Class A Addresses (Cont.)
For a Class A network, there are:
2
24
2 or 16,777,214 hosts.
Half of all IP addresses are Class A addresses.
You can use the same formula to determine the
number of Networks in an address class.
Eg., a Class A address uses 7 bits to designate
the network, so (2
7
2) = 126 or there can be
126 Class A Networks.
Peter Smith 23
Class B IP Addresses
Class B addresses use the 1
st
16 bits (two octets) for the Network
address.
The last 2 octets are used for the Host address.
The 1
st
2 bit, which are always 10, designate the address as a Class
B address & 14 bits are used to designate the Network. This leaves
16 bits (two octets) to designate the Hosts.
Peter Smith 24
Class B IP Addresses (Cont.)
So how many Class B Networks can there be?
Using our formula, (2
14
2), there can be 16,382 Class B Networks &
each Network can have (2
16
2) Hosts, or 65,534 Hosts.
Peter Smith 25
Class C IP Addresses
Class C addresses use the 1
st
24 bits (three octets) for the Network
address & only the last octet for Host addresses.the 1
st
3 bits of all
class C addresses are set to 110, leaving 21 bits for the Network
address, which means there can be 2,097,150 (2
21
2) Class C
Networks, but only 254 (2
8
2) Hosts per Network.
Peter Smith 26
Class C IP Addresses (Cont.)
Peter Smith 27
Special Addresses
A few addresses are set aside for specific purposes.
Network addresses that are all binary zeros, all binary ones &
Network addresses beginning with 127 are special Network
addresses.
Peter Smith 28
Special Addresses (Cont.)
Peter Smith 29
Special Addresses (Cont.)
Within each address class is a set of addresses that are set aside for
use in local networks sitting behind a firewall or NAT (Network
Address Translation) device or Networks not connected to the
Internet.
Peter Smith 30
Special Addresses (Cont.)
A list of these addresses for each IP address class:
Subnets
IP address:
subnet part (high order
bits)
host part (low order bits)
Whats a subnet ?
device interfaces with
same subnet part of IP
address
can physically reach
each other without
intervening router
223.1.1.1
223.1.1.2
223.1.1.3
223.1.1.4 223.1.2.9
223.1.2.2
223.1.2.1
223.1.3.2
223.1.3.1
223.1.3.27
network consisting of 3 subnets
subnet
Peter Smith 32
Subnet Mask (Cont.)
With the rapid growth of the internet & the
ever-increasing demand for new addresses,
the standard address class structure has been
expanded by borrowing bits from the Host
portion to allow for more Networks.
Under this addressing scheme, called
Subnetting, separating the Network & Host
requires a special process called Subnet
Masking.
Peter Smith 33
Subnet Mask
An IP address has 2 parts:
The Network identification.
The Host identification.
Frequently, the Network & Host portions of the
address need to be separately extracted.
In most cases, if you know the address class, its
easy to separate the 2 portions.
Peter Smith 34
Subnet Mask (Cont.)
The subnet masking process was developed
to identify & extract the Network part of the
address.
A subnet mask, which contains a binary bit
pattern of ones & zeros, is applied to an
address to determine whether the address is
on the local Network.
If it is not, the process of routing it to an
outside network begins.
Peter Smith 35
Subnet Mask (Cont.)
The function of a subnet mask is to determine
whether an IP address exists on the local
network or whether it must be routed outside
the local network.
It is applied to a messages destination
address to extract the network address.
If the extracted network address matches the
local network ID, the destination is located on
the local network.
Peter Smith 36
Subnet Mask (Cont.)
However, if they dont match, the message must be routed outside
the local network.
The process used to apply the subnet mask involves Boolean Algebra
to filter out non-matching bits to identify the network address.
Peter Smith 37
Boolean Algebra
Boolean Algebra is a process that applies
binary logic to yield binary results.
Working with subnet masks, you need only 4
basic principles of Boolean Algebra:
1 and 1 = 1
1 and 0 = 0
0 and 1 = 0
0 and 0 = 0
Peter Smith 38
Boolean Algebra (Cont.)
In another words, the only way you can get a result of a 1 is to
combine 1 & 1. Everything else will end up as a 0.
The process of combining binary values with Boolean Algebra is
called Anding.
Peter Smith 39
Default Standard Subnet Masks
There are default standard subnet masks for Class A, B
and C addresses:
Peter Smith 40
A Trial Separation
Subnet masks apply only to Class A, B or C IP addresses.
The subnet mask is like a filter that is applied to a messages
destination IP address.
Its objective is to determine if the local network is the destination
network.
Peter Smith 41
A Trial Separation (Cont.)
The subnet mask goes like this:
1. If a destination IP address is 206.175.162.21, we know that it is a
Class C address & that its binary equivalent is:
11001110.10101111.10100010.00010101
Peter Smith 42
A Trial Separation (Cont.)
2. We also know that the default standard Class C subnet mask is:
255.255.255.0 and that its binary equivalent is:
11111111.11111111.11111111.00000000
Peter Smith 43
A Trial Separation (Cont.)
3. When these two binary numbers (the
IP address & the subnet mask) are
combined using Boolean Algebra, the
Network ID of the destination network
is the result:
Peter Smith 44
A Trial Separation (Cont.)
4. The result is the IP address of the network which in this case is the
same as the local network & means that the message is for a node
on the local network.
Peter Smith 45
Routing IP Addresses
When you build a network, you need to figure out how many network
Ids your network requires.
To do so, you must account for every WAN connection & subnet on
the Network.
Every node & router interface requires a Host address, or ID.
Subnets
223.1.1.0/24
223.1.2.0/24
223.1.3.0/24
Recipe
To determine the
subnets, detach each
interface from its host or
router, creating islands
of isolated networks.
Each isolated network
is called a subnet.
Subnet mask: /24
Subnets
How many?
223.1.1.1
223.1.1.3
223.1.1.4
223.1.2.2 223.1.2.1
223.1.2.6
223.1.3.2 223.1.3.1
223.1.3.27
223.1.1.2
223.1.7.0
223.1.7.1
223.1.8.0 223.1.8.1
223.1.9.1
223.1.9.2
IP addressing: CIDR
CIDR: Classless InterDomain Routing
subnet portion of address of arbitrary length
address format: a.b.c.d/x, where x is # bits in subnet portion of address
11001000 00010111 00010000 00000000
subnet
part
host
part
200.23.16.0/23
IP addresses: how to get one?
Q: How does host get IP address?
hard-coded by system admin in a file
Wintel: control-panel->network->configuration->tcp/ip->properties
UNIX: /etc/rc.config
DHCP: Dynamic Host Configuration Protocol: dynamically get
address from as server
plug-and-play
(more in next chapter)
IP addresses: how to get one?
Q: How does network get subnet part of IP addr?
A: gets allocated portion of its provider ISPs address space
ISP's block 11001000 00010111 00010000 00000000 200.23.16.0/20
Organization 0 11001000 00010111 00010000 00000000 200.23.16.0/23
Organization 1 11001000 00010111 00010010 00000000 200.23.18.0/23
Organization 2 11001000 00010111 00010100 00000000 200.23.20.0/23
... .. . .
Organization 7 11001000 00010111 00011110 00000000 200.23.30.0/23
Hierarchical addressing: route aggregation
Send me anything
with addresses
beginning
200.23.16.0/20
200.23.16.0/23
200.23.18.0/23
200.23.30.0/23
Fly-By-Night-ISP
Organization 0
Organization 7
Internet
Organization 1
ISPs-R-Us
Send me anything
with addresses
beginning
199.31.0.0/16
200.23.20.0/23
Organization 2
.
.
.
.
.
.
Hierarchical addressing allows efficient advertisement of routing
information:
IP addressing: the last word...
Q: How does an ISP get block of addresses?
A: ICANN: Internet Corporation for Assigned
Names and Numbers
allocates addresses
manages DNS
assigns domain names, resolves disputes
NAT: Network Address Translation
10.0.0.1
10.0.0.2
10.0.0.3
10.0.0.4
138.76.29.7
local network
(e.g., home network)
10.0.0/24
rest of
Internet
Datagrams with source or
destination in this network
have 10.0.0/24 address for
source, destination (as usual)
All datagrams leaving local
network have same single source
NAT IP address: 138.76.29.7,
different source port numbers
NAT: Network Address Translation
Motivation: local network uses just one IP address as far as
outside world is concerned:
no need to be allocated range of addresses from ISP: - just one IP address
is used for all devices
can change addresses of devices in local network without notifying outside
world
can change ISP without changing addresses of devices in local network
devices inside local net not explicitly addressable, visible by outside world
(a security plus).
NAT: Network Address Translation
Implementation: NAT router must:
outgoing datagrams: replace (source IP address, port #) of every outgoing
datagram to (NAT IP address, new port #)
. . . remote clients/servers will respond using (NAT IP
address, new port #) as destination addr.
remember (in NAT translation table) every (source IP address, port #) to
(NAT IP address, new port #) translation pair
incoming datagrams: replace (NAT IP address, new port #) in dest fields of
every incoming datagram with corresponding (source IP address, port #)
stored in NAT table
NAT: Network Address Translation
10.0.0.1
10.0.0.2
10.0.0.3
S: 10.0.0.1, 3345
D: 128.119.40.186, 80
1
10.0.0.4
138.76.29.7
1: host 10.0.0.1
sends datagram to
128.119.40.186, 80
NAT translation table
WAN side addr LAN side addr
138.76.29.7, 5001 10.0.0.1, 3345
S: 128.119.40.186, 80
D: 10.0.0.1, 3345
4
S: 138.76.29.7, 5001
D: 128.119.40.186, 80
2
2: NAT router
changes datagram
source addr from
10.0.0.1, 3345 to
138.76.29.7, 5001,
updates table
S: 128.119.40.186, 80
D: 138.76.29.7, 5001
3
3: Reply arrives
dest. address:
138.76.29.7, 5001
4: NAT router
changes datagram
dest addr from
138.76.29.7, 5001 to 10.0.0.1, 3345
NAT: Network Address Translation
16-bit port-number field:
60,000 simultaneous connections with a single LAN-side address!
NAT is controversial:
routers should only process up to layer 3
violates end-to-end argument
NAT possibility must be taken into account by app designers, eg, P2P
applications
address shortage should instead be solved by IPv6