amfapp.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /** @file amfapp.c
  2. *
  3. * Copyright (c) 2006 Ericsson AB.
  4. * Author: Hans Feldt, Anders Eriksson, Lars Holm
  5. * - Refactoring of code into several AMF files
  6. * - Constructors/destructors
  7. * - Serializers/deserializers
  8. *
  9. * All rights reserved.
  10. *
  11. *
  12. * This software licensed under BSD license, the text of which follows:
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice,
  18. * this list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  23. * contributors may be used to endorse or promote products derived from this
  24. * software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  36. * THE POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * AMF Application Class implementation
  39. *
  40. * This file contains functions for handling the AMF applications. It can
  41. * be viewed as the implementation of the AMF Application class
  42. * as described in SAI-Overview-B.02.01. The SA Forum specification
  43. * SAI-AIS-AMF-B.02.01 has been used as specification of the behaviour
  44. * and is referred to as 'the spec' below.
  45. *
  46. * The functions in this file are responsible for:
  47. * - on request start the service groups it contains
  48. * - on request order the service groups to assign workload to all
  49. * service units contained in the service group, level by level
  50. * - to handle administrative operation support for the application (FUTURE)
  51. *
  52. * The cluster class contains the following state machines:
  53. * - administrative state machine (ADSM)
  54. * - availability control state machine (ACSM)
  55. *
  56. * The administrative state machine will be implemented in the future.
  57. *
  58. * ACSM handles initial start of an application. In the future it will also
  59. * handle administrative commands on the application as described in paragraph
  60. * 7.4 of the spec. ACSM includes two stable states (UNINSTANTIATED and
  61. * STARTED) and a number of states to control the transition between the
  62. * stable states.
  63. *
  64. * The application is in state UNINSTANTIATED when the application starts.
  65. * (In the future this state will also be assumed after the LOCK_INSTANTIATION
  66. * administrative command.)
  67. *
  68. * State STARTED is assumed when the application has been initially started and
  69. * will in the future be re-assumed after the administrative command RESTART
  70. * have been executed.
  71. *
  72. */
  73. #include <assert.h>
  74. #include "amf.h"
  75. #include "print.h"
  76. static int all_sg_started (struct amf_application *app)
  77. {
  78. struct amf_sg *sg;
  79. struct amf_su *su;
  80. int all_su_instantiated = 1;
  81. /* TODO: spare SUs... */
  82. for (sg = app->sg_head; sg != NULL; sg = sg->next) {
  83. for (su = sg->su_head; su != NULL; su = su->next) {
  84. if (su->saAmfSUPresenceState != SA_AMF_PRESENCE_INSTANTIATED) {
  85. all_su_instantiated = 0;
  86. break;
  87. }
  88. }
  89. }
  90. return all_su_instantiated;
  91. }
  92. void amf_application_start (
  93. struct amf_application *app, struct amf_node *node)
  94. {
  95. struct amf_sg *sg;
  96. ENTER ("'%s'", app->name.value);
  97. app->node_to_start = node;
  98. /* TODO: Calculate and set SI dependency levels */
  99. for (sg = app->sg_head; sg != NULL; sg = sg->next) {
  100. amf_sg_start (sg, node);
  101. }
  102. }
  103. void amf_application_assign_workload (
  104. struct amf_application *app, struct amf_node *node)
  105. {
  106. struct amf_sg *sg;
  107. /*
  108. * TODO: dependency level ignored
  109. * Each dependency level should be looped and amf_sg_assign_si
  110. * called several times.
  111. */
  112. app->node_to_start = node;
  113. for (sg = app->sg_head; sg != NULL; sg = sg->next) {
  114. amf_sg_assign_si (sg, 0);
  115. }
  116. }
  117. void amf_application_init (void)
  118. {
  119. log_init ("AMF");
  120. }
  121. void amf_application_sg_started (
  122. struct amf_application *app, struct amf_sg *sg, struct amf_node *node)
  123. {
  124. ENTER ("'%s'", app->name.value);
  125. if (all_sg_started (app)) {
  126. if (app->node_to_start == NULL) {
  127. amf_cluster_application_started (app->cluster, app);
  128. } else {
  129. amf_node_application_started (app->node_to_start, app);
  130. }
  131. }
  132. }
  133. void amf_application_sg_assigned (
  134. struct amf_application *app, struct amf_sg *sg)
  135. {
  136. ENTER ("'%s'", app->name.value);
  137. if (app->node_to_start == NULL) {
  138. amf_cluster_application_workload_assigned (app->cluster, app);
  139. } else {
  140. amf_node_application_workload_assigned (app->node_to_start, app);
  141. }
  142. }
  143. struct amf_application *amf_application_new (struct amf_cluster *cluster)
  144. {
  145. struct amf_application *app = amf_malloc (sizeof (struct amf_application));
  146. app->cluster = cluster;
  147. app->next = cluster->application_head;
  148. cluster->application_head = app;
  149. app->sg_head = NULL;
  150. app->si_head = NULL;
  151. return app;
  152. }
  153. void amf_application_delete (struct amf_application *app)
  154. {
  155. struct amf_sg *sg;
  156. struct amf_si *si;
  157. for (sg = app->sg_head; sg != NULL;) {
  158. struct amf_sg *tmp = sg;
  159. sg = sg->next;
  160. amf_sg_delete (tmp);
  161. }
  162. for (si = app->si_head; si != NULL;) {
  163. struct amf_si *tmp = si;
  164. si = si->next;
  165. amf_si_delete (tmp);
  166. }
  167. free (app);
  168. }
  169. void *amf_application_serialize (
  170. struct amf_application *app, int *len)
  171. {
  172. char *buf = NULL;
  173. int offset = 0, size = 0;
  174. TRACE8 ("%s", app->name.value);
  175. buf = amf_serialize_SaNameT (buf, &size, &offset, &app->name);
  176. buf = amf_serialize_SaUint32T (
  177. buf, &size, &offset, app->saAmfApplicationAdminState);
  178. buf = amf_serialize_SaUint32T (
  179. buf, &size, &offset, app->saAmfApplicationCurrNumSG);
  180. buf = amf_serialize_SaStringT (
  181. buf, &size, &offset, app->clccli_path);
  182. *len = offset;
  183. return buf;
  184. }
  185. struct amf_application *amf_application_deserialize (
  186. struct amf_cluster *cluster, char *buf, int size)
  187. {
  188. char *tmp = buf;
  189. struct amf_application *app;
  190. app = amf_application_new (cluster);
  191. tmp = amf_deserialize_SaNameT (tmp, &app->name);
  192. tmp = amf_deserialize_SaUint32T (tmp, &app->saAmfApplicationAdminState);
  193. tmp = amf_deserialize_SaUint32T (tmp, &app->saAmfApplicationCurrNumSG);
  194. tmp = amf_deserialize_SaStringT (tmp, &app->clccli_path);
  195. return app;
  196. }
  197. struct amf_application *amf_application_find (
  198. struct amf_cluster *cluster, char *name)
  199. {
  200. struct amf_application *app;
  201. for (app = cluster->application_head; app != NULL; app = app->next) {
  202. if (strncmp (name, (char*)app->name.value, app->name.length) == 0) {
  203. break;
  204. }
  205. }
  206. if (app == NULL) {
  207. dprintf ("App %s not found!", name);
  208. }
  209. return app;
  210. }