2 * Copyright (c) 2002-2003 MontaVista Software, Inc.
3 * Copyright (c) 2006 Sun Microsystems, Inc.
7 * Author: Steven Dake (sdake@mvista.com)
9 * This software licensed under BSD license, the text of which follows:
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
14 * - Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * - Neither the name of the MontaVista Software, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived from this
21 * software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33 * THE POSSIBILITY OF SUCH DAMAGE.
41 #include <sys/types.h>
42 #include <sys/socket.h>
51 SaAmfHealthcheckKeyT key0
= {
55 SaNameT compNameGlobal
;
57 void printSaNameT (SaNameT
*name
)
61 for (i
= 0; i
< name
->length
; i
++) {
62 printf ("%c", name
->value
[i
]);
66 void setSanameT (SaNameT
*name
, char *str
) {
67 name
->length
= strlen (str
);
68 memcpy (name
->value
, str
, name
->length
);
71 static int health_flag
= -1;
72 static unsigned int healthcheck_count
= 0;
73 static unsigned int healthcheck_no
= 0;
77 void HealthcheckCallback (SaInvocationT invocation
,
78 const SaNameT
*compName
,
79 SaAmfHealthcheckKeyT
*healthcheckKey
)
85 printf ("Healthcheck %u for key '%s' for component ",
86 healthcheck_no, healthcheckKey->key);
88 printSaNameT ((SaNameT *)compName);
91 res
= saAmfResponse (handle
, invocation
, SA_AIS_OK
);
92 if (healthcheck_no
== 3) {
93 res
= saAmfHealthcheckStop (handle
, &compNameGlobal
, &key0
);
98 void ComponentTerminateCallback (
99 SaInvocationT invocation
,
100 const SaNameT
*compName
)
102 printf ("ComponentTerminateCallback\n");
103 saAmfResponse (handle
, invocation
, SA_AIS_OK
);
107 void CSISetCallback (
108 SaInvocationT invocation
,
109 const SaNameT
*compName
,
110 SaAmfHAStateT haState
,
111 SaAmfCSIDescriptorT
*csiDescriptor
)
115 case SA_AMF_HA_ACTIVE
:
116 printf ("CSISetCallback:");
117 printf ("for CSI '");
118 printSaNameT ((SaNameT
*)&csiDescriptor
->csiName
);
119 printf ("' for component ");
120 printSaNameT ((SaNameT
*)compName
);
122 printf (" requested to enter hastate SA_AMF_ACTIVE.\n");
123 res
= saAmfResponse (handle
, invocation
, SA_AIS_OK
);
126 case SA_AMF_HA_STANDBY
:
127 printf ("CSISetCallback:");
128 printf ("for CSI '");
129 printSaNameT ((SaNameT
*)compName
);
130 printf ("' for component ");
131 printSaNameT ((SaNameT
*)compName
);
133 printf (" requested to enter hastate SA_AMF_STANDBY.\n");
134 saAmfResponse (handle
, invocation
, SA_AIS_OK
);
139 void CSIRemoveCallback (
140 SaInvocationT invocation
,
141 const SaNameT
*compName
,
142 const SaNameT
*csiName
,
143 const SaAmfCSIFlagsT
*csiFlags
)
147 printf ("CSIRemoveCallback for component '");
148 printSaNameT ((SaNameT
*)compName
);
149 printf ("' in CSI '");
150 printSaNameT ((SaNameT
*)csiName
);
152 res
= saAmfResponse (handle
, invocation
, SA_AIS_OK
);
156 void ProtectionGroupTrackCallback (
157 const SaNameT
*csiName
,
158 SaAmfProtectionGroupNotificationT
*notificationBuffer
,
159 SaUint32T numberOfItems
,
160 SaUint32T numberOfMembers
,
165 printf ("ProtectionGroupTrackCallback items %d members %d\n", (int)numberOfItems
, (int)numberOfMembers
);
166 printf ("buffer is %p\n", notificationBuffer
);
167 for (i
= 0; i
< numberOfItems
; i
++) {
168 printf ("component name");
169 printSaNameT (¬ificationBuffer
[i
].member
.compName
);
171 printf ("\treadiness state is %d\n", notificationBuffer
[i
].member
.readinessState
);
172 printf ("\thastate %d\n", notificationBuffer
[i
].member
.haState
);
173 printf ("\tchange is %d\n", notificationBuffer
[i
].change
);
180 SaAmfCallbacksT amfCallbacks
= {
181 .saAmfHealthcheckCallback
= HealthcheckCallback
,
182 .saAmfComponentTerminateCallback
= ComponentTerminateCallback
,
183 .saAmfCSISetCallback
= CSISetCallback
,
184 .saAmfCSIRemoveCallback
= CSIRemoveCallback
,
187 SaAmfCallbacksT amfCallbacks
;
189 SaVersionT version
= { 'B', 1, 1 };
191 #if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
192 static struct sched_param sched_param
= {
197 void sigintr_handler (int signum
) {
201 int main (int argc
, char **argv
) {
203 SaSelectionObjectT select_fd
;
209 printf ("testamf2 pid %d\n", getpid());
210 memset (&compNameGlobal
, 0, sizeof (SaNameT
));
211 signal (SIGINT
, sigintr_handler
);
212 #if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
213 result
= sched_setscheduler (0, SCHED_RR
, &sched_param
);
215 printf ("couldn't set sched priority\n");
220 c
= getopt(argc
,argv
,"h:n:");
229 sscanf (optarg
,"%ud" ,&healthcheck_count
);
232 setSanameT (&compNameGlobal
, optarg
);
239 result
= saAmfInitialize (&handle
, &amfCallbacks
, &version
);
240 if (result
!= SA_AIS_OK
) {
241 printf ("initialize result is %d\n", result
);
246 saAmfSelectionObjectGet (handle
, &select_fd
);
247 FD_SET (select_fd
, &read_fds
);
248 if (compNameGlobal
.length
<= 0) {
249 setSanameT (&compNameGlobal
, "comp_b_in_su_1");
252 result
= saAmfHealthcheckStart (handle
,
255 SA_AMF_HEALTHCHECK_AMF_INVOKED
,
256 SA_AMF_COMPONENT_FAILOVER
);
257 printf ("start %d\n", result
);
259 result
= saAmfHealthcheckStart (handle
,
262 SA_AMF_HEALTHCHECK_AMF_INVOKED
,
263 SA_AMF_COMPONENT_FAILOVER
);
264 printf ("start %d\n", result
);
265 result
= saAmfComponentRegister (handle
, &compNameGlobal
, NULL
);
266 printf ("register result is %d (should be 1)\n", result
);
269 select (select_fd
+ 1, &read_fds
, 0, 0, 0);
270 saAmfDispatch (handle
, SA_DISPATCH_ALL
);
271 } while (result
&& stop
== 0);
273 printf ("healthchecks stopped for 5 seconds\n");
275 result
= saAmfHealthcheckStart (handle
,
278 SA_AMF_HEALTHCHECK_AMF_INVOKED
,
279 SA_AMF_COMPONENT_FAILOVER
);
282 select (select_fd
+ 1, &read_fds
, 0, 0, 0);
283 saAmfDispatch (handle
, SA_DISPATCH_ALL
);
286 saAmfFinalize (handle
);