amf.c 74 KB

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