bool BSSchedulerSimple::SelectConnection()

in simulation/src/wimax/model/bs-scheduler-simple.cc [221:327]


bool BSSchedulerSimple::SelectConnection (Ptr<WimaxConnection> &connection)
{
  connection = 0;
  Time currentTime = Simulator::Now ();
  std::vector<Ptr<WimaxConnection> >::const_iterator iter1;
  std::vector<ServiceFlow*>::iterator iter2;
  ServiceFlowRecord *serviceFlowRecord;
  NS_LOG_INFO ("BS Scheduler: Selecting connection...");
  if (GetBs ()->GetBroadcastConnection ()->HasPackets ())
    {
      NS_LOG_INFO ("Return GetBroadcastConnection");
      connection = GetBs ()->GetBroadcastConnection ();
      return true;
    }
  else if (GetBs ()->GetInitialRangingConnection ()->HasPackets ())
    {
      NS_LOG_INFO ("Return GetInitialRangingConnection");
      connection = GetBs ()->GetInitialRangingConnection ();
      return true;
    }
  else
    {
      std::vector<Ptr<WimaxConnection> > connections;
      std::vector<ServiceFlow*> serviceFlows;

      connections = GetBs ()->GetConnectionManager ()->GetConnections (Cid::BASIC);
      for (iter1 = connections.begin (); iter1 != connections.end (); ++iter1)
        {
          if ((*iter1)->HasPackets ())
            {
              NS_LOG_INFO ("Return Basic");
              connection = *iter1;
              return true;
            }
        }

      connections = GetBs ()->GetConnectionManager ()->GetConnections (Cid::PRIMARY);
      for (iter1 = connections.begin (); iter1 != connections.end (); ++iter1)
        {
          if ((*iter1)->HasPackets ())
            {
              NS_LOG_INFO ("Return Primary");
              connection = *iter1;
              return true;
            }
        }

      serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_UGS);
      for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
        {
          serviceFlowRecord = (*iter2)->GetRecord ();
          NS_LOG_INFO ("processing UGS: HAS PACKET=" << (*iter2)->HasPackets () << "max Latency = "
                                                     << MilliSeconds ((*iter2)->GetMaximumLatency ()) << "Delay = " << ((currentTime
                                                                                           - serviceFlowRecord->GetDlTimeStamp ()) + GetBs ()->GetPhy ()->GetFrameDuration ()));
          // if latency would exceed in case grant is allocated in next frame then allocate in current frame
          if ((*iter2)->HasPackets () && ((currentTime - serviceFlowRecord->GetDlTimeStamp ())
                                          + GetBs ()->GetPhy ()->GetFrameDuration ()) > MilliSeconds ((*iter2)->GetMaximumLatency ()))
            {
              serviceFlowRecord->SetDlTimeStamp (currentTime);
              connection = (*iter2)->GetConnection ();
              NS_LOG_INFO ("Return UGS SF: CID = " << (*iter2)->GetCid () << "SFID = " << (*iter2)->GetSfid ());
              return true;
            }
        }

      serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_RTPS);
      for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
        {
          serviceFlowRecord = (*iter2)->GetRecord ();
          // if latency would exceed in case poll is allocated in next frame then allocate in current frame
          if ((*iter2)->HasPackets () && ((currentTime - serviceFlowRecord->GetDlTimeStamp ())
                                          + GetBs ()->GetPhy ()->GetFrameDuration ()) > MilliSeconds ((*iter2)->GetMaximumLatency ()))
            {
              serviceFlowRecord->SetDlTimeStamp (currentTime);
              connection = (*iter2)->GetConnection ();
              NS_LOG_INFO ("Return RTPS SF: CID = " << (*iter2)->GetCid () << "SFID = " << (*iter2)->GetSfid ());
              return true;
            }
        }

      serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_NRTPS);
      for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
        {
          //unused: serviceFlowRecord = (*iter2)->GetRecord ();
          if ((*iter2)->HasPackets ())
            {
              NS_LOG_INFO ("Return NRTPS SF: CID = " << (*iter2)->GetCid () << "SFID = " << (*iter2)->GetSfid ());
              connection = (*iter2)->GetConnection ();
              return true;
            }
        }

      serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_BE);
      for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
        {
          //unused: serviceFlowRecord = (*iter2)->GetRecord ();
          if ((*iter2)->HasPackets ())
            {
              NS_LOG_INFO ("Return BE SF: CID = " << (*iter2)->GetCid () << "SFID = " << (*iter2)->GetSfid ());
              connection = (*iter2)->GetConnection ();
              return true;
            }
        }
    }
  NS_LOG_INFO ("NO connection is selected!");
  return false;
}