TIPC编程指导.docx
- 文档编号:10574864
- 上传时间:2023-02-21
- 格式:DOCX
- 页数:34
- 大小:31.39KB
TIPC编程指导.docx
《TIPC编程指导.docx》由会员分享,可在线阅读,更多相关《TIPC编程指导.docx(34页珍藏版)》请在冰豆网上搜索。
TIPC编程指导
TIPCProgrammer'sGuide
JonMaloy,April2018
TABLEOFCONTENTS
1.TIPCFUNDAMENTALS
1.1.CLUSTER
1.2.ADDRESSING
1.3.MESSAGING
1.4.SERVICETRACKING
2.SOCKETAPI
2.1.STRUCTURES
2.2.ROUTINES
2.3.EXAMPLES
3.LIBTIPCCAPI
3.1.ADDRESSING
3.2.EXAMPLES
4.GOAPI
4.1.FUNCTIONS
5.TIPSANDTECHNIQUES
5.1.DETERMININGOWNNODE
5.2.CHANGINGSOCKETRECEIVEBUFFER
5.3.WHENTOUSEIMPLIEDCONNECT
5.4.PROCESSINGARETURNEDMESSAGE
Introduction
ThisdocumentisdesignedtoassistsoftwaredeveloperswritingapplicationsthatuseTIPC.IntroductoryinformationabouttheTIPCprotocol,itsmainconcepts,andinstructionsforsettingupandoperatinganodeandaclusterareavailableattheprojectwebsiteathttp:
//www.tipc.io.Tobenefitfromthistext,thereadershouldalsohaveatleastbasicknowledgeaboutcomputernetworkingandbefamiliarwithsocketprogramming.
ItshouldbenotedthatTIPChasundergonesignificantfunctionalchangesandupgradesbetweenLinux3.10,theversionreferredtointhenowsuperseded TIPC2.0documentation,andLinux4.17,theversiononwhichthisdocumentisbased.
Themostimportantofthosechangesare:
∙Anew,workqueuebasedtopologyserver.(IntroducedbyYingXueinLinux3.10.)
∙Anewmanagementtool, tipc,obsoletingtheold tipc-config.(RichardAlpe,Linux3.18.)
∙Introductionofkernelnamespacesupport.(YingXue,Linux3.19.)
∙AbilitytocarryTIPCoverUDP/IPv4orUDP/IPv6bearers.(ErikHugne,Linux4.0.)
∙Amorerobust,performantandscalablemulticastservice.(JonMaloy,Linux4.3.)
∙Abilitytoscaleouttohundredsofnodes,usingthe OverlappingRingMonitoringAlgorithm.(JonMaloy,Linux4.7.)
∙Introductionofamessagebusservicethroughthe CommunicationGroup feature.(JonMaloy,Linux4.14.)
∙Obsoletedthe zone concept,whichwasneverimplementedanyway.(JonMaloy,Linux4.17.)
∙Introducedaflat,128bit nodeidentity,replacingthepreviousstructured32bit nodeaddress.(JonMaloy,Linux4.17.)
∙Makingthenodeidentityautoconfigurable.(JonMaloy,Linux4.17.)
∙ChangedterminologyintheuserAPI,from portname to serviceaddress, portnamesequence to servicerange and portidentity to socketaddress.(JonMaloy,Linux4.17.)
DuringthesameperiodtherehasbeenahugeefforttoimproveTIPCcodequality,regardingreadability,maintainability,robustnessandperformance.Datastructureshavebeensimplifiedanddisentangled,thelockingpolicyhasbeenmuchimproved,andthecodealignedwithcommonLinuxcodingstyleguidelines.
ItshouldbeemphasizedthatthroughallthesechangesgreatcarehasbeentakentoremainbackwardscompatiblewithearlierversionsofTIPC,bothregardingtheprotocolandtheuserAPI.
1. TIPCFUNDAMENTALS
AbriefsummaryofthemajorconceptsusedinTIPCisprovidedinthefollowingsections.
1.1. Cluster
ATIPCnetworkconsistsofindividualprocessingelementsor nodes.Thosenodesarearrangedinto clusters accordingtotheirassigned clusteridentity.Allnodeshavingthesameclusteridentitywillestablishlinkstoeachother,providedthenetworkissetuptoallowmutual neighbordiscovery betweenthem.Itisonlynecessarytochangetheclusteridentityfromitsdefaultvalueifnodesindifferentclusterspotentiallymaydiscovereachother,e.g.,iftheyareattachedtothesamesubnet.NodesindifferentclusterscannotcommunicatewitheachotherusingTIPC.
Eachnodehasa128bit nodeidentity whichmustbeuniquewithinthenode'scluster.Ifthenodewillbepartofacluster,theusercaneitherrelyontheautoconfigurationcapabilityofthenode,wheretheidentityisgeneratedwhenthefirstbearerisattached,orhecansettheidentityexplicitly,e.g.,fromthenode'shostnameoraUUID.Ifanodewillnotbepartofaclusteritsidentitycanremainatthedefaultvalue,zero.
Eachnodeisalsouniquelyidentifiedbya32bit hashnumber.Thisnumberisgeneratedfromthenodeidentity,andisusedinternallybytheprotocolasnodeaddress.Anextensiontotheneighbordiscoveryprotocolguaranteesthatitsvalueisuniquewithinthecluster.Thisnumberishelpfulbothforprotocolperformanceandforbackwardscompatibility.
1.2. Addressing
TheTIPCsocketAPIprovidesthreedifferentaddresstypes:
∙ServiceAddress.Thisaddresstypeconsistsofa32bitservice type identifieranda32bitservice instance identifier.Thetypeidentifieristypicallydeterminedandhardcodedbytheuserapplicationprogrammer,butitsvaluemayhavetobecoordinatedwithotherapplicationswhichmightbepresentinthesamecluster.Theinstanceidentifierisoftencalculatedbytheprogram,basedonapplicationspecificcriteria.
∙ServiceRange.Thisaddresstyperepresentsarangeofserviceaddressesofthesametypeandwithinstancesbetweena lower andan upper rangelimit.Bybindingasockettothisaddresstypeonecanmakeitrepresentmanyinstances,somethingwhichhasprovedusefulinmanycases.Thisaddresstypeisalsousedas multicast address,whichwillbeexplainedinmoredetaillater.
∙SocketAddress.Thisaddressisareferencetoaspecificsocketinthecluster.Itcontainsa32bit portnumber anda32bit nodehashnumber.Theportnumberisgeneratedbythesystemwhenthesocketiscreated,andthenodehashisgeneratedfromthecorrespondingnodeidentityasexplainedearlier.Anaddressofthistypecanbeusedforconnectingorforsendingmessagesinthesamewayasserviceaddressescanbeused,butisonlyvalidaslongaslongasthereferencedsocketexists.
Whenbindingasockettoaserviceaddressoraddressrange,the visibilityscope ofthebindingmustbeindicated.Therearetwooptions, TIPC_NODE_SCOPE iftheuseronlywantsnodelocalvisibility,and TIPC_CLUSTER_SCOPE ifhewantsclusterglobalvisibility.Therearealmostnolimitationstohowsocketscanbeboundtoserviceaddresses:
onesocketcanbeboundtomanyaddressesorranges,andmanysocketscanbeboundtothesameaddressorrange.Theservicetypes0through63arehoweverreservedforsysteminternaluse,andarenotavailableforuserspaceapplications.
Whensendingamessagebyserviceaddressthesendermayindicatea lookupscope,alsocalled lookupdomain.Thisisanodehashnumber,limitingthesetofeligibledestinationsocketstotheindicatednode.Ifthisvalueiszero,allmatchingsocketsinthewholecluster,asvisiblefromthesourcenode,areeligible.
1.3. Messaging
TIPCmessagetransmissioncanbeperformedindifferentways.
1.3.1. DatagramMessaging
Datagrammessagesarediscretedataunitsbetween1and66,000byteoflength,transmittedbetweennon-connectedsocketsoftype SOCK_DGRAM or SOCK_RDM.JustliketheirUDPcounterparts,TIPCdatagramsarenotguaranteedtoreachtheirdestination,buttheirchancesofbeingdeliveredarestillmuchbetterthanfortheformer.Becauseofthe linklayer deliveryguarantee,theonlylimitingfactorfordatagramdeliveryisthesocketreceivebuffersize.Thechancesofsuccesscanalsobeincreasedbythesender,bygivinghissocketanappropriatedelivery importance priority.Therearefoursuch prioritylevels.Thedefaultvalueis TIPC_LOW_IMPORTANCE,butthiscanbechangedviathesocketoption TIPC_IMPORTANCE.
Furthermore,whenthereisreceivebufferoverflow,thesendercanchoosewhetherhejustwantshismessagetobedropped,orifheshouldreceiveanindicationaboutthefailuretodeliver.Inthelattercase,apotentiallytruncated(tothefirst1024bytes)copyoftheoriginalmessageisreturnedtothesender,alongwiththeerrorcode TIPC_ERR_OVERLOAD.Thismechanismalsoworksforothertypesofdeliveryfailure,soausermayevenencountertheerrorcodes TIPC_ERR_NO_NODE and TIPC_ERR_NO_PORT.Thesenderreadstheerrorcodeandandreturnedbytesas ancillarydata fromthesocket.Thedefaultsettingforthispropertyis off,butitcanbeenabledviathesocketoption TIPC_DEST_DROPPABLE.
Datagrammessagescanbesenteitherbysocketaddress,serviceaddressor multicastaddress.
∙Ifasocketaddressisindicatedthemessageistransmittedtothatexactsocket.
∙Whenaserviceaddressisused,theremightbeseveralmatchingdestinations,andthetransmissionmethodbecomeswhatisoftendenoted anycast,i.e.,thatanyofthematchingdestinationsmaybeselected.Whenthisisthecase,thefunctiontranslatingfromserviceaddresstosocketaddressusesa round-robin algorithmtodecreasetheriskofloadbiasamongthedestinations.Itshouldhoweverbenotedthatthisalgorithmisnodeglobal,sounlessasenderisaloneonthenodetousethisaddresshehasnoguaranteethathisparticularmessageswillbeevenlydistributedamongthedestinations.
∙Theaddresstypeservicerangealsodoublesas multicastaddress.Whenanapplicationspecifiesaservicerangeasdestinationaddress,itdoeseffectivelyinstructTIPCtosendacopyofthemessagetoallmatchingsocketsinthecluster.Anysocketboundtooneormoreinstancesinsidetheindicatedmulticastrangewillreceiveexactlyonecopyofthemessage,-nevermore.Multicastdatagrammessagingdifferfromtheunicast/anycastdittoinonerespect,-thelookupscopeisalwaysclusterglobal,andcannotbechanged.
Theriskofmessagerejectioncanbereducedby increasing thereceivebuffersizefromthedefaultvalue.
Datagrammessagessentbyserviceaddressmaybesubjecttoanothermechanismintendedtoreducetheriskofdeliveryfailure.Becauseofthetransaction-freeandnon-atomicnatureofbindingtableupdates,aprimaryaddresslo
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- TIPC 编程 指导