amf.c 74 KB

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