12#include "ns3/config.h"
13#include "ns3/fd-net-device.h"
16#include "ns3/object-factory.h"
17#include "ns3/packet.h"
18#include "ns3/simulator.h"
19#include "ns3/trace-helper.h"
27#include <net/ethernet.h>
29#include <netinet/in.h>
30#include <netpacket/packet.h>
35#include <sys/socket.h>
47#define EMU_MAGIC 65867
89 NS_FATAL_ERROR(
"EmuFdNetDeviceHelper::SetFileDescriptor (): m_deviceName is not set");
97 device->SetFileDescriptor(
fd);
111 NS_FATAL_ERROR(
"EmuFdNetDeviceHelper::SetFileDescriptor (): Can't get interface index");
121 ll.sll_ifindex =
ifr.ifr_ifindex;
130 "EmuFdNetDeviceHelper::SetFileDescriptor (): Can't bind to specified interface");
136 NS_FATAL_ERROR(
"EmuFdNetDeviceHelper::SetFileDescriptor (): Can't get interface flags");
141#ifdef PACKET_QDISC_BYPASS
155 NS_LOG_ERROR(
"PACKET_QDISC_BYPASS undefined; cannot use the qdisc bypass option");
182 device->SetIsBroadcast(
false);
188 device->SetIsMulticast(
true);
202 NS_FATAL_ERROR(
"FdNetDevice::SetFileDescriptor (): Can't ioctl SIOCGIFMTU");
206 device->SetMtu(
ifr2.ifr_mtu);
227 "EmuFdNetDeviceHelper::CreateFileDescriptor(): Unix socket creation error, errno = "
240 NS_FATAL_ERROR(
"EmuFdNetDeviceHelper::CreateFileDescriptor(): Could not bind(): errno = "
259 "EmuFdNetDeviceHelper::CreateFileDescriptor(): Could not getsockname(): errno = "
267 NS_LOG_INFO(
"Encoded Unix socket as \"" << path <<
"\"");
289 std::ostringstream
oss;
305 NS_FATAL_ERROR(
"EmuFdNetDeviceHelper::CreateFileDescriptor(): Back from execlp(), status = "
319 NS_FATAL_ERROR(
"EmuFdNetDeviceHelper::CreateFileDescriptor(): waitpid() fails, errno = "
334 NS_FATAL_ERROR(
"EmuFdNetDeviceHelper::CreateFileDescriptor(): socket creator "
335 "exited normally with status "
342 "EmuFdNetDeviceHelper::CreateFileDescriptor(): socket creator exited abnormally");
372 constexpr size_t msg_size =
sizeof(int);
386 msg.msg_name =
nullptr;
390 msg.msg_control = control;
391 msg.msg_controllen =
sizeof(control);
401 NS_FATAL_ERROR(
"EmuFdNetDeviceHelper::CreateFileDescriptor(): Wrong byte count from "
433 NS_FATAL_ERROR(
"Did not get the raw socket from the socket creator");
bool m_hostQdiscBypass
True if request host qdisc bypass.
std::string m_deviceName
The Unix/Linux name of the underlying device (e.g., eth0)
void HostQdiscBypass(bool hostQdiscBypass)
Request host qdisc bypass.
void SetDeviceName(std::string deviceName)
Set the device name of this device.
Ptr< NetDevice > InstallPriv(Ptr< Node > node) const override
This method creates an ns3::FdNetDevice attached to a physical network interface.
virtual void SetFileDescriptor(Ptr< FdNetDevice > device) const
Sets a file descriptor on the FileDescriptorNetDevice.
std::string GetDeviceName()
Get the device name of this device.
virtual int CreateFileDescriptor() const
Call out to a separate process running as suid root in order to get a raw socket.
EmuFdNetDeviceHelper()
Construct a EmuFdNetDeviceHelper.
virtual Ptr< NetDevice > InstallPriv(Ptr< Node > node) const
This method creates an ns3::FdNetDevice and associates it to a node.
a NetDevice to read/write network traffic from/into a file descriptor.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::string BufferToString(uint8_t *buffer, uint32_t len)
Convert a byte buffer to a string containing a hex representation of the buffer.
ns3::StringValue attribute value declarations.