signetlabdei / lorawan

An ns-3 module for simulation of LoRaWAN networks
GNU General Public License v2.0
190 stars 132 forks source link

Identify ED in downlink packets #40

Closed Fundoprajakta closed 4 years ago

Fundoprajakta commented 5 years ago

Hello,

First I was wondering how to identify recipient node in each downlink packet.

And second how to identify reply packet and request packet pair.

Thanks

DvdMgr commented 5 years ago

Hi! To get the address of the recipient ED from a DL packet, you can follow these steps:

In short, this can be accomplished with this code:

  LoraMacHeader mHdr;
  LoraFrameHeader fHdr;
  fHdr.SetAsDownlink ();
  Ptr<Packet> myPacket = packet->Copy ();
  myPacket->RemoveHeader (mHdr);
  myPacket->RemoveHeader (fHdr);
  LoraDeviceAddress address = fHdr.GetAddress ();

As for identifying reply packet and request packet pairs, you can try matching sender addresses with the address you find with the code above.

Fundoprajakta commented 5 years ago

Hello !

Thanks for replying to the query. I will try this and respond to you.

I would like to know one more. The packet tracker m_packettracker defined in lora-packetracker.cc/h contains all packets? Both downlink packets and uplink packets?

DvdMgr commented 5 years ago

The packet tracker only saves the uplink packets. The LoraPacketTracker::m_reTransmissionTracker structure, however, contains a flag indicating success of MAC packets, based on whether an ACK was correctly received in at least one of the transmission attempts.

Fundoprajakta commented 5 years ago

The idea is to get ratio of number of downlink packets sent by network server to number of packets received by end devices. m_reTramsmissionTracker can be helpful in this goal?

DvdMgr commented 5 years ago

If you want PHY level statistics, I think you are better off connecting to the trace sources, and keeping the count yourself. For instance, you can connect to the StartSending trace source at the GWs, and to the ReceivedPacket trace source at the EDs. Both trace sources are provided by the LoraPhy class, which is the base for both SimpleGatewayLoraPhy and SimpleEndDeviceLoraPhy. Once you hook those trace sources to your functions, you can update your own counters and get the ratio you need at the end of the simulation.

Fundoprajakta commented 5 years ago

Hello, I tried to create a PhyPacketData similar to m_packetTracker to record downlink packet. Unfortunately it is not recording any packets. below is the short code. Please let me know where I am making mistake.

`void LoraPacketTracker::TransmissionCallbackDownlink (Ptr packet, uint32_t gwId) { Ptr packetCopy = packet->Copy (); LoraMacHeader mHdr; packetCopy->RemoveHeader (mHdr); if (!mHdr.IsUplink ()) { NS_LOG_INFO ("PHY packet " << packet << " was transmitted by gateway " << gwId); // Create a packetStatus PacketStatusDownlink status; status.packetDownlink = packet; status.Downlink= Simulator::Now (); status.senderIdDownlink = gwId;

  m_packetTrackerDownlink.insert (std::pair<Ptr<Packet const>, PacketStatusDownlink> (packet, status));
}

}`

P.S : I also connected StartSending Trace source in lora-helper.cc which directs to call back TransmissionCallbackDownlink().

Thanks

DvdMgr commented 5 years ago

Hi! Can you fork the lorawan repository and upload these changes to a branch on your own fork? This would make it significantly easier for me to check out your changes!

Fundoprajakta commented 5 years ago

Hello! Sure! I will do this now. Also I created a method to calculate PER for each node. I would appreciate, if you have a look on it and provide feedback. It works fine for my purpose.

Fundoprajakta commented 5 years ago

Hello! I have forked the lorawan repository and uploaded the changes. Please check the adr branch : lora-helper.cc/h and lora-packet-tracker.cc/h file and let me know your feedback.

Thanks!

DvdMgr commented 5 years ago

I'm sorry for the delay - I now have some time to check this out, is this still an issue?

Fundoprajakta commented 5 years ago

Hello Thanks for responding. Yes I am still working to capture downlink packets

DvdMgr commented 5 years ago

I checked out the code on your adr branch and it doesn't seem to compile - can you confirm this?

Fundoprajakta commented 5 years ago

Hello!

I will check once again the repository and upload the if anyfile is missing.

Prajakta Lokhande

On 29-Oct-2019, at 11:46 AM, Davide Magrin notifications@github.com wrote:

 I checked out the code on your adr branch and it doesn't seem to compile - can you confirm this?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

Fundoprajakta commented 5 years ago

Hello, I checked the repository and corrected my error. I tried to run it again and it is comping now.

At the end of the complete-network-example.cc , include a line to see if the function for tracking downlink packet is working. It is still not working. It is displaying tracker size 0.

below is picture image

Thanks

DvdMgr commented 5 years ago

It looks like the EDs in your simulation weren't requesting ACKs, so no DL messages were being sent by the GW! Adding the following line in the simulation script seems to fix the issue:

Config::SetDefault ("ns3::EndDeviceLoraMac::MType", EnumValue(LoraMacHeader::CONFIRMED_DATA_UP));

Also, I had to correct line 147 in the complete-network-example to make it compile, here's the corrected line: helper.EnablePacketTrackingDownlink ();

Prapi123 commented 5 years ago

Hello, Thanks for your time and efforts to look into the matter.

I added the line in complete-network-example to test and got below error image

later I tried to change Mtype by accessing EndDevice Mac layer with following code below, `for (NodeContainer::Iterator j = endDevices.Begin (); j != endDevices.End (); ++j) { Ptr node = *j; Ptr loraNetDevice = node->GetDevice (0)->GetObject (); Ptr phy = loraNetDevice->GetPhy ();

  Ptr<LoraMac> mac = loraNetDevice->GetMac ();
  Ptr<EndDeviceLoraMac> edLoraMac = mac->GetObject<EndDeviceLoraMac> ();
  edLoraMac->SetMType (LoraMacHeader::CONFIRMED_DATA_UP);

}`

for this I got this error, image

running it under gdb has the following results. image

I made only the changes suggested by you and nothing else.

Please help me out if you know what mistake I am making.

Regards

DvdMgr commented 5 years ago

Strange, I don't get that error at all. I inserted the

Config::SetDefault ("ns3::EndDeviceLoraMac::MType", EnumValue (LoraMacHeader::CONFIRMED_DATA_UP));

line right after the CommandLine.Parse, can you try that?

Prapi123 commented 5 years ago

Hello,

I tried it, It still gives the same error as above.

Is it because of my changes in lora-helper.cc and lora-helper.h?

DvdMgr commented 5 years ago

I added the line on the adr branch on your repository (last change was 1 hour ago), so I should have the same code as you. Are you sure you don't have any other changes locally?

Prapi123 commented 5 years ago

I have master-branch repository on my local machine , only four files are different in this repository they are lora-helper.cc , lora-helper.h, lora-packet-tracker.cc, lora-packet-tracker.h. These files are from adr-branch. which are exactly the same as in my repository.

Prapi123 commented 5 years ago

There is also one other issue, I just identified, when I used only adr-branch repository and tried to run test, it says the test is failed. Previously I had master repository and 4 file that I mentioned before were from adr-branch.

DvdMgr commented 5 years ago

Regarding the test failures, this was because the wrong interference matrix was used - if you rebase on the latest changes, it should all work!

Prapi123 commented 4 years ago

Hello,

This issue is resolved and the methods created works fine for me. You can close this issue if you want.

I faced one issue while creating a method for downlink packets. When I extracting address of endDevices. with the code below

for (NodeContainer::Iterator j = endDevices.Begin (); j != endDevices.End (); ++j) { Ptr<Node> node = *j; Ptr<LoraNetDevice> loraNetDevice = node->GetDevice (0)->GetObject<LoraNetDevice> (); Ptr<LoraMac> mac = loraNetDevice->GetMac (); Ptr<EndDeviceLoraMac> edLoraMac = mac->GetObject<EndDeviceLoraMac> (); LoraDeviceAddress edAddress = edLoraMac->GetDeviceAddress (); } it worked only before Simulator::Run (); Simulator::Destroy ();

when the above piece of code was placed after Simulator::Run (); Simulator::Destroy ();

it gave error as image

That is why there was some difficulties creating methods in lora-packet-tracker for downlink packet. If possible, can you please explain me why this is happening.

Thanks

DvdMgr commented 4 years ago

Have you tried putting the code before Simulator::Destroy ()?