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