17#include "ns3/net-device.h"
18#include "ns3/node-container.h"
19#include "ns3/packet.h"
20#include "ns3/pointer.h"
36 .AddConstructor<NetworkStatus>()
37 .SetGroupName(
"lorawan");
83 NS_LOG_DEBUG(
"Added to the list a gateway with address " << address);
97 myPacket->RemoveHeader(macHdr);
100 myPacket->RemoveHeader(frameHdr);
120 double replyFrequency;
123 replyFrequency = edStatus->GetFirstReceiveWindowFrequency();
125 else if (window == 2)
127 replyFrequency = edStatus->GetSecondReceiveWindowFrequency();
138 std::map<double, Address> gwAddresses = edStatus->GetPowerGatewayMap();
144 for (
auto it = gwAddresses.rbegin(); it != gwAddresses.rend(); it++)
147 m_gatewayStatuses.find(it->second)->second->IsAvailableForTransmission(replyFrequency);
150 bestGwAddress = it->second;
155 return bestGwAddress;
163 m_gatewayStatuses.find(gwAddress)->second->GetNetDevice()->Send(packet, gwAddress, 0x0800);
171 Ptr<Packet> packet = edStatus->GetCompleteReplyPacket();
175 switch (windowNumber)
178 tag.
SetDataRate(edStatus->GetMac()->GetFirstReceiveWindowDataRate());
179 tag.
SetFrequency(edStatus->GetFirstReceiveWindowFrequency());
182 tag.
SetDataRate(edStatus->GetMac()->GetSecondReceiveWindowDataRate());
183 tag.
SetFrequency(edStatus->GetSecondReceiveWindowFrequency());
187 packet->AddPacketTag(tag);
200 myPacket->RemoveHeader(mHdr);
201 myPacket->RemoveHeader(fHdr);
a polymophic address class
A base class which provides memory management and object aggregation.
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
This class represents the device address of a LoraWAN end device.
std::string Print() const
Print the address bit-by-bit to a human-readable string.
Tag used to save various data about a packet, like its Spreading Factor and data about interference.
void SetDataRate(uint8_t dataRate)
Set the data rate for this packet.
void SetFrequency(double frequency)
Set the frequency of the packet.
~NetworkStatus() override
Destructor.
Ptr< EndDeviceStatus > GetEndDeviceStatus(Ptr< const Packet > packet)
Get the EndDeviceStatus of the device that sent a packet.
void OnReceivedPacket(Ptr< const Packet > packet, const Address &gwaddress)
Update network status on a received packet.
NetworkStatus()
Default constructor.
bool NeedsReply(LoraDeviceAddress deviceAddress)
Return whether the specified device needs a reply.
void AddNode(Ptr< ClassAEndDeviceLorawanMac > edMac)
Add a device to the ones that are tracked by this NetworkStatus object.
int CountEndDevices()
Return the number of end devices currently managed by the server.
std::map< LoraDeviceAddress, Ptr< EndDeviceStatus > > m_endDeviceStatuses
Map tracking the state of devices connected to this network server.
void SendThroughGateway(Ptr< Packet > packet, Address gwAddress)
Send a packet through a gateway.
std::map< Address, Ptr< GatewayStatus > > m_gatewayStatuses
Map tracking the state of gateways connected to this network server.
void AddGateway(Address &address, Ptr< GatewayStatus > gwStatus)
Add a new gateway to the list of gateways connected to the network.
static TypeId GetTypeId()
Register this type.
Ptr< Packet > GetReplyForDevice(LoraDeviceAddress edAddress, int windowNumber)
Get the reply packet prepared for a reception window of a device.
Address GetBestGatewayForDevice(LoraDeviceAddress deviceAddress, int window)
Return whether we have a gateway that is available to send a reply to the specified device.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#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 ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.