1 martin 1.17 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.18 //
|
3 martin 1.17 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.18 //
|
10 martin 1.17 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.18 //
|
17 martin 1.17 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.18 //
|
20 martin 1.17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.18 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.18 //
|
28 martin 1.17 //////////////////////////////////////////////////////////////////////////
|
29 yi.zhou 1.1 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include <Pegasus/Common/PegasusAssert.h>
33 #include <Pegasus/Common/Thread.h>
34 #include <Pegasus/Common/Constants.h>
35 #include <Pegasus/Common/FileSystem.h>
|
36 thilo.boehm 1.20 #include <Pegasus/General/Stopwatch.h>
|
37 yi.zhou 1.1 #include <Pegasus/Client/CIMClient.h>
|
38 dave.sudlik 1.6 #include <Pegasus/Common/HostAddress.h>
|
39 sahana.prabhakar 1.21 #include <net-snmp/net-snmp-config.h>
40 #include <net-snmp/net-snmp-includes.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 kumpf 1.9 CIMNamespaceName ("test/TestProvider");
|
48 yi.zhou 1.1
|
49 kumpf 1.9 const String INDICATION_CLASS_NAME = "Test_IndicationProviderClass";
|
50 yi.zhou 1.1
|
51 kumpf 1.9 const String SNMPV1_HANDLER_NAME = "SNMPHandler01";
52 const String SNMPV2C_HANDLER_NAME = "SNMPHandler02";
53 const String SNMPV2C_IPV6_HANDLER_NAME = "SNMPHandler03";
|
54 sahana.prabhakar 1.21 const String SNMPV3_HANDLER_NAME = "SNMPHandler04";
|
55 denise.eckstein 1.16 const String FILTER_NAME = "SNMPIPFilter01";
|
56 yi.zhou 1.1
|
57 sahana.prabhakar 1.21 enum SNMPVersion {_SNMPV1_TRAP = 2, _SNMPV2C_TRAP = 3, _SNMPV3_TRAP=5};
|
58 dave.sudlik 1.6 enum TargetHostFormat {_HOST_NAME = 2, _IPV4_ADDRESS = 3, _IPV6_ADDRESS = 4};
|
59 yi.zhou 1.1
60 #define PORT_NUMBER 2006
61
62 AtomicInt errorsEncountered(0);
63
64 ////////////////////////////////////////////////////////////////////////////////
65 //
66 // Thread Parameters Class
67 //
68 ////////////////////////////////////////////////////////////////////////////////
69
|
70 kumpf 1.7 class T_Parms
71 {
72 public:
|
73 kumpf 1.15 CIMClient* client;
|
74 yi.zhou 1.1 Uint32 indicationSendCount;
75 Uint32 uniqueID;
76 };
77
78 ///////////////////////////////////////////////////////////////////////////
79
|
80 kumpf 1.7 CIMObjectPath _getFilterObjectPath(const String & name)
|
81 yi.zhou 1.1 {
82 Array<CIMKeyBinding> keyBindings;
83 keyBindings.append (CIMKeyBinding ("SystemCreationClassName",
84 System::getSystemCreationClassName (), CIMKeyBinding::STRING));
85 keyBindings.append (CIMKeyBinding ("SystemName",
86 System::getFullyQualifiedHostName (), CIMKeyBinding::STRING));
87 keyBindings.append (CIMKeyBinding ("CreationClassName",
88 PEGASUS_CLASSNAME_INDFILTER.getString(), CIMKeyBinding::STRING));
89 keyBindings.append (CIMKeyBinding ("Name", name,
90 CIMKeyBinding::STRING));
91 return(CIMObjectPath("", CIMNamespaceName (),
92 PEGASUS_CLASSNAME_INDFILTER, keyBindings));
93 }
94
|
95 kumpf 1.7 CIMObjectPath _getHandlerObjectPath(const String & name)
|
96 yi.zhou 1.1 {
97 Array<CIMKeyBinding> keyBindings;
98 keyBindings.append (CIMKeyBinding ("SystemCreationClassName",
99 System::getSystemCreationClassName (), CIMKeyBinding::STRING));
100 keyBindings.append (CIMKeyBinding ("SystemName",
101 System::getFullyQualifiedHostName (), CIMKeyBinding::STRING));
102 keyBindings.append (CIMKeyBinding ("CreationClassName",
103 PEGASUS_CLASSNAME_INDHANDLER_SNMP.getString(),
104 CIMKeyBinding::STRING));
105 keyBindings.append (CIMKeyBinding ("Name", name,
106 CIMKeyBinding::STRING));
107 return(CIMObjectPath("", CIMNamespaceName (),
108 PEGASUS_CLASSNAME_INDHANDLER_SNMP, keyBindings));
109 }
110
|
111 kumpf 1.7 CIMObjectPath _getSubscriptionObjectPath(
112 const String & filterName,
113 const String & handlerName)
|
114 yi.zhou 1.1 {
115 CIMObjectPath filterObjectPath = _getFilterObjectPath(filterName);
116
117 CIMObjectPath handlerObjectPath = _getHandlerObjectPath(handlerName);
118
119 Array<CIMKeyBinding> subscriptionKeyBindings;
120 subscriptionKeyBindings.append (CIMKeyBinding ("Filter",
121 CIMValue(filterObjectPath)));
122 subscriptionKeyBindings.append (CIMKeyBinding ("Handler",
123 CIMValue(handlerObjectPath)));
124 return(CIMObjectPath("", CIMNamespaceName (),
125 PEGASUS_CLASSNAME_INDSUBSCRIPTION, subscriptionKeyBindings));
126 }
127
|
128 kumpf 1.7 CIMObjectPath _createHandlerInstance(
129 CIMClient & client,
130 const String & name,
131 const String & targetHost,
132 const String & securityName,
133 const Uint16 targetHostFormat,
|
134 sahana.prabhakar 1.21 const Uint16 snmpVersion,
135 const String & snmpEngineID,
136 const Uint8 & snmpSecLevel,
137 const Uint8 & snmpSecAuthProto,
138 const String & snmpSecAuthKey,
139 const Uint8 & snmpSecPrivProto,
140 const String & snmpSecPrivKey)
|
141 yi.zhou 1.1 {
142 CIMInstance handlerInstance (PEGASUS_CLASSNAME_INDHANDLER_SNMP);
143 handlerInstance.addProperty (CIMProperty (CIMName
144 ("SystemCreationClassName"), System::getSystemCreationClassName ()));
145 handlerInstance.addProperty (CIMProperty (CIMName ("SystemName"),
146 System::getFullyQualifiedHostName ()));
147 handlerInstance.addProperty (CIMProperty (CIMName ("CreationClassName"),
148 PEGASUS_CLASSNAME_INDHANDLER_SNMP.getString ()));
149 handlerInstance.addProperty (CIMProperty (CIMName ("Name"), name));
150 handlerInstance.addProperty (CIMProperty (CIMName ("TargetHost"),
151 targetHost));
152 handlerInstance.addProperty (CIMProperty (CIMName ("TargetHostFormat"),
153 CIMValue ((Uint16) targetHostFormat)));
154 handlerInstance.addProperty (CIMProperty (CIMName ("SNMPSecurityName"),
155 securityName));
156 handlerInstance.addProperty (CIMProperty (CIMName ("SnmpVersion"),
157 CIMValue ((Uint16) snmpVersion)));
158 handlerInstance.addProperty (CIMProperty (CIMName ("PortNumber"),
159 CIMValue ((Uint32) PORT_NUMBER)));
|
160 sahana.prabhakar 1.21 if(snmpVersion == _SNMPV3_TRAP)
161 {
162
163 handlerInstance.addProperty (CIMProperty (
164 CIMName ("SNMPEngineID"),snmpEngineID));
165 handlerInstance.addProperty (CIMProperty (
166 CIMName ("SNMPSecurityLevel"),snmpSecLevel)); //AuthPriv
167 handlerInstance.addProperty (CIMProperty (
168 CIMName ("SNMPSecurityAuthProtocol"),snmpSecAuthProto));
169
170 oid *snmpSecAuthProtoOid;
171 size_t snmpSecAuthProtoLen=0;
172
173 if(snmpSecAuthKey.size() > 0)
174 {
175 if(snmpSecAuthProto == 1)
176 {
177 snmpSecAuthProtoOid = snmp_duplicate_objid(
178 usmHMACMD5AuthProtocol,
179 USM_AUTH_PROTO_MD5_LEN);
180 snmpSecAuthProtoLen = USM_AUTH_PROTO_MD5_LEN;
181 sahana.prabhakar 1.21 }
182 else if(snmpSecAuthProto == 2)
183 {
184 snmpSecAuthProtoOid = snmp_duplicate_objid(
185 usmHMACSHA1AuthProtocol,
186 USM_AUTH_PROTO_SHA_LEN);
187 snmpSecAuthProtoLen = USM_AUTH_PROTO_SHA_LEN;
188 }
189 else
190 {
191 cout << "Invalid authentication protocol specified to " <<
192 "create handler." << endl;
193 PEGASUS_TEST_ASSERT(false);
194 }
195
196 CString snmpSecAuthKeyCstr = snmpSecAuthKey.getCString();
197 size_t authKeyLen = snmpSecAuthKey.size();
198 u_char * snmpSecAuthKeyPtr = (u_char *)malloc(authKeyLen);
199 u_char * encryptedSecurityAuthKey = (u_char *)malloc(authKeyLen);
200 size_t securityAuthKeyLen = USM_AUTH_KU_LEN;
201 memcpy(snmpSecAuthKeyPtr,(const char *)snmpSecAuthKeyCstr,
202 sahana.prabhakar 1.21 strlen(snmpSecAuthKeyCstr));
203 snmpSecAuthKeyPtr[authKeyLen] = '\0';
204
205 if(generate_Ku(snmpSecAuthProtoOid,
206 snmpSecAuthProtoLen,
207 snmpSecAuthKeyPtr,
208 strlen(snmpSecAuthKeyCstr),
209 encryptedSecurityAuthKey,
210 &securityAuthKeyLen) != SNMPERR_SUCCESS)
211 {
212 cout << "Failed to generate the snmp authentication key"
213 << endl;
214 free(snmpSecAuthKeyPtr);
215 free(encryptedSecurityAuthKey);
216 PEGASUS_TEST_ASSERT(false);
217 }
218
219 Array<Uint8> authKey;
220 for(Uint32 i=0; i<securityAuthKeyLen; i++)
221 {
222 authKey.append(encryptedSecurityAuthKey[i]);
223 sahana.prabhakar 1.21 }
224 handlerInstance.addProperty (CIMProperty (
225 CIMName ("SNMPSecurityAuthKey"),
226 authKey));
227 free(snmpSecAuthKeyPtr);
228 free(encryptedSecurityAuthKey);
229 }
230
231 handlerInstance.addProperty (CIMProperty (
232 CIMName ("SNMPSecurityPrivProtocol"),snmpSecPrivProto));
233
234 if(snmpSecPrivKey.size() > 0 )
235 {
236 CString snmpSecPrivKeyCstr = snmpSecPrivKey.getCString();
237 u_char * snmpSecPrivKeyPtr = (u_char *)malloc(USM_PRIV_KU_LEN);
238 u_char * encryptedSecurityPrivKey =
239 (u_char *)malloc(USM_PRIV_KU_LEN);
240 size_t securityPrivKeyLen = USM_PRIV_KU_LEN;
241 memcpy(snmpSecPrivKeyPtr,(const char *)snmpSecPrivKeyCstr,
242 USM_PRIV_KU_LEN);
243 if(generate_Ku(snmpSecAuthProtoOid,
244 sahana.prabhakar 1.21 snmpSecAuthProtoLen,
245 snmpSecPrivKeyPtr,
246 strlen(snmpSecPrivKeyCstr),
247 encryptedSecurityPrivKey,
248 &securityPrivKeyLen) != SNMPERR_SUCCESS)
249 {
250 cout << "Failed to generate the snmp privacy key"
251 << endl;
252 free(snmpSecPrivKeyPtr);
253 free(encryptedSecurityPrivKey);
254 PEGASUS_TEST_ASSERT(false);
255 }
256
257 Array<Uint8> privKey;
258 for(Uint32 i=0; i<securityPrivKeyLen; i++)
259 {
260 privKey.append(encryptedSecurityPrivKey[i]);
261 }
262
263 handlerInstance.addProperty (CIMProperty (
264 CIMName ("SNMPSecurityPrivKey"),
265 sahana.prabhakar 1.21 privKey));
266 free(snmpSecPrivKeyPtr);
267 free(encryptedSecurityPrivKey);
268 }
269 }
|
270 yi.zhou 1.1
|
271 kumpf 1.7 return client.createInstance(
272 PEGASUS_NAMESPACENAME_INTEROP, handlerInstance);
|
273 yi.zhou 1.1 }
274
|
275 kumpf 1.7 CIMObjectPath _createFilterInstance(
276 CIMClient & client,
277 const String & name,
278 const String & query,
279 const String & qlang)
|
280 yi.zhou 1.1 {
281 CIMInstance filterInstance (PEGASUS_CLASSNAME_INDFILTER);
282 filterInstance.addProperty (CIMProperty (CIMName
283 ("SystemCreationClassName"), System::getSystemCreationClassName ()));
284 filterInstance.addProperty (CIMProperty (CIMName ("SystemName"),
285 System::getFullyQualifiedHostName ()));
286 filterInstance.addProperty (CIMProperty (CIMName ("CreationClassName"),
287 PEGASUS_CLASSNAME_INDFILTER.getString ()));
288 filterInstance.addProperty (CIMProperty (CIMName ("Name"), name));
289 filterInstance.addProperty (CIMProperty (CIMName ("Query"), query));
290 filterInstance.addProperty (CIMProperty (CIMName ("QueryLanguage"),
291 String (qlang)));
292 filterInstance.addProperty (CIMProperty (CIMName ("SourceNamespace"),
293 SOURCE_NAMESPACE.getString ()));
294
|
295 kumpf 1.7 return client.createInstance(PEGASUS_NAMESPACENAME_INTEROP, filterInstance);
|
296 yi.zhou 1.1 }
297
|
298 kumpf 1.7 CIMObjectPath _createSubscriptionInstance(
299 CIMClient & client,
300 const CIMObjectPath & filterPath,
301 const CIMObjectPath & handlerPath)
|
302 yi.zhou 1.1 {
303 CIMInstance subscriptionInstance (PEGASUS_CLASSNAME_INDSUBSCRIPTION);
304 subscriptionInstance.addProperty (CIMProperty (CIMName ("Filter"),
305 filterPath, 0, PEGASUS_CLASSNAME_INDFILTER));
306 subscriptionInstance.addProperty (CIMProperty (CIMName ("Handler"),
307 handlerPath, 0, PEGASUS_CLASSNAME_INDHANDLER_SNMP));
308 subscriptionInstance.addProperty (CIMProperty
309 (CIMName ("SubscriptionState"), CIMValue ((Uint16) 2)));
310
|
311 kumpf 1.7 return client.createInstance(
312 PEGASUS_NAMESPACENAME_INTEROP, subscriptionInstance);
|
313 yi.zhou 1.1 }
314
|
315 kumpf 1.7 void _sendTestIndication(
316 CIMClient* client,
317 const CIMName & methodName,
318 Uint32 indicationSendCount)
|
319 yi.zhou 1.1 {
320 //
321 // Invoke method to send test indication
322 //
323 Array <CIMParamValue> inParams;
324 Array <CIMParamValue> outParams;
325 Array <CIMKeyBinding> keyBindings;
326 Sint32 result;
327
328 CIMObjectPath className (String::EMPTY, CIMNamespaceName (),
|
329 kumpf 1.9 CIMName ("Test_IndicationProviderClass"), keyBindings);
|
330 yi.zhou 1.1
|
331 kumpf 1.7 inParams.append(CIMParamValue(String("indicationSendCount"),
|
332 yi.zhou 1.1 CIMValue(indicationSendCount)));
333
334 CIMValue retValue = client->invokeMethod
335 (SOURCE_NAMESPACE,
336 className,
337 methodName,
338 inParams,
339 outParams);
340
341 retValue.get (result);
342 PEGASUS_TEST_ASSERT (result == 0);
343 }
344
|
345 kumpf 1.7 void _deleteSubscriptionInstance(
346 CIMClient & client,
347 const String & filterName,
348 const String & handlerName)
|
349 yi.zhou 1.1 {
350 CIMObjectPath subscriptionObjectPath =
351 _getSubscriptionObjectPath(filterName, handlerName);
|
352 kumpf 1.7 client.deleteInstance(
353 PEGASUS_NAMESPACENAME_INTEROP, subscriptionObjectPath);
|
354 yi.zhou 1.1 }
355
|
356 kumpf 1.7 void _deleteHandlerInstance(
357 CIMClient & client,
358 const String & name)
|
359 yi.zhou 1.1 {
360 CIMObjectPath handlerObjectPath = _getHandlerObjectPath(name);
|
361 karl 1.4 client.deleteInstance (PEGASUS_NAMESPACENAME_INTEROP, handlerObjectPath);
|
362 yi.zhou 1.1 }
363
|
364 kumpf 1.7 void _deleteFilterInstance(
365 CIMClient & client,
366 const String & name)
|
367 yi.zhou 1.1 {
368 CIMObjectPath filterObjectPath = _getFilterObjectPath(name);
|
369 karl 1.4 client.deleteInstance (PEGASUS_NAMESPACENAME_INTEROP, filterObjectPath);
|
370 yi.zhou 1.1 }
371
|
372 kumpf 1.7 void _usage()
|
373 yi.zhou 1.1 {
374 cerr << endl
375 << "Usage:" << endl
376 << " TestSnmpHandler setup [ WQL | DMTF:CQL ]\n"
377 << " TestSnmpHandler run <indicationSendCount> "
378 << "[<threads>]\n"
379 << " where: " << endl
380 << " <indicationSendCount> is the number of indications to\n"
381 << " generate and has to be greater than zero." << endl
382 << " <threads> is an optional number of client threads to\n"
383 << " create, default is one." << endl
384 << " TestSnmpHandler cleanup\n"
|
385 sahana.prabhakar 1.21 << " TestSnmpHandler removelog\n\n"
386 << "Note :\n"
387 << "For running snmp v3 tests create an user by name \"sahana\" in\n"
388 << "smpd.conf and snmptrapd.conf with the following credentials :- \n"
389 << "engineId = 0x80001f88808a67e858ee38ec4c \n"
390 << "Authentication protocol = MD5 \n"
391 << "Privacy Protocol = DES \n"
392 << "Authentication key = setup_passphrase \n"
|
393 yi.zhou 1.1 << endl << endl;
394 }
395
396 void _setup (CIMClient & client, const String& qlang)
397 {
398 CIMObjectPath filterObjectPath;
399 CIMObjectPath snmpv1HandlerObjectPath;
400 CIMObjectPath snmpv2HandlerObjectPath;
|
401 yi.zhou 1.8 CIMObjectPath snmpv2IPV6HandlerObjectPath;
|
402 sahana.prabhakar 1.21 CIMObjectPath snmpv3HandlerObjectPath;
|
403 yi.zhou 1.1
404 try
405 {
406 filterObjectPath = _createFilterInstance (client, FILTER_NAME,
|
407 kumpf 1.9 String ("SELECT * FROM Test_IndicationProviderClass"),
|
408 yi.zhou 1.1 qlang);
409 }
410 catch (CIMException& e)
411 {
412 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
413 {
414 filterObjectPath = _getFilterObjectPath(FILTER_NAME);
415 cerr << "----- Warning: Filter Instance Not Created: "
416 << e.getMessage () << endl;
417 }
418 else
419 {
420 cerr << "----- Error: Filter Instance Not Created: " << endl;
421 throw;
422 }
423 }
424
425 try
426 {
|
427 kumpf 1.7 // Create SNMPv1 trap handler
|
428 yi.zhou 1.1 snmpv1HandlerObjectPath = _createHandlerInstance (client,
429 SNMPV1_HANDLER_NAME,
430 System::getFullyQualifiedHostName(),
431 "",
432 _HOST_NAME,
|
433 sahana.prabhakar 1.21 _SNMPV1_TRAP,
434 String(),0,1,String(),1,String());
|
435 yi.zhou 1.1 }
436 catch (CIMException& e)
437 {
438 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
439 {
440 snmpv1HandlerObjectPath = _getHandlerObjectPath(
441 SNMPV1_HANDLER_NAME);
442 cerr << "----- Warning: SNMPv1 Trap Handler Instance Not Created: "
443 << e.getMessage () << endl;
444 }
445 else
446 {
447 cerr << "----- Error: SNMPv1 Trap Handler Instance Not Created: "
448 << endl;
449 throw;
450 }
451 }
452
453 try
454 {
455 _createSubscriptionInstance (client, filterObjectPath,
456 yi.zhou 1.1 snmpv1HandlerObjectPath);
457 }
458 catch (CIMException& e)
459 {
460 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
461 {
462 cerr << "----- Warning: Client Subscription Instance: "
463 << e.getMessage () << endl;
464 }
465 else
466 {
467 cerr << "----- Error: Client Subscription Instance: " << endl;
468 throw;
469 }
470 }
471
472 try
473 {
|
474 dave.sudlik 1.6 String ipAddress;
475 int af;
476 System::getHostIP(System::getFullyQualifiedHostName (), &af, ipAddress);
|
477 kumpf 1.7 // Create SNMPv2 trap handler
|
478 yi.zhou 1.1 snmpv2HandlerObjectPath = _createHandlerInstance (client,
479 SNMPV2C_HANDLER_NAME,
|
480 dave.sudlik 1.6 ipAddress,
|
481 yi.zhou 1.1 "public",
|
482 dave.sudlik 1.6 af == AF_INET ? _IPV4_ADDRESS : _IPV6_ADDRESS,
|
483 sahana.prabhakar 1.21 _SNMPV2C_TRAP,
484 String(),0,1,String(),1,String());
|
485 yi.zhou 1.1 }
486 catch (CIMException& e)
487 {
488 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
489 {
490 snmpv2HandlerObjectPath = _getHandlerObjectPath(
491 SNMPV2C_HANDLER_NAME);
492 cerr << "----- Warning: SNMPv2c Trap Handler Instance Not Created: "
493 << e.getMessage () << endl;
494 }
495 else
496 {
497 cerr << "----- Error: SNMPv2c Trap Handler Instance Not Created: "
498 << endl;
499 throw;
500 }
501 }
502
503 try
504 {
505 _createSubscriptionInstance (client, filterObjectPath,
506 yi.zhou 1.1 snmpv2HandlerObjectPath);
507 }
508 catch (CIMException& e)
509 {
510 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
511 {
512 cerr << "----- Warning: Client Subscription Instance: "
513 << e.getMessage () << endl;
514 }
515 else
516 {
517 cerr << "----- Error: Client Subscription Instance: " << endl;
518 throw;
519 }
520 }
|
521 yi.zhou 1.8
522 #if defined(PEGASUS_ENABLE_IPV6)
523 // create a subscription with trap destination of IPV6 address format
524 try
525 {
526 // Create SNMPv2 IPV6 trap handler
527 snmpv2IPV6HandlerObjectPath = _createHandlerInstance (client,
528 SNMPV2C_IPV6_HANDLER_NAME,
529 String("::1"),
530 "public",
531 _IPV6_ADDRESS,
|
532 sahana.prabhakar 1.21 _SNMPV2C_TRAP,
533 String(),0,1,String(),1,String());
|
534 kumpf 1.19 }
|
535 yi.zhou 1.8 catch (CIMException& e)
536 {
537 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
538 {
539 snmpv2IPV6HandlerObjectPath = _getHandlerObjectPath(
540 SNMPV2C_IPV6_HANDLER_NAME);
541 cerr << "----- Warning: SNMPv2c IPV6 Trap Handler Instance "
542 "Not Created: " << e.getMessage () << endl;
543 }
544 else
545 {
546 cerr << "----- Error: SNMPv2c IPV6 Trap Handler Instance Not "
547 "Created: " << endl;
548 throw;
549 }
550 }
551
552 try
553 {
554 _createSubscriptionInstance (client, filterObjectPath,
555 snmpv2IPV6HandlerObjectPath);
556 yi.zhou 1.8 }
557 catch (CIMException& e)
558 {
559 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
560 {
561 cerr << "----- Warning: Client Subscription Instance: "
562 << e.getMessage () << endl;
563 }
564 else
565 {
566 cerr << "----- Error: Client Subscription Instance: " << endl;
567 throw;
568 }
569 }
570 #endif
|
571 sahana.prabhakar 1.21
572 // create a snmp V3 trap handler.
573 try
574 {
575 String ipAddress;
576 int af;
577 System::getHostIP(System::getFullyQualifiedHostName (), &af, ipAddress);
578 // Create SNMPv3 trap handler
579 snmpv3HandlerObjectPath = _createHandlerInstance (client,
580 SNMPV3_HANDLER_NAME,
581 System::getFullyQualifiedHostName(),
582 "sahana",
583 _HOST_NAME,
584 _SNMPV3_TRAP,
585 "0x80001f88808a67e858ee38ec4c",
586 3,
587 1,
588 "setup_passphrase",
589 1,
590 "setup_passphrase");
591
592 sahana.prabhakar 1.21 }
593 catch (CIMException& e)
594 {
595 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
596 {
597 snmpv3HandlerObjectPath = _getHandlerObjectPath(
598 SNMPV2C_IPV6_HANDLER_NAME);
599 cerr << "----- Warning: SNMPv3 Trap Handler Instance "
600 "Not Created: " << e.getMessage () << endl;
601 }
602 else
603 {
604 cerr << "----- Error: SNMPv3 Trap Handler Instance Not "
605 "Created: " << endl;
606 throw;
607 }
608 }
609
610 try
611 {
612 _createSubscriptionInstance (client, filterObjectPath,
613 sahana.prabhakar 1.21 snmpv3HandlerObjectPath);
614 }
615 catch (CIMException& e)
616 {
617 if (e.getCode() == CIM_ERR_ALREADY_EXISTS)
618 {
619 cerr << "----- Warning: Client Subscription Instance: "
620 << e.getMessage () << endl;
621 }
622 else
623 {
624 cerr << "----- Error: Client Subscription Instance: " << endl;
625 throw;
626 }
627 }
628 #
|
629 yi.zhou 1.1 }
630
631 void _cleanup (CIMClient & client)
632 {
633 try
634 {
635 _deleteSubscriptionInstance (client, FILTER_NAME,
636 SNMPV1_HANDLER_NAME);
637 }
638 catch (CIMException& e)
639 {
640 if (e.getCode() != CIM_ERR_NOT_FOUND)
641 {
642 cerr << "----- Error: deleteSubscriptionInstance failure: "
643 << endl;
644 throw;
645 }
646 }
647 try
648 {
649 _deleteSubscriptionInstance (client, FILTER_NAME,
650 yi.zhou 1.1 SNMPV2C_HANDLER_NAME);
651 }
652 catch (CIMException& e)
653 {
654 if (e.getCode() != CIM_ERR_NOT_FOUND)
655 {
656 cerr << "----- Error: deleteSubscriptionInstance failure: "
657 << endl;
658 throw;
659 }
660 }
|
661 yi.zhou 1.8
662 #if defined(PEGASUS_ENABLE_IPV6)
|
663 kumpf 1.19 try
|
664 yi.zhou 1.8 {
665 _deleteSubscriptionInstance (client, FILTER_NAME,
666 SNMPV2C_IPV6_HANDLER_NAME);
667 }
668 catch (CIMException& e)
669 {
670 if (e.getCode() != CIM_ERR_NOT_FOUND)
671 {
672 cerr << "----- Error: deleteSubscriptionInstance failure: "
673 << endl;
674 throw;
675 }
676 }
677 #endif
678
|
679 yi.zhou 1.1 try
680 {
|
681 sahana.prabhakar 1.21 _deleteSubscriptionInstance (client, FILTER_NAME,
682 SNMPV3_HANDLER_NAME);
683 }
684 catch (CIMException& e)
685 {
686 if (e.getCode() != CIM_ERR_NOT_FOUND)
687 {
688 cerr << "----- Error: deleteSubscriptionInstance failure: "
689 << endl;
690 throw;
691 }
692 }
693
694 try
695 {
|
696 yi.zhou 1.1 _deleteFilterInstance (client, FILTER_NAME);
697 }
698 catch (CIMException& e)
699 {
700 if (e.getCode() != CIM_ERR_NOT_FOUND)
701 {
702 cerr << "----- Error: deleteFilterInstance failure: " << endl;
703 throw;
704 }
705 }
706
707 try
708 {
709 _deleteHandlerInstance (client, SNMPV1_HANDLER_NAME);
710 }
711 catch (CIMException& e)
712 {
713 if (e.getCode() != CIM_ERR_NOT_FOUND)
714 {
715 cerr << "----- Error: deleteHandlerInstance failure: " << endl;
716 throw;
717 yi.zhou 1.1 }
718 }
719 try
720 {
721 _deleteHandlerInstance (client, SNMPV2C_HANDLER_NAME);
722 }
723 catch (CIMException& e)
724 {
725 if (e.getCode() != CIM_ERR_NOT_FOUND)
726 {
727 cerr << "----- Error: deleteHandlerInstance failure: " << endl;
728 throw;
729 }
730 }
|
731 yi.zhou 1.8 #if defined(PEGASUS_ENABLE_IPV6)
732 try
733 {
734 _deleteHandlerInstance (client, SNMPV2C_IPV6_HANDLER_NAME);
735 }
736 catch (CIMException& e)
737 {
738 if (e.getCode() != CIM_ERR_NOT_FOUND)
739 {
740 cerr << "----- Error: deleteHandlerInstance failure: " << endl;
741 throw;
742 }
743 }
744 #endif
|
745 sahana.prabhakar 1.21
746 try
747 {
748 _deleteHandlerInstance (client, SNMPV3_HANDLER_NAME);
749 }
750 catch (CIMException& e)
751 {
752 if (e.getCode() != CIM_ERR_NOT_FOUND)
753 {
754 cerr << "----- Error: deleteHandlerInstance failure: " << endl;
755 throw;
756 }
757 }
|
758 yi.zhou 1.1 }
759
760 static void _testEnd(const String& uniqueID, const double elapsedTime)
761 {
762 cout << "+++++ thread" << uniqueID << ": passed in " << elapsedTime
763 << " seconds" << endl;
764 }
765
|
766 mike 1.3 ThreadReturnType PEGASUS_THREAD_CDECL _executeTests(void *parm)
|
767 yi.zhou 1.1 {
768 Thread *my_thread = (Thread *)parm;
|
769 kumpf 1.15 AutoPtr<T_Parms> parms((T_Parms *)my_thread->get_parm());
770 CIMClient* client = parms->client;
|
771 yi.zhou 1.1 Uint32 indicationSendCount = parms->indicationSendCount;
772 Uint32 id = parms->uniqueID;
773 char id_[4];
774 memset(id_,0x00,sizeof(id_));
|
775 kumpf 1.14 sprintf(id_,"%u",id);
|
776 yi.zhou 1.1 String uniqueID = "_";
777 uniqueID.append(id_);
778
779 try
780 {
781 Stopwatch elapsedTime;
782
783 elapsedTime.start();
784 try
785 {
786 _sendTestIndication (client, CIMName ("SendTestIndicationTrap"),
787 indicationSendCount);
788 }
789 catch (Exception & e)
790 {
|
791 kumpf 1.7 cerr << "----- sendTestIndication failed: " << e.getMessage () <<
792 endl;
|
793 yi.zhou 1.1 exit (-1);
794 }
795 elapsedTime.stop();
796 _testEnd(uniqueID, elapsedTime.getElapsed());
797 }
798 catch(Exception & e)
799 {
800 cout << e.getMessage() << endl;
801 }
|
802 kumpf 1.12
803 return ThreadReturnType(0);
|
804 yi.zhou 1.1 }
805
806 Thread * _runTestThreads(
807 CIMClient* client,
808 Uint32 indicationSendCount,
809 Uint32 uniqueID)
810 {
811 // package parameters, create thread and run...
812 AutoPtr<T_Parms> parms(new T_Parms());
|
813 kumpf 1.15 parms->client = client;
|
814 yi.zhou 1.1 parms->indicationSendCount = indicationSendCount;
815 parms->uniqueID = uniqueID;
816 AutoPtr<Thread> t(new Thread(_executeTests, (void*)parms.release(), false));
817 t->run();
818 return t.release();
819 }
820
|
821 yi.zhou 1.13 Uint32 _getReceivedTrapCount(Uint16 snmpVersion, const String& logFile)
|
822 yi.zhou 1.1 {
823 String trap1 = "Trap Info: TRAP, SNMP v1, community public";
824 String trap2 = "Trap Info: TRAP2, SNMP v2c, community public";
|
825 sahana.prabhakar 1.21 String trap3 = "Trap Info: TRAP2, SNMP v3, user sahana, context ";
|
826 yi.zhou 1.1
827 Uint32 receivedTrap1Count = 0;
828 Uint32 receivedTrap2Count = 0;
|
829 sahana.prabhakar 1.21 Uint32 receivedTrap3Count = 0;
|
830 kumpf 1.7
|
831 yi.zhou 1.13 ifstream ifs(logFile.getCString());
|
832 yi.zhou 1.1 if (!ifs)
833 {
834 return (0);
835 }
836
837 String line;
838 while (GetLine(ifs, line))
839 {
840 if (String::compare(line, trap1) == 0)
841 {
842 receivedTrap1Count++;
843 }
844 if (String::compare(line, trap2) == 0)
845 {
846 receivedTrap2Count++;
847 }
|
848 sahana.prabhakar 1.21 if (String::compare(line, trap3) == 0)
849 {
850 receivedTrap3Count++;
851 }
|
852 yi.zhou 1.1 }
853
854 ifs.close();
855
856 switch (snmpVersion)
857 {
858 case _SNMPV1_TRAP:
859 {
860 return (receivedTrap1Count);
861 }
862 case _SNMPV2C_TRAP:
863 {
864 return (receivedTrap2Count);
865 }
|
866 sahana.prabhakar 1.21 case _SNMPV3_TRAP:
867 {
868 return (receivedTrap3Count);
869 }
|
870 yi.zhou 1.1 default:
871 {
872 return (0);
873 }
874 }
875
876 }
877
878 #ifdef PEGASUS_USE_NET_SNMP
|
879 kumpf 1.7 // Stop snmptrapd process if it is running and remove
|
880 yi.zhou 1.1 // procIdFile file if it exists
|
881 kumpf 1.7 //
|
882 yi.zhou 1.13 void _stopSnmptrapd(const String& processIdFile)
|
883 yi.zhou 1.1 {
884 Uint32 receiverPid;
885 FILE *fd;
|
886 yi.zhou 1.13 if ((fd = fopen(processIdFile.getCString(), "r")) != NULL)
|
887 yi.zhou 1.1 {
|
888 kumpf 1.10 if (fscanf(fd, "%d\n", &receiverPid) != 1)
889 {
890 throw Exception("Failed to read trapd pid from procIdFile.");
891 }
|
892 kumpf 1.7
|
893 yi.zhou 1.1 kill(receiverPid, SIGTERM);
894
895 fclose(fd);
896 }
897
|
898 yi.zhou 1.13 if (FileSystem::exists(processIdFile))
|
899 yi.zhou 1.1 {
|
900 yi.zhou 1.13 FileSystem::removeFile(processIdFile);
|
901 yi.zhou 1.1 }
902 }
903
904 static Boolean _startSnmptrapd(
|
905 yi.zhou 1.13 FILE **trapInfo,
906 const String& processIdFile,
907 const String& logFile)
|
908 yi.zhou 1.1 {
909 String snmptrapdCmd;
910
911 Uint32 portNumber = PORT_NUMBER;
912 char portNumberStr[32];
913 sprintf(portNumberStr, "%lu", (unsigned long) portNumber);
914
915 //
916 // build snmptrapd cmd options
917 //
918
|
919 kumpf 1.7 // Specify logging incoming traps to trapLogFile
|
920 yi.zhou 1.1 // Save the process ID of the snmptrapd in procIdFile
921 snmptrapdCmd.append(
|
922 yi.zhou 1.13 "/usr/sbin/snmptrapd -f -Lf ");
923 snmptrapdCmd.append(logFile);
924 snmptrapdCmd.append(" -p ");
925 snmptrapdCmd.append(processIdFile);
|
926 yi.zhou 1.1
927 // Specify incoming trap format
928 snmptrapdCmd.append( " -F \"\nTrap Info: %P\nVariable: %v\n\"");
929
930 // Specify listening address
|
931 yi.zhou 1.8 #if defined(PEGASUS_ENABLE_IPV6)
932 snmptrapdCmd.append(" UDP6:");
933 snmptrapdCmd.append(portNumberStr);
934 snmptrapdCmd.append(",UDP:");
935 #else
|
936 yi.zhou 1.1 snmptrapdCmd.append(" UDP:");
|
937 yi.zhou 1.8 #endif
|
938 yi.zhou 1.1 snmptrapdCmd.append(System::getFullyQualifiedHostName ());
939
940 snmptrapdCmd.append(":");
941 snmptrapdCmd.append(portNumberStr);
942
943 if ((*trapInfo = popen(snmptrapdCmd.getCString(), "r")) == NULL)
944 {
945 throw Exception ("snmptrapd can not be started");
946 }
947
948 #define MAX_ITERATIONS 300
949 #define SLEEP_SEC 1
950
951 Uint32 iterations = 0;
952
|
953 kumpf 1.7 // Wait until snmptrapd started
|
954 yi.zhou 1.1 while (iterations < MAX_ITERATIONS)
955 {
956 iterations++;
|
957 yi.zhou 1.13 if (FileSystem::exists(processIdFile))
|
958 yi.zhou 1.1 {
959 return (true);
960 }
961 else
962 {
963 System::sleep(SLEEP_SEC);
|
964 kumpf 1.7
|
965 yi.zhou 1.1 }
966 }
967
968 throw Exception ("snmptrapd can not be started");
969 }
970 #endif
971
|
972 yi.zhou 1.13 void _removeTrapLogFile(const String& logFile)
|
973 yi.zhou 1.1 {
974 // if trapLogFile exists, remove it
975 if (FileSystem::exists(logFile))
976 {
977 FileSystem::removeFile(logFile);
978 }
979 }
980
|
981 kumpf 1.7 void _receiveExpectedTraps(
982 CIMClient& workClient,
|
983 yi.zhou 1.1 Uint32 indicationSendCount,
|
984 yi.zhou 1.13 Uint32 runClientThreadCount,
985 const String& logFile)
|
986 yi.zhou 1.1 {
|
987 yi.zhou 1.8 Uint32 indicationTrapV1SendCount = 0;
988 Uint32 indicationTrapV2SendCount = 0;
|
989 sahana.prabhakar 1.21 Uint32 indicationTrapV3SendCount = 0;
|
990 yi.zhou 1.8
|
991 yi.zhou 1.1 CIMClient * clientConnections = new CIMClient[runClientThreadCount];
992
993 // determine total number of indication send count
|
994 yi.zhou 1.8 indicationTrapV1SendCount =
995 indicationSendCount * runClientThreadCount;
996
997 // if IPV6 is enabled, an additional SNMPv2c trap is sent to IPV6 address
998 #if defined(PEGASUS_ENABLE_IPV6)
|
999 kumpf 1.19 indicationTrapV2SendCount = 2 * indicationTrapV1SendCount;
|
1000 yi.zhou 1.8 #else
1001 indicationTrapV2SendCount = indicationTrapV1SendCount;
1002 #endif
|
1003 yi.zhou 1.1
|
1004 sahana.prabhakar 1.21 indicationTrapV3SendCount =
1005 indicationSendCount * runClientThreadCount;
1006
|
1007 yi.zhou 1.1 // calculate the timeout based on the total send count allowing
|
1008 kumpf 1.7 // using the MSG_PER_SEC rate
1009 // allow 20 seconds of test overhead for very small tests
|
1010 yi.zhou 1.1
1011 #define MSG_PER_SEC 4
1012
|
1013 marek 1.5 Uint32 testTimeout = PEGASUS_DEFAULT_CLIENT_TIMEOUT_MILLISECONDS
|
1014 yi.zhou 1.8 + (indicationTrapV2SendCount/MSG_PER_SEC)*1000;
|
1015 yi.zhou 1.1
1016 // connect the clients
1017 for(Uint32 i = 0; i < runClientThreadCount; i++)
1018 {
1019 clientConnections[i].setTimeout(testTimeout);
1020 clientConnections[i].connectLocal();
1021 }
1022
1023 // run tests
1024 Thread ** clientThreads = new Thread *[runClientThreadCount];
1025
1026 Stopwatch trapReceiverElapsedTime;
1027
1028 trapReceiverElapsedTime.start();
1029
1030 for(Uint32 i = 0; i < runClientThreadCount; i++)
1031 {
1032 clientThreads[i] = _runTestThreads(&clientConnections[i],
1033 indicationSendCount, i);
1034 }
1035
1036 yi.zhou 1.1 for(Uint32 i=0; i< runClientThreadCount; i++)
1037 {
1038 clientThreads[i]->join();
|
1039 kumpf 1.15 delete clientThreads[i];
|
1040 yi.zhou 1.1 }
1041
1042 delete[] clientConnections;
1043 delete[] clientThreads;
1044
1045 //
1046 // Allow time for the trap to be received
1047 // Wait in SLEEP_SEC second intervals.
1048 // Put msg out every MSG_SEC intervals
1049 //
1050
1051 #define SLEEP_SEC 1
1052 #define COUT_TIME_INTERVAL 30
1053 #define MAX_NO_CHANGE_ITERATIONS COUT_TIME_INTERVAL*3
1054
1055 Uint32 noChangeIterations = 0;
1056 Uint32 priorReceivedTrap1Count = 0;
1057 Uint32 priorReceivedTrap2Count = 0;
|
1058 sahana.prabhakar 1.21 Uint32 priorReceivedTrap3Count = 0;
|
1059 yi.zhou 1.1 Uint32 currentReceivedTrap1Count = 0;
1060 Uint32 currentReceivedTrap2Count = 0;
|
1061 sahana.prabhakar 1.21 Uint32 currentReceivedTrap3Count = 0;
|
1062 yi.zhou 1.1 Uint32 totalIterations = 0;
1063
1064 //
1065 // Wait for the trap receiver to receive the expected
|
1066 yi.zhou 1.8 // number of Indication traps, indicationTrapV1SendCount
1067 // and indicationTrapV2SendCount.
|
1068 yi.zhou 1.1 //
|
1069 yi.zhou 1.8 // We will continue to wait until either (indicationTrapV1SendCount
1070 // and indicationTrapV2SendCount) Indications have been received
1071 // by the trap receiver or no new
|
1072 yi.zhou 1.1 // Indications have been received in the previous
1073 // MAX_NO_CHANGE_ITERATIONS.
|
1074 kumpf 1.7 // iterations.
|
1075 yi.zhou 1.1 //
1076
1077 Boolean receivedTrapCountComplete = false;
1078 Boolean receiverTrap1NoChange = true;
1079 Boolean receiverTrap2NoChange = true;
|
1080 sahana.prabhakar 1.21 Boolean receiverTrap3NoChange = true;
|
1081 yi.zhou 1.1
1082 while (noChangeIterations <= MAX_NO_CHANGE_ITERATIONS)
1083 {
1084 totalIterations++;
1085
|
1086 kumpf 1.19 currentReceivedTrap1Count =
|
1087 yi.zhou 1.13 _getReceivedTrapCount(_SNMPV1_TRAP, logFile);
|
1088 kumpf 1.19 currentReceivedTrap2Count =
|
1089 yi.zhou 1.13 _getReceivedTrapCount(_SNMPV2C_TRAP, logFile);
|
1090 sahana.prabhakar 1.21 currentReceivedTrap3Count =
1091 _getReceivedTrapCount(_SNMPV3_TRAP,logFile);
|
1092 yi.zhou 1.1
1093 if (totalIterations % COUT_TIME_INTERVAL == 1 &&
1094 !(receivedTrapCountComplete))
1095 {
1096 cout << "++++ The trap receiver has received "
1097 << currentReceivedTrap1Count << " of "
|
1098 yi.zhou 1.8 << indicationTrapV1SendCount << " SNMPv1 trap."
|
1099 yi.zhou 1.1 << endl;
1100 cout << "++++ The trap receiver has received "
1101 << currentReceivedTrap2Count << " of "
|
1102 yi.zhou 1.8 << indicationTrapV2SendCount << " SNMPv2c trap."
|
1103 yi.zhou 1.1 << endl;
|
1104 sahana.prabhakar 1.21 cout << "++++ The trap receiver has received "
1105 << currentReceivedTrap3Count<< " of "
1106 << indicationTrapV3SendCount << " SNMPv3 trap."
1107 << endl;
|
1108 yi.zhou 1.1 }
1109
|
1110 yi.zhou 1.8 if ((indicationTrapV1SendCount == currentReceivedTrap1Count) &&
|
1111 sahana.prabhakar 1.21 (indicationTrapV2SendCount == currentReceivedTrap2Count) &&
1112 (indicationTrapV3SendCount == currentReceivedTrap3Count))
|
1113 yi.zhou 1.1 {
1114 receivedTrapCountComplete = true;
1115 trapReceiverElapsedTime.stop();
1116 }
1117 if (!(receiverTrap1NoChange =
1118 (priorReceivedTrap1Count == currentReceivedTrap1Count)))
1119 {
1120 priorReceivedTrap1Count = currentReceivedTrap1Count;
1121 }
1122
1123 if (!(receiverTrap2NoChange =
1124 (priorReceivedTrap2Count == currentReceivedTrap2Count)))
1125 {
1126 priorReceivedTrap2Count = currentReceivedTrap2Count;
1127 }
|
1128 sahana.prabhakar 1.21 if (!(receiverTrap3NoChange =
1129 (priorReceivedTrap3Count == currentReceivedTrap3Count)))
1130 {
1131 priorReceivedTrap3Count = currentReceivedTrap3Count;
1132 }
|
1133 yi.zhou 1.1
1134 if (receivedTrapCountComplete)
1135 {
1136 cout << "++++ The trap receiver has received "
1137 << currentReceivedTrap1Count << " of "
|
1138 yi.zhou 1.8 << indicationTrapV1SendCount << " SNMPv1 trap."
|
1139 yi.zhou 1.1 << endl;
1140 cout << "++++ The trap receiver has received "
1141 << currentReceivedTrap2Count << " of "
|
1142 yi.zhou 1.8 << indicationTrapV2SendCount << " SNMPv2c trap."
|
1143 yi.zhou 1.1 << endl;
|
1144 sahana.prabhakar 1.21 cout << "++++ The trap receiver has received "
1145 << currentReceivedTrap3Count << " of "
1146 << indicationTrapV3SendCount<< " SNMPv3 trap."
1147 << endl;
|
1148 yi.zhou 1.1
1149 break;
1150 }
|
1151 sahana.prabhakar 1.21 if (receiverTrap1NoChange ||
1152 receiverTrap2NoChange ||
1153 receiverTrap3NoChange)
|
1154 yi.zhou 1.1 {
1155 noChangeIterations++;
1156 }
1157 else
1158 {
1159 noChangeIterations = 0;
1160 }
1161
1162 System::sleep (SLEEP_SEC);
1163 }
1164
1165 if (!receivedTrapCountComplete)
1166 {
1167 trapReceiverElapsedTime.stop();
1168 }
1169
|
1170 kumpf 1.7 // assert that all indications sent have been received.
|
1171 yi.zhou 1.8 PEGASUS_TEST_ASSERT(indicationTrapV1SendCount ==
|
1172 yi.zhou 1.1 currentReceivedTrap1Count);
|
1173 yi.zhou 1.8 PEGASUS_TEST_ASSERT(indicationTrapV2SendCount ==
|
1174 yi.zhou 1.1 currentReceivedTrap2Count);
|
1175 sahana.prabhakar 1.21 PEGASUS_TEST_ASSERT(indicationTrapV3SendCount ==
1176 currentReceivedTrap3Count);
|
1177 yi.zhou 1.2 }
1178
|
1179 kumpf 1.7 int _beginTest(CIMClient& workClient,
|
1180 yi.zhou 1.2 Uint32 indicationSendCount,
|
1181 yi.zhou 1.13 Uint32 runClientThreadCount,
1182 const String& processIdFile,
1183 const String& logFile)
|
1184 yi.zhou 1.2 {
|
1185 yi.zhou 1.1
1186 #ifdef PEGASUS_USE_NET_SNMP
|
1187 yi.zhou 1.2
1188 // Stop snmptrapd process if it is running
|
1189 yi.zhou 1.13 _stopSnmptrapd(processIdFile);
|
1190 yi.zhou 1.2
1191 // if trapLogFile exists, remove it
|
1192 yi.zhou 1.13 _removeTrapLogFile(logFile);
|
1193 yi.zhou 1.2
1194 FILE * trapInfo;
1195
1196 try
1197 {
|
1198 yi.zhou 1.13 _startSnmptrapd(&trapInfo, processIdFile, logFile);
|
1199 yi.zhou 1.2 }
1200 catch (Exception & e)
1201 {
1202 cerr << e.getMessage() << endl;
1203 return (-1);
1204 }
1205
1206 // Extended for all snmp implementation
|
1207 kumpf 1.7 _receiveExpectedTraps(workClient, indicationSendCount,
|
1208 yi.zhou 1.13 runClientThreadCount, logFile);
|
1209 yi.zhou 1.2
|
1210 yi.zhou 1.1 // Stop snmptrapd process if it is running and remove procIdFile
|
1211 yi.zhou 1.13 _stopSnmptrapd(processIdFile);
|
1212 yi.zhou 1.1
1213 pclose(trapInfo);
1214
1215 // if error encountered then fail the test.
1216 if (errorsEncountered.get())
|
1217 kumpf 1.7 {
|
1218 yi.zhou 1.1 cout << "+++++ test failed" << endl;
1219 return (-1);
1220 }
1221 else
1222 {
1223 cout << "+++++ passed all tests" << endl;
1224 }
|
1225 yi.zhou 1.2
1226 return (0);
1227
1228 #else
1229 cerr << "Cannot create a trap receiver." << endl;
1230 return (-1);
1231 #endif
|
1232 yi.zhou 1.1 }
1233
1234 int main (int argc, char** argv)
1235 {
1236 // This client connection is used solely to create and delete subscriptions.
1237 CIMClient workClient;
1238 try
1239 {
1240 workClient.connectLocal();
1241
|
1242 yi.zhou 1.13 String processIdFile = TRAP_DIR;
1243 processIdFile.append("/procIdFile");
1244
1245 String logFile = TRAP_DIR;
1246 logFile.append("/trapLogFile");
1247
|
1248 yi.zhou 1.1 if (argc <= 1 || argc > 4)
1249 {
1250 cerr << "Invalid argument count: " << argc << endl;
1251 _usage();
1252 return 1;
1253 }
1254 else if (strcmp(argv[1], "setup") == 0)
1255 {
1256 if (argc < 3)
1257 {
1258 cerr << "Missing query language" << endl;
1259 _usage();
1260 return -1;
1261 }
1262
1263 if ((strcmp(argv[2], "WQL") != 0) &&
1264 (strcmp(argv[2], "DMTF:CQL") != 0))
1265 {
1266 cerr << "Invalid query language: '" << argv[2] << "'" << endl;
1267 _usage();
1268 return -1;
1269 yi.zhou 1.1 }
|
1270 kumpf 1.7
|
1271 yi.zhou 1.1 _setup(workClient, argv[2]);
1272
1273 cout << "+++++ setup completed successfully" << endl;
1274 return 0;
|
1275 kumpf 1.7 }
|
1276 yi.zhou 1.1 else if (String::equalNoCase(argv[1], "run"))
1277 {
1278 if (argc < 3)
1279 {
1280 cerr << "Invalid indicationSendCount." << endl;
1281 _usage ();
1282 return -1;
1283 }
1284
1285 Uint32 indicationSendCount = atoi(argv[2]);
1286
1287 Uint32 runClientThreadCount = 1;
1288
|
1289 kumpf 1.7 if (argc == 4)
|
1290 yi.zhou 1.1 {
1291 runClientThreadCount = atoi(argv[3]);
1292 }
1293
|
1294 kumpf 1.7 int rc = _beginTest(workClient, indicationSendCount,
|
1295 yi.zhou 1.13 runClientThreadCount, processIdFile, logFile);
|
1296 yi.zhou 1.1 return rc;
|
1297 kumpf 1.7 }
|
1298 yi.zhou 1.1 else if (String::equalNoCase(argv[1], "cleanup"))
1299 {
1300 if (argc > 2)
1301 {
1302 cerr << "Invalid argument count." << endl;
1303 _usage ();
1304 return -1;
1305 }
|
1306 kumpf 1.7
|
1307 yi.zhou 1.1 _cleanup (workClient);
1308
1309 cout << "+++++ cleanup completed successfully" << endl;
1310 return 0;
1311 }
1312 else if (String::equalNoCase(argv[1], "removelog"))
1313 {
1314 if (argc > 2)
1315 {
1316 cerr << "Invalid argument count." << endl;
1317 _usage ();
1318 return -1;
1319 }
|
1320 kumpf 1.7
|
1321 yi.zhou 1.13 _removeTrapLogFile(logFile);
|
1322 yi.zhou 1.1 cout << "+++++ removelog completed successfully" << endl;
1323 return 0;
1324 }
1325 else
1326 {
1327 cerr << "Invalid option: " << argv[1] << endl;
1328 _usage ();
1329 return -1;
1330 }
1331 }
1332 catch (Exception & e)
1333 {
1334 cerr << "Error: " << e.getMessage() << endl;
1335 }
1336
|
1337 kumpf 1.11 return -1;
|
1338 yi.zhou 1.1 }
|