A Discrete-Event Network Simulator
API
ns3::TapBridge Class Reference

A bridge to make it appear that a real host process is connected to an ns-3 net device. More...

#include "tap-bridge.h"

+ Inheritance diagram for ns3::TapBridge:
+ Collaboration diagram for ns3::TapBridge:

Public Types

enum  Mode { ILLEGAL , CONFIGURE_LOCAL , USE_LOCAL , USE_BRIDGE }
 Enumeration of the operating modes supported in the class. More...
 
- Public Types inherited from ns3::NetDevice
typedef void(* LinkChangeTracedCallback) (void)
 TracedCallback signature for link changed event. More...
 
enum  PacketType {
  PACKET_HOST = 1 , NS3_PACKET_HOST = PACKET_HOST , PACKET_BROADCAST , NS3_PACKET_BROADCAST = PACKET_BROADCAST ,
  PACKET_MULTICAST , NS3_PACKET_MULTICAST = PACKET_MULTICAST , PACKET_OTHERHOST , NS3_PACKET_OTHERHOST = PACKET_OTHERHOST
}
 Packet types are used as they are in Linux. More...
 
typedef Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, enum PacketTypePromiscReceiveCallback
 
typedef Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address & > ReceiveCallback
 

Public Member Functions

 TapBridge ()
 
virtual ~TapBridge ()
 
virtual void AddLinkChangeCallback (Callback< void > callback)
 
virtual Address GetAddress (void) const
 
Ptr< NetDeviceGetBridgedNetDevice (void)
 Get the bridged net device. More...
 
virtual Address GetBroadcast (void) const
 
virtual Ptr< ChannelGetChannel (void) const
 
virtual uint32_t GetIfIndex (void) const
 
TapBridge::Mode GetMode (void)
 Get the operating mode of this device. More...
 
virtual uint16_t GetMtu (void) const
 
virtual Address GetMulticast (Ipv4Address multicastGroup) const
 Make and return a MAC multicast address using the provided multicast group. More...
 
virtual Address GetMulticast (Ipv6Address addr) const
 Get the MAC multicast address corresponding to the IPv6 address provided. More...
 
virtual Ptr< NodeGetNode (void) const
 
virtual bool IsBridge (void) const
 Return true if the net device is acting as a bridge. More...
 
virtual bool IsBroadcast (void) const
 
virtual bool IsLinkUp (void) const
 
virtual bool IsMulticast (void) const
 
virtual bool IsPointToPoint (void) const
 Return true if the net device is on a point-to-point link. More...
 
virtual bool NeedsArp (void) const
 
virtual bool Send (Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
 
virtual bool SendFrom (Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
 
virtual void SetAddress (Address address)
 Set the address of this interface. More...
 
void SetBridgedNetDevice (Ptr< NetDevice > bridgedDevice)
 Set the ns-3 net device to bridge. More...
 
virtual void SetIfIndex (const uint32_t index)
 
void SetMode (TapBridge::Mode mode)
 Set the operating mode of this device. More...
 
virtual bool SetMtu (const uint16_t mtu)
 
virtual void SetNode (Ptr< Node > node)
 
virtual void SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb)
 
virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb)
 
void Start (Time tStart)
 Set a start time for the device. More...
 
void Stop (Time tStop)
 Set a stop time for the device. More...
 
virtual bool SupportsSendFrom () const
 
- Public Member Functions inherited from ns3::NetDevice
virtual ~NetDevice ()
 
- Public Member Functions inherited from ns3::Object
 Object ()
 Constructor. More...
 
virtual ~Object ()
 Destructor. More...
 
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together. More...
 
void Dispose (void)
 Dispose of this Object. More...
 
AggregateIterator GetAggregateIterator (void) const
 Get an iterator to the Objects aggregated to this one. More...
 
virtual TypeId GetInstanceTypeId (void) const
 Get the most derived TypeId for this Object. More...
 
template<>
Ptr< ObjectGetObject () const
 Specialization of () for objects of type ns3::Object. More...
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId. More...
 
template<>
Ptr< ObjectGetObject (TypeId tid) const
 Specialization of (TypeId tid) for objects of type ns3::Object. More...
 
template<typename T >
Ptr< T > GetObject (void) const
 Get a pointer to the requested aggregated Object. More...
 
void Initialize (void)
 Invoke DoInitialize on all Objects aggregated to this one. More...
 
bool IsInitialized (void) const
 Check if the object has been initialized. More...
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor. More...
 
 SimpleRefCount (const SimpleRefCount &o[[maybe_unused]])
 Copy constructor. More...
 
uint32_t GetReferenceCount (void) const
 Get the reference count of the object. More...
 
SimpleRefCountoperator= ([[maybe_unused]] const SimpleRefCount &o)
 Assignment operator. More...
 
void Ref (void) const
 Increment the reference count. More...
 
void Unref (void) const
 Decrement the reference count. More...
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor. More...
 
void GetAttribute (std::string name, AttributeValue &value) const
 Get the value of an attribute, raising fatal errors if unsuccessful. More...
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising erros. More...
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful. More...
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors. More...
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context. More...
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context. More...
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context. More...
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context. More...
 

Static Public Member Functions

static TypeId GetTypeId (void)
 Get the type ID. More...
 
- Static Public Member Functions inherited from ns3::NetDevice
static TypeId GetTypeId (void)
 Get the type ID. More...
 
- Static Public Member Functions inherited from ns3::Object
static TypeId GetTypeId (void)
 Register this type. More...
 
- Static Public Member Functions inherited from ns3::ObjectBase
static TypeId GetTypeId (void)
 Get the type ID. More...
 

Protected Member Functions

bool DiscardFromBridgedDevice (Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, Address const &src)
 Receives a packet from a bridged Device. More...
 
virtual void DoDispose (void)
 Call out to a separate process running as suid root in order to get our tap device created. More...
 
bool ReceiveFromBridgedDevice (Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, Address const &src, Address const &dst, PacketType packetType)
 Receives a packet from a bridged Device. More...
 
- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
 Copy an Object. More...
 
virtual void DoInitialize (void)
 Initialize() implementation. More...
 
virtual void NotifyNewAggregate (void)
 Notify all Objects aggregated to this one of a new Object being aggregated. More...
 
- Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 Complete construction of ObjectBase; invoked by derived classes. More...
 
virtual void NotifyConstructionCompleted (void)
 Notifier called once the ObjectBase is fully constructed. More...
 

Private Member Functions

void CreateTap (void)
 Call out to a separate process running as suid root in order to get our tap device created. More...
 
Ptr< PacketFilter (Ptr< Packet > packet, Address *src, Address *dst, uint16_t *type)
 The host we are bridged to is in the evil real world. More...
 
void ForwardToBridgedDevice (uint8_t *buf, ssize_t len)
 Forward a packet received from the tap device to the bridged ns-3 device. More...
 
void NotifyLinkUp (void)
 Notifies that the link is up and ready. More...
 
void ReadCallback (uint8_t *buf, ssize_t len)
 Callback to process packets that are read. More...
 
void StartTapDevice (void)
 Spin up the device. More...
 
void StopTapDevice (void)
 Tear down the device. More...
 

Private Attributes

Mac48Address m_address
 The (unused) MAC address of the TapBridge net device. More...
 
Ptr< NetDevicem_bridgedDevice
 The ns-3 net device to which we are bridging. More...
 
Ptr< TapBridgeFdReaderm_fdReader
 Includes the ns-3 read thread used to do blocking reads on the fd corresponding to the host device. More...
 
uint32_t m_ifIndex
 The ns-3 interface index of this TapBridge net device. More...
 
TracedCallback m_linkChangeCallbacks
 Callbacks to fire if the link changes state (up or down). More...
 
bool m_linkUp
 Flag indicating whether or not the link is up. More...
 
Mode m_mode
 The operating mode of the bridge. More...
 
uint16_t m_mtu
 The common mtu to use for the net devices. More...
 
Ptr< Nodem_node
 Pointer to the (ghost) Node to which we are connected. More...
 
uint32_t m_nodeId
 a copy of the node id so the read thread doesn't have to GetNode() in in order to find the node ID. More...
 
bool m_ns3AddressRewritten
 Whether the MAC address of the underlying ns-3 device has already been rewritten is stored in this variable (for UseLocal/UseBridge mode only). More...
 
uint8_t * m_packetBuffer
 A 64K buffer to hold packet data while it is being sent. More...
 
NetDevice::PromiscReceiveCallback m_promiscRxCallback
 Callback used to hook the promiscuous packet receive callback of the TapBridge ns-3 net device. More...
 
NetDevice::ReceiveCallback m_rxCallback
 Callback used to hook the standard packet receive callback of the TapBridge ns-3 net device. More...
 
int m_sock
 The socket (actually interpreted as fd) to use to talk to the Tap device on the real internet host. More...
 
EventId m_startEvent
 The ID of the ns-3 event used to schedule the start up of the underlying host Tap device and ns-3 read thread. More...
 
EventId m_stopEvent
 The ID of the ns-3 event used to schedule the tear down of the underlying host Tap device and ns-3 read thread. More...
 
std::string m_tapDeviceName
 The name of the device to create on the host. More...
 
Ipv4Address m_tapGateway
 The IP address to use as the device default gateway on the host. More...
 
Ipv4Address m_tapIp
 The IP address to use as the device IP on the host. More...
 
Mac48Address m_tapMac
 The MAC address to use as the hardware address on the host; only used in UseLocal mode. More...
 
Ipv4Mask m_tapNetmask
 The network mask to assign to the device created on the host. More...
 
Time m_tStart
 Time to start spinning up the device. More...
 
Time m_tStop
 Time to start tearing down the device. More...
 
bool m_verbose
 Flag indicating whether or not the link is up. More...
 

Additional Inherited Members

Detailed Description

A bridge to make it appear that a real host process is connected to an ns-3 net device.

The Tap Bridge lives in a kind of a gray world somewhere between a Linux host and an ns-3 bridge device. From the Linux perspective, this code appears as the user mode handler for a Tap net device. That is, when the Linux host writes to a /dev/tap device (that is either manually or automatically created depending on basic operating mode – more on this later), the write is redirected into the TapBridge that lives in the ns-3 world; and from this perspective, becomes a read. In other words, a Linux process writes a packet to a tap device and this packet is redirected to an ns-3 process where it is received by the TapBridge as a result of a read operation there. The TapBridge then sends the packet to the ns-3 net device to which it is bridged. In the other direction, a packet received by an ns-3 net device is bridged to the TapBridge (it appears via a callback from that net device. The TapBridge then takes that packet and writes it back to the host using the Linux TAP mechanism. This write to the device will then appear to the Linux host as if a packet has arrived on its device.

The upshot is that the Tap Bridge appears to bridge a tap device on a Linux host in the "real world" to an ns-3 net device in the simulation and make is appear that a ns-3 net device is actually installed in the Linux host. In order to do this on the ns-3 side, we need a "ghost node" in the simulation to hold the bridged ns-3 net device and the TapBridge. This node should not actually do anything else in the simulation since its job is simply to make the net device appear in Linux. This is not just arbitrary policy, it is because:

  • Bits sent to the Tap Bridge from higher layers in the ghost node (using the TapBridge Send() method) are completely ignored. The Tap Bridge is not, itself, connected to any network, neither in Linux nor in ns-3;
  • The bridged ns-3 net device is has had its receive callback disconnected from the ns-3 node and reconnected to the Tap Bridge. All data received by a bridged device will be sent to the Linux host and will not be received by the node. From the perspective of the ghost node, you can send over this device but you cannot ever receive.

Of course, if you understand all of the issues you can take control of your own destiny and do whatever you want – we do not actively prevent you from using the ghost node for anything you decide. You will be able to perform typical ns-3 operations on the ghost node if you so desire. The internet stack, for example, must be there and functional on that node in order to participate in IP address assignment and global routing. However, as mentioned above, interfaces talking any Tap Bridge or associated bridged net devices will not work completely. If you understand exactly what you are doing, you can set up other interfaces and devices on the ghost node and use them; or take advantage of the operational send side of the bridged devices to create traffic generators. We generally recommend that you treat this node as a ghost of the Linux host and leave it to itself, though.

Config Paths

ns3::TapBridge is accessible through the following paths with Config::Set and Config::Connect:

  • "/NodeList/[i]/DeviceList/[i]/$ns3::TapBridge"

Attributes

  • Mtu: The MAC-level Maximum Transmission Unit
    • Set with class: ns3::UintegerValue
    • Underlying type: uint16_t 0:65535
    • Initial value: 0
    • Flags: construct write read
  • DeviceName: The name of the tap device to create.
    • Set with class: StringValue
    • Underlying type:
    • Initial value:
    • Flags: construct write read
  • Gateway: The IP address of the default gateway to assign to the host machine, when in ConfigureLocal mode.
  • IpAddress: The IP address to assign to the tap device, when in ConfigureLocal mode. This address will override the discovered IP address of the simulated device.
  • MacAddress: The MAC address to assign to the tap device, when in ConfigureLocal mode. This address will override the discovered MAC address of the simulated device.
  • Netmask: The network mask to assign to the tap device, when in ConfigureLocal mode. This address will override the discovered MAC address of the simulated device.
    • Set with class: Ipv4MaskValue
    • Underlying type: Ipv4Mask
    • Initial value: 255.255.255.255
    • Flags: construct write read
  • Start: The simulation time at which to spin up the tap device read thread.
    • Set with class: ns3::TimeValue
    • Underlying type: Time +9.22337e+18ns:+9.22337e+18ns
    • Initial value: +0ns
    • Flags: construct write read
  • Stop: The simulation time at which to tear down the tap device read thread.
    • Set with class: ns3::TimeValue
    • Underlying type: Time +9.22337e+18ns:+9.22337e+18ns
    • Initial value: +0ns
    • Flags: construct write read
  • Mode: The operating and configuration mode to use.
    • Set with class: ns3::EnumValue
    • Underlying type:
    • Initial value: UseLocal
    • Flags: construct write
  • Verbose: Enable verbose output from tap-creator child process
    • Set with class: BooleanValue
    • Underlying type: bool
    • Initial value: false
    • Flags: construct write read

No TraceSources are defined for this type.
Size of this type is 280 bytes (on a 64-bit architecture).

Definition at line 107 of file tap-bridge.h.

Member Enumeration Documentation

◆ Mode

Enumeration of the operating modes supported in the class.

Enumerator
ILLEGAL 

mode not set

CONFIGURE_LOCAL 

ns-3 creates and configures tap device

USE_LOCAL 

ns-3 uses a pre-created tap, without configuring it

USE_BRIDGE 

ns-3 uses a pre-created tap, and bridges to a bridging net device

Definition at line 120 of file tap-bridge.h.

Constructor & Destructor Documentation

◆ TapBridge()

ns3::TapBridge::TapBridge ( )

Definition at line 144 of file tap-bridge.cc.

References m_packetBuffer, m_tStart, NS_LOG_FUNCTION, and Start().

+ Here is the call graph for this function:

◆ ~TapBridge()

ns3::TapBridge::~TapBridge ( )
virtual

Definition at line 158 of file tap-bridge.cc.

References m_bridgedDevice, m_packetBuffer, NS_LOG_FUNCTION, and StopTapDevice().

+ Here is the call graph for this function:

Member Function Documentation

◆ AddLinkChangeCallback()

void ns3::TapBridge::AddLinkChangeCallback ( Callback< void >  callback)
virtual
Parameters
callbackthe callback to invoke

Add a callback invoked whenever the link status changes to UP. This callback is typically used by the IP/ARP layer to flush the ARP cache and by IPv6 stack to flush NDISC cache whenever the link goes up.

Implements ns3::NetDevice.

Definition at line 1112 of file tap-bridge.cc.

References ns3::TracedCallback< Ts >::ConnectWithoutContext(), m_linkChangeCallbacks, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ CreateTap()

void ns3::TapBridge::CreateTap ( void  )
private

Call out to a separate process running as suid root in order to get our tap device created.

We do this to avoid having the entire simulation running as root. If this method returns, we'll have a socket waiting for us in m_sock that we can use to talk to the tap device.

Definition at line 261 of file tap-bridge.cc.

References first::address, CONFIGURE_LOCAL, ns3::Mac48Address::ConvertFrom(), ns3::Mac48Address::CopyFrom(), ns3::NetDevice::GetAddress(), GetBridgedNetDevice(), ns3::NetDevice::GetNode(), ns3::Object::GetObject(), ns3::Ipv4Mask::GetOnes(), ns3::Ipv4Address::IsBroadcast(), ns3::Mac48Address::IsBroadcast(), m_bridgedDevice, m_mode, m_ns3AddressRewritten, m_sock, m_tapDeviceName, m_tapGateway, m_tapIp, m_tapMac, m_tapNetmask, m_verbose, NS_ABORT_MSG_IF, NS_ASSERT_MSG, NS_FATAL_ERROR, NS_LOG_DEBUG, NS_LOG_FUNCTION, NS_LOG_INFO, NS_LOG_WARN, ns3::NetDevice::SetAddress(), TAP_MAGIC, ns3::TapBufferToString(), USE_BRIDGE, and USE_LOCAL.

Referenced by StartTapDevice().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DiscardFromBridgedDevice()

bool ns3::TapBridge::DiscardFromBridgedDevice ( Ptr< NetDevice device,
Ptr< const Packet packet,
uint16_t  protocol,
Address const &  src 
)
protected

Receives a packet from a bridged Device.

Parameters
devicethe originating port
packetthe received packet
protocolthe packet protocol (e.g., Ethertype)
srcthe packet source
Returns
true on success

Definition at line 950 of file tap-bridge.cc.

References NS_LOG_FUNCTION, and NS_LOG_LOGIC.

Referenced by SetBridgedNetDevice().

+ Here is the caller graph for this function:

◆ DoDispose()

void ns3::TapBridge::DoDispose ( void  )
protectedvirtual

Call out to a separate process running as suid root in order to get our tap device created.

We do this to avoid having the entire simulation running as root. If this method returns, we'll have a socket waiting for us in m_sock that we can use to talk to the tap device.

Reimplemented from ns3::Object.

Definition at line 171 of file tap-bridge.cc.

References ns3::Object::DoDispose(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ Filter()

Ptr< Packet > ns3::TapBridge::Filter ( Ptr< Packet packet,
Address src,
Address dst,
uint16_t *  type 
)
private

The host we are bridged to is in the evil real world.

Do some sanity checking on a received packet to make sure it isn't too evil for our poor naive virginal simulator to handle.

Parameters
packetThe packet we received from the host, and which we need to check.
srcA pointer to the data structure that will get the source MAC address of the packet (extracted from the packet Ethernet header).
dstA pointer to the data structure that will get the destination MAC address of the packet (extracted from the packet Ethernet header).
typeA pointer to the variable that will get the packet type from either the Ethernet header in the case of type interpretation (DIX framing) or from the 802.2 LLC header in the case of length interpretation (802.3 framing).
Returns
the packet, or null if the packet has been filtered.

Definition at line 848 of file tap-bridge.cc.

References ns3::EthernetHeader::GetDestination(), ns3::EthernetHeader::GetLengthType(), ns3::EthernetHeader::GetSerializedSize(), ns3::LlcSnapHeader::GetSerializedSize(), ns3::Packet::GetSize(), ns3::EthernetHeader::GetSource(), ns3::LlcSnapHeader::GetType(), NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::Packet::PeekHeader(), pktSize, ns3::Packet::RemoveAtStart(), and ns3::Packet::RemoveHeader().

Referenced by ForwardToBridgedDevice().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ForwardToBridgedDevice()

void ns3::TapBridge::ForwardToBridgedDevice ( uint8_t *  buf,
ssize_t  len 
)
private

Forward a packet received from the tap device to the bridged ns-3 device.

Parameters
bufA character buffer containing the actual packet bits that were received from the host.
lenThe length of the buffer.

Definition at line 721 of file tap-bridge.cc.

References CONFIGURE_LOCAL, ns3::Mac48Address::ConvertFrom(), Filter(), m_bridgedDevice, m_mode, m_ns3AddressRewritten, NS_ASSERT_MSG, NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::NetDevice::Send(), ns3::NetDevice::SendFrom(), ns3::NetDevice::SetAddress(), USE_BRIDGE, and USE_LOCAL.

Referenced by ReadCallback().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetAddress()

Address ns3::TapBridge::GetAddress ( void  ) const
virtual
Returns
the current Address of this interface.

Implements ns3::NetDevice.

Definition at line 1058 of file tap-bridge.cc.

References m_address, and NS_LOG_FUNCTION.

◆ GetBridgedNetDevice()

Ptr< NetDevice > ns3::TapBridge::GetBridgedNetDevice ( void  )

Get the bridged net device.

The bridged net device is the ns-3 device to which this bridge is connected,

Returns
the bridged net device.

Definition at line 910 of file tap-bridge.cc.

References m_bridgedDevice, and NS_LOG_FUNCTION.

Referenced by CreateTap().

+ Here is the caller graph for this function:

◆ GetBroadcast()

Address ns3::TapBridge::GetBroadcast ( void  ) const
virtual
Returns
the broadcast address supported by this netdevice.

Calling this method is invalid if IsBroadcast returns not true.

Implements ns3::NetDevice.

Definition at line 1126 of file tap-bridge.cc.

References NS_LOG_FUNCTION.

◆ GetChannel()

Ptr< Channel > ns3::TapBridge::GetChannel ( void  ) const
virtual
Returns
the channel this NetDevice is connected to. The value returned can be zero if the NetDevice is not yet connected to any channel or if the underlying NetDevice has no concept of a channel. i.e., callers must check for zero and be ready to handle it.

Implements ns3::NetDevice.

Definition at line 1044 of file tap-bridge.cc.

References NS_LOG_FUNCTION.

◆ GetIfIndex()

uint32_t ns3::TapBridge::GetIfIndex ( void  ) const
virtual
Returns
index ifIndex of the device

Implements ns3::NetDevice.

Definition at line 1037 of file tap-bridge.cc.

References m_ifIndex, and NS_LOG_FUNCTION.

◆ GetMode()

TapBridge::Mode ns3::TapBridge::GetMode ( void  )

Get the operating mode of this device.

Returns
The operating mode of this device.

Definition at line 1072 of file tap-bridge.cc.

References m_mode, and NS_LOG_FUNCTION.

◆ GetMtu()

uint16_t ns3::TapBridge::GetMtu ( void  ) const
virtual
Returns
the link-level MTU in bytes for this interface.

This value is typically used by the IP layer to perform IP fragmentation when needed.

Implements ns3::NetDevice.

Definition at line 1087 of file tap-bridge.cc.

References m_mtu, and NS_LOG_FUNCTION.

Referenced by GetTypeId().

+ Here is the caller graph for this function:

◆ GetMulticast() [1/2]

Address ns3::TapBridge::GetMulticast ( Ipv4Address  multicastGroup) const
virtual

Make and return a MAC multicast address using the provided multicast group.

RFC 1112 says that an Ipv4 host group address is mapped to an Ethernet multicast address by placing the low-order 23-bits of the IP address into the low-order 23 bits of the Ethernet multicast address 01-00-5E-00-00-00 (hex). Similar RFCs exist for Ipv6 and Eui64 mappings. This method performs the multicast address creation function appropriate to the underlying MAC address of the device. This MAC address is encapsulated in an abstract Address to avoid dependencies on the exact MAC address format.

In the case of net devices that do not support multicast, clients are expected to test NetDevice::IsMulticast and avoid attempting to map multicast packets. Subclasses of NetDevice that do support multicasting are expected to override this method and provide an implementation appropriate to the particular device.

Parameters
multicastGroupThe IP address for the multicast group destination of the packet.
Returns
The MAC multicast Address used to send packets to the provided multicast group.
Warning
Calling this method is invalid if IsMulticast returns not true.
See also
IsMulticast()

Implements ns3::NetDevice.

Definition at line 1140 of file tap-bridge.cc.

References ns3::Mac48Address::GetMulticast(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ GetMulticast() [2/2]

Address ns3::TapBridge::GetMulticast ( Ipv6Address  addr) const
virtual

Get the MAC multicast address corresponding to the IPv6 address provided.

Parameters
addrIPv6 address
Returns
the MAC multicast address
Warning
Calling this method is invalid if IsMulticast returns not true.

Implements ns3::NetDevice.

Definition at line 1225 of file tap-bridge.cc.

References ns3::Mac48Address::GetMulticast(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ GetNode()

Ptr< Node > ns3::TapBridge::GetNode ( void  ) const
virtual
Returns
the node base class which contains this network interface.

When a subclass needs to get access to the underlying node base class to print the nodeid for example, it can invoke this method.

Implements ns3::NetDevice.

Definition at line 1184 of file tap-bridge.cc.

References m_node, and NS_LOG_FUNCTION.

Referenced by StartTapDevice().

+ Here is the caller graph for this function:

◆ GetTypeId()

◆ IsBridge()

bool ns3::TapBridge::IsBridge ( void  ) const
virtual

Return true if the net device is acting as a bridge.

Returns
value of m_isBridge flag

Implements ns3::NetDevice.

Definition at line 1155 of file tap-bridge.cc.

References NS_LOG_FUNCTION.

◆ IsBroadcast()

bool ns3::TapBridge::IsBroadcast ( void  ) const
virtual
Returns
true if this interface supports a broadcast address, false otherwise.

Implements ns3::NetDevice.

Definition at line 1119 of file tap-bridge.cc.

References NS_LOG_FUNCTION.

◆ IsLinkUp()

bool ns3::TapBridge::IsLinkUp ( void  ) const
virtual
Returns
true if link is up; false otherwise

Implements ns3::NetDevice.

Definition at line 1105 of file tap-bridge.cc.

References m_linkUp, and NS_LOG_FUNCTION.

◆ IsMulticast()

bool ns3::TapBridge::IsMulticast ( void  ) const
virtual
Returns
value of m_isMulticast flag

Implements ns3::NetDevice.

Definition at line 1133 of file tap-bridge.cc.

References NS_LOG_FUNCTION.

◆ IsPointToPoint()

bool ns3::TapBridge::IsPointToPoint ( void  ) const
virtual

Return true if the net device is on a point-to-point link.

Returns
value of m_isPointToPoint flag

Implements ns3::NetDevice.

Definition at line 1148 of file tap-bridge.cc.

References NS_LOG_FUNCTION.

◆ NeedsArp()

bool ns3::TapBridge::NeedsArp ( void  ) const
virtual
Returns
true if ARP is needed, false otherwise.

Called by higher-layers to check if this NetDevice requires ARP to be used.

Implements ns3::NetDevice.

Definition at line 1198 of file tap-bridge.cc.

References NS_LOG_FUNCTION.

◆ NotifyLinkUp()

void ns3::TapBridge::NotifyLinkUp ( void  )
private

Notifies that the link is up and ready.

Definition at line 1094 of file tap-bridge.cc.

References m_linkChangeCallbacks, m_linkUp, and NS_LOG_FUNCTION.

Referenced by StartTapDevice().

+ Here is the caller graph for this function:

◆ ReadCallback()

void ns3::TapBridge::ReadCallback ( uint8_t *  buf,
ssize_t  len 
)
private

Callback to process packets that are read.

Parameters
bufinput buffer
leninput buffer length

Definition at line 696 of file tap-bridge.cc.

References ForwardToBridgedDevice(), m_nodeId, ns3::MakeEvent(), NS_ASSERT_MSG, NS_LOG_FUNCTION, NS_LOG_INFO, ns3::Simulator::ScheduleWithContext(), and ns3::Seconds().

Referenced by StartTapDevice().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ReceiveFromBridgedDevice()

bool ns3::TapBridge::ReceiveFromBridgedDevice ( Ptr< NetDevice device,
Ptr< const Packet packet,
uint16_t  protocol,
Address const &  src,
Address const &  dst,
PacketType  packetType 
)
protected

Receives a packet from a bridged Device.

Parameters
devicethe originating port
packetthe received packet
protocolthe packet protocol (e.g., Ethertype)
srcthe packet source
dstthe packet destination
packetTypethe packet type (e.g., host, broadcast, etc.)
Returns
true on success

Definition at line 958 of file tap-bridge.cc.

References ns3::Packet::AddHeader(), CONFIGURE_LOCAL, ns3::Mac48Address::ConvertFrom(), ns3::Packet::Copy(), ns3::Packet::CopyData(), ns3::EthernetHeader::GetDestination(), ns3::Node::GetId(), ns3::EthernetHeader::GetLengthType(), ns3::Packet::GetSize(), ns3::EthernetHeader::GetSource(), ns3::Packet::GetUid(), m_bridgedDevice, m_mode, m_node, m_packetBuffer, m_sock, NS_ABORT_MSG_IF, NS_ASSERT_MSG, NS_LOG_DEBUG, NS_LOG_FUNCTION, NS_LOG_LOGIC, ns3::NetDevice::PACKET_OTHERHOST, ns3::EthernetHeader::SetDestination(), ns3::EthernetHeader::SetLengthType(), and ns3::EthernetHeader::SetSource().

Referenced by SetBridgedNetDevice().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Send()

bool ns3::TapBridge::Send ( Ptr< Packet packet,
const Address dest,
uint16_t  protocolNumber 
)
virtual
Parameters
packetpacket sent from above down to Network Device
destmac address of the destination (already resolved)
protocolNumberidentifies the type of payload contained in this packet. Used to call the right L3Protocol when the packet is received.

Called from higher layer to send packet into Network Device to the specified destination Address

Returns
whether the Send operation succeeded

Implements ns3::NetDevice.

Definition at line 1168 of file tap-bridge.cc.

References NS_FATAL_ERROR, and NS_LOG_FUNCTION.

◆ SendFrom()

bool ns3::TapBridge::SendFrom ( Ptr< Packet packet,
const Address source,
const Address dest,
uint16_t  protocolNumber 
)
virtual
Parameters
packetpacket sent from above down to Network Device
sourcesource mac address (so called "MAC spoofing")
destmac address of the destination (already resolved)
protocolNumberidentifies the type of payload contained in this packet. Used to call the right L3Protocol when the packet is received.

Called from higher layer to send packet into Network Device with the specified source and destination Addresses.

Returns
whether the Send operation succeeded

Implements ns3::NetDevice.

Definition at line 1176 of file tap-bridge.cc.

References NS_FATAL_ERROR, and NS_LOG_FUNCTION.

◆ SetAddress()

void ns3::TapBridge::SetAddress ( Address  address)
virtual

Set the address of this interface.

Parameters
addressaddress to set

Implements ns3::NetDevice.

Definition at line 1051 of file tap-bridge.cc.

References first::address, ns3::Mac48Address::ConvertFrom(), m_address, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ SetBridgedNetDevice()

void ns3::TapBridge::SetBridgedNetDevice ( Ptr< NetDevice bridgedDevice)

Set the ns-3 net device to bridge.

This method tells the bridge which ns-3 net device it should use to connect the simulation side of the bridge.

Parameters
bridgedDevicedevice to set
Attention
The ns-3 net device that is being set as the device must have an an IP address assigned to it before the simulation is run. This address will be used to set the hardware address of the host Linux device.

Definition at line 917 of file tap-bridge.cc.

References DiscardFromBridgedDevice(), ns3::NetDevice::GetAddress(), ns3::Mac48Address::IsMatchingType(), m_bridgedDevice, m_mode, m_node, ns3::MakeCallback(), NS_ASSERT_MSG, NS_FATAL_ERROR, NS_LOG_FUNCTION, ReceiveFromBridgedDevice(), ns3::NetDevice::SetPromiscReceiveCallback(), ns3::NetDevice::SetReceiveCallback(), ns3::NetDevice::SupportsSendFrom(), and USE_BRIDGE.

+ Here is the call graph for this function:

◆ SetIfIndex()

void ns3::TapBridge::SetIfIndex ( const uint32_t  index)
virtual
Parameters
indexifIndex of the device

Implements ns3::NetDevice.

Definition at line 1030 of file tap-bridge.cc.

References m_ifIndex, and NS_LOG_FUNCTION.

◆ SetMode()

void ns3::TapBridge::SetMode ( TapBridge::Mode  mode)

Set the operating mode of this device.

Parameters
modeThe operating mode of this device.

Definition at line 1065 of file tap-bridge.cc.

References m_mode, and NS_LOG_FUNCTION.

Referenced by GetTypeId().

+ Here is the caller graph for this function:

◆ SetMtu()

bool ns3::TapBridge::SetMtu ( const uint16_t  mtu)
virtual
Parameters
mtuMTU value, in bytes, to set for the device
Returns
whether the MTU value was within legal bounds

Override for default MTU defined on a per-type basis.

Implements ns3::NetDevice.

Definition at line 1079 of file tap-bridge.cc.

References m_mtu, and NS_LOG_FUNCTION.

Referenced by GetTypeId().

+ Here is the caller graph for this function:

◆ SetNode()

void ns3::TapBridge::SetNode ( Ptr< Node node)
virtual
Parameters
nodethe node associated to this netdevice.

This method is called from ns3::Node::AddDevice.

Implements ns3::NetDevice.

Definition at line 1191 of file tap-bridge.cc.

References m_node, and NS_LOG_FUNCTION.

◆ SetPromiscReceiveCallback()

void ns3::TapBridge::SetPromiscReceiveCallback ( NetDevice::PromiscReceiveCallback  cb)
virtual
Parameters
cbcallback to invoke whenever a packet has been received in promiscuous mode and must be forwarded to the higher layers.

Enables netdevice promiscuous mode and sets the callback that will handle promiscuous mode packets. Note, promiscuous mode packets means all packets, including those packets that can be sensed by the netdevice but which are intended to be received by other hosts.

Implements ns3::NetDevice.

Definition at line 1212 of file tap-bridge.cc.

References m_promiscRxCallback, and NS_LOG_FUNCTION.

◆ SetReceiveCallback()

void ns3::TapBridge::SetReceiveCallback ( NetDevice::ReceiveCallback  cb)
virtual
Parameters
cbcallback to invoke whenever a packet has been received and must be forwarded to the higher layers.

Set the callback to be used to notify higher layers when a packet has been received.

Implements ns3::NetDevice.

Definition at line 1205 of file tap-bridge.cc.

References m_rxCallback, and NS_LOG_FUNCTION.

◆ Start()

void ns3::TapBridge::Start ( Time  tStart)

Set a start time for the device.

The tap bridge consumes a non-trivial amount of time to start. It starts up in the context of a scheduled event to ensure that all configuration has been completed before extracting the configuration (IP addresses, etc.) In order to allow a more reasonable start-up sequence than a thundering herd of devices, the time at which each device starts is also configurable bot via the Attribute system and via this call.

Parameters
tStartthe start time

Definition at line 178 of file tap-bridge.cc.

References ns3::Simulator::Cancel(), m_startEvent, NS_LOG_FUNCTION, ns3::Simulator::Schedule(), and StartTapDevice().

Referenced by TapBridge().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ StartTapDevice()

void ns3::TapBridge::StartTapDevice ( void  )
private

Spin up the device.

Definition at line 201 of file tap-bridge.cc.

References CreateTap(), ns3::Node::GetId(), GetNode(), m_fdReader, m_nodeId, m_sock, ns3::MakeCallback(), NotifyLinkUp(), NS_ABORT_MSG_IF, NS_LOG_FUNCTION, NS_LOG_LOGIC, and ReadCallback().

Referenced by Start().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Stop()

void ns3::TapBridge::Stop ( Time  tStop)

Set a stop time for the device.

Parameters
tStopthe stop time
See also
TapBridge::Start

Definition at line 190 of file tap-bridge.cc.

References ns3::Simulator::Cancel(), m_startEvent, m_stopEvent, NS_LOG_FUNCTION, ns3::Simulator::Schedule(), and StopTapDevice().

+ Here is the call graph for this function:

◆ StopTapDevice()

void ns3::TapBridge::StopTapDevice ( void  )
private

Tear down the device.

Definition at line 243 of file tap-bridge.cc.

References m_fdReader, m_sock, and NS_LOG_FUNCTION.

Referenced by ~TapBridge(), and Stop().

+ Here is the caller graph for this function:

◆ SupportsSendFrom()

bool ns3::TapBridge::SupportsSendFrom ( ) const
virtual
Returns
true if this interface supports a bridging mode, false otherwise.

Implements ns3::NetDevice.

Definition at line 1219 of file tap-bridge.cc.

References NS_LOG_FUNCTION.

Member Data Documentation

◆ m_address

Mac48Address ns3::TapBridge::m_address
private

The (unused) MAC address of the TapBridge net device.

Since the TapBridge is implemented as a ns-3 net device, it is required to implement certain functionality. In this case, the TapBridge is automatically assigned a MAC address, but it is not used.

Definition at line 385 of file tap-bridge.h.

Referenced by GetAddress(), and SetAddress().

◆ m_bridgedDevice

Ptr<NetDevice> ns3::TapBridge::m_bridgedDevice
private

The ns-3 net device to which we are bridging.

Definition at line 429 of file tap-bridge.h.

Referenced by ~TapBridge(), CreateTap(), ForwardToBridgedDevice(), GetBridgedNetDevice(), ReceiveFromBridgedDevice(), and SetBridgedNetDevice().

◆ m_fdReader

Ptr<TapBridgeFdReader> ns3::TapBridge::m_fdReader
private

Includes the ns-3 read thread used to do blocking reads on the fd corresponding to the host device.

Definition at line 371 of file tap-bridge.h.

Referenced by StartTapDevice(), and StopTapDevice().

◆ m_ifIndex

uint32_t ns3::TapBridge::m_ifIndex
private

The ns-3 interface index of this TapBridge net device.

Definition at line 342 of file tap-bridge.h.

Referenced by GetIfIndex(), and SetIfIndex().

◆ m_linkChangeCallbacks

TracedCallback ns3::TapBridge::m_linkChangeCallbacks
private

Callbacks to fire if the link changes state (up or down).

Definition at line 465 of file tap-bridge.h.

Referenced by AddLinkChangeCallback(), and NotifyLinkUp().

◆ m_linkUp

bool ns3::TapBridge::m_linkUp
private

Flag indicating whether or not the link is up.

In this case, whether or not ns-3 is connected to the underlying TAP device with a file descriptor.

Definition at line 453 of file tap-bridge.h.

Referenced by IsLinkUp(), and NotifyLinkUp().

◆ m_mode

Mode ns3::TapBridge::m_mode
private

The operating mode of the bridge.

Tells basically who creates and configures the underlying network tap.

Definition at line 377 of file tap-bridge.h.

Referenced by CreateTap(), ForwardToBridgedDevice(), GetMode(), ReceiveFromBridgedDevice(), SetBridgedNetDevice(), and SetMode().

◆ m_mtu

uint16_t ns3::TapBridge::m_mtu
private

The common mtu to use for the net devices.

Definition at line 347 of file tap-bridge.h.

Referenced by GetMtu(), and SetMtu().

◆ m_node

Ptr<Node> ns3::TapBridge::m_node
private

Pointer to the (ghost) Node to which we are connected.

Definition at line 336 of file tap-bridge.h.

Referenced by GetNode(), ReceiveFromBridgedDevice(), SetBridgedNetDevice(), and SetNode().

◆ m_nodeId

uint32_t ns3::TapBridge::m_nodeId
private

a copy of the node id so the read thread doesn't have to GetNode() in in order to find the node ID.

Thread unsafe reference counting in multithreaded apps is not a good thing.

Definition at line 446 of file tap-bridge.h.

Referenced by ReadCallback(), and StartTapDevice().

◆ m_ns3AddressRewritten

bool ns3::TapBridge::m_ns3AddressRewritten
private

Whether the MAC address of the underlying ns-3 device has already been rewritten is stored in this variable (for UseLocal/UseBridge mode only).

Definition at line 434 of file tap-bridge.h.

Referenced by CreateTap(), and ForwardToBridgedDevice().

◆ m_packetBuffer

uint8_t* ns3::TapBridge::m_packetBuffer
private

A 64K buffer to hold packet data while it is being sent.

Definition at line 439 of file tap-bridge.h.

Referenced by TapBridge(), ~TapBridge(), and ReceiveFromBridgedDevice().

◆ m_promiscRxCallback

NetDevice::PromiscReceiveCallback ns3::TapBridge::m_promiscRxCallback
private

Callback used to hook the promiscuous packet receive callback of the TapBridge ns-3 net device.

This is never called, and therefore no packets will ever be received forwarded up the IP stack on the ghost node through this device.

Note that we intercept the similar callback in the bridged device in order to do the actual bridging between the bridged ns-3 net device and the Tap device on the host.

Definition at line 331 of file tap-bridge.h.

Referenced by SetPromiscReceiveCallback().

◆ m_rxCallback

NetDevice::ReceiveCallback ns3::TapBridge::m_rxCallback
private

Callback used to hook the standard packet receive callback of the TapBridge ns-3 net device.

This is never called, and therefore no packets will ever be received forwarded up the IP stack on the ghost node through this device.

Definition at line 320 of file tap-bridge.h.

Referenced by SetReceiveCallback().

◆ m_sock

int ns3::TapBridge::m_sock
private

The socket (actually interpreted as fd) to use to talk to the Tap device on the real internet host.

Definition at line 353 of file tap-bridge.h.

Referenced by CreateTap(), ReceiveFromBridgedDevice(), StartTapDevice(), and StopTapDevice().

◆ m_startEvent

EventId ns3::TapBridge::m_startEvent
private

The ID of the ns-3 event used to schedule the start up of the underlying host Tap device and ns-3 read thread.

Definition at line 359 of file tap-bridge.h.

Referenced by Start(), and Stop().

◆ m_stopEvent

EventId ns3::TapBridge::m_stopEvent
private

The ID of the ns-3 event used to schedule the tear down of the underlying host Tap device and ns-3 read thread.

Definition at line 365 of file tap-bridge.h.

Referenced by Stop().

◆ m_tapDeviceName

std::string ns3::TapBridge::m_tapDeviceName
private

The name of the device to create on the host.

If the device name is the empty string, we allow the host kernel to choose a name.

Definition at line 401 of file tap-bridge.h.

Referenced by CreateTap(), and GetTypeId().

◆ m_tapGateway

Ipv4Address ns3::TapBridge::m_tapGateway
private

The IP address to use as the device default gateway on the host.

Definition at line 406 of file tap-bridge.h.

Referenced by CreateTap(), and GetTypeId().

◆ m_tapIp

Ipv4Address ns3::TapBridge::m_tapIp
private

The IP address to use as the device IP on the host.

Definition at line 411 of file tap-bridge.h.

Referenced by CreateTap(), and GetTypeId().

◆ m_tapMac

Mac48Address ns3::TapBridge::m_tapMac
private

The MAC address to use as the hardware address on the host; only used in UseLocal mode.

This value comes from the MAC address assigned to the bridged ns-3 net device and matches the MAC address of the underlying network TAP which we configured to have the same value.

Definition at line 419 of file tap-bridge.h.

Referenced by CreateTap(), and GetTypeId().

◆ m_tapNetmask

Ipv4Mask ns3::TapBridge::m_tapNetmask
private

The network mask to assign to the device created on the host.

Definition at line 424 of file tap-bridge.h.

Referenced by CreateTap(), and GetTypeId().

◆ m_tStart

Time ns3::TapBridge::m_tStart
private

Time to start spinning up the device.

Definition at line 390 of file tap-bridge.h.

Referenced by TapBridge(), and GetTypeId().

◆ m_tStop

Time ns3::TapBridge::m_tStop
private

Time to start tearing down the device.

Definition at line 395 of file tap-bridge.h.

Referenced by GetTypeId().

◆ m_verbose

bool ns3::TapBridge::m_verbose
private

Flag indicating whether or not the link is up.

In this case, whether or not ns-3 is connected to the underlying TAP device with a file descriptor.

Definition at line 460 of file tap-bridge.h.

Referenced by CreateTap(), and GetTypeId().


The documentation for this class was generated from the following files: