amf.c 95 KB

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