Chapter 4: Network Layer
4. 1 Introduction 4.4 Routing algorithms
4.2 Virtual circuit and Link state
datagram networks Distance Vector
Hierarchical routing
4.3 IP: Internet
Protocol
Datagram format
IPv4 addressing
NAT
ICMP
IPv6
Network Layer 4-1
4.1 Network layer
on sending side encapsulates
segments into datagrams application
transport
network
data link network
on rcving side, delivers physical
network data link network
physical
segments to transport layer
data link data link
physical physical
network
data link
network
network layer protocols in
physical
data link
physical
every host, router
network
network data link
data link physical
physical
Router examines header fields network
in all IP datagrams passing data link
physical
application
transport
through it network
data link
physical
Network Layer 4-2
Key Network-Layer Functions
forwarding: move analogy:
packets from router’s
input to appropriate routing: process of
router output planning trip from
source to dest
routing: determine
route taken by forwarding: process
packets from source of correct left turns,
to dest. right turns, exits,
etc.
Routing algorithms
Network Layer 4-3
Interaction between routing and forwarding
routing algorithm
local forwarding table
header value output link
0100 3
0101 2
0111 2
1001 1
value in arriving
packet’s header
0111 1
3 2
Network Layer 4-4
Connection setup
important function in some network
architectures:
ATM
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 Layer 4-5
Network service model
Q: What service model for “channel” transporting
datagrams from sender to rcvr?
Example services for Example services for a
individual datagrams: flow of datagrams:
guaranteed delivery In-order datagram
Guaranteed delivery delivery
with less than 40 msec Guaranteed minimum
delay bandwidth to flow
Network Layer 4-6
4.2 Virtual circuit and datagram networks
Network layer connection and connection-less service
Datagram network provides network-layer
connectionless service
VC network provides network-layer
connection service
Analogous to the transport-layer services,
but:
Service: host-to-host
No choice: network provides one or the other
Implementation: in the core
Network Layer 4-7
Virtual circuits
“source-to-dest path behaves much like telephone
circuit”
performance-wise
network actions along source-to-dest path
call setup, teardown for each call before data can flow
each packet carries VC identifier (not destination host
address)
every router on source-dest path maintains “state” for
each passing connection
link, router resources (bandwidth, buffers) may be
allocated to VC
Network Layer 4-8
VC implementation
A VC consists of:
1. Path from source to destination
2. VC numbers, one number for each link along path
3. Entries in forwarding tables in routers along path
Example next slide
Packet belonging to VC carries a VC number.
VC number must be changed on each link.
New VC number comes from forwarding table
Network Layer 4-9
Forwarding table VC number
12 22 32
1 3
2
Forwarding table in interface
number
northwest router:
Incoming interface Incoming VC # Outgoing interface Outgoing VC #
1 12 3 22
2 63 1 18
3 7 2 17
1 97 3 87
… … … …
Routers maintain connection state information!
Network Layer 4-10
Virtual circuits: signaling protocols
used to setup, maintain teardown VC
used in ATM
not used in today’s Internet
application
6. Receive data application
transport 5. Data flow begins
network 4. Call connected 3. Accept call transport
data link 1. Initiate call 2. incoming call network
data link
physical
physical
Network Layer 4-11
Datagram networks
no call setup at network layer
routers: no state about end-to-end connections
no network-level concept of “connection”
packets forwarded using destination host address
packets between same source-dest pair may take
different paths
application
application
transport
transport
network
data link 1. Send data 2. Receive data network
data link
physical
physical
Network Layer 4-12
4 billion
Forwarding table possible entries
Destination Address Range Link Interface
11001000 00010111 00010000 00000000
through 0
11001000 00010111 00010111 11111111
11001000 00010111 00011000 00000000
through 1
11001000 00010111 00011000 11111111
11001000 00010111 00011001 00000000
through 2
11001000 00010111 00011111 11111111
otherwise 3
Network Layer 4-13
Longest prefix matching
Prefix Match Link Interface
11001000 00010111 00010 0
11001000 00010111 00011000 1
11001000 00010111 00011 2
otherwise 3
Examples
DA: 11001000 00010111 00010110 10100001 Which interface?
DA: 11001000 00010111 00011000 10101010 Which interface?
Network Layer 4-14
Datagram or VC network: why?
Internet ATM
data exchange among evolved from telephony
computers
human conversation:
“elastic” service, no strict
strict timing, reliability
timing req.
requirements
“smart” end systems
need for guaranteed
(computers)
service
can adapt, perform
control, error recovery
simple inside network,
complexity at “edge”
many link types
different characteristics
uniform service difficult
Network Layer 4-15
Chapter – 4
Network Layer
Lecture -2
IPV4 Addressing
Network Layer 4-16
The Internet Network layer
Host, router network layer functions:
Transport layer: TCP, UDP
Routing protocols IP protocol
•path selection •addressing conventions
•RIP, OSPF, BGP •datagram format
Network
layer forwarding
ICMP protocol
table
•error reporting
•router “signaling”
Link layer
physical layer
Network Layer 4-17
4.3 IP Fragmentation & Reassembly
network links have MTU
(max.transfer size) - largest
possible link-level frame.
different link types, fragmentation:
different MTUs in: one large datagram
large IP datagram divided out: 3 smaller datagrams
(“fragmented”) within net
one datagram becomes
several datagrams
reassembly
“reassembled” only at final
destination
IP header bits used to
identify, order related
fragments
Network Layer 4-18
IP Fragmentation and Reassembly
length ID fragflag offset
Example =4000 =x =0 =0
4000 byte
One large datagram becomes
datagram several smaller datagrams
MTU = 1500 bytes
length ID fragflag offset
=1500 =x =1 =0
1480 bytes in
data field length ID fragflag offset
=1500 =x =1 =185
offset =
1480/8 length ID fragflag offset
=1040 =x =0 =370
Network Layer 4-19
4.4 IP Addressing: introduction
IP address: 32-bit 223.1.1.1
identifier for host, 223.1.2.1
223.1.1.2
router interface 223.1.1.4 223.1.2.9
interface: connection
223.1.2.2
between host/router 223.1.1.3 223.1.3.27
and physical link
router’s typically have
multiple interfaces 223.1.3.1 223.1.3.2
host typically has one
interface
IP addresses
associated with each 223.1.1.1 = 11011111 00000001 00000001 00000001
interface
223 1 1 1
Network Layer 4-20
IP Addressing: introduction
The address in the network layer of the TCP/IP model is called
Internet Address or IP address and has 32-bit length or Consists
of 4 octets (bytes)
The IP addresses are unique and universal (must be accepted
by any host wants to connect to the internet).
Network + Host: Complete IP address
Network ID: identifies the network to which the host is connected
Host ID: identifies the interface of the network connection to the host.
Address Classification five classes: A, B, C, D, and E.
Table 1 Number of blocks and block size in classful IPv4 addressing
Table 2 Default masks for classful addressing
Classless Interdomain Routing (CIDR)
Address Classification method
Example – 1 :- Find the class of each address:
a. 00000001 00001011 00001011 11101111
b. 11110011 10011011 11111011 00001111
c. 227.12.14.87
d. 252.5.15.111
e. 134.11.78.56
Blocks in class A
Millions of class A addresses are wasted.
Number of complete IP addresses in each block is 2net bit – (all zeros host -
network address, and all ones – broadcast address)
Blocks in class B
Many class B addresses are wasted.
Blocks in class C
The number of addresses in class C block is smaller than the needs of
most organizations.
Network address
In classful addressing, the network address is the one that is assigned
to the organization.
Example - 2
Given the address 23.56.7.91 and 132.6.17.85, find the network
address.
Solution : -1
The class is A. Only the first byte defines the netid. We can find the
network address by replacing the hostid bytes (56.7.91) with 0s. Therefore,
the network address is 23.0.0.0.
Solution : -2
The class is B. The first 2 bytes defines the netid. We can find the network
address by replacing the hostid bytes (17.85) with 0s. Therefore, the
network address is 132.6.0.0.
Default masks
In Dotted-
Class In Binary Using Slash
Decimal
A 11111111 00000000 00000000 00000000 255.0.0.0 /8
B 11111111 11111111 00000000 00000000 255.255.0.0 /16
C 11111111 111111111 11111111 00000000 255.255.255.0 /24
• The network address can be found by applying the
default mask to any address in the block (including
itself).
• It retains the netid of the block and sets the hostid to 0s.
Example – 3a
• Figure below shows a block of addresses, in both binary and
dotted-decimal notation, granted to a small business that needs 16
addresses.
• The addresses are contiguous. The number of addresses is a power
of 2 (16 = 24), and the first address is divisible by 16.
Figure. A block of 16 addresses granted to a small organization
Note
In IPv4 addressing, a block of
addresses can be defined as
x.y.z.t /n
in which x.y.z.t defines one of the
addresses and the /n defines the mask.
The first address in the block can be
found by setting the rightmost
32 − n bits to 0s.
Example -3b
A block of addresses is granted to a small organization.
We know that one of the addresses is 205.16.37.39/28.
What is the first address in the block?
Solution
The binary representation of the given address is
11001101 00010000 00100101 00100111
If we set 32−28 rightmost bits to 0, we get
11001101 00010000 00100101 0010000
or
205.16.37.32.
This is actually the block shown in Figure .
Note
The last address in the block can be
found by setting the rightmost
32 − n bits to 1s.
Example -3c
Find the last address for the block in previous Example.
Solution
The binary representation of the given address is
11001101 00010000 00100101 00100111
If we set 32 − 28 rightmost bits to 1, we get
11001101 00010000 00100101 00101111 or
205.16.37.47
This is actually the block shown in Figure.
Note
The number of addresses in the block
can be found by using the formula
232−n.
Find the number of addresses in Example .
Solution
The value of n is 28, which means that number
of addresses is 2 32−28 or 16.
Example -3d
Another way to find the first address, the last address, and
the number of addresses is to represent the mask as a 32-
bit binary (or 8-digit hexadecimal) number. In previous
Example the /28 can be represented as
11111111 11111111 11111111 11110000
(twenty-eight 1s and four 0s).
Find
a. The first address
b. The last address
c. The number of addresses.
Example -3d(continued)
Solution
a. The first address can be found by ANDing the given
addresses with the mask. ANDing here is done bit by
bit. The result of ANDing 2 bits is 1 if both bits are 1s;
the result is 0 otherwise.
Example -3d (continued)
b. The last address can be found by ORing the given
addresses with the complement of the mask. ORing
here is done bit by bit. The result of ORing 2 bits is 0 if
both bits are 0s; the result is 1 otherwise. The
complement of a number is found by changing each 1
to 0 and each 0 to 1.
Example-3d (continued)
c. The number of addresses can be found by
complementing the mask, interpreting it as a decimal
number, and adding 1 to it.
Figure A network configuration for the block 205.16.37.32/28
Subnetting
Subnetting
Dividing the network into several smaller groups (subnets) with
each group having its own subnet IP address
Host portion of address partitioned into subnet number (most
significant part) and host number (least significant part)
In this case, IP address will have 3 levels (Main network, subnet,
host)
Subnet mask when ANDed with the IP address it gives the
subnetwork address
Basic Idea of Subnetting
Split the host number portion of an IP address into a
subnet number and a (smaller) host number.
Result is a 3-layer hierarchy
network prefix host number
network prefix subnet number host number
extended network prefix
Then:
Subnets can be freely assigned within the organization
Internally, subnets are treated as separate networks
Subnet structure is not visible outside the organization
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
Network Layer 4-45
NAT: Network Address Translation
rest of local network
Internet (e.g., home network)
10.0.0/24 10.0.0.1
10.0.0.4
10.0.0.2
138.76.29.7
10.0.0.3
All datagrams leaving local Datagrams with source or
network have same single source destination in this network
NAT IP address: 138.76.29.7, have 10.0.0/24 address for
different source port numbers source, destination (as usual)
Network Layer 4-46
NAT: Network Address Translation
Motivation: local network uses just one IP address as
far as outside world is concerned:
range of addresses not needed from ISP: just one IP
address 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).
Network Layer 4-47
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
Network Layer 4-48
NAT: Network Address Translation
NAT translation table
2: NAT router 1: host 10.0.0.1
WAN side addr LAN side addr
changes datagram sends datagram to
138.76.29.7, 5001 10.0.0.1, 3345 128.119.40.186, 80
source addr from
…… ……
10.0.0.1, 3345 to
138.76.29.7, 5001, S: 10.0.0.1, 3345
updates table D: 128.119.40.186, 80
10.0.0.1
1
S: 138.76.29.7, 5001
2 D: 128.119.40.186, 80 10.0.0.4
10.0.0.2
138.76.29.7 S: 128.119.40.186, 80
D: 10.0.0.1, 3345 4
S: 128.119.40.186, 80
D: 138.76.29.7, 5001 3 10.0.0.3
4: NAT router
3: Reply arrives changes datagram
dest. address: dest addr from
138.76.29.7, 5001 138.76.29.7, 5001 to 10.0.0.1, 3345
Network Layer 4-49
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
Network Layer 4-50