4
0

amfsu.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. /** @file exec/amfsu.c
  2. *
  3. * Copyright (c) 2002-2006 MontaVista Software, Inc.
  4. * Author: Steven Dake (sdake@mvista.com)
  5. *
  6. * Copyright (c) 2006 Ericsson AB.
  7. * Author: Hans Feldt
  8. * - Introduced AMF B.02 information model
  9. * - Use DN in API and multicast messages
  10. * - (Re-)Introduction of event based multicast messages
  11. * - Refactoring of code into several AMF files
  12. * Author: Anders Eriksson, Lars Holm
  13. * - Component/SU restart, SU failover
  14. *
  15. * All rights reserved.
  16. *
  17. *
  18. * This software licensed under BSD license, the text of which follows:
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions are met:
  22. *
  23. * - Redistributions of source code must retain the above copyright notice,
  24. * this list of conditions and the following disclaimer.
  25. * - Redistributions in binary form must reproduce the above copyright notice,
  26. * this list of conditions and the following disclaimer in the documentation
  27. * and/or other materials provided with the distribution.
  28. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  29. * contributors may be used to endorse or promote products derived from this
  30. * software without specific prior written permission.
  31. *
  32. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  33. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  34. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  35. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  36. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  37. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  38. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  39. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  40. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  42. * THE POSSIBILITY OF SUCH DAMAGE.
  43. *
  44. * AMF Service Unit Class Implementation
  45. *
  46. * This file contains functions for handling AMF-service units(SUs). It can be
  47. * viewed as the implementation of the AMF Service Unit class (called SU)
  48. * as described in SAI-Overview-B.02.01. The SA Forum specification
  49. * SAI-AIS-AMF-B.02.01 has been used as specification of the behaviour
  50. * and is referred to as 'the spec' below.
  51. *
  52. * The functions in this file are responsible for:
  53. * - instantiating and terminating service units on request
  54. * (considering the dependencies between components described in paragraph
  55. * 3.9.2)
  56. * - creating and deleting CSI-assignment objects between its components and
  57. * CSI-objects upon request
  58. * - receiving error reports from its components and forwarding them to
  59. * appropriate handler (SU or SG or node or cluster)
  60. * - implementing restart of itself and its components (paragraph 3.12.1.2)
  61. * - implementing error escallation level 1 (paragraph 3.12.2.2 in the spec)
  62. * - handling all run time attributes of the AMF SU; all cached
  63. * attributes are stored as variables and sent to the IMM service
  64. * upon the changes described in the specification.
  65. *
  66. * SU contains the following state machines:
  67. * - presence state machine (PRSM)
  68. * - administrative state machine (ADSM) (NOT IN THIS RELEASE)
  69. * - operational state machine (OPSM)
  70. * - readiness state machine (RESM)
  71. * - ha state per service instance (SI)
  72. * - restart control state machine (RCSM)
  73. *
  74. * The presence state machine orders intantiation of its components on request.
  75. * It fully respects the dependency rules between components at instantiation
  76. * such that it orders instantiation simultaneously only of components on the
  77. * same instantiation level. The presence state machine is implemented with
  78. * the states described in the spec and the state transitions are trigged by
  79. * reported state transitions from its contained components according to
  80. * paragraph 3.3.1.1.
  81. *
  82. * The operational state machine is not responsible for any control function.
  83. * It assumes the DISABLED state if an incoming operational state change report
  84. * from a component indicates the component has assumed the DISABLED state.
  85. * Operational state changes are reported to IMM.
  86. *
  87. * The readiness state machine is not used for any control but is updated and
  88. * reported to IMM when it is changed.
  89. *
  90. * The restart control state machine (RCSM) is used to implement level 1 of
  91. * the error escallation polycy described in chapter 3.12.2 of the spec. It
  92. * also implements component restart and service unit restart as described in
  93. * paragraph 3.12.1.2 and 3.12.1.3.
  94. * RCSM contains three composite states.
  95. * Being a composite state means that the state contains substates.
  96. * RCSM composite states are:
  97. * - ESCALLATION_LEVEL (LEVEL_0, LEVEL_1 and LEVEL_2)
  98. * - RESTARTING_COMPONENT (DEACTIVATING, RESTARTING, SETTING and ACTIVATING)
  99. * - RESTARTING_SERVICE_UNIT (DEACTIVATING, TERMINATING, INSTANTIATING,
  100. * and ACTIVATING)
  101. *
  102. * ESCALLATION_LEVEL is a kind of idle state where no actions are performed
  103. * and used only to remember the escallation level. Substate LEVEL_0 indicates
  104. * no escallation. LEVEL_1 indicates that a component restart has been
  105. * executed recently and the escallation timer is still running. At this level
  106. * component restart requests will transition to RESTARTING_COMPONENT but
  107. * if there are too many restart requests before the probation timer expires
  108. * then a transition will be made to LEVEL_2 and the restart request will
  109. * be forwarded to the node instance hosting this component.
  110. * State RESTARTING_SERVICE_UNIT will only be assumed if the node explicitly
  111. * requests the SU to execute a restart of itself (after having evaluated its
  112. * part of the error escallation policy).
  113. *
  114. */
  115. /*
  116. *
  117. */
  118. #include <stdlib.h>
  119. #include <assert.h>
  120. #include <string.h>
  121. #include <errno.h>
  122. #include "amf.h"
  123. #include "util.h"
  124. #include "print.h"
  125. #include "main.h"
  126. static int presence_state_all_comps_in_su_are_set (struct amf_su *su,
  127. SaAmfPresenceStateT state)
  128. {
  129. int all_set = 1;
  130. struct amf_comp *comp;
  131. for (comp = su->comp_head; comp != NULL; comp = comp->next) {
  132. if (comp->saAmfCompPresenceState != state) {
  133. all_set = 0;
  134. }
  135. }
  136. return all_set;
  137. }
  138. /**
  139. * This function only logs since the readiness state is runtime
  140. * calculated.
  141. * @param su
  142. * @param amf_readiness_state
  143. */
  144. static void su_readiness_state_set (struct amf_su *su,
  145. SaAmfReadinessStateT readiness_state)
  146. {
  147. log_printf (LOG_NOTICE, "Setting SU '%s' readiness state: %s\n",
  148. su->name.value, amf_readiness_state (readiness_state));
  149. }
  150. static void clear_ha_state (
  151. struct amf_su *su, struct amf_si_assignment *si_assignment)
  152. {
  153. ENTER ("");
  154. si_assignment->saAmfSISUHAState = 0;
  155. }
  156. static void su_presence_state_set (struct amf_su *su,
  157. SaAmfPresenceStateT presence_state)
  158. {
  159. /*
  160. * Set all SI's confirmed HA state to unknown if uninstantiated
  161. */
  162. if (su->saAmfSUPresenceState == SA_AMF_PRESENCE_UNINSTANTIATED) {
  163. amf_su_foreach_si_assignment (su, clear_ha_state);
  164. }
  165. su->saAmfSUPresenceState = presence_state;
  166. log_printf (LOG_NOTICE, "Setting SU '%s' presence state: %s\n",
  167. su->name.value, amf_presence_state (presence_state));
  168. if (su->restart_control_state != SU_RC_RESTART_SU_SETTING) {
  169. amf_sg_su_state_changed (
  170. su->sg, su, SA_AMF_PRESENCE_STATE, presence_state);
  171. }
  172. }
  173. static void su_operational_state_set (struct amf_su *su,
  174. SaAmfOperationalStateT oper_state)
  175. {
  176. struct amf_comp* comp;
  177. su->saAmfSUOperState = oper_state;
  178. log_printf (LOG_NOTICE, "Setting SU '%s' operational state: %s\n",
  179. su->name.value, amf_op_state (oper_state));
  180. if (oper_state == SA_AMF_OPERATIONAL_ENABLED) {
  181. su_readiness_state_set (su, SA_AMF_READINESS_IN_SERVICE);
  182. for (comp = su->comp_head; comp; comp = comp->next) {
  183. amf_comp_readiness_state_set (comp, SA_AMF_READINESS_IN_SERVICE);
  184. }
  185. } else if (oper_state == SA_AMF_OPERATIONAL_DISABLED) {
  186. su_readiness_state_set (su, SA_AMF_READINESS_OUT_OF_SERVICE);
  187. for (comp = su->comp_head; comp; comp = comp->next) {
  188. amf_comp_readiness_state_set (comp, SA_AMF_READINESS_OUT_OF_SERVICE);
  189. }
  190. }
  191. }
  192. static void comp_assign_csi (struct amf_comp *comp, struct amf_csi *csi,
  193. struct amf_si_assignment *si_assignment, SaAmfHAStateT ha_state)
  194. {
  195. struct amf_csi_assignment *csi_assignment;
  196. dprintf (" Creating CSI '%s' to comp '%s' with hastate %s\n",
  197. getSaNameT (&csi->name), getSaNameT (&comp->name),
  198. amf_ha_state (ha_state));
  199. csi_assignment = malloc (sizeof (struct amf_csi_assignment));
  200. if (csi_assignment == NULL) {
  201. openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
  202. }
  203. csi_assignment->next = csi->assigned_csis;
  204. csi->assigned_csis = csi_assignment;
  205. amf_comp_dn_make (comp, &csi_assignment->name);
  206. csi_assignment->csi = csi;
  207. csi_assignment->comp = comp;
  208. csi_assignment->saAmfCSICompHAState = 0; /* undefined confirmed HA state */
  209. csi_assignment->requested_ha_state = ha_state;
  210. csi_assignment->si_assignment = si_assignment;
  211. }
  212. static void su_restart (struct amf_su *su)
  213. {
  214. struct amf_comp *comp;
  215. SaNameT dn;
  216. ENTER ("'%s'", su->name.value);
  217. amf_su_dn_make (su, &dn);
  218. log_printf (LOG_NOTICE, "Error detected for '%s', recovery "
  219. "action:\n\t\tSU restart", dn.value);
  220. su->restart_control_state = SU_RC_RESTART_SU_DEACTIVATING;
  221. su->restart_control_state = SU_RC_RESTART_SU_INSTANTIATING;
  222. su->escalation_level_history_state =
  223. SU_RC_ESCALATION_LEVEL_2;
  224. su->saAmfSURestartCount += 1;
  225. for (comp = su->comp_head; comp != NULL; comp = comp->next) {
  226. amf_comp_restart (comp);
  227. }
  228. }
  229. static void comp_restart (struct amf_comp *comp)
  230. {
  231. SaNameT dn;
  232. ENTER ("'%s'", comp->name.value);
  233. amf_comp_dn_make (comp, &dn);
  234. log_printf (LOG_NOTICE, "Error detected for '%s', recovery "
  235. "action:\n\t\tcomponent restart", dn.value);
  236. comp->su->restart_control_state = SU_RC_RESTART_COMP_DEACTIVATING;
  237. comp->su->restart_control_state = SU_RC_RESTART_COMP_RESTARTING;
  238. comp->su->escalation_level_history_state = SU_RC_ESCALATION_LEVEL_1;
  239. amf_comp_restart (comp);
  240. }
  241. void amf_su_instantiate (struct amf_su *su)
  242. {
  243. struct amf_comp *comp;
  244. ENTER ("'%s'", su->name.value);
  245. for (comp = su->comp_head; comp != NULL; comp = comp->next) {
  246. amf_comp_instantiate (comp);
  247. }
  248. }
  249. void amf_su_assign_si (struct amf_su *su, struct amf_si *si,
  250. SaAmfHAStateT ha_state)
  251. {
  252. struct amf_si_assignment *si_assignment;
  253. dprintf ("Creating SI '%s' to SU '%s' with hastate %s\n",
  254. getSaNameT (&si->name), getSaNameT (&su->name),
  255. amf_ha_state (ha_state));
  256. si_assignment = malloc (sizeof (struct amf_si_assignment));
  257. if (si_assignment == NULL) {
  258. openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
  259. }
  260. amf_su_dn_make (su, &si_assignment->name);
  261. si_assignment->saAmfSISUHAState = 0; /* undefined confirmed HA state */
  262. si_assignment->requested_ha_state = ha_state;
  263. si_assignment->next = si->assigned_sis;
  264. si->assigned_sis = si_assignment;
  265. si_assignment->si = si;
  266. si_assignment->su = su;
  267. {
  268. struct amf_csi *csi;
  269. struct amf_comp *comp;
  270. SaNameT *cs_type;
  271. int i;
  272. /*
  273. ** for each component in SU, find a CSI in the SI with the same type
  274. */
  275. for (comp = su->comp_head; comp != NULL; comp = comp->next) {
  276. int no_of_cs_types = 0;
  277. for (i = 0; comp->saAmfCompCsTypes[i]; i++) {
  278. cs_type = comp->saAmfCompCsTypes[i];
  279. no_of_cs_types++;
  280. int no_of_assignments = 0;
  281. for (csi = si->csi_head; csi != NULL; csi = csi->next) {
  282. if (!memcmp(csi->saAmfCSTypeName.value, cs_type->value,
  283. cs_type->length)) {
  284. comp_assign_csi (comp, csi, si_assignment, ha_state);
  285. no_of_assignments++;
  286. }
  287. }
  288. if (no_of_assignments == 0) {
  289. log_printf (
  290. LOG_WARNING, "\t No CSIs of type %s configured?!!\n",
  291. getSaNameT (cs_type));
  292. }
  293. }
  294. if (no_of_cs_types == 0) {
  295. log_printf (LOG_LEVEL_ERROR,
  296. "\t No CS types configured for comp %s ?!!\n",
  297. getSaNameT (&comp->name));
  298. }
  299. }
  300. }
  301. }
  302. static void si_ha_state_assumed_cbfn (
  303. struct amf_si_assignment *si_assignment, int result)
  304. {
  305. struct amf_si_assignment *tmp_si_assignment;
  306. struct amf_comp *comp;
  307. struct amf_csi_assignment *csi_assignment;
  308. int all_confirmed = 1;
  309. ENTER ("");
  310. tmp_si_assignment = amf_su_get_next_si_assignment(si_assignment->su, NULL);
  311. while (tmp_si_assignment != NULL) {
  312. for (comp = tmp_si_assignment->su->comp_head; comp != NULL;
  313. comp = comp->next) {
  314. csi_assignment = amf_comp_get_next_csi_assignment(comp, NULL);
  315. while (csi_assignment != NULL) {
  316. if (csi_assignment->requested_ha_state !=
  317. csi_assignment->saAmfCSICompHAState) {
  318. all_confirmed = 0;
  319. }
  320. csi_assignment = amf_comp_get_next_csi_assignment(
  321. comp, csi_assignment);
  322. }
  323. }
  324. tmp_si_assignment = amf_su_get_next_si_assignment(
  325. si_assignment->su, tmp_si_assignment);
  326. }
  327. if (all_confirmed) {
  328. switch (si_assignment->su->restart_control_state) {
  329. case SU_RC_RESTART_COMP_SETTING:
  330. log_printf (LOG_NOTICE, "Component restart recovery finished");
  331. break;
  332. case SU_RC_RESTART_SU_SETTING:
  333. log_printf (LOG_NOTICE, "SU restart recovery finished");
  334. break;
  335. default:
  336. assert (0);
  337. }
  338. si_assignment->su->restart_control_state =
  339. si_assignment->su->escalation_level_history_state;
  340. }
  341. }
  342. static void reassign_sis(struct amf_su *su)
  343. {
  344. struct amf_si_assignment *si_assignment;
  345. ENTER ("");
  346. si_assignment = amf_su_get_next_si_assignment(su, NULL);
  347. while (si_assignment != NULL) {
  348. si_assignment->saAmfSISUHAState = 0; /* unknown */
  349. amf_si_ha_state_assume (si_assignment, si_ha_state_assumed_cbfn);
  350. si_assignment = amf_su_get_next_si_assignment(su, si_assignment);
  351. }
  352. }
  353. static void su_comp_presence_state_changed (
  354. struct amf_su *su, struct amf_comp *comp, int state)
  355. {
  356. ENTER ("'%s', '%s'", su->name.value, comp->name.value);
  357. switch (state) {
  358. case SA_AMF_PRESENCE_INSTANTIATED:
  359. switch (su->restart_control_state) {
  360. case SU_RC_ESCALATION_LEVEL_2:
  361. /*
  362. * TODO: send to node
  363. */
  364. case SU_RC_ESCALATION_LEVEL_0:
  365. if (presence_state_all_comps_in_su_are_set (
  366. comp->su, SA_AMF_PRESENCE_INSTANTIATED)) {
  367. su_presence_state_set (
  368. comp->su, SA_AMF_PRESENCE_INSTANTIATED);
  369. }
  370. break;
  371. case SU_RC_RESTART_COMP_RESTARTING:
  372. su->restart_control_state = SU_RC_RESTART_COMP_SETTING;
  373. reassign_sis (comp->su);
  374. break;
  375. case SU_RC_RESTART_SU_INSTANTIATING:
  376. if (presence_state_all_comps_in_su_are_set (
  377. comp->su, SA_AMF_PRESENCE_INSTANTIATED)) {
  378. su->restart_control_state = SU_RC_RESTART_SU_SETTING;
  379. su_presence_state_set (
  380. comp->su, SA_AMF_PRESENCE_INSTANTIATED);
  381. reassign_sis (comp->su);
  382. }
  383. break;
  384. default:
  385. dprintf ("state %d", su->restart_control_state);
  386. assert (0);
  387. }
  388. break;
  389. case SA_AMF_PRESENCE_UNINSTANTIATED:
  390. if (presence_state_all_comps_in_su_are_set (
  391. su, SA_AMF_PRESENCE_UNINSTANTIATED)) {
  392. su_presence_state_set (comp->su,
  393. SA_AMF_PRESENCE_UNINSTANTIATED);
  394. }
  395. break;
  396. case SA_AMF_PRESENCE_INSTANTIATING:
  397. break;
  398. case SA_AMF_PRESENCE_RESTARTING:
  399. break;
  400. case SA_AMF_PRESENCE_TERMINATING:
  401. break;
  402. default:
  403. assert (0);
  404. }
  405. }
  406. static void su_comp_op_state_changed (
  407. struct amf_su *su, struct amf_comp *comp, int state)
  408. {
  409. ENTER ("'%s', '%s'", su->name.value, comp->name.value);
  410. switch (state) {
  411. case SA_AMF_OPERATIONAL_ENABLED:
  412. {
  413. struct amf_comp *comp_compare;
  414. int all_set = 1;
  415. for (comp_compare = comp->su->comp_head;
  416. comp_compare != NULL; comp_compare = comp_compare->next) {
  417. if (comp_compare->saAmfCompOperState !=
  418. SA_AMF_OPERATIONAL_ENABLED) {
  419. all_set = 0;
  420. break;
  421. }
  422. }
  423. if (all_set) {
  424. su_operational_state_set (comp->su, SA_AMF_OPERATIONAL_ENABLED);
  425. } else {
  426. su_operational_state_set (comp->su, SA_AMF_OPERATIONAL_DISABLED);
  427. }
  428. break;
  429. }
  430. case SA_AMF_OPERATIONAL_DISABLED:
  431. break;
  432. default:
  433. assert (0);
  434. }
  435. }
  436. /**
  437. * Used by a component to report a state change event
  438. * @param su
  439. * @param comp
  440. * @param type type of state
  441. * @param state new state
  442. */
  443. void amf_su_comp_state_changed (
  444. struct amf_su *su, struct amf_comp *comp, SaAmfStateT type, int state)
  445. {
  446. switch (type) {
  447. case SA_AMF_PRESENCE_STATE:
  448. su_comp_presence_state_changed (su, comp, state);
  449. break;
  450. case SA_AMF_OP_STATE:
  451. su_comp_op_state_changed (su, comp, state);
  452. break;
  453. default:
  454. assert (0);
  455. }
  456. }
  457. /**
  458. * Determine if the SU is hosted on the local node.
  459. * @param su
  460. *
  461. * @return int
  462. */
  463. int amf_su_is_local (struct amf_su *su)
  464. {
  465. if (name_match (&this_amf_node->name, &su->saAmfSUHostedByNode)) {
  466. return 1;
  467. } else {
  468. return 0;
  469. }
  470. }
  471. /**
  472. * Called by a component to report a suspected error on a component
  473. * @param su
  474. * @param comp
  475. * @param recommended_recovery
  476. */
  477. void amf_su_comp_error_suspected (
  478. struct amf_su *su,
  479. struct amf_comp *comp,
  480. SaAmfRecommendedRecoveryT recommended_recovery)
  481. {
  482. ENTER ("Comp '%s', SU '%s'", comp->name.value, su->name.value);
  483. /*
  484. * Defer all new events. Workaround to be able to use gdb.
  485. */
  486. if (su->sg->avail_state != SG_AC_Idle) {
  487. ENTER ("Comp '%s', SU '%s'", comp->name.value, su->name.value);
  488. fprintf (stderr, "Warning Debug: event deferred!\n");
  489. return;
  490. }
  491. switch (su->restart_control_state) {
  492. case SU_RC_ESCALATION_LEVEL_0:
  493. if (comp->saAmfCompRestartCount >= su->sg->saAmfSGCompRestartMax) {
  494. su->restart_control_state = SU_RC_ESCALATION_LEVEL_1;
  495. amf_su_comp_error_suspected (su, comp, recommended_recovery);
  496. } else {
  497. comp_restart (comp);
  498. }
  499. break;
  500. case SU_RC_ESCALATION_LEVEL_1:
  501. if (comp->saAmfCompRestartCount >= su->sg->saAmfSGCompRestartMax) {
  502. if (su->saAmfSURestartCount >= su->sg->saAmfSGSuRestartMax) {
  503. su->restart_control_state = SU_RC_ESCALATION_LEVEL_2;
  504. amf_su_comp_error_suspected (su, comp, recommended_recovery);
  505. } else {
  506. su_restart (comp->su);
  507. }
  508. } else {
  509. comp_restart (comp);
  510. }
  511. break;
  512. case SU_RC_ESCALATION_LEVEL_2:
  513. if (su->saAmfSURestartCount >= su->sg->saAmfSGSuRestartMax) {
  514. /*
  515. * TODO: delegate to node
  516. */
  517. struct amf_si_assignment *si_assignment =
  518. amf_su_get_next_si_assignment (su, NULL);
  519. if (si_assignment->saAmfSISUHAState == SA_AMF_HA_ACTIVE) {
  520. SaNameT dn;
  521. su_operational_state_set (su, SA_AMF_OPERATIONAL_DISABLED);
  522. amf_comp_operational_state_set (
  523. comp, SA_AMF_OPERATIONAL_DISABLED);
  524. amf_comp_dn_make (comp, &dn);
  525. log_printf (LOG_NOTICE, "Error detected for '%s', recovery "
  526. "action:\n\t\tSU failover", dn.value);
  527. amf_sg_failover_su_req (comp->su->sg, comp->su, this_amf_node);
  528. return;
  529. } else {
  530. su_restart (comp->su);
  531. }
  532. } else {
  533. su_restart (comp->su);
  534. }
  535. break;
  536. default:
  537. assert (0);
  538. }
  539. }
  540. void amf_su_init (void)
  541. {
  542. log_init ("AMF");
  543. }
  544. void amf_su_terminate (struct amf_su *su)
  545. {
  546. struct amf_comp *comp;
  547. ENTER ("'%s'", su->name.value);
  548. for (comp = su->comp_head; comp != NULL; comp = comp->next) {
  549. /*
  550. * Terminate all components in SU abruptly
  551. */
  552. comp->error_suspected = 1;
  553. amf_comp_terminate (comp);
  554. }
  555. }
  556. char *amf_su_dn_make (struct amf_su *su, SaNameT *name)
  557. {
  558. int i = snprintf((char*) name->value, SA_MAX_NAME_LENGTH,
  559. "safSu=%s,safSg=%s,safApp=%s",
  560. su->name.value, su->sg->name.value, su->sg->application->name.value);
  561. assert (i <= SA_MAX_NAME_LENGTH);
  562. name->length = i;
  563. return (char *)name->value;
  564. }
  565. struct amf_si_assignment *amf_su_get_next_si_assignment (
  566. struct amf_su *su, const struct amf_si_assignment *si_assignment)
  567. {
  568. struct amf_si *si;
  569. struct amf_si_assignment *tmp_si_assignment;
  570. SaNameT dn;
  571. amf_su_dn_make (su, &dn);
  572. if (si_assignment == NULL) {
  573. si = su->sg->application->si_head;
  574. tmp_si_assignment = si->assigned_sis;
  575. } else {
  576. tmp_si_assignment = si_assignment->next;
  577. if (tmp_si_assignment == NULL) {
  578. si = si_assignment->si->next;
  579. if (si == NULL) {
  580. return NULL;
  581. } else {
  582. tmp_si_assignment = si->assigned_sis;
  583. }
  584. } else {
  585. si = tmp_si_assignment->si;
  586. }
  587. }
  588. for (; si != NULL; si = si->next) {
  589. if (tmp_si_assignment == NULL && si != NULL) {
  590. tmp_si_assignment = si->assigned_sis;
  591. }
  592. for (; tmp_si_assignment != NULL;
  593. tmp_si_assignment = tmp_si_assignment->next) {
  594. if (name_match (&tmp_si_assignment->name, &dn)) {
  595. return tmp_si_assignment;
  596. }
  597. }
  598. }
  599. return NULL;
  600. }
  601. void amf_su_foreach_si_assignment (
  602. struct amf_su *su,
  603. void (*foreach_fn)(struct amf_su *su,
  604. struct amf_si_assignment *si_assignment))
  605. {
  606. struct amf_si_assignment *si_assignment;
  607. assert (foreach_fn != NULL);
  608. si_assignment = amf_su_get_next_si_assignment (su, NULL);
  609. while (si_assignment != NULL) {
  610. foreach_fn (su, si_assignment);
  611. si_assignment = amf_su_get_next_si_assignment (su, si_assignment);
  612. }
  613. }
  614. int amf_su_get_saAmfSUNumCurrActiveSIs(struct amf_su *su)
  615. {
  616. int cnt = 0;
  617. struct amf_si_assignment *si_assignment;
  618. si_assignment = amf_su_get_next_si_assignment (su, NULL);
  619. while (si_assignment != NULL) {
  620. if (su->sg->avail_state == SG_AC_AssigningOnRequest &&
  621. si_assignment->requested_ha_state == SA_AMF_HA_ACTIVE) {
  622. cnt++;
  623. } else {
  624. if (si_assignment->saAmfSISUHAState == SA_AMF_HA_ACTIVE) {
  625. cnt++;
  626. }
  627. }
  628. si_assignment = amf_su_get_next_si_assignment (su, si_assignment);
  629. }
  630. return cnt;
  631. }
  632. int amf_su_get_saAmfSUNumCurrStandbySIs(struct amf_su *su)
  633. {
  634. int cnt = 0;
  635. struct amf_si_assignment *si_assignment;
  636. si_assignment = amf_su_get_next_si_assignment (su, NULL);
  637. while (si_assignment != NULL) {
  638. if (su->sg->avail_state == SG_AC_AssigningOnRequest &&
  639. si_assignment->requested_ha_state == SA_AMF_HA_STANDBY) {
  640. cnt++;
  641. } else {
  642. if (si_assignment->saAmfSISUHAState == SA_AMF_HA_STANDBY) {
  643. cnt++;
  644. }
  645. }
  646. si_assignment = amf_su_get_next_si_assignment (su, si_assignment);
  647. }
  648. return cnt;
  649. }
  650. SaAmfReadinessStateT amf_su_get_saAmfSUReadinessState (struct amf_su *su)
  651. {
  652. if ((su->saAmfSUOperState == SA_AMF_OPERATIONAL_ENABLED) &&
  653. ((su->saAmfSUPresenceState == SA_AMF_PRESENCE_INSTANTIATED) ||
  654. (su->saAmfSUPresenceState == SA_AMF_PRESENCE_RESTARTING))) {
  655. return SA_AMF_READINESS_IN_SERVICE;
  656. } else if (su->saAmfSUOperState == SA_AMF_OPERATIONAL_ENABLED) {
  657. return SA_AMF_READINESS_STOPPING;
  658. } else {
  659. return SA_AMF_READINESS_OUT_OF_SERVICE;
  660. }
  661. }