amf.c 80 KB

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