Loading...
Searching...
No Matches
satellite-lorawan-net-device.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013 Magister Solutions Ltd.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Bastien TAURAN <bastien.tauran@viveris.fr>
19 */
20
22
23#include "lora-frame-header.h"
24#include "lora-tag.h"
25#include "lorawan-mac-header.h"
26#include "satellite-topology.h"
27
28#include "ns3/ipv4-header.h"
29#include "ns3/log.h"
30#include "ns3/singleton.h"
31
32NS_LOG_COMPONENT_DEFINE("SatLorawanNetDevice");
33
34namespace ns3
35{
36
37NS_OBJECT_ENSURE_REGISTERED(SatLorawanNetDevice);
38
39TypeId
41{
42 static TypeId tid = TypeId("ns3::SatLorawanNetDevice")
43 .SetParent<SatNetDevice>()
44 .AddConstructor<SatLorawanNetDevice>();
45 return tid;
46}
47
49{
50 NS_LOG_FUNCTION(this);
51
52 switch (Singleton<SatTopology>::Get()->GetForwardLinkRegenerationMode())
53 {
55 m_isRegenerative = false;
56 break;
57 }
59 m_isRegenerative = true;
60 break;
61 }
62 default:
63 NS_FATAL_ERROR("Incorrect regeneration mode for LORA");
64 }
65}
66
67void
68SatLorawanNetDevice::Receive(Ptr<const Packet> packet)
69{
70 NS_LOG_FUNCTION(this << packet);
71 NS_LOG_INFO("Receiving a packet: " << packet->GetUid());
72
73 // Add packet trace entry:
76
77 m_packetTrace(Simulator::Now(),
79 m_nodeInfo->GetNodeType(),
80 m_nodeInfo->GetNodeId(),
81 m_nodeInfo->GetMacAddress(),
83 ld,
85
86 /*
87 * Invoke the `Rx` and `RxDelay` trace sources. We look at the packet's tags
88 * for information, but cannot remove the tags because the packet is a const.
89 */
91 {
92 Address addr; // invalid address.
93 bool isTaggedWithAddress = false;
94 ByteTagIterator it = packet->GetByteTagIterator();
95
96 while (!isTaggedWithAddress && it.HasNext())
97 {
98 ByteTagIterator::Item item = it.Next();
99
100 if (item.GetTypeId() == SatAddressTag::GetTypeId())
101 {
102 NS_LOG_DEBUG(this << " contains a SatAddressTag tag:" << " start="
103 << item.GetStart() << " end=" << item.GetEnd());
104 SatAddressTag addrTag;
105 item.GetTag(addrTag);
106 addr = addrTag.GetSourceAddress();
107 isTaggedWithAddress = true; // this will exit the while loop.
108 }
109 }
110
111 m_rxTrace(packet, addr);
112
113 SatDevTimeTag timeTag;
114 if (packet->PeekPacketTag(timeTag))
115 {
116 NS_LOG_DEBUG(this << " contains a SatDevTimeTag tag");
117 Time delay = Simulator::Now() - timeTag.GetSenderTimestamp();
118 m_rxDelayTrace(delay, addr);
119 if (m_lastDelay.IsZero() == false)
120 {
121 Time jitter = Abs(delay - m_lastDelay);
122 m_rxJitterTrace(jitter, addr);
123 }
124 m_lastDelay = delay;
125 }
126 }
127
128 // Forward to Network Server if on GW.
129 if (m_nodeInfo->GetNodeType() == SatEnums::NT_GW)
130 {
131 Ptr<Packet> pktCopy = packet->Copy();
132 m_rxNetworkServerCallback(this, pktCopy, Ipv4L3Protocol::PROT_NUMBER, Address());
133 }
134
135 // Pass the packet to the upper layer if IP header in packet (GW or UT side)
136 LorawanMacHeader mHdr;
137 LoraFrameHeader fHdr;
138 Ipv4Header ipv4Header;
139 Ptr<Packet> pktCopy = packet->Copy();
140 pktCopy->RemoveHeader(mHdr);
141 pktCopy->RemoveHeader(fHdr);
142 if (pktCopy->PeekHeader(ipv4Header))
143 {
144 m_rxCallback(this, pktCopy, Ipv4L3Protocol::PROT_NUMBER, Address());
145 }
146}
147
148bool
149SatLorawanNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
150{
151 NS_LOG_FUNCTION(this << packet << dest << protocolNumber);
152
153 // only send tagged Lora packets
154 LoraTag tag;
155 if ((!packet->PeekPacketTag(tag)) && (m_nodeInfo->GetNodeType() == SatEnums::NT_GW))
156 {
157 return false;
158 }
159
160 // Add packet trace entry:
163
164 m_packetTrace(Simulator::Now(),
166 m_nodeInfo->GetNodeType(),
167 m_nodeInfo->GetNodeId(),
168 m_nodeInfo->GetMacAddress(),
170 ld,
172
173 m_txTrace(packet);
174
175 Address addr; // invalid address.
176 bool isTaggedWithAddress = false;
177 ByteTagIterator it = packet->GetByteTagIterator();
178
179 while (!isTaggedWithAddress && it.HasNext())
180 {
181 ByteTagIterator::Item item = it.Next();
182
183 if (item.GetTypeId() == SatAddressTag::GetTypeId())
184 {
185 NS_LOG_DEBUG(this << " contains a SatAddressTag tag:" << " start=" << item.GetStart()
186 << " end=" << item.GetEnd());
187 SatAddressTag addrTag;
188 item.GetTag(addrTag);
189 addr = addrTag.GetSourceAddress();
190 isTaggedWithAddress = true; // this will exit the while loop.
191 }
192 }
193
194 if (m_isRegenerative && m_nodeInfo->GetNodeType() == SatEnums::NT_GW)
195 {
196 uint8_t flowId = m_classifier->Classify(packet, dest, protocolNumber);
197
198 m_llc->Enque(packet, dest, flowId);
199 }
200 else
201 {
202 DynamicCast<LorawanMac>(m_mac)->Send(packet, dest, protocolNumber);
203 }
204
205 return true;
206}
207
208bool
209SatLorawanNetDevice::SendControlMsg(Ptr<SatControlMessage> msg, const Address& dest)
210{
211 // We send nothing in Lora Mode. Control is made via LorawanMacCommand
212 return true;
213}
214
215void
221
222void
224{
225 NS_LOG_FUNCTION(this);
226
228}
229
230} // namespace ns3
This class represents the Frame header (FHDR) used in a LoraWAN network.
Tag used to save various data about a packet, like its Spreading Factor and data about interference.
Definition lora-tag.h:41
This class represents the Mac header of a LoRaWAN packet.
This class implements a tag that carries the MAC address of the sender of the packet.
static TypeId GetTypeId()
Inherited from ObjectBase base class.
Address GetSourceAddress() const
Get the source address.
Time tag used to identify the time when packet is enqueued at device level.
Time GetSenderTimestamp(void) const
Get sender time stamp of this tag.
SatLinkDir_t
Link direction used for packet tracing.
SatLorawanNetDevice to be utilized in the UT and GW nodes for IoT configuration.
void Receive(Ptr< const Packet > packet)
void SetReceiveNetworkServerCallback(SatLorawanNetDevice::ReceiveCallback cb)
bool SendControlMsg(Ptr< SatControlMessage > msg, const Address &dest)
static TypeId GetTypeId(void)
Get the type ID.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
virtual void DoDispose(void)
Method called to inform the Scheduler of a newly arrived uplink packet.
Callback< bool, Ptr< SatLorawanNetDevice >, Ptr< const Packet >, uint16_t, const Address & > ReceiveCallback
TracedCallback< const Time &, const Address & > m_rxDelayTrace
Traced callback for all received packets, including delay information and the address of the senders.
SatNetDevice()
Default constructor.
TracedCallback< Ptr< const Packet > > m_txTrace
Traced callback for all packets received to be transmitted.
Ptr< SatPacketClassifier > m_classifier
Time m_lastDelay
Last delay measurement.
virtual void DoDispose(void)
Dispose of this class instance.
TracedCallback< Ptr< const Packet >, const Address & > m_rxTrace
Traced callback for all received packets, including the address of the senders.
Ptr< SatNodeInfo > m_nodeInfo
TracedCallback< Time, SatEnums::SatPacketEvent_t, SatEnums::SatNodeType_t, uint32_t, Mac48Address, SatEnums::SatLogLevel_t, SatEnums::SatLinkDir_t, std::string > m_packetTrace
TracedCallback< const Time &, const Address & > m_rxJitterTrace
Traced callback for all received packets, including jitter information and the address of the senders...
NetDevice::ReceiveCallback m_rxCallback
bool m_isStatisticsTagsEnabled
EnableStatisticsTags attribute.
static std::string GetPacketInfo(const Ptr< const Packet > p)
Get packet information in std::string for printing purposes.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.