25 #include <ns3/satellite-id-mapper.h> 
   26 #include <ns3/satellite-topology.h> 
   27 #include <ns3/singleton.h> 
   36 NS_LOG_COMPONENT_DEFINE(
"SatGroupHelper");
 
   41 NS_OBJECT_ENSURE_REGISTERED(SatGroupHelper);
 
   47         TypeId(
"ns3::SatGroupHelper").SetParent<Object>().AddConstructor<SatGroupHelper>();
 
   54     NS_LOG_FUNCTION(
this);
 
   60     : m_scenarioCreated(false),
 
   61       m_satConstellationEnabled(false)
 
   63     NS_LOG_FUNCTION(
this);
 
   69     NS_LOG_FUNCTION(
this);
 
   77     NS_LOG_FUNCTION(
this);
 
   81     for (std::map<Ptr<Node>, uint32_t>::iterator it = 
m_nodesToAdd.begin();
 
   92     NS_LOG_FUNCTION(
this << groupId << node);
 
   96         NS_FATAL_ERROR(
"Method SatGroupHelper::AddUtNodeToGroup has to be called after " 
   97                        "SimulationHelper::CreateSatScenario");
 
  102         NS_FATAL_ERROR(
"Group ID 0 is reserved for UTs not manually assigned to a group");
 
  107         NS_FATAL_ERROR(
"Node " << node << 
" is already in group " << 
GetGroupId(node)
 
  108                                << 
". It cannot be added to group " << groupId);
 
  117     Singleton<SatIdMapper>::Get()->AttachMacToGroupId(
 
  118         Singleton<SatIdMapper>::Get()->GetUtMacWithNode(node),
 
  121     Singleton<SatTopology>::Get()->UpdateUtGroup(node, groupId);
 
  127     NS_LOG_FUNCTION(
this << groupId);
 
  131         NS_FATAL_ERROR(
"Method SatGroupHelper::AddUtNodesToGroup has to be called after " 
  132                        "SimulationHelper::CreateSatScenario");
 
  135     for (NodeContainer::Iterator it = nodes.Begin(); it != nodes.End(); it++)
 
  147     NS_LOG_FUNCTION(
this << groupId << center << radius);
 
  151         NS_FATAL_ERROR(
"Method SatGroupHelper::CreateGroupFromPosition has to be called after " 
  152                        "SimulationHelper::CreateSatScenario");
 
  157         NS_FATAL_ERROR(
"Cannot create new geographical group with a group ID of zero.");
 
  161         NS_FATAL_ERROR(
"Cannot create new geographical group with a group ID already used.");
 
  164     Vector centerPosition = center.
ToVector();
 
  168     for (NodeContainer::Iterator it = nodesNotAlreadyAdded.Begin();
 
  169          it != nodesNotAlreadyAdded.End();
 
  173         distance = CalculateDistance(centerPosition, nodePosition.
ToVector());
 
  174         if (distance <= radius)
 
  184     NS_LOG_FUNCTION(
this << groupIds);
 
  188         NS_FATAL_ERROR(
"Method SatGroupHelper::CreateGroupsUniformly has to be called after " 
  189                        "SimulationHelper::CreateSatScenario");
 
  192     for (uint32_t groupId : groupIds)
 
  196             NS_FATAL_ERROR(
"Cannot create new group with a group ID already used: " << groupId);
 
  202     uint32_t nbNodes = nodesNotAlreadyAdded.GetN();
 
  203     uint32_t counter = 0;
 
  205     for (uint32_t i = 0; i < nbNodes; i++)
 
  209         counter %= groupIds.size();
 
  219     NS_LOG_FUNCTION(
this << groupId << nb << center << radius);
 
  223         NS_FATAL_ERROR(
"Method SatGroupHelper::CreateUtNodesFromPosition has to be called before " 
  224                        "SimulationHelper::CreateSatScenario");
 
  229         NS_FATAL_ERROR(
"Cannot call CreateUtNodesFromPosition with a group ID of zero.");
 
  234             "Cannot call CreateUtNodesFromPosition with a group ID already used: " << groupId);
 
  237     Ptr<SatRandomCirclePositionAllocator> circleAllocator =
 
  238         CreateObject<SatRandomCirclePositionAllocator>(center, radius);
 
  240     for (uint32_t i = 0; i < nb; i++)
 
  242         GeoCoordinate position = circleAllocator->GetNextGeoPosition();
 
  252     NS_LOG_FUNCTION(
this << groupId << node);
 
  257 std::vector<std::pair<GeoCoordinate, uint32_t>>
 
  260     NS_LOG_FUNCTION(
this);
 
  268     NS_LOG_FUNCTION(
this << groupId);
 
  273         NodeContainer groupIdZeroUts;
 
  274         NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
 
  275         for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); it++)
 
  278             for (std::map<uint32_t, std::set<Ptr<Node>>>::const_iterator it2 = 
m_groupsMap.begin();
 
  282                 if (it2->second.find(*it) != it2->second.end())
 
  290                 groupIdZeroUts.Add(*it);
 
  293         return groupIdZeroUts;
 
  298         return NodeContainer();
 
  301     NodeContainer utNodes;
 
  302     std::set<Ptr<Node>> nodes = 
m_groupsMap.at(groupId);
 
  304     for (std::set<Ptr<Node>>::const_iterator i = nodes.begin(); i != nodes.end(); i++)
 
  315     NS_LOG_FUNCTION(
this);
 
  341     for (std::map<uint32_t, std::set<Ptr<Node>>>::const_iterator it = 
m_groupsMap.begin();
 
  345         if (it->second.find(node) != it->second.end())
 
  356     NS_LOG_FUNCTION(
this);
 
  358     NodeContainer nodesFiltered;
 
  360     for (uint32_t i = 0; i < nodes.GetN(); i++)
 
  365             nodesFiltered.Add(node);
 
  368     return nodesFiltered;
 
GeoCoordinate class is used to store and operate with geodetic coordinates.
 
Vector ToVector() const
Converts Geodetic coordinates to Cartesian coordinates.
 
std::list< uint32_t > GetGroups()
Get the list of groups created.
 
virtual void DoDispose()
Dispose of this class instance.
 
NodeContainer GetUtNodes(uint32_t groupId) const
 
uint32_t GetN()
Count the number of groups created.
 
void AddUtNodesToGroup(uint32_t groupId, NodeContainer nodes)
Add several nodes to a group.
 
void Init()
Initialize the helper.
 
void CreateUtNodesFromPosition(uint32_t groupId, uint32_t nb, GeoCoordinate center, uint32_t radius)
Create a new group using a central position and a radius, and create UT nodes inside this area.
 
static TypeId GetTypeId(void)
Get the type ID.
 
std::map< Ptr< Node >, uint32_t > m_nodesToAdd
 
std::map< uint32_t, std::set< Ptr< Node > > > m_groupsMap
Container to associate nodes to the groups.
 
void AddNodeToGroupAfterScenarioCreation(uint32_t groupId, Ptr< Node > node)
Schedule a node to be added to a group when scenario creation is finished.
 
std::list< uint32_t > m_groupsList
List of group ID created.
 
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
 
bool m_satConstellationEnabled
Use a constellation of satellites.
 
void CreateGroupsUniformly(std::vector< uint32_t > groupIds, NodeContainer nodes)
Create several groups and distribute nodes among them.
 
NodeContainer GetNodesNotAddedFromPosition(NodeContainer nodes)
Get list of nodes not created from position by group helper.
 
bool IsGroupExisting(uint32_t groupId) const
Tells if the groupId is already existing in the database.
 
std::vector< std::pair< GeoCoordinate, uint32_t > > GetAdditionalNodesPerBeam()
Get the position of nodes to add to the scenario.
 
SatGroupHelper()
Default constructor for SatGroupHelper.
 
void SetSatConstellationEnabled()
 
uint32_t GetGroupId(Ptr< Node > node) const
Get the group to which a node belongs.
 
void CreateGroupFromPosition(uint32_t groupId, NodeContainer nodes, GeoCoordinate center, uint32_t radius)
Create a new group using a central position and a radius.
 
std::vector< std::pair< GeoCoordinate, uint32_t > > m_additionalNodesPerBeam
Nodes created by position to add to scenario.
 
void AddUtNodeToGroup(uint32_t groupId, Ptr< Node > node)
Add a node to a group.
 
Keep track of the current position and velocity of an object in satellite network.
 
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.