(file) Return to testSnmpHandler.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Handler / snmpIndicationHandler / tests / testclient

Diff for /pegasus/src/Pegasus/Handler/snmpIndicationHandler/tests/testclient/testSnmpHandler.cpp between version 1.9 and 1.16

version 1.9, 2007/09/07 18:43:08 version 1.16, 2008/11/10 22:05:40
Line 51 
Line 51 
 const String SNMPV1_HANDLER_NAME = "SNMPHandler01"; const String SNMPV1_HANDLER_NAME = "SNMPHandler01";
 const String SNMPV2C_HANDLER_NAME = "SNMPHandler02"; const String SNMPV2C_HANDLER_NAME = "SNMPHandler02";
 const String SNMPV2C_IPV6_HANDLER_NAME = "SNMPHandler03"; const String SNMPV2C_IPV6_HANDLER_NAME = "SNMPHandler03";
 const String FILTER_NAME = "IPFilter01";  const String FILTER_NAME = "SNMPIPFilter01";
  
 enum SNMPVersion {_SNMPV1_TRAP = 2, _SNMPV2C_TRAP = 3}; enum SNMPVersion {_SNMPV1_TRAP = 2, _SNMPV2C_TRAP = 3};
 enum TargetHostFormat {_HOST_NAME = 2, _IPV4_ADDRESS = 3, _IPV6_ADDRESS = 4}; enum TargetHostFormat {_HOST_NAME = 2, _IPV4_ADDRESS = 3, _IPV6_ADDRESS = 4};
Line 69 
Line 69 
 class T_Parms class T_Parms
 { {
 public: public:
     AutoPtr<CIMClient> client;      CIMClient* client;
     Uint32 indicationSendCount;     Uint32 indicationSendCount;
     Uint32 uniqueID;     Uint32 uniqueID;
 }; };
Line 552 
Line 552 
 ThreadReturnType PEGASUS_THREAD_CDECL _executeTests(void *parm) ThreadReturnType PEGASUS_THREAD_CDECL _executeTests(void *parm)
 { {
     Thread *my_thread = (Thread *)parm;     Thread *my_thread = (Thread *)parm;
     T_Parms *parms = (T_Parms *)my_thread->get_parm();      AutoPtr<T_Parms> parms((T_Parms *)my_thread->get_parm());
     CIMClient *client = parms->client.get();      CIMClient* client = parms->client;
     Uint32 indicationSendCount = parms->indicationSendCount;     Uint32 indicationSendCount = parms->indicationSendCount;
     Uint32 id = parms->uniqueID;     Uint32 id = parms->uniqueID;
     char id_[4];     char id_[4];
     memset(id_,0x00,sizeof(id_));     memset(id_,0x00,sizeof(id_));
     sprintf(id_,"%i",id);      sprintf(id_,"%u",id);
     String uniqueID = "_";     String uniqueID = "_";
     uniqueID.append(id_);     uniqueID.append(id_);
  
Line 585 
Line 585 
     {     {
         cout << e.getMessage() << endl;         cout << e.getMessage() << endl;
     }     }
     my_thread->exit_self((ThreadReturnType)1);  
     return(0);      return ThreadReturnType(0);
 } }
  
 Thread * _runTestThreads( Thread * _runTestThreads(
Line 596 
Line 596 
 { {
     // package parameters, create thread and run...     // package parameters, create thread and run...
     AutoPtr<T_Parms> parms(new T_Parms());     AutoPtr<T_Parms> parms(new T_Parms());
     parms->client.reset(client);      parms->client = client;
     parms->indicationSendCount = indicationSendCount;     parms->indicationSendCount = indicationSendCount;
     parms->uniqueID = uniqueID;     parms->uniqueID = uniqueID;
     AutoPtr<Thread> t(new Thread(_executeTests, (void*)parms.release(), false));     AutoPtr<Thread> t(new Thread(_executeTests, (void*)parms.release(), false));
Line 604 
Line 604 
     return t.release();     return t.release();
 } }
  
 String _getLogFile()  Uint32 _getReceivedTrapCount(Uint16 snmpVersion, const String& logFile)
 {  
     return("trapLogFile");  
 }  
   
 Uint32 _getReceivedTrapCount(Uint16 snmpVersion)  
 { {
     String trap1 = "Trap Info: TRAP, SNMP v1, community public";     String trap1 = "Trap Info: TRAP, SNMP v1, community public";
     String trap2 = "Trap Info: TRAP2, SNMP v2c, community public";     String trap2 = "Trap Info: TRAP2, SNMP v2c, community public";
Line 617 
Line 612 
     Uint32 receivedTrap1Count = 0;     Uint32 receivedTrap1Count = 0;
     Uint32 receivedTrap2Count = 0;     Uint32 receivedTrap2Count = 0;
  
     ifstream ifs(_getLogFile().getCString());      ifstream ifs(logFile.getCString());
     if (!ifs)     if (!ifs)
     {     {
         return (0);         return (0);
Line 660 
Line 655 
 // Stop snmptrapd process if it is running and remove // Stop snmptrapd process if it is running and remove
 // procIdFile file if it exists // procIdFile file if it exists
 // //
 void _stopSnmptrapd()  void _stopSnmptrapd(const String& processIdFile)
 { {
     String procIdFileName = "procIdFile";  
   
     Uint32 receiverPid;     Uint32 receiverPid;
     FILE *fd;     FILE *fd;
     if ((fd = fopen(procIdFileName.getCString(), "r")) != NULL)      if ((fd = fopen(processIdFile.getCString(), "r")) != NULL)
     {     {
         fscanf(fd, "%d\n", &receiverPid);          if (fscanf(fd, "%d\n", &receiverPid) != 1)
           {
               throw Exception("Failed to read trapd pid from procIdFile.");
           }
  
         kill(receiverPid, SIGTERM);         kill(receiverPid, SIGTERM);
  
         fclose(fd);         fclose(fd);
     }     }
  
     if (FileSystem::exists(procIdFileName))      if (FileSystem::exists(processIdFile))
     {     {
         FileSystem::removeFile(procIdFileName);          FileSystem::removeFile(processIdFile);
     }     }
 } }
  
 static Boolean _startSnmptrapd( static Boolean _startSnmptrapd(
     FILE **trapInfo)      FILE **trapInfo,
       const String& processIdFile,
       const String& logFile)
 { {
     String snmptrapdCmd;     String snmptrapdCmd;
  
Line 697 
Line 695 
     // Specify logging incoming traps to trapLogFile     // Specify logging incoming traps to trapLogFile
     // Save the process ID of the snmptrapd in procIdFile     // Save the process ID of the snmptrapd in procIdFile
     snmptrapdCmd.append(     snmptrapdCmd.append(
         "/usr/sbin/snmptrapd -f -Lf trapLogFile -p procIdFile");          "/usr/sbin/snmptrapd -f -Lf ");
       snmptrapdCmd.append(logFile);
       snmptrapdCmd.append(" -p ");
       snmptrapdCmd.append(processIdFile);
  
     // Specify incoming trap format     // Specify incoming trap format
     snmptrapdCmd.append( " -F \"\nTrap Info: %P\nVariable: %v\n\"");     snmptrapdCmd.append( " -F \"\nTrap Info: %P\nVariable: %v\n\"");
Line 729 
Line 730 
     while (iterations < MAX_ITERATIONS)     while (iterations < MAX_ITERATIONS)
     {     {
         iterations++;         iterations++;
         if (FileSystem::exists("procIdFile"))          if (FileSystem::exists(processIdFile))
         {         {
             return (true);             return (true);
         }         }
Line 744 
Line 745 
 } }
 #endif #endif
  
 void _removeTrapLogFile ()  void _removeTrapLogFile(const String& logFile)
 { {
     String logFile = _getLogFile();  
   
     // if trapLogFile exists, remove it     // if trapLogFile exists, remove it
     if (FileSystem::exists(logFile))     if (FileSystem::exists(logFile))
     {     {
Line 758 
Line 757 
 void _receiveExpectedTraps( void _receiveExpectedTraps(
     CIMClient& workClient,     CIMClient& workClient,
     Uint32 indicationSendCount,     Uint32 indicationSendCount,
     Uint32 runClientThreadCount)      Uint32 runClientThreadCount,
       const String& logFile)
 { {
     Uint32 indicationTrapV1SendCount = 0;     Uint32 indicationTrapV1SendCount = 0;
     Uint32 indicationTrapV2SendCount = 0;     Uint32 indicationTrapV2SendCount = 0;
Line 808 
Line 808 
     for(Uint32 i=0; i< runClientThreadCount; i++)     for(Uint32 i=0; i< runClientThreadCount; i++)
     {     {
         clientThreads[i]->join();         clientThreads[i]->join();
           delete clientThreads[i];
     }     }
  
     delete[] clientConnections;     delete[] clientConnections;
Line 851 
Line 852 
     {     {
         totalIterations++;         totalIterations++;
  
         currentReceivedTrap1Count = _getReceivedTrapCount(_SNMPV1_TRAP);          currentReceivedTrap1Count =
         currentReceivedTrap2Count = _getReceivedTrapCount(_SNMPV2C_TRAP);              _getReceivedTrapCount(_SNMPV1_TRAP, logFile);
           currentReceivedTrap2Count =
               _getReceivedTrapCount(_SNMPV2C_TRAP, logFile);
  
         if (totalIterations % COUT_TIME_INTERVAL == 1 &&         if (totalIterations % COUT_TIME_INTERVAL == 1 &&
             !(receivedTrapCountComplete))             !(receivedTrapCountComplete))
Line 924 
Line 927 
  
 int _beginTest(CIMClient& workClient, int _beginTest(CIMClient& workClient,
     Uint32 indicationSendCount,     Uint32 indicationSendCount,
     Uint32 runClientThreadCount)      Uint32 runClientThreadCount,
       const String& processIdFile,
       const String& logFile)
 { {
  
 #ifdef PEGASUS_USE_NET_SNMP #ifdef PEGASUS_USE_NET_SNMP
  
     // Stop snmptrapd process if it is running     // Stop snmptrapd process if it is running
     _stopSnmptrapd();      _stopSnmptrapd(processIdFile);
  
     // if trapLogFile exists, remove it     // if trapLogFile exists, remove it
     _removeTrapLogFile();      _removeTrapLogFile(logFile);
  
     FILE * trapInfo;     FILE * trapInfo;
  
     try     try
     {     {
         _startSnmptrapd(&trapInfo);          _startSnmptrapd(&trapInfo, processIdFile, logFile);
     }     }
     catch (Exception & e)     catch (Exception & e)
     {     {
Line 949 
Line 954 
  
     // Extended for all snmp implementation     // Extended for all snmp implementation
     _receiveExpectedTraps(workClient, indicationSendCount,     _receiveExpectedTraps(workClient, indicationSendCount,
         runClientThreadCount);          runClientThreadCount, logFile);
  
     // Stop snmptrapd process if it is running and remove procIdFile     // Stop snmptrapd process if it is running and remove procIdFile
     _stopSnmptrapd();      _stopSnmptrapd(processIdFile);
  
     pclose(trapInfo);     pclose(trapInfo);
  
Line 983 
Line 988 
     {     {
         workClient.connectLocal();         workClient.connectLocal();
  
           String processIdFile = TRAP_DIR;
           processIdFile.append("/procIdFile");
   
           String logFile = TRAP_DIR;
           logFile.append("/trapLogFile");
   
         if (argc <= 1 || argc > 4)         if (argc <= 1 || argc > 4)
         {         {
             cerr << "Invalid argument count: " << argc << endl;             cerr << "Invalid argument count: " << argc << endl;
Line 1030 
Line 1041 
             }             }
  
             int rc = _beginTest(workClient, indicationSendCount,             int rc = _beginTest(workClient, indicationSendCount,
                 runClientThreadCount);                  runClientThreadCount, processIdFile, logFile);
             return rc;             return rc;
         }         }
         else if (String::equalNoCase(argv[1], "cleanup"))         else if (String::equalNoCase(argv[1], "cleanup"))
Line 1056 
Line 1067 
                 return -1;                 return -1;
             }             }
  
             _removeTrapLogFile ();              _removeTrapLogFile(logFile);
             cout << "+++++ removelog completed successfully" << endl;             cout << "+++++ removelog completed successfully" << endl;
             return 0;             return 0;
         }         }
Line 1072 
Line 1083 
         cerr << "Error: " << e.getMessage() << endl;         cerr << "Error: " << e.getMessage() << endl;
     }     }
  
     PEGASUS_UNREACHABLE( return 0; )      return -1;
 } }


Legend:
Removed from v.1.9  
changed lines
  Added in v.1.16

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2