amf.c 93 KB

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