amf.c 94 KB

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