20 #include "ns3/queue.h"
21 #include "ns3/simulator.h"
22 #include "ns3/mac48-address.h"
23 #include "ns3/llc-snap-header.h"
24 #include "ns3/error-model.h"
25 #include "ns3/trace-source-accessor.h"
26 #include "ns3/uinteger.h"
27 #include "ns3/pointer.h"
41 static TypeId tid =
TypeId (
"ns3::PointToPointNetDevice")
43 .SetGroupName (
"PointToPoint")
45 .AddAttribute (
"Mtu",
"The MAC-level Maximum Transmission Unit",
49 MakeUintegerChecker<uint16_t> ())
50 .AddAttribute (
"Address",
51 "The MAC address of this device.",
55 .AddAttribute (
"DataRate",
56 "The default data rate for point to point links",
60 .AddAttribute (
"ReceiveErrorModel",
61 "The receiver error model used to simulate packet loss",
64 MakePointerChecker<ErrorModel> ())
65 .AddAttribute (
"InterframeGap",
66 "The time to wait between packet (frame) transmissions",
75 .AddAttribute (
"TxQueue",
76 "A queue to use as the transmit queue in the device.",
79 MakePointerChecker<Queue<Packet> > ())
85 .AddTraceSource (
"MacTx",
86 "Trace source indicating a packet has arrived "
87 "for transmission by this device",
89 "ns3::Packet::TracedCallback")
90 .AddTraceSource (
"MacTxDrop",
91 "Trace source indicating a packet has been dropped "
92 "by the device before transmission",
94 "ns3::Packet::TracedCallback")
95 .AddTraceSource (
"MacPromiscRx",
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 promiscuous trace,",
101 "ns3::Packet::TracedCallback")
102 .AddTraceSource (
"MacRx",
103 "A packet has been received by this device, "
104 "has been passed up from the physical layer "
105 "and is being forwarded up the local protocol stack. "
106 "This is a non-promiscuous trace,",
108 "ns3::Packet::TracedCallback")
111 .AddTraceSource (
"MacRxDrop",
112 "Trace source indicating a packet was dropped "
113 "before being forwarded up the stack",
115 "ns3::Packet::TracedCallback")
121 .AddTraceSource (
"PhyTxBegin",
122 "Trace source indicating a packet has begun "
123 "transmitting over the channel",
125 "ns3::Packet::TracedCallback")
126 .AddTraceSource (
"PhyTxEnd",
127 "Trace source indicating a packet has been "
128 "completely transmitted over the channel",
130 "ns3::Packet::TracedCallback")
131 .AddTraceSource (
"PhyTxDrop",
132 "Trace source indicating a packet has been "
133 "dropped by the device during transmission",
135 "ns3::Packet::TracedCallback")
138 .AddTraceSource (
"PhyRxBegin",
139 "Trace source indicating a packet has begun "
140 "being received by the device",
142 "ns3::Packet::TracedCallback")
144 .AddTraceSource (
"PhyRxEnd",
145 "Trace source indicating a packet has been "
146 "completely received by the device",
148 "ns3::Packet::TracedCallback")
149 .AddTraceSource (
"PhyRxDrop",
150 "Trace source indicating a packet has been "
151 "dropped by the device during reception",
153 "ns3::Packet::TracedCallback")
160 .AddTraceSource (
"Sniffer",
161 "Trace source simulating a non-promiscuous packet sniffer "
162 "attached to the device",
164 "ns3::Packet::TracedCallback")
165 .AddTraceSource (
"PromiscSniffer",
166 "Trace source simulating a promiscuous packet sniffer "
167 "attached to the device",
169 "ns3::Packet::TracedCallback")
177 m_txMachineState (READY),
287 NS_LOG_LOGIC (
"No pending packets in device queue after tx complete");
335 uint16_t protocol = 0;
510 uint16_t protocolNumber)
563 uint16_t protocolNumber)
620 for (std::size_t i = 0; i <
m_channel->GetNDevices (); ++i)
654 case 0x0021:
return 0x0800;
655 case 0x0057:
return 0x86DD;
656 default:
NS_ASSERT_MSG (
false,
"PPP Protocol number not defined!");
667 case 0x0800:
return 0x0021;
668 case 0x86DD:
return 0x0057;
669 default:
NS_ASSERT_MSG (
false,
"PPP Protocol number not defined!");
a polymophic address class
bool IsNull(void) 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)
AttributeValue implementation for Mac48Address.
Network layer to device interface.
virtual Address GetAddress(void) const =0
@ PACKET_HOST
Packet addressed oo us.
virtual void DoDispose(void)
Destructor implementation.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
void AddHeader(const Header &header)
Add header to this packet.
uint64_t GetUid(void) const
Returns the packet's Uid.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
A Device for a Point to Point Network Link.
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...
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
static TypeId GetTypeId(void)
Get the TypeId.
static const uint16_t DEFAULT_MTU
Default MTU.
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
The trace source fired when a packet ends the reception process from the medium.
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
Address GetRemote(void) const
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.
virtual bool IsBroadcast(void) const
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.
TracedCallback< Ptr< const Packet > > m_macTxTrace
The trace source fired when packets come into the "top" of the device at the L3/L2 transition,...
void SetQueue(Ptr< Queue< Packet > > queue)
Attach a queue to the PointToPointNetDevice.
virtual bool SupportsSendFrom(void) const
virtual bool SetMtu(const uint16_t mtu)
void NotifyLinkUp(void)
Make the link up and running.
bool Attach(Ptr< PointToPointChannel > ch)
Attach the device to a channel.
virtual void DoDispose(void)
Dispose of the object.
virtual uint32_t GetIfIndex(void) const
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.
virtual Ptr< Channel > GetChannel(void) const
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.
virtual bool NeedsArp(void) const
void SetInterframeGap(Time t)
Set the interframe gap used to separate packets.
virtual bool IsLinkUp(void) const
virtual void SetIfIndex(const uint32_t index)
void TransmitComplete(void)
Stop Sending a Packet Down the Wire and Begin the Interframe Gap.
bool m_linkUp
Identify if the link is up or not.
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
Ptr< Queue< Packet > > GetQueue(void) const
Get a copy of the attached Queue.
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
@ 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.
virtual uint16_t GetMtu(void) const
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
virtual Ptr< Node > GetNode(void) const
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
virtual Address GetBroadcast(void) const
Mac48Address m_address
Mac48Address of this NetDevice.
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...
virtual void AddLinkChangeCallback(Callback< void > callback)
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.
virtual void SetAddress(Address address)
Set the address of this interface.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
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.
virtual ~PointToPointNetDevice()
Destroy a PointToPointNetDevice.
TxMachineState m_txMachineState
The state of the Net Device transmit state machine.
virtual void SetNode(Ptr< Node > node)
void DoMpiReceive(Ptr< Packet > p)
Handler for MPI receive event.
void SetDataRate(DataRate bps)
Set the Data Rate used for transmission of packets.
virtual bool IsMulticast(void) const
virtual Address GetAddress(void) const
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.
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.
uint32_t m_ifIndex
Index of the interface.
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
Hold objects of type Ptr<T>.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const enum 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(void)
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(void)
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
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 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.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.