amf.c 84 KB

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