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 1 commit
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;

uint8_t 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
160 changes: 145 additions & 15 deletions helper/lora-packet-tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,35 @@ 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));

if(m_packetTracker.count(packet) == 1) //first reception
{
std::map<Ptr<Packet const>, PacketStatus>::iterator it = m_packetTracker.find (packet);
(*it).second.outcomes.insert (std::pair<int, enum PhyPacketOutcome> (gwId,
RECEIVED));
}
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_DEBUG("This is copy " << i <<" of packet "<< packet);
NS_LOG_DEBUG("This packet was sent at " << (*it).second.sendTime);
NS_LOG_DEBUG("It was not yet received by GW " << gwId << " logging it now as RECEIVED.");
(*it).second.outcomes.insert(std::pair<int, enum PhyPacketOutcome> (gwId,
RECEIVED));
}
i++;
}
}
DvdMgr marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -152,9 +178,34 @@ 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));
if(m_packetTracker.count(packet) == 1) //first reception
{
std::map<Ptr<Packet const>, PacketStatus>::iterator it = m_packetTracker.find (packet);
(*it).second.outcomes.insert (std::pair<int, enum PhyPacketOutcome> (gwId,
INTERFERED));
}
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 as INTERFERED.");
(*it).second.outcomes.insert(std::pair<int, enum PhyPacketOutcome> (gwId,
INTERFERED));
}
i++;
}
}
}
}

Expand All @@ -166,9 +217,35 @@ 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));

if(m_packetTracker.count(packet) == 1) //first reception
{
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));
}
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 as NO_MORE_RECEIVERS.");
(*it).second.outcomes.insert(std::pair<int, enum PhyPacketOutcome> (gwId,
NO_MORE_RECEIVERS));
}
i++;
}
}
}
}

Expand All @@ -181,9 +258,34 @@ 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));
if(m_packetTracker.count(packet) == 1) //first reception
{
std::map<Ptr<Packet const>, PacketStatus>::iterator it = m_packetTracker.find (packet);
(*it).second.outcomes.insert (std::pair<int, enum PhyPacketOutcome> (gwId,
UNDER_SENSITIVITY));
}
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 as UNDER_SENSITIVITY.");
(*it).second.outcomes.insert(std::pair<int, enum PhyPacketOutcome> (gwId,
UNDER_SENSITIVITY));
}
i++;
}
}
}
}

Expand All @@ -196,9 +298,34 @@ 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));
if(m_packetTracker.count(packet) == 1) //first reception
{
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));
}
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 as LOST_BECAUSE_TX.");
(*it).second.outcomes.insert(std::pair<int, enum PhyPacketOutcome> (gwId,
LOST_BECAUSE_TX));
}
i++;
}
}
}
}

Expand Down Expand Up @@ -301,6 +428,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
2 changes: 1 addition & 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
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