signetlabdei / lorawan

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

Unable to read LoraFrameHeader for uplink messages (using gw mac) #159

Closed phanijsp closed 5 months ago

phanijsp commented 5 months ago

Trying to get address of ED in gateway-lorawan-mac.cc when GW receives an uplink message. Below screenshot shows the changes I have made to the GW mac. gw-mac-changes

I have captured the below log before the deserialize method of LoraFrameHeader throws errors and gets stuck in a loop. Please note that there is only 1 ED and 1 GW in this simulation. So the packet being serialized and deserialized in the log are the same. difference

Screenshot of the error: loop

Specifications

non-det-alle commented 5 months ago

Hello, you get the error because you are trying to remove the frame header without removing the mac header beforehand. As you see in your first screenshot, the mac header is only peeked - not removed - so when you call RemoveHeader ns-3 looks for the byte structure of a frame header but finds the bytes of the mac header instead. Try with something like:

        Ptr<Packet> secondPacketCopy = packet->Copy();
        LorawanMacHeader tmpMacHdr;
        secondPacketCopy->RemoveHeader(tmpMacHdr);
        LoraFrameHeader frameHdr;
        frameHdr.SetAsUplink();
        secondPacketCopy->RemoveHeader(frameHdr);

Here I'm making another copy of the Packet to avoid modifying it if you want to preserve the original one which goes into the packet tracker.

phanijsp commented 5 months ago

Thank you, that worked.