Linux Network Traffic ControlImplementation OverviewWord下载.docx
《Linux Network Traffic ControlImplementation OverviewWord下载.docx》由会员分享,可在线阅读,更多相关《Linux Network Traffic ControlImplementation OverviewWord下载.docx(19页珍藏版)》请在冰豆网上搜索。
![Linux Network Traffic ControlImplementation OverviewWord下载.docx](https://file1.bdocx.com/fileroot1/2022-12/13/7c9d456c-cd8b-492f-8a60-19ce82bb64d2/7c9d456c-cd8b-492f-8a60-19ce82bb64d21.gif)
intserv"
group[2],andwillserveasthebasisforsupportingthemorerecentworkof"
diffserv"
[3].Seealso[4]forfurtherdetailsonhowintservanddiffservarerelated.ThisdocumentillustratestheunderlyingarchitectureanddescribeshownewtrafficcontrolfunctionscanbeaddedtotheLinuxkernel.Thekernelversionweusedis2.2.6.
Figure1showsroughlyhowthekernelprocessesdatareceivedfromthenetwork,andhowitgeneratesnewdatatobesentonthenetwork:
incomingpacketsareexaminedandtheneitherdirectlyforwardedtothenetwork(e.g.onadifferentinterface,ifthemachineisactingasarouterorabridge),ortheyarepasseduptohigherlayersintheprotocolstack(e.g.toatransportprotocollikeUDPorTCP)forfurtherprocessing.Thosehigherlayersmayalsogeneratedataontheirownandhandittothelowerlayersfortaskslikeencapsulation,routing,andeventuallytransmission.
"
Forwarding"
includestheselectionoftheoutputinterface,theselectionofthenexthop,encapsulation,etc.Onceallthisisdone,packetsarequeuedontherespectiveoutputinterface.Thisisthepointwheretrafficcontrolcomesintoplay.Trafficcontrolcan,amongotherthings,decideifpacketsarequeuedoriftheyaredropped(e.g.ifthequeuehasreachedsomelengthlimit,orifthetrafficexceedssomeratelimit),itcandecideinwhichorderpacketsaresent(e.g.togiveprioritytocertainflows),itcandelaythesendingofpackets(e.g.tolimittherateofoutboundtraffic),etc.
Oncetrafficcontrolhasreleasedapacketforsending,thedevicedriverpicksitupandemitsitonthenetwork.
Sections2to4giveanoverviewandexplainsometerminology.Sections5to8describetheelementsoftrafficcontrolintheLinuxkernelinmoredetail.Section9describesaqueuingdisciplinethathasbeenimplementedbytheauthor.
2Overview
ThetrafficcontrolcodeintheLinuxkernelconsistsofthefollowingmajorconceptualcomponents:
●queuingdisciplines
●classes(withinaqueuingdiscipline)
●filters
●policing
Figure1:
Processingofnetworkdata.
Eachnetworkdevicehasaqueuingdisciplineassociatedwithit,whichcontrolshowpacketsenqueuedonthatdevicearetreated.Averysimplequeuingdisciplinemayjustconsistofasinglequeue,whereallpacketsarestoredintheorderinwhichtheyhavebeenenqueued,andwhichisemptiedasfastastherespectivedevicecansend.Seefigure2forsuchaqueuingdisciplinewithoutexternallyvisibleinternalstructure.
Figure2:
Asimplequeuingdisciplinewithoutclasses.
Moreelaboratequeuingdisciplinesmayusefilterstodistinguishamongdifferentclassesofpacketsandprocesseachclassinaspecificway,e.g.bygivingoneclasspriorityoverotherclasses.
Figure3showsanexampleofsuchaqueuingdiscipline.Notethatmultiplefiltersmaymaptothesameclass.
Queuingdisciplinesandclassesareintimatelytiedtogether:
thepresenceofclassesandtheirsemanticsarefundamentalpropertiesofthequeuingdiscipline.Incontrasttothat,filterscanbecombinedarbitrarilywithqueuingdisciplinesandclassesaslongasthequeuingdisciplinehasclassesatall.Butflexibilitydoesn'
tendyet-classesnormallydon'
ttakecareofstoringtheirpacketsthemselves,buttheyuseanotherqueuingdisciplinetotakecareofthat.Thatqueuingdisciplinecanbearbitrarilychosenfromthesetofavailablequeuingdisciplines,anditmaywellhaveclasses,whichinturnusequeuingdisciplines,etc.
Figure4showsanexampleofsuchastack:
first,thereisaqueuingdisciplinewithtwodelaypriorities.Packetswhichareselectedbythefiltergotothehigh-priorityclass,whileallotherpacketsgotothelow-priorityclass.Whenevertherearepacketsinthehigh-priorityqueue,theyaresentbeforepacketsinthelow-priorityqueue(e.g.thesch_prioqueuingdisciplineworksthisway).Inordertopreventhigh-prioritytrafficfromstarvinglow-prioritytraffic,weuseatokenbucketfilter(TBF),whichenforcesarateofatmost1Mbps.Finally,thequeuingoflow-prioritypacketsisdonebyaFIFOqueuingdiscipline.Notethattherearebetterwaystoaccomplishwhatwe'
vedonehere,e.g.byusingclass-basedqueuing(CBQ)[5].
Packetsareenqueuedasfollows:
whentheenqueuedfunctionofaqueuingdisciplineiscalled,itrunsonefilteraftertheotheruntiloneofthemindicatesamatch.Itthenqueuesthepacketforthecorrespondingclass,whichusuallymeanstoinvoketheenqueuedfunctionofthequeuingdiscipline"
owned"
bythatclass.Packetswhichdonotmatchanyofthefiltersaretypicallyattributedtosomedefaultclass.
Typically,eachclass"
owns"
onequeue,butitisinprinciplealsopossiblethatseveralclassessharethesamequeueoreventhatasinglequeueisusedbyallclassesoftherespectivequeuingdiscipline.Notehoweverthatpacketsdonotcarryanyexplicitindicationofwhichclasstheywereattributedto.Queuingdisciplinesthatchangeper-classinformationwhendequeuingpackets(e.g.CBQ)maythereforenotworkproperlyifthe"
inner"
queuesareshared,unlesstheyareableeithertorepeattheclassificationortopasstheclassificationresultfromenqueuedtodequeuebysomeothermeans.
Usuallywhenenqueuingpackets,thecorrespondingflow(s)canbepoliced,e.g.bydiscardingpacketswhichexceedacertainrate.
Wewillnottrytointroducenewterminologytodistinguishamongalgorithms,theirimplementations,andinstancesofsuchelements,butratherusethetermsqueuingdiscipline,class,andfilterthrough-outmostofthisdocument,torefertoallthreelevelsofabstractionatthesametime.
3Resources
Linuxtrafficcontrolisspreadoveracomparablylargenumberoffiles.Notethatallpathnamesarerelativetothebasedirectoryoftherespectivecomponent,Filtere.g.fortheLinuxkernelthisis/usr/src/linux/,forthetcprogramiproute2/tc/.
Figure3:
Asimplequeuingdisciplinewithmultipleclasses.
Figure4:
Combinationofpriority,TBF,andFIFOqueuingdisciplines.
Tcisauser-spaceprogramusedtomanipulateindividualtrafficcontrolelements.Itssourceisinthefileiproute2-version.tar.gz,whichcanbeobtainedfromftp:
//linux.wauug.org/pub/net/ip-routing/.
Thekernelcoderesidesmainlyinthedirectorynet/sched/.Theinterfacesbetweenkerneltrafficcontrolelementsanduserspaceprogramsusingthemaredeclaredininclude/linux/pkt_cls.handinclude/linux/pkt_sched.h.Declarationsusedonlyinsidethekernelandthedefinitionsofsomeinlinefunctionscanbefoundininclude/net/pkt_cls.handinclude/net/pkt_sched.h.
Thertnetlinkmechanismusedforcommunicationbetweentrafficcontrolelementsinuser-spaceandinthekernelisimplementedinnet/core/rtnetlink.candinclude/linux/rtnetlink.h.rtnetlinkisbasedonnetlink,whichcanbefoundinnet/netlink/andinclude/linux/netlink.h.
Thekernelsourcecanbeobtainedfromtheusualwell-knownplaces,e.g.fromftp:
//ftp.kernel.org/pub/linux/kernel/v2.2/.
Theexampleinsection9isincludedintheATMonLinuxdistribution,whichcanbedownloadedfromhttp:
//icawww1.epfl.ch/linux-atm/dist.html.
TheDifferentiatedServicesonLinuxproject(http:
//icawww1.epfl.ch/linux-diffserv/)hasproducedfurtherexamplesforextensionsofLinuxtrafficcontrolandtheiruse.
4Terminology
Unfortunately,theterminologyusedtodescribetrafficcontrolelementsisfarfromconsistentinliterature,andtherearesomevariationsevenwithinLinuxtrafficcontrol.Thepurposeofthissectionistohelptoputthingsintocontext.
Figure5showsthearchitecturalmodelsandtheterminologyusedintheIETFgroups"
[6]and"
[7,8],andhowelementsofLinuxtrafficcontrolarerelatedtothem.Notethatclassesplayanambivalentrole,becausetheydeterminethefinaloutcomeofaclassificationandtheycanalsobepartofthemechanismthatimplementsacertainqueuingorschedulingbehavior.
Table1summarizesthekeywordsusedatthetccommandline,thefilenamesusedinthekernel(innet/sched/),andthefilenamesusedinthesourceoftc.
Figure5:
RelationofelementsoftheintservanddiffservarchitecturetotrafficcontrolintheLinuxkernel.
Table1:
Keywordsandfilenamesusedfortrafficcontrolelements.
5Queuingdisciplines
Eachqueuingdisciplineprovidesthefollowingsetoffunctionstocontrolitsoperation(seestructQdisc_opsininclude/net/pkt_sched.h):
enqueueenqueuesapacketwiththequeuingdiscipline.Ifthequeuingdisciplinehasclasses,theenqueuedfunctionfirstselectsaclassandtheninvokestheenqueuefunctionofthecorrespondingqueuingdisciplineforfurtherenqueuing.
dequeuereturnsthenextpacketeligibleforsending.Ifthequeuingdisciplinehasnopacketstosend(e.g.becausethequeueisemptyorbecausethey'
renotscheduledtobesentyet),dequeuereturnsNULL.
requeueputsapacketbackintothequeueafterdequeuingitwithdequeue.Thisdiffersfromenqueueinthatthepacketshouldbequeuedate