1 yi.zhou 1.1 //%2006////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 yi.zhou 1.1 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 // Author: Yi Zhou, Hewlett-Packard Company (Yi.Zhou@hp.com)
33 //
34 // Modified By:
35 //
36 //%/////////////////////////////////////////////////////////////////////////////
37
38 #include <Pegasus/Common/PegasusAssert.h>
39 #include <Pegasus/Common/Thread.h>
40 #include <Pegasus/Common/Constants.h>
41 #include <Pegasus/Common/FileSystem.h>
42 #include <Pegasus/Common/Stopwatch.h>
43 yi.zhou 1.1 #include <Pegasus/Client/CIMClient.h>
44
45 PEGASUS_USING_PEGASUS;
46 PEGASUS_USING_STD;
47
48 const CIMNamespaceName INTEROP_NAMESPACE = CIMNamespaceName ("root/PG_InterOp");
49 const CIMNamespaceName SOURCE_NAMESPACE =
50 CIMNamespaceName ("root/SampleProvider");
51
52 const String INDICATION_CLASS_NAME = String ("RT_TestIndication");
53
54 const String SNMPV1_HANDLER_NAME = String ("SNMPHandler01");
55 const String SNMPV2C_HANDLER_NAME = String ("SNMPHandler02");
56 const String FILTER_NAME = String ("IPFilter01");
57
58 enum SNMPVersion {_SNMPV1_TRAP = 2, _SNMPV2C_TRAP = 3};
59 enum TargetHostFormat {_HOST_NAME = 2, _IPV4_ADDRESS = 3};
60
61 #define PORT_NUMBER 2006
62
63 Uint32 indicationSendCountTotal = 0;
64 yi.zhou 1.1
65 AtomicInt errorsEncountered(0);
66
67 ////////////////////////////////////////////////////////////////////////////////
68 //
69 // Thread Parameters Class
70 //
71 ////////////////////////////////////////////////////////////////////////////////
72
73 class T_Parms{
74 public:
75 AutoPtr<CIMClient> client;
76 Uint32 indicationSendCount;
77 Uint32 uniqueID;
78 };
79
80 ///////////////////////////////////////////////////////////////////////////
81
82 CIMObjectPath _getFilterObjectPath
83 (const String & name)
84 {
85 yi.zhou 1.1 Array<CIMKeyBinding> keyBindings;
86 keyBindings.append (CIMKeyBinding ("SystemCreationClassName",
87 System::getSystemCreationClassName (), CIMKeyBinding::STRING));
88 keyBindings.append (CIMKeyBinding ("SystemName",
89 System::getFullyQualifiedHostName (), CIMKeyBinding::STRING));
90 keyBindings.append (CIMKeyBinding ("CreationClassName",
91 PEGASUS_CLASSNAME_INDFILTER.getString(), CIMKeyBinding::STRING));
92 keyBindings.append (CIMKeyBinding ("Name", name,
93 CIMKeyBinding::STRING));
94 return(CIMObjectPath("", CIMNamespaceName (),
95 PEGASUS_CLASSNAME_INDFILTER, keyBindings));
96 }
97
98 CIMObjectPath _getHandlerObjectPath
99 (const String & name)
100 {
101 Array<CIMKeyBinding> keyBindings;
102 keyBindings.append (CIMKeyBinding ("SystemCreationClassName",
103 System::getSystemCreationClassName (), CIMKeyBinding::STRING));
104 keyBindings.append (CIMKeyBinding ("SystemName",
105 System::getFullyQualifiedHostName (), CIMKeyBinding::STRING));
106 yi.zhou 1.1 keyBindings.append (CIMKeyBinding ("CreationClassName",
107 PEGASUS_CLASSNAME_INDHANDLER_SNMP.getString(),
108 CIMKeyBinding::STRING));
109 keyBindings.append (CIMKeyBinding ("Name", name,
110 CIMKeyBinding::STRING));
111 return(CIMObjectPath("", CIMNamespaceName (),
112 PEGASUS_CLASSNAME_INDHANDLER_SNMP, keyBindings));
113 }
114
115 CIMObjectPath _getSubscriptionObjectPath
116 (const String & filterName,
117 const String & handlerName)
118 {
119 CIMObjectPath filterObjectPath = _getFilterObjectPath(filterName);
120
121 CIMObjectPath handlerObjectPath = _getHandlerObjectPath(handlerName);
122
123 Array<CIMKeyBinding> subscriptionKeyBindings;
124 subscriptionKeyBindings.append (CIMKeyBinding ("Filter",
125 CIMValue(filterObjectPath)));
126 subscriptionKeyBindings.append (CIMKeyBinding ("Handler",
127 yi.zhou 1.1 CIMValue(handlerObjectPath)));
128 return(CIMObjectPath("", CIMNamespaceName (),
129 PEGASUS_CLASSNAME_INDSUBSCRIPTION, subscriptionKeyBindings));
130 }
131
132 CIMObjectPath _createHandlerInstance
133 (CIMClient & client,
134 const String & name,
135 const String & targetHost,
136 const String & securityName,
137 const Uint16 targetHostFormat,
138 const Uint16 snmpVersion)
139 {
140 CIMInstance handlerInstance (PEGASUS_CLASSNAME_INDHANDLER_SNMP);
141 handlerInstance.addProperty (CIMProperty (CIMName
142 ("SystemCreationClassName"), System::getSystemCreationClassName ()));
143 handlerInstance.addProperty (CIMProperty (CIMName ("SystemName"),
144 System::getFullyQualifiedHostName ()));
145 handlerInstance.addProperty (CIMProperty (CIMName ("CreationClassName"),
146 PEGASUS_CLASSNAME_INDHANDLER_SNMP.getString ()));
147 handlerInstance.addProperty (CIMProperty (CIMName ("Name"), name));
148 yi.zhou 1.1 handlerInstance.addProperty (CIMProperty (CIMName ("TargetHost"),
149 targetHost));
150 handlerInstance.addProperty (CIMProperty (CIMName ("TargetHostFormat"),
151 CIMValue ((Uint16) targetHostFormat)));
152 handlerInstance.addProperty (CIMProperty (CIMName ("SNMPSecurityName"),
153 securityName));
154 handlerInstance.addProperty (CIMProperty (CIMName ("SnmpVersion"),
155 CIMValue ((Uint16) snmpVersion)));
156 handlerInstance.addProperty (CIMProperty (CIMName ("PortNumber"),
157 CIMValue ((Uint32) PORT_NUMBER)));
158
159 return(client.createInstance (INTEROP_NAMESPACE, handlerInstance));
160 }
161
162 CIMObjectPath _createFilterInstance
163 (CIMClient & client,
164 const String & name,
165 const String & query,
166 const String & qlang)
167 {
168 CIMInstance filterInstance (PEGASUS_CLASSNAME_INDFILTER);
169 yi.zhou 1.1 filterInstance.addProperty (CIMProperty (CIMName
170 ("SystemCreationClassName"), System::getSystemCreationClassName ()));
171 filterInstance.addProperty (CIMProperty (CIMName ("SystemName"),
172 System::getFullyQualifiedHostName ()));
173 filterInstance.addProperty (CIMProperty (CIMName ("CreationClassName"),
174 PEGASUS_CLASSNAME_INDFILTER.getString ()));
175 filterInstance.addProperty (CIMProperty (CIMName ("Name"), name));
176 filterInstance.addProperty (CIMProperty (CIMName ("Query"), query));
177 filterInstance.addProperty (CIMProperty (CIMName ("QueryLanguage"),
178 String (qlang)));
179 filterInstance.addProperty (CIMProperty (CIMName ("SourceNamespace"),
180 SOURCE_NAMESPACE.getString ()));
181
182 return(client.createInstance (INTEROP_NAMESPACE, filterInstance));
183 }
184
185 CIMObjectPath _createSubscriptionInstance
186 (CIMClient & client,
187 const CIMObjectPath & filterPath,
188 const CIMObjectPath & handlerPath)
189 {
190 yi.zhou 1.1 CIMInstance subscriptionInstance (PEGASUS_CLASSNAME_INDSUBSCRIPTION);
191 subscriptionInstance.addProperty (CIMProperty (CIMName ("Filter"),
192 filterPath, 0, PEGASUS_CLASSNAME_INDFILTER));
193 subscriptionInstance.addProperty (CIMProperty (CIMName ("Handler"),
194 handlerPath, 0, PEGASUS_CLASSNAME_INDHANDLER_SNMP));
195 subscriptionInstance.addProperty (CIMProperty
196 (CIMName ("SubscriptionState"), CIMValue ((Uint16) 2)));
197
198 return(client.createInstance (INTEROP_NAMESPACE, subscriptionInstance));
199 }
200
201 void _sendTestIndication(CIMClient* client, const CIMName & methodName,
202 Uint32 indicationSendCount)
203 {
204 //
205 // Invoke method to send test indication
206 //
207 Array <CIMParamValue> inParams;
208 Array <CIMParamValue> outParams;
209 Array <CIMKeyBinding> keyBindings;
210 Sint32 result;
211 yi.zhou 1.1
212 CIMObjectPath className (String::EMPTY, CIMNamespaceName (),
213 CIMName ("RT_TestIndication"), keyBindings);
214
215 inParams.append(CIMParamValue(String("indicationSendCount"),
216 CIMValue(indicationSendCount)));
217
218 CIMValue retValue = client->invokeMethod
219 (SOURCE_NAMESPACE,
220 className,
221 methodName,
222 inParams,
223 outParams);
224
225 retValue.get (result);
226 PEGASUS_TEST_ASSERT (result == 0);
227 }
228
229 void _deleteSubscriptionInstance
230 (CIMClient & client,
231 const String & filterName,
232 yi.zhou 1.1 const String & handlerName)
233 {
234 CIMObjectPath subscriptionObjectPath =
235 _getSubscriptionObjectPath(filterName, handlerName);
236 client.deleteInstance (INTEROP_NAMESPACE, subscriptionObjectPath);
237 }
238
239 void _deleteHandlerInstance
240 (CIMClient & client,
241 const String & name)
242 {
243 CIMObjectPath handlerObjectPath = _getHandlerObjectPath(name);
244 client.deleteInstance (INTEROP_NAMESPACE, handlerObjectPath);
245 }
246
247 void _deleteFilterInstance
248 (CIMClient & client,
249 const String & name)
250 {
251 CIMObjectPath filterObjectPath = _getFilterObjectPath(name);
252 client.deleteInstance (INTEROP_NAMESPACE, filterObjectPath);
253 yi.zhou 1.1 }
254
255 void _usage ()
256 {
257 cerr << endl
258 << "Usage:" << endl
259 << " TestSnmpHandler setup [ WQL | DMTF:CQL ]\n"
260 << " TestSnmpHandler run <indicationSendCount> "
261 << "[<threads>]\n"
262 << " where: " << endl
263 << " <indicationSendCount> is the number of indications to\n"
264 << " generate and has to be greater than zero." << endl
265 << " <threads> is an optional number of client threads to\n"
266 << " create, default is one." << endl
267 << " TestSnmpHandler cleanup\n"
268 << " TestSnmpHandler removelog"
269 << endl << endl;
270 }
271
272 void _setup (CIMClient & client, const String& qlang)
273 {
274 yi.zhou 1.1 CIMObjectPath filterObjectPath;
275 CIMObjectPath snmpv1HandlerObjectPath;
276 CIMObjectPath snmpv2HandlerObjectPath;
277
278 try
279 {
280 filterObjectPath = _createFilterInstance (client, FILTER_NAME,
281 String ("SELECT * FROM RT_TestIndication"),
282 qlang);
283 }
284 catch (CIMException& e)
285 {
286 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
287 {
288 filterObjectPath = _getFilterObjectPath(FILTER_NAME);
289 cerr << "----- Warning: Filter Instance Not Created: "
290 << e.getMessage () << endl;
291 }
292 else
293 {
294 cerr << "----- Error: Filter Instance Not Created: " << endl;
295 yi.zhou 1.1 throw;
296 }
297 }
298
299 try
300 {
301 // Create SNMPv1 trap handler
302 snmpv1HandlerObjectPath = _createHandlerInstance (client,
303 SNMPV1_HANDLER_NAME,
304 System::getFullyQualifiedHostName(),
305 "",
306 _HOST_NAME,
307 _SNMPV1_TRAP);
308 }
309 catch (CIMException& e)
310 {
311 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
312 {
313 snmpv1HandlerObjectPath = _getHandlerObjectPath(
314 SNMPV1_HANDLER_NAME);
315 cerr << "----- Warning: SNMPv1 Trap Handler Instance Not Created: "
316 yi.zhou 1.1 << e.getMessage () << endl;
317 }
318 else
319 {
320 cerr << "----- Error: SNMPv1 Trap Handler Instance Not Created: "
321 << endl;
322 throw;
323 }
324 }
325
326 try
327 {
328 _createSubscriptionInstance (client, filterObjectPath,
329 snmpv1HandlerObjectPath);
330 }
331 catch (CIMException& e)
332 {
333 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
334 {
335 cerr << "----- Warning: Client Subscription Instance: "
336 << e.getMessage () << endl;
337 yi.zhou 1.1 }
338 else
339 {
340 cerr << "----- Error: Client Subscription Instance: " << endl;
341 throw;
342 }
343 }
344
345 try
346 {
347 // Create SNMPv2 trap handler
348 snmpv2HandlerObjectPath = _createHandlerInstance (client,
349 SNMPV2C_HANDLER_NAME,
350 System::getHostIP(System::getFullyQualifiedHostName ()),
351 "public",
352 _IPV4_ADDRESS,
353 _SNMPV2C_TRAP);
354 }
355 catch (CIMException& e)
356 {
357 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
358 yi.zhou 1.1 {
359 snmpv2HandlerObjectPath = _getHandlerObjectPath(
360 SNMPV2C_HANDLER_NAME);
361 cerr << "----- Warning: SNMPv2c Trap Handler Instance Not Created: "
362 << e.getMessage () << endl;
363 }
364 else
365 {
366 cerr << "----- Error: SNMPv2c Trap Handler Instance Not Created: "
367 << endl;
368 throw;
369 }
370 }
371
372 try
373 {
374 _createSubscriptionInstance (client, filterObjectPath,
375 snmpv2HandlerObjectPath);
376 }
377 catch (CIMException& e)
378 {
379 yi.zhou 1.1 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
380 {
381 cerr << "----- Warning: Client Subscription Instance: "
382 << e.getMessage () << endl;
383 }
384 else
385 {
386 cerr << "----- Error: Client Subscription Instance: " << endl;
387 throw;
388 }
389 }
390 }
391
392 void _cleanup (CIMClient & client)
393 {
394 try
395 {
396 _deleteSubscriptionInstance (client, FILTER_NAME,
397 SNMPV1_HANDLER_NAME);
398 }
399 catch (CIMException& e)
400 yi.zhou 1.1 {
401 if (e.getCode() != CIM_ERR_NOT_FOUND)
402 {
403 cerr << "----- Error: deleteSubscriptionInstance failure: "
404 << endl;
405 throw;
406 }
407 }
408 try
409 {
410 _deleteSubscriptionInstance (client, FILTER_NAME,
411 SNMPV2C_HANDLER_NAME);
412 }
413 catch (CIMException& e)
414 {
415 if (e.getCode() != CIM_ERR_NOT_FOUND)
416 {
417 cerr << "----- Error: deleteSubscriptionInstance failure: "
418 << endl;
419 throw;
420 }
421 yi.zhou 1.1 }
422 try
423 {
424 _deleteFilterInstance (client, FILTER_NAME);
425 }
426 catch (CIMException& e)
427 {
428 if (e.getCode() != CIM_ERR_NOT_FOUND)
429 {
430 cerr << "----- Error: deleteFilterInstance failure: " << endl;
431 throw;
432 }
433 }
434
435 try
436 {
437 _deleteHandlerInstance (client, SNMPV1_HANDLER_NAME);
438 }
439 catch (CIMException& e)
440 {
441 if (e.getCode() != CIM_ERR_NOT_FOUND)
442 yi.zhou 1.1 {
443 cerr << "----- Error: deleteHandlerInstance failure: " << endl;
444 throw;
445 }
446 }
447 try
448 {
449 _deleteHandlerInstance (client, SNMPV2C_HANDLER_NAME);
450 }
451 catch (CIMException& e)
452 {
453 if (e.getCode() != CIM_ERR_NOT_FOUND)
454 {
455 cerr << "----- Error: deleteHandlerInstance failure: " << endl;
456 throw;
457 }
458 }
459 }
460
461 static void _testEnd(const String& uniqueID, const double elapsedTime)
462 {
463 yi.zhou 1.1 cout << "+++++ thread" << uniqueID << ": passed in " << elapsedTime
464 << " seconds" << endl;
465 }
466
|