amf.c 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873
  1. /*
  2. * Copyright (c) 2002-2005 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <sys/types.h>
  35. #include <sys/uio.h>
  36. #include <sys/socket.h>
  37. #include <sys/un.h>
  38. #include <netinet/in.h>
  39. #include <arpa/inet.h>
  40. #include <unistd.h>
  41. #include <fcntl.h>
  42. #include <stdlib.h>
  43. #include <stdio.h>
  44. #include <errno.h>
  45. #include <signal.h>
  46. #include <string.h>
  47. #include "../include/ais_types.h"
  48. #include "../include/ais_msg.h"
  49. #include "../include/list.h"
  50. #include "../include/queue.h"
  51. #include "totempg.h"
  52. #include "aispoll.h"
  53. #include "mempool.h"
  54. #include "util.h"
  55. #include "parse.h"
  56. #include "main.h"
  57. #include "handlers.h"
  58. #define LOG_SERVICE LOG_SERVICE_AMF
  59. #include "print.h"
  60. #define LOG_LEVEL_FROM_LIB LOG_LEVEL_DEBUG
  61. #define LOG_LEVEL_FROM_GMI LOG_LEVEL_DEBUG
  62. #define LOG_LEVEL_ENTER_FUNC LOG_LEVEL_DEBUG
  63. struct invocation {
  64. struct conn_info *conn_info;
  65. int interface;
  66. int active;
  67. };
  68. struct invocation *invocation_entries = 0;
  69. int invocation_entries_size = 0;
  70. //TODO static void *tok_call_handle = NULL;
  71. static int recovery = 0;
  72. #ifdef INPARSEDOTH
  73. enum amfOperationalState {
  74. AMF_OPER_DISABLED,
  75. AMF_OPER_ENABLED
  76. };
  77. enum amfAdministrativeState {
  78. AMF_ADMIN_UNLOCKED,
  79. AMF_ADMIN_LOCKED,
  80. AMF_ADMIN_STOPPING
  81. };
  82. enum amfOperationalAdministrativeState {
  83. AMF_ENABLED_UNLOCKED,
  84. AMF_DISABLED_UNLOCKED,
  85. AMF_DISABLED_LOCKED,
  86. AMF_ENABLED_STOPPING
  87. };
  88. /*
  89. * State machines for states in AMF
  90. */
  91. enum amfEnabledUnlockedState {
  92. AMF_ENABLED_UNLOCKED_INITIAL,
  93. AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED,
  94. AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED,
  95. AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED,
  96. AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED,
  97. AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED,
  98. AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED,
  99. };
  100. enum amfDisabledUnlockedState {
  101. AMF_DISABLED_UNLOCKED_INITIAL,
  102. AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED,
  103. AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED,
  104. AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED,
  105. AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED
  106. };
  107. enum amfDisabledLockedState {
  108. AMF_DISABLED_LOCKED_INITIAL,
  109. AMF_DISABLED_LOCKED_QUIESCED_REQUESTED,
  110. AMF_DISABLED_LOCKED_QUIESCED_COMPLETED,
  111. AMF_DISABLED_LOCKED_OUT_OF_SERVICE_REQUESTED
  112. AMF_DISABLED_LOCKED_OUT_OF_SERVICE_COMPLETED
  113. };
  114. enum amfEnabledStoppingState {
  115. AMF_ENABLED_STOPPING_INITIAL,
  116. AMF_ENABLED_STOPPING_STOPPING_REQUESTED,
  117. AMF_ENABLED_STOPPING_STOPPING_COMPLETED
  118. };
  119. /*
  120. * Internal Functions
  121. */
  122. static void componentOutOfServiceSetNoApi (
  123. struct saAmfComponent *component);
  124. #endif
  125. static void grow_amf_track_table (
  126. struct conn_info *conn_info,
  127. int growby);
  128. static int activeServiceUnitsCount (
  129. struct saAmfGroup *saAmfGroup);
  130. static void component_unregister (
  131. struct saAmfComponent *component);
  132. static void enumerate_components (
  133. void (*function)(struct saAmfComponent *, void *data),
  134. void *data);
  135. #ifdef COMPILE_OUT
  136. static void CSIRemove (
  137. struct conn_info *conn_info);
  138. static void haStateSetClusterInit (
  139. struct conn_info *conn_info,
  140. struct saAmfComponent *saAmfComponent);
  141. #endif
  142. static void ha_state_api_set (
  143. struct saAmfComponent *saAmfComponent,
  144. SaAmfHAStateT haState);
  145. static void ha_state_group_set (
  146. struct saAmfComponent *saAmfComponent,
  147. SaAmfHAStateT haState);
  148. static void readiness_state_api_set (
  149. struct saAmfComponent *component,
  150. SaAmfReadinessStateT readinessState);
  151. #ifdef COMPILE_OUT
  152. static void readinessStateSetClusterInit (
  153. struct conn_info *conn_info,
  154. struct saAmfComponent *saAmfComponent);
  155. #endif
  156. static void readiness_state_group_set (
  157. struct saAmfComponent *saAmfComponent,
  158. SaAmfReadinessStateT readinessState);
  159. #ifdef COMPILE_OUT
  160. static void enumerateComponentsClusterInit (
  161. struct saAmfComponent *component,
  162. void *data);
  163. #endif
  164. static void dsm (
  165. struct saAmfComponent *saAmfComponent);
  166. #if 0 /* NOT IMPLEMENTED */
  167. static void componentTerminate (
  168. struct conn_info *conn_info);
  169. #endif
  170. static void timer_function_libamf_healthcheck (
  171. void *data);
  172. static struct saAmfProtectionGroup *protectiongroup_find (
  173. SaNameT *csiName);
  174. static struct saAmfComponent *component_in_protectiongroup_find (
  175. SaNameT *csiName,
  176. SaNameT *compName);
  177. static void protectiongroup_notifications_send (
  178. struct saAmfComponent *changedComponent,
  179. SaAmfProtectionGroupChangesT changeToComponent);
  180. static void protectiongroup_notification_send (
  181. struct conn_info *conn_info,
  182. SaAmfProtectionGroupNotificationT *notificationBufferAddress,
  183. struct saAmfProtectionGroup *amfProtectionGroup,
  184. struct saAmfComponent *changedComponent,
  185. SaAmfProtectionGroupChangesT changeToComponent,
  186. SaUint8T trackFlags);
  187. static void response_handler_readinessstatesetcallback (
  188. struct conn_info *conn_info,
  189. struct req_amf_response *req_amf_response);
  190. static void response_handler_csisetcallback (
  191. struct conn_info *conn_info,
  192. struct req_amf_response *req_amf_response);
  193. static void amf_confchg_nleave (
  194. struct saAmfComponent *component,
  195. void *data);
  196. static void amf_confchg_njoin (
  197. struct saAmfComponent *component,
  198. void *data);
  199. static int amf_confchg_fn (
  200. enum totem_configuration_type configuration_type,
  201. struct in_addr *member_list, void *member_list_private,
  202. int member_list_entries,
  203. struct in_addr *left_list, void *left_list_private,
  204. int left_list_entries,
  205. struct in_addr *joined_list, void *joined_list_private,
  206. int joined_list_entries,
  207. struct memb_ring_id *ring_id);
  208. /***
  209. static void amf_dump (void);
  210. ***/
  211. static int amf_exit_fn (struct conn_info *conn_info);
  212. static int amf_exec_init_fn (void);
  213. static void amf_synchronize (void *message, struct in_addr source_addr);
  214. static int message_handler_req_exec_amf_componentregister (void *message, struct in_addr source_addr, int endian_conversion_required);
  215. static int message_handler_req_exec_amf_componentunregister (void *message, struct in_addr source_addr, int endian_conversion_required);
  216. static int message_handler_req_exec_amf_errorreport (void *message, struct in_addr source_addr, int endian_conversion_required);
  217. static int message_handler_req_exec_amf_errorcancelall (void *message, struct in_addr source_addr, int endian_conversion_required);
  218. static int message_handler_req_exec_amf_readinessstateset (void *message, struct in_addr source_addr, int endian_conversion_required);
  219. static int message_handler_req_exec_amf_hastateset (void *message, struct in_addr source_addr, int endian_conversion_required);
  220. static int message_handler_req_amf_init (struct conn_info *conn_info, void *message);
  221. static int message_handler_req_lib_activatepoll (struct conn_info *conn_info, void *message);
  222. static int message_handler_req_amf_componentregister (struct conn_info *conn_info, void *message);
  223. static int message_handler_req_amf_componentunregister (struct conn_info *conn_info, void *message);
  224. static int message_handler_req_amf_readinessstateget (struct conn_info *conn_info, void *message);
  225. static int message_handler_req_amf_hastateget (struct conn_info *conn_info, void *message);
  226. static int message_handler_req_amf_protectiongrouptrackstart (struct conn_info *conn_info, void *message);
  227. static int message_handler_req_amf_protectiongrouptrackstop (struct conn_info *conn_info, void *message);
  228. static int message_handler_req_amf_errorreport (struct conn_info *conn_info, void *message);
  229. static int message_handler_req_amf_errorcancelall (struct conn_info *conn_info, void *message);
  230. static int message_handler_req_amf_stoppingcomplete (struct conn_info *conn_info, void *message);
  231. static int message_handler_req_amf_response (struct conn_info *conn_info, void *message);
  232. static int message_handler_req_amf_componentcapabilitymodelget (struct conn_info *conn_info, void *message);
  233. /*
  234. int (*amf_libais_handler_fns[]) (struct conn_info *conn_info, void *) = {
  235. message_handler_req_lib_activatepoll,
  236. message_handler_req_amf_componentregister,
  237. message_handler_req_amf_componentunregister,
  238. message_handler_req_amf_readinessstateget,
  239. message_handler_req_amf_hastateget,
  240. message_handler_req_amf_protectiongrouptrackstart,
  241. message_handler_req_amf_protectiongrouptrackstop,
  242. message_handler_req_amf_errorreport,
  243. message_handler_req_amf_errorcancelall,
  244. message_handler_req_amf_stoppingcomplete,
  245. message_handler_req_amf_response,
  246. message_handler_req_amf_componentcapabilitymodelget
  247. };
  248. */
  249. struct libais_handler amf_libais_handlers[] =
  250. {
  251. { /* 0 */
  252. .libais_handler_fn = message_handler_req_lib_activatepoll,
  253. .response_size = sizeof (struct res_lib_activatepoll),
  254. .response_id = MESSAGE_RES_LIB_ACTIVATEPOLL, // TODO RESPONSE
  255. .flow_control = FLOW_CONTROL_REQUIRED
  256. },
  257. { /* 1 */
  258. .libais_handler_fn = message_handler_req_amf_componentregister,
  259. .response_size = sizeof (struct res_lib_amf_componentregister),
  260. .response_id = MESSAGE_RES_AMF_COMPONENTREGISTER,
  261. .flow_control = FLOW_CONTROL_REQUIRED
  262. },
  263. { /* 2 */
  264. .libais_handler_fn = message_handler_req_amf_componentunregister,
  265. .response_size = sizeof (struct res_lib_amf_componentunregister),
  266. .response_id = MESSAGE_RES_AMF_COMPONENTUNREGISTER,
  267. .flow_control = FLOW_CONTROL_REQUIRED
  268. },
  269. { /* 3 */
  270. .libais_handler_fn = message_handler_req_amf_readinessstateget,
  271. .response_size = sizeof (struct res_lib_amf_readinessstateget),
  272. .response_id = MESSAGE_RES_AMF_READINESSSTATEGET,
  273. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  274. },
  275. { /* 4 */
  276. .libais_handler_fn = message_handler_req_amf_hastateget,
  277. .response_size = sizeof (struct res_lib_amf_hastateget),
  278. .response_id = MESSAGE_RES_AMF_READINESSSTATEGET,
  279. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  280. },
  281. { /* 5 */
  282. .libais_handler_fn = message_handler_req_amf_protectiongrouptrackstart,
  283. .response_size = sizeof (struct res_lib_amf_protectiongrouptrackstart),
  284. .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART,
  285. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  286. },
  287. { /* 6 */
  288. .libais_handler_fn = message_handler_req_amf_protectiongrouptrackstop,
  289. .response_size = sizeof (struct res_lib_amf_protectiongrouptrackstop),
  290. .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP,
  291. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  292. },
  293. { /* 7 */
  294. .libais_handler_fn = message_handler_req_amf_errorreport,
  295. .response_size = sizeof (struct res_lib_amf_errorreport),
  296. .response_id = MESSAGE_RES_AMF_ERRORREPORT,
  297. .flow_control = FLOW_CONTROL_REQUIRED
  298. },
  299. { /* 8 */
  300. .libais_handler_fn = message_handler_req_amf_errorcancelall,
  301. .response_size = sizeof (struct res_lib_amf_errorcancelall),
  302. .response_id = MESSAGE_RES_AMF_ERRORCANCELALL,
  303. .flow_control = FLOW_CONTROL_REQUIRED
  304. },
  305. { /* 9 */
  306. .libais_handler_fn = message_handler_req_amf_stoppingcomplete,
  307. .response_size = sizeof (struct res_lib_amf_stoppingcomplete),
  308. .response_id = MESSAGE_RES_AMF_STOPPINGCOMPLETE, // TODO
  309. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  310. },
  311. { /* 10 */
  312. .libais_handler_fn = message_handler_req_amf_response,
  313. .response_size = sizeof (struct res_lib_amf_response),
  314. .response_id = MESSAGE_RES_AMF_RESPONSE, // TODO
  315. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  316. },
  317. { /* 11 */
  318. .libais_handler_fn = message_handler_req_amf_componentcapabilitymodelget,
  319. .response_size = sizeof (struct res_lib_amf_componentcapabilitymodelget),
  320. .response_id = MESSAGE_RES_AMF_COMPONENTCAPABILITYMODELGET,
  321. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  322. }
  323. };
  324. int (*amf_aisexec_handler_fns[]) (void *, struct in_addr source_addr, int endian_conversion_required) = {
  325. message_handler_req_exec_amf_componentregister,
  326. message_handler_req_exec_amf_componentunregister,
  327. message_handler_req_exec_amf_errorreport,
  328. message_handler_req_exec_amf_errorcancelall,
  329. message_handler_req_exec_amf_readinessstateset,
  330. message_handler_req_exec_amf_hastateset,
  331. };
  332. /*
  333. * Exports the interface for the service
  334. */
  335. struct service_handler amf_service_handler = {
  336. .libais_handlers = amf_libais_handlers,
  337. .libais_handlers_count = sizeof (amf_libais_handlers) / sizeof (struct libais_handler),
  338. .aisexec_handler_fns = amf_aisexec_handler_fns,
  339. .aisexec_handler_fns_count = sizeof (amf_aisexec_handler_fns) / sizeof (int (*)),
  340. .confchg_fn = amf_confchg_fn,
  341. .libais_init_fn = message_handler_req_amf_init,
  342. .libais_exit_fn = amf_exit_fn,
  343. .exec_init_fn = amf_exec_init_fn,
  344. .exec_dump_fn = amf_dump
  345. };
  346. static void grow_amf_track_table (struct conn_info *conn_info, int growby)
  347. {
  348. struct libamf_ci_trackentry *tracks;
  349. int newsize;
  350. int currsize = conn_info->ais_ci.u.libamf_ci.trackEntries;
  351. newsize = growby + currsize;
  352. if (newsize > currsize) {
  353. tracks = (struct libamf_ci_trackentry *)mempool_realloc (conn_info->ais_ci.u.libamf_ci.tracks,
  354. (newsize) * sizeof (struct libamf_ci_trackentry));
  355. if (tracks == 0) {
  356. #ifdef DEBUG
  357. printf ("grow_amf_track_table: out of memory, woops\n");
  358. #endif
  359. // TODO
  360. exit (1);
  361. }
  362. memset (&tracks[currsize], 0, growby * sizeof (struct libamf_ci_trackentry));
  363. conn_info->ais_ci.u.libamf_ci.trackEntries = newsize;
  364. conn_info->ais_ci.u.libamf_ci.tracks = tracks;
  365. }
  366. }
  367. int req_amf_invocation_create (int interface,
  368. struct conn_info *conn_info)
  369. {
  370. struct invocation *invocation_addr = 0;
  371. struct invocation *invocation_temp;
  372. int i;
  373. int loc = 0;
  374. for (i = 0; i < invocation_entries_size; i++) {
  375. if (invocation_entries[i].active == 0) {
  376. invocation_addr = &invocation_entries[i];
  377. loc = i;
  378. break;
  379. }
  380. }
  381. if (invocation_addr == 0) {
  382. invocation_temp = (struct invocation *)realloc (invocation_entries,
  383. (invocation_entries_size + 1) * sizeof (struct invocation));
  384. if (invocation_temp == 0) {
  385. return (-1);
  386. }
  387. invocation_entries = invocation_temp;
  388. invocation_addr = &invocation_entries[invocation_entries_size];
  389. loc = invocation_entries_size;
  390. invocation_entries_size += 1;
  391. }
  392. invocation_addr->interface = interface;
  393. invocation_addr->conn_info = conn_info;
  394. invocation_addr->active = 1;
  395. return (loc);
  396. }
  397. int req_amf_invocation_get_and_destroy (int invocation, int *interface,
  398. struct conn_info **conn_info)
  399. {
  400. if (invocation > invocation_entries_size) {
  401. return (-1);
  402. }
  403. if (invocation_entries[invocation].active == 0) {
  404. return (-1);
  405. }
  406. *interface = invocation_entries[invocation].interface;
  407. *conn_info = invocation_entries[invocation].conn_info;
  408. memset (&invocation_entries[invocation], 0, sizeof (struct invocation));
  409. return (0);
  410. }
  411. static void component_unregister (
  412. struct saAmfComponent *component)
  413. {
  414. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  415. struct iovec iovecs[2];
  416. /*
  417. * This only works on local components
  418. */
  419. if (component == 0 || component->local != 1) {
  420. return;
  421. }
  422. log_printf (LOG_LEVEL_ENTER_FUNC, "component_unregister: unregistering component %s\n",
  423. getSaNameT (&component->name));
  424. component->probableCause = SA_AMF_NOT_RESPONDING;
  425. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  426. req_exec_amf_componentunregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER;
  427. req_exec_amf_componentunregister.source.conn_info = 0;
  428. req_exec_amf_componentunregister.source.in_addr.s_addr = 0;
  429. memset (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  430. 0, sizeof (struct req_lib_amf_componentunregister));
  431. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister.compName,
  432. &component->name,
  433. sizeof (SaNameT));
  434. iovecs[0].iov_base = (char *)&req_exec_amf_componentunregister;
  435. iovecs[0].iov_len = sizeof (req_exec_amf_componentunregister);
  436. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  437. }
  438. static void component_register (
  439. struct saAmfComponent *component)
  440. {
  441. struct req_exec_amf_componentregister req_exec_amf_componentregister;
  442. struct iovec iovecs[2];
  443. /*
  444. * This only works on local components
  445. */
  446. if (component == 0 || component->local != 1) {
  447. return;
  448. }
  449. log_printf (LOG_LEVEL_ENTER_FUNC, "component_register: registering component %s\n",
  450. getSaNameT (&component->name));
  451. req_exec_amf_componentregister.header.size = sizeof (struct req_exec_amf_componentregister);
  452. req_exec_amf_componentregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTREGISTER;
  453. req_exec_amf_componentregister.source.conn_info = 0;
  454. req_exec_amf_componentregister.source.in_addr.s_addr = 0;
  455. req_exec_amf_componentregister.currentReadinessState = component->currentReadinessState;
  456. req_exec_amf_componentregister.newReadinessState = component->newReadinessState;
  457. req_exec_amf_componentregister.currentHAState = component->currentHAState;
  458. req_exec_amf_componentregister.newHAState = component->newHAState;
  459. memset (&req_exec_amf_componentregister.req_lib_amf_componentregister,
  460. 0, sizeof (struct req_lib_amf_componentregister));
  461. memcpy (&req_exec_amf_componentregister.req_lib_amf_componentregister.compName,
  462. &component->name,
  463. sizeof (SaNameT));
  464. iovecs[0].iov_base = (char *)&req_exec_amf_componentregister;
  465. iovecs[0].iov_len = sizeof (req_exec_amf_componentregister);
  466. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  467. }
  468. /***
  469. This should be used for a partition I think
  470. **/
  471. void enumerate_components (
  472. void (*function)(struct saAmfComponent *, void *data),
  473. void *data)
  474. {
  475. struct list_head *AmfGroupList;
  476. struct list_head *AmfUnitList;
  477. struct list_head *AmfComponentList;
  478. struct saAmfGroup *saAmfGroup;
  479. struct saAmfUnit *AmfUnit;
  480. struct saAmfComponent *AmfComponent;
  481. /*
  482. * Search all groups
  483. */
  484. for (AmfGroupList = saAmfGroupHead.next;
  485. AmfGroupList != &saAmfGroupHead;
  486. AmfGroupList = AmfGroupList->next) {
  487. saAmfGroup = list_entry (AmfGroupList,
  488. struct saAmfGroup, saAmfGroupList);
  489. /*
  490. * Search all units
  491. */
  492. for (AmfUnitList = saAmfGroup->saAmfUnitHead.next;
  493. AmfUnitList != &saAmfGroup->saAmfUnitHead;
  494. AmfUnitList = AmfUnitList->next) {
  495. AmfUnit = list_entry (AmfUnitList,
  496. struct saAmfUnit, saAmfUnitList);
  497. /*
  498. * Search all components
  499. */
  500. for (AmfComponentList = AmfUnit->saAmfComponentHead.next;
  501. AmfComponentList != &AmfUnit->saAmfComponentHead;
  502. AmfComponentList = AmfComponentList->next) {
  503. AmfComponent = list_entry (AmfComponentList,
  504. struct saAmfComponent, saAmfComponentList);
  505. function (AmfComponent, data);
  506. }
  507. }
  508. }
  509. }
  510. int activeServiceUnitsCount (struct saAmfGroup *saAmfGroup) {
  511. struct saAmfUnit *saAmfUnit;
  512. struct saAmfComponent *saAmfComponent;
  513. struct list_head *saAmfComponentList;
  514. struct list_head *saAmfUnitList;
  515. int activeServiceUnits = 0;
  516. int thisServiceUnitActive;
  517. /*
  518. * Search all units
  519. */
  520. for (activeServiceUnits = 0, saAmfUnitList = saAmfGroup->saAmfUnitHead.next;
  521. saAmfUnitList != &saAmfGroup->saAmfUnitHead;
  522. saAmfUnitList = saAmfUnitList->next) {
  523. saAmfUnit = list_entry (saAmfUnitList,
  524. struct saAmfUnit, saAmfUnitList);
  525. /*
  526. * Search all components
  527. */
  528. for (thisServiceUnitActive = 1, saAmfComponentList = saAmfUnit->saAmfComponentHead.next;
  529. saAmfComponentList != &saAmfUnit->saAmfComponentHead;
  530. saAmfComponentList = saAmfComponentList->next) {
  531. saAmfComponent = list_entry (saAmfComponentList,
  532. struct saAmfComponent, saAmfComponentList);
  533. if (saAmfComponent->newHAState != SA_AMF_ACTIVE) {
  534. thisServiceUnitActive = 0;
  535. }
  536. }
  537. /*
  538. * If all components are active in service unit, count service unit as active
  539. */
  540. if (thisServiceUnitActive) {
  541. activeServiceUnits += 1;
  542. }
  543. }
  544. return (activeServiceUnits);
  545. }
  546. #ifdef CONFIG_TODO
  547. This should be sent after a service unit is made out of service
  548. void CSIRemove (struct conn_info *conn_info)
  549. {
  550. struct res_lib_amf_csiremovecallback res_lib_amf_csiremovecallback;
  551. if (conn_info->active == 0 ||
  552. conn_info->service != SOCKET_SERVICE_AMF) {
  553. return;
  554. }
  555. log_printf (LOG_NOTICE_DEBUG, "executing CSI remove callback into API\n");
  556. res_lib_amf_csiremovecallback.header.id = MESSAGE_RES_AMF_CSIREMOVECALLBACK;
  557. res_lib_amf_csiremovecallback.header.size = sizeof (struct res_lib_amf_csiremovecallback);
  558. res_lib_amf_csiremovecallback.header.error = SA_OK;
  559. res_lib_amf_csiremovecallback.invocation =
  560. req_amf_response_set (
  561. MESSAGE_REQ_AMF_RESPONSE_SAAMFCSIREMOVECALLBACK,
  562. conn_info->fd);
  563. memcpy (&res_lib_amf_csiremovecallback.compName,
  564. &conn_info->component->name, sizeof (SaNameT));
  565. memcpy (&res_lib_amf_csiremovecallback.csiName,
  566. &conn_info->component->saAmfProtectionGroup->name, sizeof (SaNameT));
  567. res_lib_amf_csiremovecallback.csiFlags = SA_AMF_CSI_ALL_INSTANCES;
  568. libais_send_response (conn_info, &res_lib_amf_csiremovecallback,
  569. sizeof (struct res_lib_amf_csiremovecallback));
  570. }
  571. #endif
  572. void ha_state_api_set (struct saAmfComponent *component, SaAmfHAStateT haState)
  573. {
  574. struct res_lib_amf_csisetcallback res_lib_amf_csisetcallback;
  575. memset (&res_lib_amf_csisetcallback,0,sizeof(res_lib_amf_csisetcallback));
  576. log_printf (LOG_LEVEL_ENTER_FUNC, "sending ha state to API\n");
  577. if (component->local != 1) {
  578. return;
  579. }
  580. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  581. return;
  582. }
  583. /*
  584. * this should be an assertion
  585. */
  586. if (component->conn_info->state != CONN_STATE_ACTIVE ||
  587. component->conn_info->service != SOCKET_SERVICE_AMF) {
  588. return;
  589. }
  590. res_lib_amf_csisetcallback.header.id = MESSAGE_RES_AMF_CSISETCALLBACK;
  591. res_lib_amf_csisetcallback.header.size = sizeof (struct res_lib_amf_csisetcallback);
  592. res_lib_amf_csisetcallback.header.error = SA_OK;
  593. res_lib_amf_csisetcallback.invocation =
  594. req_amf_invocation_create (
  595. MESSAGE_REQ_AMF_RESPONSE_SAAMFCSISETCALLBACK,
  596. component->conn_info);
  597. if (res_lib_amf_csisetcallback.invocation == -1) {
  598. printf ("TODO set callback\n");
  599. }
  600. memcpy (&res_lib_amf_csisetcallback.compName,
  601. &component->name, sizeof (SaNameT));
  602. memcpy (&res_lib_amf_csisetcallback.csiName,
  603. &component->saAmfProtectionGroup->name, sizeof (SaNameT));
  604. res_lib_amf_csisetcallback.csiFlags = SA_AMF_CSI_ALL_INSTANCES;
  605. res_lib_amf_csisetcallback.haState = haState;
  606. // TODO set activeCompName to correct component name
  607. memcpy (&res_lib_amf_csisetcallback.activeCompName,
  608. &component->name, sizeof (SaNameT));
  609. res_lib_amf_csisetcallback.transitionDescriptor = SA_AMF_CSI_NEW_ASSIGN;
  610. component->newHAState = haState;
  611. libais_send_response (component->conn_info, &res_lib_amf_csisetcallback,
  612. sizeof (struct res_lib_amf_csisetcallback));
  613. }
  614. static void ha_state_group_set (
  615. struct saAmfComponent *component,
  616. SaAmfHAStateT haState)
  617. {
  618. struct req_exec_amf_hastateset req_exec_amf_hastateset;
  619. struct iovec iovecs[2];
  620. req_exec_amf_hastateset.header.id = MESSAGE_REQ_EXEC_AMF_HASTATESET;
  621. req_exec_amf_hastateset.header.size = sizeof (struct req_exec_amf_hastateset);
  622. memcpy (&req_exec_amf_hastateset.compName, &component->name, sizeof (SaNameT));
  623. req_exec_amf_hastateset.haState = haState;
  624. log_printf (LOG_LEVEL_ENTER_FUNC, "Sending ha state to cluster for component %s\n", getSaNameT (&component->name));
  625. log_printf (LOG_LEVEL_DEBUG, "ha state is %d\n", haState);
  626. iovecs[0].iov_base = (char *)&req_exec_amf_hastateset;
  627. iovecs[0].iov_len = sizeof (req_exec_amf_hastateset);
  628. totempg_mcast (iovecs, 1, TOTEMPG_AGREED);
  629. }
  630. void readiness_state_api_set (struct saAmfComponent *component,
  631. SaAmfReadinessStateT readinessState)
  632. {
  633. struct res_lib_amf_readinessstatesetcallback res_lib_amf_readinessstatesetcallback;
  634. memset (&res_lib_amf_readinessstatesetcallback,0,sizeof(res_lib_amf_readinessstatesetcallback));
  635. /*
  636. * If component is local, don't request service from API
  637. */
  638. if (component->local != 1) {
  639. return;
  640. }
  641. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  642. return;
  643. }
  644. /*
  645. * this should be an assertion
  646. */
  647. if (component->conn_info->state != CONN_STATE_ACTIVE ||
  648. component->conn_info->service != SOCKET_SERVICE_AMF) {
  649. return;
  650. }
  651. res_lib_amf_readinessstatesetcallback.header.id = MESSAGE_RES_AMF_READINESSSTATESETCALLBACK;
  652. res_lib_amf_readinessstatesetcallback.header.size = sizeof (struct res_lib_amf_readinessstatesetcallback);
  653. res_lib_amf_readinessstatesetcallback.header.error = SA_OK;
  654. res_lib_amf_readinessstatesetcallback.invocation =
  655. req_amf_invocation_create (
  656. MESSAGE_REQ_AMF_RESPONSE_SAAMFREADINESSSTATESETCALLBACK,
  657. component->conn_info);
  658. if (res_lib_amf_readinessstatesetcallback.invocation == -1) {
  659. printf ("TODO readiness set callback\n");
  660. }
  661. memcpy (&res_lib_amf_readinessstatesetcallback.compName,
  662. &component->name, sizeof (SaNameT));
  663. res_lib_amf_readinessstatesetcallback.readinessState = readinessState;
  664. component->newReadinessState = readinessState;
  665. log_printf (LOG_LEVEL_DEBUG, "Setting conn_info %p to readiness state %d\n", component->conn_info, readinessState);
  666. libais_send_response (component->conn_info, &res_lib_amf_readinessstatesetcallback,
  667. sizeof (struct res_lib_amf_readinessstatesetcallback));
  668. }
  669. static void readiness_state_group_set (
  670. struct saAmfComponent *component,
  671. SaAmfReadinessStateT readinessState)
  672. {
  673. struct req_exec_amf_readinessstateset req_exec_amf_readinessstateset;
  674. struct iovec iovecs[2];
  675. req_exec_amf_readinessstateset.header.id = MESSAGE_REQ_EXEC_AMF_READINESSSTATESET;
  676. req_exec_amf_readinessstateset.header.size = sizeof (struct req_exec_amf_readinessstateset);
  677. memcpy (&req_exec_amf_readinessstateset.compName, &component->name, sizeof (SaNameT));
  678. req_exec_amf_readinessstateset.readinessState = readinessState;
  679. log_printf (LOG_LEVEL_ENTER_FUNC, "Sending message to all cluster nodes to set readiness state of component %s\n",
  680. getSaNameT (&component->name));
  681. log_printf (LOG_LEVEL_DEBUG, "readiness state is %d\n", readinessState);
  682. iovecs[0].iov_base = (char *)&req_exec_amf_readinessstateset;
  683. iovecs[0].iov_len = sizeof (req_exec_amf_readinessstateset);
  684. totempg_mcast (iovecs, 1, TOTEMPG_AGREED);
  685. }
  686. static void dsmDisabledUnlockedRegisteredOrErrorCancel (
  687. struct saAmfComponent *component)
  688. {
  689. struct saAmfUnit *unit;
  690. struct list_head *list;
  691. int serviceUnitEnabled;
  692. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedRegisteredOrErrorCancel for %s\n",
  693. getSaNameT (&component->name));
  694. unit = component->saAmfUnit;
  695. for (serviceUnitEnabled = 1, list = unit->saAmfComponentHead.next;
  696. list != &unit->saAmfComponentHead;
  697. list = list->next) {
  698. component = list_entry (list,
  699. struct saAmfComponent, saAmfComponentList);
  700. if (component->registered == 0 ||
  701. component->probableCause) {
  702. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not registered or failed.\n");
  703. serviceUnitEnabled = 0;
  704. break;
  705. }
  706. }
  707. if (serviceUnitEnabled == 1) {
  708. log_printf (LOG_LEVEL_DEBUG, "dsm entering AMF_ENABLED_UNLOCKED state.\n");
  709. component->saAmfUnit->operationalAdministrativeState = AMF_ENABLED_UNLOCKED;
  710. component->disabledUnlockedState = -1; // SHOULD BE INVALID
  711. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  712. dsm (component);
  713. }
  714. }
  715. static void dsmDisabledUnlockedFailedComponent (
  716. struct saAmfComponent *component)
  717. {
  718. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedFailedComponent: for %s.\n",
  719. getSaNameT (&component->name));
  720. switch (component->enabledUnlockedState) {
  721. case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED:
  722. case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED:
  723. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  724. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  725. readiness_state_group_set (component, SA_AMF_OUT_OF_SERVICE);
  726. } else {
  727. readiness_state_api_set (component, SA_AMF_OUT_OF_SERVICE);
  728. }
  729. break;
  730. case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED:
  731. case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED:
  732. case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED:
  733. case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED:
  734. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  735. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  736. ha_state_group_set (component, SA_AMF_QUIESCED);
  737. } else {
  738. ha_state_api_set (component, SA_AMF_QUIESCED);
  739. }
  740. poll_timer_delete (aisexec_poll_handle,
  741. component->timer_healthcheck);
  742. component->timer_healthcheck = 0;
  743. break;
  744. default:
  745. log_printf (LOG_LEVEL_DEBUG, "invalid case 5 %d\n", component->enabledUnlockedState);
  746. break;
  747. }
  748. }
  749. static void dsmDisabledUnlockedFailed (
  750. struct saAmfComponent *component)
  751. {
  752. struct saAmfUnit *unit;
  753. struct list_head *list;
  754. unit = component->saAmfUnit;
  755. for (list = unit->saAmfComponentHead.next;
  756. list != &unit->saAmfComponentHead;
  757. list = list->next) {
  758. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  759. dsmDisabledUnlockedFailedComponent (component);
  760. }
  761. return;
  762. }
  763. static void dsmDisabledUnlockedQuiescedRequested (
  764. struct saAmfComponent *component)
  765. {
  766. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED;
  767. dsm (component);
  768. }
  769. static void dsmDisabledUnlockedQuiescedCompleted (
  770. struct saAmfComponent *component)
  771. {
  772. struct saAmfUnit *unit;
  773. struct list_head *list;
  774. int serviceUnitQuiesced;
  775. unit = component->saAmfUnit;
  776. for (serviceUnitQuiesced = 1, list = unit->saAmfComponentHead.next;
  777. list != &unit->saAmfComponentHead;
  778. list = list->next) {
  779. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  780. if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) {
  781. if (component->currentHAState != SA_AMF_QUIESCED) {
  782. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n");
  783. serviceUnitQuiesced = 0;
  784. break;
  785. }
  786. }
  787. }
  788. if (serviceUnitQuiesced == 1) {
  789. log_printf (LOG_LEVEL_DEBUG, "All components have quiesced, Quiescing completed\n");
  790. for (list = unit->saAmfComponentHead.next;
  791. list != &unit->saAmfComponentHead;
  792. list = list->next) {
  793. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  794. log_printf (LOG_LEVEL_DEBUG, "dsm: Sending readiness state set to OUTOFSERVICE for comp %s.\n",
  795. getSaNameT (&component->name));
  796. readiness_state_api_set (component, SA_AMF_OUT_OF_SERVICE);
  797. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  798. }
  799. }
  800. }
  801. static void dsmDisabledUnlockedOutOfServiceRequested (
  802. struct saAmfComponent *component)
  803. {
  804. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED;
  805. dsm (component);
  806. }
  807. static void dsmDisabledUnlockedOutOfServiceCompleted (
  808. struct saAmfComponent *component)
  809. {
  810. struct saAmfUnit *unit;
  811. struct list_head *list;
  812. int serviceUnitOutOfService;
  813. struct saAmfGroup *group = 0;
  814. struct list_head *comp_list = 0;
  815. struct list_head *unit_list = 0;
  816. int serviceUnitInStandby = 0;
  817. int activeServiceUnits = 0;
  818. /*
  819. * Once all components of a service unit are out of service,
  820. * activate another service unit in standby
  821. */
  822. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedOutOfServiceCompleted: component out of service %s\n", getSaNameT (&component->name));
  823. /*
  824. * Determine if all components have responded to going out of service
  825. */
  826. unit = component->saAmfUnit;
  827. for (serviceUnitOutOfService = 1, list = unit->saAmfComponentHead.next;
  828. list != &unit->saAmfComponentHead;
  829. list = list->next) {
  830. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  831. if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) {
  832. if (component->currentReadinessState != SA_AMF_OUT_OF_SERVICE) {
  833. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n");
  834. serviceUnitOutOfService = 0;
  835. break;
  836. }
  837. }
  838. if ( component->registered == 0 ) {
  839. protectiongroup_notifications_send (component, SA_AMF_PROTECTION_GROUP_REMOVED);
  840. }
  841. }
  842. group = unit->saAmfGroup;
  843. activeServiceUnits = activeServiceUnitsCount(group);
  844. if (activeServiceUnits>=group->saAmfActiveUnitsDesired) {
  845. return;
  846. }
  847. if (serviceUnitOutOfService == 1) {
  848. log_printf (LOG_LEVEL_DEBUG, "SU has gone out of service.\n");
  849. /*
  850. * Search all units
  851. */
  852. for (unit_list = group->saAmfUnitHead.next;
  853. unit_list != &group->saAmfUnitHead;
  854. unit_list = unit_list->next) {
  855. unit = list_entry (unit_list,
  856. struct saAmfUnit, saAmfUnitList);
  857. log_printf (LOG_LEVEL_DEBUG, "Checking if service unit is in standby %s\n", getSaNameT (&unit->name));
  858. /*
  859. * Search all components
  860. */
  861. for (serviceUnitInStandby = 1,
  862. comp_list = unit->saAmfComponentHead.next;
  863. comp_list != &unit->saAmfComponentHead;
  864. comp_list = comp_list->next) {
  865. component = list_entry (comp_list,
  866. struct saAmfComponent, saAmfComponentList);
  867. if (component->currentHAState != SA_AMF_STANDBY) {
  868. serviceUnitInStandby = 0;
  869. break; /* for iteration of service unit components */
  870. }
  871. }
  872. if (serviceUnitInStandby) {
  873. break; /* for iteration of service group's service units */
  874. }
  875. }
  876. /*
  877. * All components in service unit are standby, activate standby service unit
  878. */
  879. if (serviceUnitInStandby) {
  880. log_printf (LOG_LEVEL_DEBUG, "unit in standby\n");
  881. for (list = unit->saAmfComponentHead.next;
  882. list != &unit->saAmfComponentHead;
  883. list = list->next) {
  884. component = list_entry (list,
  885. struct saAmfComponent, saAmfComponentList);
  886. ha_state_api_set (component, SA_AMF_ACTIVE);
  887. }
  888. } else {
  889. log_printf (LOG_LEVEL_DEBUG, "Can't activate standby service unit because no standby is available.\n");
  890. }
  891. }
  892. }
  893. static void dsmEnabledUnlockedInitial (
  894. struct saAmfComponent *component)
  895. {
  896. struct saAmfUnit *unit;
  897. struct list_head *list;
  898. unit = component->saAmfUnit;
  899. for (list = unit->saAmfComponentHead.next;
  900. list != &unit->saAmfComponentHead;
  901. list = list->next) {
  902. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  903. readiness_state_api_set (component, SA_AMF_IN_SERVICE);
  904. log_printf (LOG_LEVEL_DEBUG, "dsm: telling component %s to enter SA_AMF_IN_SERVICE.\n",
  905. getSaNameT (&component->name));
  906. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED;
  907. }
  908. }
  909. static void dsmEnabledUnlockedInServiceRequested (
  910. struct saAmfComponent *component)
  911. {
  912. struct saAmfUnit *unit;
  913. struct list_head *list;
  914. int in_service;
  915. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceRequested %s.\n", getSaNameT (&component->name));
  916. unit = component->saAmfUnit;
  917. for (in_service = 1, list = unit->saAmfComponentHead.next;
  918. list != &unit->saAmfComponentHead;
  919. list = list->next) {
  920. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  921. if (component->currentReadinessState != SA_AMF_IN_SERVICE) {
  922. log_printf (LOG_LEVEL_DEBUG, "dsm: Found atleast one component not in service\n");
  923. in_service = 0;
  924. break;
  925. }
  926. }
  927. if (in_service) {
  928. log_printf (LOG_LEVEL_DEBUG, "DSM determined component is in service\n");
  929. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED;
  930. dsm (component);
  931. }
  932. }
  933. static void dsmEnabledUnlockedInServiceCompleted (
  934. struct saAmfComponent *component)
  935. {
  936. struct saAmfUnit *unit;
  937. struct list_head *list;
  938. SaAmfHAStateT newHaState;
  939. int activeServiceUnits;
  940. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceCompleted %s.\n", getSaNameT (&component->name));
  941. unit = component->saAmfUnit;
  942. for (list = unit->saAmfComponentHead.next;
  943. list != &unit->saAmfComponentHead;
  944. list = list->next) {
  945. component = list_entry (list,
  946. struct saAmfComponent, saAmfComponentList);
  947. log_printf (LOG_LEVEL_DEBUG, "Requesting component go active.\n");
  948. /*
  949. * Count number of active service units
  950. */
  951. activeServiceUnits = activeServiceUnitsCount (component->saAmfUnit->saAmfGroup);
  952. if (activeServiceUnits < component->saAmfUnit->saAmfGroup->saAmfActiveUnitsDesired) {
  953. newHaState = SA_AMF_ACTIVE;
  954. log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_ACTIVE\n", getSaNameT (&component->name));
  955. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED;
  956. } else {
  957. newHaState = SA_AMF_STANDBY;
  958. log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_STANDBY\n", getSaNameT (&component->name));
  959. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED;
  960. }
  961. ha_state_api_set (component, newHaState);
  962. }
  963. }
  964. static void dsmEnabledUnlockedActiveRequested (
  965. struct saAmfComponent *component)
  966. {
  967. if (component->local == 1) {
  968. log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer\n");
  969. poll_timer_add (aisexec_poll_handle,
  970. component->healthcheckInterval,
  971. (void *)component->conn_info,
  972. timer_function_libamf_healthcheck,
  973. &component->timer_healthcheck);
  974. }
  975. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED;
  976. }
  977. static void dsmEnabledUnlockedStandbyRequested (
  978. struct saAmfComponent *component)
  979. {
  980. if (component->local == 1) {
  981. log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer\n");
  982. poll_timer_add (aisexec_poll_handle,
  983. component->healthcheckInterval,
  984. (void *)component->conn_info,
  985. timer_function_libamf_healthcheck,
  986. &component->timer_healthcheck);
  987. }
  988. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED;
  989. }
  990. static void dsmEnabledUnlockedTransitionDisabledUnlocked (
  991. struct saAmfComponent *component)
  992. {
  993. struct saAmfUnit *unit;
  994. struct list_head *list;
  995. unit = component->saAmfUnit;
  996. for (list = unit->saAmfComponentHead.next;
  997. list != &unit->saAmfComponentHead;
  998. list = list->next) {
  999. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  1000. log_printf (LOG_LEVEL_DEBUG, "Requesting component %s transition to disabled.\n",
  1001. getSaNameT (&component->name));
  1002. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_FAILED;
  1003. }
  1004. component->saAmfUnit->operationalAdministrativeState = AMF_DISABLED_UNLOCKED;
  1005. dsm (component);
  1006. }
  1007. static void dsmSynchronizeStaus (
  1008. struct saAmfComponent *component)
  1009. {
  1010. enum amfOperationalAdministrativeState unit_status = AMF_DISABLED_UNLOCKED;
  1011. struct saAmfUnit *unit;
  1012. struct saAmfGroup *group;
  1013. struct list_head *list;
  1014. int activeServiceUnits;
  1015. if (component->currentReadinessState == component->newReadinessState) {
  1016. if (component->currentReadinessState == SA_AMF_OUT_OF_SERVICE) {
  1017. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1018. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  1019. } else if (component->currentReadinessState == SA_AMF_IN_SERVICE) {
  1020. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1021. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED;
  1022. unit_status = AMF_ENABLED_UNLOCKED;
  1023. } else if (component->currentReadinessState == SA_AMF_QUIESCED) {
  1024. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED;
  1025. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  1026. }
  1027. } else {
  1028. if (component->newReadinessState == SA_AMF_OUT_OF_SERVICE) {
  1029. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  1030. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  1031. } else if (component->newReadinessState == SA_AMF_IN_SERVICE) {
  1032. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1033. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED;
  1034. unit_status = AMF_ENABLED_UNLOCKED;
  1035. } else {
  1036. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  1037. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  1038. }
  1039. }
  1040. if (component->currentHAState == component->newHAState) {
  1041. if (component->currentHAState == SA_AMF_ACTIVE) {
  1042. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1043. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED;
  1044. unit_status = AMF_ENABLED_UNLOCKED;
  1045. } else if (component->currentHAState == SA_AMF_STANDBY) {
  1046. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1047. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED;
  1048. unit_status = AMF_ENABLED_UNLOCKED;
  1049. } else {
  1050. /* depend on readiness status */
  1051. }
  1052. } else {
  1053. if (component->newHAState == SA_AMF_ACTIVE) {
  1054. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1055. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED;
  1056. unit_status = AMF_ENABLED_UNLOCKED;
  1057. } else if (component->newHAState == SA_AMF_STANDBY) {
  1058. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1059. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED;
  1060. unit_status = AMF_ENABLED_UNLOCKED;
  1061. } else {
  1062. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  1063. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  1064. }
  1065. }
  1066. /* Syncronize Operational AdministrativeState */
  1067. component->saAmfUnit->operationalAdministrativeState = unit_status;
  1068. unit = component->saAmfUnit;
  1069. group = unit->saAmfGroup;
  1070. for (list = unit->saAmfComponentHead.next; list != &unit->saAmfComponentHead; list = list->next) {
  1071. activeServiceUnits = activeServiceUnitsCount(group);
  1072. if (activeServiceUnits <= group->saAmfActiveUnitsDesired) {
  1073. break;
  1074. }
  1075. if (component->currentHAState != SA_AMF_ACTIVE) {
  1076. continue;
  1077. }
  1078. ha_state_api_set (component, SA_AMF_STANDBY);
  1079. }
  1080. return;
  1081. }
  1082. static void dsmEnabledUnlocked (
  1083. struct saAmfComponent *component)
  1084. {
  1085. switch (component->enabledUnlockedState) {
  1086. case AMF_ENABLED_UNLOCKED_INITIAL:
  1087. dsmEnabledUnlockedInitial (component);
  1088. break;
  1089. case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED:
  1090. dsmEnabledUnlockedInServiceRequested (component);
  1091. break;
  1092. case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED:
  1093. dsmEnabledUnlockedInServiceCompleted (component);
  1094. break;
  1095. case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED:
  1096. dsmEnabledUnlockedActiveRequested (component);
  1097. break;
  1098. case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED:
  1099. /* noop - operational state */
  1100. break;
  1101. case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED:
  1102. dsmEnabledUnlockedStandbyRequested (component);
  1103. break;
  1104. case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED:
  1105. /* noop - operational state */
  1106. break;
  1107. default:
  1108. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlocked: unkown state machine value.\n");
  1109. }
  1110. }
  1111. static void dsmDisabledUnlocked (
  1112. struct saAmfComponent *component)
  1113. {
  1114. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked for %s state %d\n",
  1115. getSaNameT (&component->name),
  1116. component->disabledUnlockedState);
  1117. switch (component->disabledUnlockedState) {
  1118. case AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL:
  1119. dsmDisabledUnlockedRegisteredOrErrorCancel (component);
  1120. break;
  1121. case AMF_DISABLED_UNLOCKED_FAILED:
  1122. dsmDisabledUnlockedFailed (component);
  1123. break;
  1124. case AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED:
  1125. dsmDisabledUnlockedQuiescedRequested (component);
  1126. break;
  1127. case AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED:
  1128. dsmDisabledUnlockedQuiescedCompleted (component);
  1129. break;
  1130. case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED:
  1131. dsmDisabledUnlockedOutOfServiceRequested (component);
  1132. break;
  1133. case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED:
  1134. dsmDisabledUnlockedOutOfServiceCompleted (component);
  1135. break;
  1136. default:
  1137. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked: unkown state machine value %d.\n", component->disabledUnlockedState);
  1138. }
  1139. }
  1140. static void dsm (
  1141. struct saAmfComponent *component)
  1142. {
  1143. log_printf (LOG_LEVEL_DEBUG, "dsm for component %s\n", getSaNameT (&component->name));
  1144. switch (component->saAmfUnit->operationalAdministrativeState) {
  1145. case AMF_DISABLED_UNLOCKED:
  1146. dsmDisabledUnlocked (component);
  1147. break;
  1148. case AMF_ENABLED_UNLOCKED:
  1149. dsmEnabledUnlocked (component);
  1150. break;
  1151. /*
  1152. AMF_DISABLED_LOCKED,
  1153. AMF_ENABLED_STOPPING
  1154. */
  1155. default:
  1156. log_printf (LOG_LEVEL_DEBUG, "dsm: unknown state machine value.\n");
  1157. }
  1158. }
  1159. #if 0
  1160. /*
  1161. * This is currently unused, but executes the componentterminatecallback
  1162. * callback in the AMF api.
  1163. */
  1164. void componentTerminate (struct conn_info *conn_info)
  1165. {
  1166. struct res_lib_amf_componentterminatecallback res_lib_amf_componentterminatecallback;
  1167. res_lib_amf_componentterminatecallback.header.id = MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK;
  1168. res_lib_amf_componentterminatecallback.header.size = sizeof (struct res_lib_amf_componentterminatecallback);
  1169. res_lib_amf_componentterminatecallback.header.error = SA_OK;
  1170. res_lib_amf_componentterminatecallback.invocation =
  1171. req_amf_response_set (
  1172. MESSAGE_REQ_AMF_RESPONSE_SAAMFCOMPONENTTERMINATECALLBACK,
  1173. fd);
  1174. memcpy (&res_lib_amf_componentterminatecallback.compName,
  1175. &connections[fd].component->name, sizeof (SaNameT));
  1176. connections[fd].component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  1177. log_printf (LOG_LEVEL_DEBUG, "terminating component on fd %d\n", fd);
  1178. libais_send_response (fd, &res_lib_amf_componentterminatecallback,
  1179. sizeof (struct res_lib_amf_componentterminatecallback));
  1180. }
  1181. #endif /* Not currently implemented */
  1182. void error_report (
  1183. struct saAmfComponent *component,
  1184. SaAmfProbableCauseT probableCause)
  1185. {
  1186. struct req_exec_amf_errorreport req_exec_amf_errorreport;
  1187. struct iovec iovecs[2];
  1188. req_exec_amf_errorreport.header.size = sizeof (struct req_exec_amf_errorreport);
  1189. req_exec_amf_errorreport.header.id = MESSAGE_REQ_EXEC_AMF_ERRORREPORT;
  1190. req_exec_amf_errorreport.source.conn_info = 0;
  1191. req_exec_amf_errorreport.source.in_addr.s_addr = 0;
  1192. memcpy (&req_exec_amf_errorreport.req_lib_amf_errorreport.erroneousComponent,
  1193. &component->name,
  1194. sizeof (SaNameT));
  1195. req_exec_amf_errorreport.req_lib_amf_errorreport.errorDescriptor.probableCause = probableCause;
  1196. iovecs[0].iov_base = (char *)&req_exec_amf_errorreport;
  1197. iovecs[0].iov_len = sizeof (req_exec_amf_errorreport);
  1198. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1199. }
  1200. int healthcheck_instance = 0;
  1201. void timer_function_libamf_healthcheck (void *data) {
  1202. struct res_lib_amf_healthcheckcallback res_lib_amf_healthcheckcallback;
  1203. memset (&res_lib_amf_healthcheckcallback,0,sizeof(res_lib_amf_healthcheckcallback));
  1204. struct conn_info *conn_info = (struct conn_info *)data;
  1205. res_lib_amf_healthcheckcallback.header.id = MESSAGE_RES_AMF_HEALTHCHECKCALLBACK;
  1206. res_lib_amf_healthcheckcallback.header.size = sizeof (struct res_lib_amf_healthcheckcallback);
  1207. res_lib_amf_healthcheckcallback.header.error = SA_OK;
  1208. log_printf (LOG_LEVEL_DEBUG, "checking healthcheck on component %s\n",
  1209. getSaNameT (&conn_info->component->name));
  1210. if (conn_info->component->healthcheck_outstanding == 1) {
  1211. log_printf (LOG_LEVEL_DEBUG, "Healthcheck timed out on component %s\n",
  1212. getSaNameT (&conn_info->component->name));
  1213. /*
  1214. * Report the error to the rest of the cluster using the normal state machine
  1215. */
  1216. error_report (conn_info->component, SA_AMF_NOT_RESPONDING);
  1217. conn_info->component->healthcheck_outstanding = 2;
  1218. } else
  1219. if (conn_info->component->healthcheck_outstanding == 0) {
  1220. conn_info->component->healthcheck_outstanding = 1;
  1221. /*
  1222. * Send healthcheck message
  1223. */
  1224. res_lib_amf_healthcheckcallback.invocation =
  1225. req_amf_invocation_create (
  1226. MESSAGE_REQ_AMF_RESPONSE_SAAMFHEALTHCHECKCALLBACK,
  1227. conn_info);
  1228. if (res_lib_amf_healthcheckcallback.invocation == -1) {
  1229. printf ("TODO healthcheck set callback\n");
  1230. }
  1231. memcpy (&res_lib_amf_healthcheckcallback.compName,
  1232. &conn_info->component->name,
  1233. sizeof (SaNameT));
  1234. res_lib_amf_healthcheckcallback.checkType = SA_AMF_HEARTBEAT;
  1235. log_printf (LOG_LEVEL_DEBUG, "Sending instance %d\n", healthcheck_instance);
  1236. res_lib_amf_healthcheckcallback.instance = healthcheck_instance++;
  1237. libais_send_response (conn_info,
  1238. &res_lib_amf_healthcheckcallback,
  1239. sizeof (struct res_lib_amf_healthcheckcallback));
  1240. poll_timer_add (aisexec_poll_handle,
  1241. conn_info->component->healthcheckInterval,
  1242. (void *)conn_info,
  1243. timer_function_libamf_healthcheck,
  1244. &conn_info->component->timer_healthcheck);
  1245. }
  1246. }
  1247. struct saAmfProtectionGroup *protectiongroup_find (
  1248. SaNameT *csiName)
  1249. {
  1250. struct list_head *AmfGroupList;
  1251. struct list_head *AmfProtectionGroupList;
  1252. struct saAmfGroup *saAmfGroup;
  1253. struct saAmfProtectionGroup *AmfProtectionGroup;
  1254. /*
  1255. * Search all groups
  1256. */
  1257. for (AmfGroupList = saAmfGroupHead.next;
  1258. AmfGroupList != &saAmfGroupHead;
  1259. AmfGroupList = AmfGroupList->next) {
  1260. saAmfGroup = list_entry (AmfGroupList,
  1261. struct saAmfGroup, saAmfGroupList);
  1262. /*
  1263. * Search all protection groups
  1264. */
  1265. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  1266. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  1267. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  1268. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  1269. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  1270. if (name_match (csiName, &AmfProtectionGroup->name)) {
  1271. return (AmfProtectionGroup);
  1272. }
  1273. }
  1274. }
  1275. return (0);
  1276. }
  1277. struct saAmfComponent *component_in_protectiongroup_find (
  1278. SaNameT *csiName,
  1279. SaNameT *compName)
  1280. {
  1281. struct list_head *AmfGroupList = 0;
  1282. struct list_head *AmfProtectionGroupList = 0;
  1283. struct list_head *AmfComponentList = 0;
  1284. struct saAmfGroup *saAmfGroup = 0;
  1285. struct saAmfProtectionGroup *AmfProtectionGroup = 0;
  1286. struct saAmfComponent *AmfComponent = 0;
  1287. int found = 0;
  1288. /*
  1289. * Search all groups
  1290. */
  1291. for (AmfGroupList = saAmfGroupHead.next;
  1292. AmfGroupList != &saAmfGroupHead;
  1293. AmfGroupList = AmfGroupList->next) {
  1294. saAmfGroup = list_entry (AmfGroupList,
  1295. struct saAmfGroup, saAmfGroupList);
  1296. /*
  1297. * Search all protection groups
  1298. */
  1299. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  1300. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  1301. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  1302. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  1303. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  1304. if (name_match (csiName, &AmfProtectionGroup->name)) {
  1305. /*
  1306. * Search all components
  1307. */
  1308. for (AmfComponentList = AmfProtectionGroup->saAmfMembersHead.next;
  1309. AmfComponentList != &AmfProtectionGroup->saAmfMembersHead;
  1310. AmfComponentList = AmfComponentList->next) {
  1311. AmfComponent = list_entry (AmfComponentList,
  1312. struct saAmfComponent, saAmfProtectionGroupList);
  1313. if (name_match (compName, &AmfComponent->name)) {
  1314. found = 1;
  1315. }
  1316. }
  1317. }
  1318. }
  1319. }
  1320. if (found) {
  1321. return (AmfComponent);
  1322. } else {
  1323. return (0);
  1324. }
  1325. }
  1326. DECLARE_LIST_INIT (library_notification_send_listhead);
  1327. // TODO static totempg_recovery_plug_handle amf_recovery_plug_handle;
  1328. static void protectiongroup_notifications_send (
  1329. struct saAmfComponent *changedComponent,
  1330. SaAmfProtectionGroupChangesT changeToComponent)
  1331. {
  1332. int i;
  1333. struct conn_info *conn_info;
  1334. struct list_head *list;
  1335. log_printf (LOG_LEVEL_ENTER_FUNC, "protectiongroup_notifications_send: sending PGs to API.\n");
  1336. /*
  1337. * Iterate all tracked connections
  1338. */
  1339. for (list = library_notification_send_listhead.next;
  1340. list != &library_notification_send_listhead;
  1341. list = list->next) {
  1342. conn_info = list_entry (list, struct conn_info, conn_list);
  1343. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  1344. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active) {
  1345. if (conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.length
  1346. != changedComponent->saAmfProtectionGroup->name.length) {
  1347. continue;
  1348. }
  1349. if (memcmp (conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.value,
  1350. changedComponent->saAmfProtectionGroup->name.value,
  1351. conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.length)) {
  1352. continue;
  1353. }
  1354. protectiongroup_notification_send (conn_info,
  1355. conn_info->ais_ci.u.libamf_ci.tracks[i].notificationBufferAddress,
  1356. changedComponent->saAmfProtectionGroup,
  1357. changedComponent,
  1358. changeToComponent,
  1359. conn_info->ais_ci.u.libamf_ci.tracks[i].trackFlags);
  1360. } /* if track flags active */
  1361. } /* for all track entries */
  1362. } /* for all connection entries */
  1363. }
  1364. static int make_protectiongroup_notification_allcomponent (
  1365. struct saAmfComponent *changedComponent,
  1366. SaAmfProtectionGroupChangesT changeToComponent,
  1367. SaAmfProtectionGroupNotificationT **notification )
  1368. {
  1369. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  1370. int notifyEntries = 0;
  1371. struct saAmfComponent *component;
  1372. struct list_head *AmfGroupList;
  1373. struct list_head *AmfUnitList;
  1374. struct list_head *AmfComponentList;
  1375. struct saAmfGroup *saAmfGroup;
  1376. struct saAmfUnit *AmfUnit;
  1377. for (AmfGroupList = saAmfGroupHead.next; AmfGroupList != &saAmfGroupHead; AmfGroupList = AmfGroupList->next) {
  1378. saAmfGroup = list_entry (AmfGroupList, struct saAmfGroup, saAmfGroupList);
  1379. /*
  1380. * Search all units
  1381. */
  1382. for (AmfUnitList = saAmfGroup->saAmfUnitHead.next;
  1383. AmfUnitList != &saAmfGroup->saAmfUnitHead;
  1384. AmfUnitList = AmfUnitList->next) {
  1385. AmfUnit = list_entry (AmfUnitList, struct saAmfUnit, saAmfUnitList);
  1386. /*
  1387. * Search all components
  1388. */
  1389. for (AmfComponentList = AmfUnit->saAmfComponentHead.next;
  1390. AmfComponentList != &AmfUnit->saAmfComponentHead;
  1391. AmfComponentList = AmfComponentList->next) {
  1392. component = list_entry (AmfComponentList, struct saAmfComponent, saAmfComponentList);
  1393. protectionGroupNotification =
  1394. (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
  1395. sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
  1396. memset (&protectionGroupNotification[notifyEntries],
  1397. 0,sizeof (SaAmfProtectionGroupNotificationT));
  1398. memcpy (&protectionGroupNotification[notifyEntries].member.compName,
  1399. &component->name, sizeof (SaNameT));
  1400. memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
  1401. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  1402. memcpy (&protectionGroupNotification[notifyEntries].member.haState,
  1403. &component->currentHAState, sizeof (SaAmfHAStateT));
  1404. if (component == changedComponent) {
  1405. protectionGroupNotification[notifyEntries].change = changeToComponent;
  1406. } else {
  1407. protectionGroupNotification[notifyEntries].change
  1408. = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  1409. }
  1410. notifyEntries += 1;
  1411. }
  1412. }
  1413. }
  1414. if (notifyEntries) {
  1415. *notification = protectionGroupNotification;
  1416. }
  1417. return (notifyEntries);
  1418. }
  1419. static int make_protectiongroup_notification (
  1420. struct saAmfProtectionGroup *amfProtectionGroup,
  1421. struct saAmfComponent *changedComponent,
  1422. SaAmfProtectionGroupChangesT changeToComponent,
  1423. SaAmfProtectionGroupNotificationT **notification )
  1424. {
  1425. struct res_lib_amf_protectiongrouptrackcallback res_lib_amf_protectiongrouptrackcallback;
  1426. int notifyEntries = 0;
  1427. struct saAmfComponent *component;
  1428. struct list_head *componentList;
  1429. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  1430. memset (&res_lib_amf_protectiongrouptrackcallback,0,sizeof(res_lib_amf_protectiongrouptrackcallback));
  1431. for (componentList = amfProtectionGroup->saAmfMembersHead.next;
  1432. componentList != &amfProtectionGroup->saAmfMembersHead;
  1433. componentList = componentList->next) {
  1434. component = list_entry (componentList, struct saAmfComponent, saAmfProtectionGroupList);
  1435. protectionGroupNotification =
  1436. (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
  1437. sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
  1438. memset (&protectionGroupNotification[notifyEntries],0,sizeof (SaAmfProtectionGroupNotificationT));
  1439. memcpy (&protectionGroupNotification[notifyEntries].member.compName,
  1440. &component->name, sizeof (SaNameT));
  1441. memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
  1442. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  1443. memcpy (&protectionGroupNotification[notifyEntries].member.haState,
  1444. &component->currentHAState, sizeof (SaAmfHAStateT));
  1445. if (component == changedComponent) {
  1446. protectionGroupNotification[notifyEntries].change = changeToComponent;
  1447. } else {
  1448. protectionGroupNotification[notifyEntries].change = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  1449. }
  1450. notifyEntries += 1;
  1451. } /* for */
  1452. if (notifyEntries) {
  1453. *notification = protectionGroupNotification;
  1454. }
  1455. return (notifyEntries);
  1456. }
  1457. static void protectiongroup_notification_send (struct conn_info *conn_info,
  1458. SaAmfProtectionGroupNotificationT *notificationBufferAddress,
  1459. struct saAmfProtectionGroup *amfProtectionGroup,
  1460. struct saAmfComponent *changedComponent,
  1461. SaAmfProtectionGroupChangesT changeToComponent,
  1462. SaUint8T trackFlags)
  1463. {
  1464. struct res_lib_amf_protectiongrouptrackcallback res_lib_amf_protectiongrouptrackcallback;
  1465. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  1466. int notifyEntries;
  1467. /*
  1468. * Step through all components and generate protection group list for csi
  1469. */
  1470. memset (&res_lib_amf_protectiongrouptrackcallback, 0, sizeof(res_lib_amf_protectiongrouptrackcallback));
  1471. if ( trackFlags == SA_TRACK_CHANGES ) {
  1472. notifyEntries = make_protectiongroup_notification_allcomponent (changedComponent,
  1473. changeToComponent, &protectionGroupNotification);
  1474. }else if (trackFlags == SA_TRACK_CHANGES_ONLY) {
  1475. notifyEntries = make_protectiongroup_notification (amfProtectionGroup,
  1476. changedComponent, changeToComponent, &protectionGroupNotification );
  1477. }else{
  1478. notifyEntries = 0;
  1479. }
  1480. /*
  1481. * Send track callback
  1482. */
  1483. if (notifyEntries) {
  1484. res_lib_amf_protectiongrouptrackcallback.header.size =
  1485. sizeof (struct res_lib_amf_protectiongrouptrackcallback) +
  1486. (notifyEntries * sizeof (SaAmfProtectionGroupNotificationT));
  1487. res_lib_amf_protectiongrouptrackcallback.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK;
  1488. res_lib_amf_protectiongrouptrackcallback.header.error = SA_OK;
  1489. res_lib_amf_protectiongrouptrackcallback.numberOfItems = notifyEntries;
  1490. res_lib_amf_protectiongrouptrackcallback.numberOfMembers = notifyEntries;
  1491. memcpy (&res_lib_amf_protectiongrouptrackcallback.csiName,
  1492. &amfProtectionGroup->name, sizeof (SaNameT));
  1493. res_lib_amf_protectiongrouptrackcallback.notificationBufferAddress = notificationBufferAddress;
  1494. libais_send_response (conn_info, &res_lib_amf_protectiongrouptrackcallback,
  1495. sizeof (struct res_lib_amf_protectiongrouptrackcallback));
  1496. libais_send_response (conn_info, protectionGroupNotification,
  1497. sizeof (SaAmfProtectionGroupNotificationT) * notifyEntries);
  1498. mempool_free (protectionGroupNotification);
  1499. }
  1500. }
  1501. /*
  1502. * The response handler for readiness state set callback
  1503. */
  1504. static void response_handler_readinessstatesetcallback (struct conn_info *conn_info,
  1505. struct req_amf_response *req_amf_response)
  1506. {
  1507. if (req_amf_response->error == SA_OK && conn_info->component) {
  1508. log_printf (LOG_LEVEL_ENTER_FUNC, "CALLBACK sending readiness state to %s\n",
  1509. getSaNameT (&conn_info->component->name));
  1510. readiness_state_group_set (conn_info->component, conn_info->component->newReadinessState);
  1511. }
  1512. }
  1513. /*
  1514. * iterate service unit components
  1515. * telling all components not already QUIESCING to enter SA_AMF_QUIESCED state
  1516. */
  1517. static void response_handler_csisetcallback (struct conn_info *conn_info,
  1518. struct req_amf_response *req_amf_response)
  1519. {
  1520. if (req_amf_response->error == SA_OK && conn_info->component) {
  1521. ha_state_group_set (conn_info->component, conn_info->component->newHAState);
  1522. }
  1523. }
  1524. static int amf_exec_init_fn (void)
  1525. {
  1526. #ifdef TODO
  1527. int res;
  1528. res = totempg_recovery_plug_create (&amf_recovery_plug_handle);
  1529. if (res != 0) {
  1530. log_printf(LOG_LEVEL_ERROR,
  1531. "Could not create recovery plug for amf service.\n");
  1532. return (-1);
  1533. }
  1534. #endif
  1535. return (0);
  1536. }
  1537. void amf_confchg_njoin (struct saAmfComponent *component ,void *data)
  1538. {
  1539. if (component->source_addr.s_addr != this_ip.sin_addr.s_addr) {
  1540. return;
  1541. }
  1542. component_register (component);
  1543. return;
  1544. }
  1545. void amf_confchg_nleave (struct saAmfComponent *component ,void *data)
  1546. {
  1547. struct in_addr *source_addr = (struct in_addr *)data;
  1548. struct saAmfUnit *unit;
  1549. struct list_head *list;
  1550. struct saAmfComponent *leave_component = NULL;
  1551. enum amfDisabledUnlockedState disablestate = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED;
  1552. if (component->source_addr.s_addr != source_addr->s_addr) {
  1553. return;
  1554. }
  1555. if (!component->registered) {
  1556. return;
  1557. }
  1558. log_printf (LOG_LEVEL_ENTER_FUNC, "amf_confchg_nleave(%s)\n", getSaNameT (&(component->name)));
  1559. /* Component status Initialize */
  1560. unit = component->saAmfUnit;
  1561. for (list = unit->saAmfComponentHead.next; list != &unit->saAmfComponentHead; list = list->next) {
  1562. component = list_entry (list,
  1563. struct saAmfComponent, saAmfComponentList);
  1564. if (component->source_addr.s_addr != source_addr->s_addr) {
  1565. disablestate = AMF_DISABLED_UNLOCKED_FAILED;
  1566. continue;
  1567. }
  1568. component->registered = 0;
  1569. component->local = 0;
  1570. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1571. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  1572. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  1573. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  1574. component->newHAState = SA_AMF_QUIESCED;
  1575. component->currentHAState = SA_AMF_QUIESCED;
  1576. component->source_addr.s_addr = 0;
  1577. leave_component = component;
  1578. }
  1579. if (leave_component == NULL) {
  1580. return;
  1581. }
  1582. leave_component->saAmfUnit->operationalAdministrativeState = AMF_DISABLED_UNLOCKED;
  1583. leave_component->disabledUnlockedState = disablestate;
  1584. dsm (leave_component);
  1585. leave_component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1586. return;
  1587. }
  1588. static int amf_confchg_fn (
  1589. enum totem_configuration_type configuration_type,
  1590. struct in_addr *member_list, void *member_list_private,
  1591. int member_list_entries,
  1592. struct in_addr *left_list, void *left_list_private,
  1593. int left_list_entries,
  1594. struct in_addr *joined_list, void *joined_list_private,
  1595. int joined_list_entries,
  1596. struct memb_ring_id *ring_id)
  1597. {
  1598. int i;
  1599. 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);
  1600. recovery = 1;
  1601. /*
  1602. * If node join, component register
  1603. */
  1604. if ( joined_list_entries > 0 ) {
  1605. enumerate_components (amf_confchg_njoin, NULL);
  1606. }
  1607. /*
  1608. * If node leave, component unregister
  1609. */
  1610. for (i = 0; i<left_list_entries ; i++) {
  1611. enumerate_components (amf_confchg_nleave, (void *)&(left_list[i]));
  1612. }
  1613. #ifdef TODO
  1614. if (configuration_type == TOTEMPG_CONFIGURATION_REGULAR) {
  1615. totempg_recovery_plug_unplug (amf_recovery_plug_handle);
  1616. recovery = 0;
  1617. }
  1618. #endif
  1619. return (0);
  1620. }
  1621. int amf_exit_fn (struct conn_info *conn_info)
  1622. {
  1623. /*
  1624. * Unregister all components registered to this file descriptor
  1625. */
  1626. if (conn_info->service == SOCKET_SERVICE_AMF) {
  1627. component_unregister (conn_info->component);
  1628. if (conn_info->component && conn_info->component->timer_healthcheck) {
  1629. poll_timer_delete (aisexec_poll_handle,
  1630. conn_info->component->timer_healthcheck);
  1631. conn_info->component->timer_healthcheck = 0;
  1632. }
  1633. if (conn_info->ais_ci.u.libamf_ci.tracks) {
  1634. mempool_free (conn_info->ais_ci.u.libamf_ci.tracks);
  1635. conn_info->ais_ci.u.libamf_ci.tracks = 0;
  1636. list_del (&conn_info->conn_list);
  1637. }
  1638. }
  1639. return (0);
  1640. }
  1641. static int message_handler_req_exec_amf_componentregister (void *message, struct in_addr source_addr, int endian_conversion_required)
  1642. {
  1643. struct req_exec_amf_componentregister *req_exec_amf_componentregister = (struct req_exec_amf_componentregister *)message;
  1644. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  1645. struct saAmfComponent *component;
  1646. struct saAmfComponent *amfProxyComponent;
  1647. SaErrorT error;
  1648. log_printf (LOG_LEVEL_FROM_GMI, "Executive: ComponentRegister for component %s\n",
  1649. getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName));
  1650. /*
  1651. * Determine if proxy isn't registered
  1652. */
  1653. error = SA_OK;
  1654. component = findComponent (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName);
  1655. amfProxyComponent = findComponent (&req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName);
  1656. /*
  1657. * If a node is joining menber ship ,Component States Synchronize
  1658. */
  1659. if (req_exec_amf_componentregister->source.in_addr.s_addr == 0) {
  1660. amf_synchronize (message, source_addr);
  1661. return (0);
  1662. }
  1663. /*
  1664. * If component not in configuration files, return error
  1665. */
  1666. if (component == 0) {
  1667. error = SA_ERR_NOT_EXIST;
  1668. }
  1669. /*
  1670. * If proxy doesn't exist and isn't registered, return error
  1671. */
  1672. if ((amfProxyComponent == 0 &&
  1673. req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) ||
  1674. (amfProxyComponent && amfProxyComponent->registered == 0)) {
  1675. error = SA_ERR_NOT_EXIST;
  1676. }
  1677. /*
  1678. * If component already registered, return error
  1679. */
  1680. if (error == SA_OK) {
  1681. if (component->registered) {
  1682. error = SA_ERR_EXIST;
  1683. }
  1684. }
  1685. /*
  1686. * Finally register component and setup links for proxy if
  1687. * proxy present
  1688. */
  1689. if (error == SA_OK) {
  1690. component->local = 0;
  1691. component->registered = 1;
  1692. component->conn_info = req_exec_amf_componentregister->source.conn_info;
  1693. component->source_addr = source_addr;
  1694. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  1695. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  1696. component->currentHAState = 0;
  1697. component->newHAState = 0;
  1698. component->probableCause = 0;
  1699. component->enabledUnlockedState = 0;
  1700. component->disabledUnlockedState = 0;
  1701. if (req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) {
  1702. component->saAmfProxyComponent = amfProxyComponent;
  1703. }
  1704. }
  1705. /*
  1706. * If this node originated the request to the cluster, respond back
  1707. * to the AMF library
  1708. */
  1709. if (req_exec_amf_componentregister->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1710. if (error == SA_OK) {
  1711. component->local = 1;
  1712. req_exec_amf_componentregister->source.conn_info->component = component;
  1713. }
  1714. log_printf (LOG_LEVEL_DEBUG, "sending component register response to fd %d\n",
  1715. req_exec_amf_componentregister->source.conn_info->fd);
  1716. res_lib_amf_componentregister.header.size = sizeof (struct res_lib_amf_componentregister);
  1717. res_lib_amf_componentregister.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  1718. res_lib_amf_componentregister.header.error = error;
  1719. libais_send_response (req_exec_amf_componentregister->source.conn_info,
  1720. &res_lib_amf_componentregister,
  1721. sizeof (struct res_lib_amf_componentregister));
  1722. }
  1723. /*
  1724. * If no error on registration, determine if we should enter new state
  1725. */
  1726. if (error == SA_OK) {
  1727. dsm (component);
  1728. }
  1729. return (0);
  1730. }
  1731. static void amf_synchronize (void *message, struct in_addr source_addr)
  1732. {
  1733. struct req_exec_amf_componentregister *req_exec_amf_componentregister = (struct req_exec_amf_componentregister *)message;
  1734. struct saAmfComponent *component;
  1735. struct saAmfComponent *amfProxyComponent;
  1736. log_printf (LOG_LEVEL_ENTER_FUNC, "amf_synchronize%s\n",
  1737. getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName));
  1738. /* Find Component */
  1739. component = findComponent (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName);
  1740. amfProxyComponent = findComponent (&req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName);
  1741. /* If this node is Component onwer */
  1742. if (component->source_addr.s_addr == this_ip.sin_addr.s_addr) {
  1743. /* No Operation */
  1744. return;
  1745. }
  1746. /* If this isn't Synchronizing target Node */
  1747. if (!(component->local == 0 && component->registered == 0)){
  1748. /* No Operation */
  1749. return;
  1750. }
  1751. /* Synchronize Status */
  1752. component->local = 0;
  1753. component->registered = 1;
  1754. component->conn_info = req_exec_amf_componentregister->source.conn_info;
  1755. component->source_addr = source_addr;
  1756. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  1757. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  1758. component->currentHAState = SA_AMF_QUIESCED;
  1759. component->newHAState = SA_AMF_QUIESCED;
  1760. component->probableCause = 0;
  1761. component->enabledUnlockedState = 0;
  1762. component->disabledUnlockedState = 0;
  1763. component->currentReadinessState = req_exec_amf_componentregister->currentReadinessState;
  1764. component->newReadinessState = req_exec_amf_componentregister->newReadinessState;
  1765. component->currentHAState = req_exec_amf_componentregister->currentHAState;
  1766. component->newHAState = req_exec_amf_componentregister->newHAState;
  1767. if (req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) {
  1768. component->saAmfProxyComponent = amfProxyComponent;
  1769. }
  1770. /*
  1771. * Determine if we should enter new state
  1772. */
  1773. dsmSynchronizeStaus (component);
  1774. return;
  1775. }
  1776. static int message_handler_req_exec_amf_componentunregister (void *message, struct in_addr source_addr, int endian_conversion_required)
  1777. {
  1778. struct req_exec_amf_componentunregister *req_exec_amf_componentunregister = (struct req_exec_amf_componentunregister *)message;
  1779. struct res_lib_amf_componentunregister res_lib_amf_componentunregister;
  1780. struct saAmfComponent *component;
  1781. struct saAmfComponent *amfProxyComponent;
  1782. SaErrorT error;
  1783. log_printf (LOG_LEVEL_FROM_GMI, "Executive: Component_unregister for %s\n",
  1784. getSaNameT (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName));
  1785. component = findComponent (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName);
  1786. amfProxyComponent = findComponent (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName);
  1787. /*
  1788. * Check for proxy and component not existing in system
  1789. */
  1790. error = SA_OK;
  1791. if (component == 0) {
  1792. error = SA_ERR_NOT_EXIST;
  1793. }
  1794. if (req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName.length > 0) {
  1795. if (amfProxyComponent) {
  1796. if (amfProxyComponent->registered == 0) {
  1797. error = SA_ERR_NOT_EXIST;
  1798. }
  1799. } else {
  1800. error = SA_ERR_NOT_EXIST;
  1801. }
  1802. }
  1803. /*
  1804. * If there is a proxycompname, make sure it is the proxy
  1805. * of compName
  1806. */
  1807. if (error == SA_OK && amfProxyComponent) {
  1808. if (component->saAmfProxyComponent != amfProxyComponent) {
  1809. error = SA_ERR_BAD_OPERATION;
  1810. }
  1811. }
  1812. /*
  1813. * Finally unregister the component
  1814. */
  1815. if (error == SA_OK) {
  1816. component->registered = 0;
  1817. dsmEnabledUnlockedTransitionDisabledUnlocked (component);
  1818. }
  1819. /*
  1820. * If this node originated the request to the cluster, respond back
  1821. * to the AMF library
  1822. */
  1823. if (req_exec_amf_componentunregister->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1824. log_printf (LOG_LEVEL_DEBUG, "sending component unregister response to fd %d\n",
  1825. req_exec_amf_componentunregister->source.conn_info->fd);
  1826. res_lib_amf_componentunregister.header.size = sizeof (struct res_lib_amf_componentunregister);
  1827. res_lib_amf_componentunregister.header.id = MESSAGE_RES_AMF_COMPONENTUNREGISTER;
  1828. res_lib_amf_componentunregister.header.error = error;
  1829. libais_send_response (req_exec_amf_componentunregister->source.conn_info,
  1830. &res_lib_amf_componentunregister, sizeof (struct res_lib_amf_componentunregister));
  1831. }
  1832. return (0);
  1833. }
  1834. static int message_handler_req_exec_amf_errorreport (void *message, struct in_addr source_addr, int endian_conversion_required)
  1835. {
  1836. struct req_exec_amf_errorreport *req_exec_amf_errorreport = (struct req_exec_amf_errorreport *)message;
  1837. struct res_lib_amf_errorreport res_lib_amf_errorreport;
  1838. struct saAmfComponent *component;
  1839. SaErrorT error = SA_ERR_BAD_OPERATION;
  1840. log_printf (LOG_LEVEL_FROM_GMI, "Executive: ErrorReport for %s\n",
  1841. getSaNameT (&req_exec_amf_errorreport->req_lib_amf_errorreport.erroneousComponent));
  1842. component = findComponent (&req_exec_amf_errorreport->req_lib_amf_errorreport.erroneousComponent);
  1843. if (component && component->registered) {
  1844. component->probableCause = req_exec_amf_errorreport->req_lib_amf_errorreport.errorDescriptor.probableCause;
  1845. /*
  1846. * One registered component left, so transition
  1847. * SU to failed operational state
  1848. */
  1849. dsmEnabledUnlockedTransitionDisabledUnlocked (component);
  1850. error = SA_OK;
  1851. }
  1852. /*
  1853. * If this node originated the request to the cluster, respond back
  1854. * to the AMF library
  1855. */
  1856. if (req_exec_amf_errorreport->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1857. log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n",
  1858. req_exec_amf_errorreport->source.conn_info->fd);
  1859. res_lib_amf_errorreport.header.size = sizeof (struct res_lib_amf_errorreport);
  1860. res_lib_amf_errorreport.header.id = MESSAGE_RES_AMF_ERRORREPORT;
  1861. res_lib_amf_errorreport.header.error = error;
  1862. libais_send_response (req_exec_amf_errorreport->source.conn_info,
  1863. &res_lib_amf_errorreport, sizeof (struct res_lib_amf_errorreport));
  1864. }
  1865. return (0);
  1866. }
  1867. static int message_handler_req_exec_amf_errorcancelall (void *message, struct in_addr source_addr, int endian_conversion_required)
  1868. {
  1869. struct req_exec_amf_errorcancelall *req_exec_amf_errorcancelall = (struct req_exec_amf_errorcancelall *)message;
  1870. struct res_lib_amf_errorcancelall res_lib_amf_errorcancelall;
  1871. struct saAmfComponent *component;
  1872. SaErrorT error = SA_ERR_BAD_OPERATION;
  1873. log_printf (LOG_LEVEL_FROM_GMI, "Executive: ErrorCancelAll for %s\n",
  1874. getSaNameT (&req_exec_amf_errorcancelall->req_lib_amf_errorcancelall.compName));
  1875. component = findComponent (&req_exec_amf_errorcancelall->req_lib_amf_errorcancelall.compName);
  1876. if (component && component->registered) {
  1877. /*
  1878. * Mark component in service if its a AMF service
  1879. * connected to this aisexec
  1880. */
  1881. if (component->probableCause) {
  1882. component->probableCause = 0;
  1883. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1884. dsm (component);
  1885. }
  1886. error = SA_OK;
  1887. }
  1888. /*
  1889. * If this node originated the request to the cluster, respond back
  1890. * to the AMF library
  1891. */
  1892. if (req_exec_amf_errorcancelall->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1893. log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n",
  1894. req_exec_amf_errorcancelall->source.conn_info->fd);
  1895. res_lib_amf_errorcancelall.header.size = sizeof (struct res_lib_amf_errorcancelall);
  1896. res_lib_amf_errorcancelall.header.id = MESSAGE_RES_AMF_ERRORCANCELALL;
  1897. res_lib_amf_errorcancelall.header.error = error;
  1898. libais_send_response (req_exec_amf_errorcancelall->source.conn_info,
  1899. &res_lib_amf_errorcancelall, sizeof (struct res_lib_amf_errorcancelall));
  1900. }
  1901. return (0);
  1902. }
  1903. /*
  1904. * If receiving this message from another cluster node, another cluster node
  1905. * has selected a readiness state for a component connected to _that_ cluster
  1906. * node. That cluster node API has verified the readiness state, so its time to let
  1907. * the rest of the cluster nodes know about the readiness state change.
  1908. */
  1909. static int message_handler_req_exec_amf_readinessstateset (void *message, struct in_addr source_addr, int endian_conversion_required)
  1910. {
  1911. struct req_exec_amf_readinessstateset *req_exec_amf_readinessstateset = (struct req_exec_amf_readinessstateset *)message;
  1912. struct saAmfComponent *component;
  1913. component = findComponent (&req_exec_amf_readinessstateset->compName);
  1914. if (component) {
  1915. log_printf (LOG_LEVEL_FROM_GMI,
  1916. "Executive: message_handler_req_exec_amf_readinessstateset (%s, RD:%d)\n",
  1917. getSaNameT (&component->name), req_exec_amf_readinessstateset->readinessState);
  1918. component->currentReadinessState = req_exec_amf_readinessstateset->readinessState;
  1919. component->newReadinessState = component->currentReadinessState;
  1920. dsm (component);
  1921. }
  1922. return (0);
  1923. }
  1924. /*
  1925. * If receiving this message from another cluster node, another cluster node
  1926. * has selected a ha state for a component connected to _that_ cluster
  1927. * node. That cluster node API has verified the ha state, so its time to let
  1928. * the rest of the cluster nodes know about the HA state change.
  1929. */
  1930. static int message_handler_req_exec_amf_hastateset (void *message, struct in_addr source_addr, int endian_conversion_required)
  1931. {
  1932. struct req_exec_amf_hastateset *req_exec_amf_hastateset = (struct req_exec_amf_hastateset *)message;
  1933. struct saAmfComponent *component;
  1934. SaAmfProtectionGroupChangesT changeToComponent = SA_AMF_PROTECTION_GROUP_STATE_CHANGE;
  1935. component = findComponent (&req_exec_amf_hastateset->compName);
  1936. if (!component) {
  1937. return (0);
  1938. }
  1939. log_printf (LOG_LEVEL_FROM_GMI,
  1940. "Executive: message_handler_req_exec_amf_hastateset (%s, HA:%d)\n",
  1941. getSaNameT (&component->name), req_exec_amf_hastateset->haState);
  1942. if ( component->currentHAState == 0 ) {
  1943. if ( req_exec_amf_hastateset->haState == SA_AMF_ACTIVE
  1944. || req_exec_amf_hastateset->haState == SA_AMF_STANDBY ) {
  1945. changeToComponent = SA_AMF_PROTECTION_GROUP_ADDED;
  1946. }
  1947. } else {
  1948. if (component->currentHAState == req_exec_amf_hastateset->haState) {
  1949. changeToComponent = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  1950. }
  1951. }
  1952. component->currentHAState = req_exec_amf_hastateset->haState;
  1953. component->newHAState = component->currentHAState;
  1954. dsm (component);
  1955. if( changeToComponent != SA_AMF_PROTECTION_GROUP_NO_CHANGE ) {
  1956. protectiongroup_notifications_send (component, changeToComponent);
  1957. }
  1958. return (0);
  1959. }
  1960. static int message_handler_req_amf_init (struct conn_info *conn_info, void *message)
  1961. {
  1962. struct res_lib_init res_lib_init;
  1963. SaErrorT error = SA_ERR_SECURITY;
  1964. log_printf (LOG_LEVEL_DEBUG, "Got AMF request to initalize availability management framework service.\n");
  1965. if (conn_info->authenticated) {
  1966. conn_info->service = SOCKET_SERVICE_AMF;
  1967. error = SA_OK;
  1968. }
  1969. res_lib_init.header.size = sizeof (struct res_lib_init);
  1970. res_lib_init.header.id = MESSAGE_RES_INIT;
  1971. res_lib_init.header.error = error;
  1972. libais_send_response (conn_info, &res_lib_init, sizeof (res_lib_init));
  1973. list_init (&conn_info->conn_list);
  1974. if (conn_info->authenticated) {
  1975. return (0);
  1976. }
  1977. return (-1);
  1978. }
  1979. static int message_handler_req_lib_activatepoll (struct conn_info *conn_info, void *message)
  1980. {
  1981. struct res_lib_activatepoll res_lib_activatepoll;
  1982. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_activatepoll()\n");
  1983. memset (&res_lib_activatepoll,0,sizeof(res_lib_activatepoll));
  1984. res_lib_activatepoll.header.size = sizeof (struct res_lib_activatepoll);
  1985. res_lib_activatepoll.header.id = MESSAGE_RES_LIB_ACTIVATEPOLL;
  1986. libais_send_response (conn_info, &res_lib_activatepoll, sizeof (struct res_lib_activatepoll));
  1987. return (0);
  1988. }
  1989. static int message_handler_req_amf_componentregister (struct conn_info *conn_info, void *message)
  1990. {
  1991. struct req_amf_componentregister *req_lib_amf_componentregister = (struct req_amf_componentregister *)message;
  1992. struct req_exec_amf_componentregister req_exec_amf_componentregister;
  1993. struct iovec iovecs[2];
  1994. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentregister()\n");
  1995. req_exec_amf_componentregister.header.size = sizeof (struct req_exec_amf_componentregister);
  1996. req_exec_amf_componentregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTREGISTER;
  1997. req_exec_amf_componentregister.source.conn_info = conn_info;
  1998. req_exec_amf_componentregister.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1999. memcpy (&req_exec_amf_componentregister.req_lib_amf_componentregister,
  2000. req_lib_amf_componentregister,
  2001. sizeof (struct req_lib_amf_componentregister));
  2002. iovecs[0].iov_base = (char *)&req_exec_amf_componentregister;
  2003. iovecs[0].iov_len = sizeof (req_exec_amf_componentregister);
  2004. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2005. return (0);
  2006. }
  2007. static int message_handler_req_amf_componentunregister (struct conn_info *conn_info, void *message)
  2008. {
  2009. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  2010. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  2011. struct iovec iovecs[2];
  2012. struct saAmfComponent *component;
  2013. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentunregister()\n");
  2014. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  2015. req_exec_amf_componentunregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER;
  2016. req_exec_amf_componentunregister.source.conn_info = conn_info;
  2017. req_exec_amf_componentunregister.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  2018. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  2019. req_lib_amf_componentunregister,
  2020. sizeof (struct req_lib_amf_componentunregister));
  2021. component = findComponent (&req_lib_amf_componentunregister->compName);
  2022. if (component && component->registered && component->local) {
  2023. component->probableCause = SA_AMF_NOT_RESPONDING;
  2024. }
  2025. iovecs[0].iov_base = (char *)&req_exec_amf_componentunregister;
  2026. iovecs[0].iov_len = sizeof (req_exec_amf_componentunregister);
  2027. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2028. return (0);
  2029. }
  2030. static int message_handler_req_amf_readinessstateget (struct conn_info *conn_info, void *message)
  2031. {
  2032. struct req_amf_readinessstateget *req_amf_readinessstateget = (struct req_amf_readinessstateget *)message;
  2033. struct res_lib_amf_readinessstateget res_lib_amf_readinessstateget;
  2034. struct saAmfComponent *component;
  2035. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_readinessstateget()\n");
  2036. res_lib_amf_readinessstateget.header.id = MESSAGE_RES_AMF_READINESSSTATEGET;
  2037. res_lib_amf_readinessstateget.header.size = sizeof (struct res_lib_amf_readinessstateget);
  2038. res_lib_amf_readinessstateget.header.error = SA_ERR_NOT_EXIST;
  2039. component = findComponent (&req_amf_readinessstateget->compName);
  2040. log_printf (LOG_LEVEL_DEBUG, "readinessstateget: found component %p\n", component);
  2041. if (component) {
  2042. memcpy (&res_lib_amf_readinessstateget.readinessState,
  2043. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  2044. res_lib_amf_readinessstateget.header.error = SA_OK;
  2045. }
  2046. libais_send_response (conn_info, &res_lib_amf_readinessstateget, sizeof (struct res_lib_amf_readinessstateget));
  2047. return (0);
  2048. }
  2049. static int message_handler_req_amf_hastateget (struct conn_info *conn_info, void *message)
  2050. {
  2051. struct req_amf_hastateget *req_amf_hastateget = (struct req_amf_hastateget *)message;
  2052. struct res_lib_amf_hastateget res_lib_amf_hastateget;
  2053. struct saAmfComponent *component;
  2054. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_hastateget()\n");
  2055. res_lib_amf_hastateget.header.id = MESSAGE_RES_AMF_HASTATEGET;
  2056. res_lib_amf_hastateget.header.size = sizeof (struct res_lib_amf_hastateget);
  2057. res_lib_amf_hastateget.header.error = SA_ERR_NOT_EXIST;
  2058. component = component_in_protectiongroup_find (&req_amf_hastateget->csiName, &req_amf_hastateget->compName);
  2059. if (component) {
  2060. memcpy (&res_lib_amf_hastateget.haState,
  2061. &component->currentHAState, sizeof (SaAmfHAStateT));
  2062. res_lib_amf_hastateget.header.error = SA_OK;
  2063. }
  2064. libais_send_response (conn_info, &res_lib_amf_hastateget, sizeof (struct res_lib_amf_hastateget));
  2065. return (0);
  2066. }
  2067. static int message_handler_req_amf_protectiongrouptrackstart (struct conn_info *conn_info, void *message)
  2068. {
  2069. struct req_amf_protectiongrouptrackstart *req_amf_protectiongrouptrackstart = (struct req_amf_protectiongrouptrackstart *)message;
  2070. struct res_lib_amf_protectiongrouptrackstart res_lib_amf_protectiongrouptrackstart;
  2071. struct libamf_ci_trackentry *track = 0;
  2072. int i;
  2073. struct saAmfProtectionGroup *amfProtectionGroup;
  2074. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_protectiongrouptrackstart()\n");
  2075. amfProtectionGroup = protectiongroup_find (&req_amf_protectiongrouptrackstart->csiName);
  2076. if (amfProtectionGroup) {
  2077. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstart: Got valid track start on CSI: %s.\n", getSaNameT (&req_amf_protectiongrouptrackstart->csiName));
  2078. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  2079. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) {
  2080. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2081. break;
  2082. }
  2083. }
  2084. if (track == 0) {
  2085. grow_amf_track_table (conn_info, 1);
  2086. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2087. }
  2088. track->active = 1;
  2089. track->trackFlags = req_amf_protectiongrouptrackstart->trackFlags;
  2090. track->notificationBufferAddress = req_amf_protectiongrouptrackstart->notificationBufferAddress;
  2091. memcpy (&track->csiName,
  2092. &req_amf_protectiongrouptrackstart->csiName, sizeof (SaNameT));
  2093. conn_info->ais_ci.u.libamf_ci.trackActive += 1;
  2094. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  2095. /*
  2096. * If SA_TRACK_CURRENT is specified, write out all current connections
  2097. */
  2098. } else {
  2099. log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
  2100. }
  2101. res_lib_amf_protectiongrouptrackstart.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART;
  2102. res_lib_amf_protectiongrouptrackstart.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstart);
  2103. res_lib_amf_protectiongrouptrackstart.header.error = SA_ERR_NOT_EXIST;
  2104. if (amfProtectionGroup) {
  2105. res_lib_amf_protectiongrouptrackstart.header.error = SA_OK;
  2106. }
  2107. libais_send_response (conn_info, &res_lib_amf_protectiongrouptrackstart,
  2108. sizeof (struct res_lib_amf_protectiongrouptrackstart));
  2109. if (amfProtectionGroup &&
  2110. req_amf_protectiongrouptrackstart->trackFlags & SA_TRACK_CURRENT) {
  2111. protectiongroup_notification_send (conn_info,
  2112. track->notificationBufferAddress,
  2113. amfProtectionGroup,
  2114. 0,
  2115. 0,
  2116. SA_TRACK_CHANGES_ONLY);
  2117. track->trackFlags &= ~SA_TRACK_CURRENT;
  2118. }
  2119. return (0);
  2120. }
  2121. static int message_handler_req_amf_protectiongrouptrackstop (struct conn_info *conn_info, void *message)
  2122. {
  2123. struct req_amf_protectiongrouptrackstop *req_amf_protectiongrouptrackstop = (struct req_amf_protectiongrouptrackstop *)message;
  2124. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  2125. struct libamf_ci_trackentry *track = 0;
  2126. int i;
  2127. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_protectiongrouptrackstop()\n");
  2128. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  2129. if (name_match (&req_amf_protectiongrouptrackstop->csiName,
  2130. &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) {
  2131. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2132. }
  2133. }
  2134. if (track) {
  2135. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_amf_protectiongrouptrackstop->csiName));
  2136. memset (track, 0, sizeof (struct libamf_ci_trackentry));
  2137. conn_info->ais_ci.u.libamf_ci.trackActive -= 1;
  2138. if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) {
  2139. list_del (&conn_info->conn_list);
  2140. }
  2141. }
  2142. res_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
  2143. res_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstop);
  2144. res_lib_amf_protectiongrouptrackstop.header.error = SA_ERR_NOT_EXIST;
  2145. if (track) {
  2146. res_lib_amf_protectiongrouptrackstop.header.error = SA_OK;
  2147. }
  2148. libais_send_response (conn_info, &res_lib_amf_protectiongrouptrackstop,
  2149. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  2150. return (0);
  2151. }
  2152. static int message_handler_req_amf_errorreport (struct conn_info *conn_info, void *message)
  2153. {
  2154. struct req_lib_amf_errorreport *req_lib_amf_errorreport = (struct req_lib_amf_errorreport *)message;
  2155. struct req_exec_amf_errorreport req_exec_amf_errorreport;
  2156. struct iovec iovecs[2];
  2157. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_errorreport()\n");
  2158. req_exec_amf_errorreport.header.size = sizeof (struct req_exec_amf_errorreport);
  2159. req_exec_amf_errorreport.header.id = MESSAGE_REQ_EXEC_AMF_ERRORREPORT;
  2160. req_exec_amf_errorreport.source.conn_info = conn_info;
  2161. req_exec_amf_errorreport.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  2162. memcpy (&req_exec_amf_errorreport.req_lib_amf_errorreport,
  2163. req_lib_amf_errorreport,
  2164. sizeof (struct req_lib_amf_errorreport));
  2165. iovecs[0].iov_base = (char *)&req_exec_amf_errorreport;
  2166. iovecs[0].iov_len = sizeof (req_exec_amf_errorreport);
  2167. // iovecs[0].iov_len = sizeof (req_exec_amf_errorreport) - sizeof (req_lib_amf_errorreport);
  2168. // iovecs[1].iov_base = (char *)&req_lib_amf_errorreport;
  2169. // iovecs[1].iov_len = sizeof (req_lib_amf_errorreport);
  2170. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2171. return (0);
  2172. }
  2173. static int message_handler_req_amf_errorcancelall (struct conn_info *conn_info, void *message)
  2174. {
  2175. struct req_lib_amf_errorcancelall *req_lib_amf_errorcancelall = (struct req_lib_amf_errorcancelall *)message;
  2176. struct req_exec_amf_errorcancelall req_exec_amf_errorcancelall;
  2177. struct iovec iovecs[2];
  2178. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_errorcancelall()\n");
  2179. req_exec_amf_errorcancelall.header.size = sizeof (struct req_exec_amf_errorcancelall);
  2180. req_exec_amf_errorcancelall.header.id = MESSAGE_REQ_EXEC_AMF_ERRORCANCELALL;
  2181. req_exec_amf_errorcancelall.source.conn_info = conn_info;
  2182. req_exec_amf_errorcancelall.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  2183. memcpy (&req_exec_amf_errorcancelall.req_lib_amf_errorcancelall,
  2184. req_lib_amf_errorcancelall,
  2185. sizeof (struct req_lib_amf_errorcancelall));
  2186. iovecs[0].iov_base = (char *)&req_exec_amf_errorcancelall;
  2187. iovecs[0].iov_len = sizeof (req_exec_amf_errorcancelall);
  2188. // iovecs[0].iov_len = sizeof (req_exec_amf_errorcancelall) - sizeof (req_lib_amf_errorcancelall);
  2189. // iovecs[1].iov_base = (char *)&req_lib_amf_errorcancelall;
  2190. // iovecs[1].iov_len = sizeof (req_lib_amf_errorcancelall);
  2191. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2192. return (0);
  2193. }
  2194. static int message_handler_req_amf_stoppingcomplete (struct conn_info *conn_info_notused,
  2195. void *message)
  2196. {
  2197. struct req_amf_stoppingcomplete *req_amf_stoppingcomplete = (struct req_amf_stoppingcomplete *)message;
  2198. struct conn_info *inv_conn_info;
  2199. int interface;
  2200. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_stoppingcomplete()\n");
  2201. req_amf_invocation_get_and_destroy (req_amf_stoppingcomplete->invocation,
  2202. &interface, &inv_conn_info);
  2203. inv_conn_info->component->currentReadinessState = inv_conn_info->component->newReadinessState;
  2204. readiness_state_group_set (inv_conn_info->component, SA_AMF_STOPPING);
  2205. protectiongroup_notifications_send (inv_conn_info->component,SA_AMF_PROTECTION_GROUP_STATE_CHANGE);
  2206. return (0);
  2207. }
  2208. void response_handler_healthcheckcallback (struct conn_info *conn_info,
  2209. struct req_amf_response *req_amf_response) {
  2210. if (req_amf_response->error == SA_OK) {
  2211. log_printf (LOG_LEVEL_DEBUG, "setting healthcheck ok\n");
  2212. conn_info->component->healthcheck_outstanding = 0;
  2213. }
  2214. }
  2215. static int message_handler_req_amf_response (struct conn_info *conn_info_nouse, void *message)
  2216. {
  2217. struct req_amf_response *req_amf_response = (struct req_amf_response *)message;
  2218. struct conn_info *conn_info;
  2219. int interface;
  2220. int res;
  2221. log_printf (LOG_LEVEL_DEBUG, "Handle : message_handler_req_amf_response()\n");
  2222. res = req_amf_invocation_get_and_destroy (req_amf_response->invocation,
  2223. &interface, &conn_info);
  2224. log_printf (LOG_LEVEL_DEBUG, "handling response connection %p interface %x\n", conn_info, interface);
  2225. switch (interface) {
  2226. case MESSAGE_REQ_AMF_RESPONSE_SAAMFHEALTHCHECKCALLBACK:
  2227. response_handler_healthcheckcallback (conn_info, req_amf_response);
  2228. break;
  2229. case MESSAGE_REQ_AMF_RESPONSE_SAAMFREADINESSSTATESETCALLBACK:
  2230. response_handler_readinessstatesetcallback (conn_info, req_amf_response);
  2231. break;
  2232. case MESSAGE_REQ_AMF_RESPONSE_SAAMFCSISETCALLBACK:
  2233. response_handler_csisetcallback (conn_info, req_amf_response);
  2234. break;
  2235. case MESSAGE_REQ_AMF_RESPONSE_SAAMFCSIREMOVECALLBACK:
  2236. break;
  2237. default:
  2238. // TODO
  2239. log_printf (LOG_LEVEL_ERROR, "invalid invocation value %x\n", req_amf_response->invocation);
  2240. break;
  2241. }
  2242. return (0);
  2243. }
  2244. static int message_handler_req_amf_componentcapabilitymodelget (struct conn_info *conn_info, void *message)
  2245. {
  2246. struct req_amf_componentcapabilitymodelget *req_amf_componentcapabilitymodelget = (struct req_amf_componentcapabilitymodelget *)message;
  2247. struct res_lib_amf_componentcapabilitymodelget res_lib_amf_componentcapabilitymodelget;
  2248. struct saAmfComponent *component;
  2249. SaErrorT error = SA_OK;
  2250. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentcapabilitymodelget()\n");
  2251. memset( &res_lib_amf_componentcapabilitymodelget,0,sizeof(res_lib_amf_componentcapabilitymodelget));
  2252. log_printf (LOG_LEVEL_DEBUG, "componentcapabilitymodelget: Retrieve name %s.\n", getSaNameT (&req_amf_componentcapabilitymodelget->compName));
  2253. component = findComponent (&req_amf_componentcapabilitymodelget->compName);
  2254. if (component && component->registered) {
  2255. memcpy (&res_lib_amf_componentcapabilitymodelget.componentCapabilityModel,
  2256. &component->componentCapabilityModel, sizeof (SaAmfComponentCapabilityModelT));
  2257. } else {
  2258. error = SA_ERR_NOT_EXIST;
  2259. }
  2260. res_lib_amf_componentcapabilitymodelget.header.size = sizeof (struct res_lib_amf_componentcapabilitymodelget);
  2261. res_lib_amf_componentcapabilitymodelget.header.id = MESSAGE_RES_AMF_COMPONENTCAPABILITYMODELGET;
  2262. res_lib_amf_componentcapabilitymodelget.header.error = error;
  2263. libais_send_response (conn_info, &res_lib_amf_componentcapabilitymodelget,
  2264. sizeof (struct res_lib_amf_componentcapabilitymodelget));
  2265. return (0);
  2266. }
  2267. static char disabled_unlocked_state_text[6][64] = {
  2268. "AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL",
  2269. "AMF_DISABLED_UNLOCKED_FAILED",
  2270. "AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED",
  2271. "AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED",
  2272. "AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED",
  2273. "AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED"
  2274. };
  2275. static char *disabledunlockedstate_ntoa (int state)
  2276. {
  2277. static char str[64];
  2278. if (state >= 0 && state < 6) {
  2279. sprintf (str, "%s(%d)", disabled_unlocked_state_text[state], state);
  2280. }else{
  2281. sprintf (str, "Unknown(%d)", state);
  2282. }
  2283. return (str);
  2284. }
  2285. static char enabled_unlocked_state_text[7][64] = {
  2286. "AMF_ENABLED_UNLOCKED_INITIAL",
  2287. "AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED",
  2288. "AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED",
  2289. "AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED",
  2290. "AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED",
  2291. "AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED",
  2292. "AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED"
  2293. };
  2294. static char *enabledunlockedstate_ntoa (int state)
  2295. {
  2296. static char str[64];
  2297. if (state >= 0 && state < 7) {
  2298. sprintf (str, "%s(%d)", enabled_unlocked_state_text[state], state);
  2299. }else{
  2300. sprintf (str, "Unknown(%d)", state);
  2301. }
  2302. return (str);
  2303. }
  2304. static char readiness_state_text[4][32] = {
  2305. "Unknown",
  2306. "SA_AMF_OUT_OF_SERVICE",
  2307. "SA_AMF_IN_SERVICE",
  2308. "SA_AMF_QUIESCED",
  2309. };
  2310. static char *readinessstate_ntoa (int state)
  2311. {
  2312. static char str[32];
  2313. if (state > 0 && state < 4) {
  2314. sprintf (str, "%s(%d)", readiness_state_text[state], state);
  2315. }else{
  2316. sprintf (str, "Unknown(%d)", state);
  2317. }
  2318. return (str);
  2319. }
  2320. static char ha_state_text[4][32] = {
  2321. "Unknown",
  2322. "SA_AMF_ACTIVE",
  2323. "SA_AMF_STANDBY",
  2324. "SA_AMF_QUIESCED",
  2325. };
  2326. static char *hastate_ntoa (SaAmfHAStateT state)
  2327. {
  2328. static char str[32];
  2329. if (state > 0 && state < 4) {
  2330. sprintf (str, "%s(%d)", ha_state_text[state], state);
  2331. }else{
  2332. sprintf (str, "Unknown(%d)", state);
  2333. }
  2334. return (str);
  2335. }
  2336. static void amf_dump_comp (struct saAmfComponent *component ,void *data)
  2337. {
  2338. char name[64];
  2339. int level = LOG_LEVEL_NOTICE;
  2340. data = NULL;
  2341. log_printf (level, "----------------\n" );
  2342. log_printf (level, "registered = %d\n" ,component->registered);
  2343. log_printf (level, "local = %d\n" ,component->local );
  2344. log_printf (level, "source_addr = %s\n" ,inet_ntoa (component->source_addr));
  2345. memset (name, 0 , sizeof(name));
  2346. memcpy (name, component->name.value, component->name.length);
  2347. log_printf (level, "name = %s\n" ,name );
  2348. log_printf (level, "currentReadinessState = %s\n" ,readinessstate_ntoa (component->currentReadinessState));
  2349. log_printf (level, "newReadinessState = %s\n" ,readinessstate_ntoa (component->newReadinessState));
  2350. log_printf (level, "currentHAState = %s\n" ,hastate_ntoa (component->currentHAState));
  2351. log_printf (level, "newHAState = %s\n" ,hastate_ntoa (component->newHAState));
  2352. log_printf (level, "enabledUnlockedState = %s\n" ,enabledunlockedstate_ntoa (component->enabledUnlockedState));
  2353. log_printf (level, "disabledUnlockedState = %s\n" ,disabledunlockedstate_ntoa (component->disabledUnlockedState));
  2354. log_printf (level, "probableCause = %d\n" ,component->probableCause );
  2355. }
  2356. void amf_dump ( )
  2357. {
  2358. enumerate_components (amf_dump_comp, NULL);
  2359. fflush (stderr);
  2360. return;
  2361. }