amf.c 77 KB

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