Module-5_Part-2
Module-5_Part-2
Network Layer
Network Layer
The network layer supervises the handling of the
packets by the underlying physical networks. We define
this handling as the delivery of a packet.
Internet – Connectionless Packet
Switching Inter-Network
• Packets in IPv4 called Datagrams
• Communication at network layer
connectionless
– Resource allocation on demand
– No reserved bandwidth on links, no scheduled
processing time for each packet. Ex : Restaurant
• N/W Layer protocol treats each packet
independently
• No relationship between packets
• May/May not travel same path to destination
• Datagrams could arrive out of order
N/W Layer : Direct vs Indirect Delivery
• N/W Layer
– supervises handling of packets by underlying physical
networks
– Data Delivery to final destination
– Direct
• Same physical network (SA & DA) (or)
• Delivery between Last router and destination host
• Sender extracts Network Address of Destination Address using
mask and compares with directly connected network address
– Indirect
• Not on same network as deliverer
• Packet goes from Router to Router until reaches destination
network
Figure 22.1 Direct and indirect delivery
22.5
FORWARDING
Forwarding means to place the packet in its route to its
destination. Forwarding requires a host or a router to
have a routing table. When a host has a packet to send
or when a router has received a packet to be forwarded,
it looks at this table to find the route to the final
destination.
• Forwarding requires
– Host or Router to have routing table
– Look for a route to destination
– Table lookup vs number of entries
• Techniques
– Next Hop Method vs Route Method
• Only Next Hop Address vs Complete Route
– Network-specific vs Host Specific
• Reduce Routing table
• One single entity for same physical network
– Default Method
• Simplify routing
Figure 22.2 Route method versus next-hop method
22.8
Figure 22.3 Host-specific versus network-specific method
22.9
Figure 22.4 Default method
22.10
Figure 22.5 Simplified forwarding module in classless address
22.11
Fundamentals of Routes, Next Hop Addresses and Packet
Forwarding
Figure 22.6 Configuration for Example 22.1
22.13
Table 22.1 Routing table for router R1 in Figure 22.6
22.14
Example 22.2
22.16
Figure 18.34: Address aggregation
18.17
Figure 22.8 Longest mask matching
22.18
Routing Table
• Routing Table
– Static
• Administrator – manual entries
– Dynamic
• Updated automatically when change somewhere in
internet.
• Table updated as soon as there is change
• Ex : Router is down/ better route/ link failure
Why Does Routing Matter?
• Routing provides connectivity!
– Without routing, the network doesn’t function
• Routing finds “good” paths
– Propagation delay, throughput, packet loss
• Routing allows network to tolerate failures
– Limits packet loss during disruptions
• Routing can also provide “Traffic Engineering”
– Balance traffic over the routers and links
– Avoid congestion by directing traffic to lightly-
20 loaded links
Routing Protocols
• Routing Protocols
– Due to demand for dynamic routing tables
– Combination of rules/procedures
– Routers inform each other of changes
– Share whatever they know about neighborhood
or internet
– Combine information received from other
routers
Unicast Routing Protocols : Optimization
• METRIC
• Depends on type of routing protocol
• RIP, OSPF, BGP etc…
Metrics
• Hop count
– The number of times that a packet passes through the output
port of one router
• Bandwidth
– The data capacity of a link; for instance, normally, a 10-Mbps
Ethernet link is preferable to a 64-kbps leased line
• Delay
– The length of time that is required to move a packet from
source to destination
• Load
– The amount of activity on a network resource, such as a router
or link
• Reliability
– Usually refers to the bit error rate of each network link
Intra and InterDomain Routing
Routing inside AS
Routing between AS
22.25
Figure 22.13 Popular routing protocols
22.26
Distance Vector Routing
22.29
Figure 22.15 Initialization of tables in distance vector routing
Phase1 : Initialization
22.30
Phase2 : Sharing
22.31
Figure 22.16 Updating in distance vector routing
Phase3 : Updating
– Periodic Update
• 30 seconds
• Depends on the Distance vector Routing Protocol
– Triggered Update
• Any time if change in routing table
• Receives table from neighbor and changes in own
table after updating
• Failure in neighboring links results in distance ∞
Two Node Loop Instability
22.36
Solutions to 2 node loop problem
1. Defining Infinity
– Redefine ∞ to say 100
– System will become stable in less updates
– Distance taken as 1 between each node
– Infinity = 16
– Limitations : Size of network cannot
exceed 15 hops
Solutions to 2 node loop problem contd..
2. Split Horizon
– Way to eliminate routing loops
– Speed up convergence
– prevents a router from advertising a route
back out the same interface where the
router originally learned the route
• Send part of table through each interface
• B knows optimum route to reach X via A , eliminate
sending in same interface (A already knows)
• Don’t create confusion
Solutions to 2 node loop problem contd..
3. Poison Reverse
– Route poisoning enables the receiving
22.40
Figure 22.18 Three-node instability
22.43
Figure 22.19 Example of a domain using RIP
22.44
Modeling a Network
• Modeled as a graph
– Routers nodes 5
– Link edges B
3
C
5
• Possible edge costs 2
– Hop A 2 1 F
3
– Delay 1
– Congestion level 2
D E
– …. 1
• Goal of Routing
– Determine “good” path from source to destination
– “Good” usually means the lowest “cost” path
– Where cost is usually hop-count or latency
45
Link State Routing
Every router has knowledge about the network, but from its own
perspective. Ex : City Map
22.48
Figure 20.8: Example of a link-state database
20.49
Link State vs Distance Vector
• In distance vector
– Each Router tells its neighbors
what it knows about the whole AS
• In Link State
– Each Router tells the whole AS
what it knows about the neighbors
Dynamic Topology maintenance
22.52
Link State Routing
• LSP
– Advertiser ID, Sequence Number, List of neighbors
(Cost of Link) etc.
– Seq No
• Distinguish new LSPs from Old ones
20.56
Flooding of LSPs
20.58
Figure 22.22 Dijkstra algorithm
22.59
Figure 22.23 Example of formation of shortest path tree
22.60
20.61
Table 22.2 Routing table for node A
22.62
Figure 20.8: Example of a link-state database
20.63
Table 20.2: Dijkstra’s Algorithm
Figure 20.10: Least-cost tree
20.65
Example: Initialization
4 1 3 10
2 2 ∞
∞ C D E
5 8 ∞ 4 6
1
F G
∞ ∞
66
Example: Update neighbors' distance
0 2
2
A B
4 1 3 10
2 2 ∞
∞ C D E
5 8 1 4 6
Distance(B) = 2 1
F G
Distance(D) = 1
∞ ∞
67
Example: Remove vertex with
minimum distance
0 2
2
A B
4 1 3 10
2 2 ∞
∞ C D E
5 8 1 4 6
1
F G
∞ ∞
68
Example: Update neighbors
0 2
2
A B
4 1 3 10
2 2 3
3 C D E
5 8 1 4 6
Distance(C) = 1 + 2 = 3 1
F G
Distance(E) = 1 + 2 = 3
Distance(F) = 1 + 8 = 9 9 5
Distance(G) = 1 + 4 = 5
69
Example: Continued...
Pick vertex in List with minimum distance (B) and update neighbors
0 2
2
A B
4 1 3 10
2 2 3
3 C D E
5 8 1 4 6
Note : distance(D) not
F 1
G updated since D is
already known and
9 5 distance(E) not updated
since it is larger than
previously computed
70
Example: Continued...
Pick vertex List with minimum distance (E) and update neighbors
0 2
2
A B
4 1 3 10
2 2 3
3 C D E
5 8 1 4 6
1
F G
No updating
9 5
71
Example: Continued...
Pick vertex List with minimum distance (C) and update neighbors
0 2
2
A B
4 1 3 10
2 2 3
3 C D E
5 8 1 4 6
Distance(F) = 3 + 5 = 8 1
F G
8 5
72
Example: Continued...
Pick vertex List with minimum distance (G) and update neighbors
0 2
2
A B
4 1 3 10
2 2 3
3 C D E
5 8 1 4 6
1
F G
Previous distance
6 5
Distance(F) = min (8, 5+1) = 6
73
Example (end)
0 2
2
A B
4 1 3 10
2 2 3
3 C D E
5 8 1 4 6
1
F G
6 5
Pick vertex not in S with lowest cost (F) and update neighbors
74
OSPF (Open Shortest Path First)
77
Figure 21-24
Concept of Link State Routing
Dijkstra’s Algorithm
79
Single-Source Shortest Path Problem
82
Dijkstra pseudocode
Dijkstra(v1, v2):
for each vertex v: // Initialization
v's distance := infinity.
v's previous := none.
v1's distance := 0.
List := {all vertices}.
while List is not empty:
v := remove List vertex with minimum distance.
mark v as known.
for each unknown neighbor n of v:
dist := v's distance + edge (v, n)'s weight.
if dist is smaller than n's distance:
n's distance := dist.
n's previous := v.
reconstruct path from v2 back to v1,
following previous pointers.
83
Example: Initialization
4 1 3 10
2 2 ∞
∞ C D E
5 8 ∞ 4 6
1
F G
∞ ∞
84
Example: Update neighbors' distance
0 2
2
A B
4 1 3 10
2 2 ∞
∞ C D E
5 8 1 4 6
Distance(B) = 2 1
F G
Distance(D) = 1
∞ ∞
85
Example: Remove vertex with
minimum distance
0 2
2
A B
4 1 3 10
2 2 ∞
∞ C D E
5 8 1 4 6
1
F G
∞ ∞
86
Example: Update neighbors
0 2
2
A B
4 1 3 10
2 2 3
3 C D E
5 8 1 4 6
Distance(C) = 1 + 2 = 3 1
F G
Distance(E) = 1 + 2 = 3
Distance(F) = 1 + 8 = 9 9 5
Distance(G) = 1 + 4 = 5
87
Example: Continued...
Pick vertex in List with minimum distance (B) and update neighbors
0 2
2
A B
4 1 3 10
2 2 3
3 C D E
5 8 1 4 6
Note : distance(D) not
F 1
G updated since D is
already known and
9 5 distance(E) not updated
since it is larger than
previously computed
88
Example: Continued...
Pick vertex List with minimum distance (E) and update neighbors
0 2
2
A B
4 1 3 10
2 2 3
3 C D E
5 8 1 4 6
1
F G
No updating
9 5
89
Example: Continued...
Pick vertex List with minimum distance (C) and update neighbors
0 2
2
A B
4 1 3 10
2 2 3
3 C D E
5 8 1 4 6
Distance(F) = 3 + 5 = 8 1
F G
8 5
90
Example: Continued...
Pick vertex List with minimum distance (G) and update neighbors
0 2
2
A B
4 1 3 10
2 2 3
3 C D E
5 8 1 4 6
1
F G
Previous distance
6 5
Distance(F) = min (8, 5+1) = 6
91
Example (end)
0 2
2
A B
4 1 3 10
2 2 3
3 C D E
5 8 1 4 6
1
F G
6 5
Pick vertex not in S with lowest cost (F) and update neighbors
92
Bellman Ford Algorithm
1) This step initializes distances from source to all vertices as infinite and distance to source
itself as 0. Create an array dist[] of size |V| with all values as infinite except dist[src] where src
is source vertex.
2) This step calculates shortest distances. Do following |V|-1 times where |V| is the number of
vertices in given graph.
…..a) Do following for each edge u-v
………………If dist[v] > dist[u] + weight of edge uv, then update dist[v]
………………….dist[v] = dist[u] + weight of edge uv
3) This step reports if there is a negative weight cycle in graph. Do following for each edge u-v
……If dist[v] > dist[u] + weight of edge uv, then “Graph contains negative weight cycle”
The idea of step 3 is, step 2 guarantees shortest distances if graph doesn’t contain negative
weight cycle. If we iterate through all edges one more time and get a shorter path for any
vertex, then there is a negative weight cycle
Let the given source vertex be 0. Initialize all
distances as infinite, except the distance to
source itself. Total number of vertices in the
graph is 5, so all edges must be processed 4
times.
Let all edges are processed
in the following order: (B,
E), (D, B), (B, D), (A, B), (A,
C), (D, C), (B, C), (E, D).
The first row shows initial
distances.
The second row shows
distances when edges (B,
E), (D, B), (B, D) and (A, B)
are processed.
The third row shows
distances when (A, C) is
processed.
The fourth row shows
when (D, C), (B, C) and (E,
D) are processed.
The second iteration guarantees to give all shortest paths which
are at most 2 edges long.
Let all edges are processed in the following order: (B, E), (D, B),
(B, D), (A, B), (A, C), (D, C), (B, C), (E, D).