amf.c 84 KB

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