amf.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271
  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/socket.h>
  36. #include <sys/un.h>
  37. #include <sys/sysinfo.h>
  38. #include <netinet/in.h>
  39. #include <linux/if.h>
  40. #include <linux/sockios.h>
  41. #include <unistd.h>
  42. #include <fcntl.h>
  43. #include <stdlib.h>
  44. #include <stdio.h>
  45. #include <errno.h>
  46. #include <signal.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 "parse.h"
  55. #include "main.h"
  56. #include "print.h"
  57. #include "handlers.h"
  58. struct invocation {
  59. struct conn_info *conn_info;
  60. int interface;
  61. int active;
  62. };
  63. struct invocation *invocation_entries = 0;
  64. int invocation_entries_size = 0;
  65. #ifdef INPARSEDOTH
  66. enum amfOperationalState {
  67. AMF_OPER_DISABLED,
  68. AMF_OPER_ENABLED
  69. };
  70. enum amfAdministrativeState {
  71. AMF_ADMIN_UNLOCKED,
  72. AMF_ADMIN_LOCKED,
  73. AMF_ADMIN_STOPPING
  74. };
  75. enum amfOperationalAdministrativeState {
  76. AMF_ENABLED_UNLOCKED,
  77. AMF_DISABLED_UNLOCKED,
  78. AMF_DISABLED_LOCKED,
  79. AMF_ENABLED_STOPPING
  80. };
  81. /*
  82. * State machines for states in AMF
  83. */
  84. enum amfEnabledUnlockedState {
  85. AMF_ENABLED_UNLOCKED_INITIAL,
  86. AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED,
  87. AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED,
  88. AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED,
  89. AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED,
  90. AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED,
  91. AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED,
  92. };
  93. enum amfDisabledUnlockedState {
  94. AMF_DISABLED_UNLOCKED_INITIAL,
  95. AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED,
  96. AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED,
  97. AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED,
  98. AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED
  99. };
  100. enum amfDisabledLockedState {
  101. AMF_DISABLED_LOCKED_INITIAL,
  102. AMF_DISABLED_LOCKED_QUIESCED_REQUESTED,
  103. AMF_DISABLED_LOCKED_QUIESCED_COMPLETED,
  104. AMF_DISABLED_LOCKED_OUT_OF_SERVICE_REQUESTED
  105. AMF_DISABLED_LOCKED_OUT_OF_SERVICE_COMPLETED,
  106. };
  107. enum amfEnabledStoppingState {
  108. AMF_ENABLED_STOPPING_INITIAL,
  109. AMF_ENABLED_STOPPING_STOPPING_REQUESTED,
  110. AMF_ENABLED_STOPPING_STOPPING_COMPLETED,
  111. };
  112. /*
  113. * Internal Functions
  114. */
  115. static void componentOutOfServiceSetNoApi (
  116. struct saAmfComponent *component);
  117. #endif
  118. static void grow_amf_track_table (
  119. struct conn_info *conn_info,
  120. int growby);
  121. static void sendProtectionGroupNotification (
  122. struct conn_info *conn_info,
  123. SaAmfProtectionGroupNotificationT *notificationBufferAddress,
  124. struct saAmfProtectionGroup *amfProtectionGroup,
  125. struct saAmfComponent *changedComponent,
  126. SaAmfProtectionGroupChangesT changeToComponent,
  127. SaUint8T trackFlags);
  128. static int activeServiceUnitsCount (
  129. struct saAmfGroup *saAmfGroup);
  130. #ifdef COMPILE_OUT
  131. static void enumerateComponents (
  132. void (*function)(struct saAmfComponent *, void *data),
  133. void *data);
  134. static void CSIRemove (
  135. struct conn_info *conn_info);
  136. static void haStateSetClusterInit (
  137. struct conn_info *conn_info,
  138. struct saAmfComponent *saAmfComponent);
  139. #endif
  140. static void haStateSetCluster (
  141. struct saAmfComponent *saAmfComponent,
  142. SaAmfHAStateT haState);
  143. static void readinessStateSetApi (
  144. struct saAmfComponent *component,
  145. SaAmfReadinessStateT readinessState);
  146. #ifdef COMPILE_OUT
  147. static void readinessStateSetClusterInit (
  148. struct conn_info *conn_info,
  149. struct saAmfComponent *saAmfComponent);
  150. #endif
  151. static void readinessStateSetCluster (
  152. struct saAmfComponent *saAmfComponent,
  153. SaAmfReadinessStateT readinessState);
  154. #ifdef COMPILE_OUT
  155. static void enumerateComponentsClusterInit (
  156. struct saAmfComponent *component,
  157. void *data);
  158. #endif
  159. static void dsm (
  160. struct saAmfComponent *saAmfComponent);
  161. #if 0 /* NOT IMPLEMENTED */
  162. static void componentTerminate (
  163. struct conn_info *conn_info);
  164. #endif
  165. static void timer_function_libamf_healthcheck (
  166. void *data);
  167. static struct saAmfProtectionGroup *findProtectionGroup (
  168. SaNameT *csiName);
  169. static struct saAmfComponent *findComponentInProtectionGroup (
  170. SaNameT *csiName,
  171. SaNameT *compName);
  172. static void sendProtectionGroupNotifications (
  173. struct saAmfComponent *changedComponent,
  174. SaAmfProtectionGroupChangesT changeToComponent);
  175. static void sendProtectionGroupNotification (
  176. struct conn_info *conn_info,
  177. SaAmfProtectionGroupNotificationT *notificationBufferAddress,
  178. struct saAmfProtectionGroup *amfProtectionGroup,
  179. struct saAmfComponent *changedComponent,
  180. SaAmfProtectionGroupChangesT changeToComponent,
  181. SaUint8T trackFlags);
  182. static void response_handler_readinessstatesetcallback (
  183. struct conn_info *conn_info,
  184. struct req_amf_response *req_amf_response);
  185. static void response_handler_csisetcallback (
  186. struct conn_info *conn_info,
  187. struct req_amf_response *req_amf_response);
  188. static int amf_exit_fn (struct conn_info *conn_info);
  189. static int amfExecutiveInitialize (void);
  190. static int message_handler_req_exec_amf_componentregister (void *message);
  191. static int message_handler_req_exec_amf_componentunregister (void *message);
  192. static int message_handler_req_exec_amf_errorreport (void *message);
  193. static int message_handler_req_exec_amf_errorcancelall (void *message);
  194. static int message_handler_req_exec_amf_readinessstateset (void *message);
  195. static int message_handler_req_exec_amf_hastateset (void *message);
  196. static int message_handler_req_amf_init (struct conn_info *conn_info, void *message);
  197. static int message_handler_req_lib_activatepoll (struct conn_info *conn_info, void *message);
  198. static int message_handler_req_amf_componentregister (struct conn_info *conn_info, void *message);
  199. static int message_handler_req_amf_componentunregister (struct conn_info *conn_info, void *message);
  200. static int message_handler_req_amf_readinessstateget (struct conn_info *conn_info, void *message);
  201. static int message_handler_req_amf_hastateget (struct conn_info *conn_info, void *message);
  202. static int message_handler_req_amf_protectiongrouptrackstart (struct conn_info *conn_info, void *message);
  203. static int message_handler_req_amf_protectiongrouptrackstop (struct conn_info *conn_info, void *message);
  204. static int message_handler_req_amf_errorreport (struct conn_info *conn_info, void *message);
  205. static int message_handler_req_amf_errorcancelall (struct conn_info *conn_info, void *message);
  206. static int message_handler_req_amf_stoppingcomplete (struct conn_info *conn_info, void *message);
  207. static int message_handler_req_amf_response (struct conn_info *conn_info, void *message);
  208. static int message_handler_req_amf_componentcapabilitymodelget (struct conn_info *conn_info, void *message);
  209. int (*amf_libais_handler_fns[]) (struct conn_info *conn_info, void *) = {
  210. message_handler_req_lib_activatepoll,
  211. message_handler_req_amf_componentregister,
  212. message_handler_req_amf_componentunregister,
  213. message_handler_req_amf_readinessstateget,
  214. message_handler_req_amf_hastateget,
  215. message_handler_req_amf_protectiongrouptrackstart,
  216. message_handler_req_amf_protectiongrouptrackstop,
  217. message_handler_req_amf_errorreport,
  218. message_handler_req_amf_errorcancelall,
  219. message_handler_req_amf_stoppingcomplete,
  220. message_handler_req_amf_response,
  221. message_handler_req_amf_componentcapabilitymodelget
  222. };
  223. int (*amf_aisexec_handler_fns[]) (void *) = {
  224. message_handler_req_exec_amf_componentregister,
  225. message_handler_req_exec_amf_componentunregister,
  226. message_handler_req_exec_amf_errorreport,
  227. message_handler_req_exec_amf_errorcancelall,
  228. message_handler_req_exec_amf_readinessstateset,
  229. message_handler_req_exec_amf_hastateset,
  230. };
  231. /*
  232. * Exports the interface for the service
  233. */
  234. struct service_handler amf_service_handler = {
  235. libais_handler_fns: amf_libais_handler_fns,
  236. libais_handler_fns_count: sizeof (amf_libais_handler_fns) / sizeof (int (*)),
  237. aisexec_handler_fns: amf_aisexec_handler_fns,
  238. aisexec_handler_fns_count: sizeof (amf_aisexec_handler_fns) / sizeof (int (*)),
  239. confchg_fn: 0,
  240. libais_init_fn: message_handler_req_amf_init,
  241. libais_exit_fn: amf_exit_fn,
  242. aisexec_init_fn: amfExecutiveInitialize
  243. };
  244. static void grow_amf_track_table (struct conn_info *conn_info, int growby)
  245. {
  246. struct libamf_ci_trackentry *tracks;
  247. int newsize;
  248. int currsize = conn_info->ais_ci.u.libamf_ci.trackEntries;
  249. newsize = growby + currsize;
  250. if (newsize > currsize) {
  251. tracks = (struct libamf_ci_trackentry *)mempool_realloc (conn_info->ais_ci.u.libamf_ci.tracks,
  252. (newsize) * sizeof (struct libamf_ci_trackentry));
  253. if (tracks == 0) {
  254. #ifdef DEBUG
  255. printf ("grow_amf_track_table: out of memory, woops\n");
  256. #endif
  257. // TODO
  258. exit (1);
  259. }
  260. memset (&tracks[currsize], 0, growby * sizeof (struct libamf_ci_trackentry));
  261. conn_info->ais_ci.u.libamf_ci.trackEntries = newsize;
  262. conn_info->ais_ci.u.libamf_ci.tracks = tracks;
  263. }
  264. }
  265. int req_amf_invocation_create (int interface,
  266. struct conn_info *conn_info)
  267. {
  268. struct invocation *invocation_addr = 0;
  269. struct invocation *invocation_temp;
  270. int i;
  271. int loc;
  272. for (i = 0; i < invocation_entries_size; i++) {
  273. if (invocation_entries[i].active == 0) {
  274. invocation_addr = &invocation_entries[i];
  275. loc = i;
  276. break;
  277. }
  278. }
  279. if (invocation_addr == 0) {
  280. invocation_temp = (struct invocation *)realloc (invocation_entries,
  281. (invocation_entries_size + 1) * sizeof (struct invocation));
  282. if (invocation_temp == 0) {
  283. return (-1);
  284. }
  285. invocation_entries = invocation_temp;
  286. invocation_addr = &invocation_entries[invocation_entries_size];
  287. loc = invocation_entries_size;
  288. invocation_entries_size += 1;
  289. }
  290. invocation_addr->interface = interface;
  291. invocation_addr->conn_info = conn_info;
  292. invocation_addr->active = 1;
  293. return (loc);
  294. }
  295. int req_amf_invocation_get_and_destroy (int invocation, int *interface,
  296. struct conn_info **conn_info)
  297. {
  298. if (invocation > invocation_entries_size) {
  299. printf ("a\n");
  300. return (-1);
  301. }
  302. if (invocation_entries[invocation].active == 0) {
  303. printf ("b\n");
  304. return (-1);
  305. }
  306. *interface = invocation_entries[invocation].interface;
  307. *conn_info = invocation_entries[invocation].conn_info;
  308. memset (&invocation_entries[invocation], 0, sizeof (struct invocation));
  309. return (0);
  310. }
  311. void componentUnregister (
  312. struct saAmfComponent *component)
  313. {
  314. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  315. struct iovec iovecs[2];
  316. /*
  317. * This only works on local components
  318. */
  319. if (component == 0 || component->local != 1) {
  320. return;
  321. }
  322. log_printf (LOG_LEVEL_DEBUG, "componentUnregister: unregistering component %s\n",
  323. getSaNameT (&component->name));
  324. component->probableCause = SA_AMF_NOT_RESPONDING;
  325. req_exec_amf_componentunregister.header.magic = MESSAGE_MAGIC;
  326. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  327. req_exec_amf_componentunregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER;
  328. req_exec_amf_componentunregister.source.conn_info = 0;
  329. req_exec_amf_componentunregister.source.in_addr.s_addr = 0;
  330. memset (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  331. 0, sizeof (struct req_lib_amf_componentunregister));
  332. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister.compName,
  333. &component->name,
  334. sizeof (SaNameT));
  335. iovecs[0].iov_base = &req_exec_amf_componentunregister;
  336. iovecs[0].iov_len = sizeof (req_exec_amf_componentunregister);
  337. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  338. }
  339. #ifdef COMPILE_OUT
  340. This should be used for a partition I think
  341. // This should be used for partition changes
  342. void enumerateComponents (
  343. void (*function)(struct saAmfComponent *, void *data),
  344. void *data)
  345. {
  346. struct list_head *AmfGroupList;
  347. struct list_head *AmfUnitList;
  348. struct list_head *AmfComponentList;
  349. struct saAmfGroup *saAmfGroup;
  350. struct saAmfUnit *AmfUnit;
  351. struct saAmfComponent *AmfComponent;
  352. /*
  353. * Search all groups
  354. */
  355. for (AmfGroupList = saAmfGroupHead.next;
  356. AmfGroupList != &saAmfGroupHead;
  357. AmfGroupList = AmfGroupList->next) {
  358. saAmfGroup = list_entry (AmfGroupList,
  359. struct saAmfGroup, saAmfGroupList);
  360. /*
  361. * Search all units
  362. */
  363. for (AmfUnitList = saAmfGroup->saAmfUnitHead.next;
  364. AmfUnitList != &saAmfGroup->saAmfUnitHead;
  365. AmfUnitList = AmfUnitList->next) {
  366. AmfUnit = list_entry (AmfUnitList,
  367. struct saAmfUnit, saAmfUnitList);
  368. /*
  369. * Search all components
  370. */
  371. for (AmfComponentList = AmfUnit->saAmfComponentHead.next;
  372. AmfComponentList != &AmfUnit->saAmfComponentHead;
  373. AmfComponentList = AmfComponentList->next) {
  374. AmfComponent = list_entry (AmfComponentList,
  375. struct saAmfComponent, saAmfComponentList);
  376. function (AmfComponent, data);
  377. }
  378. }
  379. }
  380. }
  381. #endif
  382. int activeServiceUnitsCount (struct saAmfGroup *saAmfGroup) {
  383. struct saAmfUnit *saAmfUnit;
  384. struct saAmfComponent *saAmfComponent;
  385. struct list_head *saAmfComponentList;
  386. struct list_head *saAmfUnitList;
  387. int activeServiceUnits = 0;
  388. int thisServiceUnitActive;
  389. /*
  390. * Search all units
  391. */
  392. for (activeServiceUnits = 0, saAmfUnitList = saAmfGroup->saAmfUnitHead.next;
  393. saAmfUnitList != &saAmfGroup->saAmfUnitHead;
  394. saAmfUnitList = saAmfUnitList->next) {
  395. saAmfUnit = list_entry (saAmfUnitList,
  396. struct saAmfUnit, saAmfUnitList);
  397. /*
  398. * Search all components
  399. */
  400. for (thisServiceUnitActive = 1, saAmfComponentList = saAmfUnit->saAmfComponentHead.next;
  401. saAmfComponentList != &saAmfUnit->saAmfComponentHead;
  402. saAmfComponentList = saAmfComponentList->next) {
  403. saAmfComponent = list_entry (saAmfComponentList,
  404. struct saAmfComponent, saAmfComponentList);
  405. if (saAmfComponent->currentHAState != SA_AMF_ACTIVE) {
  406. thisServiceUnitActive = 0;
  407. }
  408. }
  409. /*
  410. * If all components are active in service unit, count service unit as active
  411. */
  412. if (thisServiceUnitActive) {
  413. activeServiceUnits += 1;
  414. }
  415. }
  416. return (activeServiceUnits);
  417. }
  418. #ifdef CONFIG_TODO
  419. This should be sent after a service unit is made out of service
  420. void CSIRemove (struct conn_info *conn_info)
  421. {
  422. struct res_amf_csiremovecallback res_amf_csiremovecallback;
  423. if (conn_info->active == 0 ||
  424. conn_info->service != SOCKET_SERVICE_AMF) {
  425. return;
  426. }
  427. log_printf (LOG_NOTICE_DEBUG, "executing CSI remove callback into API\n");
  428. res_amf_csiremovecallback.header.magic = MESSAGE_MAGIC;
  429. res_amf_csiremovecallback.header.id = MESSAGE_RES_AMF_CSIREMOVECALLBACK;
  430. res_amf_csiremovecallback.header.size = sizeof (struct res_amf_csiremovecallback);
  431. res_amf_csiremovecallback.invocation =
  432. req_amf_response_set (
  433. MESSAGE_REQ_AMF_RESPONSE_SAAMFCSIREMOVECALLBACK,
  434. conn_info->fd);
  435. memcpy (&res_amf_csiremovecallback.compName,
  436. &conn_info->component->name, sizeof (SaNameT));
  437. memcpy (&res_amf_csiremovecallback.csiName,
  438. &conn_info->component->saAmfProtectionGroup->name, sizeof (SaNameT));
  439. res_amf_csiremovecallback.csiFlags = SA_AMF_CSI_ALL_INSTANCES;
  440. libais_send_response (conn_info, &res_amf_csiremovecallback,
  441. sizeof (struct res_amf_csiremovecallback));
  442. }
  443. #endif
  444. void haStateSetApi (struct saAmfComponent *component, SaAmfHAStateT haState)
  445. {
  446. struct res_amf_csisetcallback res_amf_csisetcallback;
  447. log_printf (LOG_LEVEL_DEBUG, "sending ha state to API\n");
  448. if (component->local != 1) {
  449. return;
  450. }
  451. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  452. return;
  453. }
  454. /*
  455. * this should be an assertion
  456. */
  457. if (component->conn_info->active == 0 ||
  458. component->conn_info->service != SOCKET_SERVICE_AMF) {
  459. return;
  460. }
  461. res_amf_csisetcallback.header.magic = MESSAGE_MAGIC;
  462. res_amf_csisetcallback.header.id = MESSAGE_RES_AMF_CSISETCALLBACK;
  463. res_amf_csisetcallback.header.size = sizeof (struct res_amf_csisetcallback);
  464. res_amf_csisetcallback.invocation =
  465. req_amf_invocation_create (
  466. MESSAGE_REQ_AMF_RESPONSE_SAAMFCSISETCALLBACK,
  467. component->conn_info);
  468. if (res_amf_csisetcallback.invocation == -1) {
  469. printf ("TODO set callback\n");
  470. }
  471. memcpy (&res_amf_csisetcallback.compName,
  472. &component->name, sizeof (SaNameT));
  473. memcpy (&res_amf_csisetcallback.csiName,
  474. &component->saAmfProtectionGroup->name, sizeof (SaNameT));
  475. res_amf_csisetcallback.csiFlags = SA_AMF_CSI_ALL_INSTANCES;
  476. res_amf_csisetcallback.haState = haState;
  477. // TODO set activeCompName to correct component name
  478. memcpy (&res_amf_csisetcallback.activeCompName,
  479. &component->name, sizeof (SaNameT));
  480. res_amf_csisetcallback.transitionDescriptor = SA_AMF_CSI_NEW_ASSIGN;
  481. component->newHAState = haState;
  482. libais_send_response (component->conn_info, &res_amf_csisetcallback,
  483. sizeof (struct res_amf_csisetcallback));
  484. }
  485. #ifdef COMPILE_OUT
  486. void haStateSetClusterInit (
  487. struct conn_info *conn_info,
  488. struct saAmfComponent *saAmfComponent)
  489. {
  490. struct req_exec_amf_hastatesetcluster req_exec_amf_hastatesetcluster;
  491. return;
  492. req_exec_amf_hastatesetcluster.header.magic = MESSAGE_MAGIC;
  493. req_exec_amf_hastatesetcluster.header.id = MESSAGE_REQ_EXEC_AMF_HASTATESET;
  494. req_exec_amf_hastatesetcluster.header.size = sizeof (struct req_exec_amf_hastatesetcluster);
  495. memcpy (&req_exec_amf_hastatesetcluster.compName,
  496. &saAmfComponent->name, sizeof (SaNameT));
  497. req_exec_amf_hastatesetcluster.haState = saAmfComponent->currentHAState;
  498. log_printf (LOG_LEVEL_DEBUG, "Sending init ha state message to cluster node to set ha state of component %s\n", getSaNameT (&saAmfComponent->name));
  499. log_printf (LOG_LEVEL_DEBUG, "ha state is %d\n", saAmfComponent->currentHAState);
  500. libais_send_response (conn_info, &req_exec_amf_hastatesetcluster,
  501. sizeof (struct req_exec_amf_hastatesetcluster));
  502. }
  503. #endif
  504. void haStateSetCluster (
  505. struct saAmfComponent *component,
  506. SaAmfHAStateT haState)
  507. {
  508. struct req_exec_amf_hastateset req_exec_amf_hastateset;
  509. struct iovec iovecs[2];
  510. req_exec_amf_hastateset.header.magic = MESSAGE_MAGIC;
  511. req_exec_amf_hastateset.header.id = MESSAGE_REQ_EXEC_AMF_HASTATESET;
  512. req_exec_amf_hastateset.header.size = sizeof (struct req_exec_amf_hastateset);
  513. memcpy (&req_exec_amf_hastateset.compName, &component->name, sizeof (SaNameT));
  514. req_exec_amf_hastateset.haState = haState;
  515. log_printf (LOG_LEVEL_DEBUG, "Sending ha state to cluster for component %s\n", getSaNameT (&component->name));
  516. log_printf (LOG_LEVEL_DEBUG, "ha state is %d\n", haState);
  517. iovecs[0].iov_base = &req_exec_amf_hastateset;
  518. iovecs[0].iov_len = sizeof (req_exec_amf_hastateset);
  519. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  520. }
  521. void readinessStateSetApi (struct saAmfComponent *component,
  522. SaAmfReadinessStateT readinessState)
  523. {
  524. struct res_amf_readinessstatesetcallback res_amf_readinessstatesetcallback;
  525. /*
  526. * If component is local, don't request service from API
  527. */
  528. if (component->local != 1) {
  529. return;
  530. }
  531. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  532. return;
  533. }
  534. /*
  535. * this should be an assertion
  536. */
  537. if (component->conn_info->active == 0 ||
  538. component->conn_info->service != SOCKET_SERVICE_AMF) {
  539. return;
  540. }
  541. res_amf_readinessstatesetcallback.header.magic = MESSAGE_MAGIC;
  542. res_amf_readinessstatesetcallback.header.id = MESSAGE_RES_AMF_READINESSSTATESETCALLBACK;
  543. res_amf_readinessstatesetcallback.header.size = sizeof (struct res_amf_readinessstatesetcallback);
  544. res_amf_readinessstatesetcallback.invocation =
  545. req_amf_invocation_create (
  546. MESSAGE_REQ_AMF_RESPONSE_SAAMFREADINESSSTATESETCALLBACK,
  547. component->conn_info);
  548. if (res_amf_readinessstatesetcallback.invocation == -1) {
  549. printf ("TODO readiness set callback\n");
  550. }
  551. memcpy (&res_amf_readinessstatesetcallback.compName,
  552. &component->name, sizeof (SaNameT));
  553. res_amf_readinessstatesetcallback.readinessState = readinessState;
  554. component->newReadinessState = readinessState;
  555. log_printf (LOG_LEVEL_DEBUG, "Setting conn_info %x to readiness state %d\n", component->conn_info, readinessState);
  556. libais_send_response (component->conn_info, &res_amf_readinessstatesetcallback,
  557. sizeof (struct res_amf_readinessstatesetcallback));
  558. }
  559. #ifdef COMPILE_OUT
  560. void readinessStateSetClusterInit (
  561. struct conn_info *conn_info,
  562. struct saAmfComponent *saAmfComponent)
  563. {
  564. struct req_exec_amf_readinessstatesetcluster req_exec_amf_readinessstatesetcluster;
  565. return;
  566. req_exec_amf_readinessstatesetcluster.header.magic = MESSAGE_MAGIC;
  567. req_exec_amf_readinessstatesetcluster.header.id = MESSAGE_REQ_EXEC_AMF_READINESSSTATESET;
  568. req_exec_amf_readinessstatesetcluster.header.size = sizeof (struct req_exec_amf_readinessstateset);
  569. memcpy (&req_exec_amf_readinessstatesetcluster.compName,
  570. &saAmfComponent->name, sizeof (SaNameT));
  571. req_exec_amf_readinessstatesetcluster.readinessState = saAmfComponent->currentReadinessState;
  572. log_printf (LOG_LEVEL_DEBUG, "Sending init message to one cluster node to set readiness state of component %s\n", getSaNameT (&saAmfComponent->name));
  573. log_printf (LOG_LEVEL_DEBUG, "readiness state is %d\n", saAmfComponent->currentReadinessState);
  574. libais_send_response (conn_info, &req_exec_amf_readinessstatesetcluster,
  575. sizeof (struct req_exec_amf_readinessstatesetcluster));
  576. }
  577. #endif
  578. void readinessStateSetCluster (
  579. struct saAmfComponent *component,
  580. SaAmfReadinessStateT readinessState)
  581. {
  582. struct req_exec_amf_readinessstateset req_exec_amf_readinessstateset;
  583. struct iovec iovecs[2];
  584. req_exec_amf_readinessstateset.header.magic = MESSAGE_MAGIC;
  585. req_exec_amf_readinessstateset.header.id = MESSAGE_REQ_EXEC_AMF_READINESSSTATESET;
  586. req_exec_amf_readinessstateset.header.size = sizeof (struct req_exec_amf_readinessstateset);
  587. memcpy (&req_exec_amf_readinessstateset.compName, &component->name, sizeof (SaNameT));
  588. req_exec_amf_readinessstateset.readinessState = readinessState;
  589. log_printf (LOG_LEVEL_DEBUG, "Sending message to all cluster nodes to set readiness state of component %s\n",
  590. getSaNameT (&component->name));
  591. log_printf (LOG_LEVEL_DEBUG, "readiness state is %d\n", readinessState);
  592. iovecs[0].iov_base = &req_exec_amf_readinessstateset;
  593. iovecs[0].iov_len = sizeof (req_exec_amf_readinessstateset);
  594. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  595. }
  596. #ifdef CMOPILE_OUT
  597. void enumerateComponentsClusterInit (
  598. struct saAmfComponent *component,
  599. void *data)
  600. {
  601. struct conn_info *conn_info = (int)data;
  602. return;
  603. readinessStateSetClusterInit (fd, component);
  604. haStateSetClusterInit (fd, component);
  605. }
  606. #endif
  607. static void dsmDisabledUnlockedRegisteredOrErrorCancel (
  608. struct saAmfComponent *component)
  609. {
  610. struct saAmfUnit *unit;
  611. struct list_head *list;
  612. int serviceUnitEnabled;
  613. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedRegisteredOrErrorCancel for %s\n",
  614. getSaNameT (&component->name));
  615. unit = component->saAmfUnit;
  616. for (serviceUnitEnabled = 1, list = unit->saAmfComponentHead.next;
  617. list != &unit->saAmfComponentHead;
  618. list = list->next) {
  619. component = list_entry (list,
  620. struct saAmfComponent, saAmfComponentList);
  621. if (component->registered == 0 ||
  622. component->probableCause) {
  623. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not registered or failed.\n", getSaNameT (&component->name));
  624. serviceUnitEnabled = 0;
  625. break;
  626. }
  627. }
  628. if (serviceUnitEnabled == 1) {
  629. log_printf (LOG_LEVEL_DEBUG, "dsm entering AMF_ENABLED_UNLOCKED state.\n");
  630. component->saAmfUnit->operationalAdministrativeState = AMF_ENABLED_UNLOCKED;
  631. component->disabledUnlockedState = -1; // SHOULD BE INVALID
  632. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  633. dsm (component);
  634. }
  635. }
  636. static void dsmDisabledUnlockedFailed (
  637. struct saAmfComponent *component)
  638. {
  639. struct saAmfUnit *unit;
  640. struct list_head *list;
  641. unit = component->saAmfUnit;
  642. for (list = unit->saAmfComponentHead.next;
  643. list != &unit->saAmfComponentHead;
  644. list = list->next) {
  645. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  646. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedFailed: for %s.\n",
  647. getSaNameT (&component->name));
  648. switch (component->enabledUnlockedState) {
  649. case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED:
  650. case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED:
  651. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  652. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  653. readinessStateSetCluster (component, SA_AMF_OUT_OF_SERVICE);
  654. } else {
  655. readinessStateSetApi (component, SA_AMF_OUT_OF_SERVICE);
  656. }
  657. break;
  658. case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED:
  659. case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED:
  660. case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED:
  661. case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED:
  662. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  663. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  664. haStateSetCluster (component, SA_AMF_QUIESCED);
  665. } else {
  666. haStateSetApi (component, SA_AMF_QUIESCED);
  667. }
  668. poll_timer_delete (aisexec_poll_handle,
  669. component->timer_healthcheck);
  670. component->timer_healthcheck = 0;
  671. break;
  672. default:
  673. log_printf (LOG_LEVEL_DEBUG, "invalid case 5 %d\n", component->enabledUnlockedState);
  674. break;
  675. }
  676. }
  677. }
  678. static void dsmDisabledUnlockedQuiescedRequested (
  679. struct saAmfComponent *component)
  680. {
  681. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED;
  682. dsm (component);
  683. }
  684. static void dsmDisabledUnlockedQuiescedCompleted (
  685. struct saAmfComponent *component)
  686. {
  687. struct saAmfUnit *unit;
  688. struct list_head *list;
  689. int serviceUnitQuiesced;
  690. unit = component->saAmfUnit;
  691. for (serviceUnitQuiesced = 1, list = unit->saAmfComponentHead.next;
  692. list != &unit->saAmfComponentHead;
  693. list = list->next) {
  694. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  695. if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) {
  696. if (component->currentHAState != SA_AMF_QUIESCED) {
  697. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n", getSaNameT (&component->name));
  698. serviceUnitQuiesced = 0;
  699. break;
  700. }
  701. }
  702. }
  703. if (serviceUnitQuiesced == 1) {
  704. log_printf (LOG_LEVEL_DEBUG, "All components have quiesced, Quiescing completed\n");
  705. for (list = unit->saAmfComponentHead.next;
  706. list != &unit->saAmfComponentHead;
  707. list = list->next) {
  708. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  709. log_printf (LOG_LEVEL_DEBUG, "dsm: Sending readiness state set to OUTOFSERVICE for comp %s.\n",
  710. getSaNameT (&component->name));
  711. readinessStateSetApi (component, SA_AMF_OUT_OF_SERVICE);
  712. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  713. }
  714. }
  715. }
  716. static void dsmDisabledUnlockedOutOfServiceRequested (
  717. struct saAmfComponent *component)
  718. {
  719. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED;
  720. dsm (component);
  721. }
  722. static void dsmDisabledUnlockedOutOfServiceCompleted (
  723. struct saAmfComponent *component)
  724. {
  725. struct saAmfUnit *unit;
  726. struct list_head *list;
  727. int serviceUnitOutOfService;
  728. struct saAmfGroup *group = 0;
  729. struct list_head *comp_list = 0;
  730. struct list_head *unit_list = 0;
  731. int serviceUnitInStandby = 0;
  732. /*
  733. * Once all components of a service unit are out of service,
  734. * activate another service unit in standby
  735. */
  736. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedOutOfServiceCompleted: component out of service %s\n", getSaNameT (&component->name));
  737. /*
  738. * Determine if all components have responded to going out of service
  739. */
  740. unit = component->saAmfUnit;
  741. for (serviceUnitOutOfService = 1, list = unit->saAmfComponentHead.next;
  742. list != &unit->saAmfComponentHead;
  743. list = list->next) {
  744. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  745. if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) {
  746. if (component->currentReadinessState != SA_AMF_OUT_OF_SERVICE) {
  747. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n", getSaNameT (&component->name));
  748. serviceUnitOutOfService = 0;
  749. break;
  750. }
  751. }
  752. }
  753. group = unit->saAmfGroup;
  754. if (serviceUnitOutOfService == 1) {
  755. log_printf (LOG_LEVEL_DEBUG, "SU has gone out of service.\n");
  756. /*
  757. * Search all units
  758. */
  759. for (unit_list = group->saAmfUnitHead.next;
  760. unit_list != &group->saAmfUnitHead;
  761. unit_list = unit_list->next) {
  762. unit = list_entry (unit_list,
  763. struct saAmfUnit, saAmfUnitList);
  764. log_printf (LOG_LEVEL_DEBUG, "Checking if service unit is in standby %s\n", getSaNameT (&unit->name));
  765. /*
  766. * Search all components
  767. */
  768. for (serviceUnitInStandby = 1,
  769. comp_list = unit->saAmfComponentHead.next;
  770. comp_list != &unit->saAmfComponentHead;
  771. comp_list = comp_list->next) {
  772. component = list_entry (comp_list,
  773. struct saAmfComponent, saAmfComponentList);
  774. if (component->currentHAState != SA_AMF_STANDBY) {
  775. serviceUnitInStandby = 0;
  776. break; /* for iteration of service unit components */
  777. }
  778. }
  779. if (serviceUnitInStandby) {
  780. break; /* for iteration of service group's service units */
  781. }
  782. }
  783. /*
  784. * All components in service unit are standby, activate standby service unit
  785. */
  786. if (serviceUnitInStandby) {
  787. log_printf (LOG_LEVEL_DEBUG, "unit in standby\n");
  788. for (list = unit->saAmfComponentHead.next;
  789. list != &unit->saAmfComponentHead;
  790. list = list->next) {
  791. component = list_entry (list,
  792. struct saAmfComponent, saAmfComponentList);
  793. haStateSetApi (component, SA_AMF_ACTIVE);
  794. }
  795. } else {
  796. log_printf (LOG_LEVEL_DEBUG, "Can't activate standby service unit because no standby is available.\n");
  797. }
  798. }
  799. }
  800. static void dsmEnabledUnlockedInitial (
  801. struct saAmfComponent *component)
  802. {
  803. struct saAmfUnit *unit;
  804. struct list_head *list;
  805. unit = component->saAmfUnit;
  806. for (list = unit->saAmfComponentHead.next;
  807. list != &unit->saAmfComponentHead;
  808. list = list->next) {
  809. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  810. readinessStateSetApi (component, SA_AMF_IN_SERVICE);
  811. log_printf (LOG_LEVEL_DEBUG, "dsm: telling component %s to enter SA_AMF_IN_SERVICE.\n",
  812. getSaNameT (&component->name));
  813. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED;
  814. }
  815. }
  816. static void dsmEnabledUnlockedInServiceRequested (
  817. struct saAmfComponent *component)
  818. {
  819. struct saAmfUnit *unit;
  820. struct list_head *list;
  821. int in_service;
  822. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceRequested %s.\n", getSaNameT (&component->name));
  823. unit = component->saAmfUnit;
  824. for (in_service = 1, list = unit->saAmfComponentHead.next;
  825. list != &unit->saAmfComponentHead;
  826. list = list->next) {
  827. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  828. if (component->currentReadinessState != SA_AMF_IN_SERVICE) {
  829. log_printf (LOG_LEVEL_DEBUG, "dsm: Found atleast one component not in service\n");
  830. in_service = 0;
  831. break;
  832. }
  833. }
  834. if (in_service) {
  835. log_printf (LOG_LEVEL_DEBUG, "DSM determined component is in service\n");
  836. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED;
  837. dsm (component);
  838. }
  839. }
  840. static void dsmEnabledUnlockedInServiceCompleted (
  841. struct saAmfComponent *component)
  842. {
  843. struct saAmfUnit *unit;
  844. struct list_head *list;
  845. SaAmfHAStateT newHaState;
  846. int activeServiceUnits;
  847. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceCompleted %s.\n", getSaNameT (&component->name));
  848. unit = component->saAmfUnit;
  849. for (list = unit->saAmfComponentHead.next;
  850. list != &unit->saAmfComponentHead;
  851. list = list->next) {
  852. component = list_entry (list,
  853. struct saAmfComponent, saAmfComponentList);
  854. log_printf (LOG_LEVEL_DEBUG, "Requesting component go active.\n", getSaNameT (&component->name));
  855. /*
  856. * Count number of active service units
  857. */
  858. activeServiceUnits = activeServiceUnitsCount (component->saAmfUnit->saAmfGroup);
  859. if (activeServiceUnits < component->saAmfUnit->saAmfGroup->saAmfActiveUnitsDesired) {
  860. newHaState = SA_AMF_ACTIVE;
  861. log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_ACTIVE\n", getSaNameT (&component->name));
  862. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED;
  863. } else {
  864. newHaState = SA_AMF_STANDBY;
  865. log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_STANDBY\n", getSaNameT (&component->name));
  866. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED;
  867. }
  868. haStateSetApi (component, newHaState);
  869. }
  870. }
  871. void dsmEnabledUnlockedActiveRequested (
  872. struct saAmfComponent *component)
  873. {
  874. if (component->local == 1) {
  875. log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer\n");
  876. poll_timer_add (aisexec_poll_handle,
  877. component->healthcheckInterval,
  878. (void *)component->conn_info,
  879. timer_function_libamf_healthcheck,
  880. &component->timer_healthcheck);
  881. }
  882. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED;
  883. }
  884. void dsmEnabledUnlockedStandbyRequested (
  885. struct saAmfComponent *component)
  886. {
  887. if (component->local == 1) {
  888. log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer\n");
  889. poll_timer_add (aisexec_poll_handle,
  890. component->healthcheckInterval,
  891. (void *)component->conn_info,
  892. timer_function_libamf_healthcheck,
  893. &component->timer_healthcheck);
  894. }
  895. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED;
  896. }
  897. void dsmEnabledUnlockedTransitionDisabledUnlocked (
  898. struct saAmfComponent *component)
  899. {
  900. struct saAmfUnit *unit;
  901. struct list_head *list;
  902. unit = component->saAmfUnit;
  903. for (list = unit->saAmfComponentHead.next;
  904. list != &unit->saAmfComponentHead;
  905. list = list->next) {
  906. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  907. log_printf (LOG_LEVEL_DEBUG, "Requesting component %s transition to disabled.\n",
  908. getSaNameT (&component->name));
  909. component->saAmfUnit->operationalAdministrativeState = AMF_DISABLED_UNLOCKED;
  910. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_FAILED;
  911. }
  912. dsm (component);
  913. }
  914. static void dsmEnabledUnlocked (
  915. struct saAmfComponent *component)
  916. {
  917. switch (component->enabledUnlockedState) {
  918. case AMF_ENABLED_UNLOCKED_INITIAL:
  919. dsmEnabledUnlockedInitial (component);
  920. break;
  921. case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED:
  922. dsmEnabledUnlockedInServiceRequested (component);
  923. break;
  924. case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED:
  925. dsmEnabledUnlockedInServiceCompleted (component);
  926. break;
  927. case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED:
  928. dsmEnabledUnlockedActiveRequested (component);
  929. break;
  930. case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED:
  931. /* noop - operational state */
  932. break;
  933. case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED:
  934. dsmEnabledUnlockedActiveRequested (component);
  935. break;
  936. case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED:
  937. /* noop - operational state */
  938. break;
  939. default:
  940. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlocked: unkown state machine value.\n");
  941. }
  942. }
  943. static void dsmDisabledUnlocked (
  944. struct saAmfComponent *component)
  945. {
  946. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked for %s state %d\n",
  947. getSaNameT (&component->name),
  948. component->disabledUnlockedState);
  949. switch (component->disabledUnlockedState) {
  950. case AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL:
  951. dsmDisabledUnlockedRegisteredOrErrorCancel (component);
  952. break;
  953. case AMF_DISABLED_UNLOCKED_FAILED:
  954. dsmDisabledUnlockedFailed (component);
  955. break;
  956. case AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED:
  957. dsmDisabledUnlockedQuiescedRequested (component);
  958. break;
  959. case AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED:
  960. dsmDisabledUnlockedQuiescedCompleted (component);
  961. break;
  962. case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED:
  963. dsmDisabledUnlockedOutOfServiceRequested (component);
  964. break;
  965. case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED:
  966. dsmDisabledUnlockedOutOfServiceCompleted (component);
  967. break;
  968. default:
  969. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked: unkown state machine value %d.\n", component->disabledUnlockedState);
  970. }
  971. }
  972. static void dsm (
  973. struct saAmfComponent *component)
  974. {
  975. log_printf (LOG_LEVEL_DEBUG, "dsm for component %s\n", getSaNameT (&component->name));
  976. switch (component->saAmfUnit->operationalAdministrativeState) {
  977. case AMF_DISABLED_UNLOCKED:
  978. dsmDisabledUnlocked (component);
  979. break;
  980. case AMF_ENABLED_UNLOCKED:
  981. dsmEnabledUnlocked (component);
  982. break;
  983. /*
  984. AMF_DISABLED_LOCKED,
  985. AMF_ENABLED_STOPPING
  986. */
  987. default:
  988. log_printf (LOG_LEVEL_DEBUG, "dsm: unknown state machine value.\n");
  989. }
  990. }
  991. #if 0
  992. /*
  993. * This is currently unused, but executes the componentterminatecallback
  994. * callback in the AMF api.
  995. */
  996. void componentTerminate (struct conn_info *conn_info)
  997. {
  998. struct res_amf_componentterminatecallback res_amf_componentterminatecallback;
  999. res_amf_componentterminatecallback.header.magic = MESSAGE_MAGIC;
  1000. res_amf_componentterminatecallback.header.id = MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK;
  1001. res_amf_componentterminatecallback.header.size = sizeof (struct res_amf_componentterminatecallback);
  1002. res_amf_componentterminatecallback.invocation =
  1003. req_amf_response_set (
  1004. MESSAGE_REQ_AMF_RESPONSE_SAAMFCOMPONENTTERMINATECALLBACK,
  1005. fd);
  1006. memcpy (&res_amf_componentterminatecallback.compName,
  1007. &connections[fd].component->name, sizeof (SaNameT));
  1008. connections[fd].component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  1009. log_printf (LOG_LEVEL_DEBUG, "terminating component on fd %d\n", fd);
  1010. libais_send_response (fd, &res_amf_componentterminatecallback,
  1011. sizeof (struct res_amf_componentterminatecallback));
  1012. }
  1013. #endif /* Not currently implemented */
  1014. void errorReport (
  1015. struct saAmfComponent *component,
  1016. SaAmfProbableCauseT probableCause)
  1017. {
  1018. struct req_exec_amf_errorreport req_exec_amf_errorreport;
  1019. struct iovec iovecs[2];
  1020. req_exec_amf_errorreport.header.magic = MESSAGE_MAGIC;
  1021. req_exec_amf_errorreport.header.size = sizeof (struct req_exec_amf_errorreport);
  1022. req_exec_amf_errorreport.header.id = MESSAGE_REQ_EXEC_AMF_ERRORREPORT;
  1023. req_exec_amf_errorreport.source.conn_info = 0;
  1024. req_exec_amf_errorreport.source.in_addr.s_addr = 0;
  1025. memcpy (&req_exec_amf_errorreport.req_lib_amf_errorreport.erroneousComponent,
  1026. &component->name,
  1027. sizeof (SaNameT));
  1028. req_exec_amf_errorreport.req_lib_amf_errorreport.errorDescriptor.probableCause = probableCause;
  1029. iovecs[0].iov_base = &req_exec_amf_errorreport;
  1030. iovecs[0].iov_len = sizeof (req_exec_amf_errorreport);
  1031. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1032. }
  1033. int healthcheck_instance = 0;
  1034. void timer_function_libamf_healthcheck (void *data) {
  1035. struct res_amf_healthcheckcallback res_amf_healthcheckcallback;
  1036. struct conn_info *conn_info = (struct conn_info *)data;
  1037. res_amf_healthcheckcallback.header.magic = MESSAGE_MAGIC;
  1038. res_amf_healthcheckcallback.header.id = MESSAGE_RES_AMF_HEALTHCHECKCALLBACK;
  1039. res_amf_healthcheckcallback.header.size = sizeof (struct res_amf_healthcheckcallback);
  1040. log_printf (LOG_LEVEL_DEBUG, "checking healthcheck on component %s\n",
  1041. getSaNameT (&conn_info->component->name));
  1042. if (conn_info->component->healthcheck_outstanding == 1) {
  1043. log_printf (LOG_LEVEL_DEBUG, "Healthcheck timed out on component %s\n",
  1044. getSaNameT (&conn_info->component->name));
  1045. /*
  1046. * Report the error to the rest of the cluster using the normal state machine
  1047. */
  1048. errorReport (conn_info->component, SA_AMF_NOT_RESPONDING);
  1049. conn_info->component->healthcheck_outstanding = 2;
  1050. } else
  1051. if (conn_info->component->healthcheck_outstanding == 0) {
  1052. conn_info->component->healthcheck_outstanding = 1;
  1053. /*
  1054. * Send healthcheck message
  1055. */
  1056. res_amf_healthcheckcallback.invocation =
  1057. req_amf_invocation_create (
  1058. MESSAGE_REQ_AMF_RESPONSE_SAAMFHEALTHCHECKCALLBACK,
  1059. conn_info);
  1060. if (res_amf_healthcheckcallback.invocation == -1) {
  1061. printf ("TODO healthcheck set callback\n");
  1062. }
  1063. memcpy (&res_amf_healthcheckcallback.compName,
  1064. &conn_info->component->name,
  1065. sizeof (SaNameT));
  1066. res_amf_healthcheckcallback.checkType = SA_AMF_HEARTBEAT;
  1067. log_printf (LOG_LEVEL_DEBUG, "Sending instance %d\n", healthcheck_instance);
  1068. res_amf_healthcheckcallback.instance = healthcheck_instance++;
  1069. libais_send_response (conn_info,
  1070. &res_amf_healthcheckcallback,
  1071. sizeof (struct res_amf_healthcheckcallback));
  1072. poll_timer_add (aisexec_poll_handle,
  1073. conn_info->component->healthcheckInterval,
  1074. (void *)conn_info,
  1075. timer_function_libamf_healthcheck,
  1076. &conn_info->component->timer_healthcheck);
  1077. }
  1078. }
  1079. struct saAmfProtectionGroup *findProtectionGroup (
  1080. SaNameT *csiName)
  1081. {
  1082. struct list_head *AmfGroupList;
  1083. struct list_head *AmfProtectionGroupList;
  1084. struct saAmfGroup *saAmfGroup;
  1085. struct saAmfProtectionGroup *AmfProtectionGroup;
  1086. /*
  1087. * Search all groups
  1088. */
  1089. for (AmfGroupList = saAmfGroupHead.next;
  1090. AmfGroupList != &saAmfGroupHead;
  1091. AmfGroupList = AmfGroupList->next) {
  1092. saAmfGroup = list_entry (AmfGroupList,
  1093. struct saAmfGroup, saAmfGroupList);
  1094. /*
  1095. * Search all protection groups
  1096. */
  1097. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  1098. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  1099. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  1100. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  1101. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  1102. if (SaNameTisNameT (csiName, &AmfProtectionGroup->name)) {
  1103. return (AmfProtectionGroup);
  1104. }
  1105. }
  1106. }
  1107. return (0);
  1108. }
  1109. struct saAmfComponent *findComponentInProtectionGroup (
  1110. SaNameT *csiName,
  1111. SaNameT *compName)
  1112. {
  1113. struct list_head *AmfGroupList = 0;
  1114. struct list_head *AmfProtectionGroupList = 0;
  1115. struct list_head *AmfComponentList = 0;
  1116. struct saAmfGroup *saAmfGroup = 0;
  1117. struct saAmfProtectionGroup *AmfProtectionGroup = 0;
  1118. struct saAmfComponent *AmfComponent = 0;
  1119. int found = 0;
  1120. /*
  1121. * Search all groups
  1122. */
  1123. for (AmfGroupList = saAmfGroupHead.next;
  1124. AmfGroupList != &saAmfGroupHead;
  1125. AmfGroupList = AmfGroupList->next) {
  1126. saAmfGroup = list_entry (AmfGroupList,
  1127. struct saAmfGroup, saAmfGroupList);
  1128. /*
  1129. * Search all protection groups
  1130. */
  1131. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  1132. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  1133. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  1134. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  1135. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  1136. if (SaNameTisNameT (csiName, &AmfProtectionGroup->name)) {
  1137. /*
  1138. * Search all components
  1139. */
  1140. for (AmfComponentList = AmfProtectionGroup->saAmfMembersHead.next;
  1141. AmfComponentList != &AmfProtectionGroup->saAmfMembersHead;
  1142. AmfComponentList = AmfComponentList->next) {
  1143. AmfComponent = list_entry (AmfComponentList,
  1144. struct saAmfComponent, saAmfProtectionGroupList);
  1145. if (SaNameTisNameT (compName, &AmfComponent->name)) {
  1146. found = 1;
  1147. }
  1148. }
  1149. }
  1150. }
  1151. }
  1152. if (found) {
  1153. return (AmfComponent);
  1154. } else {
  1155. return (0);
  1156. }
  1157. }
  1158. DECLARE_LIST_INIT (library_notification_send_listhead);
  1159. void sendProtectionGroupNotifications (
  1160. struct saAmfComponent *changedComponent,
  1161. SaAmfProtectionGroupChangesT changeToComponent)
  1162. {
  1163. int i;
  1164. struct conn_info *conn_info;
  1165. struct list_head *list;
  1166. log_printf (LOG_LEVEL_DEBUG, "sendProtectionGroupNotifications: sending PGs to API.\n");
  1167. /*
  1168. * Iterate all tracked connections
  1169. */
  1170. for (list = library_notification_send_listhead.next;
  1171. list != &library_notification_send_listhead;
  1172. list = list->next) {
  1173. conn_info = list_entry (list, struct conn_info, conn_list);
  1174. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  1175. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active) {
  1176. sendProtectionGroupNotification (conn_info,
  1177. conn_info->ais_ci.u.libamf_ci.tracks[i].notificationBufferAddress,
  1178. changedComponent->saAmfProtectionGroup,
  1179. changedComponent,
  1180. changeToComponent,
  1181. conn_info->ais_ci.u.libamf_ci.tracks[i].trackFlags);
  1182. } /* if track flags active */
  1183. } /* for all track entries */
  1184. } /* for all connection entries */
  1185. }
  1186. void sendProtectionGroupNotification (struct conn_info *conn_info,
  1187. SaAmfProtectionGroupNotificationT *notificationBufferAddress,
  1188. struct saAmfProtectionGroup *amfProtectionGroup,
  1189. struct saAmfComponent *changedComponent,
  1190. SaAmfProtectionGroupChangesT changeToComponent,
  1191. SaUint8T trackFlags)
  1192. {
  1193. struct res_amf_protectiongrouptrackcallback res_amf_protectiongrouptrackcallback;
  1194. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  1195. int notifyEntries = 0;
  1196. struct saAmfComponent *component;
  1197. struct list_head *componentList;
  1198. /*
  1199. * Step through all components and generate protection group list for csi
  1200. */
  1201. for (componentList = amfProtectionGroup->saAmfMembersHead.next;
  1202. componentList != &amfProtectionGroup->saAmfMembersHead;
  1203. componentList = componentList->next) {
  1204. component = list_entry (componentList,
  1205. struct saAmfComponent, saAmfProtectionGroupList);
  1206. /*
  1207. * Generate new track entry for following cases:
  1208. * 1. If this component is the changed component and
  1209. * SA_TRACK_CHANGES_ONLY is set
  1210. * 2. If track flags indicate SA_TRACK_CURRENT or SA_TRACK_CHANGES
  1211. */
  1212. if (component == changedComponent ||
  1213. (trackFlags & (SA_TRACK_CURRENT | SA_TRACK_CHANGES))) {
  1214. protectionGroupNotification = (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
  1215. sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
  1216. memcpy (&protectionGroupNotification[notifyEntries].member.compName,
  1217. &component->name, sizeof (SaNameT));
  1218. memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
  1219. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  1220. memcpy (&protectionGroupNotification[notifyEntries].member.haState,
  1221. &component->currentHAState, sizeof (SaAmfHAStateT));
  1222. if (component == changedComponent) {
  1223. protectionGroupNotification[notifyEntries].change = changeToComponent;
  1224. } else {
  1225. protectionGroupNotification[notifyEntries].change = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  1226. }
  1227. notifyEntries += 1;
  1228. }
  1229. } /* for */
  1230. /*
  1231. * Send track callback
  1232. */
  1233. if (notifyEntries) {
  1234. res_amf_protectiongrouptrackcallback.header.magic = MESSAGE_MAGIC;
  1235. res_amf_protectiongrouptrackcallback.header.size =
  1236. sizeof (struct res_amf_protectiongrouptrackcallback) +
  1237. (notifyEntries * sizeof (SaAmfProtectionGroupNotificationT));
  1238. res_amf_protectiongrouptrackcallback.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK;
  1239. res_amf_protectiongrouptrackcallback.numberOfItems = notifyEntries;
  1240. res_amf_protectiongrouptrackcallback.numberOfMembers = notifyEntries;
  1241. memcpy (&res_amf_protectiongrouptrackcallback.csiName,
  1242. &amfProtectionGroup->name, sizeof (SaNameT));
  1243. res_amf_protectiongrouptrackcallback.notificationBufferAddress = notificationBufferAddress;
  1244. libais_send_response (conn_info, &res_amf_protectiongrouptrackcallback,
  1245. sizeof (struct res_amf_protectiongrouptrackcallback));
  1246. libais_send_response (conn_info, protectionGroupNotification,
  1247. sizeof (SaAmfProtectionGroupNotificationT) * notifyEntries);
  1248. mempool_free (protectionGroupNotification);
  1249. }
  1250. }
  1251. /*
  1252. * The response handler for readiness state set callback
  1253. */
  1254. static void response_handler_readinessstatesetcallback (struct conn_info *conn_info,
  1255. struct req_amf_response *req_amf_response)
  1256. {
  1257. if (req_amf_response->error == SA_OK && conn_info->component) {
  1258. log_printf (LOG_LEVEL_DEBUG, "CALLBACK sending readiness state to %s\n",
  1259. getSaNameT (&conn_info->component->name));
  1260. readinessStateSetCluster (conn_info->component,
  1261. conn_info->component->newReadinessState);
  1262. }
  1263. }
  1264. /*
  1265. * iterate service unit components
  1266. * telling all components not already QUIESCING to enter SA_AMF_QUIESCED state
  1267. */
  1268. static void response_handler_csisetcallback (struct conn_info *conn_info,
  1269. struct req_amf_response *req_amf_response)
  1270. {
  1271. if (req_amf_response->error == SA_OK && conn_info->component) {
  1272. haStateSetCluster (conn_info->component,
  1273. conn_info->component->newHAState);
  1274. }
  1275. }
  1276. int amfExecutiveInitialize (void)
  1277. {
  1278. return (0);
  1279. }
  1280. int amf_exit_fn (struct conn_info *conn_info)
  1281. {
  1282. /*
  1283. * Unregister all components registered to this file descriptor
  1284. */
  1285. if (conn_info->service == SOCKET_SERVICE_AMF) {
  1286. componentUnregister (conn_info->component);
  1287. if (conn_info->component && conn_info->component->timer_healthcheck) {
  1288. poll_timer_delete (aisexec_poll_handle,
  1289. conn_info->component->timer_healthcheck);
  1290. conn_info->component->timer_healthcheck = 0;
  1291. }
  1292. if (conn_info->ais_ci.u.libamf_ci.tracks) {
  1293. mempool_free (conn_info->ais_ci.u.libamf_ci.tracks);
  1294. conn_info->ais_ci.u.libamf_ci.tracks = 0;
  1295. }
  1296. }
  1297. return (0);
  1298. }
  1299. static int message_handler_req_exec_amf_componentregister (void *message)
  1300. {
  1301. struct req_exec_amf_componentregister *req_exec_amf_componentregister = (struct req_exec_amf_componentregister *)message;
  1302. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  1303. struct saAmfComponent *component;
  1304. struct saAmfComponent *amfProxyComponent;
  1305. SaErrorT error;
  1306. log_printf (LOG_LEVEL_DEBUG, "Executive: ComponentRegister for component %s\n",
  1307. getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName));
  1308. /*
  1309. * Determine if proxy isn't registered
  1310. */
  1311. error = SA_OK;
  1312. component = findComponent (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName);
  1313. amfProxyComponent = findComponent (&req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName);
  1314. /*
  1315. * If component not in configuration files, return error
  1316. */
  1317. if (component == 0) {
  1318. error = SA_ERR_NOT_EXIST;
  1319. }
  1320. /*
  1321. * If proxy doesn't exist and isn't registered, return error
  1322. */
  1323. if ((amfProxyComponent == 0 &&
  1324. req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) ||
  1325. (amfProxyComponent && amfProxyComponent->registered == 0)) {
  1326. error = SA_ERR_NOT_EXIST;
  1327. }
  1328. /*
  1329. * If component already registered, return error
  1330. */
  1331. if (error == SA_OK) {
  1332. if (component->registered) {
  1333. error = SA_ERR_EXIST;
  1334. }
  1335. }
  1336. /*
  1337. * Finally register component and setup links for proxy if
  1338. * proxy present
  1339. */
  1340. if (error == SA_OK) {
  1341. component->local = 0;
  1342. component->registered = 1;
  1343. component->conn_info = req_exec_amf_componentregister->source.conn_info;
  1344. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  1345. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  1346. component->currentHAState = SA_AMF_QUIESCED;
  1347. component->newHAState = SA_AMF_QUIESCED;
  1348. component->probableCause = 0;
  1349. component->enabledUnlockedState = 0;
  1350. component->disabledUnlockedState = 0;
  1351. if (req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) {
  1352. component->saAmfProxyComponent = amfProxyComponent;
  1353. }
  1354. }
  1355. /*
  1356. * If this node originated the request to the cluster, respond back
  1357. * to the AMF library
  1358. */
  1359. if (req_exec_amf_componentregister->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1360. if (error == SA_OK) {
  1361. component->local = 1;
  1362. req_exec_amf_componentregister->source.conn_info->component = component;
  1363. }
  1364. log_printf (LOG_LEVEL_DEBUG, "sending component register response to fd %d\n", req_exec_amf_componentregister->source.conn_info);
  1365. res_lib_amf_componentregister.header.magic = MESSAGE_MAGIC;
  1366. res_lib_amf_componentregister.header.size = sizeof (struct res_lib_amf_componentregister);
  1367. res_lib_amf_componentregister.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  1368. res_lib_amf_componentregister.error = error;
  1369. libais_send_response (req_exec_amf_componentregister->source.conn_info,
  1370. &res_lib_amf_componentregister,
  1371. sizeof (struct res_lib_amf_componentregister));
  1372. }
  1373. /*
  1374. * If no error on registration, determine if we should enter new state
  1375. */
  1376. if (error == SA_OK) {
  1377. dsm (component);
  1378. }
  1379. return (0);
  1380. }
  1381. static int message_handler_req_exec_amf_componentunregister (void *message)
  1382. {
  1383. struct req_exec_amf_componentunregister *req_exec_amf_componentunregister = (struct req_exec_amf_componentunregister *)message;
  1384. struct res_lib_amf_componentunregister res_lib_amf_componentunregister;
  1385. struct saAmfComponent *component;
  1386. struct saAmfComponent *amfProxyComponent;
  1387. SaErrorT error;
  1388. log_printf (LOG_LEVEL_DEBUG, "Executive: ComponentUnregister for %s\n",
  1389. getSaNameT (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName));
  1390. component = findComponent (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName);
  1391. amfProxyComponent = findComponent (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName);
  1392. /*
  1393. * Check for proxy and component not existing in system
  1394. */
  1395. error = SA_OK;
  1396. if (component == 0) {
  1397. error = SA_ERR_NOT_EXIST;
  1398. }
  1399. if (req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName.length > 0) {
  1400. if (amfProxyComponent) {
  1401. if (amfProxyComponent->registered == 0) {
  1402. error = SA_ERR_NOT_EXIST;
  1403. }
  1404. } else {
  1405. error = SA_ERR_NOT_EXIST;
  1406. }
  1407. }
  1408. /*
  1409. * If there is a proxycompname, make sure it is the proxy
  1410. * of compName
  1411. */
  1412. if (error == SA_OK && amfProxyComponent) {
  1413. if (component->saAmfProxyComponent != amfProxyComponent) {
  1414. error = SA_ERR_BAD_OPERATION;
  1415. }
  1416. }
  1417. /*
  1418. * Finally unregister the component
  1419. */
  1420. if (error == SA_OK) {
  1421. component->registered = 0;
  1422. dsmEnabledUnlockedTransitionDisabledUnlocked (component);
  1423. }
  1424. /*
  1425. * If this node originated the request to the cluster, respond back
  1426. * to the AMF library
  1427. */
  1428. if (req_exec_amf_componentunregister->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1429. log_printf (LOG_LEVEL_DEBUG, "sending component unregister response to fd %d\n",
  1430. req_exec_amf_componentunregister->source.conn_info);
  1431. res_lib_amf_componentunregister.header.magic = MESSAGE_MAGIC;
  1432. res_lib_amf_componentunregister.header.size = sizeof (struct res_lib_amf_componentunregister);
  1433. res_lib_amf_componentunregister.header.id = MESSAGE_RES_AMF_COMPONENTUNREGISTER;
  1434. res_lib_amf_componentunregister.error = error;
  1435. libais_send_response (req_exec_amf_componentunregister->source.conn_info,
  1436. &res_lib_amf_componentunregister, sizeof (struct res_lib_amf_componentunregister));
  1437. }
  1438. return (0);
  1439. }
  1440. static int message_handler_req_exec_amf_errorreport (void *message)
  1441. {
  1442. struct req_exec_amf_errorreport *req_exec_amf_errorreport = (struct req_exec_amf_errorreport *)message;
  1443. struct res_lib_amf_errorreport res_lib_amf_errorreport;
  1444. struct saAmfComponent *component;
  1445. SaErrorT error = SA_ERR_BAD_OPERATION;
  1446. log_printf (LOG_LEVEL_DEBUG, "Executive: ErrorReport for %s\n",
  1447. getSaNameT (&req_exec_amf_errorreport->req_lib_amf_errorreport.erroneousComponent));
  1448. component = findComponent (&req_exec_amf_errorreport->req_lib_amf_errorreport.erroneousComponent);
  1449. if (component && component->registered) {
  1450. component->probableCause = req_exec_amf_errorreport->req_lib_amf_errorreport.errorDescriptor.probableCause;
  1451. /*
  1452. * One registered component left, so transition
  1453. * SU to failed operational state
  1454. */
  1455. dsmEnabledUnlockedTransitionDisabledUnlocked (component);
  1456. error = SA_OK;
  1457. }
  1458. /*
  1459. * If this node originated the request to the cluster, respond back
  1460. * to the AMF library
  1461. */
  1462. if (req_exec_amf_errorreport->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1463. log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n",
  1464. req_exec_amf_errorreport->source.conn_info);
  1465. res_lib_amf_errorreport.header.magic = MESSAGE_MAGIC;
  1466. res_lib_amf_errorreport.header.size = sizeof (struct res_lib_amf_errorreport);
  1467. res_lib_amf_errorreport.header.id = MESSAGE_RES_AMF_ERRORREPORT;
  1468. res_lib_amf_errorreport.error = error;
  1469. libais_send_response (req_exec_amf_errorreport->source.conn_info,
  1470. &res_lib_amf_errorreport, sizeof (struct res_lib_amf_errorreport));
  1471. }
  1472. return (0);
  1473. }
  1474. static int message_handler_req_exec_amf_errorcancelall (void *message)
  1475. {
  1476. struct req_exec_amf_errorcancelall *req_exec_amf_errorcancelall = (struct req_exec_amf_errorcancelall *)message;
  1477. struct res_lib_amf_errorcancelall res_lib_amf_errorcancelall;
  1478. struct saAmfComponent *component;
  1479. SaErrorT error = SA_ERR_BAD_OPERATION;
  1480. log_printf (LOG_LEVEL_DEBUG, "Executive: ErrorCancelAll for %s\n",
  1481. getSaNameT (&req_exec_amf_errorcancelall->req_lib_amf_errorcancelall.compName));
  1482. component = findComponent (&req_exec_amf_errorcancelall->req_lib_amf_errorcancelall.compName);
  1483. if (component && component->registered) {
  1484. /*
  1485. * Mark component in service if its a AMF service
  1486. * connected to this aisexec
  1487. */
  1488. if (component->probableCause) {
  1489. component->probableCause = 0;
  1490. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1491. dsm (component);
  1492. }
  1493. error = SA_OK;
  1494. }
  1495. /*
  1496. * If this node originated the request to the cluster, respond back
  1497. * to the AMF library
  1498. */
  1499. if (req_exec_amf_errorcancelall->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1500. log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n",
  1501. req_exec_amf_errorcancelall->source.conn_info);
  1502. res_lib_amf_errorcancelall.header.magic = MESSAGE_MAGIC;
  1503. res_lib_amf_errorcancelall.header.size = sizeof (struct res_lib_amf_errorcancelall);
  1504. res_lib_amf_errorcancelall.header.id = MESSAGE_RES_AMF_ERRORCANCELALL;
  1505. res_lib_amf_errorcancelall.error = error;
  1506. libais_send_response (req_exec_amf_errorcancelall->source.conn_info,
  1507. &res_lib_amf_errorcancelall, sizeof (struct res_lib_amf_errorcancelall));
  1508. }
  1509. return (0);
  1510. }
  1511. /*
  1512. * If receiving this message from another cluster node, another cluster node
  1513. * has selected a readiness state for a component connected to _that_ cluster
  1514. * node. That cluster node API has verified the readiness state, so its time to let
  1515. * the rest of the cluster nodes know about the readiness state change.
  1516. */
  1517. static int message_handler_req_exec_amf_readinessstateset (void *message)
  1518. {
  1519. struct req_exec_amf_readinessstateset *req_exec_amf_readinessstateset = (struct req_exec_amf_readinessstateset *)message;
  1520. struct saAmfComponent *component;
  1521. component = findComponent (&req_exec_amf_readinessstateset->compName);
  1522. if (component) {
  1523. log_printf (LOG_LEVEL_DEBUG, "found component %s, setting current readiness state to %d\n",
  1524. getSaNameT (&component->name),
  1525. req_exec_amf_readinessstateset->readinessState);
  1526. component->currentReadinessState = req_exec_amf_readinessstateset->readinessState;
  1527. dsm (component);
  1528. }
  1529. return (0);
  1530. }
  1531. /*
  1532. * If receiving this message from another cluster node, another cluster node
  1533. * has selected a ha state for a component connected to _that_ cluster
  1534. * node. That cluster node API has verified the ha state, so its time to let
  1535. * the rest of the cluster nodes know about the HA state change.
  1536. */
  1537. static int message_handler_req_exec_amf_hastateset (void *message)
  1538. {
  1539. struct req_exec_amf_hastateset *req_exec_amf_hastateset = (struct req_exec_amf_hastateset *)message;
  1540. struct saAmfComponent *component;
  1541. component = findComponent (&req_exec_amf_hastateset->compName);
  1542. if (component) {
  1543. log_printf (LOG_LEVEL_DEBUG, "found component %s, setting current HA state to %d\n",
  1544. getSaNameT (&component->name),
  1545. req_exec_amf_hastateset->haState);
  1546. component->currentHAState = req_exec_amf_hastateset->haState;
  1547. dsm (component);
  1548. }
  1549. return (0);
  1550. }
  1551. static int message_handler_req_amf_init (struct conn_info *conn_info, void *message)
  1552. {
  1553. struct res_lib_init res_lib_init;
  1554. SaErrorT error = SA_ERR_SECURITY;
  1555. log_printf (LOG_LEVEL_DEBUG, "Got AMF request to initalize availability management framework service.\n");
  1556. if (conn_info->authenticated) {
  1557. conn_info->service = SOCKET_SERVICE_AMF;
  1558. error = SA_OK;
  1559. }
  1560. res_lib_init.header.magic = MESSAGE_MAGIC;
  1561. res_lib_init.header.size = sizeof (struct res_lib_init);
  1562. res_lib_init.header.id = MESSAGE_RES_INIT;
  1563. res_lib_init.error = error;
  1564. libais_send_response (conn_info, &res_lib_init, sizeof (res_lib_init));
  1565. list_init (&conn_info->conn_list);
  1566. if (conn_info->authenticated) {
  1567. return (0);
  1568. }
  1569. return (-1);
  1570. }
  1571. static int message_handler_req_lib_activatepoll (struct conn_info *conn_info, void *message)
  1572. {
  1573. struct res_lib_activatepoll res_lib_activatepoll;
  1574. res_lib_activatepoll.header.magic = MESSAGE_MAGIC;
  1575. res_lib_activatepoll.header.size = sizeof (struct res_lib_activatepoll);
  1576. res_lib_activatepoll.header.id = MESSAGE_RES_LIB_ACTIVATEPOLL;
  1577. libais_send_response (conn_info, &res_lib_activatepoll, sizeof (struct res_lib_activatepoll));
  1578. return (0);
  1579. }
  1580. static int message_handler_req_amf_componentregister (struct conn_info *conn_info, void *message)
  1581. {
  1582. struct req_amf_componentregister *req_lib_amf_componentregister = (struct req_amf_componentregister *)message;
  1583. struct req_exec_amf_componentregister req_exec_amf_componentregister;
  1584. struct iovec iovecs[2];
  1585. int result;
  1586. req_exec_amf_componentregister.header.magic = MESSAGE_MAGIC;
  1587. req_exec_amf_componentregister.header.size = sizeof (struct req_exec_amf_componentregister);
  1588. req_exec_amf_componentregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTREGISTER;
  1589. req_exec_amf_componentregister.source.conn_info = conn_info;
  1590. req_exec_amf_componentregister.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1591. memcpy (&req_exec_amf_componentregister.req_lib_amf_componentregister,
  1592. req_lib_amf_componentregister,
  1593. sizeof (struct req_lib_amf_componentregister));
  1594. iovecs[0].iov_base = &req_exec_amf_componentregister;
  1595. iovecs[0].iov_len = sizeof (req_exec_amf_componentregister);
  1596. result = gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1597. return (0);
  1598. }
  1599. static int message_handler_req_amf_componentunregister (struct conn_info *conn_info, void *message)
  1600. {
  1601. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  1602. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  1603. struct iovec iovecs[2];
  1604. int result;
  1605. struct saAmfComponent *component;
  1606. req_exec_amf_componentunregister.header.magic = MESSAGE_MAGIC;
  1607. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  1608. req_exec_amf_componentunregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER;
  1609. req_exec_amf_componentunregister.source.conn_info = conn_info;
  1610. req_exec_amf_componentunregister.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1611. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  1612. req_lib_amf_componentunregister,
  1613. sizeof (struct req_lib_amf_componentunregister));
  1614. component = findComponent (&req_lib_amf_componentunregister->compName);
  1615. if (component && component->registered && component->local) {
  1616. component->probableCause = SA_AMF_NOT_RESPONDING;
  1617. }
  1618. iovecs[0].iov_base = &req_exec_amf_componentunregister;
  1619. iovecs[0].iov_len = sizeof (req_exec_amf_componentunregister);
  1620. result = gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1621. return (0);
  1622. }
  1623. static int message_handler_req_amf_readinessstateget (struct conn_info *conn_info, void *message)
  1624. {
  1625. struct req_amf_readinessstateget *req_amf_readinessstateget = (struct req_amf_readinessstateget *)message;
  1626. struct res_amf_readinessstateget res_amf_readinessstateget;
  1627. struct saAmfComponent *component;
  1628. log_printf (LOG_LEVEL_DEBUG, "got request to return readiness state\n");
  1629. res_amf_readinessstateget.header.magic = MESSAGE_MAGIC;
  1630. res_amf_readinessstateget.header.id = MESSAGE_RES_AMF_READINESSSTATEGET;
  1631. res_amf_readinessstateget.header.size = sizeof (struct res_amf_readinessstateget);
  1632. res_amf_readinessstateget.error = SA_ERR_NOT_EXIST;
  1633. component = findComponent (&req_amf_readinessstateget->compName);
  1634. log_printf (LOG_LEVEL_DEBUG, "readinessstateget: found component %p\n", component);
  1635. if (component) {
  1636. memcpy (&res_amf_readinessstateget.readinessState,
  1637. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  1638. res_amf_readinessstateget.error = SA_OK;
  1639. }
  1640. libais_send_response (conn_info, &res_amf_readinessstateget, sizeof (struct res_amf_readinessstateget));
  1641. return (0);
  1642. }
  1643. static int message_handler_req_amf_hastateget (struct conn_info *conn_info, void *message)
  1644. {
  1645. struct req_amf_hastateget *req_amf_hastateget = (struct req_amf_hastateget *)message;
  1646. struct res_amf_hastateget res_amf_hastateget;
  1647. struct saAmfComponent *component;
  1648. res_amf_hastateget.header.magic = MESSAGE_MAGIC;
  1649. res_amf_hastateget.header.id = MESSAGE_RES_AMF_HASTATEGET;
  1650. res_amf_hastateget.header.size = sizeof (struct res_amf_hastateget);
  1651. res_amf_hastateget.error = SA_ERR_NOT_EXIST;
  1652. component = findComponentInProtectionGroup (&req_amf_hastateget->csiName, &req_amf_hastateget->compName);
  1653. if (component) {
  1654. memcpy (&res_amf_hastateget.haState,
  1655. &component->currentHAState, sizeof (SaAmfHAStateT));
  1656. res_amf_hastateget.error = SA_OK;
  1657. }
  1658. libais_send_response (conn_info, &res_amf_hastateget, sizeof (struct res_amf_hastateget));
  1659. return (0);
  1660. }
  1661. static int message_handler_req_amf_protectiongrouptrackstart (struct conn_info *conn_info, void *message)
  1662. {
  1663. struct req_amf_protectiongrouptrackstart *req_amf_protectiongrouptrackstart = (struct req_amf_protectiongrouptrackstart *)message;
  1664. struct res_amf_protectiongrouptrackstart res_amf_protectiongrouptrackstart;
  1665. struct libamf_ci_trackentry *track = 0;
  1666. int i;
  1667. struct saAmfProtectionGroup *amfProtectionGroup;
  1668. amfProtectionGroup = findProtectionGroup (&req_amf_protectiongrouptrackstart->csiName);
  1669. if (amfProtectionGroup) {
  1670. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstart: Got valid track start on CSI: %s.\n", getSaNameT (&req_amf_protectiongrouptrackstart->csiName));
  1671. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  1672. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) {
  1673. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  1674. break;
  1675. }
  1676. }
  1677. if (track == 0) {
  1678. grow_amf_track_table (conn_info, 1);
  1679. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  1680. }
  1681. track->active = 1;
  1682. track->trackFlags = req_amf_protectiongrouptrackstart->trackFlags;
  1683. track->notificationBufferAddress = req_amf_protectiongrouptrackstart->notificationBufferAddress;
  1684. memcpy (&track->csiName,
  1685. &req_amf_protectiongrouptrackstart->csiName, sizeof (SaNameT));
  1686. conn_info->ais_ci.u.libamf_ci.trackActive += 1;
  1687. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  1688. /*
  1689. * If SA_TRACK_CURRENT is specified, write out all current connections
  1690. */
  1691. } else {
  1692. log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
  1693. }
  1694. res_amf_protectiongrouptrackstart.header.magic = MESSAGE_MAGIC;
  1695. res_amf_protectiongrouptrackstart.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART;
  1696. res_amf_protectiongrouptrackstart.header.size = sizeof (struct res_amf_protectiongrouptrackstart);
  1697. res_amf_protectiongrouptrackstart.error = SA_ERR_NOT_EXIST;
  1698. if (amfProtectionGroup) {
  1699. res_amf_protectiongrouptrackstart.error = SA_OK;
  1700. }
  1701. libais_send_response (conn_info, &res_amf_protectiongrouptrackstart,
  1702. sizeof (struct res_amf_protectiongrouptrackstart));
  1703. if (amfProtectionGroup &&
  1704. req_amf_protectiongrouptrackstart->trackFlags & SA_TRACK_CURRENT) {
  1705. sendProtectionGroupNotification (conn_info,
  1706. track->notificationBufferAddress,
  1707. amfProtectionGroup,
  1708. 0,
  1709. 0,
  1710. track->trackFlags);
  1711. track->trackFlags &= ~SA_TRACK_CURRENT;
  1712. }
  1713. return (0);
  1714. }
  1715. static int message_handler_req_amf_protectiongrouptrackstop (struct conn_info *conn_info, void *message)
  1716. {
  1717. struct req_amf_protectiongrouptrackstop *req_amf_protectiongrouptrackstop = (struct req_amf_protectiongrouptrackstop *)message;
  1718. struct res_amf_protectiongrouptrackstop res_amf_protectiongrouptrackstop;
  1719. struct libamf_ci_trackentry *track = 0;
  1720. int i;
  1721. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  1722. if (SaNameTisNameT (&req_amf_protectiongrouptrackstop->csiName,
  1723. &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) {
  1724. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  1725. }
  1726. }
  1727. if (track) {
  1728. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_amf_protectiongrouptrackstop->csiName));
  1729. memset (track, 0, sizeof (struct libamf_ci_trackentry));
  1730. conn_info->ais_ci.u.libamf_ci.trackActive -= 1;
  1731. if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) {
  1732. list_del (&conn_info->conn_list);
  1733. }
  1734. }
  1735. res_amf_protectiongrouptrackstop.header.magic = MESSAGE_MAGIC;
  1736. res_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
  1737. res_amf_protectiongrouptrackstop.header.size = sizeof (struct res_amf_protectiongrouptrackstop);
  1738. res_amf_protectiongrouptrackstop.error = SA_ERR_NOT_EXIST;
  1739. if (track) {
  1740. res_amf_protectiongrouptrackstop.error = SA_OK;
  1741. }
  1742. libais_send_response (conn_info, &res_amf_protectiongrouptrackstop,
  1743. sizeof (struct res_amf_protectiongrouptrackstop));
  1744. return (0);
  1745. }
  1746. static int message_handler_req_amf_errorreport (struct conn_info *conn_info, void *message)
  1747. {
  1748. struct req_lib_amf_errorreport *req_lib_amf_errorreport = (struct req_lib_amf_errorreport *)message;
  1749. struct req_exec_amf_errorreport req_exec_amf_errorreport;
  1750. struct iovec iovecs[2];
  1751. int result;
  1752. req_exec_amf_errorreport.header.magic = MESSAGE_MAGIC;
  1753. req_exec_amf_errorreport.header.size = sizeof (struct req_exec_amf_errorreport);
  1754. req_exec_amf_errorreport.header.id = MESSAGE_REQ_EXEC_AMF_ERRORREPORT;
  1755. req_exec_amf_errorreport.source.conn_info = conn_info;
  1756. req_exec_amf_errorreport.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1757. memcpy (&req_exec_amf_errorreport.req_lib_amf_errorreport,
  1758. req_lib_amf_errorreport,
  1759. sizeof (struct req_lib_amf_errorreport));
  1760. iovecs[0].iov_base = &req_exec_amf_errorreport;
  1761. iovecs[0].iov_len = sizeof (req_exec_amf_errorreport);
  1762. // iovecs[0].iov_len = sizeof (req_exec_amf_errorreport) - sizeof (req_lib_amf_errorreport);
  1763. // iovecs[1].iov_base = &req_lib_amf_errorreport;
  1764. // iovecs[1].iov_len = sizeof (req_lib_amf_errorreport);
  1765. result = gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1766. return (0);
  1767. }
  1768. static int message_handler_req_amf_errorcancelall (struct conn_info *conn_info, void *message)
  1769. {
  1770. struct req_lib_amf_errorcancelall *req_lib_amf_errorcancelall = (struct req_lib_amf_errorcancelall *)message;
  1771. struct req_exec_amf_errorcancelall req_exec_amf_errorcancelall;
  1772. struct iovec iovecs[2];
  1773. int result;
  1774. req_exec_amf_errorcancelall.header.magic = MESSAGE_MAGIC;
  1775. req_exec_amf_errorcancelall.header.size = sizeof (struct req_exec_amf_errorcancelall);
  1776. req_exec_amf_errorcancelall.header.id = MESSAGE_REQ_EXEC_AMF_ERRORCANCELALL;
  1777. req_exec_amf_errorcancelall.source.conn_info = conn_info;
  1778. req_exec_amf_errorcancelall.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1779. memcpy (&req_exec_amf_errorcancelall.req_lib_amf_errorcancelall,
  1780. req_lib_amf_errorcancelall,
  1781. sizeof (struct req_lib_amf_errorcancelall));
  1782. iovecs[0].iov_base = &req_exec_amf_errorcancelall;
  1783. iovecs[0].iov_len = sizeof (req_exec_amf_errorcancelall);
  1784. // iovecs[0].iov_len = sizeof (req_exec_amf_errorcancelall) - sizeof (req_lib_amf_errorcancelall);
  1785. // iovecs[1].iov_base = &req_lib_amf_errorcancelall;
  1786. // iovecs[1].iov_len = sizeof (req_lib_amf_errorcancelall);
  1787. result = gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1788. return (0);
  1789. }
  1790. static int message_handler_req_amf_stoppingcomplete (struct conn_info *conn_info_notused,
  1791. void *message)
  1792. {
  1793. struct req_amf_stoppingcomplete *req_amf_stoppingcomplete = (struct req_amf_stoppingcomplete *)message;
  1794. struct conn_info *inv_conn_info;
  1795. int interface;
  1796. log_printf (LOG_LEVEL_DEBUG, "handling stopping complete\n");
  1797. req_amf_invocation_get_and_destroy (req_amf_stoppingcomplete->invocation,
  1798. &interface, &inv_conn_info);
  1799. inv_conn_info->component->currentReadinessState = inv_conn_info->component->newReadinessState;
  1800. readinessStateSetCluster (inv_conn_info->component, SA_AMF_STOPPING);
  1801. sendProtectionGroupNotifications (inv_conn_info->component,
  1802. SA_AMF_PROTECTION_GROUP_STATE_CHANGE);
  1803. return (0);
  1804. }
  1805. void response_handler_healthcheckcallback (struct conn_info *conn_info,
  1806. struct req_amf_response *req_amf_response) {
  1807. if (req_amf_response->error == SA_OK) {
  1808. log_printf (LOG_LEVEL_DEBUG, "setting healthcheck ok\n");
  1809. conn_info->component->healthcheck_outstanding = 0;
  1810. }
  1811. }
  1812. static int message_handler_req_amf_response (struct conn_info *conn_info_nouse, void *message)
  1813. {
  1814. struct req_amf_response *req_amf_response = (struct req_amf_response *)message;
  1815. struct conn_info *conn_info;
  1816. int interface;
  1817. int res;
  1818. res = req_amf_invocation_get_and_destroy (req_amf_response->invocation,
  1819. &interface, &conn_info);
  1820. log_printf (LOG_LEVEL_DEBUG, "handling response connection %x interface %x\n", conn_info, interface);
  1821. switch (interface) {
  1822. case MESSAGE_REQ_AMF_RESPONSE_SAAMFHEALTHCHECKCALLBACK:
  1823. response_handler_healthcheckcallback (conn_info, req_amf_response);
  1824. break;
  1825. case MESSAGE_REQ_AMF_RESPONSE_SAAMFREADINESSSTATESETCALLBACK:
  1826. response_handler_readinessstatesetcallback (conn_info, req_amf_response);
  1827. break;
  1828. case MESSAGE_REQ_AMF_RESPONSE_SAAMFCSISETCALLBACK:
  1829. response_handler_csisetcallback (conn_info, req_amf_response);
  1830. break;
  1831. case MESSAGE_REQ_AMF_RESPONSE_SAAMFCSIREMOVECALLBACK:
  1832. break;
  1833. default:
  1834. // TODO
  1835. log_printf (LOG_LEVEL_ERROR, "invalid invocation value %x\n", req_amf_response->invocation);
  1836. break;
  1837. }
  1838. return (0);
  1839. }
  1840. static int message_handler_req_amf_componentcapabilitymodelget (struct conn_info *conn_info, void *message)
  1841. {
  1842. struct req_amf_componentcapabilitymodelget *req_amf_componentcapabilitymodelget = (struct req_amf_componentcapabilitymodelget *)message;
  1843. struct res_amf_componentcapabilitymodelget res_amf_componentcapabilitymodelget;
  1844. struct saAmfComponent *component;
  1845. SaErrorT error = SA_OK;
  1846. log_printf (LOG_LEVEL_DEBUG, "componentcapabilitymodelget: Retrieve name %s.\n", getSaNameT (&req_amf_componentcapabilitymodelget->compName));
  1847. component = findComponent (&req_amf_componentcapabilitymodelget->compName);
  1848. if (component && component->registered) {
  1849. memcpy (&res_amf_componentcapabilitymodelget.componentCapabilityModel,
  1850. &component->componentCapabilityModel, sizeof (SaAmfComponentCapabilityModelT));
  1851. } else {
  1852. error = SA_ERR_NOT_EXIST;
  1853. }
  1854. res_amf_componentcapabilitymodelget.header.magic = MESSAGE_MAGIC;
  1855. res_amf_componentcapabilitymodelget.header.size = sizeof (struct res_amf_componentcapabilitymodelget);
  1856. res_amf_componentcapabilitymodelget.header.id = MESSAGE_RES_AMF_COMPONENTCAPABILITYMODELGET;
  1857. res_amf_componentcapabilitymodelget.error = error;
  1858. libais_send_response (conn_info, &res_amf_componentcapabilitymodelget,
  1859. sizeof (struct res_amf_componentcapabilitymodelget));
  1860. return (0);
  1861. }