31 #include <ns3/command-line.h>
33 #include <ns3/packet.h>
34 #include <ns3/pointer.h>
35 #include <ns3/simulator.h>
42 NS_LOG_COMPONENT_DEFINE(
"LoraEndDeviceStatus");
47 static TypeId tid = TypeId(
"ns3::LoraEndDeviceStatus")
49 .AddConstructor<LoraEndDeviceStatus>();
54 Ptr<LorawanMacEndDeviceClassA> endDeviceMac)
56 m_endDeviceAddress(endDeviceAddress),
60 NS_LOG_FUNCTION(endDeviceAddress);
65 NS_LOG_FUNCTION_NOARGS();
74 NS_LOG_FUNCTION_NOARGS();
84 NS_LOG_FUNCTION_NOARGS();
91 NS_LOG_FUNCTION_NOARGS();
98 NS_LOG_FUNCTION_NOARGS();
106 NS_LOG_FUNCTION_NOARGS();
114 NS_LOG_FUNCTION_NOARGS();
122 NS_LOG_FUNCTION_NOARGS();
129 NS_LOG_FUNCTION_NOARGS();
132 Ptr<Packet> replyPacket;
135 NS_LOG_DEBUG(
"Crafting reply packet from existing payload");
140 NS_LOG_DEBUG(
"Crafting reply packet using an empty payload");
141 replyPacket = Create<Packet>(0);
151 lastPacket->RemoveHeader(mHdr);
152 lastPacket->RemoveHeader(fHdr);
167 NS_LOG_FUNCTION_NOARGS();
175 NS_LOG_FUNCTION_NOARGS();
182 NS_LOG_FUNCTION_NOARGS();
189 NS_LOG_FUNCTION_NOARGS();
193 Ptr<LorawanMacEndDeviceClassA>
202 NS_LOG_FUNCTION_NOARGS();
209 NS_LOG_FUNCTION(
this << modcod);
216 NS_LOG_FUNCTION(
this << beamId);
223 NS_LOG_FUNCTION(
this << sf);
230 NS_LOG_FUNCTION(
this << frequency);
237 NS_LOG_FUNCTION(
this << offset);
244 NS_LOG_FUNCTION(
this << frequency);
251 NS_LOG_FUNCTION_NOARGS();
258 NS_LOG_FUNCTION_NOARGS();
265 NS_LOG_FUNCTION(
this << replyPayload);
275 const Address& gwAddress)
277 NS_LOG_FUNCTION(
this << receivedPacket << gwAddress);
280 Ptr<Packet> myPacket = receivedPacket->Copy();
284 myPacket->RemovePacketTag(beamTag);
289 myPacket->RemoveHeader(macHdr);
293 myPacket->RemoveHeader(frameHdr);
297 myPacket->RemovePacketTag(tag);
306 info.
packet = receivedPacket;
319 Ptr<Packet> packetCopy = ((*it).first)->Copy();
321 packetCopy->RemoveHeader(currentMacHdr);
324 packetCopy->RemoveHeader(currentFrameHdr);
326 NS_LOG_DEBUG(
"Received packet's frame counter: " <<
unsigned(frameHdr.
GetFCnt())
327 <<
"\nCurrent packet's frame counter: "
328 <<
unsigned(currentFrameHdr.
GetFCnt()));
332 NS_LOG_INFO(
"Packet was already received by another gateway");
342 gwList.insert(std::pair<Address, PacketInfoPerGw>(gwAddress, gwInfo));
344 NS_LOG_DEBUG(
"Size of gateway list: " << gwList.size());
351 NS_LOG_INFO(
"Packet was received for the first time");
356 info.
gwList.insert(std::pair<Address, PacketInfoPerGw>(gwAddress, gwInfo));
366 NS_LOG_FUNCTION_NOARGS();
381 NS_LOG_FUNCTION_NOARGS();
396 NS_LOG_FUNCTION_NOARGS();
425 std::map<double, Address>
434 std::map<double, Address> gatewayPowers;
436 for (
auto it = gwList.begin(); it != gwList.end(); it++)
438 Address currentGwAddress = (*it).first;
439 double currentRxPower = (*it).second.rxPower;
440 gatewayPowers.insert(std::pair<double, Address>(currentRxPower, currentGwAddress));
443 return gatewayPowers;
455 Ptr<const Packet> pkt = (*j).first;
456 os << pkt <<
" " << gatewayList.size() << std::endl;
457 for (LoraEndDeviceStatus::GatewayList::iterator k = gatewayList.begin();
458 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.
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