amf.c 94 KB

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