Computer Network Unit IV - Lecture Notes - Network Layer

Murugan146644 1,277 views 51 slides Mar 09, 2025
Slide 1
Slide 1 of 51
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51

About This Presentation

Title:
Lecture Notes - Unit IV - The Network Layer
Description:
Welcome to the comprehensive guide on Computer Network concepts, tailored for final year B.Sc. Computer Science students affiliated with Alagappa University. This document covers fundamental principles and advanced topics in Computer N...


Slide Content

Unit IV -The Network Layer
Dr. S.Murugan
Associate Professor, Department of Computer Science.
AlagappaGovernment Arts College,
(Affiliated by AlagappaUniversity)
Karaikudi.
Email: [email protected]

This slides compiled from
Computer Network by
Andrew S. Tenenbaum4
th
Ed.

The Network Layer
➢Thenetworklayerisconcernedwithgettingpackets
fromthesourceallthewaytothedestination.
➢Toachieveitsgoals,thenetworklayermustknow
aboutthetopologyofthecommunicationsubnet(i.e.,
thesetofallrouters)andchooseappropriatepaths
throughit.

5.1 Network Layer Design Issues
5.1.1Store-and-ForwardPacketSwitching
➢Theenvironmentofthenetworklayerprotocolis
representedinthefigure5.1.

5.1.1 Store-and-Forward Packet Switching
➢Ahostwithapackettosendtransmitsittothenearest
router,eitheronitsownLANoroverapoint-to-point
linktothecarrier.
➢Thepacketisstoredthereuntilithasfullyarrivedso
thechecksumcanbeverified.
➢Thenitisforwardedtothenextrouteralongthepath
untilitreachesthedestinationhost,whereitis
delivered.
➢Thismechanismisstore-and-forwardpacket
switching.

5.1.2 Services Provided to the Transport Layer
➢Thenetworklayerprovidesservicestothetransport
layeratthenetworklayer/transportlayerinterface.
Thenetworklayerserviceshavebeendesignedwith
thefollowinggoalsinmind.
1.Theservicesshouldbeindependentoftherouter
technology.
2.Thetransportlayershouldbeshieldedfromthe
number,type,andtopologyoftherouterspresent.
3.Thenetworkaddressesmadeavailabletothe
transportlayershoulduseauniformnumbering
plan,evenacrossLANsandWANs.

5.1.3 Implementation of Connectionless Service
➢Ifconnectionlessserviceisoffered,packetsare
injectedintothesubnetindividuallyandrouted
independentlyofeachother.Noadvancesetupis
needed.
➢Inthiscontext,thepacketsarefrequentlycalled
datagrams(inanalogywithtelegrams)andthesubnet
iscalledadatagramsubnet.
➢Ifconnection-orientedserviceisused,apathfromthe
sourceroutertothedestinationroutermustbe
establishedbeforeanydatapacketscanbesent.

5.1.3 Implementation of Connectionless Service
➢ThisconnectioniscalledaVC(virtualcircuit),in
analogywiththephysicalcircuitssetupbythe
telephonesystem,andthesubnetiscalledavirtual-
circuitsubnet.
➢Figure5.2showstheroutingwiththedatagram
subnet.ThemessageMistransferfromHost1to
Host2.
➢Thenetworklayerhastobreakthemessagesintofour
packets,1,2,3,and4andsendseachoftheminturn
torouterAusingsomepoint-to-pointprotocol,for
example,PPP.

5.1.3 Implementation of Connectionless Service
➢Atthispointthecarriertakesover.Everyrouterhasan
internaltabletellingitwheretosendpacketsforeach
possibledestination.
➢Eachtableentryisapairconsistingofadestination
andtheoutgoinglinetouseforthatdestination.
➢Onlydirectly-connectedlinescanbeused.

5.1.3 Implementation of Connectionless Service

5.1.3 Implementation of Connectionless Service
➢Forexample,inFig.5-2,Ahasonlytwooutgoing
linestoBandC.soeveryincomingpacketmustbe
senttooneoftheserouters,eveniftheultimate
destinationissomeotherrouter.A'sinitialrouting
tableisshowninthefigureunderthelabel''initially.''

➢AstheyarrivedatA,packets1,2,and3werestored.
TheneachwasforwardedtoCaccordingtoA'stable.
➢Packet1wasthenforwardedtoEandthentoF.
WhenitgottoF,itwasencapsulatedinadatalink
layerframeandsenttoH2overtheLAN.Packets2
and3followthesameroute.

5.1.3 Implementation of Connectionless Service
➢However,somethingdifferenthappenedtopacket4.
WhenitgottoAitwassenttorouterB,eventhoughit
isalsodestinedforF.
➢Forsomereason,Adecidedtosendpacket4viaa
differentroutethanthatofthefirstthree.
➢Perhapsitlearnedofatrafficjamsomewherealong
theACEpathandupdateditsroutingtable,asshown
underthelabel''later.''
➢Thealgorithmthatmanagesthetablesandmakesthe
routingdecisionsiscalledtheroutingalgorithm.

5.1.4 Implementation of Connection-Oriented
Service
➢Forconnection-orientedservice,weneedavirtual-
circuitsubnet.virtualcircuitsistoavoidhavingto
chooseanewrouteforeverypacketsent,asinFig.5-2.
➢Withconnection-orientedservice,eachpacketcarries
anidentifiertellingwhichvirtualcircuititbelongsto.
➢Asanexample,considerthesituationofFig.5-3.

5.1.4 Implementation of Connection-Oriented
Service

5.1.4 Implementation of Connection-Oriented
Service
➢Here,hostH1hasestablishedconnection1withhost
H2.Itisrememberedasthefirstentryineachofthe
routingtables.ThefirstlineofA'stablesaysthatifa
packetbearingconnectionidentifier1comesinfrom
H1,itistobesenttorouterCandgivenconnection
identifier1.Similarly,thefirstentryatCroutesthe
packettoE,alsowithconnectionidentifier1.
➢NowletusconsiderwhathappensifH3alsowantsto
establishaconnectiontoH2.

5.1.4 Implementation of Connection-Oriented
Service
➢Itchoosesconnectionidentifier1(becauseitisinitiating
theconnectionandthisisitsonlyconnection)andtells
thesubnettoestablishthevirtualcircuit.Thisleadstothe
secondrowinthetables.Notethatwehaveaconflict
herebecausealthoughAcaneasilydistinguish
connection1packetsfromH1fromconnection1packets
fromH3,Ccannotdothis.
➢Forthisreason,Aassignsadifferentconnection
identifiertotheoutgoingtrafficforthesecond
connection.Avoidingconflictsofthiskindiswhyrouters
needtheabilitytoreplaceconnectionidentifiersin
outgoingpackets.Insomecontexts,thisiscalledlabel
switching.

5.1.5 Comparison of Virtual-Circuit and Datagram
Subnets

5.2 Routing Algorithms
➢Themainfunctionofthenetworklayerisroutingpackets
fromthesourcemachinetothedestinationmachine.In
mostsubnets,packetswillrequiremultiplehopstomake
thejourney.
➢Theroutingalgorithmisthatpartofthenetworklayer
softwareresponsiblefordecidingwhichoutputlinean
incomingpacketshouldbetransmittedon.
➢Ifthesubnetusesdatagramsinternally,Forevery
arrivingpacketisroutedindependently.Whenvirtual
circuitisestablishedallpacketsarefollowsthesame
route.Thedatapacketsjustfollowthepreviously-
establishedrouteiscalledsessionrouting.

5.2 Routing Algorithms
➢Thedesirablepropertiesofaroutingalgorithm:
correctness,simplicity,robustness,stability,fairness,and
optimality.
➢Therobustnessmaybeexpectedtoruncontinuouslyfor
yearswithoutsystemwidefailures.Duringthatperiod
therewillbehardwareandsoftwarefailuresofallkinds.

➢Routingalgorithmscanbegroupedintotwomajor
classes:nonadaptiveandadaptive.
➢Innon-adaptiverouting,thechoiceoftherouteis
calculatedinadvance.Thistypeofroutingprocedureis
calledstaticrouting.

5.2 Routing Algorithms
➢Inadaptiveroutingthechoiceoftherouteisnot
calculatedinadvance.Thistypeofroutingprocedureis
calleddynamicrouting.

➢Thesetofoptimalroutesfromallsourcestoagiven
destinationformatreerootedatthedestination.Sucha
treeiscalledasinktreeandisillustratedinFig.5-6,
wherethedistancemetricisthenumberofhops.
➢Thegoalofallroutingalgorithmsistodiscoveranduse
thesinktreesforallrouters.
➢Asinktreeisindeedatree,itdoesnotcontainanyloops,
soeachpacketwillbedeliveredwithinafiniteand
boundednumberofhops.

5.2 Routing Algorithms
Figure 5-6. (a) A subnet. (b) A sink tree for router B.

5.2.2 Shortest Path Routing
➢Theideaistobuildagraphofthesubnet,witheachnode
ofthegraphrepresentingarouterandeacharcofthe
graphrepresentingacommunicationline(oftencalleda
link).
➢Tochoosearoutebetweenagivenpairofrouters,the
algorithmjustfindstheshortestpathbetweenthemon
thegraph.
➢Onewayofmeasuringpathlengthisthenumberofhops.
Usingthismetric,thepathsABCandABEinFig.5-7are
equallylong.Anothermetricisthegeographicdistance
inkilometers,inwhichcaseABCisclearlymuchlonger
thanABE(assumingthefigureisdrawntoscale).

5.2.2 Shortest Path Routing
Figure 5-7. The first five steps used in computing the shortest path from A to D.
The arrows indicate the working node.

5.2.2 Shortest Path Routing
Possible Path 1 : ABCD : 2+7+3=12
Possible path 2 : ABEFCD: 2+2+2+3+3=12
Possible path3 : ABEFHD : 2+2+2+2+2=10 -→
Shortest Path
Shortest Path : ABEGHD: 2+2+1+4+2=11

5.2.2 Shortest Path Routing
➢Severalalgorithmsforcomputingtheshortestpath
betweentwonodesofagraphareknown.Thisoneis
duetoDijkstra(1959).Eachnodeislabeled(in
parentheses)withitsdistancefromthesourcenode
alongthebestknownpath.
➢Initially,nopathsareknown,soallnodesarelabeled
withinfinity.Asthealgorithmproceedsandpathsare
found,thelabelsmaychange,reflectingbetterpaths.
Alabelmaybeeithertentativeorpermanent.Initially,
alllabelsaretentative.Whenitisdiscoveredthata
labelrepresentstheshortestpossiblepathfromthe
sourcetothatnode,itismadepermanentandnever
changedthereafter.

5.2.2 Shortest Path Routing
➢Toillustratehowthelabelingalgorithmworks,lookat
theweighted,undirectedgraphofFig.5-7(a),where
theweightsrepresent,forexample,distance.Wewant
tofindtheshortestpathfromAtoD.
➢WestartoutbymarkingnodeAaspermanent,
indicatedbyafilled-incircle.Thenweexamine,in
turn,eachofthenodesadjacenttoA(theworking
node),relabelingeachonewiththedistancetoA.
➢Wheneveranodeisrelabeled,wealsolabelitwith
thenodefromwhichtheprobewasmadesothatwe
canreconstructthefinalpathlater.

5.2.2 Shortest Path Routing
➢HavingexaminedeachofthenodesadjacenttoA,we
examineallthetentativelylabelednodesinthewhole
graphandmaketheonewiththesmallestlabel
permanent,asshowninFig.5-7(b).
➢Thisonebecomesthenewworkingnode.Wenow
startatBandexamineallnodesadjacenttoit.
➢IfthesumofthelabelonBandthedistancefromBto
thenodebeingconsideredislessthanthelabelonthat
node,wehaveashorterpath,sothenodeisrelabeled.

5.2.3 Flooding
1.Identifythenumberofhop(Jump)fromsourceto
destination.
2.Initialisethecountervalue
3.Decreasethecountervalueateachhopreaches
4.Stoptheprocesswhencounterreachestozero.

5.2.4 Distance Vector Routing
➢Moderncomputernetworksgenerallyusedynamic
routingalgorithms.Twodynamicalgorithms,in
particular,distancevectorroutingandlinkstate
routing,arethemostpopular.
➢Indistancevectorrouting,eachroutermaintainsa
routingtableindexedby,andcontainingoneentryfor,
eachrouterinthesubnet.
➢Thisentrycontainstwoparts:thepreferredoutgoing
linetouseforthatdestinationandanestimateofthe
timeordistancetothatdestination.Themetricused
mightbenumberofhops,thetimedelayin
milliseconds,totalnumberofpacketsqueuedalong
thepath,orsomethingsimilar.

5.2.4 Distance Vector Routing
➢Therouterisassumedtoknowthe''distance''toeach
ofitsneighbors.Ifthemetricishops,thedistanceis
justonehop.Ifthemetricisqueuelength,therouter
simplyexamineseachqueue.Ifthemetricisdelay,the
routercanmeasureitbytimedelay.
➢Byusingthebellmanfordcalculationforeach
neighbor,aroutercanfindoutwhichestimateseems
thebestandusethatestimateandthecorresponding
lineinitsnewroutingtable.
➢TheupdatingprocessisillustratedinFig.5-9.Part(a)
showsasubnet.TheFig5-9determinesthenext
estimateddelayfromJ.Thefirstfourcolumnsofpart
(b)showthedelayvectorsreceivedfromthe
neighborsofrouterJ.

5.2.4 Distance Vector Routing

5.2.4 Distance Vector Routing

5.2.4 Distance Vector Routing
ConsiderhowJcomputesitsnewroutetorouterG.
Step1:DistancevectorfromAtoremainingrouterB.C,D,…LviaJ
(i.e,routerAtorouterBviaJ=12msec,routerAtorouterCviaJ=25,
etc.representedasBlackbold)
Step2:Forexample,Jhasmeasuredorestimateditsdelaytoits
neighbors,A,I,H,andKas8,10,12,and6msec,respectively.
Step3:DeterminetheshortestpathfromGtoA,I,HandKvia
routerJ.
DelayforGtoA=JADelaytime+GADelaytime➔8+18=26;
DelayforGtoA=JIDelaytime+GIDelaytime➔31+10=41;
DelayforGtoA=JHDelaytime+GHDelaytime➔6+12=18;
DelayforGtoA=JKDelaytime+GKDelaytime➔31+6=37;
Step4:Thebestofthesevaluesis18,soitmakesanentryinits
routingtablethatthedelaytoGis18msecandthattheroutetouse
isviaH.
Thesamecalculationisperformedforalltheotherdestinations,with
thenewroutingtableshowninthelastcolumnofthefigure.

5.2.5 Link State Routing
➢The idea behind link state routing is simple and can be
stated as five parts. Each router must do the following:
1.Discoveritsneighborsandlearntheirnetworkaddresses.
2.Measurethedelayorcosttoeachofitsneighbors.
3.Constructapacket,tellingallithasjustlearned.
4.Sendthispackettoallotherrouters.
5.Computetheshortestpathtoeveryotherrouter.

5.2.5 Link State Routing
LearningabouttheNeighbors
➢Whenarouterisbooted,itsfirsttaskistolearnwhoits
neighborsare.Itaccomplishesthisgoalbysendinga
specialHELLOpacketoneachpoint-to-pointline.The
routerontheotherendisexpectedtosendbackareply
tellingwhoitis.
➢WhentwoormoreroutersareconnectedbyaLAN,the
situationisslightlymorecomplicated.Fig.5-11(a)
illustratesaLANtowhichthreerouters,A,C,andF,
aredirectlyconnected.Eachoftheseroutersis
connectedtooneormoreadditionalrouters,asshown.

5.2.5 Link State Routing
➢OnewaytomodeltheLANistoconsideritasanode
itself,asshowninFig.5-11(b).
➢Hereintroducedanew,artificialnode,N,towhichA,
C,andFareconnected.Thefactthatitispossibleto
gofromAtoContheLANisrepresentedbythepath
ANChere.

5.2.5 Link State Routing
MeasuringLineCost
➢Thelinkstateroutingalgorithmrequireseachrouterto
know,oratleasthaveareasonableestimateof,the
delaytoeachofitsneighbors.
➢Themostdirectwaytodeterminethisdelayistosend
overthelineaspecialECHOpacketthattheotherside
isrequiredtosendbackimmediately.
➢Unfortunately,thereisanargumentagainstincluding
theloadinthedelaycalculation.Considerthesubnetof
Fig.5-12,whichisdividedintotwoparts,Eastand
West,connectedbytwolines,CFandEI.

5.2.5 Link State Routing
➢SupposethatmostofthetrafficbetweenEastandWest
isusinglineCF,andasaresult,thislineisheavily
loadedwithlongdelays.Includingqueueingdelayin
theshortestpathcalculationwillmakeEImore
attractive.
➢Afterthenewroutingtableshavebeeninstalled,most
oftheEast-WesttrafficwillnowgooverEI,
overloadingthisline.Consequently,inthenextupdate,
CFwillappeartobetheshortestpath.Asaresult,the
routingtablesmayoscillatewildly,leadingtoerratic
routingandmanypotentialproblems.

5.2.5 Link State Routing

5.2.5 Link State Routing
Building Link State Packets
➢Oncetheinformationneededfortheexchangehasbeen
collected,thenextstepisforeachroutertobuilda
packetcontainingallthedata.Thepacketstartswiththe
identityofthesender,followedbyasequencenumber
andage(tobedescribedlater),andalistofneighbors.
➢Foreachneighbor,thedelaytothatneighborisgiven.
AnexamplesubnetisgiveninFig.5-13(a)withdelays
shownaslabelsonthelines.Thecorrespondinglink
statepacketsforallsixroutersareshowninFig.5-
13(b).

5.2.5 Link State Routing
Building Link State Packets
➢Oncetheinformationneededfortheexchangehasbeen
collected,thenextstepisforeachroutertobuilda
packetcontainingallthedata.Thepacketstartswiththe
identityofthesender,followedbyasequencenumber
andage(tobedescribedlater),andalistofneighbors.
➢Foreachneighbor,thedelaytothatneighborisgiven.
AnexamplesubnetisgiveninFig.5-13(a)withdelays
shownaslabelsonthelines.Thecorrespondinglink
statepacketsforallsixroutersareshowninFig.5-
13(b).

5.2.5 Link State Routing

5.2.5 Link State Routing
➢Thefundamentalideaistousefloodingtodistributethe
linkstatepackets.Tokeepthefloodincheck,each
packetcontainsasequencenumberthatisincremented
foreachnewpacketsent.Whenanewlinkstatepacket
comesin,itischeckedagainstthelistofpacketsalready
seen.Ifitisnew,itisforwardedonalllinesexceptthe
oneitarrivedon.Ifitisaduplicate,itisdiscarded.
➢Thesolutiontoroutercrashorsequencenumberlossis
toincludetheageofeachpacketafterthesequence
numberanddecrementitoncepersecond.Whentheage
hitszero,theinformationfromthatrouterisdiscarded.

5.2.5 Link State Routing
➢ThedatastructureusedbyrouterBforthesubnet
showninFig.5-13(a)isdepictedinFig.5-14.Eachrow
herecorrespondstoarecently-arrived,butasyetnot
fully-processed,linkstatepacket.
➢Thetablerecordswherethepacketoriginated,its
sequencenumberandage,andthedata.Inaddition,
therearesendandacknowledgementflagsforeachof
B'sthreelines(toA,C,andF,respectively).
➢Thesendflagsmeanthatthepacketmustbesentonthe
indicatedline.Theacknowledgementflagsmeanthatit
mustbeacknowledgedthere.

5.2.5 Link State Routing

5.2.5 Link State Routing
ComputingtheNewRoutes
Oncearouterhasaccumulatedafullsetoflinkstate
packets,itcanconstructtheentiresubnetgraphbecause
everylinkisrepresented.Everylinkis,infact,represented
twice,onceforeachdirection.Thetwovaluescanbe
averagedorusedseparately.

5.2.6 Hierarchical Routing
➢Whenhierarchicalroutingisused,theroutersare
dividedintowhatwewillcallregions,witheachrouter
knowingallthedetailsabouthowtoroutepacketsto
destinationswithinitsownregion.
➢Figure5-15givesaquantitativeexampleofroutingina
two-levelhierarchywithfiveregions.
➢Thefullroutingtableforrouter1Ahas17entries,as
showninFig.5-15(b).

5.2.6 Hierarchical Routing
➢Whenroutingisdonehierarchically,asinFig.5-15(c),
thereareentriesforallthelocalroutersasbefore,but
allotherregionshavebeencondensedintoasingle
router,soalltrafficforregion2goesviathe1B-2A
line,buttherestoftheremotetrafficgoesviathe1C-
3Bline.
➢Hierarchicalroutinghasreducedthetablefrom17to7
entries.Astheratioofthenumberofregionstothe
numberofroutersperregiongrows,thesavingsintable
spaceincrease.

5.2.6 Hierarchical Routing
➢Fulltablefor1AisderivedfromFig.5.15a.InFig5.15a,
Region1has2lines1Band1C.Byusingthesetwolines,
thepacketcantranvelfromoneregiontoanotherregion.

5.2.7 Broadcast Routing
➢Insomeapplications,hostsneedtosendmessages
tomanyorallotherhosts.
➢Sendingapackettoalldestinationssimultaneously
iscalledbroadcasting.
➢Forexample,aservicedistributingweather
reports,stockmarketupdates,orliveradio
programsmightworkbestbybroadcastingtoall
machines.

5.2.8 Multicast Routing
➢Someapplicationsrequirethatwidely-separated
processesworktogetheringroups,forexample,a
groupofprocessesimplementingadistributed
databasesystem.
➢Sendingamessagetosuchagroupiscalled
multicasting,anditsroutingalgorithmiscalled
multicastrouting.