amf.c 93 KB

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