amf.c 84 KB

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