amf.c 144 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712
  1. int waiting = 0;
  2. /*
  3. * Copyright (c) 2002-2005 MontaVista Software, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@mvista.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <sys/types.h>
  36. #include <sys/uio.h>
  37. #include <sys/socket.h>
  38. #include <sys/un.h>
  39. #include <sys/types.h>
  40. #include <sys/wait.h>
  41. #include <netinet/in.h>
  42. #include <arpa/inet.h>
  43. #include <unistd.h>
  44. #include <fcntl.h>
  45. #include <stdlib.h>
  46. #include <stdio.h>
  47. #include <errno.h>
  48. #include <signal.h>
  49. #include <string.h>
  50. #include <pthread.h>
  51. #include <assert.h>
  52. #include "../include/saAis.h"
  53. #include "../include/saAmf.h"
  54. #include "../include/ipc_gen.h"
  55. #include "../include/ipc_amf.h"
  56. #include "../include/list.h"
  57. #include "../include/queue.h"
  58. #include "totempg.h"
  59. #include "aispoll.h"
  60. #include "mempool.h"
  61. #include "util.h"
  62. #include "amfconfig.h"
  63. #include "main.h"
  64. #include "handlers.h"
  65. #define LOG_SERVICE LOG_SERVICE_AMF
  66. #include "print.h"
  67. #define LOG_LEVEL_FROM_LIB LOG_LEVEL_DEBUG
  68. #define LOG_LEVEL_FROM_GMI LOG_LEVEL_DEBUG
  69. #define LOG_LEVEL_ENTER_FUNC LOG_LEVEL_DEBUG
  70. struct invocation {
  71. void *data;
  72. int interface;
  73. int active;
  74. };
  75. struct invocation *invocation_entries = 0;
  76. int invocation_entries_size = 0;
  77. enum amf_response_interfaces {
  78. AMF_RESPONSE_HEALTHCHECKCALLBACK = 1,
  79. AMF_RESPONSE_CSISETCALLBACK = 2,
  80. AMF_RESPONSE_CSIREMOVECALLBACK = 3,
  81. AMF_RESPONSE_COMPONENTTERMINATECALLBACK = 4
  82. };
  83. struct csi_set_callback_data {
  84. struct amf_comp *comp;
  85. struct amf_csi *csi;
  86. struct amf_pg *pg;
  87. };
  88. struct csi_remove_callback_data {
  89. struct amf_csi *csi;
  90. };
  91. struct component_terminate_callback_data {
  92. struct amf_comp *comp;
  93. };
  94. struct healthcheck_active {
  95. SaAmfHealthcheckKeyT key;
  96. SaAmfHealthcheckInvocationT invocationType;
  97. SaAmfRecommendedRecoveryT recommendedRecovery;
  98. struct amf_comp *comp;
  99. struct amf_healthcheck *healthcheck;
  100. poll_timer_handle timer_healthcheck_duration;
  101. poll_timer_handle timer_healthcheck_period;
  102. struct list_head list;
  103. int active;
  104. };
  105. static char *presencestate_ntoa (OpenaisCfgPresenceStateT state);
  106. static char *operationalstate_ntoa (OpenaisCfgOperationalStateT state);
  107. static char *hastate_ntoa (SaAmfHAStateT state);
  108. static char *readinessstate_ntoa (int state);
  109. static int amf_confchg_fn (
  110. enum totem_configuration_type configuration_type,
  111. struct totem_ip_address *member_list, int member_list_entries,
  112. struct totem_ip_address *left_list, int left_list_entries,
  113. struct totem_ip_address *joined_list, int joined_list_entries,
  114. struct memb_ring_id *ring_id);
  115. static int amf_exit_fn (struct conn_info *conn_info);
  116. static int amf_exec_init_fn (struct openais_config *);
  117. static int amf_init_two_fn (struct conn_info *conn_info);
  118. static int message_handler_req_lib_amf_componentregister (struct conn_info *conn_info, void *message);
  119. static int message_handler_req_lib_amf_componentunregister (struct conn_info *conn_info, void *message);
  120. static int message_handler_req_lib_amf_pmstart (struct conn_info *conn_info, void *message);
  121. static int message_handler_req_lib_amf_pmstop (struct conn_info *conn_info, void *message);
  122. static int message_handler_req_lib_amf_healthcheckstart (struct conn_info *conn_info, void *message);
  123. static int message_handler_req_lib_amf_healthcheckconfirm (struct conn_info *conn_info, void *message);
  124. static int message_handler_req_lib_amf_healthcheckstop (struct conn_info *conn_info, void *message);
  125. static int message_handler_req_lib_amf_hastateget (struct conn_info *conn_info, void *message);
  126. static int message_handler_req_lib_amf_csiquiescingcomplete (struct conn_info *conn_info, void *message);
  127. static int message_handler_req_lib_amf_protectiongrouptrackstart (struct conn_info *conn_info, void *message);
  128. static int message_handler_req_lib_amf_protectiongrouptrackstop (struct conn_info *conn_info, void *message);
  129. static int message_handler_req_lib_amf_componenterrorreport (struct conn_info *conn_info, void *message);
  130. static int message_handler_req_lib_amf_componenterrorclear (struct conn_info *conn_info, void *message);
  131. static int message_handler_req_lib_amf_response (struct conn_info *conn_info, void *message);
  132. static int message_handler_req_exec_amf_operational_state_comp_set (
  133. void *message,
  134. struct totem_ip_address *source,
  135. int endian_conversion_required);
  136. static int message_handler_req_exec_amf_presence_state_comp_set (
  137. void *message,
  138. struct totem_ip_address *source,
  139. int endian_conversion_required);
  140. static int message_handler_req_exec_amf_administrative_state_csi_set (
  141. void *message,
  142. struct totem_ip_address *source,
  143. int endian_conversion_required);
  144. static int message_handler_req_exec_amf_administrative_state_unit_set (
  145. void *message,
  146. struct totem_ip_address *source,
  147. int endian_conversion_required);
  148. static int message_handler_req_exec_amf_administrative_state_group_set (
  149. void *message,
  150. struct totem_ip_address *source,
  151. int endian_conversion_required);
  152. void presence_state_comp_set (
  153. struct amf_comp *comp,
  154. OpenaisCfgPresenceStateT presence_state);
  155. void operational_state_comp_set (
  156. struct amf_comp *comp,
  157. OpenaisCfgOperationalStateT operational_state);
  158. void operational_state_unit_set (
  159. struct amf_unit *unit,
  160. OpenaisCfgOperationalStateT operational_state);
  161. int clc_instantiate_all (void);
  162. int clc_instantiate (struct amf_comp *comp);
  163. int clc_terminate (struct amf_comp *comp);
  164. int clc_cli_instantiate (struct amf_comp *comp);
  165. int clc_instantiate_callback (struct amf_comp *comp);
  166. int clc_csi_set_callback (struct amf_comp *comp);
  167. int clc_cli_terminate (struct amf_comp *comp);
  168. int clc_terminate_callback (struct amf_comp *comp);
  169. int clc_csi_remove_callback (struct amf_comp *comp);
  170. int clc_cli_cleanup (struct amf_comp *comp);
  171. int clc_cli_cleanup_local (struct amf_comp *comp);
  172. void healthcheck_activate (struct healthcheck_active *healthcheck_active);
  173. void healthcheck_deactivate (struct healthcheck_active *healthcheck_active);
  174. void comp_healthcheck_activate (struct amf_comp *comp);
  175. void comp_healthcheck_deactivate (struct amf_comp *comp);
  176. static void escalation_policy_restart (struct amf_comp *comp);
  177. struct clc_interface {
  178. int (*instantiate) (struct amf_comp *comp);
  179. int (*terminate) (struct amf_comp *comp);
  180. int (*cleanup) (struct amf_comp *comp);
  181. };
  182. /*
  183. * Life cycle functions
  184. */
  185. struct clc_interface clc_interface_sa_aware = {
  186. clc_cli_instantiate,
  187. clc_terminate_callback,
  188. clc_cli_cleanup
  189. };
  190. struct clc_interface clc_interface_proxied_pre = {
  191. clc_instantiate_callback,
  192. clc_terminate_callback,
  193. clc_cli_cleanup
  194. };
  195. struct clc_interface clc_interface_proxied_non_pre = {
  196. clc_csi_set_callback,
  197. clc_csi_remove_callback,
  198. clc_cli_cleanup_local
  199. };
  200. struct clc_interface clc_interface_non_proxied_non_saware = {
  201. clc_cli_instantiate,
  202. clc_cli_terminate,
  203. clc_cli_cleanup_local
  204. };
  205. struct clc_interface *clc_interfaces[4] = {
  206. &clc_interface_sa_aware,
  207. &clc_interface_proxied_pre,
  208. &clc_interface_proxied_non_pre,
  209. &clc_interface_non_proxied_non_saware
  210. };
  211. /*
  212. * Service Handler Definition
  213. */
  214. struct libais_handler amf_libais_handlers[] =
  215. {
  216. { /* 0 */
  217. .libais_handler_fn = message_handler_req_lib_amf_componentregister,
  218. .response_size = sizeof (struct res_lib_amf_componentregister),
  219. .response_id = MESSAGE_RES_AMF_COMPONENTREGISTER,
  220. .flow_control = FLOW_CONTROL_REQUIRED
  221. },
  222. { /* 1 */
  223. .libais_handler_fn = message_handler_req_lib_amf_componentunregister,
  224. .response_size = sizeof (struct res_lib_amf_componentunregister),
  225. .response_id = MESSAGE_RES_AMF_COMPONENTUNREGISTER,
  226. .flow_control = FLOW_CONTROL_REQUIRED
  227. },
  228. { /* 2 */
  229. .libais_handler_fn = message_handler_req_lib_amf_pmstart,
  230. .response_size = sizeof (struct res_lib_amf_pmstart),
  231. .response_id = MESSAGE_RES_AMF_PMSTART,
  232. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  233. },
  234. { /* 3 */
  235. .libais_handler_fn = message_handler_req_lib_amf_pmstop,
  236. .response_size = sizeof (struct res_lib_amf_pmstop),
  237. .response_id = MESSAGE_RES_AMF_PMSTOP,
  238. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  239. },
  240. { /* 4 */
  241. .libais_handler_fn = message_handler_req_lib_amf_healthcheckstart,
  242. .response_size = sizeof (struct res_lib_amf_healthcheckstart),
  243. .response_id = MESSAGE_RES_AMF_HEALTHCHECKSTART,
  244. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  245. },
  246. { /* 5 */
  247. .libais_handler_fn = message_handler_req_lib_amf_healthcheckconfirm,
  248. .response_size = sizeof (struct res_lib_amf_healthcheckconfirm),
  249. .response_id = MESSAGE_RES_AMF_HEALTHCHECKCONFIRM,
  250. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  251. },
  252. { /* 6 */
  253. .libais_handler_fn = message_handler_req_lib_amf_healthcheckstop,
  254. .response_size = sizeof (struct res_lib_amf_healthcheckstop),
  255. .response_id = MESSAGE_RES_AMF_HEALTHCHECKSTOP,
  256. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  257. },
  258. { /* 7 */
  259. .libais_handler_fn = message_handler_req_lib_amf_hastateget,
  260. .response_size = sizeof (struct res_lib_amf_hastateget),
  261. .response_id = MESSAGE_RES_AMF_HASTATEGET,
  262. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  263. },
  264. { /* 8 */
  265. .libais_handler_fn = message_handler_req_lib_amf_csiquiescingcomplete,
  266. .response_size = sizeof (struct res_lib_amf_csiquiescingcomplete),
  267. .response_id = MESSAGE_RES_AMF_CSIQUIESCINGCOMPLETE,
  268. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  269. },
  270. { /* 9 */
  271. .libais_handler_fn = message_handler_req_lib_amf_protectiongrouptrackstart,
  272. .response_size = sizeof (struct res_lib_amf_protectiongrouptrackstart),
  273. .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART,
  274. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  275. },
  276. { /* 10 */
  277. .libais_handler_fn = message_handler_req_lib_amf_protectiongrouptrackstop,
  278. .response_size = sizeof (struct res_lib_amf_protectiongrouptrackstop),
  279. .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP,
  280. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  281. },
  282. { /* 11 */
  283. .libais_handler_fn = message_handler_req_lib_amf_componenterrorreport,
  284. .response_size = sizeof (struct res_lib_amf_componenterrorreport),
  285. .response_id = MESSAGE_RES_AMF_COMPONENTERRORREPORT,
  286. .flow_control = FLOW_CONTROL_REQUIRED
  287. },
  288. { /* 12 */
  289. .libais_handler_fn = message_handler_req_lib_amf_componenterrorclear,
  290. .response_size = sizeof (struct res_lib_amf_componenterrorclear),
  291. .response_id = MESSAGE_RES_AMF_COMPONENTERRORCLEAR,
  292. .flow_control = FLOW_CONTROL_REQUIRED
  293. },
  294. { /* 13 */
  295. .libais_handler_fn = message_handler_req_lib_amf_response,
  296. .response_size = sizeof (struct res_lib_amf_response),
  297. .response_id = MESSAGE_RES_AMF_RESPONSE, // TODO
  298. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  299. },
  300. };
  301. int (*amf_aisexec_handler_fns[]) (
  302. void *,
  303. struct totem_ip_address *source,
  304. int endian_conversion_required) =
  305. {
  306. message_handler_req_exec_amf_operational_state_comp_set,
  307. message_handler_req_exec_amf_presence_state_comp_set,
  308. message_handler_req_exec_amf_administrative_state_csi_set,
  309. message_handler_req_exec_amf_administrative_state_unit_set,
  310. message_handler_req_exec_amf_administrative_state_group_set
  311. };
  312. /*
  313. * Exports the interface for the service
  314. */
  315. struct service_handler amf_service_handler = {
  316. .libais_handlers = amf_libais_handlers,
  317. .libais_handlers_count = sizeof (amf_libais_handlers) / sizeof (struct libais_handler),
  318. .aisexec_handler_fns = amf_aisexec_handler_fns,
  319. .aisexec_handler_fns_count = sizeof (amf_aisexec_handler_fns) / sizeof (int (*)),
  320. .confchg_fn = amf_confchg_fn,
  321. .libais_init_two_fn = amf_init_two_fn,
  322. .libais_exit_fn = amf_exit_fn,
  323. .exec_init_fn = amf_exec_init_fn,
  324. };
  325. enum clc_command_run_operation_type {
  326. CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE = 1,
  327. CLC_COMMAND_RUN_OPERATION_TYPE_TERMINATE = 2,
  328. CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP = 3
  329. };
  330. struct clc_command_run_data {
  331. struct amf_comp *comp;
  332. enum clc_command_run_operation_type type;
  333. void (*completion_callback) (void *context);
  334. };
  335. int invocation_create (
  336. int interface,
  337. void *data)
  338. {
  339. struct invocation *invocation_addr = 0;
  340. struct invocation *invocation_temp;
  341. int i;
  342. int loc = 0;
  343. for (i = 0; i < invocation_entries_size; i++) {
  344. if (invocation_entries[i].active == 0) {
  345. invocation_addr = &invocation_entries[i];
  346. loc = i;
  347. break;
  348. }
  349. }
  350. if (invocation_addr == 0) {
  351. invocation_temp = (struct invocation *)realloc (invocation_entries,
  352. (invocation_entries_size + 1) * sizeof (struct invocation));
  353. if (invocation_temp == 0) {
  354. return (-1);
  355. }
  356. invocation_entries = invocation_temp;
  357. invocation_addr = &invocation_entries[invocation_entries_size];
  358. loc = invocation_entries_size;
  359. invocation_entries_size += 1;
  360. }
  361. invocation_addr->interface = interface;
  362. invocation_addr->data = data;
  363. invocation_addr->active = 1;
  364. return (loc);
  365. }
  366. int invocation_get_and_destroy (int invocation, int *interface,
  367. void **data)
  368. {
  369. if (invocation > invocation_entries_size) {
  370. return (-1);
  371. }
  372. if (invocation_entries[invocation].active == 0) {
  373. return (-1);
  374. }
  375. *interface = invocation_entries[invocation].interface;
  376. *data = invocation_entries[invocation].data;
  377. memset (&invocation_entries[invocation], 0, sizeof (struct invocation));
  378. return (0);
  379. }
  380. void invocation_destroy_by_data (void *data)
  381. {
  382. int i;
  383. for (i = 0; i < invocation_entries_size; i++) {
  384. if (invocation_entries[i].data == data) {
  385. memset (&invocation_entries[i], 0,
  386. sizeof (struct invocation));
  387. break;
  388. }
  389. }
  390. }
  391. void *clc_command_run (void *context)
  392. {
  393. struct clc_command_run_data *clc_command_run_data = (struct clc_command_run_data *)context;
  394. pid_t pid;
  395. int res;
  396. char *argv[10];
  397. char *envp[10];
  398. int status;
  399. unsigned char cmd[1024];
  400. unsigned char env_comp_binary_name[1024];
  401. unsigned char env_comp_binary_path[1024];
  402. unsigned char env_comp_name[1024];
  403. unsigned char *binary_to_run = 0;
  404. unsigned char *binary_path = 0;
  405. char *clc_cli_interface;
  406. sleep (1);
  407. printf ("clc_command_run()\n");
  408. pid = fork();
  409. if (pid == -1) {
  410. printf ("Couldn't fork process %s\n", strerror (errno));
  411. return (0);
  412. }
  413. if (pid) {
  414. waiting = 1;
  415. printf ("waiting for pid %d to finish\n", pid);
  416. waitpid (pid, &status, 0);
  417. if (clc_command_run_data->completion_callback) {
  418. clc_command_run_data->completion_callback (context);
  419. }
  420. pthread_exit(0);
  421. }
  422. switch (clc_command_run_data->type) {
  423. case CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE:
  424. binary_to_run = clc_command_run_data->comp->instantiate_cmd;
  425. clc_cli_interface = "CLC_CLI_INTERFACE=instantiate";
  426. break;
  427. case CLC_COMMAND_RUN_OPERATION_TYPE_TERMINATE:
  428. binary_to_run = clc_command_run_data->comp->terminate_cmd;
  429. clc_cli_interface = "CLC_CLI_INTERFACE=terminate";
  430. break;
  431. case CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP:
  432. binary_to_run = clc_command_run_data->comp->cleanup_cmd;
  433. clc_cli_interface = "CLC_CLI_INTERFACE=cleanup";
  434. break;
  435. default:
  436. assert (0 != 1);
  437. break;
  438. }
  439. if (strlen (clc_command_run_data->comp->clccli_path)) {
  440. sprintf (cmd, "%s/%s",
  441. clc_command_run_data->comp->clccli_path,
  442. binary_to_run);
  443. } else
  444. if (strlen (clc_command_run_data->comp->unit->clccli_path)) {
  445. sprintf (cmd, "%s/%s",
  446. clc_command_run_data->comp->unit->clccli_path,
  447. binary_to_run);
  448. } else {
  449. sprintf (cmd, "%s/%s",
  450. clc_command_run_data->comp->unit->amf_group->clccli_path,
  451. binary_to_run);
  452. }
  453. if (strlen (clc_command_run_data->comp->binary_path)) {
  454. binary_path = clc_command_run_data->comp->binary_path;
  455. } else
  456. if (strlen (clc_command_run_data->comp->unit->binary_path)) {
  457. binary_path = clc_command_run_data->comp->unit->binary_path;
  458. } else {
  459. binary_path = clc_command_run_data->comp->unit->amf_group->binary_path;
  460. }
  461. argv[0] = cmd;
  462. argv[1] = '\0';
  463. envp[0] = cmd;
  464. envp[1] = clc_cli_interface;
  465. envp[2] = env_comp_binary_name;
  466. envp[3] = env_comp_binary_path;
  467. envp[4] = env_comp_name;
  468. envp[5] = '\0';
  469. sprintf (env_comp_binary_name, "COMP_BINARY_NAME=%s",
  470. clc_command_run_data->comp->binary_name);
  471. sprintf (env_comp_binary_path, "COMP_BINARY_PATH=%s",
  472. binary_path);
  473. strcpy (env_comp_name, "SA_AMF_COMPONENT_NAME=");
  474. strncat (env_comp_name, clc_command_run_data->comp->name.value,
  475. clc_command_run_data->comp->name.length);
  476. if (cmd[0] == '\0') {
  477. return (0);
  478. }
  479. printf ("running command '%s' with environment:\n", cmd);
  480. printf ("0 %s\n", envp[0]);
  481. printf ("1 %s\n", envp[1]);
  482. printf ("2 %s\n", envp[2]);
  483. printf ("3 %s\n", envp[3]);
  484. printf ("4 %s\n", envp[4]);
  485. res = execve (cmd, argv, envp);
  486. if (res == -1) {
  487. printf ("Couldn't exec process %d=%s\n", errno, strerror (errno));
  488. }
  489. assert (res != -1);
  490. return (0);
  491. }
  492. struct req_exec_amf_operational_state_comp_set {
  493. struct req_header header;
  494. SaNameT name;
  495. OpenaisCfgOperationalStateT operational_state;
  496. };
  497. struct req_exec_amf_presence_state_comp_set {
  498. struct req_header header;
  499. SaNameT name;
  500. OpenaisCfgPresenceStateT presence_state;
  501. };
  502. struct req_exec_amf_administrative_state_csi_set {
  503. struct req_header header;
  504. SaNameT name;
  505. OpenaisCfgAdministrativeStateT presence_state;
  506. };
  507. struct req_exec_amf_administrative_state_unit_set {
  508. struct req_header header;
  509. SaNameT name;
  510. OpenaisCfgAdministrativeStateT presence_state;
  511. };
  512. struct req_exec_amf_administrative_state_group_set {
  513. struct req_header header;
  514. SaNameT name;
  515. OpenaisCfgAdministrativeStateT presence_state;
  516. };
  517. struct req_exec_amf_comp_restart {
  518. struct req_header header;
  519. SaNameT compName;
  520. };
  521. /*
  522. * Instantiate possible operations
  523. */
  524. int clc_cli_instantiate (struct amf_comp *comp)
  525. {
  526. int res;
  527. pthread_t thread;
  528. struct clc_command_run_data *clc_command_run_data;
  529. printf ("clc_cli_instaniate\n");
  530. clc_command_run_data = malloc (sizeof (struct clc_command_run_data));
  531. clc_command_run_data->comp = comp;
  532. clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE;
  533. clc_command_run_data->completion_callback = NULL;
  534. res = pthread_create (&thread, NULL, clc_command_run, (void *)clc_command_run_data);
  535. pthread_detach (thread);
  536. // TODO error code from pthread_create
  537. return (res);
  538. }
  539. int clc_instantiate_callback (struct amf_comp *comp)
  540. {
  541. printf ("clc_instantiate_callback\n");
  542. return (0);
  543. }
  544. int clc_csi_set_callback (struct amf_comp *comp)
  545. {
  546. printf ("clc_csi_set_callback\n");
  547. return (0);
  548. }
  549. /*
  550. * Terminate possible operations
  551. */
  552. int clc_cli_terminate (struct amf_comp *comp)
  553. {
  554. printf ("clc_cli_terminate\n");
  555. return (0);
  556. }
  557. int clc_terminate_callback (struct amf_comp *comp)
  558. {
  559. struct res_lib_amf_componentterminatecallback res_lib_amf_componentterminatecallback;
  560. struct component_terminate_callback_data *component_terminate_callback_data;
  561. printf ("clc_terminate_callback %p\n", comp->conn_info);
  562. if (comp->presence_state != OPENAIS_CFG_PRESENCESTATE_INSTANTIATED) {
  563. printf ("component terminated but not instantiated %s - %d\n",
  564. getSaNameT (&comp->name), comp->presence_state);
  565. assert (0);
  566. return (0);
  567. }
  568. printf ("component name terminating %s\n", getSaNameT (&comp->name));
  569. printf ("component presence state %d\n", comp->presence_state);
  570. res_lib_amf_componentterminatecallback.header.id = MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK;
  571. res_lib_amf_componentterminatecallback.header.size = sizeof (struct res_lib_amf_componentterminatecallback);
  572. res_lib_amf_componentterminatecallback.header.error = SA_AIS_OK;
  573. memcpy (&res_lib_amf_componentterminatecallback.compName,
  574. &comp->name, sizeof (SaNameT));
  575. component_terminate_callback_data =
  576. malloc (sizeof (struct component_terminate_callback_data));
  577. assert (component_terminate_callback_data); // TODO failure here of malloc
  578. component_terminate_callback_data->comp = comp;
  579. res_lib_amf_componentterminatecallback.invocation =
  580. invocation_create (
  581. AMF_RESPONSE_COMPONENTTERMINATECALLBACK,
  582. component_terminate_callback_data);
  583. printf ("Creating invocation %lld",
  584. res_lib_amf_componentterminatecallback.invocation);
  585. libais_send_response (
  586. comp->conn_info->conn_info_partner,
  587. &res_lib_amf_componentterminatecallback,
  588. sizeof (struct res_lib_amf_componentterminatecallback));
  589. return (0);
  590. }
  591. int clc_csi_remove_callback (struct amf_comp *comp)
  592. {
  593. printf ("clc_tcsi_remove_callback\n");
  594. return (0);
  595. }
  596. /*
  597. * This reinstantiates the cleaned up component
  598. */
  599. void clc_cleanup_completion_callback (void *context) {
  600. struct clc_command_run_data *clc_command_run_data = (struct clc_command_run_data *)context;
  601. escalation_policy_restart (clc_command_run_data->comp);
  602. }
  603. /*
  604. * Cleanup possible operations
  605. */
  606. int clc_cli_cleanup (struct amf_comp *comp)
  607. {
  608. int res;
  609. pthread_t thread;
  610. struct clc_command_run_data *clc_command_run_data;
  611. printf ("clc_cli_instaniate\n");
  612. clc_command_run_data = malloc (sizeof (struct clc_command_run_data));
  613. clc_command_run_data->comp = comp;
  614. clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP;
  615. clc_command_run_data->completion_callback = clc_cleanup_completion_callback;
  616. res = pthread_create (&thread, NULL, clc_command_run, (void *)clc_command_run_data);
  617. pthread_detach (thread);
  618. // TODO error code from pthread_create
  619. return (res);
  620. return (0);
  621. }
  622. int clc_cli_cleanup_local (struct amf_comp *comp)
  623. {
  624. printf ("clc_cli_cleanup_local\n");
  625. return (0);
  626. }
  627. int clc_instantiate (struct amf_comp *comp)
  628. {
  629. int res;
  630. printf ("clc instantiate for comp %s\n", getSaNameT (&comp->name));
  631. presence_state_comp_set (comp, OPENAIS_CFG_PRESENCESTATE_INSTANTIATING);
  632. res = clc_interfaces[comp->comptype]->instantiate (comp);
  633. return (res);
  634. }
  635. int clc_terminate (struct amf_comp *comp)
  636. {
  637. int res;
  638. printf ("clc terminate for comp %s\n", getSaNameT (&comp->name));
  639. assert (0);
  640. operational_state_comp_set (comp, OPENAIS_CFG_OPERATIONALSTATE_DISABLED);
  641. presence_state_comp_set (comp, OPENAIS_CFG_PRESENCESTATE_TERMINATING);
  642. res = clc_interfaces[comp->comptype]->terminate (comp);
  643. return (0);
  644. }
  645. int clc_cleanup (struct amf_comp *comp)
  646. {
  647. int res;
  648. printf ("clc cleanup for comp %s\n", getSaNameT (&comp->name));
  649. comp_healthcheck_deactivate (comp);
  650. operational_state_comp_set (comp, OPENAIS_CFG_OPERATIONALSTATE_DISABLED);
  651. presence_state_comp_set (comp, OPENAIS_CFG_PRESENCESTATE_TERMINATING);
  652. res = clc_interfaces[comp->comptype]->cleanup (comp);
  653. return (0);
  654. }
  655. /* IMPL */
  656. static int amf_exec_init_fn (struct openais_config *openais_config)
  657. {
  658. #ifdef TODO
  659. int res;
  660. res = totempg_recovery_plug_create (&amf_recovery_plug_handle);
  661. if (res != 0) {
  662. log_printf(LOG_LEVEL_ERROR,
  663. "Could not create recovery plug for amf service.\n");
  664. return (-1);
  665. }
  666. #endif
  667. if (openais_config->amf_enabled) {
  668. clc_instantiate_all ();
  669. }
  670. return (0);
  671. }
  672. static int amf_confchg_fn (
  673. enum totem_configuration_type configuration_type,
  674. struct totem_ip_address *member_list, int member_list_entries,
  675. struct totem_ip_address *left_list, int left_list_entries,
  676. struct totem_ip_address *joined_list, int joined_list_entries,
  677. struct memb_ring_id *ring_id)
  678. {
  679. #ifdef COMPILE_OUT
  680. int i;
  681. log_printf (LOG_LEVEL_FROM_GMI, "Executive: amf_confchg_fn : type = %d,mnum = %d,jnum = %d,lnum = %d\n", configuration_type,member_list_entries,joined_list_entries,left_list_entries);
  682. recovery = 1;
  683. /*
  684. * If node join, component register
  685. */
  686. if ( joined_list_entries > 0 ) {
  687. enumerate_components (amf_confchg_njoin, NULL);
  688. }
  689. /*
  690. * If node leave, component unregister
  691. */
  692. for (i = 0; i<left_list_entries ; i++) {
  693. enumerate_components (amf_confchg_nleave, (void *)&(left_list[i]));
  694. }
  695. #ifdef TODO
  696. if (configuration_type == TOTEMPG_CONFIGURATION_REGULAR) {
  697. totempg_recovery_plug_unplug (amf_recovery_plug_handle);
  698. recovery = 0;
  699. }
  700. #endif
  701. #endif
  702. return (0);
  703. }
  704. int amf_exit_fn (struct conn_info *conn_info)
  705. {
  706. struct amf_comp *comp;
  707. comp = conn_info->ais_ci.u.libamf_ci.comp;
  708. if (comp) {
  709. comp->conn_info = 0;
  710. printf ("setting in exit fn to uninst for comp %p\n", comp);
  711. presence_state_comp_set (
  712. comp,
  713. OPENAIS_CFG_PRESENCESTATE_UNINSTANTIATED);
  714. operational_state_comp_set (
  715. comp,
  716. OPENAIS_CFG_OPERATIONALSTATE_DISABLED);
  717. comp_healthcheck_deactivate (comp);
  718. }
  719. return (0);
  720. }
  721. static int amf_init_two_fn (struct conn_info *conn_info)
  722. {
  723. log_printf (LOG_LEVEL_DEBUG, "Got request to initalize availability management framework service.\n");
  724. list_init (&conn_info->conn_list);
  725. return (0);
  726. }
  727. #ifdef COMPILE_OUT
  728. static void amf_synchronize (void *message, struct in_addr source_addr)
  729. {
  730. struct req_exec_amf_componentregister *req_exec_amf_componentregister = (struct req_exec_amf_componentregister *)message;
  731. struct amf_comp *component;
  732. struct amf_comp *amfProxyComponent;
  733. log_printf (LOG_LEVEL_ENTER_FUNC, "amf_synchronize%s\n",
  734. getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName));
  735. /* Find Component */
  736. component = find_comp (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName);
  737. amfProxyComponent = find_comp (&req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName);
  738. /* If this processor is component owner */
  739. if (component->source_addr.s_addr == this_ip->sin_addr.s_addr) {
  740. /* No Operation */
  741. return;
  742. }
  743. /* If this isn't synchronizing target processor */
  744. if (!(component->local == 0 && component->registered == 0)){
  745. /* No Operation */
  746. return;
  747. }
  748. /* Synchronize Status */
  749. component->local = 0;
  750. component->registered = 1;
  751. component->conn_info = req_exec_amf_componentregister->source.conn_info;
  752. component->source_addr = source_addr;
  753. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  754. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  755. component->currentHAState = SA_AMF_QUIESCED;
  756. component->newHAState = SA_AMF_QUIESCED;
  757. component->probableCause = 0;
  758. component->enabledUnlockedState = 0;
  759. component->disabledUnlockedState = 0;
  760. component->currentReadinessState = req_exec_amf_componentregister->currentReadinessState;
  761. component->newReadinessState = req_exec_amf_componentregister->newReadinessState;
  762. component->currentHAState = req_exec_amf_componentregister->currentHAState;
  763. component->newHAState = req_exec_amf_componentregister->newHAState;
  764. if (req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) {
  765. component->saAmfProxyComponent = amfProxyComponent;
  766. }
  767. /*
  768. * Determine if we should enter new state
  769. */
  770. dsmSynchronizeStaus (component);
  771. return;
  772. }
  773. #endif
  774. DECLARE_LIST_INIT (library_notification_send_listhead);
  775. // TODO static totempg_recovery_plug_handle amf_recovery_plug_handle;
  776. static void protectiongroup_notifications_send (
  777. struct amf_comp *changedComponent,
  778. SaAmfProtectionGroupChangesT changeToComponent)
  779. {
  780. #ifdef COMPILE_OUT
  781. int i;
  782. struct conn_info *conn_info;
  783. struct list_head *list;
  784. log_printf (LOG_LEVEL_ENTER_FUNC, "protectiongroup_notifications_send: sending PGs to API.\n");
  785. /*
  786. * Iterate all tracked connections
  787. */
  788. for (list = library_notification_send_listhead.next;
  789. list != &library_notification_send_listhead;
  790. list = list->next) {
  791. conn_info = list_entry (list, struct conn_info, conn_list);
  792. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  793. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active) {
  794. if (conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.length
  795. != changedComponent->amf_pg->name.length) {
  796. continue;
  797. }
  798. if (memcmp (conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.value,
  799. changedComponent->amf_pg->name.value,
  800. conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.length)) {
  801. continue;
  802. }
  803. #ifdef COMPILE_OUT
  804. protectiongroup_notification_send (conn_info,
  805. conn_info->ais_ci.u.libamf_ci.tracks[i].notificationBufferAddress,
  806. changedComponent->saAmfProtectionGroup,
  807. changedComponent,
  808. changeToComponent,
  809. conn_info->ais_ci.u.libamf_ci.tracks[i].trackFlags);
  810. #endif
  811. } /* if track flags active */
  812. } /* for all track entries */
  813. } /* for all connection entries */
  814. #endif
  815. }
  816. static int make_protectiongroup_notification_allcomponent (
  817. struct amf_comp *changedComponent,
  818. SaAmfProtectionGroupChangesT changeToComponent,
  819. SaAmfProtectionGroupNotificationT **notification )
  820. {
  821. #ifdef COMPILE_OUT
  822. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  823. int notifyEntries = 0;
  824. struct amf_comp *component;
  825. struct list_head *AmfGroupList;
  826. struct list_head *AmfUnitList;
  827. struct list_head *AmfComponentList;
  828. struct saAmfGroup *saAmfGroup;
  829. struct saAmfUnit *AmfUnit;
  830. for (AmfGroupList = saAmfGroupHead.next; AmfGroupList != &saAmfGroupHead; AmfGroupList = AmfGroupList->next) {
  831. saAmfGroup = list_entry (AmfGroupList, struct saAmfGroup, saAmfGroupList);
  832. /*
  833. * Search all units
  834. */
  835. for (AmfUnitList = saAmfGroup->saAmfUnitHead.next;
  836. AmfUnitList != &saAmfGroup->saAmfUnitHead;
  837. AmfUnitList = AmfUnitList->next) {
  838. AmfUnit = list_entry (AmfUnitList, struct saAmfUnit, saAmfUnitList);
  839. /*
  840. * Search all components
  841. */
  842. for (AmfComponentList = AmfUnit->amf_compHead.next;
  843. AmfComponentList != &AmfUnit->amf_compHead;
  844. AmfComponentList = AmfComponentList->next) {
  845. component = list_entry (AmfComponentList, struct amf_comp, amf_compList);
  846. protectionGroupNotification =
  847. (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
  848. sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
  849. memset (&protectionGroupNotification[notifyEntries],
  850. 0,sizeof (SaAmfProtectionGroupNotificationT));
  851. memcpy (&protectionGroupNotification[notifyEntries].member.compName,
  852. &component->name, sizeof (SaNameT));
  853. // memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
  854. // &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  855. memcpy (&protectionGroupNotification[notifyEntries].member.haState,
  856. &component->currentHAState, sizeof (SaAmfHAStateT));
  857. if (component == changedComponent) {
  858. protectionGroupNotification[notifyEntries].change = changeToComponent;
  859. } else {
  860. protectionGroupNotification[notifyEntries].change
  861. = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  862. }
  863. notifyEntries += 1;
  864. }
  865. }
  866. }
  867. if (notifyEntries) {
  868. *notification = protectionGroupNotification;
  869. }
  870. return (notifyEntries);
  871. #endif
  872. return (0);
  873. }
  874. #ifdef COMPILE_OUT
  875. static int make_protectiongroup_notification (
  876. struct saAmfProtectionGroup *amfProtectionGroup,
  877. struct amf_comp *changedComponent,
  878. SaAmfProtectionGroupChangesT changeToComponent,
  879. SaAmfProtectionGroupNotificationT **notification )
  880. {
  881. struct res_lib_amf_protectiongrouptrackcallback res_lib_amf_protectiongrouptrackcallback;
  882. int notifyEntries = 0;
  883. struct amf_comp *component;
  884. struct list_head *componentList;
  885. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  886. memset (&res_lib_amf_protectiongrouptrackcallback,0,sizeof(res_lib_amf_protectiongrouptrackcallback));
  887. for (componentList = amfProtectionGroup->saAmfMembersHead.next;
  888. componentList != &amfProtectionGroup->saAmfMembersHead;
  889. componentList = componentList->next) {
  890. component = list_entry (componentList, struct amf_comp, saAmfProtectionGroupList);
  891. protectionGroupNotification =
  892. (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
  893. sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
  894. memset (&protectionGroupNotification[notifyEntries],0,sizeof (SaAmfProtectionGroupNotificationT));
  895. memcpy (&protectionGroupNotification[notifyEntries].member.compName,
  896. &component->name, sizeof (SaNameT));
  897. // memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
  898. // &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  899. memcpy (&protectionGroupNotification[notifyEntries].member.haState,
  900. &component->currentHAState, sizeof (SaAmfHAStateT));
  901. if (component == changedComponent) {
  902. protectionGroupNotification[notifyEntries].change = changeToComponent;
  903. } else {
  904. protectionGroupNotification[notifyEntries].change = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  905. }
  906. notifyEntries += 1;
  907. } /* for */
  908. if (notifyEntries) {
  909. *notification = protectionGroupNotification;
  910. }
  911. return (notifyEntries);
  912. return (0);
  913. }
  914. #endif
  915. #ifdef COMPILE_OUT
  916. static void protectiongroup_notification_send (struct conn_info *conn_info,
  917. SaAmfProtectionGroupNotificationT *notificationBufferAddress,
  918. struct saAmfProtectionGroup *amfProtectionGroup,
  919. struct amf_comp *changedComponent,
  920. SaAmfProtectionGroupChangesT changeToComponent,
  921. SaUint8T trackFlags)
  922. {
  923. //struct res_lib_amf_protectiongrouptrackcallback res_lib_amf_protectiongrouptrackcallback;
  924. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  925. int notifyEntries;
  926. /*
  927. * Step through all components and generate protection group list for csi
  928. */
  929. memset (&res_lib_amf_protectiongrouptrackcallback, 0, sizeof(res_lib_amf_protectiongrouptrackcallback));
  930. if ( trackFlags == SA_TRACK_CHANGES ) {
  931. notifyEntries = make_protectiongroup_notification_allcomponent (changedComponent,
  932. changeToComponent, &protectionGroupNotification);
  933. }else if (trackFlags == SA_TRACK_CHANGES_ONLY) {
  934. notifyEntries = make_protectiongroup_notification (amfProtectionGroup,
  935. changedComponent, changeToComponent, &protectionGroupNotification );
  936. }else{
  937. notifyEntries = 0;
  938. }
  939. /*
  940. * Send track callback
  941. */
  942. if (notifyEntries) {
  943. res_lib_amf_protectiongrouptrackcallback.header.size =
  944. sizeof (struct res_lib_amf_protectiongrouptrackcallback) +
  945. (notifyEntries * sizeof (SaAmfProtectionGroupNotificationT));
  946. // res_lib_amf_protectiongrouptrackcallback.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK;
  947. res_lib_amf_protectiongrouptrackcallback.header.error = SA_OK;
  948. res_lib_amf_protectiongrouptrackcallback.numberOfItems = notifyEntries;
  949. res_lib_amf_protectiongrouptrackcallback.numberOfMembers = notifyEntries;
  950. memcpy (&res_lib_amf_protectiongrouptrackcallback.csiName,
  951. &amfProtectionGroup->name, sizeof (SaNameT));
  952. res_lib_amf_protectiongrouptrackcallback.notificationBufferAddress = notificationBufferAddress;
  953. libais_send_response (conn_info, &res_lib_amf_protectiongrouptrackcallback,
  954. sizeof (struct res_lib_amf_protectiongrouptrackcallback));
  955. libais_send_response (conn_info, protectionGroupNotification,
  956. sizeof (SaAmfProtectionGroupNotificationT) * notifyEntries);
  957. mempool_free (protectionGroupNotification);
  958. }
  959. }
  960. static void error_report (struct amf_comp *comp)
  961. {
  962. struct req_exec_amf_error_report req_exec_amf_error_report;
  963. struct iovec iovec;
  964. req_exec_amf_error_report.header.size = sizeof (struct req_exec_amf_error_report);
  965. req_exec_amf_error_report.header.id = MESSAGE_REQ_EXEC_AMF_ERROR_REPORT;
  966. memcpy (&req_exec_amf_error_report.compName,
  967. &comp->name,
  968. sizeof (SaNameT));
  969. iovec.iov_base = (char *)&req_exec_amf_error_report;
  970. iovec.iov_len = sizeof (req_exec_amf_error_report);
  971. assert (totempg_groups_mcast_joined (openais_group_handle,
  972. &iovec, 1, TOTEMPG_AGREED) == 0);
  973. }
  974. static void TODO_COMP_RESTART_THISISADEADPLACEHOLDER (struct amf_comp *comp)
  975. {
  976. struct req_exec_amf_comp_restart req_exec_amf_comp_restart;
  977. struct iovec iovec;
  978. req_exec_amf_comp_restart.header.size = sizeof (struct req_exec_amf_comp_restart);
  979. req_exec_amf_comp_restart.header.id = MESSAGE_REQ_EXEC_AMF_UNIT_RESTART;
  980. memcpy (&req_exec_amf_comp_restart.compName, &comp->name,
  981. sizeof (SaNameT));
  982. iovec.iov_base = (char *)&req_exec_amf_comp_restart;
  983. iovec.iov_len = sizeof (req_exec_amf_comp_restart);
  984. assert (totempg_groups_mcast_joined (openais_group_handle,
  985. &iovec, 1, TOTEMPG_AGREED) == 0);
  986. }
  987. #endif
  988. #define INVOCATION_DONT_COMPARE 0xFFFFFFFFULL
  989. struct healthcheck_active *find_healthcheck_active (
  990. struct amf_comp *comp,
  991. SaAmfHealthcheckKeyT *key,
  992. SaAmfHealthcheckInvocationT invocation)
  993. {
  994. struct list_head *list;
  995. struct healthcheck_active *ret_healthcheck_active = 0;
  996. struct healthcheck_active *healthcheck_active;
  997. for (list = comp->healthcheck_list.next;
  998. list != &comp->healthcheck_list;
  999. list = list->next) {
  1000. healthcheck_active = list_entry (list,
  1001. struct healthcheck_active, list);
  1002. if ((memcmp (key, &healthcheck_active->key,
  1003. sizeof (SaAmfHealthcheckKeyT)) == 0) &&
  1004. (invocation == INVOCATION_DONT_COMPARE ||
  1005. healthcheck_active->invocationType == invocation)) {
  1006. ret_healthcheck_active = healthcheck_active;
  1007. break;
  1008. }
  1009. }
  1010. return (ret_healthcheck_active);
  1011. }
  1012. void comp_healthcheck_activate (
  1013. struct amf_comp *comp)
  1014. {
  1015. struct list_head *key_list;
  1016. struct healthcheck_active *healthcheck_active;
  1017. for (key_list = comp->healthcheck_list.next;
  1018. key_list != &comp->healthcheck_list;
  1019. key_list = key_list->next) {
  1020. healthcheck_active = list_entry (key_list,
  1021. struct healthcheck_active, list);
  1022. if (healthcheck_active->active == 0) {
  1023. healthcheck_activate (healthcheck_active);
  1024. }
  1025. }
  1026. }
  1027. void comp_healthcheck_deactivate (
  1028. struct amf_comp *comp)
  1029. {
  1030. struct list_head *list;
  1031. struct list_head *next;
  1032. struct healthcheck_active *healthcheck_active;
  1033. log_printf (LOG_LEVEL_NOTICE, "ZZZ comp_healthcheck_deactivate %s\n",
  1034. getSaNameT (&comp->name));
  1035. for (list = comp->healthcheck_list.next, next = list->next;
  1036. list != &comp->healthcheck_list;
  1037. list = next, next = list->next) {
  1038. healthcheck_active = list_entry (list,
  1039. struct healthcheck_active, list);
  1040. printf ("healthcheck deactivating %p\n", healthcheck_active);
  1041. healthcheck_deactivate (healthcheck_active);
  1042. }
  1043. }
  1044. void presence_state_comp_set (
  1045. struct amf_comp *comp,
  1046. OpenaisCfgPresenceStateT presence_state)
  1047. {
  1048. struct req_exec_amf_presence_state_comp_set req_exec_amf_presence_state_comp_set;
  1049. struct iovec iovec;
  1050. req_exec_amf_presence_state_comp_set.header.size = sizeof (struct req_exec_amf_presence_state_comp_set);
  1051. req_exec_amf_presence_state_comp_set.header.id = MESSAGE_REQ_EXEC_AMF_PRESENCE_STATE_COMP_SET;
  1052. req_exec_amf_presence_state_comp_set.presence_state = presence_state;
  1053. memcpy (&req_exec_amf_presence_state_comp_set.name,
  1054. &comp->name,
  1055. sizeof (SaNameT));
  1056. iovec.iov_base = (char *)&req_exec_amf_presence_state_comp_set;
  1057. iovec.iov_len = sizeof (req_exec_amf_presence_state_comp_set);
  1058. assert (totempg_groups_mcast_joined (openais_group_handle,
  1059. &iovec, 1, TOTEMPG_AGREED) == 0);
  1060. }
  1061. void readiness_state_comp_set (struct amf_comp *comp)
  1062. {
  1063. printf ("inputs to readiness_state_comp_set\n");
  1064. printf ("\tunit readiness state %s\n",
  1065. readinessstate_ntoa (comp->unit->readiness_state));
  1066. printf ("\tcomp operational state %s\n",
  1067. operationalstate_ntoa (comp->unit->readiness_state));
  1068. /*
  1069. * Set component readiness state appropriately
  1070. * if unit in service and component is enabled, it is in service
  1071. * otherwise it is out of service page 37
  1072. */
  1073. if (comp->unit->readiness_state == OPENAIS_CFG_READINESSSTATE_INSERVICE &&
  1074. comp->operational_state == OPENAIS_CFG_OPERATIONALSTATE_ENABLED) {
  1075. comp->readiness_state = OPENAIS_CFG_READINESSSTATE_INSERVICE;
  1076. } else {
  1077. comp->readiness_state = OPENAIS_CFG_READINESSSTATE_OUTOFSERVICE;
  1078. }
  1079. printf ("readiness_state_comp_set (%s)\n",
  1080. operationalstate_ntoa (comp->operational_state));
  1081. }
  1082. void operational_state_comp_set (struct amf_comp *comp, OpenaisCfgOperationalStateT operational_state)
  1083. {
  1084. struct req_exec_amf_operational_state_comp_set req_exec_amf_operational_state_comp_set;
  1085. struct iovec iovec;
  1086. req_exec_amf_operational_state_comp_set.header.size = sizeof (struct req_exec_amf_operational_state_comp_set);
  1087. req_exec_amf_operational_state_comp_set.header.id = MESSAGE_REQ_EXEC_AMF_OPERATIONAL_STATE_COMP_SET;
  1088. req_exec_amf_operational_state_comp_set.operational_state = operational_state;
  1089. memcpy (&req_exec_amf_operational_state_comp_set.name,
  1090. &comp->name,
  1091. sizeof (SaNameT));
  1092. iovec.iov_base = (char *)&req_exec_amf_operational_state_comp_set;
  1093. iovec.iov_len = sizeof (req_exec_amf_operational_state_comp_set);
  1094. assert (totempg_groups_mcast_joined (openais_group_handle,
  1095. &iovec, 1, TOTEMPG_AGREED) == 0);
  1096. }
  1097. void csi_comp_set_callback (
  1098. struct amf_comp *comp,
  1099. struct amf_csi *csi,
  1100. struct amf_pg *pg)
  1101. {
  1102. struct res_lib_amf_csisetcallback res_lib_amf_csisetcallback;
  1103. struct csi_set_callback_data *csi_set_callback_data;
  1104. printf ("\t%s\n",
  1105. getSaNameT (&comp->name));
  1106. res_lib_amf_csisetcallback.header.id = MESSAGE_RES_AMF_CSISETCALLBACK;
  1107. res_lib_amf_csisetcallback.header.size = sizeof (struct res_lib_amf_csisetcallback);
  1108. res_lib_amf_csisetcallback.header.error = SA_OK;
  1109. memcpy (&res_lib_amf_csisetcallback.compName,
  1110. &comp->name, sizeof (SaNameT));
  1111. memcpy (&res_lib_amf_csisetcallback.csiDescriptor.csiName,
  1112. &csi->name, sizeof (SaNameT));
  1113. res_lib_amf_csisetcallback.haState = comp->unit->requested_ha_state;
  1114. csi_set_callback_data = malloc (sizeof (struct csi_set_callback_data));
  1115. assert (csi_set_callback_data); // TODO failure here of malloc
  1116. csi_set_callback_data->comp = comp;
  1117. csi_set_callback_data->csi = csi;
  1118. csi_set_callback_data->pg = pg;
  1119. printf ("pg is %p\n", pg);
  1120. res_lib_amf_csisetcallback.invocation =
  1121. invocation_create (
  1122. AMF_RESPONSE_CSISETCALLBACK,
  1123. csi_set_callback_data);
  1124. libais_send_response (comp->conn_info->conn_info_partner,
  1125. &res_lib_amf_csisetcallback,
  1126. sizeof (struct res_lib_amf_csisetcallback));
  1127. }
  1128. void pg_create (struct amf_si *si, struct amf_pg **pg_out)
  1129. {
  1130. struct amf_pg *pg;
  1131. // struct amf_pg_comp *pg_comp;
  1132. pg = malloc (sizeof (struct amf_pg));
  1133. assert (pg);
  1134. list_init (&pg->pg_comp_head);
  1135. list_init (&pg->pg_list);
  1136. list_add (&pg->pg_list, &si->pg_head);
  1137. *pg_out = pg;
  1138. }
  1139. void csi_unit_set_callback (struct amf_csi *csi_in)
  1140. {
  1141. struct list_head *list;
  1142. struct amf_comp *comp;
  1143. struct amf_pg *pg;
  1144. pg_create (csi_in->si, &pg);
  1145. // TODO remove si from csi data structure
  1146. printf ("assigning CSI %s to ",
  1147. getSaNameT (&csi_in->name));
  1148. printf ("SU %s for components:\n",
  1149. getSaNameT (&csi_in->unit->name));
  1150. for (list = csi_in->unit->comp_head.next;
  1151. list != &csi_in->unit->comp_head;
  1152. list = list->next) {
  1153. comp = list_entry (list,
  1154. struct amf_comp, comp_list);
  1155. csi_comp_set_callback (comp, csi_in, pg);
  1156. }
  1157. }
  1158. void csi_comp_remove_callback (struct amf_comp *comp, struct amf_csi *csi)
  1159. {
  1160. struct res_lib_amf_csiremovecallback res_lib_amf_csiremovecallback;
  1161. struct csi_remove_callback_data *csi_remove_callback_data;
  1162. printf ("\t%s\n",
  1163. getSaNameT (&comp->name));
  1164. res_lib_amf_csiremovecallback.header.id = MESSAGE_RES_AMF_CSIREMOVECALLBACK;
  1165. res_lib_amf_csiremovecallback.header.size = sizeof (struct res_lib_amf_csiremovecallback);
  1166. res_lib_amf_csiremovecallback.header.error = SA_OK;
  1167. csi_remove_callback_data = malloc (sizeof (struct csi_remove_callback_data));
  1168. assert (csi_remove_callback_data); // TODO failure here of malloc
  1169. csi_remove_callback_data->csi = csi;
  1170. res_lib_amf_csiremovecallback.invocation =
  1171. invocation_create (
  1172. AMF_RESPONSE_CSIREMOVECALLBACK,
  1173. csi_remove_callback_data);
  1174. memcpy (&res_lib_amf_csiremovecallback.compName,
  1175. &comp->name, sizeof (SaNameT));
  1176. memcpy (&res_lib_amf_csiremovecallback.csiName,
  1177. &csi->name, sizeof (SaNameT));
  1178. res_lib_amf_csiremovecallback.csiFlags = 0;
  1179. libais_send_response (comp->conn_info->conn_info_partner,
  1180. &res_lib_amf_csiremovecallback,
  1181. sizeof (struct res_lib_amf_csiremovecallback));
  1182. }
  1183. extern struct list_head amf_groupHead;
  1184. int clc_instantiate_all (void) {
  1185. struct list_head *list_group;
  1186. struct amf_group *group;
  1187. struct list_head *list_unit;
  1188. struct amf_unit *unit;
  1189. struct list_head *list_comp;
  1190. struct amf_comp *comp;
  1191. for (list_group = amf_groupHead.next;
  1192. list_group != &amf_groupHead;
  1193. list_group = list_group->next) {
  1194. group = list_entry (list_group,
  1195. struct amf_group, group_list);
  1196. for (list_unit = group->unit_head.next;
  1197. list_unit != &group->unit_head;
  1198. list_unit = list_unit->next) {
  1199. unit = list_entry (list_unit,
  1200. struct amf_unit, unit_list);
  1201. for (list_comp = unit->comp_head.next;
  1202. list_comp != &unit->comp_head;
  1203. list_comp = list_comp->next) {
  1204. comp = list_entry (list_comp,
  1205. struct amf_comp, comp_list);
  1206. if (strlen (comp->instantiate_cmd)) {
  1207. clc_instantiate (comp);
  1208. }
  1209. }
  1210. }
  1211. }
  1212. return (0);
  1213. }
  1214. void comp_terminate (struct amf_comp *comp)
  1215. {
  1216. clc_terminate (comp);
  1217. }
  1218. void unit_terminate (struct amf_unit *unit)
  1219. {
  1220. struct list_head *list_comp;
  1221. struct amf_comp *comp;
  1222. for (list_comp = unit->comp_head.next;
  1223. list_comp != &unit->comp_head;
  1224. list_comp = list_comp->next) {
  1225. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1226. clc_terminate (comp);
  1227. }
  1228. }
  1229. void comp_cleanup (struct amf_comp *comp)
  1230. {
  1231. clc_cleanup (comp);
  1232. }
  1233. void unit_cleanup (struct amf_unit *unit)
  1234. {
  1235. struct list_head *list_comp;
  1236. struct amf_comp *comp;
  1237. for (list_comp = unit->comp_head.next;
  1238. list_comp != &unit->comp_head;
  1239. list_comp = list_comp->next) {
  1240. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1241. clc_cleanup (comp);
  1242. }
  1243. }
  1244. void comp_restart (struct amf_comp *comp)
  1245. {
  1246. presence_state_comp_set (comp, OPENAIS_CFG_PRESENCESTATE_RESTARTING);
  1247. }
  1248. void unit_restart (struct amf_unit *unit)
  1249. {
  1250. struct list_head *list_comp;
  1251. struct amf_comp *comp;
  1252. for (list_comp = unit->comp_head.next;
  1253. list_comp != &unit->comp_head;
  1254. list_comp = list_comp->next) {
  1255. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1256. presence_state_comp_set (comp, OPENAIS_CFG_PRESENCESTATE_RESTARTING);
  1257. }
  1258. }
  1259. void clc_unit_instantiate (struct amf_unit *unit)
  1260. {
  1261. struct list_head *list_comp;
  1262. struct amf_comp *comp;
  1263. printf ("ZZZZZZZZZZZZZZZZZ clc_unit_instantitate\n");
  1264. for (list_comp = unit->comp_head.next;
  1265. list_comp != &unit->comp_head;
  1266. list_comp = list_comp->next) {
  1267. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1268. clc_instantiate (comp);
  1269. }
  1270. }
  1271. void csi_unit_remove_callbacks (struct amf_unit *unit)
  1272. {
  1273. struct list_head *list_si;
  1274. struct list_head *list_csi;
  1275. struct list_head *list_comp;
  1276. struct amf_si *si;
  1277. struct amf_csi *csi;
  1278. struct amf_comp *comp;
  1279. for (list_si = unit->si_head.next;
  1280. list_si != &unit->si_head;
  1281. list_si = list_si->next) {
  1282. si = list_entry (list_si, struct amf_si, unit_list);
  1283. for (list_csi = si->csi_head.next;
  1284. list_csi != &si->csi_head;
  1285. list_csi = list_csi->next) {
  1286. csi = list_entry (list_csi, struct amf_csi, list);
  1287. for (list_comp = csi->unit->comp_head.next;
  1288. list_comp != &csi->unit->comp_head;
  1289. list_comp = list_comp->next) {
  1290. comp = list_entry (list_comp, struct amf_comp, comp_list);
  1291. }
  1292. }
  1293. }
  1294. }
  1295. // THIS MIGHT BE GOOD FOR SOMEPTHING ELSE
  1296. #ifdef COMPILE_OUT
  1297. void csi_unit_remove_callbacks (struct amf_unit *unit)
  1298. {
  1299. struct list_head *list_comp;
  1300. struct list_head *list_si;
  1301. struct list_head *list_csi;
  1302. struct list_head *list_pg;
  1303. struct list_head *list_pg_comp;
  1304. struct amf_comp *comp;
  1305. struct amf_csi *csi;
  1306. struct amf_si *si;
  1307. struct amf_pg *pg;
  1308. struct amf_pg_comp *pg_comp;
  1309. for (list_si = unit->si_head.next;
  1310. list_si != &unit->si_head;
  1311. list_si = list_si->next) {
  1312. si = list_entry (list_si, struct amf_si, unit_list);
  1313. for (list_pg = si->pg_head.next;
  1314. list_pg != &si->pg_head;
  1315. list_pg = list_pg->next) {
  1316. pg = list_entry (list_pg, struct amf_pg, pg_list);
  1317. printf ("pg %x\n", pg);
  1318. for (list_pg_comp = pg->pg_comp_head.next;
  1319. list_pg_comp != &pg->pg_comp_head;
  1320. list_pg_comp = list_pg_comp->next) {
  1321. pg_comp = list_entry (list_pg_comp,
  1322. struct amf_pg_comp, list);
  1323. printf ("pg_comp %x\n", pg_comp);
  1324. printf ("remove component callback\n");
  1325. csi_comp_remove_callback (
  1326. pg_comp->comp,
  1327. pg_comp->csi);
  1328. }
  1329. }
  1330. }
  1331. }
  1332. #endif
  1333. char csi_number = 0;
  1334. void csi_unit_create (struct amf_unit *unit, struct amf_si *si,
  1335. struct amf_csi **csi_out)
  1336. {
  1337. struct amf_csi *csi;
  1338. printf ("creating csi for si %p unit %p\n", si, unit);
  1339. si->csi_count += 1;
  1340. csi = malloc (sizeof (struct amf_csi));
  1341. list_init (&csi->list);
  1342. list_init (&csi->csi_list);
  1343. list_add (&csi->list, &si->csi_head);
  1344. list_add (&si->unit_list, &unit->si_head);
  1345. csi->si = si;
  1346. csi->unit = unit;
  1347. csi->pg_set = 0;
  1348. sprintf (csi->name.value, "CSI %d", csi_number);
  1349. csi->name.length = strlen (csi->name.value);
  1350. csi_number += 1;
  1351. *csi_out = csi;
  1352. }
  1353. void ha_state_unit_set (struct amf_unit *unit, struct amf_si *si,
  1354. SaAmfHAStateT ha_state)
  1355. {
  1356. struct amf_csi *csi;
  1357. printf ("Assigning SI %s ", getSaNameT (&si->name));
  1358. printf ("to SU %s ", getSaNameT (&unit->name));
  1359. printf ("with hastate %s\n", hastate_ntoa (ha_state));
  1360. unit->requested_ha_state = ha_state;
  1361. csi_unit_create (unit, si, &csi);
  1362. csi_unit_set_callback (csi);
  1363. }
  1364. int unit_inservice_count (struct amf_group *group)
  1365. {
  1366. struct list_head *list;
  1367. struct amf_unit *unit;
  1368. int answer = 0;
  1369. for (list = group->unit_head.next;
  1370. list != &group->unit_head;
  1371. list = list->next) {
  1372. unit = list_entry (list,
  1373. struct amf_unit, unit_list);
  1374. if (unit->readiness_state == OPENAIS_CFG_READINESSSTATE_INSERVICE) {
  1375. answer += 1;
  1376. }
  1377. }
  1378. return (answer);
  1379. }
  1380. int comp_inservice_count (struct amf_unit *unit)
  1381. {
  1382. struct list_head *list;
  1383. struct amf_comp *comp;
  1384. int answer = 0;
  1385. for (list = unit->comp_head.next;
  1386. list != &unit->comp_head;
  1387. list = list->next) {
  1388. comp = list_entry (list, struct amf_comp, comp_list);
  1389. if (comp->readiness_state == OPENAIS_CFG_READINESSSTATE_INSERVICE) {
  1390. answer += 1;
  1391. }
  1392. }
  1393. return (answer);
  1394. }
  1395. int si_count (struct amf_group *group)
  1396. {
  1397. struct list_head *list_si;
  1398. struct amf_si *si;
  1399. int answer = 0;
  1400. for (list_si = group->si_head.next;
  1401. list_si != &group->si_head;
  1402. list_si = list_si->next) {
  1403. si = list_entry (list_si,
  1404. struct amf_si, list);
  1405. answer += 1;
  1406. }
  1407. return (answer);
  1408. }
  1409. static inline int div_round (int a, int b)
  1410. {
  1411. int res;
  1412. res = a / b;
  1413. if ((a % b) != 0)
  1414. res++;
  1415. return res;
  1416. }
  1417. void assign_nm_active (struct amf_group *group, int su_units_assign)
  1418. {
  1419. struct amf_unit *unit;
  1420. struct amf_si *si;
  1421. struct list_head *list_si;
  1422. struct list_head *list_unit;
  1423. int assigned = 0;
  1424. int assign_per_su = 0;
  1425. int total_assigned = 0;
  1426. assign_per_su = si_count (group);
  1427. assign_per_su = div_round (assign_per_su, su_units_assign);
  1428. if (assign_per_su > group->maximum_active_instances) {
  1429. assign_per_su = group->maximum_active_instances;
  1430. }
  1431. list_si = group->si_head.next;
  1432. list_unit = group->unit_head.next;
  1433. while (list_unit != &group->unit_head) {
  1434. unit = list_entry (list_unit,
  1435. struct amf_unit, unit_list);
  1436. if (unit->readiness_state != OPENAIS_CFG_READINESSSTATE_INSERVICE) {
  1437. list_unit = list_unit->next;
  1438. continue; /* Not in service */
  1439. }
  1440. assigned = 0;
  1441. while (list_si != &group->si_head &&
  1442. assigned < assign_per_su &&
  1443. total_assigned < si_count (group)) {
  1444. si = list_entry (list_si, struct amf_si, list);
  1445. assigned += 1;
  1446. total_assigned += 1;
  1447. ha_state_unit_set (unit, si, SA_AMF_HA_ACTIVE);
  1448. list_si = list_si->next;
  1449. }
  1450. list_unit = list_unit->next;
  1451. }
  1452. }
  1453. void assign_nm_standby (struct amf_group *group, int units_assign_standby)
  1454. {
  1455. struct amf_unit *unit;
  1456. struct amf_si *si;
  1457. struct list_head *list_si;
  1458. struct list_head *list_unit;
  1459. int assigned = 0;
  1460. int assign_per_su = 0;
  1461. if (units_assign_standby == 0) {
  1462. return;
  1463. }
  1464. assign_per_su = si_count (group);
  1465. assign_per_su = div_round (assign_per_su, units_assign_standby);
  1466. if (assign_per_su > group->maximum_standby_instances) {
  1467. assign_per_su = group->maximum_standby_instances;
  1468. }
  1469. list_si = group->si_head.next;
  1470. list_unit = group->unit_head.next;
  1471. while (list_unit != &group->unit_head) {
  1472. unit = list_entry (list_unit,
  1473. struct amf_unit, unit_list);
  1474. if (unit->readiness_state != OPENAIS_CFG_READINESSSTATE_INSERVICE ||
  1475. unit->requested_ha_state == SA_AMF_HA_ACTIVE) {
  1476. list_unit = list_unit->next;
  1477. continue; /* Not available for assignment */
  1478. }
  1479. assigned = 0;
  1480. while (list_si != &group->si_head && assigned < assign_per_su) {
  1481. si = list_entry (list_si, struct amf_si, list);
  1482. assigned += 1;
  1483. ha_state_unit_set (unit, si, SA_AMF_HA_STANDBY);
  1484. list_si = list_si->next;
  1485. }
  1486. list_unit = list_unit->next;
  1487. }
  1488. }
  1489. void assign_nm_spare (struct amf_group *group)
  1490. {
  1491. struct amf_unit *unit;
  1492. struct list_head *list;
  1493. for (list = group->unit_head.next;
  1494. list != &group->unit_head;
  1495. list = list->next) {
  1496. unit = list_entry (list,
  1497. struct amf_unit, unit_list);
  1498. if (unit->readiness_state == OPENAIS_CFG_READINESSSTATE_INSERVICE &&
  1499. (unit->requested_ha_state != SA_AMF_HA_ACTIVE &&
  1500. unit->requested_ha_state != SA_AMF_HA_STANDBY)) {
  1501. printf ("Assigning to SU %s with SPARE\n",
  1502. getSaNameT (&unit->name));
  1503. }
  1504. }
  1505. }
  1506. void clear_requested_ha_state (struct amf_group *group)
  1507. {
  1508. struct list_head *list;
  1509. struct amf_unit *unit;
  1510. for (list = group->unit_head.next;
  1511. list != &group->unit_head;
  1512. list = list->next) {
  1513. unit = list_entry (list,
  1514. struct amf_unit, unit_list);
  1515. unit->requested_ha_state = 0;
  1516. }
  1517. csi_number = 0;
  1518. }
  1519. void assign_sis (struct amf_group *group)
  1520. {
  1521. int active_sus_needed;
  1522. int standby_sus_needed;
  1523. int inservice_count;
  1524. int units_for_standby;
  1525. int units_for_active;
  1526. int ii_spare;
  1527. int su_active_assign;
  1528. int su_standby_assign;
  1529. int su_spare_assign;
  1530. clear_requested_ha_state (group);
  1531. /*
  1532. * Number of SUs to assign to active or standby state
  1533. */
  1534. inservice_count = (float)unit_inservice_count (group);
  1535. active_sus_needed = div_round (si_count(group),
  1536. group->maximum_active_instances);
  1537. standby_sus_needed = div_round (si_count(group),
  1538. group->maximum_standby_instances);
  1539. units_for_active = inservice_count - group->preferred_standby_units;
  1540. if (units_for_active < 0) {
  1541. units_for_active = 0;
  1542. }
  1543. units_for_standby = inservice_count - group->preferred_active_units;
  1544. if (units_for_standby < 0) {
  1545. units_for_standby = 0;
  1546. }
  1547. ii_spare = inservice_count - group->preferred_active_units - group->preferred_standby_units;
  1548. if (ii_spare < 0) {
  1549. ii_spare = 0;
  1550. }
  1551. /*
  1552. * Determine number of active and standby service units
  1553. * to assign based upon reduction procedure
  1554. */
  1555. if ((inservice_count - active_sus_needed) < 0) {
  1556. printf ("assignment VI - partial assignment with SIs drop outs\n");
  1557. su_active_assign = active_sus_needed;
  1558. su_standby_assign = 0;
  1559. su_spare_assign = 0;
  1560. } else
  1561. if ((inservice_count - active_sus_needed - standby_sus_needed) < 0) {
  1562. printf ("assignment V - partial assignment with reduction of standby units\n");
  1563. su_active_assign = active_sus_needed;
  1564. if (standby_sus_needed > units_for_standby) {
  1565. su_standby_assign = units_for_standby;
  1566. } else {
  1567. su_standby_assign = standby_sus_needed;
  1568. }
  1569. su_spare_assign = 0;
  1570. } else
  1571. if ((group->maximum_standby_instances * units_for_standby) <= si_count (group)) {
  1572. printf ("IV: full assignment with reduction of active service units\n");
  1573. su_active_assign = inservice_count - standby_sus_needed;
  1574. su_standby_assign = standby_sus_needed;
  1575. su_spare_assign = 0;
  1576. } else
  1577. if ((group->maximum_active_instances * units_for_active) <= si_count (group)) {
  1578. printf ("III: full assignment with reduction of standby service units\n");
  1579. su_active_assign = group->preferred_active_units;
  1580. su_standby_assign = units_for_standby;
  1581. su_spare_assign = 0;
  1582. } else
  1583. if (ii_spare == 0) {
  1584. printf ("II: full assignment with spare reduction\n");
  1585. su_active_assign = group->preferred_active_units;
  1586. su_standby_assign = group->preferred_standby_units;
  1587. su_spare_assign = 0;
  1588. } else {
  1589. printf ("I: full assignment with spares\n");
  1590. su_active_assign = group->preferred_active_units;
  1591. su_standby_assign = group->preferred_standby_units;
  1592. su_spare_assign = ii_spare;
  1593. }
  1594. printf ("(inservice=%d) (assigning active=%d) (assigning standby=%d) (assigning spares=%d)\n",
  1595. inservice_count, su_active_assign, su_standby_assign, su_spare_assign);
  1596. assign_nm_active (group, su_active_assign);
  1597. assign_nm_standby (group, su_standby_assign);
  1598. }
  1599. void readiness_state_unit_set (struct amf_unit *unit, OpenaisCfgReadinessStateT readiness_state)
  1600. {
  1601. printf ("Assigning unit %s ",
  1602. getSaNameT (&unit->name));
  1603. printf ("readiness state %s\n",
  1604. readinessstate_ntoa (readiness_state));
  1605. unit->readiness_state = readiness_state;
  1606. assign_sis (unit->amf_group);
  1607. }
  1608. void presence_state_unit_set (struct amf_unit *unit, OpenaisCfgPresenceStateT presence_state)
  1609. {
  1610. printf ("Setting service unit presence state %s\n",
  1611. presencestate_ntoa (presence_state));
  1612. }
  1613. static void escalation_policy_restart (struct amf_comp *comp)
  1614. {
  1615. printf ("escalation_policy_restart %d\n", comp->unit->escalation_level);
  1616. printf ("escalation policy restart uninsint %p\n", comp);
  1617. presence_state_comp_set (
  1618. comp,
  1619. OPENAIS_CFG_PRESENCESTATE_UNINSTANTIATED);
  1620. operational_state_comp_set (
  1621. comp,
  1622. OPENAIS_CFG_OPERATIONALSTATE_DISABLED);
  1623. switch (comp->unit->escalation_level) {
  1624. case ESCALATION_LEVEL_NO_ESCALATION:
  1625. comp_restart (comp);
  1626. break;
  1627. case ESCALATION_LEVEL_ONE:
  1628. comp_restart (comp);
  1629. break;
  1630. case ESCALATION_LEVEL_TWO:
  1631. break;
  1632. case ESCALATION_LEVEL_THREE:
  1633. break;
  1634. }
  1635. }
  1636. static void escalation_policy_cleanup (struct amf_comp *comp)
  1637. {
  1638. // escalation_timer_start (comp);
  1639. switch (comp->unit->escalation_level) {
  1640. case ESCALATION_LEVEL_NO_ESCALATION:
  1641. comp->unit->restart_count += 1;
  1642. if (comp->unit->restart_count >= comp->unit->amf_group->component_restart_max) {
  1643. comp->unit->escalation_level = ESCALATION_LEVEL_ONE;
  1644. escalation_policy_cleanup (comp);
  1645. comp->unit->restart_count = 0;
  1646. return;
  1647. }
  1648. printf ("Escalation level 0 - restart component\n");
  1649. printf ("Cleaning up and restarting component.\n");
  1650. comp_cleanup (comp);
  1651. break;
  1652. case ESCALATION_LEVEL_ONE:
  1653. comp->unit->restart_count += 1;
  1654. if (comp->unit->restart_count >= comp->unit->amf_group->unit_restart_max) {
  1655. comp->unit->escalation_level = ESCALATION_LEVEL_TWO;
  1656. escalation_policy_cleanup (comp);
  1657. return;
  1658. }
  1659. printf ("Escalation level 1 - restart unit\n");
  1660. printf ("Cleaning up and restarting unit.\n");
  1661. unit_cleanup (comp->unit);
  1662. break;
  1663. case ESCALATION_LEVEL_TWO:
  1664. printf ("Escalation level TWO\n");
  1665. unit_cleanup (comp->unit);
  1666. // unit_terminate_failover (comp);
  1667. break;
  1668. case ESCALATION_LEVEL_THREE:
  1669. //TODO
  1670. break;
  1671. }
  1672. }
  1673. static void timer_function_healthcheck_timeout (
  1674. void *data)
  1675. {
  1676. struct healthcheck_active *healthcheck_active =
  1677. (struct healthcheck_active *)data;
  1678. printf ("timeout occured on healthcheck for component %s.\n",
  1679. getSaNameT (&healthcheck_active->comp->name));
  1680. escalation_policy_cleanup (healthcheck_active->comp);
  1681. }
  1682. void healthcheck_activate (struct healthcheck_active *healthcheck_active)
  1683. {
  1684. struct res_lib_amf_healthcheckcallback res_lib_amf_healthcheckcallback;
  1685. healthcheck_active->active = 1;
  1686. // TODO memset (&res_lib_amf_healthcheckcallback, 0, sizeof(res_lib_amf_healthcheckcallback));
  1687. res_lib_amf_healthcheckcallback.header.id = MESSAGE_RES_AMF_HEALTHCHECKCALLBACK;
  1688. res_lib_amf_healthcheckcallback.header.size = sizeof (struct res_lib_amf_healthcheckcallback);
  1689. res_lib_amf_healthcheckcallback.header.error = SA_AIS_OK;
  1690. log_printf (LOG_LEVEL_NOTICE, "sending healthcheck to component %s\n",
  1691. getSaNameT (&healthcheck_active->comp->name));
  1692. res_lib_amf_healthcheckcallback.invocation =
  1693. invocation_create (
  1694. AMF_RESPONSE_HEALTHCHECKCALLBACK,
  1695. (void *)healthcheck_active);
  1696. memcpy (&res_lib_amf_healthcheckcallback.compName,
  1697. &healthcheck_active->comp->name,
  1698. sizeof (SaNameT));
  1699. memcpy (&res_lib_amf_healthcheckcallback.key,
  1700. &healthcheck_active->key,
  1701. sizeof (SaAmfHealthcheckKeyT));
  1702. libais_send_response (healthcheck_active->comp->conn_info->conn_info_partner,
  1703. &res_lib_amf_healthcheckcallback,
  1704. sizeof (struct res_lib_amf_healthcheckcallback));
  1705. poll_timer_delete (aisexec_poll_handle,
  1706. healthcheck_active->timer_healthcheck_duration);
  1707. poll_timer_add (aisexec_poll_handle,
  1708. healthcheck_active->healthcheck->maximum_duration,
  1709. (void *)healthcheck_active,
  1710. timer_function_healthcheck_timeout,
  1711. &healthcheck_active->timer_healthcheck_duration);
  1712. }
  1713. void healthcheck_deactivate (struct healthcheck_active *healthcheck_active)
  1714. {
  1715. log_printf (LOG_LEVEL_NOTICE, "ZZZ deactivating healthcheck for component %s\n",
  1716. getSaNameT (&healthcheck_active->comp->name));
  1717. poll_timer_delete (aisexec_poll_handle,
  1718. healthcheck_active->timer_healthcheck_period);
  1719. poll_timer_delete (aisexec_poll_handle,
  1720. healthcheck_active->timer_healthcheck_duration);
  1721. invocation_destroy_by_data ((void *)healthcheck_active);
  1722. list_del (&healthcheck_active->list);
  1723. free (healthcheck_active);
  1724. }
  1725. static void timer_function_healthcheck_next (
  1726. void *data)
  1727. {
  1728. healthcheck_activate (data);
  1729. }
  1730. void healthcheck_unit_deactivate (
  1731. struct amf_unit *unit)
  1732. {
  1733. struct list_head *list;
  1734. struct list_head *key_list;
  1735. struct healthcheck_active *healthcheck_active;
  1736. struct amf_comp *comp;
  1737. for (list = unit->comp_head.next;
  1738. list != &unit->comp_head;
  1739. list = list->next) {
  1740. comp = list_entry (list, struct amf_comp, comp_list);
  1741. for (key_list = comp->healthcheck_list.next;
  1742. key_list != &comp->healthcheck_list;
  1743. key_list = key_list->next) {
  1744. healthcheck_active = list_entry (key_list,
  1745. struct healthcheck_active, list);
  1746. healthcheck_deactivate (healthcheck_active);
  1747. }
  1748. }
  1749. }
  1750. void healthcheck_unit_activate (
  1751. struct amf_unit *unit)
  1752. {
  1753. struct list_head *list;
  1754. struct list_head *key_list;
  1755. struct healthcheck_active *healthcheck_active;
  1756. struct amf_comp *comp;
  1757. for (list = unit->comp_head.next;
  1758. list != &unit->comp_head;
  1759. list = list->next) {
  1760. comp = list_entry (list, struct amf_comp, comp_list);
  1761. for (key_list = comp->healthcheck_list.next;
  1762. key_list != &comp->healthcheck_list;
  1763. key_list = key_list->next) {
  1764. healthcheck_active = list_entry (key_list,
  1765. struct healthcheck_active, list);
  1766. healthcheck_activate (healthcheck_active);
  1767. }
  1768. }
  1769. }
  1770. void operational_state_unit_set (
  1771. struct amf_unit *unit,
  1772. OpenaisCfgOperationalStateT operational_state)
  1773. {
  1774. if (operational_state == unit->operational_state) {
  1775. printf ("Not assigning service unit new operational state - same state\n");
  1776. return;
  1777. }
  1778. unit->operational_state = operational_state;
  1779. printf ("Service unit operational state set to %s\n",
  1780. operationalstate_ntoa (operational_state));
  1781. if (operational_state == OPENAIS_CFG_OPERATIONALSTATE_ENABLED) {
  1782. readiness_state_unit_set (unit,
  1783. OPENAIS_CFG_READINESSSTATE_INSERVICE);
  1784. /*
  1785. * Start healthcheck now
  1786. */
  1787. // TODO healthcheck_unit_activate (unit);
  1788. } else
  1789. if (operational_state == OPENAIS_CFG_OPERATIONALSTATE_DISABLED) {
  1790. readiness_state_unit_set (unit,
  1791. OPENAIS_CFG_READINESSSTATE_OUTOFSERVICE);
  1792. // ha_state_unit_set (unit, si, SA_AMF_HA_STANDBY);
  1793. // healthcheck_unit_deactivate (unit);
  1794. }
  1795. }
  1796. static int message_handler_req_exec_amf_operational_state_comp_set (
  1797. void *message,
  1798. struct totem_ip_address *address,
  1799. int endian_conversion_required)
  1800. {
  1801. struct req_exec_amf_operational_state_comp_set *req_exec_amf_operational_state_comp_set =
  1802. (struct req_exec_amf_operational_state_comp_set *)message;
  1803. struct amf_comp *comp;
  1804. struct amf_comp *comp_compare;
  1805. struct list_head *list;
  1806. int all_set = 1;
  1807. comp = find_comp (&req_exec_amf_operational_state_comp_set->name);
  1808. comp->operational_state = req_exec_amf_operational_state_comp_set->operational_state;
  1809. printf ("Setting component %s operational state to %s\n",
  1810. getSaNameT (&comp->name),
  1811. operationalstate_ntoa (comp->operational_state));
  1812. /*
  1813. * If all operational states are ENABLED, then SU should be ENABLED
  1814. */
  1815. for (list = comp->unit->comp_head.next;
  1816. list != &comp->unit->comp_head;
  1817. list = list->next) {
  1818. comp_compare = list_entry (list,
  1819. struct amf_comp, comp_list);
  1820. if (comp_compare->operational_state != OPENAIS_CFG_OPERATIONALSTATE_ENABLED) {
  1821. all_set = 0;
  1822. break;
  1823. }
  1824. }
  1825. if (all_set) {
  1826. operational_state_unit_set (comp->unit,
  1827. OPENAIS_CFG_OPERATIONALSTATE_ENABLED);
  1828. } else {
  1829. operational_state_unit_set (comp->unit,
  1830. OPENAIS_CFG_OPERATIONALSTATE_DISABLED);
  1831. }
  1832. readiness_state_comp_set (comp);
  1833. return (0);
  1834. }
  1835. static int message_handler_req_exec_amf_presence_state_comp_set (
  1836. void *message,
  1837. struct totem_ip_address *address,
  1838. int endian_conversion_required)
  1839. {
  1840. struct req_exec_amf_presence_state_comp_set *req_exec_amf_presence_state_comp_set =
  1841. (struct req_exec_amf_presence_state_comp_set *)message;
  1842. struct amf_comp *comp;
  1843. struct amf_comp *comp_compare;
  1844. struct list_head *list;
  1845. int all_set = 1;
  1846. comp = find_comp (&req_exec_amf_presence_state_comp_set->name);
  1847. if (req_exec_amf_presence_state_comp_set->presence_state == comp->presence_state) {
  1848. printf ("duplicate presence state set, not setting presence state\n");
  1849. return (0);
  1850. }
  1851. if (req_exec_amf_presence_state_comp_set->presence_state == OPENAIS_CFG_PRESENCESTATE_UNINSTANTIATED) {
  1852. comp->conn_info = 0;
  1853. }
  1854. /*
  1855. * The restarting state can only be entered from the uninstantiated state
  1856. */
  1857. if (req_exec_amf_presence_state_comp_set->presence_state == OPENAIS_CFG_PRESENCESTATE_RESTARTING &&
  1858. comp->presence_state != OPENAIS_CFG_PRESENCESTATE_UNINSTANTIATED) {
  1859. printf ("restart presence state set even though not in terminating state\n");
  1860. return (0);
  1861. }
  1862. comp->presence_state = req_exec_amf_presence_state_comp_set->presence_state;
  1863. if (comp->presence_state == OPENAIS_CFG_PRESENCESTATE_RESTARTING) {
  1864. printf ("SET TO RESTARTING instantiating now\n");
  1865. clc_instantiate (comp);
  1866. }
  1867. printf ("Setting component %s presence state %s\n",
  1868. getSaNameT (&comp->name),
  1869. presencestate_ntoa (comp->presence_state));
  1870. /*
  1871. * Restart components that are requested to enter the restarting presence state
  1872. */
  1873. /*
  1874. * If all comp presence states are INSTANTIATED, then SU should be instantated
  1875. */
  1876. for (list = comp->unit->comp_head.next;
  1877. list != &comp->unit->comp_head;
  1878. list = list->next) {
  1879. comp_compare = list_entry (list,
  1880. struct amf_comp, comp_list);
  1881. if (comp_compare->presence_state != OPENAIS_CFG_PRESENCESTATE_INSTANTIATED) {
  1882. all_set = 0;
  1883. break;
  1884. }
  1885. }
  1886. if (all_set) {
  1887. presence_state_unit_set (comp->unit,
  1888. OPENAIS_CFG_PRESENCESTATE_INSTANTIATED);
  1889. }
  1890. return (0);
  1891. }
  1892. static int message_handler_req_exec_amf_administrative_state_csi_set (
  1893. void *message,
  1894. struct totem_ip_address *address,
  1895. int endian_conversion_required)
  1896. {
  1897. // struct req_exec_amf_administrative_state_csi_set *req_exec_amf_administrative_state_csi_set =
  1898. // (struct req_exec_amf_administrative_state_csi_set *)message;
  1899. // TODO
  1900. return (0);
  1901. }
  1902. static int message_handler_req_exec_amf_administrative_state_unit_set (
  1903. void *message,
  1904. struct totem_ip_address *address,
  1905. int endian_conversion_required)
  1906. {
  1907. // struct req_exec_amf_administrative_state_unit_set *req_exec_amf_administrative_state_unit_set =
  1908. // (struct req_exec_amf_administrative_state_unit_set *)message;
  1909. // TODO
  1910. return (0);
  1911. }
  1912. static int message_handler_req_exec_amf_administrative_state_group_set (
  1913. void *message,
  1914. struct totem_ip_address *source,
  1915. int endian_conversion_required)
  1916. {
  1917. // struct req_exec_amf_administrative_state_group_set *req_exec_amf_administrative_state_group_set =
  1918. // (struct req_exec_amf_administrative_state_group_set *)message;
  1919. // TODO
  1920. return (0);
  1921. }
  1922. /*
  1923. * Library Interface Implementation
  1924. */
  1925. static int message_handler_req_lib_amf_componentregister (struct conn_info *conn_info, void *message)
  1926. {
  1927. struct req_lib_amf_componentregister *req_lib_amf_componentregister =
  1928. (struct req_lib_amf_componentregister *)message;
  1929. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  1930. struct amf_comp *comp;
  1931. SaAisErrorT error = SA_AIS_ERR_NOT_EXIST;
  1932. comp = find_comp (&req_lib_amf_componentregister->compName);
  1933. if (comp) {
  1934. presence_state_comp_set (comp,
  1935. OPENAIS_CFG_PRESENCESTATE_INSTANTIATED);
  1936. operational_state_comp_set (comp,
  1937. OPENAIS_CFG_OPERATIONALSTATE_ENABLED);
  1938. comp->conn_info = conn_info;
  1939. comp->conn_info->ais_ci.u.libamf_ci.comp = comp;
  1940. comp_healthcheck_activate (comp);
  1941. error = SA_AIS_OK;
  1942. }
  1943. res_lib_amf_componentregister.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  1944. res_lib_amf_componentregister.header.size = sizeof (struct res_lib_amf_componentregister);
  1945. res_lib_amf_componentregister.header.error = error;
  1946. libais_send_response (conn_info, &res_lib_amf_componentregister,
  1947. sizeof (struct res_lib_amf_componentregister));
  1948. return (0);
  1949. }
  1950. static int message_handler_req_lib_amf_componentunregister (struct conn_info *conn_info, void *message)
  1951. {
  1952. #ifdef COMPILE_OUT
  1953. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  1954. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  1955. struct iovec iovec;
  1956. struct amf_comp *component;
  1957. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componentunregister()\n");
  1958. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  1959. req_exec_amf_componentunregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER;
  1960. message_source_set (&req_exec_amf_componentunregister.source, conn_info);
  1961. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  1962. req_lib_amf_componentunregister,
  1963. sizeof (struct req_lib_amf_componentunregister));
  1964. component = find_comp (&req_lib_amf_componentunregister->compName);
  1965. if (component && component->registered && component->local) {
  1966. // component->probableCause = SA_AMF_NOT_RESPONDING;
  1967. }
  1968. iovec.iov_base = (char *)&req_exec_amf_componentunregister;
  1969. iovec.iov_len = sizeof (req_exec_amf_componentunregister);
  1970. assert (totempg_groups_mcast_joined (openais_group_handle,
  1971. &iovec, 1, TOTEMPG_AGREED) == 0);
  1972. #endif
  1973. return (0);
  1974. }
  1975. static int message_handler_req_lib_amf_pmstart (struct conn_info *conn_info, void *message)
  1976. {
  1977. return (0);
  1978. }
  1979. static int message_handler_req_lib_amf_pmstop (struct conn_info *conn_info, void *message)
  1980. {
  1981. return (0);
  1982. }
  1983. static int message_handler_req_lib_amf_healthcheckstart (struct conn_info *conn_info, void *message)
  1984. {
  1985. struct req_lib_amf_healthcheckstart *req_lib_amf_healthcheckstart =
  1986. (struct req_lib_amf_healthcheckstart *)message;
  1987. struct res_lib_amf_healthcheckstart res_lib_amf_healthcheckstart;
  1988. struct amf_healthcheck *healthcheck;
  1989. struct healthcheck_active *healthcheck_active;
  1990. struct amf_comp *comp;
  1991. SaErrorT error = SA_AIS_OK;
  1992. printf ("healthcheck start\n");
  1993. fflush (stdout);
  1994. healthcheck = find_healthcheck (&req_lib_amf_healthcheckstart->healthcheckKey);
  1995. if (healthcheck == 0) {
  1996. error = SA_AIS_ERR_NOT_EXIST;
  1997. }
  1998. comp = find_comp (&req_lib_amf_healthcheckstart->compName);
  1999. if (comp == 0) {
  2000. error = SA_AIS_ERR_NOT_EXIST;
  2001. goto error_exit;
  2002. }
  2003. /*
  2004. * Determine if this healthcheck is already active
  2005. */
  2006. healthcheck_active = find_healthcheck_active (
  2007. comp,
  2008. &req_lib_amf_healthcheckstart->healthcheckKey,
  2009. req_lib_amf_healthcheckstart->invocationType);
  2010. if (healthcheck_active) {
  2011. error = SA_AIS_ERR_EXIST;
  2012. goto error_exit;
  2013. }
  2014. healthcheck_active = malloc (sizeof (struct healthcheck_active));
  2015. if (healthcheck_active == 0) {
  2016. error = SA_AIS_ERR_NO_MEMORY;
  2017. goto error_exit;
  2018. }
  2019. /*
  2020. * Make new instance of healthcheck key
  2021. */
  2022. list_init (&healthcheck_active->list);
  2023. memcpy (&healthcheck_active->key,
  2024. &req_lib_amf_healthcheckstart->healthcheckKey,
  2025. sizeof (SaAmfHealthcheckKeyT));
  2026. healthcheck_active->comp = comp;
  2027. healthcheck_active->invocationType = req_lib_amf_healthcheckstart->invocationType;
  2028. healthcheck_active->healthcheck = healthcheck;
  2029. healthcheck_active->timer_healthcheck_duration = 0;
  2030. healthcheck_active->timer_healthcheck_period = 0;
  2031. healthcheck_active->active = 0;
  2032. list_add_tail (&healthcheck_active->list, &comp->healthcheck_list);
  2033. if (comp->conn_info != 0) {
  2034. printf ("Activating healthcheck for the first time %p\n", healthcheck_active);
  2035. healthcheck_activate (healthcheck_active);
  2036. }
  2037. #ifdef TODO
  2038. do we want to do healtchecking only when full su has registered or also of non-fully registered sus
  2039. if (comp->unit->operational_state == OPENAIS_CFG_OPERATIONALSTATE_ENABLED) {
  2040. /*
  2041. * Start healthcheck now
  2042. */
  2043. healthcheck_unit_activate (comp->unit);
  2044. }
  2045. #endif
  2046. error_exit:
  2047. res_lib_amf_healthcheckstart.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTART;
  2048. res_lib_amf_healthcheckstart.header.size = sizeof (struct res_lib_amf_healthcheckstart);
  2049. res_lib_amf_healthcheckstart.header.error = error;
  2050. libais_send_response (conn_info, &res_lib_amf_healthcheckstart,
  2051. sizeof (struct res_lib_amf_healthcheckstart));
  2052. return (0);
  2053. }
  2054. static int message_handler_req_lib_amf_healthcheckconfirm (struct conn_info *conn_info, void *message)
  2055. {
  2056. return (0);
  2057. }
  2058. static int message_handler_req_lib_amf_healthcheckstop (struct conn_info *conn_info, void *message)
  2059. {
  2060. struct req_lib_amf_healthcheckstop *req_lib_amf_healthcheckstop =
  2061. (struct req_lib_amf_healthcheckstop *)message;
  2062. struct res_lib_amf_healthcheckstop res_lib_amf_healthcheckstop;
  2063. struct healthcheck_active *healthcheck_active;
  2064. struct amf_comp *comp;
  2065. SaErrorT error = SA_AIS_OK;
  2066. printf ("healthcheck stop\n");
  2067. comp = find_comp (&req_lib_amf_healthcheckstop->compName);
  2068. if (comp == 0) {
  2069. error = SA_AIS_ERR_NOT_EXIST;
  2070. goto error_exit;
  2071. }
  2072. healthcheck_active = find_healthcheck_active (
  2073. comp,
  2074. &req_lib_amf_healthcheckstop->healthcheckKey,
  2075. INVOCATION_DONT_COMPARE);
  2076. printf ("active %p\n", healthcheck_active);
  2077. if (healthcheck_active == 0) {
  2078. error = SA_AIS_ERR_NOT_EXIST;
  2079. goto error_exit;
  2080. }
  2081. healthcheck_deactivate (healthcheck_active);
  2082. error_exit:
  2083. printf ("healthcheck stop\n");
  2084. res_lib_amf_healthcheckstop.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTOP;
  2085. res_lib_amf_healthcheckstop.header.size = sizeof (struct res_lib_amf_healthcheckstop);
  2086. res_lib_amf_healthcheckstop.header.error = error;
  2087. libais_send_response (conn_info, &res_lib_amf_healthcheckstop,
  2088. sizeof (struct res_lib_amf_healthcheckstop));
  2089. return (0);
  2090. }
  2091. static int message_handler_req_lib_amf_hastateget (struct conn_info *conn_info, void *message)
  2092. {
  2093. #ifdef COMPILE_OUT
  2094. struct req_lib_amf_hastateget *req_lib_amf_hastateget = (struct req_lib_amf_hastateget *)message;
  2095. struct res_lib_amf_hastateget res_lib_amf_hastateget;
  2096. struct amf_comp *component;
  2097. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_hastateget()\n");
  2098. res_lib_amf_hastateget.header.id = MESSAGE_RES_AMF_HASTATEGET;
  2099. res_lib_amf_hastateget.header.size = sizeof (struct res_lib_amf_hastateget);
  2100. res_lib_amf_hastateget.header.error = SA_ERR_NOT_EXIST;
  2101. #ifdef COMPILE_OUT
  2102. component = component_in_protectiongroup_find (&req_lib_amf_hastateget->csiName, &req_lib_amf_hastateget->compName);
  2103. #endif
  2104. if (component) {
  2105. memcpy (&res_lib_amf_hastateget.haState,
  2106. &component->currentHAState, sizeof (SaAmfHAStateT));
  2107. res_lib_amf_hastateget.header.error = SA_OK;
  2108. }
  2109. libais_send_response (conn_info, &res_lib_amf_hastateget, sizeof (struct res_lib_amf_hastateget));
  2110. #endif
  2111. return (0);
  2112. }
  2113. static int message_handler_req_lib_amf_protectiongrouptrackstart (struct conn_info *conn_info, void *message)
  2114. {
  2115. #ifdef COMPILE_OUT
  2116. struct req_lib_amf_protectiongrouptrackstart *req_lib_amf_protectiongrouptrackstart = (struct req_lib_amf_protectiongrouptrackstart *)message;
  2117. struct res_lib_amf_protectiongrouptrackstart res_lib_amf_protectiongrouptrackstart;
  2118. struct libamf_ci_trackentry *track = 0;
  2119. int i;
  2120. struct saAmfProtectionGroup *amfProtectionGroup;
  2121. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrackstart()\n");
  2122. amfProtectionGroup = protectiongroup_find (&req_lib_amf_protectiongrouptrackstart->csiName);
  2123. if (amfProtectionGroup) {
  2124. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstart: Got valid track start on CSI: %s.\n", getSaNameT (&req_lib_amf_protectiongrouptrackstart->csiName));
  2125. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  2126. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) {
  2127. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2128. break;
  2129. }
  2130. }
  2131. if (track == 0) {
  2132. grow_amf_track_table (conn_info, 1);
  2133. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2134. }
  2135. track->active = 1;
  2136. track->trackFlags = req_lib_amf_protectiongrouptrackstart->trackFlags;
  2137. track->notificationBufferAddress = req_lib_amf_protectiongrouptrackstart->notificationBufferAddress;
  2138. memcpy (&track->csiName,
  2139. &req_lib_amf_protectiongrouptrackstart->csiName, sizeof (SaNameT));
  2140. conn_info->ais_ci.u.libamf_ci.trackActive += 1;
  2141. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  2142. /*
  2143. * If SA_TRACK_CURRENT is specified, write out all current connections
  2144. */
  2145. } else {
  2146. log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
  2147. }
  2148. res_lib_amf_protectiongrouptrackstart.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART;
  2149. res_lib_amf_protectiongrouptrackstart.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstart);
  2150. res_lib_amf_protectiongrouptrackstart.header.error = SA_ERR_NOT_EXIST;
  2151. if (amfProtectionGroup) {
  2152. res_lib_amf_protectiongrouptrackstart.header.error = SA_OK;
  2153. }
  2154. libais_send_response (conn_info, &res_lib_amf_protectiongrouptrackstart,
  2155. sizeof (struct res_lib_amf_protectiongrouptrackstart));
  2156. if (amfProtectionGroup &&
  2157. req_lib_amf_protectiongrouptrackstart->trackFlags & SA_TRACK_CURRENT) {
  2158. protectiongroup_notification_send (conn_info,
  2159. track->notificationBufferAddress,
  2160. amfProtectionGroup,
  2161. 0,
  2162. 0,
  2163. SA_TRACK_CHANGES_ONLY);
  2164. track->trackFlags &= ~SA_TRACK_CURRENT;
  2165. }
  2166. #endif
  2167. return (0);
  2168. }
  2169. static int message_handler_req_lib_amf_csiquiescingcomplete (struct conn_info *conn_info, void *message)
  2170. {
  2171. return (0);
  2172. }
  2173. static int message_handler_req_lib_amf_protectiongrouptrackstop (struct conn_info *conn_info, void *message)
  2174. {
  2175. #ifdef COMPILE_OUT
  2176. struct req_lib_amf_protectiongrouptrackstop *req_lib_amf_protectiongrouptrackstop = (struct req_lib_amf_protectiongrouptrackstop *)message;
  2177. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  2178. struct libamf_ci_trackentry *track = 0;
  2179. int i;
  2180. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrackstop()\n");
  2181. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  2182. if (name_match (&req_lib_amf_protectiongrouptrackstop->csiName,
  2183. &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) {
  2184. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2185. }
  2186. }
  2187. if (track) {
  2188. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_lib_amf_protectiongrouptrackstop->csiName));
  2189. memset (track, 0, sizeof (struct libamf_ci_trackentry));
  2190. conn_info->ais_ci.u.libamf_ci.trackActive -= 1;
  2191. if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) {
  2192. list_del (&conn_info->conn_list);
  2193. }
  2194. }
  2195. res_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
  2196. res_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstop);
  2197. res_lib_amf_protectiongrouptrackstop.header.error = SA_ERR_NOT_EXIST;
  2198. if (track) {
  2199. res_lib_amf_protectiongrouptrackstop.header.error = SA_OK;
  2200. }
  2201. libais_send_response (conn_info, &res_lib_amf_protectiongrouptrackstop,
  2202. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  2203. #endif
  2204. return (0);
  2205. }
  2206. static int message_handler_req_lib_amf_componenterrorreport (struct conn_info *conn_info, void *message)
  2207. {
  2208. struct req_lib_amf_componenterrorreport *req_lib_amf_componenterrorreport = (struct req_lib_amf_componenterrorreport *)message;
  2209. struct res_lib_amf_componenterrorreport res_lib_amf_componenterrorreport;
  2210. struct amf_comp *comp;
  2211. SaAisErrorT error = SA_AIS_ERR_NOT_EXIST;
  2212. log_printf (LOG_LEVEL_NOTICE, "Handle : message_handler_req_lib_amf_componenterrorreport()\n");
  2213. printf ("ERROR REPORT\n");
  2214. comp = find_comp (&req_lib_amf_componenterrorreport->erroneousComponent);
  2215. if (comp) {
  2216. printf ("escalation policy terminate\n");
  2217. escalation_policy_cleanup (comp);
  2218. error = SA_AIS_OK;
  2219. }
  2220. res_lib_amf_componenterrorreport.header.size = sizeof (struct res_lib_amf_componenterrorreport);
  2221. res_lib_amf_componenterrorreport.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT;
  2222. res_lib_amf_componenterrorreport.header.error = error;
  2223. libais_send_response (
  2224. conn_info,
  2225. &res_lib_amf_componenterrorreport,
  2226. sizeof (struct res_lib_amf_componenterrorreport));
  2227. return (0);
  2228. }
  2229. static int message_handler_req_lib_amf_componenterrorclear (struct conn_info *conn_info, void *message)
  2230. {
  2231. #ifdef COMPILLE_OUT
  2232. struct req_lib_amf_componenterrorclear *req_lib_amf_componenterrorclear = (struct req_lib_amf_componenterrorclear *)message;
  2233. struct req_exec_amf_componenterrorclear req_exec_amf_componenterrorclear;
  2234. struct iovec iovec;
  2235. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componenterrorclear()\n");
  2236. req_exec_amf_componenterrorclear.header.size = sizeof (struct req_exec_amf_componenterrorclear);
  2237. req_exec_amf_componenterrorclear.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTERRORCLEAR;
  2238. message_source_set (&req_exec_amf_componenterrorclear.source, conn_info);
  2239. memcpy (&req_exec_amf_componenterrorclear.req_lib_amf_componenterrorclear,
  2240. req_lib_amf_componenterrorclear,
  2241. sizeof (struct req_lib_amf_componenterrorclear));
  2242. iovec.iov_base = (char *)&req_exec_amf_componenterrorclear;
  2243. iovec.iov_len = sizeof (req_exec_amf_componenterrorclear);
  2244. assert (totempg_groups_mcast_joined (openais_group_handle,
  2245. &iovec, 1, TOTEMPG_AGREED) == 0);
  2246. #endif
  2247. return (0);
  2248. }
  2249. void pg_comp_create (
  2250. struct amf_pg *pg,
  2251. struct amf_csi *csi,
  2252. struct amf_comp *comp)
  2253. {
  2254. struct amf_pg_comp *pg_comp;
  2255. printf ("creating component for pg\n");
  2256. pg_comp = malloc (sizeof (struct amf_pg_comp));
  2257. assert (pg_comp);
  2258. pg_comp->comp = comp;
  2259. pg_comp->csi = csi;
  2260. list_init (&pg_comp->list);
  2261. list_add_tail (&pg_comp->list, &pg->pg_comp_head);
  2262. }
  2263. static int message_handler_req_lib_amf_response (struct conn_info *conn_info_nouse, void *message)
  2264. {
  2265. struct req_lib_amf_response *req_lib_amf_response = (struct req_lib_amf_response *)message;
  2266. struct res_lib_amf_response res_lib_amf_response;
  2267. struct conn_info *conn_info;
  2268. struct csi_set_callback_data *csi_set_callback_data;
  2269. struct csi_remove_callback_data *csi_remove_callback_data;
  2270. struct component_terminate_callback_data *component_terminate_callback_data;
  2271. struct healthcheck_active *healthcheck_active;
  2272. int interface;
  2273. int res;
  2274. void *data;
  2275. SaAisErrorT error = SA_AIS_OK;
  2276. log_printf (LOG_LEVEL_DEBUG, "message_handler_req_lib_amf_response()\n");
  2277. res = invocation_get_and_destroy (req_lib_amf_response->invocation,
  2278. &interface, &data);
  2279. if (res == -1) {
  2280. printf ("invocation not found\n");
  2281. error = SA_AIS_ERR_NOT_EXIST;
  2282. goto error_exit;
  2283. }
  2284. log_printf (LOG_LEVEL_DEBUG, "handling response connection %p interface %x\n", conn_info, interface);
  2285. switch (interface) {
  2286. case AMF_RESPONSE_HEALTHCHECKCALLBACK:
  2287. healthcheck_active = (struct healthcheck_active *)data;
  2288. poll_timer_delete (aisexec_poll_handle,
  2289. healthcheck_active->timer_healthcheck_duration);
  2290. healthcheck_active->timer_healthcheck_duration = 0;
  2291. poll_timer_add (aisexec_poll_handle,
  2292. healthcheck_active->healthcheck->period,
  2293. (void *)healthcheck_active,
  2294. timer_function_healthcheck_next,
  2295. &healthcheck_active->timer_healthcheck_period);
  2296. break;
  2297. case AMF_RESPONSE_CSISETCALLBACK:
  2298. csi_set_callback_data = (struct csi_set_callback_data *)data;
  2299. printf ("csi callback executed from library.\n");
  2300. csi_set_callback_data->comp->ha_state =
  2301. csi_set_callback_data->comp->unit->requested_ha_state;
  2302. // list_add (&csi_set_callback_data->comp->
  2303. /*
  2304. pg_comp_create (
  2305. csi_set_callback_data->pg,
  2306. csi_set_callback_data->csi,
  2307. csi_set_callback_data->comp);
  2308. */
  2309. free (csi_set_callback_data);
  2310. break;
  2311. case AMF_RESPONSE_CSIREMOVECALLBACK:
  2312. csi_remove_callback_data = (struct csi_remove_callback_data *)data;
  2313. printf ("response from removing the CSI\n");
  2314. // AAAA
  2315. list_del (&csi_remove_callback_data->csi->si->unit_list);
  2316. list_del (&csi_remove_callback_data->csi->list);
  2317. free (csi_remove_callback_data);
  2318. break;
  2319. case AMF_RESPONSE_COMPONENTTERMINATECALLBACK:
  2320. component_terminate_callback_data = (struct component_terminate_callback_data *)data;
  2321. printf ("response from terminating component\n");
  2322. comp_healthcheck_deactivate (component_terminate_callback_data->comp);
  2323. escalation_policy_restart (component_terminate_callback_data->comp);
  2324. break;
  2325. default:
  2326. // TODO
  2327. log_printf (LOG_LEVEL_ERROR, "invalid invocation value %x\n", req_lib_amf_response->invocation);
  2328. break;
  2329. }
  2330. error_exit:
  2331. res_lib_amf_response.header.id = MESSAGE_RES_AMF_RESPONSE;
  2332. res_lib_amf_response.header.size = sizeof (struct res_lib_amf_response);
  2333. res_lib_amf_response.header.error = SA_AIS_OK;
  2334. libais_send_response (conn_info_nouse,
  2335. &res_lib_amf_response,
  2336. sizeof (struct res_lib_amf_response));
  2337. return (0);
  2338. }
  2339. #ifdef COMPILE_OUT
  2340. /*
  2341. * Executive Message Implementation
  2342. */
  2343. static int message_handler_req_exec_amf_componentregister (void *message, struct in_addr source_addr, int endian_conversion_required)
  2344. {
  2345. #ifdef COMPILE_OUT
  2346. struct req_exec_amf_componentregister *req_exec_amf_componentregister = (struct req_exec_amf_componentregister *)message;
  2347. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  2348. struct amf_comp *component;
  2349. struct amf_comp *amfProxyComponent;
  2350. SaErrorT error;
  2351. log_printf (LOG_LEVEL_FROM_GMI, "Executive: ComponentRegister for component %s\n",
  2352. getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName));
  2353. /*
  2354. * Determine if proxy isn't registered
  2355. */
  2356. error = SA_OK;
  2357. component = find_comp (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName);
  2358. amfProxyComponent = find_comp (&req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName);
  2359. /*
  2360. * If a node is joining menber ship ,Component States Synchronize
  2361. */
  2362. if (req_exec_amf_componentregister->source.in_addr.s_addr == 0) {
  2363. amf_synchronize (message, source_addr);
  2364. return (0);
  2365. }
  2366. /*
  2367. * If component not in configuration files, return error
  2368. */
  2369. if (component == 0) {
  2370. error = SA_ERR_NOT_EXIST;
  2371. }
  2372. /*
  2373. * If proxy doesn't exist and isn't registered, return error
  2374. */
  2375. if ((amfProxyComponent == 0 &&
  2376. req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) ||
  2377. (amfProxyComponent && amfProxyComponent->registered == 0)) {
  2378. error = SA_ERR_NOT_EXIST;
  2379. }
  2380. /*
  2381. * If component already registered, return error
  2382. */
  2383. if (error == SA_OK) {
  2384. if (component->registered) {
  2385. error = SA_ERR_EXIST;
  2386. }
  2387. }
  2388. /*
  2389. * Finally register component and setup links for proxy if
  2390. * proxy present
  2391. */
  2392. if (error == SA_OK) {
  2393. component->local = 0;
  2394. component->registered = 1;
  2395. component->conn_info = req_exec_amf_componentregister->source.conn_info;
  2396. component->source_addr = source_addr;
  2397. // component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  2398. // component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  2399. component->currentHAState = 0;
  2400. component->newHAState = 0;
  2401. component->probableCause = 0;
  2402. component->enabledUnlockedState = 0;
  2403. component->disabledUnlockedState = 0;
  2404. component->healthcheck_outstanding = 0;
  2405. if (req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) {
  2406. component->saAmfProxyComponent = amfProxyComponent;
  2407. }
  2408. }
  2409. /*
  2410. * If this node originated the request to the cluster, respond back
  2411. * to the AMF library
  2412. */
  2413. if (message_source_is_local(&req_exec_amf_componentregister->source)) {
  2414. if (error == SA_OK) {
  2415. component->local = 1;
  2416. req_exec_amf_componentregister->source.conn_info->component = component;
  2417. }
  2418. log_printf (LOG_LEVEL_DEBUG, "sending component register response to fd %d\n",
  2419. req_exec_amf_componentregister->source.conn_info->fd);
  2420. res_lib_amf_componentregister.header.size = sizeof (struct res_lib_amf_componentregister);
  2421. res_lib_amf_componentregister.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  2422. res_lib_amf_componentregister.header.error = error;
  2423. libais_send_response (req_exec_amf_componentregister->source.conn_info,
  2424. &res_lib_amf_componentregister,
  2425. sizeof (struct res_lib_amf_componentregister));
  2426. }
  2427. /*
  2428. * If no error on registration, determine if we should enter new state
  2429. */
  2430. if (error == SA_OK) {
  2431. dsm (component);
  2432. }
  2433. #endif
  2434. return (0);
  2435. }
  2436. static int message_handler_req_exec_amf_componentunregister (void *message, struct in_addr source_addr, int endian_conversion_required)
  2437. {
  2438. struct req_exec_amf_componentunregister *req_exec_amf_componentunregister = (struct req_exec_amf_componentunregister *)message;
  2439. struct res_lib_amf_componentunregister res_lib_amf_componentunregister;
  2440. struct amf_comp *component;
  2441. struct amf_comp *amfProxyComponent;
  2442. SaErrorT error;
  2443. log_printf (LOG_LEVEL_FROM_GMI, "Executive: Component_unregister for %s\n",
  2444. getSaNameT (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName));
  2445. component = find_comp (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName);
  2446. amfProxyComponent = find_comp (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName);
  2447. /*
  2448. * Check for proxy and component not existing in system
  2449. */
  2450. error = SA_OK;
  2451. if (component == 0) {
  2452. error = SA_ERR_NOT_EXIST;
  2453. }
  2454. if (req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName.length > 0) {
  2455. if (amfProxyComponent) {
  2456. if (amfProxyComponent->registered == 0) {
  2457. error = SA_ERR_NOT_EXIST;
  2458. }
  2459. } else {
  2460. error = SA_ERR_NOT_EXIST;
  2461. }
  2462. }
  2463. /*
  2464. * If there is a proxycompname, make sure it is the proxy
  2465. * of compName
  2466. */
  2467. if (error == SA_OK && amfProxyComponent) {
  2468. if (component->saAmfProxyComponent != amfProxyComponent) {
  2469. error = SA_ERR_BAD_OPERATION;
  2470. }
  2471. }
  2472. /*
  2473. * Finally unregister the component
  2474. */
  2475. if (error == SA_OK) {
  2476. component->registered = 0;
  2477. // dsmEnabledUnlockedTransitionDisabledUnlocked (component);
  2478. }
  2479. /*
  2480. * If this node originated the request to the cluster, respond back
  2481. * to the AMF library
  2482. */
  2483. if (message_source_is_local (&req_exec_amf_componentunregister->source)) {
  2484. log_printf (LOG_LEVEL_DEBUG, "sending component unregister response to fd %d\n",
  2485. req_exec_amf_componentunregister->source.conn_info->fd);
  2486. res_lib_amf_componentunregister.header.size = sizeof (struct res_lib_amf_componentunregister);
  2487. res_lib_amf_componentunregister.header.id = MESSAGE_RES_AMF_COMPONENTUNREGISTER;
  2488. res_lib_amf_componentunregister.header.error = error;
  2489. libais_send_response (req_exec_amf_componentunregister->source.conn_info,
  2490. &res_lib_amf_componentunregister, sizeof (struct res_lib_amf_componentunregister));
  2491. }
  2492. return (0);
  2493. }
  2494. static int message_handler_req_exec_amf_componenterrorreport (void *message, struct in_addr source_addr, int endian_conversion_required)
  2495. {
  2496. struct req_exec_amf_componenterrorreport *req_exec_amf_componenterrorreport = (struct req_exec_amf_componenterrorreport *)message;
  2497. struct res_lib_amf_componenterrorreport res_lib_amf_componenterrorreport;
  2498. struct amf_comp *comp;
  2499. SaErrorT error = SA_AIS_OK;
  2500. log_printf (LOG_LEVEL_NOTICE, "Executive: ErrorReport for %s\n",
  2501. getSaNameT (&req_exec_amf_componenterrorreport->req_lib_amf_componenterrorreport.erroneousComponent));
  2502. comp = find_comp (&req_exec_amf_componenterrorreport->req_lib_amf_componenterrorreport.erroneousComponent);
  2503. if (comp == 0) {
  2504. error = SA_AIS_ERR_NOT_EXIST;
  2505. }
  2506. /*
  2507. * If this node originated the request to the cluster, respond back
  2508. * to the AMF library
  2509. */
  2510. if (message_source_is_local (&req_exec_amf_componenterrorreport->source)) {
  2511. log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n",
  2512. req_exec_amf_componenterrorreport->source.conn_info->fd);
  2513. if (comp) {
  2514. }
  2515. res_lib_amf_componenterrorreport.header.size = sizeof (struct res_lib_amf_componenterrorreport);
  2516. res_lib_amf_componenterrorreport.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT;
  2517. res_lib_amf_componenterrorreport.header.error = error;
  2518. libais_send_response (req_exec_amf_componenterrorreport->source.conn_info,
  2519. &res_lib_amf_componenterrorreport, sizeof (struct res_lib_amf_componenterrorreport));
  2520. }
  2521. return (0);
  2522. }
  2523. static int message_handler_req_exec_amf_componenterrorclear (void *message, struct in_addr source_addr, int endian_conversion_required)
  2524. {
  2525. struct req_exec_amf_componenterrorclear *req_exec_amf_componenterrorclear = (struct req_exec_amf_componenterrorclear *)message;
  2526. struct res_lib_amf_componenterrorclear res_lib_amf_componenterrorclear;
  2527. struct amf_comp *component;
  2528. SaErrorT error = SA_ERR_BAD_OPERATION;
  2529. #ifdef COMPILE_OUT
  2530. log_printf (LOG_LEVEL_FROM_GMI, "Executive: ErrorCancelAll for %s\n",
  2531. getSaNameT (&req_exec_amf_componenterrorclear->req_lib_amf_componenterrorclear.compName));
  2532. component = find_comp (&req_exec_amf_componenterrorclear->req_lib_amf_componenterrorclear.compName);
  2533. if (component && component->registered) {
  2534. /*
  2535. * Mark component in service if its a AMF service
  2536. * connected to this aisexec
  2537. */
  2538. if (component->probableCause) {
  2539. component->probableCause = 0;
  2540. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  2541. dsm (component);
  2542. }
  2543. error = SA_OK;
  2544. }
  2545. /*
  2546. * If this node originated the request to the cluster, respond back
  2547. * to the AMF library
  2548. */
  2549. if (message_source_is_local (&req_exec_amf_componenterrorclear->source)) {
  2550. log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n",
  2551. req_exec_amf_componenterrorclear->source.conn_info->fd);
  2552. res_lib_amf_componenterrorclear.header.size = sizeof (struct res_lib_amf_componenterrorclear);
  2553. res_lib_amf_componenterrorclear.header.id = MESSAGE_RES_AMF_COMPONENTERRORCLEAR;
  2554. res_lib_amf_componenterrorclear.header.error = error;
  2555. libais_send_response (req_exec_amf_componenterrorclear->source.conn_info,
  2556. &res_lib_amf_componenterrorclear, sizeof (struct res_lib_amf_componenterrorclear));
  2557. }
  2558. #endif
  2559. return (0);
  2560. }
  2561. #endif
  2562. #ifdef COMPILE_OUT
  2563. static void grow_amf_track_table (struct conn_info *conn_info, int growby)
  2564. {
  2565. struct libamf_ci_trackentry *tracks;
  2566. int newsize;
  2567. int currsize = conn_info->ais_ci.u.libamf_ci.trackEntries;
  2568. newsize = growby + currsize;
  2569. if (newsize > currsize) {
  2570. tracks = (struct libamf_ci_trackentry *)mempool_realloc (conn_info->ais_ci.u.libamf_ci.tracks,
  2571. (newsize) * sizeof (struct libamf_ci_trackentry));
  2572. if (tracks == 0) {
  2573. #ifdef DEBUG
  2574. printf ("grow_amf_track_table: out of memory, woops\n");
  2575. #endif
  2576. // TODO
  2577. exit (1);
  2578. }
  2579. memset (&tracks[currsize], 0, growby * sizeof (struct libamf_ci_trackentry));
  2580. conn_info->ais_ci.u.libamf_ci.trackEntries = newsize;
  2581. conn_info->ais_ci.u.libamf_ci.tracks = tracks;
  2582. }
  2583. }
  2584. static void component_unregister (
  2585. struct amf_comp *component)
  2586. {
  2587. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  2588. struct iovec iovec;
  2589. /*
  2590. * This only works on local components
  2591. */
  2592. if (component == 0 || component->local != 1) {
  2593. return;
  2594. }
  2595. log_printf (LOG_LEVEL_ENTER_FUNC, "component_unregister: unregistering component %s\n",
  2596. getSaNameT (&component->name));
  2597. component->probableCause = SA_AMF_NOT_RESPONDING;
  2598. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  2599. req_exec_amf_componentunregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER;
  2600. req_exec_amf_componentunregister.source.conn_info = 0;
  2601. req_exec_amf_componentunregister.source.in_addr.s_addr = 0;
  2602. memset (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  2603. 0, sizeof (struct req_lib_amf_componentunregister));
  2604. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister.compName,
  2605. &component->name,
  2606. sizeof (SaNameT));
  2607. iovec.iov_base = (char *)&req_exec_amf_componentunregister;
  2608. iovec.iov_len = sizeof (req_exec_amf_componentunregister);
  2609. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  2610. }
  2611. static void component_register (
  2612. struct amf_comp *component)
  2613. {
  2614. struct req_exec_amf_componentregister req_exec_amf_componentregister;
  2615. struct iovec iovec;
  2616. /*
  2617. * This only works on local components
  2618. */
  2619. if (component == 0 || component->local != 1) {
  2620. return;
  2621. }
  2622. log_printf (LOG_LEVEL_ENTER_FUNC, "component_register: registering component %s\n",
  2623. getSaNameT (&component->name));
  2624. req_exec_amf_componentregister.header.size = sizeof (struct req_exec_amf_componentregister);
  2625. req_exec_amf_componentregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTREGISTER;
  2626. req_exec_amf_componentregister.source.conn_info = 0;
  2627. req_exec_amf_componentregister.source.in_addr.s_addr = 0;
  2628. req_exec_amf_componentregister.currentReadinessState = component->currentReadinessState;
  2629. req_exec_amf_componentregister.newReadinessState = component->newReadinessState;
  2630. req_exec_amf_componentregister.currentHAState = component->currentHAState;
  2631. req_exec_amf_componentregister.newHAState = component->newHAState;
  2632. memset (&req_exec_amf_componentregister.req_lib_amf_componentregister,
  2633. 0, sizeof (struct req_lib_amf_componentregister));
  2634. memcpy (&req_exec_amf_componentregister.req_lib_amf_componentregister.compName,
  2635. &component->name,
  2636. sizeof (SaNameT));
  2637. iovec.iov_base = (char *)&req_exec_amf_componentregister;
  2638. iovec.iov_len = sizeof (req_exec_amf_componentregister);
  2639. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  2640. }
  2641. /***
  2642. This should be used for a partition I think
  2643. **/
  2644. void enumerate_components (
  2645. void (*function)(struct amf_comp *, void *data),
  2646. void *data)
  2647. {
  2648. struct list_head *AmfGroupList;
  2649. struct list_head *AmfUnitList;
  2650. struct list_head *AmfComponentList;
  2651. struct saAmfGroup *saAmfGroup;
  2652. struct saAmfUnit *AmfUnit;
  2653. struct amf_comp *AmfComponent;
  2654. /*
  2655. * Search all groups
  2656. */
  2657. for (AmfGroupList = saAmfGroupHead.next;
  2658. AmfGroupList != &saAmfGroupHead;
  2659. AmfGroupList = AmfGroupList->next) {
  2660. saAmfGroup = list_entry (AmfGroupList,
  2661. struct saAmfGroup, saAmfGroupList);
  2662. /*
  2663. * Search all units
  2664. */
  2665. for (AmfUnitList = saAmfGroup->saAmfUnitHead.next;
  2666. AmfUnitList != &saAmfGroup->saAmfUnitHead;
  2667. AmfUnitList = AmfUnitList->next) {
  2668. AmfUnit = list_entry (AmfUnitList,
  2669. struct saAmfUnit, saAmfUnitList);
  2670. /*
  2671. * Search all components
  2672. */
  2673. for (AmfComponentList = AmfUnit->amf_compHead.next;
  2674. AmfComponentList != &AmfUnit->amf_compHead;
  2675. AmfComponentList = AmfComponentList->next) {
  2676. AmfComponent = list_entry (AmfComponentList,
  2677. struct amf_comp, amf_compList);
  2678. function (AmfComponent, data);
  2679. }
  2680. }
  2681. }
  2682. }
  2683. void ha_state_api_set (struct amf_comp *component, SaAmfHAStateT haState)
  2684. {
  2685. struct res_lib_amf_csisetcallback res_lib_amf_csisetcallback;
  2686. memset (&res_lib_amf_csisetcallback,0,sizeof(res_lib_amf_csisetcallback));
  2687. log_printf (LOG_LEVEL_ENTER_FUNC, "sending ha state to API\n");
  2688. if (component->local != 1) {
  2689. return;
  2690. }
  2691. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  2692. return;
  2693. }
  2694. /*
  2695. * this should be an assertion
  2696. */
  2697. if (component->conn_info->state != CONN_STATE_ACTIVE ||
  2698. component->conn_info->service != AMF_SERVICE) {
  2699. return;
  2700. }
  2701. res_lib_amf_csisetcallback.header.id = MESSAGE_RES_AMF_CSISETCALLBACK;
  2702. res_lib_amf_csisetcallback.header.size = sizeof (struct res_lib_amf_csisetcallback);
  2703. res_lib_amf_csisetcallback.header.error = SA_OK;
  2704. if (res_lib_amf_csisetcallback.invocation == -1) {
  2705. printf ("TODO set callback\n");
  2706. }
  2707. memcpy (&res_lib_amf_csisetcallback.compName,
  2708. &component->name, sizeof (SaNameT));
  2709. memcpy (&res_lib_amf_csisetcallback.csiName,
  2710. &component->saAmfProtectionGroup->name, sizeof (SaNameT));
  2711. res_lib_amf_csisetcallback.csiFlags = SA_AMF_CSI_ALL_INSTANCES;
  2712. res_lib_amf_csisetcallback.haState = haState;
  2713. // TODO set activeCompName to correct component name
  2714. memcpy (&res_lib_amf_csisetcallback.activeCompName,
  2715. &component->name, sizeof (SaNameT));
  2716. res_lib_amf_csisetcallback.transitionDescriptor = SA_AMF_CSI_NEW_ASSIGN;
  2717. component->newHAState = haState;
  2718. libais_send_response (component->conn_info->conn_info_partner,
  2719. &res_lib_amf_csisetcallback,
  2720. sizeof (struct res_lib_amf_csisetcallback));
  2721. }
  2722. static void ha_state_group_set (
  2723. struct amf_comp *component,
  2724. SaAmfHAStateT haState)
  2725. {
  2726. struct req_exec_amf_hastateset req_exec_amf_hastateset;
  2727. struct iovec iovec;
  2728. req_exec_amf_hastateset.header.id = MESSAGE_REQ_EXEC_AMF_HASTATESET;
  2729. req_exec_amf_hastateset.header.size = sizeof (struct req_exec_amf_hastateset);
  2730. memcpy (&req_exec_amf_hastateset.compName, &component->name, sizeof (SaNameT));
  2731. req_exec_amf_hastateset.haState = haState;
  2732. log_printf (LOG_LEVEL_ENTER_FUNC, "Sending ha state to cluster for component %s\n", getSaNameT (&component->name));
  2733. log_printf (LOG_LEVEL_DEBUG, "ha state is %d\n", haState);
  2734. iovec.iov_base = (char *)&req_exec_amf_hastateset;
  2735. iovec.iov_len = sizeof (req_exec_amf_hastateset);
  2736. assert (totempg_groups_mcast_joined (openais_group_handle, iovec, 1, TOTEMPG_AGREED) == 0);
  2737. }
  2738. void readiness_state_api_set (struct amf_comp *component,
  2739. SaAmfReadinessStateT readinessState)
  2740. {
  2741. struct res_lib_amf_readinessstatesetcallback res_lib_amf_readinessstatesetcallback;
  2742. memset (&res_lib_amf_readinessstatesetcallback,0,sizeof(res_lib_amf_readinessstatesetcallback));
  2743. /*
  2744. * If component is local, don't request service from API
  2745. */
  2746. if (component->local != 1) {
  2747. return;
  2748. }
  2749. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  2750. return;
  2751. }
  2752. /*
  2753. * this should be an assertion
  2754. */
  2755. if (component->conn_info->state != CONN_STATE_ACTIVE ||
  2756. component->conn_info->service != AMF_SERVICE) {
  2757. return;
  2758. }
  2759. res_lib_amf_readinessstatesetcallback.header.id = MESSAGE_RES_AMF_READINESSSTATESETCALLBACK;
  2760. res_lib_amf_readinessstatesetcallback.header.size = sizeof (struct res_lib_amf_readinessstatesetcallback);
  2761. res_lib_amf_readinessstatesetcallback.header.error = SA_OK;
  2762. res_lib_amf_readinessstatesetcallback.invocation =
  2763. req_lib_amf_invocation_create (
  2764. MESSAGE_REQ_AMF_RESPONSE_SAAMFREADINESSSTATESETCALLBACK,
  2765. comp);
  2766. if (res_lib_amf_readinessstatesetcallback.invocation == -1) {
  2767. printf ("TODO readiness set callback\n");
  2768. }
  2769. memcpy (&res_lib_amf_readinessstatesetcallback.compName,
  2770. &component->name, sizeof (SaNameT));
  2771. res_lib_amf_readinessstatesetcallback.readinessState = readinessState;
  2772. component->newReadinessState = readinessState;
  2773. log_printf (LOG_LEVEL_DEBUG, "Setting conn_info %p to readiness state %d\n", component->conn_info, readinessState);
  2774. libais_send_response (component->conn_info->conn_info_partner,
  2775. &res_lib_amf_readinessstatesetcallback,
  2776. sizeof (struct res_lib_amf_readinessstatesetcallback));
  2777. }
  2778. static void readiness_state_group_set (
  2779. struct amf_comp *component,
  2780. SaAmfReadinessStateT readinessState)
  2781. {
  2782. struct req_exec_amf_readinessstateset req_exec_amf_readinessstateset;
  2783. struct iovec iovec;
  2784. req_exec_amf_readinessstateset.header.id = MESSAGE_REQ_EXEC_AMF_READINESSSTATESET;
  2785. req_exec_amf_readinessstateset.header.size = sizeof (struct req_exec_amf_readinessstateset);
  2786. memcpy (&req_exec_amf_readinessstateset.compName, &component->name, sizeof (SaNameT));
  2787. req_exec_amf_readinessstateset.readinessState = readinessState;
  2788. log_printf (LOG_LEVEL_ENTER_FUNC, "Sending message to all cluster nodes to set readiness state of component %s\n",
  2789. getSaNameT (&component->name));
  2790. log_printf (LOG_LEVEL_DEBUG, "readiness state is %d\n", readinessState);
  2791. iovec.iov_base = (char *)&req_exec_amf_readinessstateset;
  2792. iovec.iov_len = sizeof (req_exec_amf_readinessstateset);
  2793. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  2794. }
  2795. static void dsmDisabledUnlockedRegisteredOrErrorCancel (
  2796. struct amf_comp *component)
  2797. {
  2798. struct saAmfUnit *unit;
  2799. struct list_head *list;
  2800. int serviceUnitEnabled;
  2801. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedRegisteredOrErrorCancel for %s\n",
  2802. getSaNameT (&component->name));
  2803. unit = component->saAmfUnit;
  2804. for (serviceUnitEnabled = 1, list = unit->amf_compHead.next;
  2805. list != &unit->amf_compHead;
  2806. list = list->next) {
  2807. component = list_entry (list,
  2808. struct amf_comp, amf_compList);
  2809. if (component->registered == 0 ||
  2810. component->probableCause) {
  2811. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not registered or failed.\n");
  2812. serviceUnitEnabled = 0;
  2813. break;
  2814. }
  2815. }
  2816. if (serviceUnitEnabled == 1) {
  2817. log_printf (LOG_LEVEL_DEBUG, "dsm entering AMF_ENABLED_UNLOCKED state.\n");
  2818. component->saAmfUnit->operationalAdministrativeState = AMF_ENABLED_UNLOCKED;
  2819. component->disabledUnlockedState = -1; // SHOULD BE INVALID
  2820. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  2821. dsm (component);
  2822. }
  2823. }
  2824. static void dsmDisabledUnlockedFailedComponent (
  2825. struct amf_comp *component)
  2826. {
  2827. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedFailedComponent: for %s.\n",
  2828. getSaNameT (&component->name));
  2829. switch (component->enabledUnlockedState) {
  2830. case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED:
  2831. case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED:
  2832. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  2833. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  2834. readiness_state_group_set (component, SA_AMF_OUT_OF_SERVICE);
  2835. } else {
  2836. readiness_state_api_set (component, SA_AMF_OUT_OF_SERVICE);
  2837. }
  2838. break;
  2839. case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED:
  2840. case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED:
  2841. case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED:
  2842. case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED:
  2843. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  2844. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  2845. ha_state_group_set (component, SA_AMF_QUIESCED);
  2846. } else {
  2847. ha_state_api_set (component, SA_AMF_QUIESCED);
  2848. }
  2849. poll_timer_delete (aisexec_poll_handle,
  2850. component->timer_healthcheck);
  2851. component->timer_healthcheck = 0;
  2852. break;
  2853. default:
  2854. log_printf (LOG_LEVEL_DEBUG, "invalid case 5 %d\n", component->enabledUnlockedState);
  2855. break;
  2856. }
  2857. }
  2858. static void dsmDisabledUnlockedFailed (
  2859. struct amf_comp *component)
  2860. {
  2861. struct saAmfUnit *unit;
  2862. struct list_head *list;
  2863. unit = component->saAmfUnit;
  2864. for (list = unit->amf_compHead.next;
  2865. list != &unit->amf_compHead;
  2866. list = list->next) {
  2867. component = list_entry (list, struct amf_comp, amf_compList);
  2868. dsmDisabledUnlockedFailedComponent (component);
  2869. }
  2870. return;
  2871. }
  2872. static void dsmDisabledUnlockedQuiescedRequested (
  2873. struct amf_comp *component)
  2874. {
  2875. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED;
  2876. dsm (component);
  2877. }
  2878. static void dsmDisabledUnlockedQuiescedCompleted (
  2879. struct amf_comp *component)
  2880. {
  2881. struct saAmfUnit *unit;
  2882. struct list_head *list;
  2883. int serviceUnitQuiesced;
  2884. unit = component->saAmfUnit;
  2885. for (serviceUnitQuiesced = 1, list = unit->amf_compHead.next;
  2886. list != &unit->amf_compHead;
  2887. list = list->next) {
  2888. component = list_entry (list, struct amf_comp, amf_compList);
  2889. if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) {
  2890. if (component->currentHAState != SA_AMF_QUIESCED) {
  2891. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n");
  2892. serviceUnitQuiesced = 0;
  2893. break;
  2894. }
  2895. }
  2896. }
  2897. if (serviceUnitQuiesced == 1) {
  2898. log_printf (LOG_LEVEL_DEBUG, "All components have quiesced, Quiescing completed\n");
  2899. for (list = unit->amf_compHead.next;
  2900. list != &unit->amf_compHead;
  2901. list = list->next) {
  2902. component = list_entry (list, struct amf_comp, amf_compList);
  2903. log_printf (LOG_LEVEL_DEBUG, "dsm: Sending readiness state set to OUTOFSERVICE for comp %s.\n",
  2904. getSaNameT (&component->name));
  2905. if ( component->probableCause == SA_AMF_NOT_RESPONDING ) {
  2906. readiness_state_group_set (component, SA_AMF_OUT_OF_SERVICE);
  2907. } else {
  2908. readiness_state_api_set (component, SA_AMF_OUT_OF_SERVICE);
  2909. }
  2910. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  2911. }
  2912. }
  2913. }
  2914. static void dsmDisabledUnlockedOutOfServiceRequested (
  2915. struct amf_comp *component)
  2916. {
  2917. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED;
  2918. dsm (component);
  2919. }
  2920. static void dsmDisabledUnlockedOutOfServiceCompleted (
  2921. struct amf_comp *component)
  2922. {
  2923. struct saAmfUnit *unit;
  2924. struct list_head *list;
  2925. int serviceUnitOutOfService;
  2926. struct saAmfGroup *group = 0;
  2927. struct list_head *comp_list = 0;
  2928. struct list_head *unit_list = 0;
  2929. int serviceUnitInStandby = 0;
  2930. int activeServiceUnits = 0;
  2931. /*
  2932. * Once all components of a service unit are out of service,
  2933. * activate another service unit in standby
  2934. */
  2935. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedOutOfServiceCompleted: component out of service %s\n", getSaNameT (&component->name));
  2936. /*
  2937. * Determine if all components have responded to going out of service
  2938. */
  2939. unit = component->saAmfUnit;
  2940. for (serviceUnitOutOfService = 1, list = unit->amf_compHead.next;
  2941. list != &unit->amf_compHead;
  2942. list = list->next) {
  2943. component = list_entry (list, struct amf_comp, amf_compList);
  2944. if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) {
  2945. if (component->currentReadinessState != SA_AMF_OUT_OF_SERVICE) {
  2946. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n");
  2947. serviceUnitOutOfService = 0;
  2948. break;
  2949. }
  2950. }
  2951. if ( component->registered == 0 ) {
  2952. protectiongroup_notifications_send (component, SA_AMF_PROTECTION_GROUP_REMOVED);
  2953. }
  2954. }
  2955. group = unit->saAmfGroup;
  2956. activeServiceUnits = activeServiceUnitsCount(group);
  2957. if (activeServiceUnits>=group->saAmfActiveUnitsDesired) {
  2958. return;
  2959. }
  2960. if (serviceUnitOutOfService == 1) {
  2961. log_printf (LOG_LEVEL_DEBUG, "SU has gone out of service.\n");
  2962. /*
  2963. * Search all units
  2964. */
  2965. for (unit_list = group->saAmfUnitHead.next;
  2966. unit_list != &group->saAmfUnitHead;
  2967. unit_list = unit_list->next) {
  2968. unit = list_entry (unit_list,
  2969. struct saAmfUnit, saAmfUnitList);
  2970. log_printf (LOG_LEVEL_DEBUG, "Checking if service unit is in standby %s\n", getSaNameT (&unit->name));
  2971. /*
  2972. * Search all components
  2973. */
  2974. for (serviceUnitInStandby = 1,
  2975. comp_list = unit->amf_compHead.next;
  2976. comp_list != &unit->amf_compHead;
  2977. comp_list = comp_list->next) {
  2978. component = list_entry (comp_list,
  2979. struct amf_comp, amf_compList);
  2980. if (component->currentHAState != SA_AMF_STANDBY) {
  2981. serviceUnitInStandby = 0;
  2982. break; /* for iteration of service unit components */
  2983. }
  2984. }
  2985. if (serviceUnitInStandby) {
  2986. break; /* for iteration of service group's service units */
  2987. }
  2988. }
  2989. /*
  2990. * All components in service unit are standby, activate standby service unit
  2991. */
  2992. if (serviceUnitInStandby) {
  2993. log_printf (LOG_LEVEL_DEBUG, "unit in standby\n");
  2994. for (list = unit->amf_compHead.next;
  2995. list != &unit->amf_compHead;
  2996. list = list->next) {
  2997. component = list_entry (list,
  2998. struct amf_comp, amf_compList);
  2999. ha_state_api_set (component, SA_AMF_ACTIVE);
  3000. }
  3001. } else {
  3002. log_printf (LOG_LEVEL_DEBUG, "Can't activate standby service unit because no standby is available.\n");
  3003. }
  3004. }
  3005. }
  3006. static void dsmEnabledUnlockedInitial (
  3007. struct amf_comp *component)
  3008. {
  3009. struct saAmfUnit *unit;
  3010. struct list_head *list;
  3011. unit = component->saAmfUnit;
  3012. for (list = unit->amf_compHead.next;
  3013. list != &unit->amf_compHead;
  3014. list = list->next) {
  3015. component = list_entry (list, struct amf_comp, amf_compList);
  3016. readiness_state_api_set (component, SA_AMF_IN_SERVICE);
  3017. log_printf (LOG_LEVEL_DEBUG, "dsm: telling component %s to enter SA_AMF_IN_SERVICE.\n",
  3018. getSaNameT (&component->name));
  3019. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED;
  3020. }
  3021. }
  3022. static void dsmEnabledUnlockedInServiceRequested (
  3023. struct amf_comp *component)
  3024. {
  3025. struct saAmfUnit *unit;
  3026. struct list_head *list;
  3027. int in_service;
  3028. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceRequested %s.\n", getSaNameT (&component->name));
  3029. unit = component->saAmfUnit;
  3030. for (in_service = 1, list = unit->amf_compHead.next;
  3031. list != &unit->amf_compHead;
  3032. list = list->next) {
  3033. component = list_entry (list, struct amf_comp, amf_compList);
  3034. if (component->currentReadinessState != SA_AMF_IN_SERVICE) {
  3035. log_printf (LOG_LEVEL_DEBUG, "dsm: Found atleast one component not in service\n");
  3036. in_service = 0;
  3037. break;
  3038. }
  3039. }
  3040. if (in_service) {
  3041. log_printf (LOG_LEVEL_DEBUG, "DSM determined component is in service\n");
  3042. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED;
  3043. dsm (component);
  3044. }
  3045. }
  3046. static void dsmEnabledUnlockedInServiceCompleted (
  3047. struct amf_comp *component)
  3048. {
  3049. struct saAmfUnit *unit;
  3050. struct list_head *list;
  3051. SaAmfHAStateT newHaState;
  3052. int activeServiceUnits;
  3053. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceCompleted %s.\n", getSaNameT (&component->name));
  3054. unit = component->saAmfUnit;
  3055. for (list = unit->amf_compHead.next;
  3056. list != &unit->amf_compHead;
  3057. list = list->next) {
  3058. component = list_entry (list,
  3059. struct amf_comp, amf_compList);
  3060. log_printf (LOG_LEVEL_DEBUG, "Requesting component go active.\n");
  3061. /*
  3062. * Count number of active service units
  3063. */
  3064. activeServiceUnits = activeServiceUnitsCount (component->saAmfUnit->saAmfGroup);
  3065. if (activeServiceUnits < component->saAmfUnit->saAmfGroup->saAmfActiveUnitsDesired) {
  3066. newHaState = SA_AMF_ACTIVE;
  3067. log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_ACTIVE\n", getSaNameT (&component->name));
  3068. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED;
  3069. } else {
  3070. newHaState = SA_AMF_STANDBY;
  3071. log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_STANDBY\n", getSaNameT (&component->name));
  3072. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED;
  3073. }
  3074. ha_state_api_set (component, newHaState);
  3075. }
  3076. }
  3077. static void dsmEnabledUnlockedActiveRequested (
  3078. struct amf_comp *component)
  3079. {
  3080. if (component->local == 1) {
  3081. log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer1\n");
  3082. poll_timer_add (aisexec_poll_handle,
  3083. component->healthcheckInterval,
  3084. (void *)component->conn_info,
  3085. timer_function_libamf_healthcheck,
  3086. &component->timer_healthcheck);
  3087. }
  3088. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED;
  3089. }
  3090. static void dsmEnabledUnlockedStandbyRequested (
  3091. struct amf_comp *component)
  3092. {
  3093. if (component->local == 1) {
  3094. log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer2\n");
  3095. poll_timer_add (aisexec_poll_handle,
  3096. component->healthcheckInterval,
  3097. (void *)component->conn_info,
  3098. timer_function_libamf_healthcheck,
  3099. &component->timer_healthcheck);
  3100. }
  3101. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED;
  3102. }
  3103. static void dsmEnabledUnlockedTransitionDisabledUnlocked (
  3104. struct amf_comp *component)
  3105. {
  3106. struct saAmfUnit *unit;
  3107. struct list_head *list;
  3108. unit = component->saAmfUnit;
  3109. for (list = unit->amf_compHead.next;
  3110. list != &unit->amf_compHead;
  3111. list = list->next) {
  3112. component = list_entry (list, struct amf_comp, amf_compList);
  3113. log_printf (LOG_LEVEL_DEBUG, "Requesting component %s transition to disabled.\n",
  3114. getSaNameT (&component->name));
  3115. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_FAILED;
  3116. }
  3117. component->saAmfUnit->operationalAdministrativeState = AMF_DISABLED_UNLOCKED;
  3118. dsm (component);
  3119. }
  3120. static void dsmSynchronizeStaus (
  3121. struct amf_comp *component)
  3122. {
  3123. enum amfOperationalAdministrativeState unit_status = AMF_DISABLED_UNLOCKED;
  3124. struct saAmfUnit *unit;
  3125. struct saAmfGroup *group;
  3126. struct list_head *list;
  3127. int activeServiceUnits;
  3128. if (component->currentReadinessState == component->newReadinessState) {
  3129. if (component->currentReadinessState == SA_AMF_OUT_OF_SERVICE) {
  3130. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3131. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3132. } else if (component->currentReadinessState == SA_AMF_IN_SERVICE) {
  3133. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3134. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED;
  3135. unit_status = AMF_ENABLED_UNLOCKED;
  3136. } else if (component->currentReadinessState == SA_AMF_QUIESCED) {
  3137. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED;
  3138. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3139. }
  3140. } else {
  3141. if (component->newReadinessState == SA_AMF_OUT_OF_SERVICE) {
  3142. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  3143. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3144. } else if (component->newReadinessState == SA_AMF_IN_SERVICE) {
  3145. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3146. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED;
  3147. unit_status = AMF_ENABLED_UNLOCKED;
  3148. } else {
  3149. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  3150. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3151. }
  3152. }
  3153. if (component->currentHAState == component->newHAState) {
  3154. if (component->currentHAState == SA_AMF_ACTIVE) {
  3155. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3156. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED;
  3157. unit_status = AMF_ENABLED_UNLOCKED;
  3158. } else if (component->currentHAState == SA_AMF_STANDBY) {
  3159. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3160. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED;
  3161. unit_status = AMF_ENABLED_UNLOCKED;
  3162. } else {
  3163. /* depend on readiness status */
  3164. }
  3165. } else {
  3166. if (component->newHAState == SA_AMF_ACTIVE) {
  3167. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3168. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED;
  3169. unit_status = AMF_ENABLED_UNLOCKED;
  3170. } else if (component->newHAState == SA_AMF_STANDBY) {
  3171. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3172. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED;
  3173. unit_status = AMF_ENABLED_UNLOCKED;
  3174. } else {
  3175. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  3176. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3177. }
  3178. }
  3179. /* Syncronize Operational AdministrativeState */
  3180. component->saAmfUnit->operationalAdministrativeState = unit_status;
  3181. unit = component->saAmfUnit;
  3182. group = unit->saAmfGroup;
  3183. for (list = unit->amf_compHead.next; list != &unit->amf_compHead; list = list->next) {
  3184. activeServiceUnits = activeServiceUnitsCount(group);
  3185. if (activeServiceUnits <= group->saAmfActiveUnitsDesired) {
  3186. break;
  3187. }
  3188. if (component->currentHAState != SA_AMF_ACTIVE) {
  3189. continue;
  3190. }
  3191. ha_state_api_set (component, SA_AMF_STANDBY);
  3192. }
  3193. return;
  3194. }
  3195. static void dsmEnabledUnlocked (
  3196. struct amf_comp *component)
  3197. {
  3198. switch (component->enabledUnlockedState) {
  3199. case AMF_ENABLED_UNLOCKED_INITIAL:
  3200. dsmEnabledUnlockedInitial (component);
  3201. break;
  3202. case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED:
  3203. dsmEnabledUnlockedInServiceRequested (component);
  3204. break;
  3205. case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED:
  3206. dsmEnabledUnlockedInServiceCompleted (component);
  3207. break;
  3208. case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED:
  3209. dsmEnabledUnlockedActiveRequested (component);
  3210. break;
  3211. case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED:
  3212. /* noop - operational state */
  3213. break;
  3214. case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED:
  3215. dsmEnabledUnlockedStandbyRequested (component);
  3216. break;
  3217. case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED:
  3218. /* noop - operational state */
  3219. break;
  3220. default:
  3221. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlocked: unkown state machine value.\n");
  3222. }
  3223. }
  3224. static void dsmDisabledUnlocked (
  3225. struct amf_comp *component)
  3226. {
  3227. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked for %s state %d\n",
  3228. getSaNameT (&component->name),
  3229. component->disabledUnlockedState);
  3230. switch (component->disabledUnlockedState) {
  3231. case AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL:
  3232. dsmDisabledUnlockedRegisteredOrErrorCancel (component);
  3233. break;
  3234. case AMF_DISABLED_UNLOCKED_FAILED:
  3235. dsmDisabledUnlockedFailed (component);
  3236. break;
  3237. case AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED:
  3238. dsmDisabledUnlockedQuiescedRequested (component);
  3239. break;
  3240. case AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED:
  3241. dsmDisabledUnlockedQuiescedCompleted (component);
  3242. break;
  3243. case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED:
  3244. dsmDisabledUnlockedOutOfServiceRequested (component);
  3245. break;
  3246. case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED:
  3247. dsmDisabledUnlockedOutOfServiceCompleted (component);
  3248. break;
  3249. default:
  3250. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked: unkown state machine value %d.\n", component->disabledUnlockedState);
  3251. }
  3252. }
  3253. static void dsm (
  3254. struct amf_comp *component)
  3255. {
  3256. log_printf (LOG_LEVEL_DEBUG, "dsm for component %s\n", getSaNameT (&component->name));
  3257. switch (component->saAmfUnit->operationalAdministrativeState) {
  3258. case AMF_DISABLED_UNLOCKED:
  3259. dsmDisabledUnlocked (component);
  3260. break;
  3261. case AMF_ENABLED_UNLOCKED:
  3262. dsmEnabledUnlocked (component);
  3263. break;
  3264. /*
  3265. AMF_DISABLED_LOCKED,
  3266. AMF_ENABLED_STOPPING
  3267. */
  3268. default:
  3269. log_printf (LOG_LEVEL_DEBUG, "dsm: unknown state machine value.\n");
  3270. }
  3271. }
  3272. void error_report (
  3273. struct amf_comp *component,
  3274. SaAmfProbableCauseT probableCause)
  3275. {
  3276. struct req_exec_amf_componenterrorreport req_exec_amf_componenterrorreport;
  3277. struct iovec iovec;
  3278. req_exec_amf_componenterrorreport.header.size = sizeof (struct req_exec_amf_componenterrorreport);
  3279. req_exec_amf_componenterrorreport.header.id = MESSAGE_REQ_EXEC_AMF_ERRORREPORT;
  3280. req_exec_amf_componenterrorreport.source.conn_info = 0;
  3281. req_exec_amf_componenterrorreport.source.in_addr.s_addr = 0;
  3282. memcpy (&req_exec_amf_componenterrorreport.req_lib_amf_componenterrorreport.erroneousComponent,
  3283. &component->name,
  3284. sizeof (SaNameT));
  3285. req_exec_amf_componenterrorreport.req_lib_amf_componenterrorreport.errorDescriptor.probableCause = probableCause;
  3286. iovec.iov_base = (char *)&req_exec_amf_componenterrorreport;
  3287. iovec.iov_len = sizeof (req_exec_amf_componenterrorreport);
  3288. assert (totempg_groups_mcast_joined (openais_group_handle, iovec, 2, TOTEMPG_AGREED) == 0);
  3289. }
  3290. int healthcheck_instance = 0;
  3291. struct saAmfProtectionGroup *protectiongroup_find (
  3292. SaNameT *csiName)
  3293. {
  3294. struct list_head *AmfGroupList;
  3295. struct list_head *AmfProtectionGroupList;
  3296. struct saAmfGroup *saAmfGroup;
  3297. struct saAmfProtectionGroup *AmfProtectionGroup;
  3298. /*
  3299. * Search all groups
  3300. */
  3301. for (AmfGroupList = saAmfGroupHead.next;
  3302. AmfGroupList != &saAmfGroupHead;
  3303. AmfGroupList = AmfGroupList->next) {
  3304. saAmfGroup = list_entry (AmfGroupList,
  3305. struct saAmfGroup, saAmfGroupList);
  3306. /*
  3307. * Search all protection groups
  3308. */
  3309. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  3310. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  3311. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  3312. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  3313. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  3314. if (name_match (csiName, &AmfProtectionGroup->name)) {
  3315. return (AmfProtectionGroup);
  3316. }
  3317. }
  3318. }
  3319. return (0);
  3320. }
  3321. struct amf_comp *component_in_protectiongroup_find (
  3322. SaNameT *csiName,
  3323. SaNameT *compName)
  3324. {
  3325. struct list_head *AmfGroupList = 0;
  3326. struct list_head *AmfProtectionGroupList = 0;
  3327. struct list_head *AmfComponentList = 0;
  3328. struct saAmfGroup *saAmfGroup = 0;
  3329. struct saAmfProtectionGroup *AmfProtectionGroup = 0;
  3330. struct amf_comp *AmfComponent = 0;
  3331. int found = 0;
  3332. /*
  3333. * Search all groups
  3334. */
  3335. for (AmfGroupList = saAmfGroupHead.next;
  3336. AmfGroupList != &saAmfGroupHead;
  3337. AmfGroupList = AmfGroupList->next) {
  3338. saAmfGroup = list_entry (AmfGroupList,
  3339. struct saAmfGroup, saAmfGroupList);
  3340. /*
  3341. * Search all protection groups
  3342. */
  3343. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  3344. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  3345. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  3346. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  3347. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  3348. if (name_match (csiName, &AmfProtectionGroup->name)) {
  3349. /*
  3350. * Search all components
  3351. */
  3352. for (AmfComponentList = AmfProtectionGroup->saAmfMembersHead.next;
  3353. AmfComponentList != &AmfProtectionGroup->saAmfMembersHead;
  3354. AmfComponentList = AmfComponentList->next) {
  3355. AmfComponent = list_entry (AmfComponentList,
  3356. struct amf_comp, saAmfProtectionGroupList);
  3357. if (name_match (compName, &AmfComponent->name)) {
  3358. found = 1;
  3359. }
  3360. }
  3361. }
  3362. }
  3363. }
  3364. if (found) {
  3365. return (AmfComponent);
  3366. } else {
  3367. return (0);
  3368. }
  3369. }
  3370. /*
  3371. * The response handler for readiness state set callback
  3372. */
  3373. static void response_handler_readinessstatesetcallback (struct conn_info *conn_info,
  3374. struct req_lib_amf_response *req_lib_amf_response)
  3375. {
  3376. if (req_lib_amf_response->error == SA_OK && conn_info->component) {
  3377. log_printf (LOG_LEVEL_ENTER_FUNC, "CALLBACK sending readiness state to %s\n",
  3378. getSaNameT (&conn_info->component->name));
  3379. readiness_state_group_set (conn_info->component, conn_info->component->newReadinessState);
  3380. }
  3381. }
  3382. /*
  3383. * iterate service unit components
  3384. * telling all components not already QUIESCING to enter SA_AMF_QUIESCED state
  3385. */
  3386. static void response_handler_csisetcallback (struct conn_info *conn_info,
  3387. struct req_lib_amf_response *req_lib_amf_response)
  3388. {
  3389. if (req_lib_amf_response->error == SA_OK && conn_info->component) {
  3390. ha_state_group_set (conn_info->component, conn_info->component->newHAState);
  3391. }
  3392. }
  3393. void amf_confchg_njoin (struct amf_comp *component ,void *data)
  3394. {
  3395. if (component->source_addr.s_addr != this_ip->sin_addr.s_addr) {
  3396. return;
  3397. }
  3398. component_register (component);
  3399. return;
  3400. }
  3401. void amf_confchg_nleave (struct amf_comp *component ,void *data)
  3402. {
  3403. struct in_addr *source_addr = (struct in_addr *)data;
  3404. struct saAmfUnit *unit;
  3405. struct list_head *list;
  3406. struct amf_comp *leave_component = NULL;
  3407. enum amfDisabledUnlockedState disablestate = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED;
  3408. if (component->source_addr.s_addr != source_addr->s_addr) {
  3409. return;
  3410. }
  3411. if (!component->registered) {
  3412. return;
  3413. }
  3414. log_printf (LOG_LEVEL_ENTER_FUNC, "amf_confchg_nleave(%s)\n", getSaNameT (&(component->name)));
  3415. /* Component status Initialize */
  3416. unit = component->saAmfUnit;
  3417. for (list = unit->amf_compHead.next; list != &unit->amf_compHead; list = list->next) {
  3418. component = list_entry (list,
  3419. struct amf_comp, amf_compList);
  3420. if (component->source_addr.s_addr != source_addr->s_addr) {
  3421. disablestate = AMF_DISABLED_UNLOCKED_FAILED;
  3422. continue;
  3423. }
  3424. component->registered = 0;
  3425. component->local = 0;
  3426. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3427. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  3428. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  3429. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  3430. component->newHAState = SA_AMF_QUIESCED;
  3431. component->currentHAState = SA_AMF_QUIESCED;
  3432. component->source_addr.s_addr = 0;
  3433. leave_component = component;
  3434. }
  3435. if (leave_component == NULL) {
  3436. return;
  3437. }
  3438. leave_component->saAmfUnit->operationalAdministrativeState = AMF_DISABLED_UNLOCKED;
  3439. leave_component->disabledUnlockedState = disablestate;
  3440. dsm (leave_component);
  3441. leave_component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  3442. return;
  3443. }
  3444. /*
  3445. * If receiving this message from another cluster node, another cluster node
  3446. * has selected a readiness state for a component connected to _that_ cluster
  3447. * node. That cluster node API has verified the readiness state, so its time to let
  3448. * the rest of the cluster nodes know about the readiness state change.
  3449. */
  3450. static int message_handler_req_exec_amf_readinessstateset (void *message, struct in_addr source_addr, int endian_conversion_required)
  3451. {
  3452. struct req_exec_amf_readinessstateset *req_exec_amf_readinessstateset = (struct req_exec_amf_readinessstateset *)message;
  3453. struct amf_comp *component;
  3454. component = find_comp (&req_exec_amf_readinessstateset->compName);
  3455. if (component) {
  3456. log_printf (LOG_LEVEL_FROM_GMI,
  3457. "Executive: message_handler_req_exec_amf_readinessstateset (%s, RD:%d)\n",
  3458. getSaNameT (&component->name), req_exec_amf_readinessstateset->readinessState);
  3459. component->currentReadinessState = req_exec_amf_readinessstateset->readinessState;
  3460. component->newReadinessState = component->currentReadinessState;
  3461. dsm (component);
  3462. }
  3463. return (0);
  3464. }
  3465. /*
  3466. * If receiving this message from another cluster node, another cluster node
  3467. * has selected a ha state for a component connected to _that_ cluster
  3468. * node. That cluster node API has verified the ha state, so its time to let
  3469. * the rest of the cluster nodes know about the HA state change.
  3470. */
  3471. static int message_handler_req_exec_amf_hastateset (void *message, struct in_addr source_addr, int endian_conversion_required)
  3472. {
  3473. struct req_exec_amf_hastateset *req_exec_amf_hastateset = (struct req_exec_amf_hastateset *)message;
  3474. struct amf_comp *component;
  3475. SaAmfProtectionGroupChangesT changeToComponent = SA_AMF_PROTECTION_GROUP_STATE_CHANGE;
  3476. component = find_comp (&req_exec_amf_hastateset->compName);
  3477. if (!component) {
  3478. return (0);
  3479. }
  3480. log_printf (LOG_LEVEL_FROM_GMI,
  3481. "Executive: message_handler_req_exec_amf_hastateset (%s, HA:%d)\n",
  3482. getSaNameT (&component->name), req_exec_amf_hastateset->haState);
  3483. if ( component->currentHAState == 0 ) {
  3484. if ( req_exec_amf_hastateset->haState == SA_AMF_ACTIVE
  3485. || req_exec_amf_hastateset->haState == SA_AMF_STANDBY ) {
  3486. changeToComponent = SA_AMF_PROTECTION_GROUP_ADDED;
  3487. }
  3488. } else {
  3489. if (component->currentHAState == req_exec_amf_hastateset->haState) {
  3490. changeToComponent = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  3491. }
  3492. }
  3493. component->currentHAState = req_exec_amf_hastateset->haState;
  3494. component->newHAState = component->currentHAState;
  3495. dsm (component);
  3496. if( changeToComponent != SA_AMF_PROTECTION_GROUP_NO_CHANGE ) {
  3497. protectiongroup_notifications_send (component, changeToComponent);
  3498. }
  3499. return (0);
  3500. }
  3501. static int message_handler_req_lib_amf_readinessstateget (struct conn_info *conn_info, void *message)
  3502. {
  3503. <<<<<<< .mine
  3504. struct req_lib_amf_readinessstateget *req_lib_amf_readinessstateget = (struct req_lib_amf_readinessstateget *)message;
  3505. =======
  3506. struct req_lib_amf_componentregister *req_lib_amf_componentregister = (struct req_lib_amf_componentregister *)message;
  3507. struct req_exec_amf_componentregister req_exec_amf_componentregister;
  3508. struct iovec iovec;
  3509. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentregister()\n");
  3510. req_exec_amf_componentregister.header.size = sizeof (struct req_exec_amf_componentregister);
  3511. req_exec_amf_componentregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTREGISTER;
  3512. message_source_set (&req_exec_amf_componentregister.source, conn_info);
  3513. memcpy (&req_exec_amf_componentregister.req_lib_amf_componentregister,
  3514. req_lib_amf_componentregister,
  3515. sizeof (struct req_lib_amf_componentregister));
  3516. iovec.iov_base = (char *)&req_exec_amf_componentregister;
  3517. iovec.iov_len = sizeof (req_exec_amf_componentregister);
  3518. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  3519. return (0);
  3520. }
  3521. static int message_handler_req_amf_componentunregister (struct conn_info *conn_info, void *message)
  3522. {
  3523. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  3524. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  3525. struct iovec iovec;
  3526. struct saAmfComponent *component;
  3527. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentunregister()\n");
  3528. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  3529. req_exec_amf_componentunregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER;
  3530. message_source_set (&req_exec_amf_componentunregister.source, conn_info);
  3531. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  3532. req_lib_amf_componentunregister,
  3533. sizeof (struct req_lib_amf_componentunregister));
  3534. component = findComponent (&req_lib_amf_componentunregister->compName);
  3535. if (component && component->registered && component->local) {
  3536. component->probableCause = SA_AMF_NOT_RESPONDING;
  3537. }
  3538. iovec.iov_base = (char *)&req_exec_amf_componentunregister;
  3539. iovec.iov_len = sizeof (req_exec_amf_componentunregister);
  3540. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  3541. return (0);
  3542. }
  3543. static int message_handler_req_amf_readinessstateget (struct conn_info *conn_info, void *message)
  3544. {
  3545. struct req_amf_readinessstateget *req_amf_readinessstateget = (struct req_amf_readinessstateget *)message;
  3546. >>>>>>> .r872
  3547. struct res_lib_amf_readinessstateget res_lib_amf_readinessstateget;
  3548. struct amf_comp *component;
  3549. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_readinessstateget()\n");
  3550. res_lib_amf_readinessstateget.header.id = MESSAGE_RES_AMF_READINESSSTATEGET;
  3551. res_lib_amf_readinessstateget.header.size = sizeof (struct res_lib_amf_readinessstateget);
  3552. res_lib_amf_readinessstateget.header.error = SA_ERR_NOT_EXIST;
  3553. component = find_comp (&req_lib_amf_readinessstateget->compName);
  3554. log_printf (LOG_LEVEL_DEBUG, "readinessstateget: found component %p\n", component);
  3555. if (component) {
  3556. memcpy (&res_lib_amf_readinessstateget.readinessState,
  3557. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  3558. res_lib_amf_readinessstateget.header.error = SA_OK;
  3559. }
  3560. libais_send_response (conn_info, &res_lib_amf_readinessstateget, sizeof (struct res_lib_amf_readinessstateget));
  3561. return (0);
  3562. }
  3563. static int message_handler_req_lib_amf_stoppingcomplete (struct conn_info *conn_info_notused,
  3564. void *message)
  3565. {
  3566. struct req_lib_amf_stoppingcomplete *req_lib_amf_stoppingcomplete = (struct req_lib_amf_stoppingcomplete *)message;
  3567. <<<<<<< .mine
  3568. struct conn_info *inv_conn_info;
  3569. =======
  3570. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_protectiongrouptrackstart()\n");
  3571. amfProtectionGroup = protectiongroup_find (&req_amf_protectiongrouptrackstart->csiName);
  3572. if (amfProtectionGroup) {
  3573. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstart: Got valid track start on CSI: %s.\n", getSaNameT (&req_amf_protectiongrouptrackstart->csiName));
  3574. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  3575. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) {
  3576. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  3577. break;
  3578. }
  3579. }
  3580. if (track == 0) {
  3581. grow_amf_track_table (conn_info, 1);
  3582. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  3583. }
  3584. track->active = 1;
  3585. track->trackFlags = req_amf_protectiongrouptrackstart->trackFlags;
  3586. track->notificationBufferAddress = req_amf_protectiongrouptrackstart->notificationBufferAddress;
  3587. memcpy (&track->csiName,
  3588. &req_amf_protectiongrouptrackstart->csiName, sizeof (SaNameT));
  3589. conn_info->ais_ci.u.libamf_ci.trackActive += 1;
  3590. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  3591. /*
  3592. * If SA_TRACK_CURRENT is specified, write out all current connections
  3593. */
  3594. } else {
  3595. log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
  3596. }
  3597. res_lib_amf_protectiongrouptrackstart.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART;
  3598. res_lib_amf_protectiongrouptrackstart.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstart);
  3599. res_lib_amf_protectiongrouptrackstart.header.error = SA_ERR_NOT_EXIST;
  3600. if (amfProtectionGroup) {
  3601. res_lib_amf_protectiongrouptrackstart.header.error = SA_OK;
  3602. }
  3603. libais_send_response (conn_info, &res_lib_amf_protectiongrouptrackstart,
  3604. sizeof (struct res_lib_amf_protectiongrouptrackstart));
  3605. if (amfProtectionGroup &&
  3606. req_amf_protectiongrouptrackstart->trackFlags & SA_TRACK_CURRENT) {
  3607. protectiongroup_notification_send (conn_info,
  3608. track->notificationBufferAddress,
  3609. amfProtectionGroup,
  3610. 0,
  3611. 0,
  3612. SA_TRACK_CHANGES_ONLY);
  3613. track->trackFlags &= ~SA_TRACK_CURRENT;
  3614. }
  3615. return (0);
  3616. }
  3617. static int message_handler_req_amf_protectiongrouptrackstop (struct conn_info *conn_info, void *message)
  3618. {
  3619. struct req_amf_protectiongrouptrackstop *req_amf_protectiongrouptrackstop = (struct req_amf_protectiongrouptrackstop *)message;
  3620. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  3621. struct libamf_ci_trackentry *track = 0;
  3622. int i;
  3623. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_protectiongrouptrackstop()\n");
  3624. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  3625. if (name_match (&req_amf_protectiongrouptrackstop->csiName,
  3626. &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) {
  3627. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  3628. }
  3629. }
  3630. if (track) {
  3631. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_amf_protectiongrouptrackstop->csiName));
  3632. memset (track, 0, sizeof (struct libamf_ci_trackentry));
  3633. conn_info->ais_ci.u.libamf_ci.trackActive -= 1;
  3634. if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) {
  3635. list_del (&conn_info->conn_list);
  3636. }
  3637. }
  3638. res_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
  3639. res_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstop);
  3640. res_lib_amf_protectiongrouptrackstop.header.error = SA_ERR_NOT_EXIST;
  3641. if (track) {
  3642. res_lib_amf_protectiongrouptrackstop.header.error = SA_OK;
  3643. }
  3644. libais_send_response (conn_info, &res_lib_amf_protectiongrouptrackstop,
  3645. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  3646. return (0);
  3647. }
  3648. static int message_handler_req_amf_errorreport (struct conn_info *conn_info, void *message)
  3649. {
  3650. struct req_lib_amf_errorreport *req_lib_amf_errorreport = (struct req_lib_amf_errorreport *)message;
  3651. struct req_exec_amf_errorreport req_exec_amf_errorreport;
  3652. struct iovec iovec;
  3653. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_errorreport()\n");
  3654. req_exec_amf_errorreport.header.size = sizeof (struct req_exec_amf_errorreport);
  3655. req_exec_amf_errorreport.header.id = MESSAGE_REQ_EXEC_AMF_ERRORREPORT;
  3656. message_source_set (&req_exec_amf_errorreport.source, conn_info);
  3657. memcpy (&req_exec_amf_errorreport.req_lib_amf_errorreport,
  3658. req_lib_amf_errorreport,
  3659. sizeof (struct req_lib_amf_errorreport));
  3660. iovec.iov_base = (char *)&req_exec_amf_errorreport;
  3661. iovec.iov_len = sizeof (req_exec_amf_errorreport);
  3662. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  3663. return (0);
  3664. }
  3665. static int message_handler_req_amf_errorcancelall (struct conn_info *conn_info, void *message)
  3666. {
  3667. struct req_lib_amf_errorcancelall *req_lib_amf_errorcancelall = (struct req_lib_amf_errorcancelall *)message;
  3668. struct req_exec_amf_errorcancelall req_exec_amf_errorcancelall;
  3669. struct iovec iovec;
  3670. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_errorcancelall()\n");
  3671. req_exec_amf_errorcancelall.header.size = sizeof (struct req_exec_amf_errorcancelall);
  3672. req_exec_amf_errorcancelall.header.id = MESSAGE_REQ_EXEC_AMF_ERRORCANCELALL;
  3673. message_source_set (&req_exec_amf_errorcancelall.source, conn_info);
  3674. memcpy (&req_exec_amf_errorcancelall.req_lib_amf_errorcancelall,
  3675. req_lib_amf_errorcancelall,
  3676. sizeof (struct req_lib_amf_errorcancelall));
  3677. iovec.iov_base = (char *)&req_exec_amf_errorcancelall;
  3678. iovec.iov_len = sizeof (req_exec_amf_errorcancelall);
  3679. assert (totempg_groups_mcast_joined (openais_group_handle, iovec, 1, TOTEMPG_AGREED) == 0);
  3680. return (0);
  3681. }
  3682. static int message_handler_req_amf_stoppingcomplete (struct conn_info *conn_info_notused,
  3683. void *message)
  3684. {
  3685. struct req_amf_stoppingcomplete *req_amf_stoppingcomplete = (struct req_amf_stoppingcomplete *)message;
  3686. struct conn_info *inv_conn_info = NULL;
  3687. >>>>>>> .r872
  3688. int interface;
  3689. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_stoppingcomplete()\n");
  3690. req_lib_amf_invocation_get_and_destroy (req_lib_amf_stoppingcomplete->invocation,
  3691. &interface, &inv_conn_info);
  3692. inv_conn_info->component->currentReadinessState = inv_conn_info->component->newReadinessState;
  3693. readiness_state_group_set (inv_conn_info->component, SA_AMF_STOPPING);
  3694. protectiongroup_notifications_send (inv_conn_info->component,SA_AMF_PROTECTION_GROUP_STATE_CHANGE);
  3695. return (0);
  3696. }
  3697. void response_handler_healthcheckcallback (struct conn_info *conn_info,
  3698. struct req_lib_amf_response *req_lib_amf_response) {
  3699. if (req_lib_amf_response->error == SA_OK) {
  3700. log_printf (LOG_LEVEL_DEBUG, "setting healthcheck ok\n");
  3701. conn_info->component->healthcheck_outstanding = 0;
  3702. }
  3703. }
  3704. static int message_handler_req_lib_amf_componentcapabilitymodelget (struct conn_info *conn_info, void *message)
  3705. {
  3706. struct req_lib_amf_componentcapabilitymodelget *req_lib_amf_componentcapabilitymodelget = (struct req_lib_amf_componentcapabilitymodelget *)message;
  3707. struct res_lib_amf_componentcapabilitymodelget res_lib_amf_componentcapabilitymodelget;
  3708. struct amf_comp *component;
  3709. SaErrorT error = SA_OK;
  3710. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componentcapabilitymodelget()\n");
  3711. memset( &res_lib_amf_componentcapabilitymodelget,0,sizeof(res_lib_amf_componentcapabilitymodelget));
  3712. log_printf (LOG_LEVEL_DEBUG, "componentcapabilitymodelget: Retrieve name %s.\n", getSaNameT (&req_lib_amf_componentcapabilitymodelget->compName));
  3713. component = find_comp (&req_lib_amf_componentcapabilitymodelget->compName);
  3714. if (component && component->registered) {
  3715. memcpy (&res_lib_amf_componentcapabilitymodelget.componentCapabilityModel,
  3716. &component->componentCapabilityModel, sizeof (SaAmfComponentCapabilityModelT));
  3717. } else {
  3718. error = SA_ERR_NOT_EXIST;
  3719. }
  3720. res_lib_amf_componentcapabilitymodelget.header.size = sizeof (struct res_lib_amf_componentcapabilitymodelget);
  3721. res_lib_amf_componentcapabilitymodelget.header.id = MESSAGE_RES_AMF_COMPONENTCAPABILITYMODELGET;
  3722. res_lib_amf_componentcapabilitymodelget.header.error = error;
  3723. libais_send_response (conn_info, &res_lib_amf_componentcapabilitymodelget,
  3724. sizeof (struct res_lib_amf_componentcapabilitymodelget));
  3725. return (0);
  3726. }
  3727. static char disabled_unlocked_state_text[6][64] = {
  3728. "AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL",
  3729. "AMF_DISABLED_UNLOCKED_FAILED",
  3730. "AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED",
  3731. "AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED",
  3732. "AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED",
  3733. "AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED"
  3734. };
  3735. static char *disabledunlockedstate_ntoa (int state)
  3736. {
  3737. static char str[64];
  3738. if (state >= 0 && state < 6) {
  3739. sprintf (str, "%s(%d)", disabled_unlocked_state_text[state], state);
  3740. }else{
  3741. sprintf (str, "Unknown(%d)", state);
  3742. }
  3743. return (str);
  3744. }
  3745. static char enabled_unlocked_state_text[7][64] = {
  3746. "AMF_ENABLED_UNLOCKED_INITIAL",
  3747. "AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED",
  3748. "AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED",
  3749. "AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED",
  3750. "AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED",
  3751. "AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED",
  3752. "AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED"
  3753. };
  3754. static char *enabledunlockedstate_ntoa (int state)
  3755. {
  3756. static char str[64];
  3757. if (state >= 0 && state < 7) {
  3758. sprintf (str, "%s(%d)", enabled_unlocked_state_text[state], state);
  3759. }else{
  3760. sprintf (str, "Unknown(%d)", state);
  3761. }
  3762. return (str);
  3763. }
  3764. #endif
  3765. static char presence_state_text[8][32] = {
  3766. "unknown",
  3767. "uninstantiated",
  3768. "instantiating",
  3769. "instantiated",
  3770. "terminating",
  3771. "restarting",
  3772. "instantion_failed",
  3773. "terminiation_failed"
  3774. };
  3775. static char *presencestate_ntoa (OpenaisCfgPresenceStateT state)
  3776. {
  3777. static char str[32];
  3778. if (state > 0 && state < 9) {
  3779. sprintf (str, "%s(%d)", presence_state_text[state], state);
  3780. }else{
  3781. sprintf (str, "Unknown(%d)", state);
  3782. }
  3783. return (str);
  3784. }
  3785. static char operational_state_text[4][64] = {
  3786. "Unknown",
  3787. "enabled",
  3788. "disabled"
  3789. };
  3790. static char *operationalstate_ntoa (OpenaisCfgOperationalStateT state)
  3791. {
  3792. static char str[32];
  3793. if (state > 0 && state < 3) {
  3794. sprintf (str, "%s(%d)", operational_state_text[state], state);
  3795. }else{
  3796. sprintf (str, "Unknown(%d)", state);
  3797. }
  3798. return (str);
  3799. }
  3800. static char readiness_state_text[4][32] = {
  3801. "Unknown",
  3802. "out of service",
  3803. "in service",
  3804. "quiesced",
  3805. };
  3806. static char *readinessstate_ntoa (int state)
  3807. {
  3808. static char str[32];
  3809. if (state > 0 && state < 4) {
  3810. sprintf (str, "%s(%d)", readiness_state_text[state], state);
  3811. }else{
  3812. sprintf (str, "Unknown(%d)", state);
  3813. }
  3814. return (str);
  3815. }
  3816. static char ha_state_text[4][32] = {
  3817. "Unknown",
  3818. "active",
  3819. "standby",
  3820. "quiesced",
  3821. };
  3822. static char *hastate_ntoa (SaAmfHAStateT state)
  3823. {
  3824. static char str[32];
  3825. if (state > 0 && state < 4) {
  3826. sprintf (str, "%s(%d)", ha_state_text[state], state);
  3827. }else{
  3828. sprintf (str, "Unknown(%d)", state);
  3829. }
  3830. return (str);
  3831. }
  3832. #ifdef COMPILE_OUT
  3833. static void amf_dump_comp (struct amf_comp *component ,void *data)
  3834. {
  3835. char name[64];
  3836. int level = LOG_LEVEL_NOTICE;
  3837. data = NULL;
  3838. log_printf (level, "----------------\n" );
  3839. log_printf (level, "registered = %d\n" ,component->registered);
  3840. log_printf (level, "local = %d\n" ,component->local );
  3841. log_printf (level, "source_addr = %s\n" ,inet_ntoa (component->source_addr));
  3842. memset (name, 0 , sizeof(name));
  3843. memcpy (name, component->name.value, component->name.length);
  3844. log_printf (level, "name = %s\n" ,name );
  3845. log_printf (level, "currentReadinessState = %s\n" ,readinessstate_ntoa (component->currentReadinessState));
  3846. log_printf (level, "newReadinessState = %s\n" ,readinessstate_ntoa (component->newReadinessState));
  3847. log_printf (level, "currentHAState = %s\n" ,hastate_ntoa (component->currentHAState));
  3848. log_printf (level, "newHAState = %s\n" ,hastate_ntoa (component->newHAState));
  3849. log_printf (level, "enabledUnlockedState = %s\n" ,enabledunlockedstate_ntoa (component->enabledUnlockedState));
  3850. log_printf (level, "disabledUnlockedState = %s\n" ,disabledunlockedstate_ntoa (component->disabledUnlockedState));
  3851. log_printf (level, "probableCause = %d\n" ,component->probableCause );
  3852. }
  3853. void amf_dump ( )
  3854. {
  3855. enumerate_components (amf_dump_comp, NULL);
  3856. fflush (stderr);
  3857. return;
  3858. }
  3859. #endif