amf.c 74 KB

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