Unit3-Network Layer
Unit3-Network Layer
Unit3-Network Layer
Transport
Network
Link
Physical
Computer Networks
Network Layer
6. Receive data
3. Accept call applicatio
n
2. Incoming call transport
network
5. Data flow begins data link
4. Call connected physical
applicatio 1. Initiate call
n
transport
network
data link
physical
Comparison of Virtual-Circuit and Datagram
Internet ATM
Quality of Service: QoS
• Factors:
– Timing
• Connection Establishment Delay
• End-To-End Delay
– Connection Establishment Failure Probability
– Throughput or Bandwidth Guarantee
– Ordering Preservation
– Congestion Control
– Bit-Error rate or Packet-Loss Rate Control
– Protection
– Priority
– …
Routing (1)
• The network layer is responsible for routing packets from the source to
destination.
• The routing algorithm is the piece of software that decides where a
packet goes next (e.g., which output line, or which node on a broadcast
channel).
– Dynamic (Adaptive)
• routes update more quickly use dynamic information of current topology such as load, delay, …
• Examples: Distance Vector, Link State Routing
Single-Source Shortest Path Problem
Dijkstra Algorithm
Single-Source Shortest Path Problem - The problem of
finding shortest paths from a source vertex v to all other vertices
in the graph.
Applications
- Maps (Map Quest, Google Maps)
- Routing Systems
Dijkstra's algorithm
Dijkstra's algorithm - is a solution to the single-source
shortest path problem in graph theory.
2
Start with G
3
5 F C K dv pv
10
A 7 3 A
8 4
18 B
4
B D
9 C
10
H D
2 9 25
3 E
G E
7 F
G T 0
H
Dijkstra’s algorithm
2
Update unselected nodes
3
5 F C K dv pv
10
A 7 3 A
8 4
18 B
4
B D
9 C
10
H D 2 G
2 9 25
3 E
G E
7 F
G T 0
H 3 G
Dijkstra’s algorithm
2
Select minimum distance
3
5 F C K dv pv
10
A 7 3 A
8 4
18 B
4
B D
9 C
10
H D T 2 G
2 9 25
3 E
G E
7 F
G T 0
H 3 G
Dijkstra’s algorithm
2
Update unselected nodes
3
5 F C K dv pv
10
A 7 3 A
8 4
18 B
4
B D
9 C
10
H D T 2 G
2 9 25
3 E 27 D
G E
7 F 20 D
G T 0
H 3 G
Dijkstra’s algorithm
2
Select minimum distance
3
5 F C K dv pv
10
A 7 3 A
8 4
18 B
4
B D
9 C
10
H D T 2 G
2 9 25
3 E 27 D
G E
7 F 20 D
G T 0
H T 3 G
Dijkstra’s algorithm
2
Update unselected nodes
3
5 F C K dv pv
10
A 7 3 A 7 H
8 4
18 B 12 H
4
B D
9 C
10
H D T 2 G
2 9 25
3 E 27 D
G E
7 F 20 D
G T 0
H T 3 G
Dijkstra’s algorithm
2
Select minimum distance
3
5 F C K dv pv
10
A 7 3 A T 7 H
8 4
18 B 12 H
4
B D
9 C
10
H D T 2 G
2 9 25
3 E 27 D
G E
7 F 20 D
G T 0
H T 3 G
Dijkstra’s algorithm
2
Update unselected nodes
3
5 F C K dv pv
10
A 7 3 A T 7 H
8 4
18 B 12 H
4
B D
9 C
10
H D T 2 G
2 9 25
3 E 27 D
G E
7 F 17 A
G T 0
H T 3 G
Dijkstra’s algorithm
2
Select minimum distance
3
5 F C K dv pv
10
A 7 3 A T 7 H
8 4
18 B T 12 H
4
B D
9 C
10
H D T 2 G
2 9 25
3 E 27 D
G E
7 F 17 A
G T 0
H T 3 G
Dijkstra’s algorithm
2
Update unselected nodes
3
5 F C K dv pv
10
A 7 3 A T 7 H
8 4
18 B T 12 H
4
B D
9 C 16 B
10
H D T 2 G
2 9 25
3 E 22 B
G E
7 F 17 A
G T 0
H T 3 G
Dijkstra’s algorithm
2
Select minimum distance
3
5 F C K dv pv
10
A 7 3 A T 7 H
8 4
18 B T 12 H
4
B D
9 C T 16 B
10
H D T 2 G
2 9 25
3 E 22 B
G E
7 F 17 A
G T 0
H T 3 G
Dijkstra’s algorithm
2
Update unselected nodes
3
5 F C K dv pv
10
A 7 3 A T 7 H
8 4
18 B T 12 H
4
B D
9 C T 16 B
10
H D T 2 G
2 9 25
3 E 22 B
G E
7 F 17 A
G T 0
H T 3 G
Dijkstra’s algorithm
2
Select minimum distance
3
5 F C K dv pv
10
A 7 3 A T 7 H
8 4
18 B T 12 H
4
B D
9 C T 16 B
10
H D T 2 G
2 9 25
3 E 22 B
G E
7 F T 17 A
G T 0
H T 3 G
Dijkstra’s algorithm
2
Update unselected nodes
3
5 F C K dv pv
10
A 7 A T 7 H
8 4
18 B T 12 H
4
B D
9 C T 16 B
10
H D T 2 G
2 9 25
3 E 19 F
G E
7 F T 17 A
G T 0
H T 3 G
Dijkstra’s algorithm
2
Select minimum distance
3
5 F C K dv pv
10
A 7 A T 7 H
8 4
18 B T 12 H
4
B D
9 C T 16 B
10
H D T 2 G
2 9 25
3 E T 19 F
G E
7 F T 17 A
G T 0
H T 3 G
Done
Dijkstra’s-Example
4 1 3 10
2 2
∞ C D E ∞
5 8 ∞ 4 6
1
F G
∞ ∞
Distance to Node
Info at
1
B C
node A B C D E
7
A 0 7 1
A B C 7
8 2 0 1 8
D 1 0 2
1
E 2 D E 2 0 2
1 8 2 0
Distance Vector Routing
D sends vector to E
Iʼm 2 from C, 0
from D and 2 from
E
Distance to Node
Info at
1
B C
node A B C D E
7
A 0 7 1
A B
8 2 7 0 1 8
C 1 0 2
1
E 2 D D 2 0 2
E 1 8 4 2 0
D is 2 away, 2+2< ,
so best path to C is 4
Distance Vector Routing
B sends vector to A
Iʼm 7 from A, 0
from B, 1 from C &
8 from E
Distance to Node
Info at
1
B C
node A B C D E
7
A 0 7 8 1
A B
8 2 7 0 1 8
C 1 0 2
1
E 2 D D 2 0 2
E 1 8 4 2 0
B is 7 away, 1+7< so
best path to C is 8
Distance Vector Routing
E sends vector to A
E is 1 away, 4+1<8
so C is 5 away, 1+2<
so D is 3 away
Distance to Node
Info at
1
B C
node A B C D E
7
A 0 7 5 3 1
A B
8 2 7 0 1 8
C 1 0 2
1
E 2 D D 2 0 2
E 1 8 4 2 0
Iʼm 1 from A, 8 from B, 4
from C, 2 from D & 0 from E
Distance Vector Routing
…until Convergence
Distance To Node
Info at
1
B C
node A B C D E
7
A 0 6 5 3 1
A B
8 2 6 0 1 3 5
C 5 1 0 2 4
1
E 2 D D 3 3 2 0 2
E 1 5 4 2 0
Distance Vector Routing
Next hop
Dest A E
B 1 C
7
C
A 6
A 8 2 C 1
D 3
1
E 2 D E 5
Distance Vector Routing
Handling Link Failure
• A marks distance to E as , and tells B
• E marks distance to A as , and tells B and
D
• B and D recompute routes and tell C, E and E
• etc… until converge Info at Distance to Node
1 node
B C
A B C D E
7
A 8 2
A 0 7 8 10 12
B 7 0 1 3 5
1
E 2 D
C 8 1 0 2 4
D 10 3 2 0 2
E 12 5 4 2 0
Distance Vector Routing-Example
4 1 3 10
2 2
∞ C D E ∞
5 8 ∞ 4 6
1
F G
∞ ∞
• If parts of the directions incorrect, the routing may be incorrect until the routing algorithms has re-converged.
AA BB CC
DD EE FF
Distance Vector vs. Link State Routing
• In link state routing, each node has a complete map of the topology (Link state information must be flooded to all nodes).
A B C A B C A B C
D E F D E F D E F
AA BB CC
DD EE FF
A B C
A B C A B C
D E F
D E F D E F
Link State Routing
• Each router creates a link state packet (LSP) which contains names (e.g. network addresses) and cost to each of its neighbours
– The LSP is transmitted to all other routers, who each update their own records.
– When a routers receives LSPs from all routers, it can use (collectively) that information to make topology-level decisions
Link State Packets
• LSPs are generated and distributed when:
– A time period passes(proactive routing)
– New neighbours connect to the router
– The link cost of a neighbour has changed
– A link to a neighbour has failed (link failure)
– A neighbour has failed (node failure)
– Essentially, the algorithm runs at each router, computing each possible path to the destination, adding up each cost
Dijkstra’s
Received Link State Algorithm IP Routing
LSAs Database Table
6 2
A B C 5
2 1 2 G
2 4
D E F 1
C (0)
Dijkstra’s LSR Algorithm
a) Examine C’s LSP
– Add F, G, and B to TENT
C (0)
C (0)
(3) G (6)
E
Dijkstra’s LSR Algorithm
a) G exists in TENT twice, keep only the best
– The new G is a better path than the old (3 < 5)
C (0)
(3) G (6)
E
Dijkstra’s LSR Algorithm
a) Put B into path (shown as solid line)
– Add A and E to TENT
C (0)
(2) F B (2)
C (0)
(2) F B (2)
C (0)
(2) F B (2)
(5)
D
Dijkstra’s LSR Algorithm
a) Place G in PATH (shown as solid line)
– All G’s LSP elements already exist in TENT
C (0)
(2) F B (2)
(5)
D
Dijkstra’s LSR Algorithm
a) Place D in PATH (shown as solid line)
– Add path to A since it is better than old A
C (0)
(2) F B (2)
(5)
D
A (7)
Dijkstra’s LSR Algorithm
a) Place A in PATH (shown as solid line)
– All A’s LSP elements already exist in PATH
C (0)
(2) F B (2)
(3) G (3)
E
(5)
D
A (7)
Dijkstra’s LSR Algorithm
a) We are done since all routes from TENT
were placed into PATH
C (0)
(2) F B (2)
(3) G (3)
E
(5)
D
A (7)
Dijkstra’s LSR Algorithm
• We can now create a forwarding database:
Forwarding
Database
C (0)
Destinatio Port
(2) F n
B (2)
C C
(3) G (3) F F
E
G F
(5) B B
D
E B
D B
A (7)
A B
Wireless Networks
• Two types of wireless networks:
– infrastructured network:
• base stations are the bridges
• a mobile host will communicate with the nearest base station
• handoff is taken when a host roams from one base to another
– ad hoc network:
• infrastructureless: no fixed base stations
• without the assistance of base stations for communication
• Due to transmission range constraint,
– two MHs need multi-hop routing for communication
• quickly and unpredictably changing topology
MANET
• MANET = Mobile Ad Hoc Networks
– a set of mobile hosts, each with a transceiver
– no base stations; no fixed network infrastructure
– multi-hop communication
– needs a routing protocol which can handle changing topology
Applications of MANET
• battlefields
• fleet in oceans
• historical cites
• festival ground
On-demand vs. Table-driven
64 bits
RREQ
• Example: Node A
A
needs to communicate
RREQ
with F
RREQ B
• RREQ A->F is released
C
to network
D • Neighbors C and B
receive RREQ and
E F learn route to A
Path discovery (3/5)
• Intermediate nodes C
and B do not have route
to F
A • RREQ is broadcasted
forward with increased
B hop count only if hop
limit is not yet reached
C • A receives it’s own
D RREQ
– paths to B and C are formed
– RREQ is discarded
F • Intermediate node D
E receives multiple copies
of RREQ form A
– Direct routes to C and B are
formed
– The first arrived RREQ is
set used to form route to A
(e.g. B here)
Path discovery (4/5)
• D forwards RREQ
A • B and C discard
duplicate RREQ and
B learn route to D
C • Destination node F
D finally gets RREQ
F
E
RREP-Path discovery (5/5)
• Route reply packet (RREP) is
sent back to node A along
reverse route
A – In fact any node, which has a
RREP fresh route to destination can
B send RREP and therefore end
route search
C RREP • Active forward path from A to
F is created
D – Intermediate nodes also have
now active forward path to F
RREP • Route is ready for data
transmission
E F
64 bits
ctrl_info hop_cnt
RREP
A Dest Nex hop Num hops Exp time Seq num dest Active neighbors
A A 1 10 s
B D
F
D
D
1
2
3s
20 s
C Dest
C
Nex hop
C
Num hops Exp time Seq num dest
1 3s
Active neighbors
E E 1 3s
D A
B
B
B
2
1
10 s
10 s
F F 1 20 s
Dest Nex hop Num hops Exp time Seq num dest Active neighbors
E F D
A
D
D
1
3
10 s
10 s
B
RREQ:S
S A
C D
B
RREQ:S
S A
C D
B
RREQ:S, A
S A
RRE C D
Q :S, A
1. Node S needs a route to D
2. Broadcasts RREQ packet
3. Node A receives packet, has no route to D
Rebroadcasts packet after adding its address to
source route
DSR – Route Discovery
B
RREQ: S, A
S A RREQ: S, A
C D
RREQ: S, A, C
S A
C D
RREQ: S, A, C
S A
C D
Z
S E
F
B
C M L
J
A G
H D
K
I N
[S] Z
S E
F
B
C M L
J
A G
H D
K
I N
Represents transmission of
RREQ
[X,Y] Represents list of identifiers appended to
RREQ
Route Discovery in DSR
Y
Z
S [S,E]
E
F
B
C M L
J
A [S,C] G
H D
K
I N
Z
S E
F [S,E,F]
B
C M L
J
A G
H D
[S,C,G] K
I N
Z
S E
F [S,E,F,J]
B
C M L
J
A G
H D
K
I [S,C,G,K] N
Z
S E
[S,E,F,J,M]
F
B
C M L
J
A G
H D
K
I N
Z
S RREP [D,J,F, E,S]
E
F
B
C M L
J
A G
H D
K
I N
DATA [S,E,F,J,D] Z
S E
F
B
C M L
J
A G
H D
K
I N