testamf.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /*
  2. * Copyright (c) 2002-2003 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@redhat.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 <stdio.h>
  35. #include <stdlib.h>
  36. #include <errno.h>
  37. #include <sys/types.h>
  38. #include <sys/socket.h>
  39. #include <sys/un.h>
  40. #include <unistd.h>
  41. #include <signal.h>
  42. #include "ais_types.h"
  43. #include "ais_amf.h"
  44. #include "saClm.h"
  45. void printSaClmNodeAddressT (SaClmNodeAddressT *nodeAddress) {
  46. int i;
  47. for (i = 0; i < nodeAddress->length; i++) {
  48. printf ("%d.", nodeAddress->value[i]);
  49. }
  50. }
  51. void printSaNameT (SaNameT *name)
  52. {
  53. int i;
  54. for (i = 0; i < name->length; i++) {
  55. printf ("%c", name->value[i]);
  56. }
  57. }
  58. void setSanameT (SaNameT *name, char *str) {
  59. name->length = strlen (str);
  60. memcpy (name->value, str, name->length);
  61. }
  62. static int health_flag = -1;
  63. static unsigned int healthcheck_count = 0;
  64. static unsigned int healthcheck_no = 0;
  65. void HealthcheckCallback (SaInvocationT invocation,
  66. const SaNameT *compName,
  67. SaAmfHealthcheckT checkType)
  68. {
  69. SaErrorT res;
  70. healthcheck_no ++;
  71. if (health_flag == -1 || healthcheck_no%healthcheck_count == 0) {
  72. printf ("%u HealthcheckCallback have occured for component: ",healthcheck_no);
  73. printSaNameT ((SaNameT *)compName);
  74. printf ("\n");
  75. }
  76. res = saAmfResponse (invocation, SA_OK);
  77. if (res != SA_OK) {
  78. printf ("response res is %d\n", res);
  79. }
  80. }
  81. void ReadinessStateSetCallback (SaInvocationT invocation,
  82. const SaNameT *compName,
  83. SaAmfReadinessStateT readinessState)
  84. {
  85. switch (readinessState) {
  86. case SA_AMF_IN_SERVICE:
  87. printf ("ReadinessStateSetCallback: '");
  88. printSaNameT ((SaNameT *)compName);
  89. printf ("' requested to enter operational state SA_AMF_IN_SERVICE.\n");
  90. saAmfResponse (invocation, SA_OK);
  91. break;
  92. case SA_AMF_OUT_OF_SERVICE:
  93. printf ("ReadinessStateSetCallback: '");
  94. printSaNameT ((SaNameT *)compName);
  95. printf ("' requested to enter operational state SA_AMF_OUT_OF_SERVICE.\n");
  96. saAmfResponse (invocation, SA_OK);
  97. break;
  98. case SA_AMF_STOPPING:
  99. printf ("ReadinessStateSetCallback: '");
  100. printSaNameT ((SaNameT *)compName);
  101. printf ("' requested to stop, stopping.\n");
  102. saAmfStoppingComplete (invocation, SA_OK);
  103. break;
  104. }
  105. }
  106. void ComponentTerminateCallback (
  107. SaInvocationT invocation,
  108. const SaNameT *compName)
  109. {
  110. printf ("ComponentTerminateCallback\n");
  111. }
  112. void CSISetCallback (
  113. SaInvocationT invocation,
  114. const SaNameT *compName,
  115. const SaNameT *csiName,
  116. SaAmfCSIFlagsT csiFlags,
  117. SaAmfHAStateT *haState,
  118. SaNameT *activeCompName,
  119. SaAmfCSITransitionDescriptorT transitionDescriptor)
  120. {
  121. switch (*haState) {
  122. case SA_AMF_ACTIVE:
  123. printf ("CSISetCallback: '");
  124. printSaNameT ((SaNameT *)compName);
  125. printf ("' for CSI '");
  126. printSaNameT ((SaNameT *)compName);
  127. printf ("'");
  128. printf (" requested to enter hastate SA_AMF_ACTIVE.\n");
  129. saAmfResponse (invocation, SA_OK);
  130. break;
  131. case SA_AMF_STANDBY:
  132. printf ("CSISetCallback: '");
  133. printSaNameT ((SaNameT *)compName);
  134. printf ("' for CSI '");
  135. printSaNameT ((SaNameT *)compName);
  136. printf ("'");
  137. printf (" requested to enter hastate SA_AMF_STANDBY.\n");
  138. saAmfResponse (invocation, SA_OK);
  139. break;
  140. case SA_AMF_QUIESCED:
  141. printf ("CSISetCallback: '");
  142. printSaNameT ((SaNameT *)compName);
  143. printf ("' for CSI '");
  144. printSaNameT ((SaNameT *)compName);
  145. printf ("'");
  146. printf (" requested to enter hastate SA_AMF_QUIESCED.\n");
  147. saAmfResponse (invocation, SA_OK);
  148. break;
  149. }
  150. }
  151. void CSIRemoveCallback (
  152. SaInvocationT invocation,
  153. const SaNameT *compName,
  154. const SaNameT *csiName,
  155. const SaAmfCSIFlagsT *csiFlags)
  156. {
  157. printf ("CSIRemoveCallback invocation id %llu compName ",
  158. (unsigned long long)invocation);
  159. printSaNameT ((SaNameT *)compName);
  160. printf (" csiName ");
  161. printSaNameT ((SaNameT *)csiName);
  162. printf ("\n");
  163. saAmfResponse (invocation, SA_OK);
  164. }
  165. void ProtectionGroupTrackCallback (
  166. const SaNameT *csiName,
  167. SaAmfProtectionGroupNotificationT *notificationBuffer,
  168. SaUint32T numberOfItems,
  169. SaUint32T numberOfMembers,
  170. SaErrorT error)
  171. {
  172. int i;
  173. printf ("ProtectionGroupTrackCallback items %d members %d\n", (int)numberOfItems, (int)numberOfMembers);
  174. printf ("buffer is %p\n", notificationBuffer);
  175. for (i = 0; i < numberOfItems; i++) {
  176. printf ("component name");
  177. printSaNameT (&notificationBuffer[i].member.compName);
  178. printf ("\n");
  179. printf ("\treadiness state is %d\n", notificationBuffer[i].member.readinessState);
  180. printf ("\thastate %d\n", notificationBuffer[i].member.haState);
  181. printf ("\tchange is %d\n", notificationBuffer[i].change);
  182. }
  183. }
  184. void ExternalComponentRestartCallback (
  185. const SaInvocationT invocation,
  186. const SaNameT *externalCompName)
  187. {
  188. printf ("ExternalComponentRestartCallback\n");
  189. }
  190. void ExternalComponentControlCallback (
  191. const SaInvocationT invocation,
  192. const SaNameT *externalCompName,
  193. SaAmfExternalComponentActionT controlAction)
  194. {
  195. printf ("ExternalComponentControlCallback\n");
  196. }
  197. void PendingOperationConfirmCallback (
  198. const SaInvocationT invocation,
  199. const SaNameT *compName,
  200. SaAmfPendingOperationFlagsT pendingOperationFlags)
  201. {
  202. printf ("PendingOperationConfirmCallback\n");
  203. }
  204. void PendingOperationExpiredCallback (
  205. const SaNameT *compName,
  206. SaAmfPendingOperationFlagsT pendingOperationFlags)
  207. {
  208. printf ("PendingOperationExpiredCallback\n");
  209. }
  210. SaAmfCallbacksT amfCallbacks = {
  211. HealthcheckCallback,
  212. ReadinessStateSetCallback,
  213. ComponentTerminateCallback,
  214. CSISetCallback,
  215. CSIRemoveCallback,
  216. ProtectionGroupTrackCallback,
  217. ExternalComponentRestartCallback,
  218. ExternalComponentControlCallback,
  219. PendingOperationConfirmCallback,
  220. PendingOperationExpiredCallback
  221. };
  222. SaVersionT version = { 'A', 1, 1 };
  223. void sigintr_handler (int signum) {
  224. exit (0);
  225. }
  226. int main (int argc, char **argv) {
  227. SaAmfHandleT handle;
  228. SaAmfHandleT handleproxy;
  229. int result;
  230. SaSelectionObjectT select_fd;
  231. fd_set read_fds;
  232. SaNameT compName;
  233. SaNameT csiName;
  234. SaNameT compname_get_name;
  235. SaAmfReadinessStateT readinessState;
  236. SaAmfHAStateT HAState;
  237. SaAmfComponentCapabilityModelT componentCapabilityModel;
  238. SaAmfProtectionGroupNotificationT protectionGroupNotificationBuffer[64];
  239. SaAmfPendingOperationFlagsT pending_operation;
  240. extern char *optarg;
  241. extern int optind;
  242. int c;
  243. signal (SIGINT, sigintr_handler);
  244. for (;;) {
  245. c = getopt(argc,argv,"h:");
  246. if (c==-1) {
  247. break;
  248. }
  249. switch (c) {
  250. case 0 :
  251. break;
  252. case 'h':
  253. health_flag = 0;
  254. sscanf (optarg,"%ud" ,&healthcheck_count);
  255. break;
  256. default :
  257. break;
  258. }
  259. }
  260. result = saAmfInitialize (&handle, &amfCallbacks, &version);
  261. if (result != SA_OK) {
  262. printf ("initialize result is %d\n", result);
  263. exit (1);
  264. }
  265. result = saAmfInitialize (&handleproxy, &amfCallbacks, &version);
  266. if (result != SA_OK) {
  267. printf ("initialize result is %d\n", result);
  268. exit (1);
  269. }
  270. FD_ZERO (&read_fds);
  271. saAmfSelectionObjectGet (&handle, &select_fd);
  272. FD_SET (select_fd, &read_fds);
  273. saAmfSelectionObjectGet (&handleproxy, &select_fd);
  274. FD_SET (select_fd, &read_fds);
  275. setSanameT (&compName, "comp_a_in_su_x");
  276. setSanameT (&csiName, "pgA");
  277. result = saAmfComponentRegister (&handle, &compName, NULL);
  278. printf ("saAmfComponentRegister with result %d (should be 1) is:", result);
  279. result = saAmfCompNameGet (&handle, &compname_get_name);
  280. printf ("saAmfCompNameGet with result %d (should be 1) is:", result);
  281. printSaNameT (&compname_get_name);
  282. printf ("\n");
  283. result = saAmfPendingOperationGet (&compName, &pending_operation);
  284. printf ("saAmfPendingOperationGet with value %d result %d (should be 1) is:",
  285. pending_operation, result);
  286. result = saAmfComponentCapabilityModelGet (&compName, &componentCapabilityModel);
  287. printf ("component capability model get is %d (should be 1)\n", result);
  288. result = saAmfProtectionGroupTrack (&handle, &csiName, SA_TRACK_CURRENT | SA_TRACK_CHANGES, protectionGroupNotificationBuffer, 64);
  289. printf ("track start result is %d (should be 1)\n", result);
  290. result = saAmfProtectionGroupTrackStop (&handle, &csiName);
  291. printf ("track stop result is %d (should be 1)\n", result);
  292. result = saAmfReadinessStateGet (&compName, &readinessState);
  293. printf ("saAmfReadinessStateGet (%d) result %d (should be 1)\n",
  294. readinessState, result);
  295. result = saAmfHAStateGet (&compName, &csiName, &HAState);
  296. printf ("saAmfHAStateGet (%d) result %d (should be 1)\n",
  297. HAState, result);
  298. do {
  299. FD_SET (STDIN_FILENO, &read_fds);
  300. select (select_fd + 1, &read_fds, 0, 0, 0);
  301. if (FD_ISSET (STDIN_FILENO, &read_fds)) {
  302. break;
  303. }
  304. saAmfDispatch (&handle, SA_DISPATCH_ALL);
  305. } while (result);
  306. result = saAmfProtectionGroupTrackStop (&handle, &csiName);
  307. saAmfFinalize (&handle);
  308. return (0);
  309. }