amf.c 77 KB

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