amf.c 77 KB

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