20 #include "error-net-device.h"
21 #include "error-channel.h"
23 #include "ns3/packet.h"
25 #include "ns3/pointer.h"
26 #include "ns3/error-model.h"
27 #include "ns3/trace-source-accessor.h"
33 NS_OBJECT_ENSURE_REGISTERED (ErrorNetDevice);
36 ErrorNetDevice::GetTypeId (
void)
38 static TypeId tid = TypeId (
"ns3::ErrorNetDevice")
39 .SetParent<NetDevice> ()
40 .AddConstructor<ErrorNetDevice> ()
41 .AddAttribute (
"ReceiveErrorModel",
42 "The receiver error model used to simulate packet loss",
44 MakePointerAccessor (&ErrorNetDevice::m_receiveErrorModel),
45 MakePointerChecker<ErrorModel> ())
46 .AddTraceSource (
"PhyRxDrop",
47 "Trace source indicating a packet has been dropped by the device during reception",
53 ErrorNetDevice::ErrorNetDevice ()
61 ErrorNetDevice::Receive (Ptr<Packet> packet, uint16_t protocol,
62 Mac48Address to, Mac48Address from)
67 if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) )
77 else if (to.IsBroadcast ())
81 else if (to.IsGroup ())
89 m_rxCallback (
this, packet, protocol, from);
90 if (!m_promiscCallback.IsNull ())
92 m_promiscCallback (
this, packet, protocol, from, to, packetType);
97 ErrorNetDevice::SetChannel (Ptr<ErrorChannel> channel)
100 m_channel->Add (
this);
106 m_receiveErrorModel = em;
199 m_channel->Send (packet, protocolNumber, to, m_address,
this);
205 NS_LOG_FUNCTION (packet << source << dest << protocolNumber << *packet);
208 m_channel->Send (packet, protocolNumber, to, from,
this);
238 m_receiveErrorModel = 0;
246 m_promiscCallback = cb;
virtual uint32_t GetIfIndex(void) const
virtual Address GetBroadcast(void) const
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
#define NS_LOG_COMPONENT_DEFINE(name)
virtual void DoDispose(void)
virtual bool SetMtu(const uint16_t mtu)
virtual bool IsBroadcast(void) const
virtual bool IsLinkUp(void) const
virtual Address GetAddress(void) const
virtual void SetIfIndex(const uint32_t index)
a polymophic address class
static Mac48Address GetMulticast(Ipv4Address address)
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
virtual bool SupportsSendFrom(void) const
virtual Ptr< Channel > GetChannel(void) const
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
static Mac48Address ConvertFrom(const Address &address)
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
virtual uint16_t GetMtu(void) const
virtual void SetNode(Ptr< Node > node)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
void SetReceiveErrorModel(Ptr< ErrorModel > em)
virtual void SetAddress(Address address)
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
Describes an IPv6 address.
Ipv4 addresses are stored in host order in this class.
virtual Ptr< Node > GetNode(void) const
virtual bool NeedsArp(void) const
virtual void DoDispose(void)
virtual void AddLinkChangeCallback(Callback< void > callback)
virtual bool IsMulticast(void) const
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)