12#include "ns3/error-model.h"
13#include "ns3/llc-snap-header.h"
15#include "ns3/mac48-address.h"
16#include "ns3/pointer.h"
18#include "ns3/simulator.h"
19#include "ns3/trace-source-accessor.h"
20#include "ns3/uinteger.h"
33 TypeId(
"ns3::PointToPointNetDevice")
35 .SetGroupName(
"PointToPoint")
38 "The MAC-level Maximum Transmission Unit",
43 .AddAttribute(
"Address",
44 "The MAC address of this device.",
48 .AddAttribute(
"DataRate",
49 "The default data rate for point to point links",
53 .AddAttribute(
"ReceiveErrorModel",
54 "The receiver error model used to simulate packet loss",
58 .AddAttribute(
"InterframeGap",
59 "The time to wait between packet (frame) transmissions",
68 .AddAttribute(
"TxQueue",
69 "A queue to use as the transmit queue in the device.",
78 .AddTraceSource(
"MacTx",
79 "Trace source indicating a packet has arrived "
80 "for transmission by this device",
82 "ns3::Packet::TracedCallback")
83 .AddTraceSource(
"MacTxDrop",
84 "Trace source indicating a packet has been dropped "
85 "by the device before transmission",
87 "ns3::Packet::TracedCallback")
88 .AddTraceSource(
"MacPromiscRx",
89 "A packet has been received by this device, "
90 "has been passed up from the physical layer "
91 "and is being forwarded up the local protocol stack. "
92 "This is a promiscuous trace,",
94 "ns3::Packet::TracedCallback")
95 .AddTraceSource(
"MacRx",
96 "A packet has been received by this device, "
97 "has been passed up from the physical layer "
98 "and is being forwarded up the local protocol stack. "
99 "This is a non-promiscuous trace,",
101 "ns3::Packet::TracedCallback")
104 .AddTraceSource (
"MacRxDrop",
105 "Trace source indicating a packet was dropped "
106 "before being forwarded up the stack",
108 "ns3::Packet::TracedCallback")
114 .AddTraceSource(
"PhyTxBegin",
115 "Trace source indicating a packet has begun "
116 "transmitting over the channel",
118 "ns3::Packet::TracedCallback")
119 .AddTraceSource(
"PhyTxEnd",
120 "Trace source indicating a packet has been "
121 "completely transmitted over the channel",
123 "ns3::Packet::TracedCallback")
124 .AddTraceSource(
"PhyTxDrop",
125 "Trace source indicating a packet has been "
126 "dropped by the device during transmission",
128 "ns3::Packet::TracedCallback")
131 .AddTraceSource (
"PhyRxBegin",
132 "Trace source indicating a packet has begun "
133 "being received by the device",
135 "ns3::Packet::TracedCallback")
137 .AddTraceSource(
"PhyRxEnd",
138 "Trace source indicating a packet has been "
139 "completely received by the device",
141 "ns3::Packet::TracedCallback")
142 .AddTraceSource(
"PhyRxDrop",
143 "Trace source indicating a packet has been "
144 "dropped by the device during reception",
146 "ns3::Packet::TracedCallback")
153 .AddTraceSource(
"Sniffer",
154 "Trace source simulating a non-promiscuous packet sniffer "
155 "attached to the device",
157 "ns3::Packet::TracedCallback")
158 .AddTraceSource(
"PromiscSniffer",
159 "Trace source simulating a promiscuous packet sniffer "
160 "attached to the device",
162 "ns3::Packet::TracedCallback");
167 : m_txMachineState(READY),
170 m_currentPkt(nullptr)
194 p->RemoveHeader(ppp);
247 bool result =
m_channel->TransmitStart(p,
this, txTime);
277 NS_LOG_LOGIC(
"No pending packets in device queue after tx complete");
325 uint16_t protocol = 0;
555 uint16_t protocolNumber)
612 for (std::size_t i = 0; i <
m_channel->GetNDevices(); ++i)
617 return tmp->GetAddress();
a polymophic address class
bool IsNull() const
Check for null implementation.
Class for representing data rates.
Time CalculateBytesTxTime(uint32_t bytes) const
Calculate transmission time.
AttributeValue implementation for DataRate.
Ipv4 addresses are stored in host order in this class.
Describes an IPv6 address.
static Mac48Address ConvertFrom(const Address &address)
static Mac48Address GetBroadcast()
AttributeValue implementation for Mac48Address.
Network layer to device interface.
@ PACKET_HOST
Packet addressed to us.
virtual void DoDispose()
Destructor implementation.
A Device for a Point to Point Network Link.
bool IsBroadcast() const override
void AddHeader(Ptr< Packet > p, uint16_t protocolNumber)
Adds the necessary headers and trailers to a packet of data in order to respect the protocol implemen...
static const uint16_t DEFAULT_MTU
Default MTU.
Ptr< Node > GetNode() const override
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
The trace source fired when a packet ends the reception process from the medium.
Address GetMulticast(Ipv4Address multicastGroup) const override
Make and return a MAC multicast address using the provided multicast group.
Address GetBroadcast() const override
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
PointToPointNetDevice()
Construct a PointToPointNetDevice.
Ptr< PointToPointChannel > m_channel
The PointToPointChannel to which this PointToPointNetDevice has been attached.
bool NeedsArp() const override
DataRate m_bps
The data rate that the Net Device uses to simulate packet transmission timing.
bool TransmitStart(Ptr< Packet > p)
Start Sending a Packet Down the Wire.
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired for packets successfully received by the device but are dropped before being f...
TracedCallback m_linkChangeCallbacks
Callback for the link change event.
Address GetRemote() const
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition,...
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
void SetNode(Ptr< Node > node) override
void SetQueue(Ptr< Queue< Packet > > queue)
Attach a queue to the PointToPointNetDevice.
void SetIfIndex(const uint32_t index) override
void AddLinkChangeCallback(Callback< void > callback) override
bool IsLinkUp() const override
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
bool IsPointToPoint() const override
Return true if the net device is on a point-to-point link.
bool Attach(Ptr< PointToPointChannel > ch)
Attach the device to a channel.
static uint16_t EtherToPpp(uint16_t protocol)
Ethernet to PPP protocol number mapping.
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the PointToPointNetDevice.
bool IsMulticast() const override
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
The trace source fired when the phy layer drops a packet before it tries to transmit it.
Ptr< ErrorModel > m_receiveErrorModel
Error model for receive packet events.
void SetInterframeGap(Time t)
Set the interframe gap used to separate packets.
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
bool m_linkUp
Identify if the link is up or not.
uint16_t GetMtu() const override
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
void NotifyLinkUp()
Make the link up and running.
Ptr< Queue< Packet > > GetQueue() const
Get a copy of the attached Queue.
@ READY
The transmitter is ready to begin transmission of a packet.
@ BUSY
The transmitter is busy transmitting a packet.
static uint16_t PppToEther(uint16_t protocol)
PPP to Ethernet protocol number mapping.
Address GetAddress() const override
bool IsBridge() const override
Return true if the net device is acting as a bridge.
Ptr< Channel > GetChannel() const override
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
void DoDispose() override
Dispose of the object.
void SetAddress(Address address) override
Set the address of this interface.
void TransmitComplete()
Stop Sending a Packet Down the Wire and Begin the Interframe Gap.
~PointToPointNetDevice() override
Destroy a PointToPointNetDevice.
static TypeId GetTypeId()
Get the TypeId.
Mac48Address m_address
Mac48Address of this NetDevice.
uint32_t GetIfIndex() const override
Time m_tInterframeGap
The interframe gap that the Net Device uses to throttle packet transmission.
Ptr< Packet > m_currentPkt
Current packet processed.
bool ProcessHeader(Ptr< Packet > p, uint16_t ¶m)
Removes, from a packet of data, all headers and trailers that relate to the protocol implemented by t...
void Receive(Ptr< Packet > p)
Receive a packet from a connected PointToPointChannel.
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium – when the simulate...
Ptr< Queue< Packet > > m_queue
The Queue which this PointToPointNetDevice uses as a packet source.
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device.
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
The trace source fired when a packet ends the transmission process on the medium.
TxMachineState m_txMachineState
The state of the Net Device transmit state machine.
void DoMpiReceive(Ptr< Packet > p)
Handler for MPI receive event.
void SetDataRate(DataRate bps)
Set the Data Rate used for transmission of packets.
uint32_t m_mtu
The Maximum Transmission Unit.
Ptr< Node > m_node
Node owning this NetDevice.
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
bool SetMtu(const uint16_t mtu) override
TracedCallback< Ptr< const Packet > > m_macTxDropTrace
The trace source fired when packets coming into the "top" of the device at the L3/L2 transition are d...
NetDevice::PromiscReceiveCallback m_promiscCallback
Receive callback.
NetDevice::ReceiveCallback m_rxCallback
Receive callback.
void SetPromiscReceiveCallback(PromiscReceiveCallback cb) override
bool SupportsSendFrom() const override
uint32_t m_ifIndex
Index of the interface.
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
Template class for packet Queues.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
AttributeValue implementation for Time.
void ConnectWithoutContext(const CallbackBase &callback)
Append a Callback to the chain (without a context).
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent 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...
Ptr< const AttributeAccessor > MakeDataRateAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeDataRateChecker()
Ptr< const AttributeAccessor > MakeMac48AddressAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeMac48AddressChecker()
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.