33 #include <ns3/command-line.h>
35 #include <ns3/packet.h>
36 #include <ns3/pointer.h>
37 #include <ns3/simulator.h>
38 #include <ns3/singleton.h>
49 NS_LOG_COMPONENT_DEFINE(
"LoraEndDeviceStatus");
54 static TypeId tid = TypeId(
"ns3::LoraEndDeviceStatus")
56 .AddConstructor<LoraEndDeviceStatus>();
61 Ptr<LorawanMacEndDeviceClassA> endDeviceMac)
63 m_endDeviceAddress(endDeviceAddress),
64 m_utAddress(endDeviceMac->GetAddress()),
68 NS_LOG_FUNCTION(endDeviceAddress);
73 NS_LOG_FUNCTION_NOARGS();
82 NS_LOG_FUNCTION_NOARGS();
92 NS_LOG_FUNCTION_NOARGS();
99 NS_LOG_FUNCTION_NOARGS();
106 NS_LOG_FUNCTION_NOARGS();
114 NS_LOG_FUNCTION_NOARGS();
122 NS_LOG_FUNCTION_NOARGS();
130 NS_LOG_FUNCTION_NOARGS();
137 NS_LOG_FUNCTION_NOARGS();
140 Ptr<Packet> replyPacket;
143 NS_LOG_DEBUG(
"Crafting reply packet from existing payload");
148 NS_LOG_DEBUG(
"Crafting reply packet using an empty payload");
149 replyPacket = Create<Packet>(0);
159 lastPacket->RemoveHeader(mHdr);
160 lastPacket->RemoveHeader(fHdr);
166 if (Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode() ==
171 replyPacket->AddPacketTag(groundStationAddressTag);
183 NS_LOG_FUNCTION_NOARGS();
191 NS_LOG_FUNCTION_NOARGS();
198 NS_LOG_FUNCTION_NOARGS();
205 NS_LOG_FUNCTION_NOARGS();
209 Ptr<LorawanMacEndDeviceClassA>
218 NS_LOG_FUNCTION_NOARGS();
225 NS_LOG_FUNCTION(
this << modcod);
232 NS_LOG_FUNCTION(
this << beamId);
240 NS_LOG_FUNCTION(
this << sf);
247 NS_LOG_FUNCTION(
this << frequency);
254 NS_LOG_FUNCTION(
this << offset);
261 NS_LOG_FUNCTION(
this << frequency);
268 NS_LOG_FUNCTION_NOARGS();
275 NS_LOG_FUNCTION_NOARGS();
282 NS_LOG_FUNCTION(
this << replyPayload);
292 const Address& gwAddress)
294 NS_LOG_FUNCTION(
this << receivedPacket << gwAddress);
297 Ptr<Packet> myPacket = receivedPacket->Copy();
301 myPacket->RemovePacketTag(beamTag);
306 myPacket->RemoveHeader(macHdr);
310 myPacket->RemoveHeader(frameHdr);
314 myPacket->RemovePacketTag(tag);
323 info.
packet = receivedPacket;
336 Ptr<Packet> packetCopy = ((*it).first)->Copy();
338 packetCopy->RemoveHeader(currentMacHdr);
341 packetCopy->RemoveHeader(currentFrameHdr);
343 NS_LOG_DEBUG(
"Received packet's frame counter: " <<
unsigned(frameHdr.
GetFCnt())
344 <<
"\nCurrent packet's frame counter: "
345 <<
unsigned(currentFrameHdr.
GetFCnt()));
349 NS_LOG_INFO(
"Packet was already received by another gateway");
359 gwList.insert(std::pair<Address, PacketInfoPerGw>(gwAddress, gwInfo));
361 NS_LOG_DEBUG(
"Size of gateway list: " << gwList.size());
368 NS_LOG_INFO(
"Packet was received for the first time");
373 info.
gwList.insert(std::pair<Address, PacketInfoPerGw>(gwAddress, gwInfo));
383 NS_LOG_FUNCTION_NOARGS();
398 NS_LOG_FUNCTION_NOARGS();
413 NS_LOG_FUNCTION_NOARGS();
442 std::map<double, Address>
451 std::map<double, Address> gatewayPowers;
453 for (
auto it = gwList.begin(); it != gwList.end(); it++)
455 Address currentGwAddress = (*it).first;
456 double currentRxPower = (*it).second.rxPower;
457 gatewayPowers.insert(std::pair<double, Address>(currentRxPower, currentGwAddress));
460 return gatewayPowers;
472 Ptr<const Packet> pkt = (*j).first;
473 os << pkt <<
" " << gatewayList.size() << std::endl;
474 for (LoraEndDeviceStatus::GatewayList::iterator k = gatewayList.begin();
475 k != gatewayList.end();
Tag used to save various data about a packet, like its Spreading Factor and data about interference.
uint8_t GetBeamId() const
Read which beam ID this packet was transmitted with.
This class represents the device address of a LoraWAN End Device.
This class represents the Network Server's knowledge about an End Device in the LoRaWAN network it is...
double m_firstReceiveWindowFrequency
uint8_t GetBeamId(void)
Get the beam ID this device is using.
double GetFirstReceiveWindowFrequency(void)
Get the first window frequency of this device.
ReceivedPacketList GetReceivedPacketList(void)
Get the received packet list.
void AddMACCommand(Ptr< LorawanMacCommand > macCommand)
Add MAC command to the list.
Ptr< Packet > GetReplyPayload(void)
Get the data of the reply packet.
virtual ~LoraEndDeviceStatus()
void SetSecondReceiveWindowFrequency(double frequency)
Set the second window frequency of this device.
void SetSecondReceiveWindowOffset(uint8_t offset)
Set the spreading factor this device is using in the first receive window.
void SetFirstReceiveWindowSpreadingFactor(uint8_t sf)
Set the spreading factor this device is using in the first receive window.
void RemoveReceiveWindowOpportunity(void)
void SetBeamId(uint8_t beamId)
Set the beam ID this device is using.
uint8_t GetFirstReceiveWindowSpreadingFactor(void)
Get the spreading factor this device is using in the first receive window.
double m_secondReceiveWindowFrequency
LorawanMacHeader GetReplyMacHeader(void)
Get the reply packet mac header.
std::list< std::pair< Ptr< const Packet >, ReceivedPacketInfo > > ReceivedPacketList
uint8_t m_secondReceiveWindowOffset
void SetReplyMacHeader(LorawanMacHeader macHeader)
Set the reply packet mac header.
bool NeedsReply(void)
Whether the end device needs a reply.
LoraEndDeviceStatus::ReceivedPacketInfo GetLastReceivedPacketInfo(void)
Return the information about the last packet that was received from the device.
uint8_t GetModcod(void)
Get the modcod this device is using.
static TypeId GetTypeId(void)
Ptr< Packet > GetCompleteReplyPacket(void)
Get the reply packet.
void SetReplyPayload(Ptr< Packet > replyPayload)
Set the packet reply payload.
void SetReplyFrameHeader(LoraFrameHeader frameHeader)
Set the reply packet frame header.
EventId m_receiveWindowEvent
std::map< Address, PacketInfoPerGw > GatewayList
void InitializeReply(void)
Initialize reply.
Ptr< LorawanMacEndDeviceClassA > m_mac
Pointer to the MAC layer of this device.
double GetSecondReceiveWindowFrequency(void)
Return the second window frequency of this device.
Ptr< const Packet > GetLastPacketReceivedFromDevice(void)
Return the last packet that was received from this device.
uint8_t GetSecondReceiveWindowOffset(void)
Get the offset of spreading factor this device is using in the second receive window with respect to ...
void SetModcod(uint8_t modcod)
Set the modcod this device is using.
void InsertReceivedPacket(Ptr< const Packet > receivedPacket, const Address &gwAddress)
Insert a received packet in the packet list.
bool HasReceiveWindowOpportunityScheduled()
Returns whether we already decided we will schedule a transmission to this ED.
LoraFrameHeader GetReplyFrameHeader(void)
Get the reply packet frame header.
ReceivedPacketList m_receivedPacketList
uint8_t m_firstReceiveWindowSpreadingFactor
void SetFirstReceiveWindowFrequency(double frequency)
Set the first window frequency of this device.
LoraDeviceAddress m_endDeviceAddress
void SetReceiveWindowOpportunity(EventId event)
std::map< double, Address > GetPowerGatewayMap(void)
Return an ordered list of the best gateways.
Ptr< LorawanMacEndDeviceClassA > GetMac(void)
Tag used to save various data about a packet, like its Spreading Factor and data about interference.
double GetFrequency(void)
Get the frequency of the packet.
uint8_t GetSpreadingFactor() const
Read which Spreading Factor this packet was transmitted with.
uint8_t GetModcod(void)
Get the modcod for this packet.
double GetReceivePower() const
Read the power this packet arrived with.
Tag to store ground station destination address.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
std::ostream & operator<<(std::ostream &os, const GeoCoordinate &coordinate)
Structure saving information regarding the packet reception in each gateway.
Time receivedTime
Time at which the packet was received by this gateway.
Address gwAddress
Address of the gateway that received the packet.
double rxPower
Reception power of the packet at this gateway.
Structure saving information regarding all packet receptions.
GatewayList gwList
List of gateways that received this packet.
Ptr< const Packet > packet
The received packet.
Structure representing the reply that the network server will send this device at the first opportuni...
LorawanMacHeader macHeader
LoraFrameHeader frameHeader