Getting the Source IP Address of a packet, while tracing at the Physical Layer

146 views
Skip to first unread message

Cosmos

unread,
Jun 2, 2017, 4:32:35 PM6/2/17
to ns-3-users
Hi everyone,

I am tracing packets at the Physical Layer as follows -

template <int node>
void MonitorRx(Ptr<const Packet> packet, uint16_t channelFreqMhz, uint16_t channelNumber,
        uint32_t rate
, WifiPreamble preamble, WifiTxVector txVector, struct mpduInfo aMpdu
       
,struct signalNoiseDbm signalNoise)
{
   
static long int count = 1;
    std
::stringstream ss;
    ss
<< "SniffRx-"<<node<<".log"; //Node ID (IP = N.ID + 1)
   
static std::fstream f (ss.str().c_str(), std::ios::out);
    f
<< "Packet Number - " << count << ":\n";
    f
<< "Packet Size: " << packet->GetSize() << std::endl;
    f
<< "Channel Number: " << channelNumber << std::endl;
    f
<< "\n";
    count
++;
}

int main()
{
.
.
.
     
Config::ConnectWithoutContext("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/MonitorSnifferRx",MakeCallback(&MonitorRx<0>));
.
.
.
}

Through this scheme, I want to observe the SNR of packets being received at Node 0 (the AP) based on the source IP address of the packet. My question is - how can I extract the source IP address of from 'packet' in the MonitorRx() function? My understanding is that the header at the Physical Layer would have several encapsulated headers, so how do I access the IP header?

Thanks.

Cosmos

unread,
Jun 4, 2017, 12:29:53 PM6/4/17
to ns-3-users
Any ideas?

Thanks.

Rediet

unread,
Jun 6, 2017, 3:20:22 AM6/6/17
to ns-3-users
Hi Cosmos,

If you successively remove header up to IP (WifiMacHeader and LlcSnapHeader, network-module) you should be able to peek the IP header. I don't know if it's very conventional but I just enabled ascii output, noted expected headers (when there is an IP packet encapsulated), and removed them before peeking the IP header (b/c it just looked at the beginning of the buffer).

BR,

Rediet

Varun Reddy

unread,
Aug 26, 2017, 1:13:29 PM8/26/17
to ns-3-users
Hi Rediet,

My query is related to this post, hence I'm posting on this thread. I'm trying to extract the Ipv4Header from the packet -

template <int node>
void MonitorRx(Ptr<const Packet> packet, uint16_t channelFreqMhz, WifiTxVector txVector, struct MpduInfo aMpdu
       
,struct SignalNoiseDbm signalNoise)
{

 
Ptr<Packet> p = packet->Copy();
 
PacketMetadata::ItemIterator i = p->BeginItem ();
 
PacketMetadata::Item item;
 
WifiMacHeader head1;
 
LlcSnapHeader head2;
 
Ipv4Header head3;
  p
->RemoveHeader(head1);
  p
->RemoveHeader(head2);
  p
->PeekHeader(head3);
  std
::cout<<node<<"\t"<<head3.GetSource()<<"\t"<<head3.GetDestination()<<"\n";

However, this isn't working. What am I missing?

Thanks!
Varun

Rediet

unread,
Aug 31, 2017, 3:36:00 AM8/31/17
to ns-3-users
Reply all
Reply to author
Forward
0 new messages