amf.c 76 KB

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