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 //%/////////////////////////////////////////////////////////////////////////////
33
34 #include <Pegasus/Common/PegasusAssert.h>
35 #include <Pegasus/Common/Thread.h>
36 #include <Pegasus/Common/Constants.h>
37 #include <Pegasus/Common/FileSystem.h>
38 #include <Pegasus/Common/Stopwatch.h>
39 #include <Pegasus/Client/CIMClient.h>
|
40 dave.sudlik 1.6 #include <Pegasus/Common/HostAddress.h>
|
41 yi.zhou 1.1
42 PEGASUS_USING_PEGASUS;
43 PEGASUS_USING_STD;
44
|
45 karl 1.4 // Interop namespace used with PEGASUS_NAMESPACENAME_INTEROP in Constants.h
|
46 kumpf 1.7 const CIMNamespaceName SOURCE_NAMESPACE =
|
47 yi.zhou 1.1 CIMNamespaceName ("root/SampleProvider");
48
49 const String INDICATION_CLASS_NAME = String ("RT_TestIndication");
50
51 const String SNMPV1_HANDLER_NAME = String ("SNMPHandler01");
52 const String SNMPV2C_HANDLER_NAME = String ("SNMPHandler02");
|
53 yi.zhou 1.8 const String SNMPV2C_IPV6_HANDLER_NAME = String ("SNMPHandler03");
|
54 yi.zhou 1.1 const String FILTER_NAME = String ("IPFilter01");
55
56 enum SNMPVersion {_SNMPV1_TRAP = 2, _SNMPV2C_TRAP = 3};
|
57 dave.sudlik 1.6 enum TargetHostFormat {_HOST_NAME = 2, _IPV4_ADDRESS = 3, _IPV6_ADDRESS = 4};
|
58 yi.zhou 1.1
59 #define PORT_NUMBER 2006
60
61 AtomicInt errorsEncountered(0);
62
63 ////////////////////////////////////////////////////////////////////////////////
64 //
65 // Thread Parameters Class
66 //
67 ////////////////////////////////////////////////////////////////////////////////
68
|
69 kumpf 1.7 class T_Parms
70 {
71 public:
|
72 yi.zhou 1.1 AutoPtr<CIMClient> client;
73 Uint32 indicationSendCount;
74 Uint32 uniqueID;
75 };
76
77 ///////////////////////////////////////////////////////////////////////////
78
|
79 kumpf 1.7 CIMObjectPath _getFilterObjectPath(const String & name)
|
80 yi.zhou 1.1 {
81 Array<CIMKeyBinding> keyBindings;
82 keyBindings.append (CIMKeyBinding ("SystemCreationClassName",
83 System::getSystemCreationClassName (), CIMKeyBinding::STRING));
84 keyBindings.append (CIMKeyBinding ("SystemName",
85 System::getFullyQualifiedHostName (), CIMKeyBinding::STRING));
86 keyBindings.append (CIMKeyBinding ("CreationClassName",
87 PEGASUS_CLASSNAME_INDFILTER.getString(), CIMKeyBinding::STRING));
88 keyBindings.append (CIMKeyBinding ("Name", name,
89 CIMKeyBinding::STRING));
90 return(CIMObjectPath("", CIMNamespaceName (),
91 PEGASUS_CLASSNAME_INDFILTER, keyBindings));
92 }
93
|
94 kumpf 1.7 CIMObjectPath _getHandlerObjectPath(const String & name)
|
95 yi.zhou 1.1 {
96 Array<CIMKeyBinding> keyBindings;
97 keyBindings.append (CIMKeyBinding ("SystemCreationClassName",
98 System::getSystemCreationClassName (), CIMKeyBinding::STRING));
99 keyBindings.append (CIMKeyBinding ("SystemName",
100 System::getFullyQualifiedHostName (), CIMKeyBinding::STRING));
101 keyBindings.append (CIMKeyBinding ("CreationClassName",
102 PEGASUS_CLASSNAME_INDHANDLER_SNMP.getString(),
103 CIMKeyBinding::STRING));
104 keyBindings.append (CIMKeyBinding ("Name", name,
105 CIMKeyBinding::STRING));
106 return(CIMObjectPath("", CIMNamespaceName (),
107 PEGASUS_CLASSNAME_INDHANDLER_SNMP, keyBindings));
108 }
109
|
110 kumpf 1.7 CIMObjectPath _getSubscriptionObjectPath(
111 const String & filterName,
112 const String & handlerName)
|
113 yi.zhou 1.1 {
114 CIMObjectPath filterObjectPath = _getFilterObjectPath(filterName);
115
116 CIMObjectPath handlerObjectPath = _getHandlerObjectPath(handlerName);
117
118 Array<CIMKeyBinding> subscriptionKeyBindings;
119 subscriptionKeyBindings.append (CIMKeyBinding ("Filter",
120 CIMValue(filterObjectPath)));
121 subscriptionKeyBindings.append (CIMKeyBinding ("Handler",
122 CIMValue(handlerObjectPath)));
123 return(CIMObjectPath("", CIMNamespaceName (),
124 PEGASUS_CLASSNAME_INDSUBSCRIPTION, subscriptionKeyBindings));
125 }
126
|
127 kumpf 1.7 CIMObjectPath _createHandlerInstance(
128 CIMClient & client,
129 const String & name,
130 const String & targetHost,
131 const String & securityName,
132 const Uint16 targetHostFormat,
133 const Uint16 snmpVersion)
|
134 yi.zhou 1.1 {
135 CIMInstance handlerInstance (PEGASUS_CLASSNAME_INDHANDLER_SNMP);
136 handlerInstance.addProperty (CIMProperty (CIMName
137 ("SystemCreationClassName"), System::getSystemCreationClassName ()));
138 handlerInstance.addProperty (CIMProperty (CIMName ("SystemName"),
139 System::getFullyQualifiedHostName ()));
140 handlerInstance.addProperty (CIMProperty (CIMName ("CreationClassName"),
141 PEGASUS_CLASSNAME_INDHANDLER_SNMP.getString ()));
142 handlerInstance.addProperty (CIMProperty (CIMName ("Name"), name));
143 handlerInstance.addProperty (CIMProperty (CIMName ("TargetHost"),
144 targetHost));
145 handlerInstance.addProperty (CIMProperty (CIMName ("TargetHostFormat"),
146 CIMValue ((Uint16) targetHostFormat)));
147 handlerInstance.addProperty (CIMProperty (CIMName ("SNMPSecurityName"),
148 securityName));
149 handlerInstance.addProperty (CIMProperty (CIMName ("SnmpVersion"),
150 CIMValue ((Uint16) snmpVersion)));
151 handlerInstance.addProperty (CIMProperty (CIMName ("PortNumber"),
152 CIMValue ((Uint32) PORT_NUMBER)));
153
|
154 kumpf 1.7 return client.createInstance(
155 PEGASUS_NAMESPACENAME_INTEROP, handlerInstance);
|
156 yi.zhou 1.1 }
157
|
158 kumpf 1.7 CIMObjectPath _createFilterInstance(
159 CIMClient & client,
160 const String & name,
161 const String & query,
162 const String & qlang)
|
163 yi.zhou 1.1 {
164 CIMInstance filterInstance (PEGASUS_CLASSNAME_INDFILTER);
165 filterInstance.addProperty (CIMProperty (CIMName
166 ("SystemCreationClassName"), System::getSystemCreationClassName ()));
167 filterInstance.addProperty (CIMProperty (CIMName ("SystemName"),
168 System::getFullyQualifiedHostName ()));
169 filterInstance.addProperty (CIMProperty (CIMName ("CreationClassName"),
170 PEGASUS_CLASSNAME_INDFILTER.getString ()));
171 filterInstance.addProperty (CIMProperty (CIMName ("Name"), name));
172 filterInstance.addProperty (CIMProperty (CIMName ("Query"), query));
173 filterInstance.addProperty (CIMProperty (CIMName ("QueryLanguage"),
174 String (qlang)));
175 filterInstance.addProperty (CIMProperty (CIMName ("SourceNamespace"),
176 SOURCE_NAMESPACE.getString ()));
177
|
178 kumpf 1.7 return client.createInstance(PEGASUS_NAMESPACENAME_INTEROP, filterInstance);
|
179 yi.zhou 1.1 }
180
|
181 kumpf 1.7 CIMObjectPath _createSubscriptionInstance(
182 CIMClient & client,
183 const CIMObjectPath & filterPath,
184 const CIMObjectPath & handlerPath)
|
185 yi.zhou 1.1 {
186 CIMInstance subscriptionInstance (PEGASUS_CLASSNAME_INDSUBSCRIPTION);
187 subscriptionInstance.addProperty (CIMProperty (CIMName ("Filter"),
188 filterPath, 0, PEGASUS_CLASSNAME_INDFILTER));
189 subscriptionInstance.addProperty (CIMProperty (CIMName ("Handler"),
190 handlerPath, 0, PEGASUS_CLASSNAME_INDHANDLER_SNMP));
191 subscriptionInstance.addProperty (CIMProperty
192 (CIMName ("SubscriptionState"), CIMValue ((Uint16) 2)));
193
|
194 kumpf 1.7 return client.createInstance(
195 PEGASUS_NAMESPACENAME_INTEROP, subscriptionInstance);
|
196 yi.zhou 1.1 }
197
|
198 kumpf 1.7 void _sendTestIndication(
199 CIMClient* client,
200 const CIMName & methodName,
201 Uint32 indicationSendCount)
|
202 yi.zhou 1.1 {
203 //
204 // Invoke method to send test indication
205 //
206 Array <CIMParamValue> inParams;
207 Array <CIMParamValue> outParams;
208 Array <CIMKeyBinding> keyBindings;
209 Sint32 result;
210
211 CIMObjectPath className (String::EMPTY, CIMNamespaceName (),
212 CIMName ("RT_TestIndication"), keyBindings);
213
|
214 kumpf 1.7 inParams.append(CIMParamValue(String("indicationSendCount"),
|
215 yi.zhou 1.1 CIMValue(indicationSendCount)));
216
217 CIMValue retValue = client->invokeMethod
218 (SOURCE_NAMESPACE,
219 className,
220 methodName,
221 inParams,
222 outParams);
223
224 retValue.get (result);
225 PEGASUS_TEST_ASSERT (result == 0);
226 }
227
|
228 kumpf 1.7 void _deleteSubscriptionInstance(
229 CIMClient & client,
230 const String & filterName,
231 const String & handlerName)
|
232 yi.zhou 1.1 {
233 CIMObjectPath subscriptionObjectPath =
234 _getSubscriptionObjectPath(filterName, handlerName);
|
235 kumpf 1.7 client.deleteInstance(
236 PEGASUS_NAMESPACENAME_INTEROP, subscriptionObjectPath);
|
237 yi.zhou 1.1 }
238
|
239 kumpf 1.7 void _deleteHandlerInstance(
240 CIMClient & client,
241 const String & name)
|
242 yi.zhou 1.1 {
243 CIMObjectPath handlerObjectPath = _getHandlerObjectPath(name);
|
244 karl 1.4 client.deleteInstance (PEGASUS_NAMESPACENAME_INTEROP, handlerObjectPath);
|
245 yi.zhou 1.1 }
246
|
247 kumpf 1.7 void _deleteFilterInstance(
248 CIMClient & client,
249 const String & name)
|
250 yi.zhou 1.1 {
251 CIMObjectPath filterObjectPath = _getFilterObjectPath(name);
|
252 karl 1.4 client.deleteInstance (PEGASUS_NAMESPACENAME_INTEROP, filterObjectPath);
|
253 yi.zhou 1.1 }
254
|
255 kumpf 1.7 void _usage()
|
256 yi.zhou 1.1 {
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 CIMObjectPath filterObjectPath;
275 CIMObjectPath snmpv1HandlerObjectPath;
276 CIMObjectPath snmpv2HandlerObjectPath;
|
277 yi.zhou 1.8 CIMObjectPath snmpv2IPV6HandlerObjectPath;
|
278 yi.zhou 1.1
279 try
280 {
281 filterObjectPath = _createFilterInstance (client, FILTER_NAME,
282 String ("SELECT * FROM RT_TestIndication"),
283 qlang);
284 }
285 catch (CIMException& e)
286 {
287 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
288 {
289 filterObjectPath = _getFilterObjectPath(FILTER_NAME);
290 cerr << "----- Warning: Filter Instance Not Created: "
291 << e.getMessage () << endl;
292 }
293 else
294 {
295 cerr << "----- Error: Filter Instance Not Created: " << endl;
296 throw;
297 }
298 }
299 yi.zhou 1.1
300 try
301 {
|
302 kumpf 1.7 // Create SNMPv1 trap handler
|
303 yi.zhou 1.1 snmpv1HandlerObjectPath = _createHandlerInstance (client,
304 SNMPV1_HANDLER_NAME,
305 System::getFullyQualifiedHostName(),
306 "",
307 _HOST_NAME,
308 _SNMPV1_TRAP);
309 }
310 catch (CIMException& e)
311 {
312 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
313 {
314 snmpv1HandlerObjectPath = _getHandlerObjectPath(
315 SNMPV1_HANDLER_NAME);
316 cerr << "----- Warning: SNMPv1 Trap Handler Instance Not Created: "
317 << e.getMessage () << endl;
318 }
319 else
320 {
321 cerr << "----- Error: SNMPv1 Trap Handler Instance Not Created: "
322 << endl;
323 throw;
324 yi.zhou 1.1 }
325 }
326
327 try
328 {
329 _createSubscriptionInstance (client, filterObjectPath,
330 snmpv1HandlerObjectPath);
331 }
332 catch (CIMException& e)
333 {
334 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
335 {
336 cerr << "----- Warning: Client Subscription Instance: "
337 << e.getMessage () << endl;
338 }
339 else
340 {
341 cerr << "----- Error: Client Subscription Instance: " << endl;
342 throw;
343 }
344 }
345 yi.zhou 1.1
346 try
347 {
|
348 dave.sudlik 1.6 String ipAddress;
349 int af;
350 System::getHostIP(System::getFullyQualifiedHostName (), &af, ipAddress);
|
351 kumpf 1.7 // Create SNMPv2 trap handler
|
352 yi.zhou 1.1 snmpv2HandlerObjectPath = _createHandlerInstance (client,
353 SNMPV2C_HANDLER_NAME,
|
354 dave.sudlik 1.6 ipAddress,
|
355 yi.zhou 1.1 "public",
|
356 dave.sudlik 1.6 af == AF_INET ? _IPV4_ADDRESS : _IPV6_ADDRESS,
|
357 yi.zhou 1.1 _SNMPV2C_TRAP);
358 }
359 catch (CIMException& e)
360 {
361 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
362 {
363 snmpv2HandlerObjectPath = _getHandlerObjectPath(
364 SNMPV2C_HANDLER_NAME);
365 cerr << "----- Warning: SNMPv2c Trap Handler Instance Not Created: "
366 << e.getMessage () << endl;
367 }
368 else
369 {
370 cerr << "----- Error: SNMPv2c Trap Handler Instance Not Created: "
371 << endl;
372 throw;
373 }
374 }
375
376 try
377 {
378 yi.zhou 1.1 _createSubscriptionInstance (client, filterObjectPath,
379 snmpv2HandlerObjectPath);
380 }
381 catch (CIMException& e)
382 {
383 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
384 {
385 cerr << "----- Warning: Client Subscription Instance: "
386 << e.getMessage () << endl;
387 }
388 else
389 {
390 cerr << "----- Error: Client Subscription Instance: " << endl;
391 throw;
392 }
393 }
|
394 yi.zhou 1.8
395 #if defined(PEGASUS_ENABLE_IPV6)
396 // create a subscription with trap destination of IPV6 address format
397 try
398 {
399 // Create SNMPv2 IPV6 trap handler
400 snmpv2IPV6HandlerObjectPath = _createHandlerInstance (client,
401 SNMPV2C_IPV6_HANDLER_NAME,
402 String("::1"),
403 "public",
404 _IPV6_ADDRESS,
405 _SNMPV2C_TRAP);
406 }
407 catch (CIMException& e)
408 {
409 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
410 {
411 snmpv2IPV6HandlerObjectPath = _getHandlerObjectPath(
412 SNMPV2C_IPV6_HANDLER_NAME);
413 cerr << "----- Warning: SNMPv2c IPV6 Trap Handler Instance "
414 "Not Created: " << e.getMessage () << endl;
415 yi.zhou 1.8 }
416 else
417 {
418 cerr << "----- Error: SNMPv2c IPV6 Trap Handler Instance Not "
419 "Created: " << endl;
420 throw;
421 }
422 }
423
424 try
425 {
426 _createSubscriptionInstance (client, filterObjectPath,
427 snmpv2IPV6HandlerObjectPath);
428 }
429 catch (CIMException& e)
430 {
431 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
432 {
433 cerr << "----- Warning: Client Subscription Instance: "
434 << e.getMessage () << endl;
435 }
436 yi.zhou 1.8 else
437 {
438 cerr << "----- Error: Client Subscription Instance: " << endl;
439 throw;
440 }
441 }
442 #endif
|
443 yi.zhou 1.1 }
444
445 void _cleanup (CIMClient & client)
446 {
447 try
448 {
449 _deleteSubscriptionInstance (client, FILTER_NAME,
450 SNMPV1_HANDLER_NAME);
451 }
452 catch (CIMException& e)
453 {
454 if (e.getCode() != CIM_ERR_NOT_FOUND)
455 {
456 cerr << "----- Error: deleteSubscriptionInstance failure: "
457 << endl;
458 throw;
459 }
460 }
461 try
462 {
463 _deleteSubscriptionInstance (client, FILTER_NAME,
464 yi.zhou 1.1 SNMPV2C_HANDLER_NAME);
465 }
466 catch (CIMException& e)
467 {
468 if (e.getCode() != CIM_ERR_NOT_FOUND)
469 {
470 cerr << "----- Error: deleteSubscriptionInstance failure: "
471 << endl;
472 throw;
473 }
474 }
|
475 yi.zhou 1.8
476 #if defined(PEGASUS_ENABLE_IPV6)
477 try
478 {
479 _deleteSubscriptionInstance (client, FILTER_NAME,
480 SNMPV2C_IPV6_HANDLER_NAME);
481 }
482 catch (CIMException& e)
483 {
484 if (e.getCode() != CIM_ERR_NOT_FOUND)
485 {
486 cerr << "----- Error: deleteSubscriptionInstance failure: "
487 << endl;
488 throw;
489 }
490 }
491 #endif
492
|
493 yi.zhou 1.1 try
494 {
495 _deleteFilterInstance (client, FILTER_NAME);
496 }
497 catch (CIMException& e)
498 {
499 if (e.getCode() != CIM_ERR_NOT_FOUND)
500 {
501 cerr << "----- Error: deleteFilterInstance failure: " << endl;
502 throw;
503 }
504 }
505
506 try
507 {
508 _deleteHandlerInstance (client, SNMPV1_HANDLER_NAME);
509 }
510 catch (CIMException& e)
511 {
512 if (e.getCode() != CIM_ERR_NOT_FOUND)
513 {
514 yi.zhou 1.1 cerr << "----- Error: deleteHandlerInstance failure: " << endl;
515 throw;
516 }
517 }
518 try
519 {
520 _deleteHandlerInstance (client, SNMPV2C_HANDLER_NAME);
521 }
522 catch (CIMException& e)
523 {
524 if (e.getCode() != CIM_ERR_NOT_FOUND)
525 {
526 cerr << "----- Error: deleteHandlerInstance failure: " << endl;
527 throw;
528 }
529 }
|
530 yi.zhou 1.8 #if defined(PEGASUS_ENABLE_IPV6)
531 try
532 {
533 _deleteHandlerInstance (client, SNMPV2C_IPV6_HANDLER_NAME);
534 }
535 catch (CIMException& e)
536 {
537 if (e.getCode() != CIM_ERR_NOT_FOUND)
538 {
539 cerr << "----- Error: deleteHandlerInstance failure: " << endl;
540 throw;
541 }
542 }
543 #endif
|
544 yi.zhou 1.1 }
545
546 static void _testEnd(const String& uniqueID, const double elapsedTime)
547 {
548 cout << "+++++ thread" << uniqueID << ": passed in " << elapsedTime
549 << " seconds" << endl;
550 }
551
|
552 mike 1.3 ThreadReturnType PEGASUS_THREAD_CDECL _executeTests(void *parm)
|
553 yi.zhou 1.1 {
554 Thread *my_thread = (Thread *)parm;
555 T_Parms *parms = (T_Parms *)my_thread->get_parm();
556 CIMClient *client = parms->client.get();
557 Uint32 indicationSendCount = parms->indicationSendCount;
558 Uint32 id = parms->uniqueID;
559 char id_[4];
560 memset(id_,0x00,sizeof(id_));
561 sprintf(id_,"%i",id);
562 String uniqueID = "_";
563 uniqueID.append(id_);
564
565 try
566 {
567 Stopwatch elapsedTime;
568
569 elapsedTime.start();
570 try
571 {
572 _sendTestIndication (client, CIMName ("SendTestIndicationTrap"),
573 indicationSendCount);
574 yi.zhou 1.1 }
575 catch (Exception & e)
576 {
|
577 kumpf 1.7 cerr << "----- sendTestIndication failed: " << e.getMessage () <<
578 endl;
|
579 yi.zhou 1.1 exit (-1);
580 }
581 elapsedTime.stop();
582 _testEnd(uniqueID, elapsedTime.getElapsed());
583 }
584 catch(Exception & e)
585 {
586 cout << e.getMessage() << endl;
587 }
|
588 mike 1.3 my_thread->exit_self((ThreadReturnType)1);
|
589 yi.zhou 1.1 return(0);
590 }
591
592 Thread * _runTestThreads(
593 CIMClient* client,
594 Uint32 indicationSendCount,
595 Uint32 uniqueID)
596 {
597 // package parameters, create thread and run...
598 AutoPtr<T_Parms> parms(new T_Parms());
599 parms->client.reset(client);
600 parms->indicationSendCount = indicationSendCount;
601 parms->uniqueID = uniqueID;
602 AutoPtr<Thread> t(new Thread(_executeTests, (void*)parms.release(), false));
603 t->run();
604 return t.release();
605 }
606
607 String _getLogFile()
608 {
609 return("trapLogFile");
610 yi.zhou 1.1 }
611
612 Uint32 _getReceivedTrapCount(Uint16 snmpVersion)
613 {
614 String trap1 = "Trap Info: TRAP, SNMP v1, community public";
615 String trap2 = "Trap Info: TRAP2, SNMP v2c, community public";
616
617 Uint32 receivedTrap1Count = 0;
618 Uint32 receivedTrap2Count = 0;
|
619 kumpf 1.7
|
620 yi.zhou 1.1 ifstream ifs(_getLogFile().getCString());
621 if (!ifs)
622 {
623 return (0);
624 }
625
626 String line;
627 while (GetLine(ifs, line))
628 {
629 if (String::compare(line, trap1) == 0)
630 {
631 receivedTrap1Count++;
632 }
633 if (String::compare(line, trap2) == 0)
634 {
635 receivedTrap2Count++;
636 }
637 }
638
639 ifs.close();
640
641 yi.zhou 1.1 switch (snmpVersion)
642 {
643 case _SNMPV1_TRAP:
644 {
645 return (receivedTrap1Count);
646 }
647 case _SNMPV2C_TRAP:
648 {
649 return (receivedTrap2Count);
650 }
651 default:
652 {
653 return (0);
654 }
655 }
656
657 }
658
659 #ifdef PEGASUS_USE_NET_SNMP
|
660 kumpf 1.7 // Stop snmptrapd process if it is running and remove
|
661 yi.zhou 1.1 // procIdFile file if it exists
|
662 kumpf 1.7 //
|
663 yi.zhou 1.1 void _stopSnmptrapd()
664 {
665 String procIdFileName = "procIdFile";
666
667 Uint32 receiverPid;
668 FILE *fd;
669 if ((fd = fopen(procIdFileName.getCString(), "r")) != NULL)
670 {
671 fscanf(fd, "%d\n", &receiverPid);
|
672 kumpf 1.7
|
673 yi.zhou 1.1 kill(receiverPid, SIGTERM);
674
675 fclose(fd);
676 }
677
678 if (FileSystem::exists(procIdFileName))
679 {
680 FileSystem::removeFile(procIdFileName);
681 }
682 }
683
684 static Boolean _startSnmptrapd(
685 FILE **trapInfo)
686 {
687 String snmptrapdCmd;
688
689 Uint32 portNumber = PORT_NUMBER;
690 char portNumberStr[32];
691 sprintf(portNumberStr, "%lu", (unsigned long) portNumber);
692
693 //
694 yi.zhou 1.1 // build snmptrapd cmd options
695 //
696
|
697 kumpf 1.7 // Specify logging incoming traps to trapLogFile
|
698 yi.zhou 1.1 // Save the process ID of the snmptrapd in procIdFile
699 snmptrapdCmd.append(
700 "/usr/sbin/snmptrapd -f -Lf trapLogFile -p procIdFile");
701
702 // Specify incoming trap format
703 snmptrapdCmd.append( " -F \"\nTrap Info: %P\nVariable: %v\n\"");
704
705 // Specify listening address
|
706 yi.zhou 1.8 #if defined(PEGASUS_ENABLE_IPV6)
707 snmptrapdCmd.append(" UDP6:");
708 snmptrapdCmd.append(portNumberStr);
709 snmptrapdCmd.append(",UDP:");
710 #else
|
711 yi.zhou 1.1 snmptrapdCmd.append(" UDP:");
|
712 yi.zhou 1.8 #endif
|
713 yi.zhou 1.1 snmptrapdCmd.append(System::getFullyQualifiedHostName ());
714
715 snmptrapdCmd.append(":");
716 snmptrapdCmd.append(portNumberStr);
717
718 if ((*trapInfo = popen(snmptrapdCmd.getCString(), "r")) == NULL)
719 {
720 throw Exception ("snmptrapd can not be started");
721 }
722
723 #define MAX_ITERATIONS 300
724 #define SLEEP_SEC 1
725
726 Uint32 iterations = 0;
727
|
728 kumpf 1.7 // Wait until snmptrapd started
|
729 yi.zhou 1.1 while (iterations < MAX_ITERATIONS)
730 {
731 iterations++;
732 if (FileSystem::exists("procIdFile"))
733 {
734 return (true);
735 }
736 else
737 {
738 System::sleep(SLEEP_SEC);
|
739 kumpf 1.7
|
740 yi.zhou 1.1 }
741 }
742
743 throw Exception ("snmptrapd can not be started");
744 }
745 #endif
746
747 void _removeTrapLogFile ()
748 {
749 String logFile = _getLogFile();
750
751 // if trapLogFile exists, remove it
752 if (FileSystem::exists(logFile))
753 {
754 FileSystem::removeFile(logFile);
755 }
756 }
757
|
758 kumpf 1.7 void _receiveExpectedTraps(
759 CIMClient& workClient,
|
760 yi.zhou 1.1 Uint32 indicationSendCount,
761 Uint32 runClientThreadCount)
762 {
|
763 yi.zhou 1.8 Uint32 indicationTrapV1SendCount = 0;
764 Uint32 indicationTrapV2SendCount = 0;
765
|
766 yi.zhou 1.1 CIMClient * clientConnections = new CIMClient[runClientThreadCount];
767
768 // determine total number of indication send count
|
769 yi.zhou 1.8 indicationTrapV1SendCount =
770 indicationSendCount * runClientThreadCount;
771
772 // if IPV6 is enabled, an additional SNMPv2c trap is sent to IPV6 address
773 #if defined(PEGASUS_ENABLE_IPV6)
774 indicationTrapV2SendCount = 2 * indicationTrapV1SendCount;
775 #else
776 indicationTrapV2SendCount = indicationTrapV1SendCount;
777 #endif
|
778 yi.zhou 1.1
779 // calculate the timeout based on the total send count allowing
|
780 kumpf 1.7 // using the MSG_PER_SEC rate
781 // allow 20 seconds of test overhead for very small tests
|
782 yi.zhou 1.1
783 #define MSG_PER_SEC 4
784
|
785 marek 1.5 Uint32 testTimeout = PEGASUS_DEFAULT_CLIENT_TIMEOUT_MILLISECONDS
|
786 yi.zhou 1.8 + (indicationTrapV2SendCount/MSG_PER_SEC)*1000;
|
787 yi.zhou 1.1
788 // connect the clients
789 for(Uint32 i = 0; i < runClientThreadCount; i++)
790 {
791 clientConnections[i].setTimeout(testTimeout);
792 clientConnections[i].connectLocal();
793 }
794
795 // run tests
796 Thread ** clientThreads = new Thread *[runClientThreadCount];
797
798 Stopwatch trapReceiverElapsedTime;
799
800 trapReceiverElapsedTime.start();
801
802 for(Uint32 i = 0; i < runClientThreadCount; i++)
803 {
804 clientThreads[i] = _runTestThreads(&clientConnections[i],
805 indicationSendCount, i);
806 }
807
808 yi.zhou 1.1 for(Uint32 i=0; i< runClientThreadCount; i++)
809 {
810 clientThreads[i]->join();
811 }
812
813 delete[] clientConnections;
814 delete[] clientThreads;
815
816 //
817 // Allow time for the trap to be received
818 // Wait in SLEEP_SEC second intervals.
819 // Put msg out every MSG_SEC intervals
820 //
821
822 #define SLEEP_SEC 1
823 #define COUT_TIME_INTERVAL 30
824 #define MAX_NO_CHANGE_ITERATIONS COUT_TIME_INTERVAL*3
825
826 Uint32 noChangeIterations = 0;
827 Uint32 priorReceivedTrap1Count = 0;
828 Uint32 priorReceivedTrap2Count = 0;
829 yi.zhou 1.1 Uint32 currentReceivedTrap1Count = 0;
830 Uint32 currentReceivedTrap2Count = 0;
831 Uint32 totalIterations = 0;
832
833 //
834 // Wait for the trap receiver to receive the expected
|
835 yi.zhou 1.8 // number of Indication traps, indicationTrapV1SendCount
836 // and indicationTrapV2SendCount.
|
837 yi.zhou 1.1 //
|
838 yi.zhou 1.8 // We will continue to wait until either (indicationTrapV1SendCount
839 // and indicationTrapV2SendCount) Indications have been received
840 // by the trap receiver or no new
|
841 yi.zhou 1.1 // Indications have been received in the previous
842 // MAX_NO_CHANGE_ITERATIONS.
|
843 kumpf 1.7 // iterations.
|
844 yi.zhou 1.1 //
845
846 Boolean receivedTrapCountComplete = false;
847 Boolean receiverTrap1NoChange = true;
848 Boolean receiverTrap2NoChange = true;
849
850 while (noChangeIterations <= MAX_NO_CHANGE_ITERATIONS)
851 {
852 totalIterations++;
853
|
854 kumpf 1.7 currentReceivedTrap1Count = _getReceivedTrapCount(_SNMPV1_TRAP);
855 currentReceivedTrap2Count = _getReceivedTrapCount(_SNMPV2C_TRAP);
|
856 yi.zhou 1.1
857 if (totalIterations % COUT_TIME_INTERVAL == 1 &&
858 !(receivedTrapCountComplete))
859 {
860 cout << "++++ The trap receiver has received "
861 << currentReceivedTrap1Count << " of "
|
862 yi.zhou 1.8 << indicationTrapV1SendCount << " SNMPv1 trap."
|
863 yi.zhou 1.1 << endl;
864 cout << "++++ The trap receiver has received "
865 << currentReceivedTrap2Count << " of "
|
866 yi.zhou 1.8 << indicationTrapV2SendCount << " SNMPv2c trap."
|
867 yi.zhou 1.1 << endl;
868 }
869
|
870 yi.zhou 1.8 if ((indicationTrapV1SendCount == currentReceivedTrap1Count) &&
871 (indicationTrapV2SendCount == currentReceivedTrap2Count))
|
872 yi.zhou 1.1 {
873 receivedTrapCountComplete = true;
874 trapReceiverElapsedTime.stop();
875 }
876 if (!(receiverTrap1NoChange =
877 (priorReceivedTrap1Count == currentReceivedTrap1Count)))
878 {
879 priorReceivedTrap1Count = currentReceivedTrap1Count;
880 }
881
882 if (!(receiverTrap2NoChange =
883 (priorReceivedTrap2Count == currentReceivedTrap2Count)))
884 {
885 priorReceivedTrap2Count = currentReceivedTrap2Count;
886 }
887
888 if (receivedTrapCountComplete)
889 {
890 cout << "++++ The trap receiver has received "
891 << currentReceivedTrap1Count << " of "
|
892 yi.zhou 1.8 << indicationTrapV1SendCount << " SNMPv1 trap."
|
893 yi.zhou 1.1 << endl;
894 cout << "++++ The trap receiver has received "
895 << currentReceivedTrap2Count << " of "
|
896 yi.zhou 1.8 << indicationTrapV2SendCount << " SNMPv2c trap."
|
897 yi.zhou 1.1 << endl;
898
899 break;
900 }
901 if (receiverTrap1NoChange || receiverTrap2NoChange)
902 {
903 noChangeIterations++;
904 }
905 else
906 {
907 noChangeIterations = 0;
908 }
909
910 System::sleep (SLEEP_SEC);
911 }
912
913 if (!receivedTrapCountComplete)
914 {
915 trapReceiverElapsedTime.stop();
916 }
917
|
918 kumpf 1.7 // assert that all indications sent have been received.
|
919 yi.zhou 1.8 PEGASUS_TEST_ASSERT(indicationTrapV1SendCount ==
|
920 yi.zhou 1.1 currentReceivedTrap1Count);
|
921 yi.zhou 1.8 PEGASUS_TEST_ASSERT(indicationTrapV2SendCount ==
|
922 yi.zhou 1.1 currentReceivedTrap2Count);
|
923 yi.zhou 1.2 }
924
|
925 kumpf 1.7 int _beginTest(CIMClient& workClient,
|
926 yi.zhou 1.2 Uint32 indicationSendCount,
927 Uint32 runClientThreadCount)
928 {
|
929 yi.zhou 1.1
930 #ifdef PEGASUS_USE_NET_SNMP
|
931 yi.zhou 1.2
932 // Stop snmptrapd process if it is running
933 _stopSnmptrapd();
934
935 // if trapLogFile exists, remove it
936 _removeTrapLogFile();
937
938 FILE * trapInfo;
939
940 try
941 {
942 _startSnmptrapd(&trapInfo);
943 }
944 catch (Exception & e)
945 {
946 cerr << e.getMessage() << endl;
947 return (-1);
948 }
949
950 // Extended for all snmp implementation
|
951 kumpf 1.7 _receiveExpectedTraps(workClient, indicationSendCount,
952 runClientThreadCount);
|
953 yi.zhou 1.2
|
954 yi.zhou 1.1 // Stop snmptrapd process if it is running and remove procIdFile
955 _stopSnmptrapd();
956
957 pclose(trapInfo);
958
959 // if error encountered then fail the test.
960 if (errorsEncountered.get())
|
961 kumpf 1.7 {
|
962 yi.zhou 1.1 cout << "+++++ test failed" << endl;
963 return (-1);
964 }
965 else
966 {
967 cout << "+++++ passed all tests" << endl;
968 }
|
969 yi.zhou 1.2
970 return (0);
971
972 #else
973 cerr << "Cannot create a trap receiver." << endl;
974 return (-1);
975 #endif
|
976 yi.zhou 1.1 }
977
978 int main (int argc, char** argv)
979 {
980 // This client connection is used solely to create and delete subscriptions.
981 CIMClient workClient;
982 try
983 {
984 workClient.connectLocal();
985
986 if (argc <= 1 || argc > 4)
987 {
988 cerr << "Invalid argument count: " << argc << endl;
989 _usage();
990 return 1;
991 }
992 else if (strcmp(argv[1], "setup") == 0)
993 {
994 if (argc < 3)
995 {
996 cerr << "Missing query language" << endl;
997 yi.zhou 1.1 _usage();
998 return -1;
999 }
1000
1001 if ((strcmp(argv[2], "WQL") != 0) &&
1002 (strcmp(argv[2], "DMTF:CQL") != 0))
1003 {
1004 cerr << "Invalid query language: '" << argv[2] << "'" << endl;
1005 _usage();
1006 return -1;
1007 }
|
1008 kumpf 1.7
|
1009 yi.zhou 1.1 _setup(workClient, argv[2]);
1010
1011 cout << "+++++ setup completed successfully" << endl;
1012 return 0;
|
1013 kumpf 1.7 }
|
1014 yi.zhou 1.1 else if (String::equalNoCase(argv[1], "run"))
1015 {
1016 if (argc < 3)
1017 {
1018 cerr << "Invalid indicationSendCount." << endl;
1019 _usage ();
1020 return -1;
1021 }
1022
1023 Uint32 indicationSendCount = atoi(argv[2]);
1024
1025 Uint32 runClientThreadCount = 1;
1026
|
1027 kumpf 1.7 if (argc == 4)
|
1028 yi.zhou 1.1 {
1029 runClientThreadCount = atoi(argv[3]);
1030 }
1031
|
1032 kumpf 1.7 int rc = _beginTest(workClient, indicationSendCount,
|
1033 yi.zhou 1.1 runClientThreadCount);
1034 return rc;
|
1035 kumpf 1.7 }
|
1036 yi.zhou 1.1 else if (String::equalNoCase(argv[1], "cleanup"))
1037 {
1038 if (argc > 2)
1039 {
1040 cerr << "Invalid argument count." << endl;
1041 _usage ();
1042 return -1;
1043 }
|
1044 kumpf 1.7
|
1045 yi.zhou 1.1 _cleanup (workClient);
1046
1047 cout << "+++++ cleanup completed successfully" << endl;
1048 return 0;
1049 }
1050 else if (String::equalNoCase(argv[1], "removelog"))
1051 {
1052 if (argc > 2)
1053 {
1054 cerr << "Invalid argument count." << endl;
1055 _usage ();
1056 return -1;
1057 }
|
1058 kumpf 1.7
|
1059 yi.zhou 1.1 _removeTrapLogFile ();
1060 cout << "+++++ removelog completed successfully" << endl;
1061 return 0;
1062 }
1063 else
1064 {
1065 cerr << "Invalid option: " << argv[1] << endl;
1066 _usage ();
1067 return -1;
1068 }
1069 }
1070 catch (Exception & e)
1071 {
1072 cerr << "Error: " << e.getMessage() << endl;
1073 }
1074
1075 PEGASUS_UNREACHABLE( return 0; )
1076 }
|