amf.c 93 KB

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