amf.c 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335
  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->state != CONN_STATE_ACTIVE ||
  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->state != CONN_STATE_ACTIVE ||
  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. int activeServiceUnits = 0;
  803. /*
  804. * Once all components of a service unit are out of service,
  805. * activate another service unit in standby
  806. */
  807. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedOutOfServiceCompleted: component out of service %s\n", getSaNameT (&component->name));
  808. /*
  809. * Determine if all components have responded to going out of service
  810. */
  811. unit = component->saAmfUnit;
  812. for (serviceUnitOutOfService = 1, list = unit->saAmfComponentHead.next;
  813. list != &unit->saAmfComponentHead;
  814. list = list->next) {
  815. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  816. if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) {
  817. if (component->currentReadinessState != SA_AMF_OUT_OF_SERVICE) {
  818. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n", getSaNameT (&component->name));
  819. serviceUnitOutOfService = 0;
  820. break;
  821. }
  822. }
  823. }
  824. group = unit->saAmfGroup;
  825. activeServiceUnits = activeServiceUnitsCount(group);
  826. if (activeServiceUnits>=group->saAmfActiveUnitsDesired) {
  827. return;
  828. }
  829. if (serviceUnitOutOfService == 1) {
  830. log_printf (LOG_LEVEL_DEBUG, "SU has gone out of service.\n");
  831. /*
  832. * Search all units
  833. */
  834. for (unit_list = group->saAmfUnitHead.next;
  835. unit_list != &group->saAmfUnitHead;
  836. unit_list = unit_list->next) {
  837. unit = list_entry (unit_list,
  838. struct saAmfUnit, saAmfUnitList);
  839. log_printf (LOG_LEVEL_DEBUG, "Checking if service unit is in standby %s\n", getSaNameT (&unit->name));
  840. /*
  841. * Search all components
  842. */
  843. for (serviceUnitInStandby = 1,
  844. comp_list = unit->saAmfComponentHead.next;
  845. comp_list != &unit->saAmfComponentHead;
  846. comp_list = comp_list->next) {
  847. component = list_entry (comp_list,
  848. struct saAmfComponent, saAmfComponentList);
  849. if (component->currentHAState != SA_AMF_STANDBY) {
  850. serviceUnitInStandby = 0;
  851. break; /* for iteration of service unit components */
  852. }
  853. }
  854. if (serviceUnitInStandby) {
  855. break; /* for iteration of service group's service units */
  856. }
  857. }
  858. /*
  859. * All components in service unit are standby, activate standby service unit
  860. */
  861. if (serviceUnitInStandby) {
  862. log_printf (LOG_LEVEL_DEBUG, "unit in standby\n");
  863. for (list = unit->saAmfComponentHead.next;
  864. list != &unit->saAmfComponentHead;
  865. list = list->next) {
  866. component = list_entry (list,
  867. struct saAmfComponent, saAmfComponentList);
  868. haStateSetApi (component, SA_AMF_ACTIVE);
  869. }
  870. } else {
  871. log_printf (LOG_LEVEL_DEBUG, "Can't activate standby service unit because no standby is available.\n");
  872. }
  873. }
  874. }
  875. static void dsmEnabledUnlockedInitial (
  876. struct saAmfComponent *component)
  877. {
  878. struct saAmfUnit *unit;
  879. struct list_head *list;
  880. unit = component->saAmfUnit;
  881. for (list = unit->saAmfComponentHead.next;
  882. list != &unit->saAmfComponentHead;
  883. list = list->next) {
  884. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  885. readinessStateSetApi (component, SA_AMF_IN_SERVICE);
  886. log_printf (LOG_LEVEL_DEBUG, "dsm: telling component %s to enter SA_AMF_IN_SERVICE.\n",
  887. getSaNameT (&component->name));
  888. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED;
  889. }
  890. }
  891. static void dsmEnabledUnlockedInServiceRequested (
  892. struct saAmfComponent *component)
  893. {
  894. struct saAmfUnit *unit;
  895. struct list_head *list;
  896. int in_service;
  897. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceRequested %s.\n", getSaNameT (&component->name));
  898. unit = component->saAmfUnit;
  899. for (in_service = 1, list = unit->saAmfComponentHead.next;
  900. list != &unit->saAmfComponentHead;
  901. list = list->next) {
  902. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  903. if (component->currentReadinessState != SA_AMF_IN_SERVICE) {
  904. log_printf (LOG_LEVEL_DEBUG, "dsm: Found atleast one component not in service\n");
  905. in_service = 0;
  906. break;
  907. }
  908. }
  909. if (in_service) {
  910. log_printf (LOG_LEVEL_DEBUG, "DSM determined component is in service\n");
  911. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED;
  912. dsm (component);
  913. }
  914. }
  915. static void dsmEnabledUnlockedInServiceCompleted (
  916. struct saAmfComponent *component)
  917. {
  918. struct saAmfUnit *unit;
  919. struct list_head *list;
  920. SaAmfHAStateT newHaState;
  921. int activeServiceUnits;
  922. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceCompleted %s.\n", getSaNameT (&component->name));
  923. unit = component->saAmfUnit;
  924. for (list = unit->saAmfComponentHead.next;
  925. list != &unit->saAmfComponentHead;
  926. list = list->next) {
  927. component = list_entry (list,
  928. struct saAmfComponent, saAmfComponentList);
  929. log_printf (LOG_LEVEL_DEBUG, "Requesting component go active.\n", getSaNameT (&component->name));
  930. /*
  931. * Count number of active service units
  932. */
  933. activeServiceUnits = activeServiceUnitsCount (component->saAmfUnit->saAmfGroup);
  934. if (activeServiceUnits < component->saAmfUnit->saAmfGroup->saAmfActiveUnitsDesired) {
  935. newHaState = SA_AMF_ACTIVE;
  936. log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_ACTIVE\n", getSaNameT (&component->name));
  937. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED;
  938. } else {
  939. newHaState = SA_AMF_STANDBY;
  940. log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_STANDBY\n", getSaNameT (&component->name));
  941. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED;
  942. }
  943. haStateSetApi (component, newHaState);
  944. }
  945. }
  946. void dsmEnabledUnlockedActiveRequested (
  947. struct saAmfComponent *component)
  948. {
  949. if (component->local == 1) {
  950. log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer\n");
  951. poll_timer_add (aisexec_poll_handle,
  952. component->healthcheckInterval,
  953. (void *)component->conn_info,
  954. timer_function_libamf_healthcheck,
  955. &component->timer_healthcheck);
  956. }
  957. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED;
  958. }
  959. void dsmEnabledUnlockedStandbyRequested (
  960. struct saAmfComponent *component)
  961. {
  962. if (component->local == 1) {
  963. log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer\n");
  964. poll_timer_add (aisexec_poll_handle,
  965. component->healthcheckInterval,
  966. (void *)component->conn_info,
  967. timer_function_libamf_healthcheck,
  968. &component->timer_healthcheck);
  969. }
  970. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED;
  971. }
  972. void dsmEnabledUnlockedTransitionDisabledUnlocked (
  973. struct saAmfComponent *component)
  974. {
  975. struct saAmfUnit *unit;
  976. struct list_head *list;
  977. unit = component->saAmfUnit;
  978. for (list = unit->saAmfComponentHead.next;
  979. list != &unit->saAmfComponentHead;
  980. list = list->next) {
  981. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  982. log_printf (LOG_LEVEL_DEBUG, "Requesting component %s transition to disabled.\n",
  983. getSaNameT (&component->name));
  984. component->saAmfUnit->operationalAdministrativeState = AMF_DISABLED_UNLOCKED;
  985. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_FAILED;
  986. }
  987. dsm (component);
  988. }
  989. static void dsmEnabledUnlocked (
  990. struct saAmfComponent *component)
  991. {
  992. switch (component->enabledUnlockedState) {
  993. case AMF_ENABLED_UNLOCKED_INITIAL:
  994. dsmEnabledUnlockedInitial (component);
  995. break;
  996. case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED:
  997. dsmEnabledUnlockedInServiceRequested (component);
  998. break;
  999. case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED:
  1000. dsmEnabledUnlockedInServiceCompleted (component);
  1001. break;
  1002. case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED:
  1003. dsmEnabledUnlockedActiveRequested (component);
  1004. break;
  1005. case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED:
  1006. /* noop - operational state */
  1007. break;
  1008. case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED:
  1009. dsmEnabledUnlockedActiveRequested (component);
  1010. break;
  1011. case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED:
  1012. /* noop - operational state */
  1013. break;
  1014. default:
  1015. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlocked: unkown state machine value.\n");
  1016. }
  1017. }
  1018. static void dsmDisabledUnlocked (
  1019. struct saAmfComponent *component)
  1020. {
  1021. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked for %s state %d\n",
  1022. getSaNameT (&component->name),
  1023. component->disabledUnlockedState);
  1024. switch (component->disabledUnlockedState) {
  1025. case AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL:
  1026. dsmDisabledUnlockedRegisteredOrErrorCancel (component);
  1027. break;
  1028. case AMF_DISABLED_UNLOCKED_FAILED:
  1029. dsmDisabledUnlockedFailed (component);
  1030. break;
  1031. case AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED:
  1032. dsmDisabledUnlockedQuiescedRequested (component);
  1033. break;
  1034. case AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED:
  1035. dsmDisabledUnlockedQuiescedCompleted (component);
  1036. break;
  1037. case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED:
  1038. dsmDisabledUnlockedOutOfServiceRequested (component);
  1039. break;
  1040. case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED:
  1041. dsmDisabledUnlockedOutOfServiceCompleted (component);
  1042. break;
  1043. default:
  1044. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked: unkown state machine value %d.\n", component->disabledUnlockedState);
  1045. }
  1046. }
  1047. static void dsm (
  1048. struct saAmfComponent *component)
  1049. {
  1050. log_printf (LOG_LEVEL_DEBUG, "dsm for component %s\n", getSaNameT (&component->name));
  1051. switch (component->saAmfUnit->operationalAdministrativeState) {
  1052. case AMF_DISABLED_UNLOCKED:
  1053. dsmDisabledUnlocked (component);
  1054. break;
  1055. case AMF_ENABLED_UNLOCKED:
  1056. dsmEnabledUnlocked (component);
  1057. break;
  1058. /*
  1059. AMF_DISABLED_LOCKED,
  1060. AMF_ENABLED_STOPPING
  1061. */
  1062. default:
  1063. log_printf (LOG_LEVEL_DEBUG, "dsm: unknown state machine value.\n");
  1064. }
  1065. }
  1066. #if 0
  1067. /*
  1068. * This is currently unused, but executes the componentterminatecallback
  1069. * callback in the AMF api.
  1070. */
  1071. void componentTerminate (struct conn_info *conn_info)
  1072. {
  1073. struct res_lib_amf_componentterminatecallback res_lib_amf_componentterminatecallback;
  1074. res_lib_amf_componentterminatecallback.header.id = MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK;
  1075. res_lib_amf_componentterminatecallback.header.size = sizeof (struct res_lib_amf_componentterminatecallback);
  1076. res_lib_amf_componentterminatecallback.header.error = SA_OK;
  1077. res_lib_amf_componentterminatecallback.invocation =
  1078. req_amf_response_set (
  1079. MESSAGE_REQ_AMF_RESPONSE_SAAMFCOMPONENTTERMINATECALLBACK,
  1080. fd);
  1081. memcpy (&res_lib_amf_componentterminatecallback.compName,
  1082. &connections[fd].component->name, sizeof (SaNameT));
  1083. connections[fd].component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  1084. log_printf (LOG_LEVEL_DEBUG, "terminating component on fd %d\n", fd);
  1085. libais_send_response (fd, &res_lib_amf_componentterminatecallback,
  1086. sizeof (struct res_lib_amf_componentterminatecallback));
  1087. }
  1088. #endif /* Not currently implemented */
  1089. void errorReport (
  1090. struct saAmfComponent *component,
  1091. SaAmfProbableCauseT probableCause)
  1092. {
  1093. struct req_exec_amf_errorreport req_exec_amf_errorreport;
  1094. struct iovec iovecs[2];
  1095. req_exec_amf_errorreport.header.size = sizeof (struct req_exec_amf_errorreport);
  1096. req_exec_amf_errorreport.header.id = MESSAGE_REQ_EXEC_AMF_ERRORREPORT;
  1097. req_exec_amf_errorreport.source.conn_info = 0;
  1098. req_exec_amf_errorreport.source.in_addr.s_addr = 0;
  1099. memcpy (&req_exec_amf_errorreport.req_lib_amf_errorreport.erroneousComponent,
  1100. &component->name,
  1101. sizeof (SaNameT));
  1102. req_exec_amf_errorreport.req_lib_amf_errorreport.errorDescriptor.probableCause = probableCause;
  1103. iovecs[0].iov_base = (char *)&req_exec_amf_errorreport;
  1104. iovecs[0].iov_len = sizeof (req_exec_amf_errorreport);
  1105. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1106. }
  1107. int healthcheck_instance = 0;
  1108. void timer_function_libamf_healthcheck (void *data) {
  1109. struct res_lib_amf_healthcheckcallback res_lib_amf_healthcheckcallback;
  1110. struct conn_info *conn_info = (struct conn_info *)data;
  1111. res_lib_amf_healthcheckcallback.header.id = MESSAGE_RES_AMF_HEALTHCHECKCALLBACK;
  1112. res_lib_amf_healthcheckcallback.header.size = sizeof (struct res_lib_amf_healthcheckcallback);
  1113. res_lib_amf_healthcheckcallback.header.error = SA_OK;
  1114. log_printf (LOG_LEVEL_DEBUG, "checking healthcheck on component %s\n",
  1115. getSaNameT (&conn_info->component->name));
  1116. if (conn_info->component->healthcheck_outstanding == 1) {
  1117. log_printf (LOG_LEVEL_DEBUG, "Healthcheck timed out on component %s\n",
  1118. getSaNameT (&conn_info->component->name));
  1119. /*
  1120. * Report the error to the rest of the cluster using the normal state machine
  1121. */
  1122. errorReport (conn_info->component, SA_AMF_NOT_RESPONDING);
  1123. conn_info->component->healthcheck_outstanding = 2;
  1124. } else
  1125. if (conn_info->component->healthcheck_outstanding == 0) {
  1126. conn_info->component->healthcheck_outstanding = 1;
  1127. /*
  1128. * Send healthcheck message
  1129. */
  1130. res_lib_amf_healthcheckcallback.invocation =
  1131. req_amf_invocation_create (
  1132. MESSAGE_REQ_AMF_RESPONSE_SAAMFHEALTHCHECKCALLBACK,
  1133. conn_info);
  1134. if (res_lib_amf_healthcheckcallback.invocation == -1) {
  1135. printf ("TODO healthcheck set callback\n");
  1136. }
  1137. memcpy (&res_lib_amf_healthcheckcallback.compName,
  1138. &conn_info->component->name,
  1139. sizeof (SaNameT));
  1140. res_lib_amf_healthcheckcallback.checkType = SA_AMF_HEARTBEAT;
  1141. log_printf (LOG_LEVEL_DEBUG, "Sending instance %d\n", healthcheck_instance);
  1142. res_lib_amf_healthcheckcallback.instance = healthcheck_instance++;
  1143. libais_send_response (conn_info,
  1144. &res_lib_amf_healthcheckcallback,
  1145. sizeof (struct res_lib_amf_healthcheckcallback));
  1146. poll_timer_add (aisexec_poll_handle,
  1147. conn_info->component->healthcheckInterval,
  1148. (void *)conn_info,
  1149. timer_function_libamf_healthcheck,
  1150. &conn_info->component->timer_healthcheck);
  1151. }
  1152. }
  1153. struct saAmfProtectionGroup *findProtectionGroup (
  1154. SaNameT *csiName)
  1155. {
  1156. struct list_head *AmfGroupList;
  1157. struct list_head *AmfProtectionGroupList;
  1158. struct saAmfGroup *saAmfGroup;
  1159. struct saAmfProtectionGroup *AmfProtectionGroup;
  1160. /*
  1161. * Search all groups
  1162. */
  1163. for (AmfGroupList = saAmfGroupHead.next;
  1164. AmfGroupList != &saAmfGroupHead;
  1165. AmfGroupList = AmfGroupList->next) {
  1166. saAmfGroup = list_entry (AmfGroupList,
  1167. struct saAmfGroup, saAmfGroupList);
  1168. /*
  1169. * Search all protection groups
  1170. */
  1171. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  1172. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  1173. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  1174. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  1175. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  1176. if (SaNameTisNameT (csiName, &AmfProtectionGroup->name)) {
  1177. return (AmfProtectionGroup);
  1178. }
  1179. }
  1180. }
  1181. return (0);
  1182. }
  1183. struct saAmfComponent *findComponentInProtectionGroup (
  1184. SaNameT *csiName,
  1185. SaNameT *compName)
  1186. {
  1187. struct list_head *AmfGroupList = 0;
  1188. struct list_head *AmfProtectionGroupList = 0;
  1189. struct list_head *AmfComponentList = 0;
  1190. struct saAmfGroup *saAmfGroup = 0;
  1191. struct saAmfProtectionGroup *AmfProtectionGroup = 0;
  1192. struct saAmfComponent *AmfComponent = 0;
  1193. int found = 0;
  1194. /*
  1195. * Search all groups
  1196. */
  1197. for (AmfGroupList = saAmfGroupHead.next;
  1198. AmfGroupList != &saAmfGroupHead;
  1199. AmfGroupList = AmfGroupList->next) {
  1200. saAmfGroup = list_entry (AmfGroupList,
  1201. struct saAmfGroup, saAmfGroupList);
  1202. /*
  1203. * Search all protection groups
  1204. */
  1205. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  1206. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  1207. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  1208. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  1209. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  1210. if (SaNameTisNameT (csiName, &AmfProtectionGroup->name)) {
  1211. /*
  1212. * Search all components
  1213. */
  1214. for (AmfComponentList = AmfProtectionGroup->saAmfMembersHead.next;
  1215. AmfComponentList != &AmfProtectionGroup->saAmfMembersHead;
  1216. AmfComponentList = AmfComponentList->next) {
  1217. AmfComponent = list_entry (AmfComponentList,
  1218. struct saAmfComponent, saAmfProtectionGroupList);
  1219. if (SaNameTisNameT (compName, &AmfComponent->name)) {
  1220. found = 1;
  1221. }
  1222. }
  1223. }
  1224. }
  1225. }
  1226. if (found) {
  1227. return (AmfComponent);
  1228. } else {
  1229. return (0);
  1230. }
  1231. }
  1232. DECLARE_LIST_INIT (library_notification_send_listhead);
  1233. void sendProtectionGroupNotifications (
  1234. struct saAmfComponent *changedComponent,
  1235. SaAmfProtectionGroupChangesT changeToComponent)
  1236. {
  1237. int i;
  1238. struct conn_info *conn_info;
  1239. struct list_head *list;
  1240. log_printf (LOG_LEVEL_DEBUG, "sendProtectionGroupNotifications: sending PGs to API.\n");
  1241. /*
  1242. * Iterate all tracked connections
  1243. */
  1244. for (list = library_notification_send_listhead.next;
  1245. list != &library_notification_send_listhead;
  1246. list = list->next) {
  1247. conn_info = list_entry (list, struct conn_info, conn_list);
  1248. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  1249. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active) {
  1250. sendProtectionGroupNotification (conn_info,
  1251. conn_info->ais_ci.u.libamf_ci.tracks[i].notificationBufferAddress,
  1252. changedComponent->saAmfProtectionGroup,
  1253. changedComponent,
  1254. changeToComponent,
  1255. conn_info->ais_ci.u.libamf_ci.tracks[i].trackFlags);
  1256. } /* if track flags active */
  1257. } /* for all track entries */
  1258. } /* for all connection entries */
  1259. }
  1260. void sendProtectionGroupNotification (struct conn_info *conn_info,
  1261. SaAmfProtectionGroupNotificationT *notificationBufferAddress,
  1262. struct saAmfProtectionGroup *amfProtectionGroup,
  1263. struct saAmfComponent *changedComponent,
  1264. SaAmfProtectionGroupChangesT changeToComponent,
  1265. SaUint8T trackFlags)
  1266. {
  1267. struct res_lib_amf_protectiongrouptrackcallback res_lib_amf_protectiongrouptrackcallback;
  1268. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  1269. int notifyEntries = 0;
  1270. struct saAmfComponent *component;
  1271. struct list_head *componentList;
  1272. /*
  1273. * Step through all components and generate protection group list for csi
  1274. */
  1275. for (componentList = amfProtectionGroup->saAmfMembersHead.next;
  1276. componentList != &amfProtectionGroup->saAmfMembersHead;
  1277. componentList = componentList->next) {
  1278. component = list_entry (componentList,
  1279. struct saAmfComponent, saAmfProtectionGroupList);
  1280. /*
  1281. * Generate new track entry for following cases:
  1282. * 1. If this component is the changed component and
  1283. * SA_TRACK_CHANGES_ONLY is set
  1284. * 2. If track flags indicate SA_TRACK_CURRENT or SA_TRACK_CHANGES
  1285. */
  1286. if (component == changedComponent ||
  1287. (trackFlags & (SA_TRACK_CURRENT | SA_TRACK_CHANGES))) {
  1288. protectionGroupNotification = (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
  1289. sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
  1290. memcpy (&protectionGroupNotification[notifyEntries].member.compName,
  1291. &component->name, sizeof (SaNameT));
  1292. memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
  1293. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  1294. memcpy (&protectionGroupNotification[notifyEntries].member.haState,
  1295. &component->currentHAState, sizeof (SaAmfHAStateT));
  1296. if (component == changedComponent) {
  1297. protectionGroupNotification[notifyEntries].change = changeToComponent;
  1298. } else {
  1299. protectionGroupNotification[notifyEntries].change = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  1300. }
  1301. notifyEntries += 1;
  1302. }
  1303. } /* for */
  1304. /*
  1305. * Send track callback
  1306. */
  1307. if (notifyEntries) {
  1308. res_lib_amf_protectiongrouptrackcallback.header.size =
  1309. sizeof (struct res_lib_amf_protectiongrouptrackcallback) +
  1310. (notifyEntries * sizeof (SaAmfProtectionGroupNotificationT));
  1311. res_lib_amf_protectiongrouptrackcallback.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK;
  1312. res_lib_amf_protectiongrouptrackcallback.header.error = SA_OK;
  1313. res_lib_amf_protectiongrouptrackcallback.numberOfItems = notifyEntries;
  1314. res_lib_amf_protectiongrouptrackcallback.numberOfMembers = notifyEntries;
  1315. memcpy (&res_lib_amf_protectiongrouptrackcallback.csiName,
  1316. &amfProtectionGroup->name, sizeof (SaNameT));
  1317. res_lib_amf_protectiongrouptrackcallback.notificationBufferAddress = notificationBufferAddress;
  1318. libais_send_response (conn_info, &res_lib_amf_protectiongrouptrackcallback,
  1319. sizeof (struct res_lib_amf_protectiongrouptrackcallback));
  1320. libais_send_response (conn_info, protectionGroupNotification,
  1321. sizeof (SaAmfProtectionGroupNotificationT) * notifyEntries);
  1322. mempool_free (protectionGroupNotification);
  1323. }
  1324. }
  1325. /*
  1326. * The response handler for readiness state set callback
  1327. */
  1328. static void response_handler_readinessstatesetcallback (struct conn_info *conn_info,
  1329. struct req_amf_response *req_amf_response)
  1330. {
  1331. if (req_amf_response->error == SA_OK && conn_info->component) {
  1332. log_printf (LOG_LEVEL_DEBUG, "CALLBACK sending readiness state to %s\n",
  1333. getSaNameT (&conn_info->component->name));
  1334. readinessStateSetCluster (conn_info->component,
  1335. conn_info->component->newReadinessState);
  1336. }
  1337. }
  1338. /*
  1339. * iterate service unit components
  1340. * telling all components not already QUIESCING to enter SA_AMF_QUIESCED state
  1341. */
  1342. static void response_handler_csisetcallback (struct conn_info *conn_info,
  1343. struct req_amf_response *req_amf_response)
  1344. {
  1345. if (req_amf_response->error == SA_OK && conn_info->component) {
  1346. haStateSetCluster (conn_info->component,
  1347. conn_info->component->newHAState);
  1348. }
  1349. }
  1350. int amfExecutiveInitialize (void)
  1351. {
  1352. return (0);
  1353. }
  1354. int amf_exit_fn (struct conn_info *conn_info)
  1355. {
  1356. /*
  1357. * Unregister all components registered to this file descriptor
  1358. */
  1359. if (conn_info->service == SOCKET_SERVICE_AMF) {
  1360. componentUnregister (conn_info->component);
  1361. if (conn_info->component && conn_info->component->timer_healthcheck) {
  1362. poll_timer_delete (aisexec_poll_handle,
  1363. conn_info->component->timer_healthcheck);
  1364. conn_info->component->timer_healthcheck = 0;
  1365. }
  1366. if (conn_info->ais_ci.u.libamf_ci.tracks) {
  1367. mempool_free (conn_info->ais_ci.u.libamf_ci.tracks);
  1368. conn_info->ais_ci.u.libamf_ci.tracks = 0;
  1369. }
  1370. }
  1371. return (0);
  1372. }
  1373. static int message_handler_req_exec_amf_componentregister (void *message, struct in_addr source_addr)
  1374. {
  1375. struct req_exec_amf_componentregister *req_exec_amf_componentregister = (struct req_exec_amf_componentregister *)message;
  1376. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  1377. struct saAmfComponent *component;
  1378. struct saAmfComponent *amfProxyComponent;
  1379. SaErrorT error;
  1380. log_printf (LOG_LEVEL_DEBUG, "Executive: ComponentRegister for component %s\n",
  1381. getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName));
  1382. /*
  1383. * Determine if proxy isn't registered
  1384. */
  1385. error = SA_OK;
  1386. component = findComponent (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName);
  1387. amfProxyComponent = findComponent (&req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName);
  1388. /*
  1389. * If component not in configuration files, return error
  1390. */
  1391. if (component == 0) {
  1392. error = SA_ERR_NOT_EXIST;
  1393. }
  1394. /*
  1395. * If proxy doesn't exist and isn't registered, return error
  1396. */
  1397. if ((amfProxyComponent == 0 &&
  1398. req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) ||
  1399. (amfProxyComponent && amfProxyComponent->registered == 0)) {
  1400. error = SA_ERR_NOT_EXIST;
  1401. }
  1402. /*
  1403. * If component already registered, return error
  1404. */
  1405. if (error == SA_OK) {
  1406. if (component->registered) {
  1407. error = SA_ERR_EXIST;
  1408. }
  1409. }
  1410. /*
  1411. * Finally register component and setup links for proxy if
  1412. * proxy present
  1413. */
  1414. if (error == SA_OK) {
  1415. component->local = 0;
  1416. component->registered = 1;
  1417. component->conn_info = req_exec_amf_componentregister->source.conn_info;
  1418. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  1419. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  1420. component->currentHAState = SA_AMF_QUIESCED;
  1421. component->newHAState = SA_AMF_QUIESCED;
  1422. component->probableCause = 0;
  1423. component->enabledUnlockedState = 0;
  1424. component->disabledUnlockedState = 0;
  1425. if (req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) {
  1426. component->saAmfProxyComponent = amfProxyComponent;
  1427. }
  1428. }
  1429. /*
  1430. * If this node originated the request to the cluster, respond back
  1431. * to the AMF library
  1432. */
  1433. if (req_exec_amf_componentregister->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1434. if (error == SA_OK) {
  1435. component->local = 1;
  1436. req_exec_amf_componentregister->source.conn_info->component = component;
  1437. }
  1438. log_printf (LOG_LEVEL_DEBUG, "sending component register response to fd %d\n", req_exec_amf_componentregister->source.conn_info);
  1439. res_lib_amf_componentregister.header.size = sizeof (struct res_lib_amf_componentregister);
  1440. res_lib_amf_componentregister.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  1441. res_lib_amf_componentregister.header.error = error;
  1442. printf ("setting error to %d\n", error);
  1443. libais_send_response (req_exec_amf_componentregister->source.conn_info,
  1444. &res_lib_amf_componentregister,
  1445. sizeof (struct res_lib_amf_componentregister));
  1446. }
  1447. /*
  1448. * If no error on registration, determine if we should enter new state
  1449. */
  1450. if (error == SA_OK) {
  1451. dsm (component);
  1452. }
  1453. return (0);
  1454. }
  1455. static int message_handler_req_exec_amf_componentunregister (void *message, struct in_addr source_addr)
  1456. {
  1457. struct req_exec_amf_componentunregister *req_exec_amf_componentunregister = (struct req_exec_amf_componentunregister *)message;
  1458. struct res_lib_amf_componentunregister res_lib_amf_componentunregister;
  1459. struct saAmfComponent *component;
  1460. struct saAmfComponent *amfProxyComponent;
  1461. SaErrorT error;
  1462. log_printf (LOG_LEVEL_DEBUG, "Executive: ComponentUnregister for %s\n",
  1463. getSaNameT (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName));
  1464. component = findComponent (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName);
  1465. amfProxyComponent = findComponent (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName);
  1466. /*
  1467. * Check for proxy and component not existing in system
  1468. */
  1469. error = SA_OK;
  1470. if (component == 0) {
  1471. error = SA_ERR_NOT_EXIST;
  1472. }
  1473. if (req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName.length > 0) {
  1474. if (amfProxyComponent) {
  1475. if (amfProxyComponent->registered == 0) {
  1476. error = SA_ERR_NOT_EXIST;
  1477. }
  1478. } else {
  1479. error = SA_ERR_NOT_EXIST;
  1480. }
  1481. }
  1482. /*
  1483. * If there is a proxycompname, make sure it is the proxy
  1484. * of compName
  1485. */
  1486. if (error == SA_OK && amfProxyComponent) {
  1487. if (component->saAmfProxyComponent != amfProxyComponent) {
  1488. error = SA_ERR_BAD_OPERATION;
  1489. }
  1490. }
  1491. /*
  1492. * Finally unregister the component
  1493. */
  1494. if (error == SA_OK) {
  1495. component->registered = 0;
  1496. dsmEnabledUnlockedTransitionDisabledUnlocked (component);
  1497. }
  1498. /*
  1499. * If this node originated the request to the cluster, respond back
  1500. * to the AMF library
  1501. */
  1502. if (req_exec_amf_componentunregister->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1503. log_printf (LOG_LEVEL_DEBUG, "sending component unregister response to fd %d\n",
  1504. req_exec_amf_componentunregister->source.conn_info);
  1505. res_lib_amf_componentunregister.header.size = sizeof (struct res_lib_amf_componentunregister);
  1506. res_lib_amf_componentunregister.header.id = MESSAGE_RES_AMF_COMPONENTUNREGISTER;
  1507. res_lib_amf_componentunregister.header.error = error;
  1508. libais_send_response (req_exec_amf_componentunregister->source.conn_info,
  1509. &res_lib_amf_componentunregister, sizeof (struct res_lib_amf_componentunregister));
  1510. }
  1511. return (0);
  1512. }
  1513. static int message_handler_req_exec_amf_errorreport (void *message, struct in_addr source_addr)
  1514. {
  1515. struct req_exec_amf_errorreport *req_exec_amf_errorreport = (struct req_exec_amf_errorreport *)message;
  1516. struct res_lib_amf_errorreport res_lib_amf_errorreport;
  1517. struct saAmfComponent *component;
  1518. SaErrorT error = SA_ERR_BAD_OPERATION;
  1519. log_printf (LOG_LEVEL_DEBUG, "Executive: ErrorReport for %s\n",
  1520. getSaNameT (&req_exec_amf_errorreport->req_lib_amf_errorreport.erroneousComponent));
  1521. component = findComponent (&req_exec_amf_errorreport->req_lib_amf_errorreport.erroneousComponent);
  1522. if (component && component->registered) {
  1523. component->probableCause = req_exec_amf_errorreport->req_lib_amf_errorreport.errorDescriptor.probableCause;
  1524. /*
  1525. * One registered component left, so transition
  1526. * SU to failed operational state
  1527. */
  1528. dsmEnabledUnlockedTransitionDisabledUnlocked (component);
  1529. error = SA_OK;
  1530. }
  1531. /*
  1532. * If this node originated the request to the cluster, respond back
  1533. * to the AMF library
  1534. */
  1535. if (req_exec_amf_errorreport->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1536. log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n",
  1537. req_exec_amf_errorreport->source.conn_info);
  1538. res_lib_amf_errorreport.header.size = sizeof (struct res_lib_amf_errorreport);
  1539. res_lib_amf_errorreport.header.id = MESSAGE_RES_AMF_ERRORREPORT;
  1540. res_lib_amf_errorreport.header.error = error;
  1541. libais_send_response (req_exec_amf_errorreport->source.conn_info,
  1542. &res_lib_amf_errorreport, sizeof (struct res_lib_amf_errorreport));
  1543. }
  1544. return (0);
  1545. }
  1546. static int message_handler_req_exec_amf_errorcancelall (void *message, struct in_addr source_addr)
  1547. {
  1548. struct req_exec_amf_errorcancelall *req_exec_amf_errorcancelall = (struct req_exec_amf_errorcancelall *)message;
  1549. struct res_lib_amf_errorcancelall res_lib_amf_errorcancelall;
  1550. struct saAmfComponent *component;
  1551. SaErrorT error = SA_ERR_BAD_OPERATION;
  1552. log_printf (LOG_LEVEL_DEBUG, "Executive: ErrorCancelAll for %s\n",
  1553. getSaNameT (&req_exec_amf_errorcancelall->req_lib_amf_errorcancelall.compName));
  1554. component = findComponent (&req_exec_amf_errorcancelall->req_lib_amf_errorcancelall.compName);
  1555. if (component && component->registered) {
  1556. /*
  1557. * Mark component in service if its a AMF service
  1558. * connected to this aisexec
  1559. */
  1560. if (component->probableCause) {
  1561. component->probableCause = 0;
  1562. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1563. dsm (component);
  1564. }
  1565. error = SA_OK;
  1566. }
  1567. /*
  1568. * If this node originated the request to the cluster, respond back
  1569. * to the AMF library
  1570. */
  1571. if (req_exec_amf_errorcancelall->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1572. log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n",
  1573. req_exec_amf_errorcancelall->source.conn_info);
  1574. res_lib_amf_errorcancelall.header.size = sizeof (struct res_lib_amf_errorcancelall);
  1575. res_lib_amf_errorcancelall.header.id = MESSAGE_RES_AMF_ERRORCANCELALL;
  1576. res_lib_amf_errorcancelall.header.error = error;
  1577. libais_send_response (req_exec_amf_errorcancelall->source.conn_info,
  1578. &res_lib_amf_errorcancelall, sizeof (struct res_lib_amf_errorcancelall));
  1579. }
  1580. return (0);
  1581. }
  1582. /*
  1583. * If receiving this message from another cluster node, another cluster node
  1584. * has selected a readiness state for a component connected to _that_ cluster
  1585. * node. That cluster node API has verified the readiness state, so its time to let
  1586. * the rest of the cluster nodes know about the readiness state change.
  1587. */
  1588. static int message_handler_req_exec_amf_readinessstateset (void *message, struct in_addr source_addr)
  1589. {
  1590. struct req_exec_amf_readinessstateset *req_exec_amf_readinessstateset = (struct req_exec_amf_readinessstateset *)message;
  1591. struct saAmfComponent *component;
  1592. component = findComponent (&req_exec_amf_readinessstateset->compName);
  1593. if (component) {
  1594. log_printf (LOG_LEVEL_DEBUG, "found component %s, setting current readiness state to %d\n",
  1595. getSaNameT (&component->name),
  1596. req_exec_amf_readinessstateset->readinessState);
  1597. component->currentReadinessState = req_exec_amf_readinessstateset->readinessState;
  1598. dsm (component);
  1599. }
  1600. return (0);
  1601. }
  1602. /*
  1603. * If receiving this message from another cluster node, another cluster node
  1604. * has selected a ha state for a component connected to _that_ cluster
  1605. * node. That cluster node API has verified the ha state, so its time to let
  1606. * the rest of the cluster nodes know about the HA state change.
  1607. */
  1608. static int message_handler_req_exec_amf_hastateset (void *message, struct in_addr source_addr)
  1609. {
  1610. struct req_exec_amf_hastateset *req_exec_amf_hastateset = (struct req_exec_amf_hastateset *)message;
  1611. struct saAmfComponent *component;
  1612. component = findComponent (&req_exec_amf_hastateset->compName);
  1613. if (component) {
  1614. log_printf (LOG_LEVEL_DEBUG, "found component %s, setting current HA state to %d\n",
  1615. getSaNameT (&component->name),
  1616. req_exec_amf_hastateset->haState);
  1617. component->currentHAState = req_exec_amf_hastateset->haState;
  1618. dsm (component);
  1619. }
  1620. return (0);
  1621. }
  1622. static int message_handler_req_amf_init (struct conn_info *conn_info, void *message)
  1623. {
  1624. struct res_lib_init res_lib_init;
  1625. SaErrorT error = SA_ERR_SECURITY;
  1626. log_printf (LOG_LEVEL_DEBUG, "Got AMF request to initalize availability management framework service.\n");
  1627. if (conn_info->authenticated) {
  1628. conn_info->service = SOCKET_SERVICE_AMF;
  1629. error = SA_OK;
  1630. }
  1631. res_lib_init.header.size = sizeof (struct res_lib_init);
  1632. res_lib_init.header.id = MESSAGE_RES_INIT;
  1633. res_lib_init.header.error = error;
  1634. libais_send_response (conn_info, &res_lib_init, sizeof (res_lib_init));
  1635. list_init (&conn_info->conn_list);
  1636. if (conn_info->authenticated) {
  1637. return (0);
  1638. }
  1639. return (-1);
  1640. }
  1641. static int message_handler_req_lib_activatepoll (struct conn_info *conn_info, void *message)
  1642. {
  1643. struct res_lib_activatepoll res_lib_activatepoll;
  1644. res_lib_activatepoll.header.size = sizeof (struct res_lib_activatepoll);
  1645. res_lib_activatepoll.header.id = MESSAGE_RES_LIB_ACTIVATEPOLL;
  1646. libais_send_response (conn_info, &res_lib_activatepoll, sizeof (struct res_lib_activatepoll));
  1647. return (0);
  1648. }
  1649. static int message_handler_req_amf_componentregister (struct conn_info *conn_info, void *message)
  1650. {
  1651. struct req_amf_componentregister *req_lib_amf_componentregister = (struct req_amf_componentregister *)message;
  1652. struct req_exec_amf_componentregister req_exec_amf_componentregister;
  1653. struct iovec iovecs[2];
  1654. int result;
  1655. req_exec_amf_componentregister.header.size = sizeof (struct req_exec_amf_componentregister);
  1656. req_exec_amf_componentregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTREGISTER;
  1657. req_exec_amf_componentregister.source.conn_info = conn_info;
  1658. req_exec_amf_componentregister.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1659. memcpy (&req_exec_amf_componentregister.req_lib_amf_componentregister,
  1660. req_lib_amf_componentregister,
  1661. sizeof (struct req_lib_amf_componentregister));
  1662. iovecs[0].iov_base = (char *)&req_exec_amf_componentregister;
  1663. iovecs[0].iov_len = sizeof (req_exec_amf_componentregister);
  1664. result = gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1665. return (0);
  1666. }
  1667. static int message_handler_req_amf_componentunregister (struct conn_info *conn_info, void *message)
  1668. {
  1669. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  1670. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  1671. struct iovec iovecs[2];
  1672. int result;
  1673. struct saAmfComponent *component;
  1674. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  1675. req_exec_amf_componentunregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER;
  1676. req_exec_amf_componentunregister.source.conn_info = conn_info;
  1677. req_exec_amf_componentunregister.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1678. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  1679. req_lib_amf_componentunregister,
  1680. sizeof (struct req_lib_amf_componentunregister));
  1681. component = findComponent (&req_lib_amf_componentunregister->compName);
  1682. if (component && component->registered && component->local) {
  1683. component->probableCause = SA_AMF_NOT_RESPONDING;
  1684. }
  1685. iovecs[0].iov_base = (char *)&req_exec_amf_componentunregister;
  1686. iovecs[0].iov_len = sizeof (req_exec_amf_componentunregister);
  1687. result = gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1688. return (0);
  1689. }
  1690. static int message_handler_req_amf_readinessstateget (struct conn_info *conn_info, void *message)
  1691. {
  1692. struct req_amf_readinessstateget *req_amf_readinessstateget = (struct req_amf_readinessstateget *)message;
  1693. struct res_lib_amf_readinessstateget res_lib_amf_readinessstateget;
  1694. struct saAmfComponent *component;
  1695. log_printf (LOG_LEVEL_DEBUG, "got request to return readiness state\n");
  1696. res_lib_amf_readinessstateget.header.id = MESSAGE_RES_AMF_READINESSSTATEGET;
  1697. res_lib_amf_readinessstateget.header.size = sizeof (struct res_lib_amf_readinessstateget);
  1698. res_lib_amf_readinessstateget.header.error = SA_ERR_NOT_EXIST;
  1699. component = findComponent (&req_amf_readinessstateget->compName);
  1700. log_printf (LOG_LEVEL_DEBUG, "readinessstateget: found component %p\n", component);
  1701. if (component) {
  1702. memcpy (&res_lib_amf_readinessstateget.readinessState,
  1703. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  1704. res_lib_amf_readinessstateget.header.error = SA_OK;
  1705. }
  1706. libais_send_response (conn_info, &res_lib_amf_readinessstateget, sizeof (struct res_lib_amf_readinessstateget));
  1707. return (0);
  1708. }
  1709. static int message_handler_req_amf_hastateget (struct conn_info *conn_info, void *message)
  1710. {
  1711. struct req_amf_hastateget *req_amf_hastateget = (struct req_amf_hastateget *)message;
  1712. struct res_lib_amf_hastateget res_lib_amf_hastateget;
  1713. struct saAmfComponent *component;
  1714. res_lib_amf_hastateget.header.id = MESSAGE_RES_AMF_HASTATEGET;
  1715. res_lib_amf_hastateget.header.size = sizeof (struct res_lib_amf_hastateget);
  1716. res_lib_amf_hastateget.header.error = SA_ERR_NOT_EXIST;
  1717. component = findComponentInProtectionGroup (&req_amf_hastateget->csiName, &req_amf_hastateget->compName);
  1718. if (component) {
  1719. memcpy (&res_lib_amf_hastateget.haState,
  1720. &component->currentHAState, sizeof (SaAmfHAStateT));
  1721. res_lib_amf_hastateget.header.error = SA_OK;
  1722. }
  1723. libais_send_response (conn_info, &res_lib_amf_hastateget, sizeof (struct res_lib_amf_hastateget));
  1724. return (0);
  1725. }
  1726. static int message_handler_req_amf_protectiongrouptrackstart (struct conn_info *conn_info, void *message)
  1727. {
  1728. struct req_amf_protectiongrouptrackstart *req_amf_protectiongrouptrackstart = (struct req_amf_protectiongrouptrackstart *)message;
  1729. struct res_lib_amf_protectiongrouptrackstart res_lib_amf_protectiongrouptrackstart;
  1730. struct libamf_ci_trackentry *track = 0;
  1731. int i;
  1732. struct saAmfProtectionGroup *amfProtectionGroup;
  1733. amfProtectionGroup = findProtectionGroup (&req_amf_protectiongrouptrackstart->csiName);
  1734. if (amfProtectionGroup) {
  1735. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstart: Got valid track start on CSI: %s.\n", getSaNameT (&req_amf_protectiongrouptrackstart->csiName));
  1736. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  1737. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) {
  1738. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  1739. break;
  1740. }
  1741. }
  1742. if (track == 0) {
  1743. grow_amf_track_table (conn_info, 1);
  1744. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  1745. }
  1746. track->active = 1;
  1747. track->trackFlags = req_amf_protectiongrouptrackstart->trackFlags;
  1748. track->notificationBufferAddress = req_amf_protectiongrouptrackstart->notificationBufferAddress;
  1749. memcpy (&track->csiName,
  1750. &req_amf_protectiongrouptrackstart->csiName, sizeof (SaNameT));
  1751. conn_info->ais_ci.u.libamf_ci.trackActive += 1;
  1752. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  1753. /*
  1754. * If SA_TRACK_CURRENT is specified, write out all current connections
  1755. */
  1756. } else {
  1757. log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
  1758. }
  1759. res_lib_amf_protectiongrouptrackstart.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART;
  1760. res_lib_amf_protectiongrouptrackstart.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstart);
  1761. res_lib_amf_protectiongrouptrackstart.header.error = SA_ERR_NOT_EXIST;
  1762. if (amfProtectionGroup) {
  1763. res_lib_amf_protectiongrouptrackstart.header.error = SA_OK;
  1764. }
  1765. libais_send_response (conn_info, &res_lib_amf_protectiongrouptrackstart,
  1766. sizeof (struct res_lib_amf_protectiongrouptrackstart));
  1767. if (amfProtectionGroup &&
  1768. req_amf_protectiongrouptrackstart->trackFlags & SA_TRACK_CURRENT) {
  1769. sendProtectionGroupNotification (conn_info,
  1770. track->notificationBufferAddress,
  1771. amfProtectionGroup,
  1772. 0,
  1773. 0,
  1774. track->trackFlags);
  1775. track->trackFlags &= ~SA_TRACK_CURRENT;
  1776. }
  1777. return (0);
  1778. }
  1779. static int message_handler_req_amf_protectiongrouptrackstop (struct conn_info *conn_info, void *message)
  1780. {
  1781. struct req_amf_protectiongrouptrackstop *req_amf_protectiongrouptrackstop = (struct req_amf_protectiongrouptrackstop *)message;
  1782. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  1783. struct libamf_ci_trackentry *track = 0;
  1784. int i;
  1785. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  1786. if (SaNameTisNameT (&req_amf_protectiongrouptrackstop->csiName,
  1787. &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) {
  1788. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  1789. }
  1790. }
  1791. if (track) {
  1792. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_amf_protectiongrouptrackstop->csiName));
  1793. memset (track, 0, sizeof (struct libamf_ci_trackentry));
  1794. conn_info->ais_ci.u.libamf_ci.trackActive -= 1;
  1795. if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) {
  1796. list_del (&conn_info->conn_list);
  1797. }
  1798. }
  1799. res_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
  1800. res_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstop);
  1801. res_lib_amf_protectiongrouptrackstop.header.error = SA_ERR_NOT_EXIST;
  1802. if (track) {
  1803. res_lib_amf_protectiongrouptrackstop.header.error = SA_OK;
  1804. }
  1805. libais_send_response (conn_info, &res_lib_amf_protectiongrouptrackstop,
  1806. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  1807. return (0);
  1808. }
  1809. static int message_handler_req_amf_errorreport (struct conn_info *conn_info, void *message)
  1810. {
  1811. struct req_lib_amf_errorreport *req_lib_amf_errorreport = (struct req_lib_amf_errorreport *)message;
  1812. struct req_exec_amf_errorreport req_exec_amf_errorreport;
  1813. struct iovec iovecs[2];
  1814. int result;
  1815. req_exec_amf_errorreport.header.size = sizeof (struct req_exec_amf_errorreport);
  1816. req_exec_amf_errorreport.header.id = MESSAGE_REQ_EXEC_AMF_ERRORREPORT;
  1817. req_exec_amf_errorreport.source.conn_info = conn_info;
  1818. req_exec_amf_errorreport.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1819. memcpy (&req_exec_amf_errorreport.req_lib_amf_errorreport,
  1820. req_lib_amf_errorreport,
  1821. sizeof (struct req_lib_amf_errorreport));
  1822. iovecs[0].iov_base = (char *)&req_exec_amf_errorreport;
  1823. iovecs[0].iov_len = sizeof (req_exec_amf_errorreport);
  1824. // iovecs[0].iov_len = sizeof (req_exec_amf_errorreport) - sizeof (req_lib_amf_errorreport);
  1825. // iovecs[1].iov_base = (char *)&req_lib_amf_errorreport;
  1826. // iovecs[1].iov_len = sizeof (req_lib_amf_errorreport);
  1827. result = gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1828. return (0);
  1829. }
  1830. static int message_handler_req_amf_errorcancelall (struct conn_info *conn_info, void *message)
  1831. {
  1832. struct req_lib_amf_errorcancelall *req_lib_amf_errorcancelall = (struct req_lib_amf_errorcancelall *)message;
  1833. struct req_exec_amf_errorcancelall req_exec_amf_errorcancelall;
  1834. struct iovec iovecs[2];
  1835. int result;
  1836. req_exec_amf_errorcancelall.header.size = sizeof (struct req_exec_amf_errorcancelall);
  1837. req_exec_amf_errorcancelall.header.id = MESSAGE_REQ_EXEC_AMF_ERRORCANCELALL;
  1838. req_exec_amf_errorcancelall.source.conn_info = conn_info;
  1839. req_exec_amf_errorcancelall.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1840. memcpy (&req_exec_amf_errorcancelall.req_lib_amf_errorcancelall,
  1841. req_lib_amf_errorcancelall,
  1842. sizeof (struct req_lib_amf_errorcancelall));
  1843. iovecs[0].iov_base = (char *)&req_exec_amf_errorcancelall;
  1844. iovecs[0].iov_len = sizeof (req_exec_amf_errorcancelall);
  1845. // iovecs[0].iov_len = sizeof (req_exec_amf_errorcancelall) - sizeof (req_lib_amf_errorcancelall);
  1846. // iovecs[1].iov_base = (char *)&req_lib_amf_errorcancelall;
  1847. // iovecs[1].iov_len = sizeof (req_lib_amf_errorcancelall);
  1848. result = gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1849. return (0);
  1850. }
  1851. static int message_handler_req_amf_stoppingcomplete (struct conn_info *conn_info_notused,
  1852. void *message)
  1853. {
  1854. struct req_amf_stoppingcomplete *req_amf_stoppingcomplete = (struct req_amf_stoppingcomplete *)message;
  1855. struct conn_info *inv_conn_info;
  1856. int interface;
  1857. log_printf (LOG_LEVEL_DEBUG, "handling stopping complete\n");
  1858. req_amf_invocation_get_and_destroy (req_amf_stoppingcomplete->invocation,
  1859. &interface, &inv_conn_info);
  1860. inv_conn_info->component->currentReadinessState = inv_conn_info->component->newReadinessState;
  1861. readinessStateSetCluster (inv_conn_info->component, SA_AMF_STOPPING);
  1862. sendProtectionGroupNotifications (inv_conn_info->component,
  1863. SA_AMF_PROTECTION_GROUP_STATE_CHANGE);
  1864. return (0);
  1865. }
  1866. void response_handler_healthcheckcallback (struct conn_info *conn_info,
  1867. struct req_amf_response *req_amf_response) {
  1868. if (req_amf_response->error == SA_OK) {
  1869. log_printf (LOG_LEVEL_DEBUG, "setting healthcheck ok\n");
  1870. conn_info->component->healthcheck_outstanding = 0;
  1871. }
  1872. }
  1873. static int message_handler_req_amf_response (struct conn_info *conn_info_nouse, void *message)
  1874. {
  1875. struct req_amf_response *req_amf_response = (struct req_amf_response *)message;
  1876. struct conn_info *conn_info;
  1877. int interface;
  1878. int res;
  1879. res = req_amf_invocation_get_and_destroy (req_amf_response->invocation,
  1880. &interface, &conn_info);
  1881. log_printf (LOG_LEVEL_DEBUG, "handling response connection %x interface %x\n", conn_info, interface);
  1882. switch (interface) {
  1883. case MESSAGE_REQ_AMF_RESPONSE_SAAMFHEALTHCHECKCALLBACK:
  1884. response_handler_healthcheckcallback (conn_info, req_amf_response);
  1885. break;
  1886. case MESSAGE_REQ_AMF_RESPONSE_SAAMFREADINESSSTATESETCALLBACK:
  1887. response_handler_readinessstatesetcallback (conn_info, req_amf_response);
  1888. break;
  1889. case MESSAGE_REQ_AMF_RESPONSE_SAAMFCSISETCALLBACK:
  1890. response_handler_csisetcallback (conn_info, req_amf_response);
  1891. break;
  1892. case MESSAGE_REQ_AMF_RESPONSE_SAAMFCSIREMOVECALLBACK:
  1893. break;
  1894. default:
  1895. // TODO
  1896. log_printf (LOG_LEVEL_ERROR, "invalid invocation value %x\n", req_amf_response->invocation);
  1897. break;
  1898. }
  1899. return (0);
  1900. }
  1901. static int message_handler_req_amf_componentcapabilitymodelget (struct conn_info *conn_info, void *message)
  1902. {
  1903. struct req_amf_componentcapabilitymodelget *req_amf_componentcapabilitymodelget = (struct req_amf_componentcapabilitymodelget *)message;
  1904. struct res_lib_amf_componentcapabilitymodelget res_lib_amf_componentcapabilitymodelget;
  1905. struct saAmfComponent *component;
  1906. SaErrorT error = SA_OK;
  1907. log_printf (LOG_LEVEL_DEBUG, "componentcapabilitymodelget: Retrieve name %s.\n", getSaNameT (&req_amf_componentcapabilitymodelget->compName));
  1908. component = findComponent (&req_amf_componentcapabilitymodelget->compName);
  1909. if (component && component->registered) {
  1910. memcpy (&res_lib_amf_componentcapabilitymodelget.componentCapabilityModel,
  1911. &component->componentCapabilityModel, sizeof (SaAmfComponentCapabilityModelT));
  1912. } else {
  1913. error = SA_ERR_NOT_EXIST;
  1914. }
  1915. res_lib_amf_componentcapabilitymodelget.header.size = sizeof (struct res_lib_amf_componentcapabilitymodelget);
  1916. res_lib_amf_componentcapabilitymodelget.header.id = MESSAGE_RES_AMF_COMPONENTCAPABILITYMODELGET;
  1917. res_lib_amf_componentcapabilitymodelget.header.error = error;
  1918. libais_send_response (conn_info, &res_lib_amf_componentcapabilitymodelget,
  1919. sizeof (struct res_lib_amf_componentcapabilitymodelget));
  1920. return (0);
  1921. }