/*
 *  DEBUG
 */
void
NetworkManager::Print (void)
{
  cout << " TOTAL Network Manager Debug: " << endl;

  std::vector<Cell*>* cellContainer = GetCellContainer ();
  std::vector<Cell*>::iterator iter;
  Cell *cell;
  for (iter = cellContainer->begin ();
      iter !=cellContainer->end (); iter++)
    {
    cell = *iter;
    cell->Print();
    }

  std::vector<ENodeB*>* eNodeBContainer = GetENodeBContainer ();
  std::vector<ENodeB*>::iterator iter2;
  ENodeB *eNodeB;
  for (iter2 = eNodeBContainer->begin ();
      iter2 !=eNodeBContainer->end (); iter2++)
    {
    eNodeB = *iter2;
    eNodeB->Print();
    }

  std::vector<UserEquipment*>* userEquipmentContainer = GetUserEquipmentContainer ();
  std::vector<UserEquipment*>::iterator iter3;
  UserEquipment *userEquipment;
  for (iter3 = userEquipmentContainer->begin ();
      iter3 !=userEquipmentContainer->end (); iter3++)
    {
    userEquipment = *iter3;
    userEquipment->Print();
    }
}
UserEquipment*
NetworkManager::CreateUserEquipment (int id,
				 					 double pos_X, double pos_Y, double speed, double speedDirection,
									 Cell* cell, ENodeB* enb)
{
  UserEquipment* ue = new UserEquipment (id,
										 pos_X, pos_Y, speed, speedDirection,
										 cell, enb,
										 0,
										 Mobility::RANDOM_DIRECTION);

  ue->GetPhy ()->SetDlChannel (enb->GetPhy()->GetDlChannel ());
  ue->GetPhy ()->SetUlChannel (enb->GetPhy()->GetUlChannel ());

  FullbandCqiManager *cqiManager = new FullbandCqiManager ();
  cqiManager->SetCqiReportingMode (CqiManager::PERIODIC);
  cqiManager->SetReportingInterval (1);
  cqiManager->SetDevice (ue);
  ue->SetCqiManager (cqiManager);

  enb->RegisterUserEquipment (ue);

  MacroCellUrbanAreaChannelRealization* c_dl = new MacroCellUrbanAreaChannelRealization (enb, ue);
  enb->GetPhy()->GetDlChannel ()->GetPropagationLossModel ()->AddChannelRealization (c_dl);
  MacroCellUrbanAreaChannelRealization* c_ul = new MacroCellUrbanAreaChannelRealization (ue, enb);
  enb->GetPhy()->GetUlChannel ()->GetPropagationLossModel ()->AddChannelRealization (c_ul);

  GetUserEquipmentContainer ()->push_back (ue);

  return ue;
}
double
MacroCellUrbanAreaChannelRealization::GetPathLoss (void)
{
  /*
   * According to  ---  insert standard 3gpp ---
   * the Path Loss Model For Urban Environment is
   * L = I + 37.6log10(R)
   * R, in kilometers, is the distance between two nodes
   * I = 128.1 at 2GHz
   */
  double distance;
  double externalWallAttenuation = 20; //[dB]

  NetworkNode* src = GetSourceNode ();
  NetworkNode* dst = GetDestinationNode ();

  distance = src->GetMobilityModel ()->GetAbsolutePosition ()->GetDistance (
		  dst->GetMobilityModel ()->GetAbsolutePosition ());

  /*
  if (GetSourceNode ()->GetNodeType () == NetworkNode::TYPE_UE
		  && GetDestinationNode ()->GetNodeType () == NetworkNode::TYPE_ENODEB)
    {
	  UserEquipment* ue = (UserEquipment*) GetSourceNode ();
	  ENodeB* enb = (ENodeB*) GetDestinationNode ();

	  distance =  ue->GetMobilityModel ()->GetAbsolutePosition ()->GetDistance (enb->GetMobilityModel ()->GetAbsolutePosition ());
    }

  else if (GetDestinationNode ()->GetNodeType () == NetworkNode::TYPE_UE
		  && GetSourceNode ()->GetNodeType () == NetworkNode::TYPE_ENODEB)
    {
	  UserEquipment* ue = (UserEquipment*) GetDestinationNode ();
	  ENodeB* enb = (ENodeB*) GetSourceNode ();

	  distance =  ue->GetMobilityModel ()->GetAbsolutePosition ()->GetDistance (enb->GetMobilityModel ()->GetAbsolutePosition ());
    }
  */

  m_pathLoss = 128.1 + (37.6 * log10 (distance * 0.001));

  UserEquipment* ue;
  if (GetSourceNode ()->GetNodeType () == NetworkNode::TYPE_UE)
    {
	  ue = (UserEquipment*) GetSourceNode ();
    }
  else
   {
	  ue = (UserEquipment*) GetDestinationNode ();
   }

  if ( ue->IsIndoor() )
  {
	  m_pathLoss = m_pathLoss + externalWallAttenuation;
  }


  return m_pathLoss;
}
double
FemtoCellUrbanAreaChannelRealization::GetPathLoss (void)
{
	/*
	 * Path loss Models from sect. 5.2 in
	 * 3GPP TSG RAN WG4 R4-092042
	 *
	 * Alternative simplified model based on LTE-A evaluation methodology which avoids modeling any walls.
	 */

  double distance;
  double minimumCouplingLoss = 45; //[dB] - see 3GPP TSG RAN WG4 #42bis (R4-070456)
  double floorPenetration = 0.0;
  //18.3 n ((n+2)/(n+1)-0.46)

  if (GetSourceNode ()->GetNodeType () == NetworkNode::TYPE_UE
		  && ( GetDestinationNode ()->GetNodeType () == NetworkNode::TYPE_ENODEB || GetDestinationNode ()->GetNodeType () == NetworkNode::TYPE_HOME_BASE_STATION) )
    {
	  UserEquipment* ue = (UserEquipment*) GetSourceNode ();
	  ENodeB* enb = (ENodeB*) GetDestinationNode ();

	  if( enb->GetCell()->GetCellCenterPosition()->GetCoordinateZ() > 0
			  && ue->IsIndoor()
			     && enb->GetCell()->GetCellCenterPosition()->GetCoordinateZ() != ue->GetCell()->GetCellCenterPosition()->GetCoordinateZ())
	  {
		  int n = (int) abs( enb->GetCell()->GetCellCenterPosition()->GetCoordinateZ() - ue->GetCell()->GetCellCenterPosition()->GetCoordinateZ() );
		  floorPenetration = 18.3 * pow( n, ((n+2)/(n+1)-0.46));
	  }

	  distance =  ue->GetMobilityModel ()->GetAbsolutePosition ()->GetDistance (enb->GetMobilityModel ()->GetAbsolutePosition ());
    }

  else if (GetDestinationNode ()->GetNodeType () == NetworkNode::TYPE_UE
		  && ( GetSourceNode ()->GetNodeType () == NetworkNode::TYPE_ENODEB || GetSourceNode ()->GetNodeType () == NetworkNode::TYPE_HOME_BASE_STATION) )
  {
	  UserEquipment* ue = (UserEquipment*) GetDestinationNode ();
	  ENodeB* enb = (ENodeB*) GetSourceNode ();

	  if( enb->GetCell()->GetCellCenterPosition()->GetCoordinateZ() > 0
			  && ue->IsIndoor()
			  && enb->GetCell()->GetCellCenterPosition()->GetCoordinateZ() != ue->GetCell()->GetCellCenterPosition()->GetCoordinateZ())
	  {
		  int n = (int) abs( enb->GetCell()->GetCellCenterPosition()->GetCoordinateZ() - ue->GetCell()->GetCellCenterPosition()->GetCoordinateZ() );
		  floorPenetration = 18.3 * pow( n, ((n+2)/(n+1)-0.46));
	  }

	  distance =  ue->GetMobilityModel ()->GetAbsolutePosition ()->GetDistance (enb->GetMobilityModel ()->GetAbsolutePosition ());
  }




  m_pathLoss = max( minimumCouplingLoss, 127 + ( 30 * log10 (distance * 0.001) ) + floorPenetration);


  return m_pathLoss;
}
UserEquipment*
NetworkManager::GetUserEquipmentByID (int idUE)
{
  std::vector<UserEquipment*>* userEquipmentContainer = GetUserEquipmentContainer ();
  std::vector<UserEquipment*>::iterator iter3;
  UserEquipment *userEquipment;
  for (iter3 = userEquipmentContainer->begin ();
      iter3 !=userEquipmentContainer->end (); iter3++)
    {
    userEquipment = *iter3;
    if (userEquipment->GetIDNetworkNode() == idUE)
      {
      return userEquipment;
      }
    }
  return false;
}
NetworkNode*
NetworkManager::GetNetworkNodeByID (int id)
{
  std::vector<ENodeB*>* eNodeBContainer = GetENodeBContainer ();
  std::vector<ENodeB*>::iterator iter2;
  ENodeB *eNodeB;
  for (iter2 = eNodeBContainer->begin ();
      iter2 !=eNodeBContainer->end (); iter2++)
    {
    eNodeB = *iter2;
    if (eNodeB->GetIDNetworkNode() == id)
      {
      return eNodeB;
      }
    }

  std::vector<UserEquipment*>* userEquipmentContainer = GetUserEquipmentContainer ();
  std::vector<UserEquipment*>::iterator iter3;
  UserEquipment *userEquipment;
  for (iter3 = userEquipmentContainer->begin ();
      iter3 !=userEquipmentContainer->end (); iter3++)
    {
    userEquipment = *iter3;
    if (userEquipment->GetIDNetworkNode() == id)
      {
      return userEquipment;
      }
    }

  std::vector<Gateway*>* gatewayContainer = GetGatewayContainer ();
  std::vector<Gateway*>::iterator iter;
  Gateway *gateway;

  for (iter = gatewayContainer->begin ();
      iter !=gatewayContainer->end (); iter++)
    {
    gateway = *iter;
    if (gateway->GetIDNetworkNode() == id)
      {
      return gateway;
      }
    }
  return false;
}
std::vector<UserEquipment*>*
NetworkManager::GetRegisteredUEToENodeB (int idENB)
{
  std::vector<UserEquipment*>* UElist = new std::vector<UserEquipment*>;

  std::vector<UserEquipment*>* userEquipmentContainer = GetUserEquipmentContainer ();
  std::vector<UserEquipment*>::iterator iter;
  UserEquipment *userEquipment;
  for (iter = userEquipmentContainer->begin ();
      iter !=userEquipmentContainer->end (); iter++)
    {
    userEquipment = *iter;
    if (userEquipment->GetTargetNode ()->GetIDNetworkNode() == idENB)
      {
      UElist->push_back(userEquipment);
      }
    }
  return UElist;
}
void
NetworkManager::PrintUserPosition (void)
{
  std::vector<UserEquipment*>* users = GetUserEquipmentContainer();
  std::vector<UserEquipment*>::iterator iter;
  UserEquipment *user;

  std::cout << " UserPosition X [at " << Simulator::Init()->Now() << "] ";
  for (iter = users->begin(); iter != users->end(); iter++)
    {
    user = *iter;
    std::cout << user->GetMobilityModel ()->GetAbsolutePosition()->GetCoordinateX() << " ";
    }

  std::cout << "\n UserPosition Y [at " << Simulator::Init()->Now() << "] ";
  for (iter = users->begin(); iter != users->end(); iter++)
    {
    user = *iter;
    std::cout << user->GetMobilityModel ()->GetAbsolutePosition()->GetCoordinateY() << " ";
    }
  std::cout << std::endl;
}
double
WinnerDownlinkChannelRealization::GetPathLoss (void)
{
    /*
     * Path Loss Model For Indoor Environment.
     * "WINNER II channel models, ver 1.1, Tech Report"
     * PL = A*log10(r) + B + C*log10(fc/5) + X; [r in meters; fc in GHz]
     * I = 128.1 – 2GHz
     * X depends on the number of walls in between
     * FL = 17 + 4 (Nfloors - 1) --- floor loss
     */

    double distance;
    UserEquipment* ue;
    ENodeB* enb;

    assert (GetDestinationNode ()->GetNodeType () == NetworkNode::TYPE_HOME_BASE_STATION  || GetSourceNode ()->GetNodeType () == NetworkNode::TYPE_HOME_BASE_STATION);

    if (GetSourceNode ()->GetNodeType () == NetworkNode::TYPE_UE
            && GetDestinationNode ()->GetNodeType () == NetworkNode::TYPE_HOME_BASE_STATION )
    {
        ue = (UserEquipment*) GetSourceNode ();
        enb = (ENodeB*) GetDestinationNode ();

        distance =  ue->GetMobilityModel ()->GetAbsolutePosition ()->GetDistance (enb->GetMobilityModel ()->GetAbsolutePosition ());
    }

    else if (GetDestinationNode ()->GetNodeType () == NetworkNode::TYPE_UE
             && GetSourceNode ()->GetNodeType () == NetworkNode::TYPE_HOME_BASE_STATION )
    {
        ue = (UserEquipment*) GetDestinationNode ();
        enb = (ENodeB*) GetSourceNode ();

        distance =  ue->GetMobilityModel ()->GetAbsolutePosition ()->GetDistance (enb->GetMobilityModel ()->GetAbsolutePosition ());
    }

    int* nbWalls = GetWalls( (Femtocell*) (enb->GetCell()), ue);

    double A, B, C;
    double ExternalWallsAttenuation = 20.0;
    double InternalWallsAttenuation = 10.0;

    if (nbWalls[0] == 0 && nbWalls[1] == 0)
    {   //LOS
        A = 18.7;
        B = 46.8;
        C = 20.0;
    }
    else
    {   //NLOS
        A = 20.0;
        B = 46.4;
        C = 20.0;
    }

    m_pathLoss = A * log10( distance ) +
                 B +
                 C * log10(2. / 5.0) +
                 InternalWallsAttenuation * nbWalls[1] +
                 ExternalWallsAttenuation * nbWalls[0];

    delete [] nbWalls;
    return m_pathLoss;
}
Exemple #10
0
void
Manhattan::UpdatePosition (double timestamp)
{
#ifdef MOBILITY_DEBUG
//	cout << "\t START MOBILITY MODEL for "<< GetNodeID () << endl;
#endif

  if (GetSpeed () == 0)
    {
#ifdef MOBILITY_DEBUG
	cout << "\t\t speed = 0 --> position has not been updated!"<< endl;
#endif
      return;
    }

  double timeInterval = timestamp - GetPositionLastUpdate ();
  double speedDirection;

  UserEquipment *thisNode = NetworkManager::Init ()->GetUserEquipmentByID (GetNodeID ());
  Cell *thisCell = thisNode->GetCell ();


  NetworkNode *targetNode = thisNode->GetTargetNode ();

#ifdef MOBILITY_DEBUG
	cout << "MOBILITY_DEBUG: User ID: " << GetNodeID ()
	    << "\n\t Cell ID " <<
					NetworkManager::Init()->GetCellIDFromPosition (GetAbsolutePosition()->GetCoordinateX(),
																   GetAbsolutePosition()->GetCoordinateY())
		<< "\n\t Initial Position (X): " << GetAbsolutePosition()->GetCoordinateX()
		<< "\n\t Initial Position (Y): " << GetAbsolutePosition()->GetCoordinateY()
		<< "\n\t Speed: " << GetSpeed()
		<< "\n\t Speed Direction: " << GetSpeedDirection()
		<< "\n\t Time Last Update: " << GetPositionLastUpdate()
		<< "\n\t Time Interval: " << timeInterval
		<< endl;
#endif
#ifdef MOBILITY_DEBUG_TAB
	cout <<  GetNodeID () << " "
		<< GetAbsolutePosition()->GetCoordinateX() << " "
		<< GetAbsolutePosition()->GetCoordinateY() << " "
		<< GetSpeed() << " "
		<< GetSpeedDirection() << " "
		<< GetPositionLastUpdate() << " "
		<< timeInterval << " "
		<< "-> ";
#endif
	const double pi = 3.14;

//  Init speedDirection if its not pointing into the direction of Manhattans Streets
	vector<double> directions;
	for(int i=0;i<=3;i++) {
	  directions.push_back(i * 1.57); // 1.57 = 90.0 * ((2.0*pi)/360.0))
	}

	double newdir;
	vector<double>::iterator it;
	it = find(directions.begin(), directions.end(), GetSpeedDirection());

	if(it == directions.end()) {
	  newdir = (double)(pi / 2) * round(GetSpeedDirection() * (double)(2 / pi));
	  if(newdir==6.28) newdir = 0;
	  SetSpeedDirection(newdir);
#ifdef MOBILITY_DEBUG_TAB
	  cout << "NEW SPEED-DIRECTION: " << newdir << " -> ";
#endif
	}

	double shift = timeInterval * (GetSpeed()*(1000.0/3600.0));

	CartesianCoordinates *newPosition = new CartesianCoordinates(GetAbsolutePosition()->GetCoordinateX(), GetAbsolutePosition()->GetCoordinateY());
	CartesianCoordinates *ENodeBPosition = targetNode->GetMobilityModel ()->GetAbsolutePosition ();

// Init Manhattan grid position
  if(fmod(GetAbsolutePosition()->GetCoordinateY(),100)!=0 && fmod(GetAbsolutePosition()->GetCoordinateX(),100)!=0){
	CartesianCoordinates *Correction = new CartesianCoordinates();
	double distfromEnB = newPosition->GetDistance (ENodeBPosition);
	double azim = newPosition->GetPolarAzimut (ENodeBPosition);

	//if it was randomly put outside the cell -> shift it inside
	if(distfromEnB > (thisCell->GetRadius()*1000)) {
	  Correction->SetCoordinates((newPosition->GetDistance (ENodeBPosition) - (thisCell->GetRadius()*1000)) * cos(azim),
			  (newPosition->GetDistance (ENodeBPosition) - (thisCell->GetRadius()*1000)) * sin(azim));
	  newPosition->SetCoordinates(newPosition->GetCoordinateX() - Correction->GetCoordinateX(),
			  newPosition->GetCoordinateY() - Correction->GetCoordinateY());
	}
	delete Correction;


	if(GetSpeedDirection()==0 || GetSpeedDirection()==3.14) {
			  if(newPosition->GetCoordinateY() < 0)
				  newPosition->SetCoordinateY( ceil( (double)(newPosition->GetCoordinateY() / 100) ) * 100);
			  else
				  newPosition->SetCoordinateY( floor( (double)(newPosition->GetCoordinateY() / 100) ) * 100);
		  }
	else {
			  if(newPosition->GetCoordinateX() < 0)
				  newPosition->SetCoordinateX( ceil( (double)(newPosition->GetCoordinateX() / 100)) * 100);
			  else
				  newPosition->SetCoordinateX( floor( (double)(newPosition->GetCoordinateX() / 100) ) * 100);
	}
  }

//Shift it
  double shift_x = shift * cos(GetSpeedDirection());
  double shift_y = shift * sin(GetSpeedDirection());
  if(GetSpeedDirection()==0 || GetSpeedDirection()==3.14) {
	  newPosition->SetCoordinateX(newPosition->GetCoordinateX()+shift_x);
  }
  else {
	  newPosition->SetCoordinateY(newPosition->GetCoordinateY()+shift_y);
  }

// if a node reaches a crossing, choose new speedDirection
  double old_x = abs( ((int)( GetAbsolutePosition()->GetCoordinateX() *1000))/1000.0 ); //cut after 3 decimal places
  double new_x = abs( ((int)( newPosition->GetCoordinateX() *1000))/1000.0 );
  double old_y = abs( ((int)( GetAbsolutePosition()->GetCoordinateY() *1000))/1000.0 );
  double new_y = abs( ((int)( newPosition->GetCoordinateY() *1000))/1000.0 );
  double rounded_x = abs( round(old_x/100)*100 );
  double rounded_y = abs( round(old_y/100)*100 );

  if( ((old_x<rounded_x && rounded_x<=new_x) || (old_x>rounded_x && rounded_x>=new_x)) ||
		  ((old_y<rounded_y && rounded_y<=new_y) || (old_y>rounded_y && rounded_y>=new_y)) ||
		  (rounded_x==0 && old_x<rounded_x && rounded_x<=new_x) || (rounded_x==0 && old_x>rounded_x && rounded_x>=new_x) ||
		  (rounded_y==0 && old_y<rounded_y && rounded_y<=new_y) || (rounded_y==0 && old_y>rounded_y && rounded_y>=new_y) )
  {
	  srand ( time(NULL) );
	  double prob_turn = (rand()%100)*0.01;
	  if(prob_turn<=0.25) {
		  speedDirection = GetSpeedDirection() + 1.57; //turn left;
		  newPosition->SetCoordinates(round(newPosition->GetCoordinateX()),round(newPosition->GetCoordinateY()));
#ifdef MOBILITY_DEBUG_TAB
		  cout << "TURN LEFT: " << speedDirection << " -> ";
#endif
	  }
	  if(prob_turn>0.25 && prob_turn<0.75) {
		  newPosition->SetCoordinates(round(newPosition->GetCoordinateX()),round(newPosition->GetCoordinateY()) );
		  speedDirection = GetSpeedDirection();
#ifdef MOBILITY_DEBUG_TAB
		  cout << "no TURN: straight -> ";
#endif
	  }
	  if(prob_turn>=0.75) {
		  newPosition->SetCoordinates(round(newPosition->GetCoordinateX()),round(newPosition->GetCoordinateY()) );
		  speedDirection = GetSpeedDirection() - 1.57;
#ifdef MOBILITY_DEBUG_TAB
		  cout << "TURN RIGHT: " << speedDirection << " -> ";
#endif
	  }

	  //Correction if speedDirection €! [0,2pi[
	  if(speedDirection>=2*pi) speedDirection -= 2*pi;
	  if(speedDirection<0) speedDirection += 2*pi;
	  SetSpeedDirection(speedDirection);
  }



//If node moves beyond the cell edge
  double azimut = newPosition->GetPolarAzimut (ENodeBPosition);
  double newDistanceFromTheENodeB = newPosition->GetDistance (ENodeBPosition);

  if (newDistanceFromTheENodeB >= (thisCell->GetRadius()*1000))
    {
	  if (GetHandover()== false)
		{
		  newPosition->SetCoordinateX(GetAbsolutePosition()->GetCoordinateX());
		  newPosition->SetCoordinateY(GetAbsolutePosition()->GetCoordinateY());

		  speedDirection = GetSpeedDirection() - pi;
#ifdef MOBILITY_DEBUG_TAB
		  cout << "Moved back to cell: SPEED DIRECTION CHANGE (HO): " << speedDirection << " -> ";
#endif
		  if(speedDirection<0) speedDirection = speedDirection + 2*pi;
		  SetSpeedDirection(speedDirection);
		}
	  else if (newPosition->GetDistance(0.0, 0.0) >= GetTopologyBorder ())
	      {
		  newPosition->SetCoordinateX(GetAbsolutePosition()->GetCoordinateX());
		  newPosition->SetCoordinateY(GetAbsolutePosition()->GetCoordinateY());

		  speedDirection = GetSpeedDirection() - 1.57;
#ifdef MOBILITY_DEBUG_TAB
		  cout << "Moved back to cell: SPEED DIRECTION CHANGE (TOPOLOGY-BORDER): " << speedDirection << " -> ";
#endif
		  if(speedDirection<0) speedDirection = speedDirection + 2*pi;
		  SetSpeedDirection(speedDirection);
	      }
    }

  SetAbsolutePosition(newPosition);
  SetPositionLastUpdate (timestamp);

#ifdef MOBILITY_DEBUG
  cout << "\n\t Final Position (X): " << GetAbsolutePosition()->GetCoordinateX()
			<< "\n\t Final Position (Y): " << GetAbsolutePosition()->GetCoordinateY()
			<< endl;
#endif
#ifdef MOBILITY_DEBUG_TAB
  cout << GetAbsolutePosition()->GetCoordinateX() << " "
			<< GetAbsolutePosition()->GetCoordinateY() << " " << GetSpeedDirection()
			<< endl;
#endif
  delete newPosition;
}
Packet*
RadioBearer::CreatePacket (int bytes)
{
  Packet *p = new Packet ();

  p->SetID(Simulator::Init()->GetUID ());
  p->SetTimeStamp(Simulator::Init()->Now ());

  UDPHeader *udp = new UDPHeader (GetClassifierParameters ()->GetSourcePort(),
		                          GetClassifierParameters ()->GetDestinationPort ());
  p->AddUDPHeader(udp);

  IPHeader *ip = new IPHeader (GetClassifierParameters ()->GetSourceID (),
                               GetClassifierParameters ()->GetDestinationID());
  p->AddIPHeader(ip);

  PDCPHeader *pdcp = new PDCPHeader ();
  p->AddPDCPHeader (pdcp);

  RLCHeader *rlc = new RLCHeader ();
  p->AddRLCHeader(rlc);

  PacketTAGs *tags = new PacketTAGs ();
  tags->SetApplicationType(PacketTAGs::APPLICATION_TYPE_INFINITE_BUFFER);
  p->SetPacketTags(tags);

  if (_APP_TRACING_)
    {
	  /*
	   * Trace format:
	   *
	   * TX   APPLICATION_TYPE   BEARER_ID  SIZE   SRC_ID   DST_ID   TIME
	   */
	  UserEquipment* ue = (UserEquipment*) GetApplication ()->GetDestination ();
	   std::cout << "TX";
	   switch (p->GetPacketTags ()->GetApplicationType ())
	     {
	       case Application::APPLICATION_TYPE_VOIP:
	         {
	     	  std::cout << " VOIP";
	     	  break;
	         }
	       case Application::APPLICATION_TYPE_TRACE_BASED:
	         {
	           std::cout << " VIDEO";
	     	  break;
	         }
	       case Application::APPLICATION_TYPE_CBR:
	         {
	     	  std::cout << " CBR";
	     	  break;
	         }
	       case Application::APPLICATION_TYPE_INFINITE_BUFFER:
	         {
	     	  std::cout << " INF_BUF";
	     	  break;
	         }
	       default:
	         {
	     	  std::cout << " UNDEFINED";
	     	  break;
	         }
	     }

	   if (bytes > 1490) bytes = 1490;
	   else bytes = bytes - 13;

       std::cout << " ID " << p->GetID ()
	 		    << " B " << GetRlcEntity ()->GetRlcEntityIndex ()
	 			<< " SIZE " << bytes
	 			<< " SRC " << GetSource ()->GetIDNetworkNode ()
	 			<< " DST " << GetDestination ()->GetIDNetworkNode ()
	 			<< " T " << Simulator::Init()->Now()
	 			<< " " << ue->IsIndoor () << std::endl;
    }

  return p;
}
Exemple #12
0
void
Application::Start ()
{
#ifdef TEST_START_APPLICATION
  std::cout << "Start Application: src: " << GetSource ()->GetIDNetworkNode ()
		  << " dst: " << GetDestination ()->GetIDNetworkNode () << std::endl;
#endif

  // 1 - create radio bearer
  m_radioBearer = new RadioBearer ();
  //std::cout<<"RB"<<std::endl;//memorytest
  m_radioBearer->GetRlcEntity ()->SetRlcEntityIndex (GetApplicationID ());


  if (GetSource ()->GetNodeType() == NetworkNode::TYPE_UE)
    {
	  //create an UL radio bearer between UE and targetENB
	  UserEquipment* ue = (UserEquipment*) GetSource ();
	  ue->SetNodeState (NetworkNode::STATE_ACTIVE);

#ifdef TEST_START_APPLICATION
      std::cout << "Create UL radio bearer bewtween: " << GetSource ()->GetIDNetworkNode ()
		  << " and " << ue->GetTargetNode ()->GetIDNetworkNode () << std::endl;
#endif

	  m_radioBearer->SetSource (ue);
	  m_radioBearer->SetDestination (ue->GetTargetNode ());
	  m_radioBearer->SetClassifierParameters (GetClassifierParameters ());
	  m_radioBearer->SetApplication (this);
	  m_radioBearer->SetQoSParameters (GetQoSParameters ());
    }
  else if (GetSource ()->GetNodeType() == NetworkNode::TYPE_GW
		  ||
		  GetSource ()->GetNodeType() == NetworkNode::TYPE_ENODEB
		  ||
		  GetSource ()->GetNodeType() == NetworkNode::TYPE_HOME_BASE_STATION)
    {
	  //create an DL radio bearer between targetENB and UE
	  UserEquipment* ue = (UserEquipment*) GetDestination ();
	  ue->SetNodeState (NetworkNode::STATE_ACTIVE);

#ifdef TEST_START_APPLICATION
      std::cout << "Create DL radio bearer bewtween: " << ue->GetTargetNode ()->GetIDNetworkNode ()
    		  << " and " << ue->GetIDNetworkNode ()  << std::endl;
#endif

	  m_radioBearer->SetSource (ue->GetTargetNode ());
	  m_radioBearer->SetDestination (ue);
	  m_radioBearer->SetClassifierParameters (GetClassifierParameters ());
	  m_radioBearer->SetApplication (this);
	  m_radioBearer->SetQoSParameters (GetQoSParameters ());
    }

  m_radioBearer->GetSource ()->GetProtocolStack ()->GetRrcEntity ()->AddRadioBearer (m_radioBearer);


  // 2 - create application sink
  m_applicationSink = new ApplicationSink ();
  //std::cout<<"AS"<<std::endl;//memorytest
  m_applicationSink->SetClassifierParameters (GetClassifierParameters ());
  m_applicationSink->SetSourceApplication (this);


  // 3 - create radio bearer sink
  m_bearerSink = new RadioBearerSink ();
  //std::cout<<"RBS"<<std::endl;//memorytest
  m_bearerSink->GetRlcEntity ()->SetRlcEntityIndex (GetApplicationID ());
  m_bearerSink->SetApplication (m_applicationSink);
  m_bearerSink->SetClassifierParameters (GetClassifierParameters ());
  m_bearerSink->SetQoSParameters (GetQoSParameters ());
  if (GetSource ()->GetNodeType() == NetworkNode::TYPE_UE)
    {
	  UserEquipment* ue = (UserEquipment*) GetSource ();
	  ue->SetNodeState (NetworkNode::STATE_ACTIVE);
	  m_bearerSink->SetSource (ue);
	  m_bearerSink->SetDestination (ue->GetTargetNode ());
    }
  else if (GetSource ()->GetNodeType() == NetworkNode::TYPE_GW || GetSource ()->GetNodeType() == NetworkNode::TYPE_ENODEB
		  || GetSource ()->GetNodeType() == NetworkNode::TYPE_HOME_BASE_STATION)
    {
	  UserEquipment* ue = (UserEquipment*) GetDestination ();
	  ue->SetNodeState (NetworkNode::STATE_ACTIVE);
	  m_bearerSink->SetSource (ue->GetTargetNode ());
	  m_bearerSink->SetDestination (ue);
    }


  // 4 - add in radio bearer a pointer to the radio bearer sink
  m_radioBearer->GetDestination() ->GetProtocolStack ()->GetRrcEntity ()->AddRadioBearerSink(m_bearerSink);
  m_applicationSink->SetRadioBearerSink (m_bearerSink);


  // 4 attach UE on the UL or DL channel
  if (GetSource ()->GetNodeType() == NetworkNode::TYPE_UE)
    {
	  UserEquipment* ue = (UserEquipment*) GetSource ();
/*mouan
	  LteChannel *ch = ue->GetTargetNode ()->GetPhy ()->GetUlChannel ();

	  if (!ch->IsAttached (ue))
	    {
		  ch->AddDevice (ue);
	    }
mouan end*/

	  ue->MakeActive ();
    }
  else if (GetSource ()->GetNodeType() == NetworkNode::TYPE_GW || GetSource ()->GetNodeType() == NetworkNode::TYPE_ENODEB
		  || GetSource ()->GetNodeType() == NetworkNode::TYPE_HOME_BASE_STATION)
    {
	  UserEquipment* ue = (UserEquipment*) GetDestination ();
	  LteChannel *ch = ue->GetTargetNode ()->GetPhy ()->GetDlChannel ();

	  if (!ch->IsAttached (ue))
	    {
		  ch->AddDevice (ue);
	    }

	  ue->MakeActive ();
    }

#ifdef TEST_START_APPLICATION
  std::cout << "CREATED RADIO BEARER " << m_radioBearer->GetApplication ()->GetApplicationID ()
		  << " BETWEEN "
		  << m_radioBearer->GetSource ()->GetIDNetworkNode () << " and "
		  << m_radioBearer->GetDestination () ->GetIDNetworkNode ()<< std::endl;
#endif

  DoStart ();
}
void
NetworkManager::UpdateUserPosition (double time)
{
  std::vector<UserEquipment*> *records = GetUserEquipmentContainer ();
  std::vector<UserEquipment*>::iterator iter;
  UserEquipment *record;

#ifdef MOBILITY_DEBUG
  std::cout << "MOBILITY_DEBUG: UPDATE POSITION, "
      "number of UE = " << records->size () <<
      " time = " << time << std::endl;
#endif

  for (iter = records->begin(); iter != records->end(); iter++)
    {
      record = *iter;

#ifdef MOBILITY_DEBUG
    std::cout << "\t USER  " << record->GetIDNetworkNode ()
	              << std::endl;
#endif

      record->UpdateUserPosition (time);
      record->SetIndoorFlag( CheckIndoorUsers(record) );

#ifdef AMC_MAPPING
  std::cout << "time: " << time << "\n\t position: "
		  << record->GetMobilityModel ()->GetAbsolutePosition ()->GetCoordinateX () <<
		  " " << record->GetMobilityModel ()->GetAbsolutePosition ()->GetCoordinateY ()
		  << std::endl;
#endif
#ifdef MOBILITY_DEBUG
  std::cout << "time: " << time << "\t position: "
		  << record->GetMobilityModel ()->GetAbsolutePosition ()->GetCoordinateX () <<
		  " " << record->GetMobilityModel ()->GetAbsolutePosition ()->GetCoordinateY ()
		  << std::endl;
#endif


      if (record->GetMobilityModel ()->GetHandover () == true)
        {
    	  NetworkNode* targetNode = record->GetTargetNode ();

          if (targetNode->GetProtocolStack ()->GetRrcEntity ()->
        		  GetHandoverEntity ()->CheckHandoverNeed (record))
            {
        	  NetworkNode* newTagertNode = targetNode->GetProtocolStack ()
        			  ->GetRrcEntity ()->GetHandoverEntity ()->GetHoManager ()->m_target;

#ifdef HANDOVER_DEBUG
              std::cout << "** HO ** \t time: " << time << " user " <<  record->GetIDNetworkNode () <<
            		  " old eNB " << targetNode->GetIDNetworkNode () <<
            		  " new eNB " << newTagertNode->GetIDNetworkNode () << std::endl;
#endif
              HandoverProcedure(time, record, targetNode, newTagertNode);
            }
        }
    }

  //PrintUEsForEachCell();
}
void
NetworkManager::Print (NetworkManager::m_debugInfo info)
{
  cout << " Network Manager Debug: " << endl;

  switch (info)
  {
  case NetworkManager::ALL_NETWORK:
    {
      this->Print();
      break;
    }

  case NetworkManager::ONLY_CELL_DETAILS:
    {
      std::vector<Cell*>* cellContainer = GetCellContainer ();
      std::vector<Cell*>::iterator iter;
      Cell *cell;
      for (iter = cellContainer->begin ();
          iter !=cellContainer->end (); iter++)
        {
        cell = *iter;
        cell->Print();
        }
      break;
    }

  case NetworkManager::ONLY_ENODEB_DETAILS:
    {
      std::vector<ENodeB*>* eNodeBContainer = GetENodeBContainer ();
      std::vector<ENodeB*>::iterator iter2;
      ENodeB *eNodeB;
      for (iter2 = eNodeBContainer->begin ();
          iter2 !=eNodeBContainer->end (); iter2++)
        {
        eNodeB = *iter2;
        eNodeB->Print();
        }
      break;
    }
  case NetworkManager::ONLY_USER_EQUIPMENT_DETAILS:
    {
      std::vector<UserEquipment*>* userEquipmentContainer = GetUserEquipmentContainer ();
      std::vector<UserEquipment*>::iterator iter3;
      UserEquipment *userEquipment;
      for (iter3 = userEquipmentContainer->begin ();
          iter3 !=userEquipmentContainer->end (); iter3++)
        {
        userEquipment = *iter3;
        userEquipment->Print();
        }
      break;
    }

  default:
    {
      cout << " INVALID NETWORK DEBUG CODE " << endl;
      break;
    }

  }
}