14#include "ns3/config.h"
15#include "ns3/fd-net-device.h"
18#include "ns3/netmap-net-device.h"
19#include "ns3/object-factory.h"
20#include "ns3/packet.h"
21#include "ns3/simulator.h"
22#include "ns3/trace-helper.h"
23#include "ns3/uinteger.h"
31#include <net/ethernet.h>
33#include <net/netmap_user.h>
34#include <netinet/in.h>
40#include <sys/socket.h>
52#define EMU_MAGIC 65867
91 device->AggregateObject(
ndqi);
102 NS_FATAL_ERROR(
"NetmapNetDeviceHelper::SetFileDescriptor (): m_deviceName is not set");
123 NS_FATAL_ERROR(
"NetmapNetDeviceHelper::SetFileDescriptor (): Can't get interface index");
129 NS_FATAL_ERROR(
"NetmapNetDeviceHelper::SetFileDescriptor (): Can't get interface flags");
147 <<
" is not in promiscuous mode. Please config the interface in promiscuous "
148 "mode before to run the simulation.");
157 device->SetIsBroadcast(
false);
163 device->SetIsMulticast(
true);
177 NS_FATAL_ERROR(
"FdNetDevice::SetFileDescriptor (): Can't ioctl SIOCGIFMTU");
181 device->SetMtu(
ifr.ifr_mtu);
204 "NetmapNetDeviceHelper::CreateFileDescriptor(): Unix socket creation error, errno = "
217 NS_FATAL_ERROR(
"NetmapNetDeviceHelper::CreateFileDescriptor(): Could not bind(): errno = "
236 "NetmapNetDeviceHelper::CreateFileDescriptor(): Could not getsockname(): errno = "
244 NS_LOG_INFO(
"Encoded Unix socket as \"" << path <<
"\"");
266 std::ostringstream
oss;
285 "NetmapNetDeviceHelper::CreateFileDescriptor(): Back from execlp(), status = "
300 "NetmapNetDeviceHelper::CreateFileDescriptor(): waitpid() fails, errno = "
315 NS_FATAL_ERROR(
"NetmapNetDeviceHelper::CreateFileDescriptor(): socket creator "
316 "exited normally with status "
323 "NetmapNetDeviceHelper::CreateFileDescriptor(): socket creator exited abnormally");
366 msg.msg_name =
nullptr;
370 msg.msg_control = control;
371 msg.msg_controllen =
sizeof(control);
381 NS_FATAL_ERROR(
"NetmapNetDeviceHelper::CreateFileDescriptor(): Wrong byte count from "
413 NS_FATAL_ERROR(
"Did not get the raw socket from the socket creator");
461 NS_FATAL_ERROR(
"Failed getting the base struct of the interface in netmap mode");
464 device->SetNetmapInterfaceRepresentation(
nifp);
465 device->SetTxRingsInfo(
nifp->ni_tx_rings,
nmr.nr_tx_slots);
466 device->SetRxRingsInfo(
nifp->ni_rx_rings,
nmr.nr_rx_slots);
468 device->SetFileDescriptor(
fd);
virtual Ptr< NetDevice > InstallPriv(Ptr< Node > node) const
This method creates an ns3::FdNetDevice and associates it to a node.
void SetTypeId(std::string type)
Set the TypeId of the Objects to be created by this helper.
a NetDevice to read/write network traffic from/into a file descriptor.
static TypeId GetTypeId()
Get the type ID.
Ptr< NetDevice > InstallPriv(Ptr< Node > node) const
This method creates an ns3::FdNetDevice attached to a physical network interface.
virtual int CreateFileDescriptor() const
Call out to a separate process running as suid root in order to get a raw socket.
void SetDeviceName(std::string deviceName)
Set the device name of this device.
std::string m_deviceName
The unix/linux name of the underlying device (e.g., eth0)
void SwitchInNetmapMode(int fd, Ptr< NetmapNetDevice > device) const
Switch the fd in netmap mode.
std::string GetDeviceName()
Get the device name of this device.
virtual void SetDeviceAttributes(Ptr< FdNetDevice > device) const
Sets device flags and MTU.
Smart pointer class similar to boost::intrusive_ptr.
AttributeValue implementation for TypeId.
Hold an unsigned integer type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#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_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.