32 #include <ns3/net-device.h>
33 #include <ns3/node-container.h>
34 #include <ns3/packet.h>
35 #include <ns3/pointer.h>
40 NS_LOG_COMPONENT_DEFINE(
"LoraNetworkStatus");
42 NS_OBJECT_ENSURE_REGISTERED(LoraNetworkStatus);
47 static TypeId tid = TypeId(
"ns3::LoraNetworkStatus").AddConstructor<
LoraNetworkStatus>();
53 NS_LOG_FUNCTION_NOARGS();
58 NS_LOG_FUNCTION_NOARGS();
64 NS_LOG_FUNCTION(
this << edMac);
71 Ptr<LoraEndDeviceStatus> edStatus =
72 CreateObject<LoraEndDeviceStatus>(edAddress,
78 NS_LOG_DEBUG(
"Added to the list a device with address " << edAddress.
Print());
85 NS_LOG_FUNCTION(
this << address << gwStatus);
93 m_gatewayStatuses.insert(std::pair<Address, Ptr<LoraGatewayStatus>>(address, gwStatus));
94 NS_LOG_DEBUG(
"Added to the list a gateway with address " << address);
101 NS_LOG_FUNCTION(
this << packet << gwAddress);
104 Ptr<Packet> myPacket = packet->Copy();
108 myPacket->RemoveHeader(macHdr);
111 myPacket->RemoveHeader(frameHdr);
115 NS_LOG_DEBUG(
"Node address: " << edAddr);
129 NS_LOG_FUNCTION(
this << deviceAddress << window);
133 double replyFrequency;
136 replyFrequency = edStatus->GetFirstReceiveWindowFrequency();
138 else if (window == 2)
140 replyFrequency = edStatus->GetSecondReceiveWindowFrequency();
144 NS_ABORT_MSG(
"Invalid window value");
151 std::map<double, Address> gwAddresses = edStatus->GetPowerGatewayMap();
156 Address bestGwAddress;
157 for (
auto it = gwAddresses.rbegin(); it != gwAddresses.rend(); it++)
160 m_gatewayStatuses.find(it->second)->second->IsAvailableForTransmission(replyFrequency);
163 bestGwAddress = it->second;
168 return bestGwAddress;
174 NS_LOG_FUNCTION(packet << gwAddress);
176 m_gatewayStatuses.find(gwAddress)->second->GetNetDevice()->Send(packet, gwAddress, 0x0800);
184 Ptr<Packet> packet = edStatus->GetCompleteReplyPacket();
189 switch (windowNumber)
192 tag.
SetDataRate(edStatus->GetMac()->GetFirstReceiveWindowDataRate());
193 tag.
SetFrequency(edStatus->GetFirstReceiveWindowFrequency());
196 tag.
SetDataRate(edStatus->GetMac()->GetSecondReceiveWindowDataRate());
197 tag.
SetFrequency(edStatus->GetSecondReceiveWindowFrequency());
201 packet->AddPacketTag(tag);
205 beamTag.
SetBeamId(edStatus->GetBeamId());
206 packet->AddPacketTag(beamTag);
210 Ptr<LoraEndDeviceStatus>
213 NS_LOG_FUNCTION(
this << packet);
218 Ptr<Packet> myPacket = packet->Copy();
219 myPacket->RemoveHeader(mHdr);
220 myPacket->RemoveHeader(fHdr);
228 NS_LOG_ERROR(
"EndDeviceStatus not found");
233 Ptr<LoraEndDeviceStatus>
236 NS_LOG_FUNCTION(
this << address);
245 NS_LOG_ERROR(
"EndDeviceStatus not found");
253 NS_LOG_FUNCTION(
this);
Tag used to save various data about a packet, like its Spreading Factor and data about interference.
void SetBeamId(uint8_t beamId)
Set which beamId this packet was transmitted with.
This class represents the device address of a LoraWAN End Device.
std::string Print(void) const
Print the address bit-by-bit to a human-readable string.
This class represents the knowledge about the state of the network that is available at the Network S...
void AddNode(Ptr< LorawanMacEndDeviceClassA > edMac)
Add a device to the ones that are tracked by this LoraNetworkStatus object.
void OnReceivedPacket(Ptr< const Packet > packet, const Address &gwaddress)
Update network status on the received packet.
Ptr< Packet > GetReplyForDevice(LoraDeviceAddress edAddress, int windowNumber)
Get the reply for the specified device address.
void AddGateway(Address &address, Ptr< LoraGatewayStatus > gwStatus)
Add this gateway to the list of gateways connected to the network.
Address GetBestGatewayForDevice(LoraDeviceAddress deviceAddress, int window)
Return whether we have a gateway that is available to send a reply to the specified device.
static TypeId GetTypeId(void)
Ptr< LoraEndDeviceStatus > GetEndDeviceStatus(Ptr< const Packet > packet)
Get the EndDeviceStatus for the device that sent a packet.
bool NeedsReply(LoraDeviceAddress deviceAddress)
Return whether the specified device needs a reply.
int CountEndDevices(void)
Return the number of end devices currently managed by the server.
void SendThroughGateway(Ptr< Packet > packet, Address gwAddress)
Send a packet through a Gateway.
virtual ~LoraNetworkStatus()
std::map< Address, Ptr< LoraGatewayStatus > > m_gatewayStatuses
std::map< LoraDeviceAddress, Ptr< LoraEndDeviceStatus > > m_endDeviceStatuses
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.
void SetModcod(uint8_t modcod)
Set the modcod for this packet.
Class representing the MAC layer of a Class A LoRaWAN device.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.