Probing Network Characteristics 
by Michael Larson

Listing One


template <class T>
class Task : public Task_Base
{
public:
   /*
    * Constructor and Destructor
    */
   Task (const string &taskName, int iMaxQueueSize = 1000);
   virtual ~Task (void);

   /*
    * Initialize object
    */
   virtual int init();

   /*
    * orderly shutdown of task
    */
   virtual int shutdown();

   /*
    * putter/getter for message queue
    */
   virtual int put(T *pT);
   virtual T* get();

   /*
    * size of message queue
    */
   virtual int size();

   /*
    * thread entry point
    */
   virtual int svc();

   /*
    * derived class must implement. main processing entry point.
    */
   virtual void run() = 0;

   /*
    * name of task
    */
   string getName() {return m_taskName;}

   /*
    * Returns a pointer to the lock adapter.
    */
   static ACE_Lock_Adapter<ACE_SYNCH_MUTEX> *lock_adapter (void);

   protected:
   int initTask();

private:
   string m_taskName;

   // Simple Barrier to make sure all service threads have
   // entered their loop before accepting any messages.
   ACE_Barrier m_barrier;

   // This Lock_Adapter is used to synchronize operations
   // on the ACE_Message_Block objects
   static ACE_Lock_Adapter<ACE_SYNCH_MUTEX> lock_adapter_;

   //count of queue
   int m_iQueueCt;
   int m_iMaxQueueSize;
};


Listing Two

class Test
{
public:
typedef enum {kBegin = 0, kBandwidth = 1, kLatency = 2, kEnd = 3} TestType;

public:
   typedef map<TestType, ResultBase*> ResultColl;
   typedef map<TestType, ResultBase*>::iterator ResultIter;

   public:
   /*
    * Constructor and Destructor
    */
   Test() : m_ulTarget(0), m_curTest(kBegin) {addTest(kBegin);}
   ~Test();

   /*
    * Copy Constructor
    */
   Test(Test &test); //copy constructor

   /*
    * Assignment operator
    */
   Test& operator=(Test &test); //assignment operator


   /*
    * Returns target host
    */
   unsigned long
   getTarget() {return m_ulTarget;}

   /*
    * Sets target host
    */
   void
   setTarget(unsigned long ulTarget) {m_ulTarget = ulTarget;}

   /*
    * Copies test object
    */
   void
   copyTest(TestType type, ResultBase *pResult);

   /*
    * Adds new test type
    */
   void
   addTest(TestType type);

   /*
    * Returns curren test
    */
   TestType
   getActiveTest() {return m_curTest;}

   /*
    * Finds next test
    */
   TestType
   nextTest();

   /*
    * Have all tests been iterated?
    */
   bool
   isLastTest();

   /*
    * Sets Latency
    */
   void
   setLatency(double dVal);

   /*
    * Sets Bandwidth
    */
   void
   setBandwidth(long lVal);

   /*
    * Gets Latency
    */
   double
   getLatency();

   /*
    * Gets Bandwidth
    */
   long
   getBandwidth();

   /*
    * Returns result collection
    */
   ResultColl
   getResults() {return m_results;}

   /*
    * Converts value to test type
    */
   static TestType
   toTestType(unsigned char ucType);

   private:
   unsigned long m_ulTarget;  //target address
   ResultColl m_results;      //result collection
   TestType m_curTest;        //current test
};


Listing Three

/**
 * ToolManager::run()
 * Main entry point for tests. Tests are cycled through tools.
 *
 **/
void
ToolManager::run()
{
   ToolBase *pToolBase;

   cout << "ToolManager::StartTask::run(), starting..." << endl;
   while (true)
   {
      Test *pTest(get());
      if (pTest != NULL)
      {
         pTest->nextTest(); //move past kBegin
         pToolBase = getTool(pTest->getActiveTest());
         if (pToolBase != NULL)
         {
            pToolBase->put(pTest);
         }
         else
         {
            delete pTest;
         }
      }
      else
      {
         cout << "event is null..." << endl;
      }
   }
}

   /**
 * ToolManager::CompleteTask::run()
 * Competed tests are either returned to the main test processing
 * thread, or completed tests are dispatched to action processing
 * block.
 *
 **/
void
ToolManager::CompleteTask::run()
{
   while (true)
   {
      Test *pTest(get());
      //      cout << "receiving a test result..." << endl;
      if (pTest != NULL)
      {
         if (pTest->isLastTest() == true)
         {
            m_pToolManager->m_pActionManager->put(pTest); //done
         }
         else
         {
            //put up into parent queue
            m_pToolManager->put(pTest);
         }
      }
   }
}



