22 #include "ns3/queue.h"
23 #include "ns3/simulator.h"
24 #include "ns3/mac48-address.h"
25 #include "ns3/llc-snap-header.h"
26 #include "ns3/error-model.h"
27 #include "virtual-net-device.h"
28 #include "ns3/channel.h"
29 #include "ns3/trace-source-accessor.h"
30 #include "ns3/uinteger.h"
37 NS_OBJECT_ENSURE_REGISTERED (VirtualNetDevice);
40 VirtualNetDevice::GetTypeId (
void)
42 static TypeId tid = TypeId (
"ns3::VirtualNetDevice")
43 .SetParent<NetDevice> ()
44 .AddConstructor<VirtualNetDevice> ()
45 .AddAttribute (
"Mtu",
"The MAC-level Maximum Transmission Unit",
49 MakeUintegerChecker<uint16_t> ())
50 .AddTraceSource (
"MacTx",
51 "Trace source indicating a packet has arrived for transmission by this device",
53 .AddTraceSource (
"MacPromiscRx",
54 "A packet has been received by this device, has been passed up from the physical layer "
55 "and is being forwarded up the local protocol stack. This is a promiscuous trace,",
57 .AddTraceSource (
"MacRx",
58 "A packet has been received by this device, has been passed up from the physical layer "
59 "and is being forwarded up the local protocol stack. This is a non-promiscuous trace,",
64 .AddTraceSource (
"Sniffer",
65 "Trace source simulating a non-promiscuous packet sniffer attached to the device",
67 .AddTraceSource (
"PromiscSniffer",
68 "Trace source simulating a promiscuous packet sniffer attached to the device",
74 VirtualNetDevice::VirtualNetDevice ()
77 m_supportsSendFrom =
true;
78 m_isPointToPoint =
true;
91 m_needsArp = needsArp;
97 m_supportsSendFrom = supportsSendFrom;
103 m_isPointToPoint = isPointToPoint;
114 VirtualNetDevice::~VirtualNetDevice()
137 m_promiscSnifferTrace (packet);
138 if (!m_promiscRxCallback.IsNull ())
140 m_macPromiscRxTrace (packet);
141 m_promiscRxCallback (
this, packet, protocol, source, destination, packetType);
151 m_snifferTrace (packet);
152 m_macRxTrace (packet);
153 return m_rxCallback (
this, packet, protocol, source);
238 return m_isPointToPoint;
244 m_macTxTrace (packet);
245 if (m_sendCb (packet,
GetAddress (), dest, protocolNumber))
256 m_macTxTrace (packet);
257 if (m_sendCb (packet, source, dest, protocolNumber))
291 m_promiscRxCallback = cb;
297 return m_supportsSendFrom;
void SetNeedsArp(bool needsArp)
Configure whether the virtual device needs ARP.
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
virtual bool SupportsSendFrom() const
virtual void DoDispose(void)
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
bool SetMtu(const uint16_t mtu)
Configure the reported MTU for the virtual device.
virtual void DoDispose(void)
bool Receive(Ptr< Packet > packet, uint16_t protocol, const Address &source, const Address &destination, PacketType packetType)
#define NS_LOG_FUNCTION_NOARGS()
virtual bool NeedsArp(void) const
a polymophic address class
virtual bool IsBroadcast(void) const
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
virtual Address GetAddress(void) const
virtual uint16_t GetMtu(void) const
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
virtual bool IsMulticast(void) const
virtual Ptr< Channel > GetChannel(void) const
virtual void SetAddress(Address address)
virtual void SetIfIndex(const uint32_t index)
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
void SetIsPointToPoint(bool isPointToPoint)
Configure whether the virtual device is point-to-point.
void SetSupportsSendFrom(bool supportsSendFrom)
Configure whether the virtual device supports SendFrom.
virtual void SetNode(Ptr< Node > node)
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
virtual void AddLinkChangeCallback(Callback< void > callback)
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
virtual Ptr< Node > GetNode(void) const
Describes an IPv6 address.
Ipv4 addresses are stored in host order in this class.
virtual uint32_t GetIfIndex(void) const
virtual bool IsLinkUp(void) const
void SetSendCallback(SendCallback transmitCb)
Set the user callback to be called when a L2 packet is to be transmitted.
virtual Address GetBroadcast(void) const