33 NS_LOG_COMPONENT_DEFINE(
"LorawanLorawanMacCommand");
35 NS_OBJECT_ENSURE_REGISTERED(LorawanMacCommand);
40 static TypeId tid = TypeId(
"ns3::LorawanMacCommand").SetParent<Object>();
46 NS_LOG_FUNCTION(
this);
51 NS_LOG_FUNCTION(
this);
57 NS_LOG_FUNCTION_NOARGS();
65 NS_LOG_FUNCTION_NOARGS();
73 NS_LOG_FUNCTION_NOARGS();
126 NS_LOG_FUNCTION_NOARGS();
133 NS_LOG_FUNCTION_NOARGS();
139 NS_LOG_FUNCTION_NOARGS();
144 NS_LOG_DEBUG(
"Serialized LinkCheckReq: " <<
unsigned(cid));
150 NS_LOG_FUNCTION_NOARGS();
161 NS_LOG_FUNCTION_NOARGS();
163 os <<
"LinkCheckReq" << std::endl;
174 NS_LOG_FUNCTION(
this);
184 NS_LOG_FUNCTION(
this <<
unsigned(margin) <<
unsigned(gwCnt));
193 NS_LOG_FUNCTION_NOARGS();
206 NS_LOG_FUNCTION_NOARGS();
218 NS_LOG_FUNCTION_NOARGS();
220 os <<
"LinkCheckAns" << std::endl;
221 os <<
"margin: " << unsigned(
m_margin) << std::endl;
222 os <<
"gwCnt: " << unsigned(
m_gwCnt) << std::endl;
228 NS_LOG_FUNCTION(
this <<
unsigned(margin));
236 NS_LOG_FUNCTION(
this);
244 NS_LOG_FUNCTION(
this <<
unsigned(gwCnt));
252 NS_LOG_FUNCTION(
this);
260 NS_LOG_FUNCTION(
this);
271 NS_LOG_FUNCTION(
this);
279 uint16_t channelMask,
282 : m_dataRate(dataRate),
284 m_channelMask(channelMask),
285 m_chMaskCntl(chMaskCntl),
288 NS_LOG_FUNCTION(
this);
297 NS_LOG_FUNCTION_NOARGS();
309 NS_LOG_FUNCTION_NOARGS();
313 uint8_t firstByte = start.ReadU8();
317 uint8_t fourthByte = start.ReadU8();
327 NS_LOG_FUNCTION_NOARGS();
329 os <<
"LinkAdrReq" << std::endl;
330 os <<
"dataRate: " << unsigned(
m_dataRate) << std::endl;
331 os <<
"txPower: " << unsigned(
m_txPower) << std::endl;
332 os <<
"channelMask: " << std::bitset<16>(
m_channelMask) << std::endl;
333 os <<
"chMaskCntl: " << unsigned(
m_chMaskCntl) << std::endl;
334 os <<
"nbRep: " << unsigned(
m_nbRep) << std::endl;
340 NS_LOG_FUNCTION(
this);
348 NS_LOG_FUNCTION(
this);
356 NS_LOG_FUNCTION(
this);
358 std::list<int> channelIndices;
359 for (
int i = 0; i < 16; i++)
363 NS_LOG_DEBUG(
"Adding channel index " << i);
364 channelIndices.push_back(i);
368 return channelIndices;
374 NS_LOG_FUNCTION(
this);
385 NS_LOG_FUNCTION(
this);
392 : m_powerAck(powerAck),
393 m_dataRateAck(dataRateAck),
394 m_channelMaskAck(channelMaskAck)
396 NS_LOG_FUNCTION(
this);
405 NS_LOG_FUNCTION_NOARGS();
418 NS_LOG_FUNCTION_NOARGS();
423 uint8_t
byte = start.ReadU8();
435 NS_LOG_FUNCTION_NOARGS();
437 os <<
"LinkAdrAns" << std::endl;
446 NS_LOG_FUNCTION(
this);
453 : m_maxDCycle(dutyCycle)
455 NS_LOG_FUNCTION(
this);
464 NS_LOG_FUNCTION_NOARGS();
474 NS_LOG_FUNCTION_NOARGS();
486 NS_LOG_FUNCTION_NOARGS();
488 os <<
"DutyCycleReq" << std::endl;
489 os <<
"maxDCycle: " << unsigned(
m_maxDCycle) << std::endl;
496 NS_LOG_FUNCTION(
this);
518 NS_LOG_FUNCTION(
this);
527 NS_LOG_FUNCTION_NOARGS();
536 NS_LOG_FUNCTION_NOARGS();
546 NS_LOG_FUNCTION_NOARGS();
548 os <<
"DutyCycleAns" << std::endl;
557 NS_LOG_FUNCTION(
this);
564 : m_rx1DrOffset(rx1DrOffset),
565 m_rx2DataRate(rx2DataRate),
566 m_frequency(frequency)
568 NS_LOG_FUNCTION(
this <<
unsigned(rx1DrOffset) <<
unsigned(rx2DataRate) << frequency);
570 if ((rx1DrOffset & 0b11111000) != 0)
573 "Warning: received an rx1DrOffset greater than 7. Actual value will be different.");
575 if ((rx2DataRate & 0b11110000) != 0)
578 "Warning: received a rx2DataRate greater than 15. Actual value will be different.");
588 NS_LOG_FUNCTION_NOARGS();
594 uint32_t encodedFrequency = uint32_t(
m_frequency / 100);
595 NS_LOG_DEBUG(
unsigned(encodedFrequency));
596 NS_LOG_DEBUG(std::bitset<32>(encodedFrequency));
597 start.WriteU8((encodedFrequency & 0xff0000) >> 16);
598 start.WriteU8((encodedFrequency & 0xff00) >> 8);
599 start.WriteU8(encodedFrequency & 0xff);
605 NS_LOG_FUNCTION_NOARGS();
610 uint8_t firstByte = start.ReadU8();
613 uint32_t secondByte = start.ReadU8();
614 uint32_t thirdByte = start.ReadU8();
615 uint32_t fourthByte = start.ReadU8();
616 uint32_t encodedFrequency = (secondByte << 16) | (thirdByte << 8) | fourthByte;
617 NS_LOG_DEBUG(std::bitset<32>(encodedFrequency));
626 NS_LOG_FUNCTION_NOARGS();
628 os <<
"RxParamSetupReq" << std::endl;
629 os <<
"rx1DrOffset: " << unsigned(
m_rx1DrOffset) << std::endl;
630 os <<
"rx2DataRate: " << unsigned(
m_rx2DataRate) << std::endl;
637 NS_LOG_FUNCTION(
this);
645 NS_LOG_FUNCTION(
this);
653 NS_LOG_FUNCTION(
this);
664 NS_LOG_FUNCTION(
this);
671 : m_rx1DrOffsetAck(rx1DrOffsetAck),
672 m_rx2DataRateAck(rx2DataRateAck),
673 m_channelAck(channelAck)
675 NS_LOG_FUNCTION(
this << rx1DrOffsetAck << rx2DataRateAck << channelAck);
684 NS_LOG_FUNCTION_NOARGS();
696 NS_LOG_FUNCTION_NOARGS();
701 uint8_t
byte = start.ReadU8();
713 NS_LOG_FUNCTION_NOARGS();
715 os <<
"RxParamSetupAns" << std::endl;
727 NS_LOG_FUNCTION(
this);
736 NS_LOG_FUNCTION_NOARGS();
745 NS_LOG_FUNCTION_NOARGS();
756 NS_LOG_FUNCTION_NOARGS();
758 os <<
"DevStatusReq" << std::endl;
767 NS_LOG_FUNCTION(
this);
774 : m_battery(battery),
777 NS_LOG_FUNCTION(
this <<
unsigned(battery) <<
unsigned(margin));
786 NS_LOG_FUNCTION_NOARGS();
797 NS_LOG_FUNCTION_NOARGS();
802 m_margin = start.ReadU8() & 0b111111;
810 NS_LOG_FUNCTION_NOARGS();
812 os <<
"DevStatusAns" << std::endl;
813 os <<
"Battery: " << unsigned(
m_battery) << std::endl;
814 os <<
"Margin: " << unsigned(
m_margin) << std::endl;
820 NS_LOG_FUNCTION_NOARGS();
828 NS_LOG_FUNCTION_NOARGS();
839 NS_LOG_FUNCTION(
this);
849 : m_chIndex(chIndex),
850 m_frequency(frequency),
851 m_minDataRate(minDataRate),
852 m_maxDataRate(maxDataRate)
854 NS_LOG_FUNCTION(
this);
863 NS_LOG_FUNCTION_NOARGS();
869 uint32_t encodedFrequency = uint32_t(
m_frequency / 100);
870 start.WriteU8((encodedFrequency & 0xff0000) >> 16);
871 start.WriteU8((encodedFrequency & 0xff00) >> 8);
872 start.WriteU8(encodedFrequency & 0xff);
879 NS_LOG_FUNCTION_NOARGS();
885 uint32_t encodedFrequency = 0;
886 encodedFrequency |= uint32_t(start.ReadU16()) << 8;
887 encodedFrequency |= uint32_t(start.ReadU8());
889 uint8_t dataRateByte = start.ReadU8();
899 NS_LOG_FUNCTION_NOARGS();
901 os <<
"NewChannelReq" << std::endl;
907 NS_LOG_FUNCTION_NOARGS();
915 NS_LOG_FUNCTION_NOARGS();
923 NS_LOG_FUNCTION_NOARGS();
931 NS_LOG_FUNCTION_NOARGS();
942 NS_LOG_FUNCTION(
this);
949 : m_dataRateRangeOk(dataRateRangeOk),
950 m_channelFrequencyOk(channelFrequencyOk)
952 NS_LOG_FUNCTION(
this);
961 NS_LOG_FUNCTION_NOARGS();
972 NS_LOG_FUNCTION_NOARGS();
977 uint8_t
byte = start.ReadU8();
987 NS_LOG_FUNCTION_NOARGS();
989 os <<
"NewChannelAns" << std::endl;
1000 NS_LOG_FUNCTION(
this);
1009 NS_LOG_FUNCTION(
this);
1018 NS_LOG_FUNCTION_NOARGS();
1029 NS_LOG_FUNCTION_NOARGS();
1034 m_delay = start.ReadU8() & 0xf;
1042 NS_LOG_FUNCTION_NOARGS();
1044 os <<
"RxTimingSetupReq" << std::endl;
1050 NS_LOG_FUNCTION(
this);
1065 NS_LOG_FUNCTION(
this);
1074 NS_LOG_FUNCTION_NOARGS();
1083 NS_LOG_FUNCTION_NOARGS();
1094 NS_LOG_FUNCTION_NOARGS();
1096 os <<
"RxTimingSetupAns" << std::endl;
1105 NS_LOG_FUNCTION(
this);
1114 NS_LOG_FUNCTION_NOARGS();
1123 NS_LOG_FUNCTION_NOARGS();
1134 NS_LOG_FUNCTION_NOARGS();
1136 os <<
"DlChannelAns" << std::endl;
1145 NS_LOG_FUNCTION(
this);
1154 NS_LOG_FUNCTION_NOARGS();
1163 NS_LOG_FUNCTION_NOARGS();
1174 NS_LOG_FUNCTION_NOARGS();
1176 os <<
"TxParamSetupReq" << std::endl;
1185 NS_LOG_FUNCTION(
this);
1194 NS_LOG_FUNCTION_NOARGS();
1203 NS_LOG_FUNCTION_NOARGS();
1214 NS_LOG_FUNCTION_NOARGS();
1216 os <<
"TxParamSetupAns" << std::endl;
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
uint8_t GetBattery(void)
Get the battery information contained in this MAC command.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
uint8_t GetMargin(void)
Get the demodulation margin contained in this MAC command.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
double GetMaximumAllowedDutyCycle(void) const
Get the maximum duty cycle prescribed by this Mac command, in fraction form.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
int GetRepetitions(void)
Get the number of repetitions prescribed by this MAC command.
std::list< int > GetEnabledChannelsList(void)
Get the list of enabled channels.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
uint8_t GetTxPower(void)
Get the transmission power prescribed by this MAC command.
uint8_t GetDataRate(void)
Return the data rate prescribed by this MAC command.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
uint8_t GetGwCnt(void) const
Get the gateway count value.
uint8_t GetMargin(void) const
Get the demodulation margin value.
uint8_t m_gwCnt
This MAC command's gateway count value.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
uint8_t m_margin
This MAC command's demodulation margin value.
void SetMargin(uint8_t margin)
Set the demodulation margin value.
void SetGwCnt(uint8_t gwCnt)
Set the gateway count value.
void IncrementGwCnt(void)
Increment this LorawanMacCommand's gwCnt value.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
static uint8_t GetCIDFromLorawanMacCommand(enum MacCommandType commandType)
Get the CID that corresponds to this MAC command.
enum MacCommandType m_commandType
The type of this command.
virtual uint8_t GetSerializedSize(void) const
Get serialized length of this MAC command.
static TypeId GetTypeId(void)
virtual enum MacCommandType GetCommandType(void) const
Get the commandType of this MAC command.
uint8_t m_serializedSize
This MAC command's serialized size.
virtual ~LorawanMacCommand()
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
bool m_channelFrequencyOk
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
double GetFrequency(void)
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
uint8_t GetMinDataRate(void)
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
uint8_t GetChannelIndex(void)
uint8_t GetMaxDataRate(void)
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
double m_frequency
The frequency in Hz
uint8_t GetRx1DrOffset(void)
Get this command's Rx1DrOffset parameter.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
uint8_t GetRx2DataRate(void)
Get this command's Rx2DataRate parameter.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
double GetFrequency(void)
Get this command's frequency.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
Time GetDelay(void)
Get the first window delay as a Time instance.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
virtual void Serialize(Buffer::Iterator &start) const
Serialize the contents of this MAC command into a buffer, according to the LoRaWAN standard.
virtual void Print(std::ostream &os) const
Print the contents of this MAC command in human-readable format.
virtual uint8_t Deserialize(Buffer::Iterator &start)
Deserialize the buffer into a MAC command.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
MacCommandType
Enum for every possible command type.