amf.c 95 KB

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