25 #include <ns3/satellite-id-mapper.h>
26 #include <ns3/singleton.h>
28 NS_LOG_COMPONENT_DEFINE(
"SatGroupHelper");
33 NS_OBJECT_ENSURE_REGISTERED(SatGroupHelper);
39 TypeId(
"ns3::SatGroupHelper").SetParent<Object>().AddConstructor<SatGroupHelper>();
46 NS_LOG_FUNCTION(
this);
52 : m_scenarioCreated(false),
53 m_satConstellationEnabled(false)
55 NS_LOG_FUNCTION(
this);
61 NS_LOG_FUNCTION(
this);
69 NS_LOG_FUNCTION(
this);
74 for (std::map<Ptr<Node>, uint32_t>::iterator it =
m_nodesToAdd.begin();
85 NS_LOG_FUNCTION(
this << groupId << node);
89 NS_FATAL_ERROR(
"Method SatGroupHelper::AddUtNodeToGroup has to be called after "
90 "SimulationHelper::CreateSatScenario");
95 NS_FATAL_ERROR(
"Group ID 0 is reserved for UTs not manually assigned to a group");
100 NS_FATAL_ERROR(
"Node " << node <<
" is already in group " <<
GetGroupId(node)
101 <<
". It cannot be added to group " << groupId);
110 Singleton<SatIdMapper>::Get()->AttachMacToGroupId(
111 Singleton<SatIdMapper>::Get()->GetUtMacWithNode(node),
118 NS_LOG_FUNCTION(
this << groupId);
122 NS_FATAL_ERROR(
"Method SatGroupHelper::AddUtNodesToGroup has to be called after "
123 "SimulationHelper::CreateSatScenario");
126 for (NodeContainer::Iterator it = nodes.Begin(); it != nodes.End(); it++)
138 NS_LOG_FUNCTION(
this << groupId << center << radius);
142 NS_FATAL_ERROR(
"Method SatGroupHelper::CreateGroupFromPosition has to be called after "
143 "SimulationHelper::CreateSatScenario");
148 NS_FATAL_ERROR(
"Cannot create new geographical group with a group ID of zero.");
152 NS_FATAL_ERROR(
"Cannot create new geographical group with a group ID already used.");
155 Vector centerPosition = center.
ToVector();
159 for (NodeContainer::Iterator it = nodesNotAlreadyAdded.Begin();
160 it != nodesNotAlreadyAdded.End();
164 distance = CalculateDistance(centerPosition, nodePosition.
ToVector());
165 if (distance <= radius)
175 NS_LOG_FUNCTION(
this << groupIds);
179 NS_FATAL_ERROR(
"Method SatGroupHelper::CreateGroupsUniformly has to be called after "
180 "SimulationHelper::CreateSatScenario");
183 for (uint32_t groupId : groupIds)
187 NS_FATAL_ERROR(
"Cannot create new group with a group ID already used: " << groupId);
193 uint32_t nbNodes = nodesNotAlreadyAdded.GetN();
194 uint32_t counter = 0;
196 for (uint32_t i = 0; i < nbNodes; i++)
200 counter %= groupIds.size();
210 NS_LOG_FUNCTION(
this << groupId << nb << center << radius);
214 NS_FATAL_ERROR(
"Method SatGroupHelper::CreateUtNodesFromPosition has to be called before "
215 "SimulationHelper::CreateSatScenario");
220 NS_FATAL_ERROR(
"Cannot call CreateUtNodesFromPosition with a group ID of zero.");
225 "Cannot call CreateUtNodesFromPosition with a group ID already used: " << groupId);
228 Ptr<SatRandomCirclePositionAllocator> circleAllocator =
229 CreateObject<SatRandomCirclePositionAllocator>(center, radius);
231 for (uint32_t i = 0; i < nb; i++)
233 GeoCoordinate position = circleAllocator->GetNextGeoPosition();
243 NS_LOG_FUNCTION(
this << groupId << node);
248 std::vector<std::pair<GeoCoordinate, uint32_t>>
251 NS_LOG_FUNCTION(
this);
259 NS_LOG_FUNCTION(
this << groupId);
264 NodeContainer groupIdZeroUts;
265 for (NodeContainer::Iterator it =
m_uts.Begin(); it !=
m_uts.End(); it++)
268 for (std::map<uint32_t, std::set<Ptr<Node>>>::const_iterator it2 =
m_groupsMap.begin();
272 if (it2->second.find(*it) != it2->second.end())
280 groupIdZeroUts.Add(*it);
283 return groupIdZeroUts;
288 return NodeContainer();
291 NodeContainer utNodes;
292 std::set<Ptr<Node>> nodes =
m_groupsMap.at(groupId);
294 for (std::set<Ptr<Node>>::const_iterator i = nodes.begin(); i != nodes.end(); i++)
305 NS_LOG_FUNCTION(
this);
331 for (std::map<uint32_t, std::set<Ptr<Node>>>::const_iterator it =
m_groupsMap.begin();
335 if (it->second.find(node) != it->second.end())
346 NS_LOG_FUNCTION(
this);
348 NodeContainer nodesFiltered;
350 for (uint32_t i = 0; i < nodes.GetN(); i++)
355 nodesFiltered.Add(node);
358 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.
void Init(NodeContainer uts)
Initialize the helper.
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.
NodeContainer m_uts
The list of all the UTs in the simulation.
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.