Route Control & Streaming Video
by Michael Larson 

Listing One

class MeasurementBase
{
public:
     bool processRequest(MsmtRequest &req) = 0; //implemented by derived class

     bool shutdown(); //shutdown this component

protected:
     MeasurementBase(RouteComm *pRouteComm, int iPort) :
m_pRouteComm(pRouteComm), m_iPort(iPort) {;}
     virtual MeasurementBase() {;}

     //commit collected data to data store
     bool submit(Target &target, double dSample);

private:
     bool listen(); //initiates a listen to port, base class will take care of
initial contact

private: //variables
     RouteComm *m_pRouteComm;
     int m_iPort;
};


Listing Two

bool JitterActive::processRequest(MsmtRequest &msmtReq)
{
      Prefix prefix;
      PrefixPaths paths;
      PrefixPaths::iterator iter;
      bool fErr;
      int i;
      double dValue, dResult;
      vector<double> respColl;
      Target target;

      prefix = msmtReq.getPrefix();
      paths = prefix.getPaths();

      iter = paths.begin();
      if (iter == paths.end())
            return Konstants::bFail;

      while (iter != paths.end())
      {
            target = iter->getTarget();
            try
            {
                  fErr = m_pRouteComm->insertTargetRoute(target);
            }
            catch (Exception e)
            {
                  cerr << "Error in insertion of route" << endl;
                  return Konstants::bFailure;
            }

            if (fErr == Konstants::bSuccess)
            {
                  for (i = 0; i < Konstants::iNumProbes; ++i)
                  {
                        fErr = sendProbe(target);
                        if (fErr == Konstants::bFail)
                        {
                              cerr << "Error in sending probe" << endl;
                        }
                        else
                        {
                              dValue = waitForResponse(target);
                              if (dValue < 0)
                              {
                                    dValue = Konstants::dJitterMax;
                                    cerr << "Error in receiving data" << endl;
                              }
                              respColl.push_back(dValue);
                        }
                  }

                  //compute score for this path
                  fErr = computeScore(target, respColl, dResult);
                  if (fErr == Konstants::bFail)
                  {
                        cerr << "Error computing rank for this path" << endl;
                  }
                  else
                  {
                        fErr = submit(target, dResult);
                        if (fErr == Konstants::bFail)
                        {
                              cerr << "Error in writing response" << endl;
                        }
                  }
            }
            //empty result vect
            respColl.erase(respColl.begin(), respColl.end());
            //move to next path
            ++iter;
      }

      try
      {
            //remove last target route
            fErr = m_pRouteComm->removeTargetRoute(target);
      }
      catch (Exception e)
      {
            cerr << "Error in removal of route" << endl;
            return Konstants::bFailure;
      }
      if (fErr == Konstants::bFail)
      {
            cerr << "Error in removal of route" << endl;
            return Konstants::bFailure;
      }

      //finished performing measurements for this target
      return Konstants::bSuccess;
}


Listing Three

bool RouteSelection::engineer(Prefix& prefix)
{
      PrefixPaths paths;
      PrefixPaths::iterator iter;
      int iVal;
      bool fErr;

      paths = prefix.getPaths();
      if (paths.empty() == true)
            return Konstants::bFail;

      //collection is already sorted by path score
      iter = paths.begin(); //best path

      try
      {
            fErr = m_pRouteComm->insertRoute(*iter);
            if (fErr == Konstants::bFail)
                  return fErr;
      }
      catch(Exception e)
      {
            cerr << "Exception thrown by routerInterface " << e << endl;
            return Konstants::bFail;
      }


      if (fErr == Konstants::bFail)
      {
            //recursive call until we get this right
            prefix.removePath(*iter);

            fErr = engineer(prefix);
            if (fErr == Konstants::bFail);
                  return fErr;
      }
      else
      {
            try
            {
                  fErr = m_pState->recordEngineered(*iter);
                  if (fErr == Konstants::bFail)
                        return fErr;
            }
            catch(Exception e)
            {
                  cout << "Exception thrown by State " << e << endl;
                  return Konstants::bFail;
            }
      }
      return Konstants::bSuccess;
}





