Difference Between FdNetDevice and TapFdNetDevice

292 views
Skip to first unread message

Muhammad Nauman Chattha

unread,
Jun 15, 2022, 7:43:52 AM6/15/22
to ns-3-users
I modified the FdPing example. I replaced the ping application with an upd socket to the server and a function with send packet. (Blue node in the diagram). It's working fine. 
I noticed it created 1 tap interface with 10.0.0.1 and 10.0.0.2 for the actual application.

options.jpg

Now I want to extend this topology with multiple nodes with client applications installed. 

While doing this I had some issues with understanding the difference between the FdNetDevice and TapFdNetDevice.

I am not sure how to extend the topology? do I need to create a tap interface for all the nodes separately? (Which doesn't seem right) . As in the tap-Bridge example, they used one tap for multiple nodes.

Can you please guide and explain how these two work and the difference between them? and what can the correct approach to extend the topology?

Regards
Nauman

Tom Henderson

unread,
Jun 17, 2022, 4:08:27 PM6/17/22
to ns-3-...@googlegroups.com
On 6/15/22 04:43, Muhammad Nauman Chattha wrote:
I modified the FdPing example. I replaced the ping application with an upd socket to the server and a function with send packet. (Blue node in the diagram). It's working fine. 
I noticed it created 1 tap interface with 10.0.0.1 and 10.0.0.2 for the actual application.

options.jpg

Now I want to extend this topology with multiple nodes with client applications installed. 

While doing this I had some issues with understanding the difference between the FdNetDevice and TapFdNetDevice.


The FdNetDevice is a generic device that allows ns-3 to read/write packets to and from a file descriptor.  To ns-3, this looks like a NetDevice.  However, unlike other NetDevice types, it is not hooked to a physical layer model but instead to a file descriptor.

A file descriptor can be associated with a real device, such as your Ethernet device (e.g., 'eth0').  With this kind of binding, you can send/receive frames from the real device (to hook ns-3 up with the outside world). The EmuFdNetDevice helper class can manage this binding.

A tap device is a special virtual network device-- it is not associated to any real hardware device.  However, it can be bridged to other (virtual or real) network devices using a Linux bridge.  In ns-3, it can be bridged

In general, if you want a real application or container or Linux network namespace to run "on top of" an ns-3 network (like a Wi-Fi network), you would use a TapBridge device to bridge to an ns-3 NetDevice.

In general, if you want ns-3 applications to run "on top of" a real network, you would use the EmuFdNetDevice helper to associate a FdNetDevice with a real underlying physical device.

So, one way to think of the difference is that they are kind of the inverse of one another, depending on whether you want ns-3 to be providing the higher layers (Emu) or the lower layers (TapBridge).

So, if you want real applications to be sending into the ns-3 simulation from multiple vantage points, you would need to create multiple TapBridge devices and associate each one of these with a distinct ns-3 NetDevice.

Hope this helps,

Tom



I am not sure how to extend the topology? do I need to create a tap interface for all the nodes separately? (Which doesn't seem right) . As in the tap-Bridge example, they used one tap for multiple nodes.

Can you please guide and explain how these two work and the difference between them? and what can the correct approach to extend the topology?

Regards
Nauman
--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/c5051a50-25aa-434a-b624-f78e4c6a5077n%40googlegroups.com.


Rabia Saleh

unread,
Jun 18, 2022, 3:26:19 PM6/18/22
to ns-3-users
Hi Tom

> if you want real applications to be sending into the ns-3 simulation from multiple vantage points, you would need to create multiple TapBridge devices and associate each one of these with a distinct ns-3 NetDevice.

I use multiple TapBridge devices and associate each one to Ns3 node, but this will not work with multi-hop wireless networks, it will work in single-hop only as this problem mentions there https://groups.google.com/g/ns-3-users/c/RZ-jR90NVNA/m/jmkwTQ3bs-EJ
this problem needs more work in NS3 side. I am also searching for a solution for it.

Tom Henderson

unread,
Jun 18, 2022, 6:16:26 PM6/18/22
to ns-3-...@googlegroups.com, Rabia Saleh
On 6/18/22 12:26, Rabia Saleh wrote:
> Hi Tom
>
> > if you want real applications to be sending into the ns-3 simulation
> from multiple vantage points, you would need to create multiple
> TapBridge devices and associate each one of these with a distinct ns-3
> NetDevice.
>
> I use multiple TapBridge devices and associate each one to Ns3 node, but
> this will not work with multi-hop wireless networks, it will work in
> single-hop only as this problem mentions
> there https://groups.google.com/g/ns-3-users/c/RZ-jR90NVNA/m/jmkwTQ3bs-EJ
> this problem needs more work in NS3 side. I am also searching for a
> solution for it.

I read that old message. I agree that ARP will not work on a MANET but
I am not sure whether it is a TapBridge problem or just an address
configuration problem. In MANET, I believe that the network (for IPv4)
should be configured with /32 addresses, and there should not be any
ARP. Can you try to configure it that way?

- Tom
Message has been deleted

Vadim Hapanchak

unread,
Jun 20, 2022, 4:42:01 AM6/20/22
to ns-3-users
Take a look at this presentation, it might be useful for your case. 

суббота, 18 июня 2022 г. в 23:35:51 UTC+1, rabiasa...@gmail.com:
Hi Tom
Many thanks for your reply, I use docker container and LXC and give the containers IP address (eth0)  outside the ns-3 script. My topology is like the below graph (use docker container). In this scenario only single-hop works. I have tried to run a routing protocol in ns3 script but it does not work.  In this case, I think I can not stop ARP because the TAP device works in L2.
 
gragh3.png

Muhammad Nauman Chattha

unread,
Jul 22, 2022, 3:25:59 PM7/22/22
to ns-3-users
Hi Tom,

Thanks a lot for the clarification. I think EMU would be more appropriate for my use case. 
Anyhow, I am trying with EMU now but I am unable to ping the devices. I made changes to the emu ping example.  here is the code: 

#include "ns3/abort.h"
#include "ns3/core-module.h"
#include "ns3/internet-module.h"
#include "ns3/network-module.h"
#include "ns3/fd-net-device-module.h"
#include "ns3/internet-apps-module.h"
#include "ns3/ipv4-static-routing-helper.h"
#include "ns3/ipv4-list-routing-helper.h"

using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("PingEmulationExample");

static void
PingRtt (std::string context, Time rtt)
{
NS_LOG_UNCOND ("Received Response with RTT = " << rtt);
}

int
main (int argc, char *argv[])
{
NS_LOG_INFO ("Ping Emulation Example");

std::string deviceName ("enp0s25");
std::string remote ("10.0.0.1");
std::string localAddress ("192.168.0.100");
std::string localGateway ("0.0.0.0");
std::string emuMode ("raw");

Ipv4Address remoteIp (remote.c_str ());
Ipv4Address localIp (localAddress.c_str ());
NS_ABORT_MSG_IF (localIp == "1.2.3.4", "You must change the local IP address before running this example");

Ipv4Mask localMask ("255.255.255.0");

GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl"));

GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));


NS_LOG_INFO ("Create Node");
Ptr<Node> node = CreateObject<Node> ();

NS_LOG_INFO ("Create Device");

EmuFdNetDeviceHelper* helper = new EmuFdNetDeviceHelper;
helper->SetDeviceName(deviceName);

NetDeviceContainer devices = helper->Install (node);
Ptr<NetDevice> device = devices.Get (0);
device->SetAttribute ("Address", Mac48AddressValue (Mac48Address::Allocate ()));

//
// Add a default internet stack to the node. This gets us the ns-3 versions
// of ARP, IPv4, ICMP, UDP and TCP.
//
NS_LOG_INFO ("Add Internet Stack");
InternetStackHelper internetStackHelper;
internetStackHelper.Install (node);

NS_LOG_INFO ("Create IPv4 Interface");
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
uint32_t interface = ipv4->AddInterface (device);
Ipv4InterfaceAddress address = Ipv4InterfaceAddress (localIp, localMask);
ipv4->AddAddress (interface, address);
ipv4->SetMetric (interface, 1);
ipv4->SetUp (interface);

Ipv4Address gateway (localGateway.c_str ());
NS_ABORT_MSG_IF (gateway == "1.2.3.4", "You must change the gateway IP address before running this example");

Ipv4StaticRoutingHelper ipv4RoutingHelper;
Ptr<Ipv4StaticRouting> staticRouting = ipv4RoutingHelper.GetStaticRouting (ipv4);
staticRouting->SetDefaultRoute (gateway, interface);


NS_LOG_INFO ("Create V4Ping Appliation");
Ptr<V4Ping> app = CreateObject<V4Ping> ();
app->SetAttribute ("Remote", Ipv4AddressValue (remoteIp));
app->SetAttribute ("Verbose", BooleanValue (true) );
node->AddApplication (app);
app->SetStartTime (Seconds (1.0));
app->SetStopTime (Seconds (22.0));

//
// Give the application a name. This makes life much easier when constructing
// config paths.
//
Names::Add ("app", app);

//
// Hook a trace to print something when the response comes back.
//
Config::Connect ("/Names/app/Rtt", MakeCallback (&PingRtt));

//
// Enable a promiscuous pcap trace to see what is coming and going on our device.
//
helper->EnablePcap (emuMode + "-emu-ping", device, true);

//
// Now, do the actual emulation.
//
NS_LOG_INFO ("Run Emulation in " << emuMode << " mode.");
Simulator::Stop (Seconds (23.0));
Simulator::Run ();
Simulator::Destroy ();
delete helper;
NS_LOG_INFO ("Done.");
}

can you please pointout if i am missing something?

Tom Henderson

unread,
Jul 22, 2022, 4:31:43 PM7/22/22
to ns-3-...@googlegroups.com, Muhammad Nauman Chattha
On 7/22/22 12:25, Muhammad Nauman Chattha wrote:
> Hi Tom,
>
> Thanks a lot for the clarification. I think EMU would be more
> appropriate for my use case.
> Anyhow, I am trying with EMU now but I am unable to ping the devices. I
> made changes to the emu ping example.  here is the code:

It looks like you are trying to ping host 10.0.0.1 from host
192.168.0.100 (the ns-3 machine). Do you have a route to that network
on 192.168.0.100 and also on all the intervening routers? Is there a
route on 10.0.0.1 back to 192.168.0.100?

To debug this, check using tcpdump that packets are leaving the source,
then that packets are arriving on the router, then leaving the router,
etc. In other words, use tcpdump on each interface involved, to find
where the problem is.

- Tom
> <https://www.youtube.com/watch?v=rurAMkuWgaY>, it might be useful
> for your case.
>
> суббота, 18 июня 2022 г. в 23:35:51 UTC+1, rabiasa...@gmail.com:
>
> Hi Tom
> Many thanks for your reply, I use docker container and LXC and
> give the containers IP address (eth0)  outside the ns-3 script.
> My topology is like the below graph (use docker container). In
> this scenario only single-hop works. I have tried to run a
> routing protocol in ns3 script but it does not work.  In this
> case, I think I can not stop ARP because the TAP device works in L2.
>
> --
> Posting to this group should follow these guidelines
> https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
> <https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting>
> ---
> You received this message because you are subscribed to the Google
> Groups "ns-3-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to ns-3-users+...@googlegroups.com
> <mailto:ns-3-users+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ns-3-users/6fe6e2ad-85d8-4f2f-99e1-707c75107cd5n%40googlegroups.com
> <https://groups.google.com/d/msgid/ns-3-users/6fe6e2ad-85d8-4f2f-99e1-707c75107cd5n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Muhammad Nauman Chattha

unread,
Jul 23, 2022, 6:18:52 PM7/23/22
to ns-3-users
Hi Tom,
I tried your suggestions,
  • I have a route as I am using the local network IP and gateway. so I have a route from 192.168.0.0 gw 192.168.0.1.
  • with tcpdump, I haven't got anything on this interface.
  • i checked the pcap file and there is only ARP , nothing else.
it seems like somehow the node in ns3 is unable to use the actual device. Can you give me some pointers to check this? I tried to run the actual example but it seem I am having same issue with that as well.

荣鑫

unread,
Oct 21, 2022, 2:07:12 AM10/21/22
to ns-3-users
I'm interested in your initial example, I'd like to ask how to set up/develop an application in Python Server to accept packets sent out of NS3? Is there any code I can refer to? Thanks thanks.
Reply all
Reply to author
Forward
0 new messages