Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving NbTrans support for class A #114

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions examples/complete-network-example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ bool realisticChannelModel = false;

int appPeriodSeconds = 600;

int numberOfTransmissions = 1; // The maximum number of transmissions allowed, valid is [1:15]

// Output control
bool print = true;

Expand Down Expand Up @@ -87,6 +89,10 @@ main (int argc, char *argv[])
// LogComponentEnable("NetworkStatus", LOG_LEVEL_ALL);
// LogComponentEnable("NetworkController", LOG_LEVEL_ALL);

LogComponentEnableAll (LOG_PREFIX_FUNC);
LogComponentEnableAll (LOG_PREFIX_NODE);
LogComponentEnableAll (LOG_PREFIX_TIME);

/***********
* Setup *
***********/
Expand Down Expand Up @@ -190,6 +196,10 @@ main (int argc, char *argv[])
Ptr<Node> node = *j;
Ptr<LoraNetDevice> loraNetDevice = node->GetDevice (0)->GetObject<LoraNetDevice> ();
Ptr<LoraPhy> phy = loraNetDevice->GetPhy ();

Ptr<LorawanMac> edMac = loraNetDevice->GetMac ();
Ptr<ClassAEndDeviceLorawanMac> edLorawanMac = edMac->GetObject<ClassAEndDeviceLorawanMac> ();
edLorawanMac->SetMaxNumberOfTransmissions (numberOfTransmissions);
}

/*********************
Expand Down
60 changes: 45 additions & 15 deletions helper/lora-packet-tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ LoraPacketTracker::PacketReceptionCallback (Ptr<Packet const> packet, uint32_t g
<< " was successfully received at gateway "
<< gwId);

std::map<Ptr<Packet const>, PacketStatus>::iterator it = m_packetTracker.find (packet);
(*it).second.outcomes.insert (std::pair<int, enum PhyPacketOutcome> (gwId,
RECEIVED));
SetPacketOutcome(packet, std::pair<int, enum PhyPacketOutcome> (gwId,RECEIVED));
}
}

Expand All @@ -152,9 +150,7 @@ LoraPacketTracker::InterferenceCallback (Ptr<Packet const> packet, uint32_t gwId
<< " was interfered at gateway "
<< gwId);

std::map<Ptr<Packet const>, PacketStatus>::iterator it = m_packetTracker.find (packet);
(*it).second.outcomes.insert (std::pair<int, enum PhyPacketOutcome> (gwId,
INTERFERED));
SetPacketOutcome(packet, std::pair<int, enum PhyPacketOutcome> (gwId,INTERFERED));
}
}

Expand All @@ -166,9 +162,8 @@ LoraPacketTracker::NoMoreReceiversCallback (Ptr<Packet const> packet, uint32_t g
NS_LOG_INFO ("PHY packet " << packet
<< " was lost because no more receivers at gateway "
<< gwId);
std::map<Ptr<Packet const>, PacketStatus>::iterator it = m_packetTracker.find (packet);
(*it).second.outcomes.insert (std::pair<int, enum PhyPacketOutcome> (gwId,
NO_MORE_RECEIVERS));

SetPacketOutcome(packet, std::pair<int, enum PhyPacketOutcome> (gwId,NO_MORE_RECEIVERS));
}
}

Expand All @@ -181,9 +176,7 @@ LoraPacketTracker::UnderSensitivityCallback (Ptr<Packet const> packet, uint32_t
<< " was lost because under sensitivity at gateway "
<< gwId);

std::map<Ptr<Packet const>, PacketStatus>::iterator it = m_packetTracker.find (packet);
(*it).second.outcomes.insert (std::pair<int, enum PhyPacketOutcome> (gwId,
UNDER_SENSITIVITY));
SetPacketOutcome(packet, std::pair<int, enum PhyPacketOutcome> (gwId,UNDER_SENSITIVITY));
}
}

Expand All @@ -196,12 +189,46 @@ LoraPacketTracker::LostBecauseTxCallback (Ptr<Packet const> packet, uint32_t gwI
<< " was lost because of GW transmission at gateway "
<< gwId);

std::map<Ptr<Packet const>, PacketStatus>::iterator it = m_packetTracker.find (packet);
(*it).second.outcomes.insert (std::pair<int, enum PhyPacketOutcome> (gwId,
LOST_BECAUSE_TX));
SetPacketOutcome(packet, std::pair<int, enum PhyPacketOutcome> (gwId, LOST_BECAUSE_TX));
}
}

void
LoraPacketTracker::SetPacketOutcome(Ptr<Packet const> packet, std::pair<int, enum PhyPacketOutcome> outcome)
{
NS_LOG_FUNCTION (this);

uint32_t gwId = outcome.first;

if(m_packetTracker.count(packet) == 1) //first reception
{
std::map<Ptr<Packet const>, PacketStatus>::iterator it = m_packetTracker.find (packet);
(*it).second.outcomes.insert (outcome);
}
else
{
std::pair <std::multimap<Ptr<Packet const>, PacketStatus>::iterator, std::multimap<Ptr<Packet const>, PacketStatus>::iterator> ret;
ret = m_packetTracker.equal_range(packet); // find all instances of received packet

int i = 1;

//loop through all instances and find the one which doesn't yet have an outcome at this gateway
for(std::multimap<Ptr<Packet const>, PacketStatus>::iterator it=ret.first; it != ret.second; ++it)
{

if((*it).second.outcomes.find(gwId) == (*it).second.outcomes.end())
{
NS_LOG_INFO("This is copy " << i <<" of packet "<< packet);
NS_LOG_INFO("This packet was sent at " << (*it).second.sendTime);
NS_LOG_INFO("It was not yet received by GW " << gwId << " logging it now with outcome " << outcome.second);
(*it).second.outcomes.insert(outcome);
}
i++;
}
}

}

bool
LoraPacketTracker::IsUplink (Ptr<Packet const> packet)
{
Expand Down Expand Up @@ -301,6 +328,9 @@ LoraPacketTracker::PrintPhyPacketsPerGw (Time startTime, Time stopTime,
NS_LOG_DEBUG ("This packet was received by " <<
(*itPhy).second.outcomes.size () << " gateways");

if((*itPhy).second.outcomes.find(gwId) != (*itPhy).second.outcomes.end())
NS_LOG_DEBUG ("Packet outcome:" << (*itPhy).second.outcomes.at(gwId));

if ((*itPhy).second.outcomes.count (gwId) > 0)
{
switch ((*itPhy).second.outcomes.at (gwId))
Expand Down
6 changes: 5 additions & 1 deletion helper/lora-packet-tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct RetransmissionStatus
};

typedef std::map<Ptr<Packet const>, MacPacketStatus> MacPacketData;
typedef std::map<Ptr<Packet const>, PacketStatus> PhyPacketData;
typedef std::multimap<Ptr<Packet const>, PacketStatus> PhyPacketData;
JacoTuks marked this conversation as resolved.
Show resolved Hide resolved
typedef std::map<Ptr<Packet const>, RetransmissionStatus> RetransmissionData;


Expand Down Expand Up @@ -107,6 +107,10 @@ class LoraPacketTracker
// macPacketTracker, RetransmissionData reTransmissionTracker,
// PhyPacketData packetTracker);

/*
* Sets a packet's outcome at a specified gateway to one of PhyPacketOutcome's values.
*/
void SetPacketOutcome(Ptr<Packet const> packet, std::pair<int, enum PhyPacketOutcome> outcome);
/**
* Count packets to evaluate the performance at PHY level of a specific
* gateway.
Expand Down
98 changes: 59 additions & 39 deletions model/class-a-end-device-lorawan-mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,18 @@ ClassAEndDeviceLorawanMac::Receive (Ptr<Packet const> packet)
// packet in the second receive window and finding out, after the
// fact, that the packet is not for us. In either case, if we no
// longer have any retransmissions left, we declare failure.
if (m_retxParams.waitingAck && m_secondReceiveWindow.IsExpired ())
if (m_secondReceiveWindow.IsExpired ())
{
if (m_retxParams.retxLeft == 0)
{
uint8_t txs = m_maxNumbTx - (m_retxParams.retxLeft);
m_requiredTxCallback (txs, false, m_retxParams.firstAttempt, m_retxParams.packet);
NS_LOG_DEBUG ("Failure: no more retransmissions left. Used " << unsigned(txs) << " transmissions.");
if(m_retxParams.waitingAck)
{
m_requiredTxCallback (txs, false, m_retxParams.firstAttempt, m_retxParams.packet);
NS_LOG_DEBUG ("Failure: no more retransmissions left for confirmed packet. Used " << unsigned(txs) << " transmissions.");
}
else if(m_retxParams.sendingMultipleUnconfirmed)
NS_LOG_DEBUG ("Failure: no more retransmissions left for unconfirmed packet. Used " << unsigned(txs) << " transmissions.");

// Reset retransmission parameters
resetRetransmissionParameters ();
Expand All @@ -214,7 +219,7 @@ ClassAEndDeviceLorawanMac::Receive (Ptr<Packet const> packet)
}
}
}
else if (m_retxParams.waitingAck && m_secondReceiveWindow.IsExpired ())
else if (m_secondReceiveWindow.IsExpired ())
{
NS_LOG_INFO ("The packet we are receiving is in uplink.");
if (m_retxParams.retxLeft > 0)
Expand All @@ -225,8 +230,14 @@ ClassAEndDeviceLorawanMac::Receive (Ptr<Packet const> packet)
else
{
uint8_t txs = m_maxNumbTx - (m_retxParams.retxLeft);
m_requiredTxCallback (txs, false, m_retxParams.firstAttempt, m_retxParams.packet);
NS_LOG_DEBUG ("Failure: no more retransmissions left. Used " << unsigned(txs) << " transmissions.");
if(m_retxParams.waitingAck)
{

m_requiredTxCallback (txs, false, m_retxParams.firstAttempt, m_retxParams.packet);
NS_LOG_DEBUG ("Failure: no more retransmissions left for confirmed packet. Used " << unsigned(txs) << " transmissions.");
}
else if (m_retxParams.sendingMultipleUnconfirmed)
NS_LOG_DEBUG ("Failure: no more retransmissions left for unconfirmed packet. Used " << unsigned(txs) << " transmissions.");

// Reset retransmission parameters
resetRetransmissionParameters ();
Expand All @@ -244,7 +255,7 @@ ClassAEndDeviceLorawanMac::FailedReception (Ptr<Packet const> packet)
// Switch to sleep after a failed reception
m_phy->GetObject<EndDeviceLoraPhy> ()->SwitchToSleep ();

if (m_secondReceiveWindow.IsExpired () && m_retxParams.waitingAck)
if (m_secondReceiveWindow.IsExpired ())
{
if (m_retxParams.retxLeft > 0)
{
Expand All @@ -254,8 +265,15 @@ ClassAEndDeviceLorawanMac::FailedReception (Ptr<Packet const> packet)
else
{
uint8_t txs = m_maxNumbTx - (m_retxParams.retxLeft);
m_requiredTxCallback (txs, false, m_retxParams.firstAttempt, m_retxParams.packet);
NS_LOG_DEBUG ("Failure: no more retransmissions left. Used " << unsigned(txs) << " transmissions.");
if( m_retxParams.waitingAck)
{

m_requiredTxCallback (txs, false, m_retxParams.firstAttempt, m_retxParams.packet);
NS_LOG_DEBUG ("Failure: no more retransmissions left for confirmed packet. Used " << unsigned(txs) << " transmissions.");
}
else if(m_retxParams.sendingMultipleUnconfirmed)
NS_LOG_DEBUG ("Failure: no more retransmissions left for unconfirmed packet. Used " << unsigned(txs) << " transmissions.");


// Reset retransmission parameters
resetRetransmissionParameters ();
Expand Down Expand Up @@ -405,40 +423,42 @@ ClassAEndDeviceLorawanMac::CloseSecondReceiveWindow (void)
break;
}

if (m_retxParams.waitingAck)
{
NS_LOG_DEBUG ("No reception initiated by PHY: rescheduling transmission.");
if (m_retxParams.retxLeft > 0 )
{
NS_LOG_INFO ("We have " << unsigned(m_retxParams.retxLeft) << " retransmissions left: rescheduling transmission.");
this->Send (m_retxParams.packet);
}

else if (m_retxParams.retxLeft == 0 && m_phy->GetObject<EndDeviceLoraPhy> ()->GetState () != EndDeviceLoraPhy::RX)
{
uint8_t txs = m_maxNumbTx - (m_retxParams.retxLeft);
m_requiredTxCallback (txs, false, m_retxParams.firstAttempt, m_retxParams.packet);
NS_LOG_DEBUG ("Failure: no more retransmissions left. Used " << unsigned(txs) << " transmissions.");

// Reset retransmission parameters
resetRetransmissionParameters ();
}
if (m_retxParams.retxLeft > 0 )
{
if(m_retxParams.waitingAck)
NS_LOG_DEBUG ("No reception initiated by PHY: rescheduling transmission of confirmed packet.");

else
{
NS_ABORT_MSG ("The number of retransmissions left is negative ! ");
}
}
else
{
uint8_t txs = m_maxNumbTx - (m_retxParams.retxLeft );
m_requiredTxCallback (txs, true, m_retxParams.firstAttempt, m_retxParams.packet);
NS_LOG_INFO ("We have " << unsigned(m_retxParams.retxLeft) <<
" transmissions left. We were not transmitting confirmed messages.");
if(m_retxParams.sendingMultipleUnconfirmed)
NS_LOG_DEBUG ("No reception initiated by PHY: rescheduling transmission of unconfirmed packet.");

NS_LOG_INFO ("We have " << unsigned(m_retxParams.retxLeft) << " retransmissions left: rescheduling transmission.");

// Reset retransmission parameters
resetRetransmissionParameters ();
}
this->Send (m_retxParams.packet);
}

else if (m_retxParams.retxLeft == 0 && m_phy->GetObject<EndDeviceLoraPhy> ()->GetState () != EndDeviceLoraPhy::RX)
{

uint8_t txs = m_maxNumbTx - (m_retxParams.retxLeft);
if(m_retxParams.waitingAck)
{

m_requiredTxCallback (txs, false, m_retxParams.firstAttempt, m_retxParams.packet);
NS_LOG_DEBUG ("Failure: no more retransmissions left for confirmed packet. Used " << unsigned(txs) << " transmissions.");
}
else if (m_retxParams.sendingMultipleUnconfirmed)
NS_LOG_DEBUG ("Finished: no more retransmissions left for unconfirmed packet. Used " << unsigned(txs) << " transmissions.");

// Reset retransmission parameters
resetRetransmissionParameters ();
}

else
{
NS_ABORT_MSG ("The number of retransmissions left is negative ! ");
}
}

/////////////////////////
Expand Down
Loading