Forwarding and Routing

businessmakeshiftNetworking and Communications

Oct 29, 2013 (3 years and 9 months ago)

86 views

Forwarding and Routing

The role of the network layer is thus deceptively simple


to move packets from a sending host to a receiving host.
To do so, two important network
-

layer functions can be identified:

• Forwarding. When a packet arrives at a
router’s input link, the router must move the packet to the
appropriate output link. For example, a packet arriving from Host H1 to Router R1 must be forwarded to the
next router on a path to H2. In Section 4.3, we’ll look inside a router and examine how a

packet is actually
for
-
warded from an input link to an output link within a router.

• Routing. The network layer must determine the route or path taken by packets as they flow from a sender
to a receiver. The algorithms that calculate these paths are refe
rred to as
routing algorithms
. A routing
algorithm would determine, for example, the path along which packets flow from H1 to H2.

The terms forwarding and routing are often used interchangeably by authors dis
-
cussing the network layer.
We’ll use these ter
ms much more precisely in this book. Forwarding refers to the router
-

local action of transferring a
packet from an input link interface to the appropriate output link interface. Routing refers to the network
-

wide process
that determines the end
-

to
-

end
paths that packets take from source to destina
-
tion. Using a driving analogy,
consider the trip from Pennsylvania to Florida under
-
taken by our traveler back in Section 1.3.1. During this trip, our
driver passes through many interchanges en route to Florid
a. We can think of forwarding as the process of getting
through a single interchange: A car enters the interchange from one road and determines which road it should take to
leave the interchange. We can think of routing as the process of planning the trip
from Pennsylvania to Florida:
Before embarking on the trip, the driver has consulted a map and chosen one of many paths possible, with each path
consisting of a series of road segments connected at interchanges.

Every router has a
forwarding table
. A rout
er forwards a packet by examin
-
ing the value of a field in the
arriving packet’s header, and then using this header value to index into the router’s forwarding table. The value stored
in the forward
-
ing table entry for that header indicates the router’s ou
tgoing link interface to which that packet is to be
forwarded. Depending on the network
-

layer protocol, the header value could be the destination address of the packet
or an indication of the connection to which the packet belongs. Figure 4.2 provides an
example. In Figure 4.2, a
packet with a header field value of 0111 arrives to a router. The router indexes into its forwarding table and
determines that the output link interface for this packet is interface 2. The router then internally forwards the packe
t to
interface 2. In Section 4.3, we’ll look inside a router and examine the forwarding function in much greater detail.

You might now be wondering how the forwarding tables in the routers are con
-
figured. This is a crucial
issue, one that exposes the imp
ortant interplay between

routing and forwarding. As shown in Figure 4.2, the routing
algorithm determines the values that are inserted into the routers’ forwarding tables. The routing algorithm may be
centralized ( e. g., with an algorithm executing on a c
entral site and down
-
loading routing information to each of the
routers) or decentralized ( i. e., with a piece of the distributed routing algorithm running in each router). In either case,

a router receives routing protocol messages, which are used to con
figure its forward
-
ing table. The distinct and
different purposes of the forwarding and routing func
-
tions can be further illustrated by considering the hypothetical (
and unrealistic, but technically feasible) case of a network in which all forwarding tab
les are configured directly by
human network operators physically present at the routers. In this case, no routing protocols would be required! Of
course, the human operators would need to interact with each other to ensure that the forwarding tables were
configured in such a way that packets reached their intended destinations. It’s also likely that human configuration
would be more error
-

prone and much slower to respond to changes in the network topology than a routing protocol.
We’re thus fortunate that

all networks have both a forwarding and a routing function!

While we’re on the topic of terminology, it’s worth mentioning two other terms that are often used
interchangeably, but that we will use more carefully. We’ll reserve the term packet switch to me
an a general packet
-

switching device that transfers a packet from input link interface to output link interface, according to the value in a
field in the header of the packet. Some packet switches, called link
-

layer switches ( exam
-
ined in Chapter 5), ba
se
their forwarding decision on values in the fields of the link
-
layer frame; switches are thus referred to as link
-

layer (
layer 2) devices. Other packet switches, called routers, base their forwarding decision on the value in the network
-
layer field. Ro
uters are thus network
-

layer ( layer 3) devices, but must also implement layer 2 protocols as well, since
layer 3 devices require the services of layer 2 to imple
-
ment their ( layer 3) functionality. ( To fully appreciate this
important distinction, you m
ight want to review Section 1.5.2, where we discuss network
-

layer datagrams and link
-

layer frames and their relationship.) To confuse matters, marketing literature often refers to “ layer 3 switches” for
routers with Ethernet interfaces, but these are re
ally layer 3 devices. Since our focus in this chapter is on the network
layer, we use the term router in place of packet switch. We’ll even use the term router when talking about packet
switches in virtual
-

circuit networks ( soon to be discussed).

Routing

Algorithms

So far in this chapter, we’ve mostly explored the network layer’s forwarding func
-
tion. We learned that when a packet
arrives to a router, the router indexes a forward
-
ing

table and determines the link interface to which the packet is to
be directed. We also learned that routing algorithms, operating in network routers, exchange and

compute the
information that is used to configure these forwarding tables. The inter
-
play be
tween routing algorithms and
forwarding tables was shown in Figure 4.2. Having explored forwarding in some depth we now turn our attention to
the other major topic of this chapter, namely, the network layer’s critical routing function. Whether the network
layer
provides a datagram service ( in which case different pack
-
ets between a given source
-

destination pair may take
different routes) or a VC serv
-
ice ( in which case all packets between a given source and destination will take the
same path), the netwo
rk layer must nonetheless determine the path that packets take from senders to receivers.
We’ll see that the job of routing is to determine good paths ( equivalently, routes), from senders to receivers, through
the network of routers.


Typically a host is
attached directly to one router,

the

default router

for the host ( also called

the

first
-

hop router

for the host). Whenever a host sends a packet, the packet is transferred to its default router. We refer to the default
router of the
source host

as the so
urce router and the default router of the destination host as the
destination
router
. The problem of routing a packet from source host to destination host clearly boils down to the problem of
routing the packet from source router to destination router, whi
ch is the focus of this section.


The purpose of a routing algorithm is then simple: given a set of routers, with links connecting the routers, a routing
algorithm finds a “ good” path from source router to destination router. Typically, a good path is one

that has the least
cost. We’ll see, however, that in practice, real
-

world concerns such as policy issues ( for example, a rule such as “
router x, belonging to organization Y, should not forward any packets originating from the network owned by
organizat
ion Z”) also come into play to complicate the conceptually simple and elegant algorithms whose theory
underlies the practice of routing in today’s networks.


A graph is used to formulate routing problems. Recall that a
graph

G = ( N, E) is a set N of nodes

and a collection E
of edges, where each edge is a pair of nodes from N. In the context of network
-

layer routing, the nodes in the graph
represent routers


the points at which packet
-

forwarding decisions are made


and the edges connecting these
nodes rep
resent the physical links between these routers. Such a graph abstraction of a computer network is shown
in Figure 4.27. To view some graphs representing real network maps, see [ Dodge 2012, Cheswick 2000]; for a
discussion of how well different graph
-

bas
ed models model the Internet, see [ Zegura 1997, Faloutsos 1999, Li
2004].

As shown in Figure 4.27, an edge also has a value representing its cost. Typi
-
cally, an edge’s cost may reflect the
physical length of the corresponding link ( for example, a trans
oceanic link might have a higher cost than a short
-

haul
terrestrial link), the link speed, or the monetary cost associated with a link. For our purposes, we’ll simply take the
edge costs as a given and won’t worry about how they are determined. For any ed
ge ( x, y) in E, we denote c( x, y)
as the cost of the edge between nodes x and y. If the pair ( x, y) does not belong to E, we set c( x, y) = 8. Also,
through
-
out we consider only undirected graphs ( i. e., graphs whose edges do not have a direction), so
that edge ( x,
y) is the same as edge ( y, x) and that c( x, y) = c( y, x). Also, a node y is said to be a
neighbor

of node x if ( x, y)
belongs to E.











5









3




2






5























2


3


1























1






2
























1



Figure 4.27 Abstract graph model of a computer network



Gi ven that costs are assi gned to the vari ous edges i n the graph abstracti on, a natu
-
ral

goal of a routi ng al gori thm i s
to i denti fy the l east costl y paths between sources and desti nati ons. To make thi s probl em more preci se, recal l that
a
path

i n a graph G = ( N, E) i s a sequence of nodes ( x 1 , x 2 ,..., x p ) such that each of the pai rs ( x

1 , x 2 ), ( x 2 , x
3 ),...,( x p
-

1 , x p ) are edges i n E. The cost of a path ( x 1 , x 2 ,..., x p ) i s si mpl y the sum of al l the edge costs al ong
the path, that i s, c( x 1 , x 2 ) + c( x 2 , x 3 ) + ...+ c( x p
-

1 , x p ). Gi ven any two nodes x and y
, there are typi cal l y
many paths between the two nodes, wi th each path havi ng a cost. One or more of these paths i s a
least
-

cost path.

The l east
-

cost probl em i s therefore cl ear: Fi nd a path between the source and desti nati on that has l east cost. In
Fi gur
e 4.27, for exampl e, the l east
-

cost path between source node u and desti nati on node w i s ( u, x, y, w) wi th a
path cost of 3. Note that i f al l edges i n the graph have the same cost, the l east
-

cost path i s al so the
shortest path
(
that i s, the path wi th t
he smal l est number of l i nks between the source and the desti nati on).


As a si mpl e exerci se, try fi ndi ng the l east
-

cost path from node u to z i n Fi gure 4.27 and refl ect for a moment on
how you cal culated that path. If you are l i ke most peopl e, you found t
he path from u to z by exami ni ng Fi gure 4.27,
traci ng a few routes from u to z, and somehow convi nci ng yoursel f that the path you had chosen had the l east cost
among al l possi bl e paths. ( Di d you check al l of the 17 possi bl e paths between u and z? Probabl y

not!) Such a
cal cul ati on i s an exampl e of a central i zed routi ng al gori thm


the routi ng al gori thm was run i n one l ocati on, your
brai n, wi th compl ete i nformati on about the network. Broadl y, one way i n whi ch we can cl assify routi ng al gori thms
i s accordi ng to

whether they are gl obal or decentral i zed.


• A
global routing algorithm

computes the l east
-

cost path between a source and desti nati on usi ng
compl ete, gl obal knowl edge about the network. That i s, the al gori thm takes the connecti vi ty between al l
nodes and

al l l i nk costs as i nputs. Thi s then requi res that the al gori thm somehow obtai n thi s i nformati on
before actual l y performi ng the cal cul ati on. The cal cul ati on i tsel f can be run at one si te

(a central i zed
gl obal routi ng al gori thm) or repl i cated at mul ti pl e si
tes. The key di sti ngui shi ng feature here, however, i s
that a gl obal al gorithm has compl ete i nformati on about connecti vi ty and l i nk costs. In practi ce, al gori thms
wi th gl obal state i nformati on are often referred to as
link
-

state ( LS) algorithms
, si nce the

al gori thm must
be aware of the cost of each l i nk i n the network. We’l l study LS al gori thms i n Secti on 4.5.1.


V


W


Z


X


Y


U

• In a
decentralized routing algorithm
, the cal cul ation of the l east
-

cost path i s carri ed out i n an i terati ve,
di stri buted manner. No node has compl ete i nformati on about the costs of al l network l i nks. Instead, each
node begi ns wi th onl y the knowl edge of the costs of i ts own di rectl y attached

l i nks. Then, through an
i tera
-
ti ve process of cal cul ati on and exchange of i nformati on wi th i ts nei ghbori ng nodes ( that i s, nodes
that are at the other end of l i nks to whi ch i t i tsel f i s attached), a node gradual l y cal cul ates the l east
-

cost
path to a des
ti nati on or set of desti nati ons. The decentral i zed routi ng al gori thm we’l l study bel ow i n
Secti on 4.5.2 i s cal l ed a di stance
-

vector ( DV) al gori thm, because each node mai ntai ns a vector of
esti mates of the costs ( di stances) to al l other nodes i n the netw
ork.


A second broad way to cl assi fy routi ng al gori thms i s accordi ng to whether they are stati c or dynami c. In
static
routing algorithms
, routes change very sl owl y over ti me, often as a resul t of human i nterventi on ( for exampl e, a
human manual l y edi t
-
i ng

a router’s forwardi ng tabl e).
Dynamic routing algorithms

change the routi ng paths as the
network traffi c l oads or topol ogy change. A dynami c al gori thm can be run ei ther peri odi cal l y or i n di rect response
to topol ogy or l i nk cost changes. Whi l e dynami c al g
ori thms are more responsi ve to network changes, they are al so
more suscepti bl e to probl ems such as routi ng l oops and osci l l ati on i n routes.


Athi rd way to cl assi fy routi ng al gori thms i s accordi ng to whether they are l oad
-
sensi ti ve or l oad
-

i nsensi ti ve. In

a
load
-

sensitive algorithm
, l i nk costs vary dynami
-
cal l y to refl ect the current l evel of congesti on i n the underl yi ng
l i nk. If a hi gh cost i s associ ated wi th a l i nk that i s currentl y congested, a routi ng al gori thm wi l l tend to choose
routes around such a

congested l i nk. Whi l e earl y ARPAnet routi ng al go
-
ri thms were l oad
-

sensi ti ve [ McQui l l an
1980], a number of di ffi cul ti es were encoun
-
tered [ Hui tema 1998]. Today’s Internet routi ng al gori thms ( such as
RIP, OSPF, and BGP) are
load
-

insensitive
, as a l i nk’
s cost does not expl i ci tl y refl ect i ts current ( or recent past) l evel
of congesti on.


4.5.1 The Link
-

State ( LS) Routing Algorithm


Recal l that i n a l i nk
-

state al gori thm, the network topol ogy and al l l i nk costs are known, that i s, avai lable as i nput to

the LS al gori thm. In practi ce thi s i s accom
-
pl i shed by havi ng each node broadcast l i nk
-

state packets to al l other
nodes i n the network, wi th each l i nk
-

state packet contai ni ng the i denti ti es and costs of i ts attached l i nks. In
practi ce ( for exampl e, wi t
h the Internet’s OSPF routi ng protocol, di scussed i n Secti on 4.6.1) thi s i s often
accompl i shed by a
link
-

state broadcast

algorithm
[ Perl man 1999]. We’l l cover broadcast al gori thms i n Secti on
4.7. The resul t of the nodes’ broadcast i s that al l nodes have
an i denti cal and compl ete vi ew of the network. Each
node can then run the LS al gori thm and compute the same set of l east
-

cost paths as every other node.


The l i nk
-

state routi ng al gori thm we present bel ow i s known as Di jkstra’s al go
-
ri thm, named after i t
s i nventor. A
cl osel y rel ated al gori thm i s Pri m’s al gori thm; see [ Cormen 2001] for a general di scussi on of graph al gori thms.
Di jkstra’s al gori thm computes the l east
-

cost path from one node ( the source, whi ch we wi l l refer to as u) to al l
other nodes i n
the network. Di jkstra’s algorithm i s i terati ve and has the prop
-
erty that after the kth i terati on of the
al gori thm, the l east
-

cost paths are known to k desti nati on nodes, and among the l east
-

cost paths to al l
desti nati on nodes, these k paths wi l l have th
e k smal l est costs. Let us defi ne the fol l owi ng notati on:




D( v): cost of the l east
-

cost path from the source node to desti nati on v as of thi s i terati on of the al gori thm.

• p( v): previ ous node ( nei ghbor of v) al ong the current l east
-

cost path from t
he source to v.

• N : subset of nodes; v i s i n N i f the l east
-

cost path from the source to v i s defi ni ti vel y known.


The gl obal routi ng al gori thm consi sts of an i ni ti al i zati on step fol l owed by a l oop. The number of ti mes the l oop i s
executed i s equal to
the number of nodes i n the network. Upon termi nati on, the al gori thm wi l l have cal cul ated the
shortest paths from the source node u to every other node i n the network.


Li nk
-

State ( LS) Al gori thm for Source Node u

1 Ini ti alization:

2 N’ = { u}

3 for al l nodes v

4 i f v i s a nei ghbor of u

5 then D( v) = c( u, v)


6 el se D( v) = 8

7
----

8 Loop

9 fi nd w not i n N’ such that D( w) i s a mi ni mum

10 add w to N’

11 update D( v) for each nei ghbor v of w and not i n N’:

12 D( v) = mi n( D( v), D( w) +

c( w, v) )

13 /* new cost to v i s ei ther ol d cost to v or known

14 l east path cost to w pl us cost from w to v */

15 unti l N’= N


As an exampl e, l et’s consi der the network i n Fi gure 4.27 and compute the l east
-

cost paths from u to al l possi bl e
desti nati ons. A tabul ar summary of the al gori thm’s computati on i s shown i n Tabl e 4.3, where each l i ne i n the tabl e
gi ves the val ues of the al g
ori thm’s vari abl es at the end of the i terati on. Let’s consi der the few fi rst steps i n detai l.


• In the i ni ti alizati on step, the currentl y known l east
-

cost paths from u to i ts di rectl y attached nei ghbors,
v, x, and w, are i ni ti al ized to 2, 1, and 5, resp
ecti vel y. Note i n parti cul ar that the cost to w i s set to 5 ( even
though we wi l l soon see that a l esser
-

cost path does i ndeed exi st) si nce thi s i s the cost of the di rect ( one
hop) l i nk from u to w. The costs to y and z are set to i nfi ni ty because they a
re not di rectl y connected to u.


• In the fi rst i terati on, we l ook among those nodes not yet added to the set N and fi nd that node wi th the
l east cost as of the end of the previ ous i terati on. That node i s x, wi th a cost of 1, and thus x i s added to
the se
t N . Li ne 12 of the LS al go
-
ri thm i s then performed to update D( v) for al l nodes v, yi el di ng the
resul ts shown i n the second l i ne ( Step 1) i n Tabl e 4.3. The cost of the path to v i s unchanged. The cost of
the path to w ( whi ch was 5 at the end of the i n
i ti al i zati on) through node x i s found to have a cost of 4.
Hence thi s l ower
-

cost path i s sel ected and w’s predecessor al ong the shortest path from u i s set to x.
Si mi l arl y, the cost to y ( through x) i s computed to be 2, and the tabl e i s updated accordi ng
l y.


• In the second i terati on, nodes v and y are found to have the l east
-

cost paths ( 2), and we break the ti e
arbi trari l y and add y to the set N so that N now contai ns u, x, and y. The cost to the remai ni ng nodes not
yet i n N , that i s, nodes v, w, and

z, are updated vi a l i ne 12 of the LS al gori thm, yi el di ng the resul ts shown
i n the thi rd row i n the Tabl e 4.3.


• And so on. . . .



Step

N

D(v), p(v)

D(w),
p(w)

D(x),p(x)


D(y),p(y)

D(z),p(z)

0

u


2,v



5,u



1,u









1

ux


2,v



4,x





2,x





2

uxy


2,v



3,y







4,y

3

uxyv




3,y







4,y

4

uxyvw










4,y

5

uxyvwz







Table 4.3 Running the link
-

state algorithm on the network in Figure 4.27










When the LS a
l gori thm termi nates, we have, for each node, i ts predecessor al ong the l east
-

cost path from the
source node. For each predecessor, we al so

have i ts predecessor, and so i n thi s manner we can construct the
enti re path from the source to al l desti nati ons. The forwardi ng tabl e i n a node, say node u, can then be
constructed from thi s i nformati on by stori ng, for each desti nati on, the next
-

hop node

on the l east
-

cost path from
u to the desti nati on. Fi gure 4.28 shows the resul ti ng l east
-

cost paths and forwardi ng tabl e i n u for the network i n
Fi gure 4.27.


What i s the computati onal compl exi ty of thi s al gori thm? That i s, gi ven n nodes ( not counti ng
the source), how
much computati on must be done i n the worst case to fi nd the l east
-

cost paths from the source to al l desti nati ons?
In the fi rst i terati on, we need to search through al l n nodes to determi ne the node, w, not i n N that has the
mi ni mum cost.
In the second i terati on, we need to check n


1 nodes to determi ne the mi ni mum cost; i n the thi rd
i terati on n


2 nodes, and so on. Overal l, the total number of nodes we need to search through over al l the i ter
-
ati ons i s n( n + 1)/ 2, and thus we say that
the precedi ng i mpl ementati on of the LS al gori thm has worst
-

case
compl exi ty of order n squared: O( n2). ( A more sophi sti
-
cated i mpl ementati on of thi s al gori thm, usi ng a data
structure known as a heap, can fi nd the mi ni mum i n l i ne 9 i n l ogari thmi c rather t
han l i near ti me, thus reduc
-
i ng
the compl exi ty.)


Before compl eti ng our di scussion of the LS al gori thm, l et us consi der a pathol
-
ogy that can ari se. Fi gure 4.29 shows
a si mpl e network topol ogy where l i nk costs are equal to the l oad carri ed on the l i nk, fo
r exampl e, refl ecti ng the
del ay that woul d be experi enced. In thi s exampl e, l i nk costs are not symmetri c; that i s, c( u, v) equal s c( v, u) onl y i f
the l oad carri ed on both di recti ons on the l i nk ( u, v) i s the same. In thi s exampl e, node z ori gi nates a un
i t of traffi c
desti ned for w, node x al so ori gi nates a uni t of traffi c desti ned for w, and node y i njects an amount of traffi c equal
to e, al so desti ned for w. The i ni ti al routi ng i s shown i n Fi gure 4.29( a) wi th the l i nk costs cor
-
respondi ng to the
amount

of traffi c carri ed.
















Destination



Link










V


(u, v)










w


(u, x)












x


(u, x)














y


(u, x)











z


(u, x)




























































Figure 4.28 Least cost path and forwarding table for nodule u











V


W


Z


X


Y


U



When the LS al gori thm i s next run, node y determi nes ( based

on the l i nk costs shown i n Fi gure 4.29( a)) that the
cl ockwi se path to w has a cost of 1, whi l e the countercl ockwi se path to w ( whi ch i t had been usi ng) has a cost of 1
+ e. Hence y’s

l east
-

cost l east
-
cost path to w i s now cl ockwi se. Si mi l arl y, x determ
i nes that i ts new l east
-

cost path
to w i s al so cl ockwi se, resul ti ng i n costs shown i n Fi gure 4.29( b). When the LS al gori thm i s run next, nodes x, y, and
z al l detect a zero
-

cost path to w i n the countercl ockwi se di recti on, and al l route thei r traffi c to

the
countercl ockwi se routes. The next ti me the LS al gori thm i s run, x, y, and z al l then route thei r traffi c to the
cl ockwi se routes.


What can be done to prevent such osci l l ati ons ( whi ch can occur i n any al go
-
ri thm, not just an LS al gori thm, that
uses
a congesti on or del ay
-

based l i nk met
-
ri c)? One sol uti on woul d be to mandate that l i nk costs not depend on
the amount of traffi c carri ed


an unacceptabl e sol uti on since one goal of routi ng i s to avoi d hi ghl y congested ( for
exampl e, hi gh
-

del ay) l i nks. Ano
ther sol uti on i s to ensure that not al l routers run the LS al gori thm at the same ti me.
Thi s seems a more reasonabl e sol uti on, si nce we woul d hope that even i f routers ran the LS al gori thm wi th the
same peri odi ci ty, the executi on i nstance of the al gori thm w
oul d not be the same at each node. Interesti ngl y,
researchers have found that routers i n the Internet can sel f
-

synchroni ze among themsel ves [ Fl oyd
Synchroni zati on 1994]. That i s, even though they i ni ti al l y execute the al gori thm wi th the same peri od but a
t
di fferent i nstants of ti me, the al gori thm executi on i nstance can eventual l y become, and remai n, synchroni zed at
the routers. One way to avoi d such sel f
-
synchronizati on i s for each router to randomi ze the ti me i t sends out a l i nk
adverti sement.


Havi ng s
tudi ed the LS al gori thm, l et’s consi der the other major routi ng al go
-
ri thm that i s used i n practi ce today


the di stance
-

vector routi ng al gori thm.