amf.c 84 KB

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