2 * Copyright (c) 2002-2003 MontaVista Software, Inc.
6 * Author: Steven Dake (sdake@mvista.com)
8 * This software licensed under BSD license, the text of which follows:
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
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.
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.
40 #include <sys/types.h>
41 #include <sys/socket.h>
45 #include "ais_types.h"
50 SaAmfHealthcheckKeyT key0
= {
54 SaNameT compNameGlobal
;
56 void printSaNameT (SaNameT
*name
)
60 for (i
= 0; i
< name
->length
; i
++) {
61 printf ("%c", name
->value
[i
]);
65 void setSanameT (SaNameT
*name
, char *str
) {
66 name
->length
= strlen (str
);
67 memcpy (name
->value
, str
, name
->length
);
70 static int health_flag
= -1;
71 static unsigned int healthcheck_count
= 0;
72 static unsigned int healthcheck_no
= 0;
75 void HealthcheckCallback (SaInvocationT invocation
,
76 const SaNameT
*compName
,
77 SaAmfHealthcheckKeyT
*healthcheckKey
)
82 printf ("Healthcheck %u for key '%s' for component ",
83 healthcheck_no
, healthcheckKey
->key
);
85 printSaNameT ((SaNameT
*)compName
);
87 res
= saAmfResponse (handle
, invocation
, SA_AIS_OK
);
89 printf ("response res is %d\n", res
);
91 if (healthcheck_no
== 20) {
92 res
= saAmfHealthcheckStop (handle
, &compNameGlobal
, &key0
);
95 printf ("done res = %d\n", res
);
100 void ComponentTerminateCallback (
101 SaInvocationT invocation
,
102 const SaNameT
*compName
)
104 printf ("ComponentTerminateCallback\n");
108 void CSISetCallback (
109 SaInvocationT invocation
,
110 const SaNameT
*compName
,
111 SaAmfHAStateT haState
,
112 SaAmfCSIDescriptorT
*csiDescriptor
)
116 case SA_AMF_HA_ACTIVE
:
117 printf ("CSISetCallback:");
118 printf ("for CSI '");
119 printSaNameT ((SaNameT
*)&csiDescriptor
->csiName
);
120 printf ("' for component ");
121 printSaNameT ((SaNameT
*)compName
);
123 printf (" requested to enter hastate SA_AMF_ACTIVE.\n");
124 res
= saAmfResponse (handle
, invocation
, SA_AIS_OK
);
127 case SA_AMF_HA_STANDBY
:
128 printf ("CSISetCallback:");
129 printf ("for CSI '");
130 printSaNameT ((SaNameT
*)compName
);
131 printf ("' for component ");
132 printSaNameT ((SaNameT
*)compName
);
134 printf (" requested to enter hastate SA_AMF_STANDBY.\n");
135 saAmfResponse (handle
, invocation
, SA_AIS_OK
);
141 void CSIRemoveCallback (
142 SaInvocationT invocation
,
143 const SaNameT
*compName
,
144 const SaNameT
*csiName
,
145 const SaAmfCSIFlagsT
*csiFlags
)
147 printf ("CSIRemoveCallback for component '");
148 printSaNameT ((SaNameT
*)compName
);
149 printf ("' in CSI '");
150 printSaNameT ((SaNameT
*)csiName
);
152 saAmfResponse (invocation
, SA_OK
);
155 void ProtectionGroupTrackCallback (
156 const SaNameT
*csiName
,
157 SaAmfProtectionGroupNotificationT
*notificationBuffer
,
158 SaUint32T numberOfItems
,
159 SaUint32T numberOfMembers
,
164 printf ("ProtectionGroupTrackCallback items %d members %d\n", (int)numberOfItems
, (int)numberOfMembers
);
165 printf ("buffer is %p\n", notificationBuffer
);
166 for (i
= 0; i
< numberOfItems
; i
++) {
167 printf ("component name");
168 printSaNameT (¬ificationBuffer
[i
].member
.compName
);
170 printf ("\treadiness state is %d\n", notificationBuffer
[i
].member
.readinessState
);
171 printf ("\thastate %d\n", notificationBuffer
[i
].member
.haState
);
172 printf ("\tchange is %d\n", notificationBuffer
[i
].change
);
177 void ExternalComponentRestartCallback (
178 const SaInvocationT invocation
,
179 const SaNameT
*externalCompName
)
181 printf ("ExternalComponentRestartCallback\n");
184 void ExternalComponentControlCallback (
185 const SaInvocationT invocation
,
186 const SaNameT
*externalCompName
,
187 SaAmfExternalComponentActionT controlAction
)
189 printf ("ExternalComponentControlCallback\n");
192 void PendingOperationConfirmCallback (
193 const SaInvocationT invocation
,
194 const SaNameT
*compName
,
195 SaAmfPendingOperationFlagsT pendingOperationFlags
)
197 printf ("PendingOperationConfirmCallback\n");
200 void PendingOperationExpiredCallback (
201 const SaNameT
*compName
,
202 SaAmfPendingOperationFlagsT pendingOperationFlags
)
204 printf ("PendingOperationExpiredCallback\n");
208 SaAmfCallbacksT amfCallbacks
= {
209 .saAmfHealthcheckCallback
= HealthcheckCallback
,
210 .saAmfCSISetCallback
= CSISetCallback
,
213 SaAmfCallbacksT amfCallbacks
;
215 SaVersionT version
= { 'B', 1, 1 };
217 #if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
218 static struct sched_param sched_param
= {
223 void sigintr_handler (int signum
) {
227 int main (int argc
, char **argv
) {
229 SaSelectionObjectT select_fd
;
235 memset (&compNameGlobal
, 0, sizeof (SaNameT
));
236 signal (SIGINT
, sigintr_handler
);
237 #if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
238 result
= sched_setscheduler (0, SCHED_RR
, &sched_param
);
240 printf ("couldn't set sched priority\n");
245 c
= getopt(argc
,argv
,"h:n:");
254 sscanf (optarg
,"%ud" ,&healthcheck_count
);
257 setSanameT (&compNameGlobal
, optarg
);
264 result
= saAmfInitialize (&handle
, &amfCallbacks
, &version
);
265 if (result
!= SA_OK
) {
266 printf ("initialize result is %d\n", result
);
271 saAmfSelectionObjectGet (handle
, &select_fd
);
272 FD_SET (select_fd
, &read_fds
);
273 if (compNameGlobal
.length
<= 0) {
274 setSanameT (&compNameGlobal
, "comp_b_in_su_2");
277 result
= saAmfHealthcheckStart (handle
,
280 SA_AMF_HEALTHCHECK_AMF_INVOKED
,
281 SA_AMF_COMPONENT_FAILOVER
);
282 printf ("start %d\n", result
);
284 result
= saAmfHealthcheckStart (handle
,
287 SA_AMF_HEALTHCHECK_AMF_INVOKED
,
288 SA_AMF_COMPONENT_FAILOVER
);
289 printf ("start %d\n", result
);
290 result
= saAmfComponentRegister (handle
, &compNameGlobal
, NULL
);
291 printf ("register result is %d (should be 1)\n", result
);
294 select (select_fd
+ 1, &read_fds
, 0, 0, 0);
295 saAmfDispatch (handle
, SA_DISPATCH_ALL
);
296 } while (result
&& stop
== 0);
299 result
= saAmfHealthcheckStart (handle
,
302 SA_AMF_HEALTHCHECK_AMF_INVOKED
,
303 SA_AMF_COMPONENT_FAILOVER
);
306 select (select_fd
+ 1, &read_fds
, 0, 0, 0);
307 saAmfDispatch (handle
, SA_DISPATCH_ALL
);
310 saAmfFinalize (handle
);