how to obtain the configured IP Address of a packet instead of the default 102.102.102.102?

122 views
Skip to first unread message

Shey Janota

unread,
May 24, 2023, 6:12:54 PM5/24/23
to ns-3-users
Hello everyone!

I have a scenario with 2 stations and 1 access point. and I'm using two functions to count how many packets were transmitted and received throughout the simulation.

The Ip Address is configured in the function PopulateARPcache()IpAddrrConfig.JPG

The functions to count the Tx and Rx packets are  the following:
simFunctions.JPG

When I ran the simulation the terminal logs are showing the default IP address I don't know why. How can I get the configured IP Address instead of its default value?
Logs.JPG

Can anyone help me with this issue?


Thanks in advance.


Best Regards.

Sheila Janota



Tommaso Pecorella

unread,
May 25, 2023, 5:05:21 AM5/25/23
to ns-3-users
Hi,

to populate the ARP caches you can use the NeighborCacheHelper class - it's there.

About the default IP, it's a sign that you're trying to remove an IP header, but the IP header isn't where you expect it. Maybe you're calling the functions from a callback at MAC level (where the packet does have another header), or from another layer where the IP header has been already removed. Without the full script it's impossible to say.

Shey Janota

unread,
May 25, 2023, 2:40:57 PM5/25/23
to ns-3-users
Hi Tommaso,

Thanks for the reply. In attachment I'm sending the full simulation files. I'm using version ns-3.29

When you have an available time can you please check it?



Best Regards.

Sheila Janota
cw.cc
scenario.h

Tommaso Pecorella

unread,
May 25, 2023, 5:07:13 PM5/25/23
to ns-3-users
udpServer->TraceConnectWithoutContext("Rx", callback);

You're getting the packets from the UdpServer application. The IP header is not there.
You can use the "RxWithAddresses" trace, which does have packet's sender address filled and MIGHT have the destination address filled (it's filled only if the socket was bound to a specific address).

If that trace isn't in your ns-3... upgrade it.

Shey Janota

unread,
May 26, 2023, 11:24:17 AM5/26/23
to ns-3-users
Hi Tommaso,

I made those changes and it's showing different Mac addresses 
udp_setting.JPG
-----------------------------------------------------------
functionRX.JPG
result2.JPG

I set up fixed Mac addresses, and I wanted to view those on the terminal logs, but they are not showing.
MacSetting.JPG

The files I used are in the attachment.

Best Regards.

Sheila Janota

cw_v02.cc
scenario_v02.h

Tommaso Pecorella

unread,
May 26, 2023, 3:46:15 PM5/26/23
to ns-3-users
I'm deeply sorry, but I need to be honest with you.
You can't add code without understanding what you're doing. The chances that you'll get it right are practically zero.

I told you explicitly that the packet does not have the IP address in that trace, because the trace is at the application layer, and the IP address has been removed already. And yet, your code is the following:

void packetRxAddr(Ptr<const Packet> packet, const Address &srcAddress, const Address &destAddress)
{
    std::cout << "RxWithAddresses" << std::endl;
    std::cout << "--------------" << std::endl;
           
    std::cout << "srcAddress: " << srcAddress << std::endl;
    std::cout << "destAddress: " << destAddress << "\n" << std::endl;
   
    // IP Address
    Ipv4Header ipv4Header;
    packet->PeekHeader(ipv4Header);
    std::cout << "Source IP: " << ipv4Header.GetSource() << std::endl;
    std::cout << "Destination IP: " << ipv4Header.GetDestination() << std::endl;
    std::cout << "--------------" << "\n" << std::endl;
   
    // MAC Address
    WifiMacHeader macHeader;      
    packet->PeekHeader (macHeader);
   
    std::cout << "GetAddr1: " << macHeader.GetAddr1() << std::endl;
    std::cout << "GetAddr2: " << macHeader.GetAddr2() << std::endl;
    std::cout << "GetAddr3: " << macHeader.GetAddr3() << std::endl;
    std::cout << "GetAddr4: " << macHeader.GetAddr4() << std::endl;
    std::cout << "--------------" << "\n" << std::endl;
   
   
    g_rxPktNum++;
       
}

The IP addresses are in "srcAddress" and "destAddress", and they can be printed with InetSocketAddress::ConvertFrom(srcAddress).GetIpv4()

About the MAC addresses, perhaps there's a little confusion. Perhaps it should be highlighted better in the manual, so you're (partially) excused. Only partially tho, because it's in the Doxygen page: https://www.nsnam.org/docs/doxygen/d8/df4/classns3_1_1_packet.html#a9b9c770b6b0a9410e58140c6ae5dd731
I guess we need to state it even more clearly tho... You can remove or peek only the 1st header in the packet, NOT the following ones.
Moreover, the function returns a number, and it will be (hopefully) ZERO if the header you're trying to peek or remove is not there.

So... no, not only you didn't get the IP numbers, you kept doing the same mistake. The headers are not there.
And "03-07-c0:a8:01:01:01:0:00" is an InetSocketAddress (only written in a different way). Which is kinda clear if one checks the code of the PacketSink application.

Shey Janota

unread,
May 26, 2023, 5:43:31 PM5/26/23
to ns-3-users
Hi Tommaso,

Thanks for the explanation.

My function looks like this now.
functionRx2.JPG


And the terminal logs show the destAddress as zeros. So this means that this IP address has been removed, right?

result3.JPG

But when I print the srcAddress and the destAddress before converting by using (InetSocketAddress::ConvertFrom(destAddress).GetIpv4()) the destAddress changes.

destAddr.JPG
Should I make a copy of the destAddress before converting so it doesn't be removed?


Best Regards.

Sheila Janota

Tommaso Pecorella

unread,
May 27, 2023, 6:09:31 AM5/27/23
to ns-3-users
Hi Sheila,

sorry but I won't answer your question.
I gave you already enough informations to understand why that address is what it is.
There is a (fairly good) documentation.
You have the code for all the classes.
Hence, you must be able to answer this question by yourself.

Do it, or you'll keep relying on help for the most stupidest thing, and you'll not be able to progress in your work.

Shey Janota

unread,
May 28, 2023, 10:12:59 PM5/28/23
to ns-3-users
It's alright.

Thanks for everything.


Best Regards.

Sheila Janota

Reply all
Reply to author
Forward
0 new messages