Unit 4
Unit 4
Network Layer
Introduction,
Inside Router,
application
6. receive data application
transport 5. data flow begins transport
network 4. call connected 3. accept call
network
data link 1. initiate call 2. incoming call
data link
physical physical
Routing and Forwarding
value in arriving
packet’s header
0111 1
3 2
VC Forwarding Table
3.Datagram Network
application application
transport transport
network 1. send datagrams 2. receive datagrams network
data link data link
physical physical
Datagram Forwarding Table
A datagram forwarding table helps a router decide
where to send packets based on their destination
address.
How It Works?
IP destination address in
arriving packet’s header
1
3 2
Network Layer
Datagram forwarding table
Destination Address Range Link Interface
otherwise 3
How Longest Prefix Match Works
Example 1:
Example 3:
Components of a Router
1. Input Ports – Receive incoming data packets.
2. Switching Fabric – Moves packets inside the router.
Fig: Components of a
Router
forwarding data
plane (hardware)
high-seed
switching
fabric
physical layer:
bit-level reception
data link layer: decentralized switching:
e.g., Ethernet • given datagram dest., lookup output port
using forwarding table in input port memory
(“match plus action”)
• goal: complete input port processing at ‘line
speed’
• queuing: if datagrams arrive faster than
forwarding rate into switch fabric
Input Port Functions
1.Receives Data (Physical Layer) – Takes in bits from incoming
packets.
2.Processes Data Link Layer – Understands Ethernet or other link-
layer protocols.
3.Looks Up Destination – Uses a forwarding table to decide where
to send the packet.
4.Queues Packets – Holds packets temporarily if they arrive faster
than they can be forwarded.
5.Sends to Switch Fabric – Transfers packets to the next stage for
forwarding.
Let me know if you need further simplification!kj
Input Port Functions
memory
system bus
• Like traditional computers, with switching between input and
output ports being done under direct control of the CPU (routing
processor).
• Only one memory read/write over the shared system bus can be
done at a time.
Switching via bus
• An input port transfers a packet to the output
port over a shared bus, without intervention by
the routing processor.
datagram
switch buffer link
fabric layer line
protocol termination
queueing (send)
buffering required when datagrams arrive from fabric faster than the
transmission rate
scheduling discipline chooses among queued datagrams for
transmission
datagram
switch buffer link
fabric layer line
protocol termination
queueing (send)
switch
switch
fabric
fabric
• buffering when arrival rate via switch exceeds output line speed
• queueing (delay) and loss due to output port buffer overflow!
Routing Processor
link layer
physical layer
• Internet’s network layer has three major components.
• The first component is the IP protocol
• The second major component is the routing component, which determines the path a
datagram follows from source to destination and compute the forwarding tables that
are used to forward packets through the network.
• The final component of the network layer is a facility to report errors in datagrams and
respond to requests for certain network-layer information
IPv4 Datagram format
IP protocol version 32 bits
number total datagram
header length type of length (bytes)
ver head. length
(bytes) len service for
“type” of data fragment fragmentation/
16-bit identifier flgs
offset reassembly
max number time to upper header
remaining hops live layer checksum
(decremented at
32 bit source IP address
each router)
32 bit destination IP address
upper layer protocol
to deliver payload to options (if any) e.g. timestamp,
record route
data taken, specify
(variable length, list of routers
typically a TCP to visit.
or UDP segment)
• Version number: These 4 bits specify the IP protocol version of
the datagram. It determines how to interpret the header. Currently
the only permitted values are 4 (0100) or 6 (0110).
• Flags:
• In order for the destination host to be absolutely sure it has received
the last fragment of the original datagram, the last fragment has a flag
bit set to 0, whereas all the other fragments have this flag bit set to 1.
• Fragmentation offset:
• When fragmentation of a message occurs, this field specifies the
offset, or position, in the overall message where the data in this
fragment goes.
• It is specified in units of 8 bytes (64 bits).
• Time-to-live:
• Specifies how long the datagram is allowed to “live” on the network. Each router
decrements the value of the TTL field (reduces it by one) prior to transmitting it.
• If the TTL field drops to zero, the datagram is assumed to have taken too long a route
and is discarded.
• Protocol:
• This field is used only when an IP datagram reaches its final destination.
• The value of this field indicates the specific transport-layer protocol to which the
data portion of this IP datagram should be passed.
• For example, a value of 6 indicates that the data portion is passed to TCP, while a
value of 17 indicates that the data is passed to UDP.
…
in: one large datagram
out: 3 smaller datagrams
• large IP datagram divided
(“fragmented”) within net
• one datagram becomes several
datagrams reassembly
• “reassembled” only at final
destination
• IP header bits used to identify, …
order related fragments
IP fragmentation, reassembly
• IP addresses are 32 bit numbers which are divided into 4 octets. Each octet
represents 8 bit binary number. Below is an example of an IP address:
172 16 254 1
223.1.1.4 223.1.2.9
• Interface: It is a connection
between host/router and 223.1.3.27
physical link. 223.1.1.3
223.1.2.2
223 1 1 1
Interface Example
223.1.1.1
Q: how are interfaces actually
connected? 223.1.2.1
223.1.1.2
223.1.1.4 223.1.2.9
223.1.3.27
223.1.1.3
223.1.2.2
7 Bit 24 Bit
Fix Network ID Host ID
Class: B
1 0
Fix
Class: E Multicast address
1 1 1 1
223.1.3.0/24
subnet
223.1.3.1 223.1.3.2
223.1.3.0/24
Type of addresses in IPv4 Network
• Network address - The address by which we refer to the network.
• E.g.: 10.0.0.0
subnet host
part part
11001000 00010111 00010000 00000000
200.23.16.0/23
Classless Inter-Domain Routing(CIDR)
• CIDR is a slash notation of subnet mask. CIDR tells us number of
on bits in a network address.
subnet host
part part
11001000 00010111 00010000 00000000
200.23.16.0/23
• A single IP address can be used to designate many unique IP
addresses with CIDR.
• CIDR addresses reduce the size of routing tables and make more IP
addresses available within organizations.
Subnetting
• Subnetting take places when we extend the default subnet mask.
• Now find the host bits borrowed to create subnets and convert them
in decimal.
• In second step find the block size and count from zero in block until
subnet mask value.
• We have 32 - 26
1. [Total bits in IP address - Bits consumed by network address] = 6
2. Total hosts per subnet would be 26 = 64
Network Prefixes
• For Class C, Default subnet mask of class C is 255.255.255.0
DHCP
223.1.1.0/24
server
223.1.1.1 223.1.2.1
223.1.2.0/24
223.1.3.1 223.1.3.2
223.1.3.0/24
• With dynamic addressing, a device can have a different IP address
every time it connects to the network.
DHCP offer
src: 223.1.2.5, 67
Broadcast: I’m a DHCP
dest: 255.255.255.255, 68
server!
yiaddrr:Here’s
223.1.2.4an IP
transaction
address youID:can
654 use
lifetime: 3600 secs
DHCP request
src: 0.0.0.0, 68
dest:: 255.255.255.255, 67
Broadcast: OK. I’ll
yiaddrr: 223.1.2.4
take that IPID:address!
transaction 655
lifetime: 3600 secs
DHCP ACK
src: 223.1.2.5, 67
dest: 255.255.255.255,
Broadcast: 68
OK. You’ve
yiaddrr: 223.1.2.4
gottransaction
that IPID:address!
655
lifetime: 3600 secs
DHCP: More than IP addresses
DHCP can return more than just allocated IP address on subnet:
address of first-hop router for client
encapsulated in UDP,
DHCP DHCP 168.1.1.1 encapsulated in IP,
DHCP UDP encapsulated in 802.1
DHCP IP Ethernet frame
DHCP Eth router with DHCP
Phy server built into broadcast (dest:
router FFFFFFFFFFFF) on LAN,
received at router
running DHCP
Ethernet demuxedserver to
IP demuxed, UDP
demuxed to DHCP
DHCP DHCP • DCP server formulates DHCP
DHCP UDP ACK containing client’s IP
DHCP IP address, IP address of first-
DHCP Eth hop router for client, name
Phy & IP address of DNS server
encapsulation of
DHCP DHCP DHCP server, frame
DHCP UDP forwarded to client,
DHCP IP demuxing up to
Eth router with DHCP
DHCP
DHCP at client
DHCP
Phy server built into client now knows its
router IP address, name
and IP address of
DSN server, IP
address of its first-
hop router
Network Address Translation
• NAT is a method that is used to translate Private IP addresses to
Public IP addresses.
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
• Inside Global Address: The name of the inside host after translation. This
would be the Public IP.
• Outside Local Address: The name of the destination host before translation.
• Outside Global Address: The name of the destination host after translation.
• Where:
• Global Addresses → Public
• Local Addresses → Private
• Inside Hosts → Within Local Network
• Outside Hosts → Outside Local Network
Implementation : NAT router must:
• 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 translation table 1: host 10.0.0.1
2: NAT router WAN side addr LAN side addr
changes datagram sends datagram to
source addr from 138.76.29.7, 5001 10.0.0.1, 3345 128.119.40.186, 80
10.0.0.1, 3345 to …… ……
138.76.29.7, 5001,
updates table S: 10.0.0.1, 3345
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
Internet Control Message Protocol - ICMP
• When something unexpected occurs, the event is reported by the
ICMP, which is also used to test the Internet.
• Some of the ICMP messages are defined and are listed below.
Each ICMP message type is encapsulated in an IP packet.
• additional motivation:
• header format helps speed processing/forwarding
• header changes to facilitate QoS
• Traffic Class:
• The size of Traffic Class field is 8 bits. Traffic Class field is similar to the IPv4 Type
of Service (ToS) field.
• The Traffic Class field indicates the IPv6 packet’s class or priority.
• Flow Label:
• The size of Flow Label field is 20 bits.
• The Flow Label field provide additional support for real-time datagram delivery and
quality of service features.
• The purpose of Flow Label field is to indicate that this packet belongs to a specific
sequence of packets between a source and destination and can be used to prioritized
delivery of packets for services like voice.
• Payload Length: The size of the Payload Length field is 16 bits. The Payload
Length field shows the length of the IPv6 payload, including the extension
headers and the upper layer protocol data
• Next Header: The size of the Next Header field is 8 bits. The Next Header
field shows either the type of the first extension (if any extension header is
available) or the protocol in the upper layer such as TCP, UDP, or ICMPv6.
• Hop Limit: The size of the Hop Limit field is 8 bits The Hop Limit field shows
the maximum number of routers the IPv6 packet can travel. This Hop Limit
field is similar to IPv4 Time to Live (TTL) field.
• Source Address: The size of the Source Address field is 128 bits. The Source
Address field shows the IPv6 address of the source of the packet.
Difference between IPv4 & IPv6
IPv4 IPv6
32 bit length 128 bit length
Fragmentation is done by sender Fragmentation is done only by sender
and forwarding routers
No packet flow identification Packet flow identification is available within
the IPv6 header using the Flow Label field
Checksum field in header No checksum field in header
Options fields are available in No option fields, but Extension headers are
header available
Address Resolution Protocol (ARP)is Address Resolution Protocol (ARP) is
available to map IPv4 addresses replaced with Neighbor Discovery Protocol
to MAC addresses
2. decentralized:
• router knows physically-connected neighbors, link costs to
neighbors
• iterative process of computation, exchange of info with neighbors
• “distance vector” algorithms
Second way
1. Static:
routes change slowly over time
2. Dynamic:
routes change more quickly
periodic update
in response to link cost changes
Third way
1. Load-sensitive algorithm
• In link costs vary dynamically to reflect the current level of
congestion in the underlying link.
• If a high cost is associated with a link that is currently congested,
a routing algorithm will tend to choose routes around such a
congested link.
•
2. Load-insensitive :
• Today’s Internet routing algorithms (such as RIP, OSPF, and BGP)
are load-insensitive, as a link’s cost does not explicitly reflect its
current (or recent past) level of congestion.
Link State Routing Algorithm
• Also known as Dijkstra’s Algorithm.
• It computes the least-cost path from one node (source node) to all
other nodes in the network.
• Its iterative and after the kth least-cost paths are known to k
destination nodes.
• Notation:
• c(x,y): link cost from node x to y; = ∞ if not direct neighbours
• D(v): current value of cost of path from source to destination v
• p(v): predecessor node along path from source to v
• N': set of nodes whose least cost path definitively known
Basics of Dijkstra's Algorithm
• Dijkstra's Algorithm basically starts at the node that you choose (the source
node) and it analyses the graph to find the shortest path between that node
and all the other nodes in the graph.
• The algorithm keeps track of the currently known shortest distance from each
node to the source node and it updates these values if it finds a shorter path.
• Once the algorithm has found the shortest path between the source node and
another node, that node is marked as "visited" and added to the path.
• The process continues until all the nodes in the graph have been added to the
path. This way, we have a path that connects the source node to all other
nodes following the shortest path possible to reach each node.
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'
Dijkstra’s Algorithm – Example:1
D(v) D(w) D(x) D(y) D(z)
Step N' p(v) p(w) p(x) p(y) p(z)
0 u 7,u 3,u 5,u ∞ ∞
1 uw 6,w 5,u 11,w ∞
2 uwx 6,w 11,w 14,x
3 uwxv 10,v 14,x
x
4 uwxvy 12,y 9
5 uwxvyz
5 7
4
notes: 8
construct shortest path 3
tree by tracing u w y z
2
predecessor nodes
ties can exist (can be 3
broken arbitrarily) 7 4
v
Dijkstra’s Algorithm – Example:2
5
3
v w 5
2
u 2 1 z
3
1 2
x 1
y
Distance Vector Algorithm
• Distance-vector (DV) algorithm is iterative, asynchronous, and
distributed.
dx(y) = min
v
{c(x,v) + d v(y) }
from
from
y ∞∞ ∞ y 2 0 1
z ∞∞ ∞ z 7 1 0
Dx(z) = min{c(x,y) +
node y cost to
table x y z Dy(z), c(x,z) + Dz(z)}
x ∞ ∞ ∞ = min{2+1 , 7+0} = 3
y 2 0 1
from
z ∞∞ ∞
y
2 1
node z cost to
table x y z x z
7
x ∞∞ ∞
from
y ∞∞ ∞
z 7 1 0
time
Distance Vector Algorithm - Example
node x cost to cost to cost to
table x y z x y z x y z
x 0 2 7 x 0 2 3 x 0 2 3
from
from
y ∞∞ ∞ y 2 0 1 y 2 0 1
from
y
z ∞∞ ∞ z 7 1 0 z 3 1 0 2 1
node y cost to
x z
cost to cost to 7
table x y z x y z x y z
x ∞ ∞ ∞ x 0 2 7 x 0 2 3
from
y 2 0 1 y 2 0 1
from
y 2 0 1
from
z ∞∞ ∞ z 7 1 0 z 3 1 0
x ∞∞ ∞ x 0 2 7 x 0 2 3
from
from
y 2 0 1 y 2 0 1
from
y ∞∞ ∞
z 7 1 0 z 3 1 0 z 3 1 0
time
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 Updates are triggered not periodic
update at every 30 or 90 second
Update are broadcasted Updates are multicasted
Updates are sent to directly connected Update are sent to entire network & to just
neighbour only directly connected neighbour
Routers don't have end to end visibility Routers have visibility of entire network of that
of entire network. area only.
It is prone to routing loops No routing loops
Hierarchical Routing
• As networks grow in size, the router routing tables grow
proportionally.
• Each router knowing all the details about how to route packets to
destinations within its own region.
• One router was indistinguishable from another in the sense that all
routers executed the same routing algorithm to compute routing
paths through the entire network.
• At a certain point the network may grow to the point where it is no longer
feasible for every router to have an entry for every other router, so the
routing will have to be done hierarchically, as it is in the telephone
network.
2. Administrative autonomy.
• Although researchers tend to ignore issues such as a company’s
desire to run its routers as it pleases (for example, to run whatever
routing algorithm it chooses) or to hide aspects of its network’s
internal organization from the outside, these are important
considerations.
• Ideally, an organization should be able to run and administer its
network as it wishes, while still being able to connect its network
to other outside networks.
• When hierarchical routing is used, the routers are divided into what
called regions, with each router knowing all the details about how
to route packets to destinations within its own region, but knowing
nothing about the internal structure of other regions.
• Both of these problems can be solved by organizing routers into
autonomous systems (ASs), with each AS consisting of a group of
routers that are typically under the same administrative control
(e.g., operated by the same ISP or belonging to the same company
network).
• Routers within the same AS all run the same routing algorithm (for
example, an LS or DV algorithm)
• To connect ASs to each other, and thus one or more of the routers in
an AS will have the added task of being responsible for forwarding
packets to destinations outside the AS; these routers are called
gateway routers.
• When hierarchical routing is used, the routers are divided into what called
regions, with each router knowing all the details about how to route packets
to destinations within its own region, but knowing nothing about the
internal structure of other regions.
• Figure below provides a simple example with three ASs: AS1, AS2, and AS3.
• In figure, the heavy lines represent direct link connections between pairs of
routers.
• The thinner lines hanging from the routers represent subnets that are
directly connected to the routers.
Interconnected ASes
3c
3a 2c
3b 2a
AS3 2b
1c AS2
1a 1b AS1
1d forwarding table
configured by both intra-
and inter-AS routing
Intra-AS
Routing
Inter-AS
Routing
algorithm
algorithm algorithm intra-AS sets entries for internal
dests
Forwarding inter-AS & intra-AS sets entries
table
for external dests
Inter-AS tasks
suppose router in AS1 AS1 must:
receives datagram destined 1. learn which dests are
outside of AS1: reachable through AS2,
router should forward packet to
gateway router, but which one?
which through AS3
2. propagate this
reachability info to all
routers in AS1
job of inter-AS routing!
3c
3a
3b
AS3 2c other
1c 2a networks
other 1a 2b
networks 1b AS2
AS1 1d
Hierarchical Routing - Example
THANK YOU