26 #include <ns3/address.h>
36 NS_LOG_COMPONENT_DEFINE(
"SatIdMapper");
41 NS_OBJECT_ENSURE_REGISTERED(SatIdMapper);
47 TypeId(
"ns3::SatIdMapper").SetParent<Object>().AddConstructor<SatIdMapper>();
56 m_enableMapPrint(false)
58 NS_LOG_FUNCTION(
this);
63 NS_LOG_FUNCTION(
this);
71 NS_LOG_FUNCTION(
this);
81 NS_LOG_FUNCTION(
this);
161 std::cout <<
"SatIdMapper GW/UT MAC to satellite ID map" << std::endl;
162 std::map<Mac48Address, uint32_t>::iterator it;
165 std::cout << it->first <<
" " << it->second << std::endl;
167 std::cout << std::endl;
175 NS_LOG_FUNCTION(
this << mac);
179 std::pair<std::map<Address, uint32_t>::iterator,
bool> resultMacToTraceId =
182 if (resultMacToTraceId.second ==
false)
184 NS_FATAL_ERROR(
"SatIdMapper::AttachMacToTraceId - MAC to Trace ID failed. MAC "
188 NS_LOG_INFO(
"Added MAC " << mac <<
" with Trace ID " <<
m_traceIdIndex);
197 NS_LOG_FUNCTION(
this << mac);
200 std::pair<std::map<Address, uint32_t>::iterator,
bool> resultMacToUtId =
203 if (resultMacToUtId.second ==
false)
205 NS_FATAL_ERROR(
"SatIdMapper::AttachMacToUtId - MAC to UT ID failed");
208 NS_LOG_INFO(
"Added MAC " << mac <<
" with UT ID " <<
m_utIdIndex);
217 NS_LOG_FUNCTION(
this << mac);
220 std::pair<std::map<Address, uint32_t>::iterator,
bool> resultMacToUtUserId =
223 if (resultMacToUtUserId.second ==
false)
225 NS_FATAL_ERROR(
"SatIdMapper::AttachMacToUtUserId - MAC to UT user ID failed");
228 NS_LOG_INFO(
"Added MAC " << mac <<
" with UT user ID " <<
m_utUserIdIndex);
237 NS_LOG_FUNCTION(
this << mac << satId);
239 std::pair<std::map<Address, uint32_t>::iterator,
bool> resultMacToSatId =
242 if (resultMacToSatId.second ==
false)
244 NS_FATAL_ERROR(
"SatIdMapper::AttachMacToSatId - MAC to sat ID failed");
247 NS_LOG_INFO(
"Added MAC " << mac <<
" with sat ID " << satId);
253 NS_LOG_FUNCTION(
this << mac << beamId);
255 std::pair<std::map<Address, uint32_t>::iterator,
bool> resultMacToBeamId =
258 if (resultMacToBeamId.second ==
false)
260 NS_FATAL_ERROR(
"SatIdMapper::AttachMacToBeamId - MAC to beam ID failed");
263 NS_LOG_INFO(
"Added MAC " << mac <<
" with beam ID " << beamId);
269 NS_LOG_FUNCTION(
this << mac << groupId);
271 std::pair<std::map<Address, uint32_t>::iterator,
bool> resultMacToGroupId =
274 if (resultMacToGroupId.second ==
false)
276 NS_FATAL_ERROR(
"SatIdMapper::AttachMacToGroupId - MAC to group ID failed");
279 NS_LOG_INFO(
"Added MAC " << mac <<
" with group ID " << groupId);
285 NS_LOG_FUNCTION(
this << mac << gwId);
287 std::pair<std::map<Address, uint32_t>::iterator,
bool> resultMacToGwId =
290 if (resultMacToGwId.second ==
false)
292 NS_FATAL_ERROR(
"SatIdMapper::AttachMacToGwId - MAC to GW ID failed");
295 NS_LOG_INFO(
"Added MAC " << mac <<
" with GW ID " << gwId);
301 NS_LOG_FUNCTION(
this << mac);
304 std::pair<std::map<Address, uint32_t>::iterator,
bool> resultMacToGwUserId =
307 if (resultMacToGwUserId.second ==
false)
309 NS_FATAL_ERROR(
"SatIdMapper::AttachMacToGwUserId - MAC to GW user ID failed");
312 NS_LOG_INFO(
"Added MAC " << mac <<
" with GW user ID " <<
m_gwUserIdIndex);
321 NS_LOG_FUNCTION(
this << mac << satId);
323 std::pair<std::map<Mac48Address, uint32_t>::iterator,
bool> resultMacToSatId =
326 if (resultMacToSatId.second ==
false)
328 NS_FATAL_ERROR(
"SatIdMapper::AttachMacToSatIdIsl - MAC to sat ID failed");
331 NS_LOG_INFO(
"Added MAC " << mac <<
" with sat ISL ID " << satId);
337 NS_LOG_FUNCTION(
this << mac);
341 NS_FATAL_ERROR(
"SatIdMapper::RemoveMacToSatIdIsl - MAC " << mac <<
" not in map");
344 NS_LOG_INFO(
"Removed MAC " << mac <<
" from ISL IDs");
350 NS_LOG_FUNCTION(
this << mac << satId);
352 std::map<Address, uint32_t>::iterator iter =
m_macToSatIdMap.find(mac);
356 NS_FATAL_ERROR(
"Mac address " << mac <<
" not in map");
359 iter->second = satId + 1;
361 NS_LOG_INFO(
"Updated MAC " << mac <<
" with sat ID " << satId);
367 NS_LOG_FUNCTION(
this << mac << beamId);
373 NS_FATAL_ERROR(
"Mac address " << mac <<
" not in map");
376 iter->second = beamId;
378 NS_LOG_INFO(
"Updated MAC " << mac <<
" with beam ID " << beamId);
386 NS_LOG_FUNCTION(
this << mac);
401 NS_LOG_FUNCTION(
this << mac);
403 std::map<Address, uint32_t>::const_iterator iter =
m_macToUtIdMap.find(mac);
416 NS_LOG_FUNCTION(
this << mac);
431 NS_LOG_FUNCTION(
this << mac);
433 std::map<Address, uint32_t>::const_iterator iter =
m_macToSatIdMap.find(mac);
446 NS_LOG_FUNCTION(
this << mac);
448 std::map<Address, uint32_t>::const_iterator iter =
m_macToBeamIdMap.find(mac);
461 NS_LOG_FUNCTION(
this << mac);
476 NS_LOG_FUNCTION(
this << mac);
478 std::map<Address, uint32_t>::const_iterator iter =
m_macToGwIdMap.find(mac);
491 NS_LOG_FUNCTION(
this << mac);
506 NS_LOG_FUNCTION(
this << mac);
523 NS_LOG_FUNCTION(
this << gwNode->GetId());
525 if (gwNode->GetNDevices() >= 3)
532 Ptr<NetDevice> dev = gwNode->GetDevice(1);
536 if (Mac48Address::IsMatchingType(dev->GetAddress()))
538 return dev->GetAddress();
542 NS_LOG_WARN(
this <<
" Device 1 of Node " << gwNode->GetId()
543 <<
" is not have a valid Mac48Address");
549 NS_LOG_WARN(
this <<
" Node " << gwNode->GetId() <<
" is not a valid GW");
555 NS_LOG_WARN(
this <<
" Node " << gwNode->GetId() <<
" is not a valid GW");
563 NS_LOG_FUNCTION(
this << satNode->GetId());
565 if (satNode->GetNDevices() >= 1)
567 Ptr<NetDevice> dev = satNode->GetDevice(0);
571 if (Mac48Address::IsMatchingType(dev->GetAddress()))
573 return dev->GetAddress();
577 NS_LOG_WARN(
this <<
" Device 0 of Node " << satNode->GetId()
578 <<
" does not have a valid Mac48Address");
584 NS_LOG_WARN(
this <<
" Node " << satNode->GetId() <<
" is not a valid SAT");
590 NS_LOG_WARN(
this <<
" Node " << satNode->GetId() <<
" is not a valid SAT");
598 NS_LOG_FUNCTION(
this << utNode->GetId());
600 if (utNode->GetNDevices() >= 3)
606 Ptr<NetDevice> dev = utNode->GetDevice(2);
610 if (Mac48Address::IsMatchingType(dev->GetAddress()))
612 return dev->GetAddress();
616 NS_LOG_WARN(
this <<
" Device 2 of Node " << utNode->GetId()
617 <<
" is not have a valid Mac48Address");
623 NS_LOG_WARN(
this <<
" Node " << utNode->GetId() <<
" is not a valid UT");
629 NS_LOG_WARN(
this <<
" Node " << utNode->GetId() <<
" is not a valid UT");
637 NS_LOG_FUNCTION(
this << utUserNode->GetId());
639 if (utUserNode->GetNDevices() >= 2)
645 Ptr<NetDevice> dev = utUserNode->GetDevice(1);
646 NS_ASSERT(dev !=
nullptr);
648 if (Mac48Address::IsMatchingType(dev->GetAddress()))
650 return dev->GetAddress();
654 NS_LOG_WARN(
this <<
" Device 1 of Node " << utUserNode->GetId()
655 <<
" is not have a valid Mac48Address");
661 NS_LOG_WARN(
this <<
" Node " << utUserNode->GetId() <<
" is not a valid UT user");
669 NS_LOG_FUNCTION(
this);
671 std::stringstream out;
672 bool isInMap =
false;
676 std::map<Address, uint32_t>::const_iterator iterTrace =
m_macToTraceIdMap.find(mac);
680 out <<
"trace ID: " << iterTrace->second <<
" ";
684 std::map<Address, uint32_t>::const_iterator iterSat =
m_macToSatIdMap.find(mac);
688 out <<
"sat ID: " << iterSat->second <<
" ";
692 std::map<Address, uint32_t>::const_iterator iterBeam =
m_macToBeamIdMap.find(mac);
696 out <<
"beam ID: " << iterBeam->second <<
" ";
700 std::map<Address, uint32_t>::const_iterator iterGroup =
m_macToGroupIdMap.find(mac);
704 out <<
"beam ID: " << iterGroup->second <<
" ";
708 std::map<Address, uint32_t>::const_iterator iterUt =
m_macToUtIdMap.find(mac);
712 out <<
"UT ID: " << iterUt->second <<
" ";
716 std::map<Address, uint32_t>::const_iterator iterGw =
m_macToGwIdMap.find(mac);
720 out <<
"GW ID: " << iterGw->second <<
" ";
724 std::string infoString = out.str();
729 out <<
"not found in the mapper";
730 infoString = out.str();
739 NS_LOG_FUNCTION(
this);
741 std::map<Address, uint32_t>::const_iterator iter;
745 std::cout <<
GetMacInfo(iter->first) << std::endl;
void Reset()
Function for resetting the variables.
int32_t GetTraceIdWithMac(Address mac) const
Function for getting the trace ID with MAC.
std::map< Mac48Address, uint32_t > m_macToSatIdIslMap
Map for GW/UT MAC to associated SAT ID conversion.
~SatIdMapper()
Destructor.
int32_t GetBeamIdWithMac(Address mac) const
Function for getting the beam ID with MAC.
void UpdateMacToSatId(Address mac, uint32_t satId)
Update MAC address to the SAT ID maps.
std::map< Address, uint32_t > m_macToGroupIdMap
Map for MAC to group ID conversion.
uint32_t m_utUserIdIndex
Running UT user index number.
SatIdMapper()
Constructor.
int32_t GetUtUserIdWithMac(Address mac) const
Function for getting the UT user ID with MAC.
bool m_enableMapPrint
Is map printing enabled or not.
int32_t GetSatIdWithMac(Address mac) const
Function for getting the SAT ID with MAC.
uint32_t AttachMacToTraceId(Address mac)
Attach MAC address to the Trace ID maps and give it a running trace ID (starting from 1)
uint32_t AttachMacToGwUserId(Address mac)
Attach MAC address to the GW user ID maps and give it a running GW user ID (starting from 1)
std::map< Address, uint32_t > m_macToSatIdMap
Map for MAC to SAT ID conversion.
void PrintTraceMap() const
Function for printing out the trace map.
void ShowIslMap()
Print the map GW/UT address to satellite ID.
std::string GetMacInfo(Address mac) const
Function for getting the IDs related to a MAC address in an info string.
Address GetSatMacWithNode(Ptr< Node > satNode) const
uint32_t AttachMacToUtUserId(Address mac)
Attach MAC address to the UT user ID maps and give it a running UT user ID (starting from 1)
std::map< Address, uint32_t > m_macToBeamIdMap
Map for MAC to beam ID conversion.
std::map< Address, uint32_t > m_macToUtUserIdMap
Map for MAC to UT user ID conversion.
uint32_t m_utIdIndex
Running UT index number.
uint32_t m_traceIdIndex
Running trace index number.
void AttachMacToGwId(Address mac, uint32_t gwId)
Attach MAC address to the GW ID maps.
void RemoveMacToSatIdIsl(Mac48Address mac)
Remove GW/UT MAC address to the satellite this node is connected.
uint32_t m_gwUserIdIndex
Running GW user index number.
std::map< Address, uint32_t > m_macToTraceIdMap
Map for MAC to trace ID conversion.
int32_t GetGwIdWithMac(Address mac) const
Function for getting the GW ID with MAC.
std::map< Address, uint32_t > m_macToGwUserIdMap
Map for MAC to GW user ID conversion.
void AttachMacToBeamId(Address mac, uint32_t beamId)
Attach MAC address to the beam ID maps.
void AttachMacToSatId(Address mac, uint32_t satId)
Attach MAC address to the SAT ID maps and give it a running SAT ID (starting from 1)
static TypeId GetTypeId(void)
NS-3 type id function.
void DoDispose()
Do needed dispose actions.
std::map< Address, uint32_t > m_macToUtIdMap
Map for MAC to UT ID conversion.
int32_t GetSatIdWithMacIsl(Mac48Address mac) const
Function for getting the satellite ID connected to a GW/UT MAC address.
int32_t GetUtIdWithMac(Address mac) const
Function for getting the UT ID with MAC.
void UpdateMacToBeamId(Address mac, uint32_t beamId)
Update MAC address to the beam ID maps.
Address GetGwMacWithNode(Ptr< Node > gwNode) const
void AttachMacToSatIdIsl(Mac48Address mac, uint32_t satId)
Attach GW/UT MAC address to the satellite this node is connected.
std::map< Address, uint32_t > m_macToGwIdMap
Map for MAC to GW ID conversion.
uint32_t AttachMacToUtId(Address mac)
Attach MAC address to the UT ID maps and give it a running UT ID (starting from 1)
void AttachMacToGroupId(Address mac, uint32_t groupId)
Attach MAC address to the group ID maps.
int32_t GetGwUserIdWithMac(Address mac) const
Function for getting the GW user ID with MAC.
Address GetUtMacWithNode(Ptr< Node > utNode) const
Address GetUtUserMacWithNode(Ptr< Node > utUserNode) const
int32_t GetGroupIdWithMac(Address mac) const
Function for getting the group ID with MAC.
SatNetDevice to be utilized in the UT and GW nodes.
SatOrbiterNetDevice to be utilized in geostationary satellite.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.