amf.c 91 KB

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