lr-wpan: (fixes !326) Inactive Periods Queue fix

This commit is contained in:
Alberto Gallegos Ramonet
2020-06-09 22:49:43 +09:00
committed by Tom Henderson
parent ca96c28cc9
commit c5c5972c4f
4 changed files with 66 additions and 33 deletions

View File

@@ -416,7 +416,7 @@ LrWpanCsmaCa::CanProceed ()
// The MAC sublayer shall proceed if the remaining CSMA-CA algorithm steps
// can be completed before the end of the CAP.
// See IEEE 802.15.4-2011 (Sections 5.1.1.1 and 5.1.1.4)
// Transaction = 2 CCA + frame transmission (PPDU) + turnaroudtime or Ack time (optional) + IFS
// Transaction = 2 CCA + frame transmission (SHR+PHR+PPDU) + turnaroudtime*2 (Rx->Tx & Tx->Rx) + IFS (LIFS or SIFS) and Ack time (if ack flag true)
transactionSymbols = ccaSymbols + m_mac->GetTxPacketSymbols ();
@@ -427,8 +427,8 @@ LrWpanCsmaCa::CanProceed ()
}
else
{
//time the PHY takes to switch from TX to Rx or Rx to Tx
transactionSymbols += m_mac->GetPhy ()->aTurnaroundTime;
//time the PHY takes to switch from Rx to Tx and Tx to Rx
transactionSymbols += (m_mac->GetPhy ()->aTurnaroundTime *2);
}
transactionSymbols += m_mac->GetIfsSize ();

View File

@@ -632,15 +632,12 @@ LrWpanMac::MlmePollRequest (MlmePollRequestParams params)
{
NS_LOG_FUNCTION (this);
LrWpanMacHeader macHdr (LrWpanMacHeader::LRWPAN_MAC_COMMAND, m_macBsn.GetValue ());
m_macBsn++;
CommandPayloadHeader macPayload (CommandPayloadHeader::DATA_REQ);
Ptr<Packet> beaconPacket = Create <Packet> ();
}
@@ -671,21 +668,16 @@ LrWpanMac::SendOneBeacon ()
macHdr.SetSrcAddrFields (GetPanId (), GetShortAddress ());
}
macHdr.SetSecDisable ();
macHdr.SetNoAckReq ();
macPayload.SetSuperframeSpecField (GetSuperframeField ());
macPayload.SetGtsFields (GetGtsFields ());
macPayload.SetPndAddrFields (GetPendingAddrFields ());
beaconPacket->AddHeader (macPayload);
beaconPacket->AddHeader (macHdr);
// Calculate FCS if the global attribute ChecksumEnable is set.
if (Node::ChecksumEnabled ())
{
@@ -698,14 +690,12 @@ LrWpanMac::SendOneBeacon ()
//Set the Beacon packet to be transmitted
m_txPkt = beaconPacket;
m_outSuperframeStatus = BEACON;
NS_LOG_DEBUG ("Outgoing superframe Active Portion (Beacon + CAP + CFP): " << m_superframeDuration << " symbols");
ChangeMacState (MAC_SENDING);
m_phy->PlmeSetTRXStateRequest (IEEE_802_15_4_PHY_TX_ON);
}
@@ -888,13 +878,13 @@ LrWpanMac::CheckQueue ()
{
NS_LOG_FUNCTION (this);
// Pull a packet from the queue and start sending if we are not already sending.
if (m_lrWpanMacState == MAC_IDLE && !m_txQueue.empty () && m_txPkt == 0 && !m_setMacState.IsRunning ())
if (m_lrWpanMacState == MAC_IDLE && !m_txQueue.empty () && !m_setMacState.IsRunning ())
{
TxQueueElement *txQElement = m_txQueue.front ();
m_txPkt = txQElement->txQPkt;
//TODO: this should check if the node is a coordinator and using the outcoming superframe not just the PAN coordinator
if (m_csmaCa->IsUnSlottedCsmaCa () || (m_outSuperframeStatus == CAP && m_panCoor) || m_incSuperframeStatus == CAP)
{
TxQueueElement *txQElement = m_txQueue.front ();
m_txPkt = txQElement->txQPkt;
m_setMacState = Simulator::ScheduleNow (&LrWpanMac::SetLrWpanMacState, this, MAC_CSMA);
}
}
@@ -1051,11 +1041,9 @@ LrWpanMac::PdDataIndication (uint32_t psduLength, Ptr<Packet> p, uint8_t lqi)
{
case SHORT_ADDR:
params.m_srcAddr = receivedMacHdr.GetShortSrcAddr ();
NS_LOG_DEBUG ("Packet from " << params.m_srcAddr);
break;
case EXT_ADDR:
params.m_srcExtAddr = receivedMacHdr.GetExtSrcAddr ();
NS_LOG_DEBUG ("Packet from " << params.m_srcExtAddr);
break;
default:
break;
@@ -1066,11 +1054,9 @@ LrWpanMac::PdDataIndication (uint32_t psduLength, Ptr<Packet> p, uint8_t lqi)
{
case SHORT_ADDR:
params.m_dstAddr = receivedMacHdr.GetShortDstAddr ();
NS_LOG_DEBUG ("Packet to " << params.m_dstAddr);
break;
case EXT_ADDR:
params.m_dstExtAddr = receivedMacHdr.GetExtDstAddr ();
NS_LOG_DEBUG ("Packet to " << params.m_dstExtAddr);
break;
default:
break;
@@ -1079,6 +1065,17 @@ LrWpanMac::PdDataIndication (uint32_t psduLength, Ptr<Packet> p, uint8_t lqi)
if (m_macPromiscuousMode)
{
//level 2 filtering
if (receivedMacHdr.GetDstAddrMode () == SHORT_ADDR)
{
NS_LOG_DEBUG ("Packet from " << params.m_srcAddr);
NS_LOG_DEBUG ("Packet to " << params.m_dstAddr);
}
else if (receivedMacHdr.GetDstAddrMode () == EXT_ADDR)
{
NS_LOG_DEBUG ("Packet from " << params.m_srcExtAddr);
NS_LOG_DEBUG ("Packet to " << params.m_dstExtAddr);
}
//TODO: Fix here, this should trigger different Indication Callbacks
//depending the type of frame received (data,command, beacon)
if (!m_mcpsDataIndicationCallback.IsNull ())
@@ -1124,12 +1121,18 @@ LrWpanMac::PdDataIndication (uint32_t psduLength, Ptr<Packet> p, uint8_t lqi)
else
{
// multicast
// See RFC 4944, Section 12
// Multicast address 16 bits: 100X XXXX XXXX XXXX
uint8_t buf[2];
receivedMacHdr.GetShortDstAddr ().CopyTo (buf);
if (buf[0] & 0x80)
{
acceptFrame = true;
}
else
{
acceptFrame = false;
}
}
}
@@ -1196,6 +1199,19 @@ LrWpanMac::PdDataIndication (uint32_t psduLength, Ptr<Packet> p, uint8_t lqi)
m_setMacState = Simulator::ScheduleNow (&LrWpanMac::SendAck, this, receivedMacHdr.GetSeqNum ());
}
if (receivedMacHdr.GetDstAddrMode () == SHORT_ADDR)
{
NS_LOG_DEBUG ("Packet from " << params.m_srcAddr);
NS_LOG_DEBUG ("Packet to " << params.m_dstAddr);
}
else if (receivedMacHdr.GetDstAddrMode () == EXT_ADDR)
{
NS_LOG_DEBUG ("Packet from " << params.m_srcExtAddr);
NS_LOG_DEBUG ("Packet to " << params.m_dstExtAddr);
}
if (receivedMacHdr.IsBeacon ())
{
@@ -1208,7 +1224,7 @@ LrWpanMac::PdDataIndication (uint32_t psduLength, Ptr<Packet> p, uint8_t lqi)
// The start of Rx beacon time and start of the Incoming superframe Active Period
m_macBeaconRxTime = Simulator::Now () - Seconds (double(m_rxBeaconSymbols) / symbolRate);
NS_LOG_DEBUG ("Beacon Received (m_macBeaconRxTime: " << m_macBeaconRxTime.As (Time::S) << ")");
NS_LOG_DEBUG ("Beacon Received; forwarding up (m_macBeaconRxTime: " << m_macBeaconRxTime.As (Time::S) << ")");
//TODO: Handle mlme-scan.request here
@@ -1249,15 +1265,11 @@ LrWpanMac::PdDataIndication (uint32_t psduLength, Ptr<Packet> p, uint8_t lqi)
m_csmaCa->SetBatteryLifeExtension (false);
}
if (m_incomingBeaconOrder < 15 && !m_csmaCa->IsSlottedCsmaCa ())
{
m_csmaCa->SetSlottedCsmaCa ();
}
//TODO: get Incoming frame GTS Fields here
NS_LOG_DEBUG ("Incoming superframe Active Portion (Beacon + CAP + CFP): " << m_incomingSuperframeDuration << " symbols");
@@ -1309,15 +1321,13 @@ LrWpanMac::PdDataIndication (uint32_t psduLength, Ptr<Packet> p, uint8_t lqi)
// is in the short address pending list or in the extended address
// pending list.
}
}
}
else if (receivedMacHdr.IsData () && !m_mcpsDataIndicationCallback.IsNull ())
{
// If it is a data frame, push it up the stack.
NS_LOG_DEBUG ("PdDataIndication(): Packet is for me; forwarding up");
NS_LOG_DEBUG ("Data Packet is for me; forwarding up");
m_mcpsDataIndicationCallback (params, p);
}
else if (receivedMacHdr.IsAcknowledgment () && m_txPkt && m_lrWpanMacState == MAC_ACK_PENDING)
@@ -1780,6 +1790,12 @@ LrWpanMac::GetMacMaxFrameRetries (void) const
return m_macMaxFrameRetries;
}
void
LrWpanMac::PrintTransmitQueueSize (void)
{
NS_LOG_DEBUG("Transit Queue Size: "<<m_txQueue.size());
}
void
LrWpanMac::SetMacMaxFrameRetries (uint8_t retries)
{

View File

@@ -908,6 +908,10 @@ public:
* \return the maximum number of retries
*/
uint8_t GetMacMaxFrameRetries (void) const;
/**
* Print the number of elements in the packet transmit queue.
*/
void PrintTransmitQueueSize (void);
/**
* Set the macMaxFrameRetries attribute value.
*

View File

@@ -138,13 +138,13 @@ LrWpanSlottedCsmacaTestCase::TransEndIndication (LrWpanSlottedCsmacaTestCase *te
void
LrWpanSlottedCsmacaTestCase::DataIndicationCoordinator (LrWpanSlottedCsmacaTestCase *testcase, Ptr<LrWpanNetDevice> dev, McpsDataIndicationParams params, Ptr<Packet> p)
{
NS_LOG_UNCOND (Simulator::Now ().GetSeconds () << "s Coordinator Received DATA packet (size " << p->GetSize () << " bytes)");
NS_LOG_UNCOND (Simulator::Now ().As(Time::S) << "s Coordinator Received DATA packet (size " << p->GetSize () << " bytes)");
}
void
LrWpanSlottedCsmacaTestCase::StartConfirm (LrWpanSlottedCsmacaTestCase *testcase, Ptr<LrWpanNetDevice> dev, MlmeStartConfirmParams params)
{
NS_LOG_UNCOND (Simulator::Now ().GetSeconds () << "s Beacon Sent");
NS_LOG_UNCOND (Simulator::Now ().As(Time::S) << "s Beacon Sent");
}
void
@@ -153,7 +153,7 @@ LrWpanSlottedCsmacaTestCase::IncomingSuperframeStatus (LrWpanSlottedCsmacaTestCa
if (newValue == SuperframeStatus::CAP)
{
testcase->m_startCap = Simulator::Now ();
NS_LOG_UNCOND (Simulator::Now ().GetSeconds () << "s Incoming superframe CAP starts");
NS_LOG_UNCOND (Simulator::Now ().As(Time::S) << "s Incoming superframe CAP starts");
}
}
@@ -162,7 +162,7 @@ LrWpanSlottedCsmacaTestCase::TransactionCost (LrWpanSlottedCsmacaTestCase *testc
{
testcase->m_apBoundary = Simulator::Now ();
testcase->m_transCost = trans;
NS_LOG_UNCOND (Simulator::Now ().GetSeconds () << "s Transaction Cost is:" << trans);
NS_LOG_UNCOND (Simulator::Now ().As(Time::S) << "s Transaction Cost is:" << trans);
}
@@ -309,7 +309,20 @@ LrWpanSlottedCsmacaTestCase::DoRun ()
ifsSize = 12;
}
transactionTime = MicroSeconds ((m_transCost - ifsSize) * 1000 * 1000 / symbolRate);
// The transaction cost here includes the ifsSize and the turnAroundTime (Tx->Rx)
// therefore we subtract these before the final comparison
//
// Transmission Start Transmission End
// | |
// +-------+--------------------+--------+------------------------+------+
// | 2 CCA | TurnAround(Rx->Tx)| Data | TurnAround(Tx->Rx) | IFS |
// +-------+--------------------+--------+------------------------+------+
// TODO: This test need some rework to make it more clear
transactionTime = Seconds ((double)(m_transCost-(ifsSize + 12)) / symbolRate);
NS_LOG_UNCOND ("Transmission start time(On a boundary): "<<m_apBoundary.As(Time::S));
NS_LOG_UNCOND ("Transmission End time (McpsData.confirm): "<<m_sentTime.As(Time::S));
NS_TEST_EXPECT_MSG_EQ (m_sentTime,(m_apBoundary + transactionTime),"Error, the transaction time is not the expected value");