Computer Networks
Unit-4
Network Layer
Introduction: Network Layer
application
transport
network
data link
physical
application
transport
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
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
Unit: 4 – Network Layer | Darshan Institute of Engineering & Technology |
2
Key Function of Network Layer
Unit: 4 Network Layer | | |
3
Routing and Forwarding
1
2
3
0111
value in arriving
packet’s header
routing algorithm
local forwarding table
header value
output link
0100
0101
0111
1001
3
2
2
1
routing algorithm determines
end-end-path through network
forwarding table determines
local forwarding at this router
Unit: 4 Network Layer | | |
4
Network Service Model
Unit: 4 Network Layer | | |
5
Network Service Model – Cont…
Unit: 4 Network Layer | | |
6
Network Service Model – Cont…
Unit: 4 Network Layer | | |
7
Virtual Circuit Switching
Unit: 4 Network Layer | | |
8
VC Forwarding Table
12
22
32
1
2
3
VC number
interface
number
Incoming interface Incoming VC # Outgoing interface Outgoing VC #
1 12 3 22
2 63 1 18
3 7 2 17
1 97 3 87
… … … …
forwarding table in
router:
VC routers maintain connection state information
Unit: 4 Network Layer | | |
9
Virtual Circuit Setup
There are three identifiable phases in a virtual circuit:
application
transport
network
data link
physical
1. initiate call
2. incoming call
3. accept call
4. call connected
5. data flow begins
6. receive data
application
transport
network
data link
physical
Unit: 4 Network Layer | | |
10
Datagram Network
1. send datagrams
application
transport
network
data link
physical
application
transport
network
data link
physical
2. receive datagrams
Unit: 4 Network Layer | | |
11
Datagram Network vs. Virtual Circuit Network
| Datagram | Virtual Circuit |
Connection Setup | None | Required |
Addressing | Packet contains full source and destination address | Each virtual circuit number entered to table on setup, used for routing. |
State Information | None other than router table containing destination network | Route established at setup, all packets follow same route. |
Effect of Router Failure | Only on packets lost during crash | All virtual circuits passing through failed router terminated. |
Congestion Control | Difficult since all packets routed independently router resource requirements can vary. | Simple by pre-allocating enough buffers to each virtual circuit at setup, since maximum number of circuits fixed. |
Unit: 4 Network Layer | | |
12
Router Architecture
Unit: 4 Network Layer | | |
13
Input Port Functions
line
termination
link
layer
protocol
(receive)
lookup,
forwarding
queueing
switch
fabric
Unit: 4 Network Layer | | |
14
Input Port Functions – Cont…
Unit: 4 Network Layer | | |
15
Switching Fabrics
memory
memory
bus
crossbar
Unit: 4 Network Layer | | |
16
Switching via Memory
input
port
(e.g.,
Ethernet)
memory
output
port
(e.g.,
Ethernet)
system bus
Unit: 4 Network Layer | | |
17
Switching via Memory – Cont…
Unit: 4 Network Layer | | |
18
Switching via bus
bus
Unit: 4 – Network Layer | Darshan Institute of Engineering & Technology |
19
Switching via an interconnection network
Unit: 4 – Network Layer | Darshan Institute of Engineering & Technology |
20
Output Port
line
termination
link
layer
protocol
(send)
switch
fabric
datagram
buffer
queueing
Unit: 4 Network Layer | | |
21
Routing Processor
Unit: 4 Network Layer | | |
22
Internet Network Layer
forwarding
table
routing protocols
IP protocol
ICMP protocol
transport layer: TCP, UDP
link layer
physical layer
network
layer
Unit: 4 Network Layer | | |
23
IPv4 Datagram format
ver
length
32 bits
data
(variable length,
typically a TCP
or UDP segment)
16-bit identifier
header
checksum
time to
live
32 bit source IP address
head.
len
type of
service
flgs
fragment
offset
upper
layer
32 bit destination IP address
options (if any)
IP protocol version
number
header length
(bytes)
upper layer protocol
to deliver payload to
total datagram
length (bytes)
“type” of data
for
fragmentation/
reassembly
max number
remaining hops
(decremented at
each router)
e.g. timestamp,
record route
taken, specify
list of routers
to visit.
how much overhead?
Unit: 4 Network Layer | | |
24
IP Address
10101100
00010000
11111110
00000001
172
16
254
1
IP addresses are divided into 2 parts:
Network ID & Host ID
<NID> <HID> = IP Address
Unit: 4 Network Layer | | |
25
Classification of IP Addresses (Classful Addressing)
0 | | | | |
Class: A
Fix
7 Bit Network ID
24 Bit Host ID
1 | 0 | | | | |
Class: B
Fix
14 Bit Network ID
16 Bit Host ID
1 | 1 | 0 | | | | |
Class: C
Fix
21 Bit Network ID
8 Bit Host ID
1 | 1 | 1 | 0 | | | | |
Class: D
Fix
Multicast address
1 | 1 | 1 | 1 | | | | |
Class: E
Fix
Reserved address
Unit: 4 Network Layer | | |
26
Class A: (0.0.0.0 to 127.255.255.255)
0 | | | | |
7 Bit Network ID
24 Bit Host ID
0.0.0.0 | Special IP Address |
00000001.0.0.1 1.0.0.2 1.0.0.3 . . . 126.255.255.254 | 224 – 2 are Host IP |
127.255.255.255 | Special IP Address – Loopback |
Unit: 4 Network Layer | | |
27
Class B: (128.0.0.0 to 191.255.255.255)
1 | 0 | | | | |
Fix
14 Bit Network ID
16 Bit Host ID
128.0.0.0 | Special IP Address |
10000001.0.0.1 130.0.0.2 130.0.0.3 . . . 190.255.255.254 | 216 – 2 are Host IP |
10111111.255.255.255 | Special IP Address – Loopback |
Unit: 4 Network Layer | | |
28
Class C: (192.0.0.0 to 223.255.255.255)
1 | 1 | 0 | | | | |
Fix
21 Bit Network ID
8 Bit Host ID
192.0.0.0 | Special IP Address |
11000001.0.0.1 194.0.0.2 194.0.0.3 . . . 222.255.255.254 | 28 – 2 are Host IP |
11011111.255.255.255 | Special IP Address – Loopback |
Unit: 4 Network Layer | | |
29
Class D: (224.0.0.0 to 239.255.255.255)
Unit: 4 Network Layer | | |
30
Class E: (240.0.0.0 to 255.255.255.255)
Unit: 4 Network Layer | | |
31
IP Addressing Summary
Class | Leading�bits | Size of network�number bit field | Size of rest�bit field | Number�of networks | Addresses�per network | Total addresses�in class | Start address | End address | Default subnet mask in dot-decimal notation | CIDR notation |
Class A | 0 | 8 | 24 | 128 (27) | 16,777,216 (224) | 2,147,483,648 (231) | 0.0.0.0 | 127.255.255.255 | 255.0.0.0 | /8 |
Class B | 10 | 16 | 16 | 16,384 (214) | 65,536 (216) | 1,073,741,824 (230) | 128.0.0.0 | 191.255.255.255 | 255.255.0.0 | /16 |
Class C | 110 | 24 | 8 | 2,097,152 (221) | 256 (28) | 536,870,912 (229) | 192.0.0.0 | 223.255.255.255 | 255.255.255.0 | /24 |
Class D (multicast) | 1110 | not defined | not defined | not defined | not defined | 268,435,456 (228) | 224.0.0.0 | 239.255.255.255 | not defined | not defined |
Class E (reserved) | 1111 | not defined | not defined | not defined | not defined | 268,435,456 (228) | 240.0.0.0 | 255.255.255.255 | not defined | not defined |
Unit: 4 Network Layer | | |
32
IP Addressing - Example
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
Unit: 4 – Network Layer | Darshan Institute of Engineering & Technology |
33
Subnet
Network consisting of 3 subnets
223.1.1.0/24
223.1.2.0/24
223.1.3.0/24
223.1.1.1
223.1.1.3
223.1.1.4
223.1.2.9
223.1.3.2
223.1.3.1
subnet
223.1.1.2
223.1.3.27
223.1.2.2
223.1.2.1
Unit: 4 – Network Layer | Darshan Institute of Engineering & Technology |
34
Type of addresses in IPv4 Network
Unit: 4 Network Layer | | |
35
Type of addresses – Cont…
Unit: 4 Network Layer | | |
36
Classless Inter-Domain Routing(CIDR)
11001000 00010111 00010000 00000000
subnet
part
host
part
200.23.16.0/23
Unit: 4 Network Layer | | |
37
Subnetting
11111111 11111111 11110000 00000000
255 255 240 0
Unit: 4 Network Layer | | |
38
How many subnets from given subnet mask?
Unit: 4 Network Layer | | |
39
What are the valid subnets?
Unit: 4 Network Layer | | |
40
What are the total hosts?
Unit: 4 Network Layer | | |
41
Network Prefixes
CIDR | Decimal | Binary |
/25 | 128 | 10000000 |
/26 | 192 | 11000000 |
/27 | 224 | 11100000 |
/28 | 240 | 11110000 |
/29 | 248 | 11111000 |
/30 | 252 | 11111100 |
Unit: 4 Network Layer | | |
42
Network Prefixes- Example
Unit: 4 Network Layer | | |
43
Dynamic Host Configuration Protocol - DHCP
223.1.1.0/24
223.1.2.0/24
223.1.3.0/24
223.1.1.1
223.1.1.3
223.1.1.4
223.1.2.9
223.1.3.2
223.1.3.1
223.1.1.2
223.1.3.27
223.1.2.2
223.1.2.1
DHCP
server
arriving DHCP
client needs
address in this
network
Unit: 4 Network Layer | | |
44
DHCP – Cont…
Unit: 4 Network Layer | | |
45
DHCP Client Server Interaction
DHCP server: 223.1.2.5
arriving
client
DHCP discover
src : 0.0.0.0, 68
dest.: 255.255.255.255,67
yiaddr: 0.0.0.0
transaction ID: 654
DHCP offer
src: 223.1.2.5, 67
dest: 255.255.255.255, 68
yiaddrr: 223.1.2.4
transaction ID: 654
lifetime: 3600 secs
DHCP request
src: 0.0.0.0, 68
dest:: 255.255.255.255, 67
yiaddrr: 223.1.2.4
transaction ID: 655
lifetime: 3600 secs
DHCP ACK
src: 223.1.2.5, 67
dest: 255.255.255.255, 68
yiaddrr: 223.1.2.4
transaction ID: 655
lifetime: 3600 secs
Broadcast: is there a DHCP server out there?
Broadcast: I’m a DHCP server! Here’s an IP address you can use
Broadcast: OK. I’ll take that IP address!
Broadcast: OK. You’ve got that IP address!
Unit: 4 Network Layer | | |
46
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
Unit: 4 Network Layer | | |
47
NAT – Cont…
Unit: 4 Network Layer | | |
48
NAT Terminology
Unit: 4 Network Layer | | |
49
NAT – Cont…
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
Unit: 4 Network Layer | | |
50
Internet Control Message Protocol - ICMP
Message Type | Description |
Destination unreachable | Packet could not be delivered |
Time exceeded | Time to live field hit 0 |
Parameter problem | Invalid header field |
Source quench | Choke packet |
Redirect | Teach a router about geography |
Echo | Ask a machine if it is alive |
Echo reply | Yes, I am alive |
Timestamp request | Same as Echo request, but with timestamp |
Timestamp reply | Same as Echo reply, but with timestamp |
Unit: 4 Network Layer | | |
51
IPv6 Datagram Format
Unit: 4 Network Layer | | |
52
Difference between IPv4 & IPv6
IPv4 | IPv6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Unit: 4 Network Layer | | |
53
Link State Routing Algorithm
Unit: 4 Network Layer | | |
54
Dijkstra’s Algorithm
1 Initialization:
2 N' = {u}
3 for all nodes v
4 if v adjacent to u
5 then D(v) = c(u,v)
6 else D(v) = ∞
7
8 Loop
9 find w not in N' such that D(w) is a minimum
10 add w to N'
11 update D(v) for all v adjacent to w and not in N' :
12 D(v) = min( D(v), D(w) + c(w,v) )
13 /* new cost to v is either old cost to v or known
14 shortest path cost to w plus cost from w to v */
15 until all nodes in N'
Unit: 4 Network Layer | | |
55
Dijkstra’s Algorithm – Example:1
w
3
4
v
x
u
5
3
7
4
y
8
z
2
7
9
Step
N'
D(v)
p(v)
0
1
2
3
4
5
D(w)
p(w)
D(x)
p(x)
D(y)
p(y)
D(z)
p(z)
u
∞
∞
7,u
3,u
5,u
uw
∞
11,w
6,w
5,u
14,x
11,w
6,w
uwx
uwxv
14,x
10,v
uwxvy
12,y
uwxvyz
Unit: 4 Network Layer | | |
56
Dijkstra’s Algorithm – Example:2
Step
0
1
2
3
4
5
N'
u
ux
uxy
uxyv
uxyvw
uxyvwz
D(v),p(v)
2,u
2,u
2,u
D(w),p(w)
5,u
4,x
3,y
3,y
D(x),p(x)
1,u
D(y),p(y)
∞
2,x
D(z),p(z)
∞
∞
4,y
4,y
4,y
u
y
x
w
v
z
2
2
1
3
1
1
2
5
3
5
Unit: 4 Network Layer | | |
57
Dijkstra’s Algorithm – Example:2
u
y
x
w
v
z
resulting shortest-path tree from u:
v
x
y
w
z
(u,v)
(u,x)
(u,x)
(u,x)
(u,x)
destination
link
resulting forwarding table in u:
Unit: 4 Network Layer | | |
58
Distance Vector Algorithm
Unit: 4 Network Layer | | |
59
Distance Vector Algorithm – Cont…
4-60
dx(y) = cost of least-cost path from x to y then
dx(y) = min {c(x,v) + dv(y) }
v
cost to neighbor v
min taken over all neighbors v of x
cost from neighbor v to destination y
Unit: 4 Network Layer | | |
60
Distance Vector Algorithm – Cont…
wait for (change in local link cost or message from neighbor)
recompute estimates
if DV to any destination has changed, notify neighbors
each node:
Unit: 4 Network Layer | | |
61
Distance Vector Algorithm - Example
x y z
x
y
z
0 2 7
∞
∞
∞
∞
∞
∞
from
cost to
from
from
x y z
x
y
z
0
x y z
x
y
z
∞
∞
∞
∞
∞
cost to
x y z
x
y
z
∞
∞
∞
7
1
0
cost to
∞
2 0 1
∞ ∞ ∞
2 0 1
7 1 0
time
x
z
1
2
7
y
node x
table
Dx(y) = min{c(x,y) + Dy(y), c(x,z) + Dz(y)} � = min{2+0 , 7+1} = 2
Dx(z) = min{c(x,y) + � Dy(z), c(x,z) + Dz(z)}
= min{2+1 , 7+0} = 3
3
2
node y
table
node z
table
cost to
from
Unit: 4 Network Layer | | |
62
Distance Vector Algorithm - Example
x y z
x
y
z
0 2 3
from
cost to
x y z
x
y
z
0 2 7
from
cost to
x y z
x
y
z
0 2 3
from
cost to
x y z
x
y
z
0 2 3
from
cost to
x y z
x
y
z
0 2 7
from
cost to
2 0 1
7 1 0
2 0 1
3 1 0
2 0 1
3 1 0
2 0 1
3 1 0
2 0 1
3 1 0
time
x y z
x
y
z
0 2 7
∞
∞
∞
∞
∞
∞
from
cost to
from
from
x y z
x
y
z
0
x y z
x
y
z
∞
∞
∞
∞
∞
cost to
x y z
x
y
z
∞
∞
∞
7
1
0
cost to
∞
2 0 1
∞ ∞ ∞
2 0 1
7 1 0
time
x
z
1
2
7
y
node x
table
3
2
node y
table
node z
table
cost to
from
Unit: 4 Network Layer | | |
63
Difference: LS and DV Routing Algorithm
Distance Vector Protocol | Link State Protocol |
Entire routing table is sent as an update | Updates are incremental & entire routing table is not sent as update |
Distance vector protocol send periodic update at every 30 or 90 second | Updates are triggered not periodic |
Update are broadcasted | Updates are multicasted |
Updates are sent to directly connected neighbour only | Update are sent to entire network & to just directly connected neighbour |
Routers don't have end to end visibility of entire network. | Routers have visibility of entire network of that area only. |
It is prone to routing loops | No routing loops |
Unit: 4 Network Layer | | |
64
Hierarchical Routing
Unit: 4 Network Layer | | |
65
Hierarchical Routing - Example
Unit: 4 Network Layer | | |
66
Broadcast Routing
Unit: 4 Network Layer | | |
67
Broadcast Routing – Cont…
Unit: 4 Network Layer | | |
68
Broadcast Routing – Cont…
Unit: 4 Network Layer | | |
69
Multicast Routing
Unit: 4 Network Layer | | |
70
Multicast Routing – Cont…
Unit: 4 Network Layer | | |
71
Comparison between RIP OSPF and BGP
RIP | OSPF | BGP |
RIP is intra domain routing protocol used with in the autonomous system | OSPF is also intra domain routing protocol used with in the autonomous system | It is inter domain routing protocol used between the autonomous system |
RIP is used for Small networks with maximum number of hops 16 | OSPF is used in large autonomous system with no limitation | The BGP protocol is used for very large-scale networks |
RIP uses Distance Vector | OSPF uses Link State | BGP uses Path Vector |
RIP send entire routing update to all directly connected interface | OSPF send multicast Hello packet to the neighbours, to create session | BGP send Open packet to the neighbours to create session |
RIP use Bellman ford Algorithm | OSPF use Dijikstra Algorithm | BGP use Path-Vector Routing |
Unit: 4 Network Layer | | |
72
Thank You