amf.c 99 KB

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