amfapp.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. /* TODO: Calculate and set SI dependency levels */
  98. for (sg = app->sg_head; sg != NULL; sg = sg->next) {
  99. amf_sg_start (sg, node);
  100. }
  101. }
  102. void amf_application_assign_workload (
  103. struct amf_application *app, struct amf_node *node)
  104. {
  105. struct amf_sg *sg;
  106. /*
  107. * TODO: dependency level ignored
  108. * Each dependency level should be looped and amf_sg_assign_si
  109. * called several times.
  110. */
  111. for (sg = app->sg_head; sg != NULL; sg = sg->next) {
  112. amf_sg_assign_si (sg, 0);
  113. }
  114. }
  115. void amf_application_init (void)
  116. {
  117. log_init ("AMF");
  118. }
  119. void amf_application_sg_started (
  120. struct amf_application *app, struct amf_sg *sg, struct amf_node *node)
  121. {
  122. ENTER ("'%s'", app->name.value);
  123. if (all_sg_started (app)) {
  124. amf_cluster_application_started (app->cluster, app);
  125. }
  126. }
  127. void amf_application_sg_assigned (
  128. struct amf_application *app, struct amf_sg *sg)
  129. {
  130. ENTER ("'%s'", app->name.value);
  131. amf_cluster_application_workload_assigned (app->cluster, app);
  132. }
  133. struct amf_application *amf_application_new (struct amf_cluster *cluster)
  134. {
  135. struct amf_application *app = amf_malloc (sizeof (struct amf_application));
  136. app->cluster = cluster;
  137. app->next = cluster->application_head;
  138. cluster->application_head = app;
  139. app->sg_head = NULL;
  140. app->si_head = NULL;
  141. return app;
  142. }
  143. void amf_application_delete (struct amf_application *app)
  144. {
  145. struct amf_sg *sg;
  146. struct amf_si *si;
  147. for (sg = app->sg_head; sg != NULL;) {
  148. struct amf_sg *tmp = sg;
  149. sg = sg->next;
  150. amf_sg_delete (tmp);
  151. }
  152. for (si = app->si_head; si != NULL;) {
  153. struct amf_si *tmp = si;
  154. si = si->next;
  155. amf_si_delete (tmp);
  156. }
  157. free (app);
  158. }
  159. void *amf_application_serialize (
  160. struct amf_application *app, int *len)
  161. {
  162. char *buf = NULL;
  163. int offset = 0, size = 0;
  164. TRACE8 ("%s", app->name.value);
  165. buf = amf_serialize_SaNameT (buf, &size, &offset, &app->name);
  166. buf = amf_serialize_SaUint32T (
  167. buf, &size, &offset, app->saAmfApplicationAdminState);
  168. buf = amf_serialize_SaUint32T (
  169. buf, &size, &offset, app->saAmfApplicationCurrNumSG);
  170. buf = amf_serialize_SaStringT (
  171. buf, &size, &offset, app->clccli_path);
  172. *len = offset;
  173. return buf;
  174. }
  175. struct amf_application *amf_application_deserialize (
  176. struct amf_cluster *cluster, char *buf, int size)
  177. {
  178. char *tmp = buf;
  179. struct amf_application *app;
  180. app = amf_application_new (cluster);
  181. tmp = amf_deserialize_SaNameT (tmp, &app->name);
  182. tmp = amf_deserialize_SaUint32T (tmp, &app->saAmfApplicationAdminState);
  183. tmp = amf_deserialize_SaUint32T (tmp, &app->saAmfApplicationCurrNumSG);
  184. tmp = amf_deserialize_SaStringT (tmp, &app->clccli_path);
  185. return app;
  186. }
  187. struct amf_application *amf_application_find (
  188. struct amf_cluster *cluster, char *name)
  189. {
  190. struct amf_application *app;
  191. ENTER ("%s", name);
  192. for (app = cluster->application_head; app != NULL; app = app->next) {
  193. if (strncmp (name, (char*)app->name.value, app->name.length) == 0) {
  194. break;
  195. }
  196. }
  197. return app;
  198. }