amf.c 100 KB

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