25#include "ns3/satellite-id-mapper.h"
26#include "ns3/satellite-topology.h"
27#include "ns3/singleton.h"
36NS_LOG_COMPONENT_DEFINE(
"SatGroupHelper");
47 TypeId(
"ns3::SatGroupHelper").SetParent<Object>().AddConstructor<SatGroupHelper>();
55 NS_LOG_FUNCTION(
this);
61 NS_LOG_FUNCTION(
this);
69 NS_LOG_FUNCTION(
this);
73 for (std::map<Ptr<Node>, uint32_t>::iterator it =
m_nodesToAdd.begin();
84 NS_LOG_FUNCTION(
this << groupId << node);
88 NS_FATAL_ERROR(
"Method SatGroupHelper::AddUtNodeToGroup has to be called after "
89 "SimulationHelper::CreateSatScenario");
94 NS_FATAL_ERROR(
"Group ID 0 is reserved for UTs not manually assigned to a group");
99 NS_FATAL_ERROR(
"Node " << node <<
" is already in group " <<
GetGroupId(node)
100 <<
". It cannot be added to group " << groupId);
109 Singleton<SatIdMapper>::Get()->AttachMacToGroupId(
110 Singleton<SatIdMapper>::Get()->GetUtMacWithNode(node),
113 Singleton<SatTopology>::Get()->UpdateUtGroup(node, groupId);
119 NS_LOG_FUNCTION(
this << groupId);
123 NS_FATAL_ERROR(
"Method SatGroupHelper::AddUtNodesToGroup has to be called after "
124 "SimulationHelper::CreateSatScenario");
127 for (NodeContainer::Iterator it = nodes.Begin(); it != nodes.End(); it++)
139 NS_LOG_FUNCTION(
this << groupId << center << radius);
143 NS_FATAL_ERROR(
"Method SatGroupHelper::CreateGroupFromPosition has to be called after "
144 "SimulationHelper::CreateSatScenario");
149 NS_FATAL_ERROR(
"Cannot create new geographical group with a group ID of zero.");
153 NS_FATAL_ERROR(
"Cannot create new geographical group with a group ID already used.");
156 Vector centerPosition = center.
ToVector();
160 for (NodeContainer::Iterator it = nodesNotAlreadyAdded.Begin();
161 it != nodesNotAlreadyAdded.End();
165 distance = CalculateDistance(centerPosition, nodePosition.
ToVector());
166 if (distance <= radius)
176 NS_LOG_FUNCTION(
this << groupIds);
180 NS_FATAL_ERROR(
"Method SatGroupHelper::CreateGroupsUniformly has to be called after "
181 "SimulationHelper::CreateSatScenario");
184 for (uint32_t groupId : groupIds)
188 NS_FATAL_ERROR(
"Cannot create new group with a group ID already used: " << groupId);
194 uint32_t nbNodes = nodesNotAlreadyAdded.GetN();
195 uint32_t counter = 0;
197 for (uint32_t i = 0; i < nbNodes; i++)
201 counter %= groupIds.size();
211 NS_LOG_FUNCTION(
this << groupId << nb << center << radius);
215 NS_FATAL_ERROR(
"Method SatGroupHelper::CreateUtNodesFromPosition has to be called before "
216 "SimulationHelper::CreateSatScenario");
221 NS_FATAL_ERROR(
"Cannot call CreateUtNodesFromPosition with a group ID of zero.");
226 "Cannot call CreateUtNodesFromPosition with a group ID already used: " << groupId);
229 Ptr<SatRandomCirclePositionAllocator> circleAllocator =
230 CreateObject<SatRandomCirclePositionAllocator>(center, radius);
232 for (uint32_t i = 0; i < nb; i++)
234 GeoCoordinate position = circleAllocator->GetNextGeoPosition();
244 NS_LOG_FUNCTION(
this << groupId << node);
249std::vector<std::pair<GeoCoordinate, uint32_t>>
252 NS_LOG_FUNCTION(
this);
260 NS_LOG_FUNCTION(
this << groupId);
265 NodeContainer groupIdZeroUts;
266 NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
267 for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); it++)
270 for (std::map<uint32_t, std::set<Ptr<Node>>>::const_iterator it2 =
m_groupsMap.begin();
274 if (it2->second.find(*it) != it2->second.end())
282 groupIdZeroUts.Add(*it);
285 return groupIdZeroUts;
290 return NodeContainer();
293 NodeContainer utNodes;
294 std::set<Ptr<Node>> nodes =
m_groupsMap.at(groupId);
296 for (std::set<Ptr<Node>>::const_iterator i = nodes.begin(); i != nodes.end(); i++)
307 NS_LOG_FUNCTION(
this);
333 for (std::map<uint32_t, std::set<Ptr<Node>>>::const_iterator it =
m_groupsMap.begin();
337 if (it->second.find(node) != it->second.end())
348 NS_LOG_FUNCTION(
this);
350 NodeContainer nodesFiltered;
352 for (uint32_t i = 0; i < nodes.GetN(); i++)
357 nodesFiltered.Add(node);
360 return nodesFiltered;
GeoCoordinate class is used to store and operate with geodetic coordinates.
Vector ToVector() const
Converts Geodetic coordinates to Cartesian coordinates.
This helper is used to create groups of UTs.
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.
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.