16#include "ns3/command-line.h"
18#include "ns3/packet.h"
19#include "ns3/pointer.h"
20#include "ns3/simulator.h"
36 .AddConstructor<EndDeviceStatus>()
37 .SetGroupName(
"lorawan");
44 m_endDeviceAddress(endDeviceAddress),
109 NS_LOG_DEBUG(
"Crafting reply packet from existing payload");
114 NS_LOG_DEBUG(
"Crafting reply packet using an empty payload");
124 lastPacket->RemoveHeader(mHdr);
125 lastPacket->RemoveHeader(fHdr);
242 myPacket->RemoveHeader(macHdr);
246 myPacket->RemoveHeader(frameHdr);
250 myPacket->RemovePacketTag(tag);
258 info.
packet = receivedPacket;
273 packetCopy->RemoveHeader(currentMacHdr);
276 packetCopy->RemoveHeader(currentFrameHdr);
279 <<
"\nCurrent packet's frame counter: "
280 <<
unsigned(currentFrameHdr.
GetFCnt()));
284 NS_LOG_INFO(
"Packet was already received by another gateway");
294 gwList.insert(std::pair<Address, PacketInfoPerGw>(gwAddress, gwInfo));
296 NS_LOG_DEBUG(
"Size of gateway list: " << gwList.size());
303 NS_LOG_INFO(
"Packet was received for the first time");
308 info.
gwList.insert(std::pair<Address, PacketInfoPerGw>(gwAddress, gwInfo));
376std::map<double, Address>
385 std::map<double, Address> gatewayPowers;
387 for (
auto it = gwList.begin(); it != gwList.end(); it++)
389 Address currentGwAddress = (*it).first;
390 double currentRxPower = (*it).second.rxPower;
391 gatewayPowers.insert(std::pair<double, Address>(currentRxPower, currentGwAddress));
394 return gatewayPowers;
407 os << pkt <<
" " << gatewayList.size() << std::endl;
408 for (
auto k = gatewayList.begin(); k != gatewayList.end(); k++)
a polymophic address class
An identifier for simulation events.
bool IsPending() const
This method is syntactic sugar for !IsExpired().
A base class which provides memory management and object aggregation.
Ptr< Packet > Copy() const
performs a COW copy of the packet.
Smart pointer class similar to boost::intrusive_ptr.
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
static Time Now()
Return the current simulation virtual time.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
This class represents the network server's knowledge about an end device in the LoRaWAN network it is...
EndDeviceStatus::ReceivedPacketInfo GetLastReceivedPacketInfo()
Return the information about the last packet that was received from the device.
void SetFirstReceiveWindowFrequency(double frequency)
Set the first window frequency of this device.
void SetSecondReceiveWindowFrequency(double frequency)
Set the second window frequency of this device.
uint8_t m_secondReceiveWindowSpreadingFactor
Spreading Factor (SF) for RX2 window.
bool HasReceiveWindowOpportunityScheduled()
Check if there is already a running reception window event scheduled for this end device.
void SetReplyMacHeader(LorawanMacHeader macHeader)
Set the reply packet mac header.
void SetReplyFrameHeader(LoraFrameHeader frameHeader)
Set the reply packet frame header.
double m_firstReceiveWindowFrequency
Frequency [MHz] for RX1 window.
static TypeId GetTypeId()
Register this type.
Ptr< Packet > GetReplyPayload()
Get the data of the reply packet.
std::list< std::pair< Ptr< const Packet >, ReceivedPacketInfo > > ReceivedPacketList
typedef of a list of packets paired to their reception info.
void SetSecondReceiveWindowSpreadingFactor(uint8_t sf)
Set the spreading factor this device is using in the second receive window.
LorawanMacHeader GetReplyMacHeader() const
Get the reply packet mac header.
uint8_t m_firstReceiveWindowSpreadingFactor
Spreading Factor (SF) for RX1 window.
void InsertReceivedPacket(Ptr< const Packet > receivedPacket, const Address &gwAddress)
Insert a received packet in the packet list.
EventId m_receiveWindowEvent
Event storing the next scheduled downlink transmission.
struct Reply m_reply
Next reply intended for this device.
LoraDeviceAddress m_endDeviceAddress
The address of this device.
bool NeedsReply() const
Whether the end device needs a reply.
LoraFrameHeader GetReplyFrameHeader() const
Get the reply packet frame header.
double m_secondReceiveWindowFrequency
Frequency [MHz] for RX2 window.
double GetSecondReceiveWindowFrequency() const
Return the second window frequency of this device.
std::map< Address, PacketInfoPerGw > GatewayList
typedef of a list of gateways with relative reception information.
ReceivedPacketList m_receivedPacketList
List of received packets.
void RemoveReceiveWindowOpportunity()
Cancel next scheduled reception window event.
void SetReceiveWindowOpportunity(EventId event)
Store next scheduled reception window event.
ReceivedPacketList GetReceivedPacketList() const
Get the received packet list.
double GetFirstReceiveWindowFrequency() const
Get the first window frequency of this device.
Ptr< const Packet > GetLastPacketReceivedFromDevice()
Return the last packet that was received from this device.
void SetReplyPayload(Ptr< Packet > replyPayload)
Set the packet reply payload.
void AddMACCommand(Ptr< MacCommand > macCommand)
Add MAC command to the frame header of next reply.
uint8_t GetFirstReceiveWindowSpreadingFactor() const
Get 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.
Ptr< ClassAEndDeviceLorawanMac > m_mac
Pointer to the MAC layer of this device.
void InitializeReply()
Reset the next reply state.
std::map< double, Address > GetPowerGatewayMap()
Get the gateways which received the last packet from the end device.
uint8_t GetSecondReceiveWindowSpreadingFactor() const
Get the spreading factor this device is using in the second receive window.
Ptr< Packet > GetCompleteReplyPacket()
Get the reply packet.
~EndDeviceStatus() override
Destructor.
EndDeviceStatus()
Default constructor.
Ptr< ClassAEndDeviceLorawanMac > GetMac()
Get the MAC layer of the end device.
This class represents the device address of a LoraWAN end device.
Tag used to save various data about a packet, like its Spreading Factor and data about interference.
double GetReceivePower() const
Read the power this packet arrived with.
uint8_t GetSpreadingFactor() const
Read which Spreading Factor this packet was transmitted with.
double GetFrequency() const
Get the frequency of the packet.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
std::ostream & operator<<(std::ostream &os, const EndDeviceStatus &status)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T > Copy(Ptr< T > object)
Return a deep copy of a Ptr.
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.
double frequency
Carrier frequency [MHz] used to send this packet.
Ptr< const Packet > packet
The received packet.
uint8_t sf
Spreading factor used to send this packet.
Structure representing the reply that the network server will send this device at the first opportuni...
LorawanMacHeader macHeader
The MAC Header to attach to the reply packet.
bool needsReply
Whether or not this device needs a reply.
Ptr< Packet > payload
The data packet that will be sent as a reply.
LoraFrameHeader frameHeader
The Frame Header to attach to the reply packet.