|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
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),
257 bool result =
m_channel->TransmitStart (p,
this, txTime);
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 unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
static uint16_t PppToEther(uint16_t protocol)
PPP to Ethernet protocol number mapping.
AttributeValue implementation for DataRate.
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
NetDevice::PromiscReceiveCallback m_promiscCallback
Receive callback.
Time CalculateBytesTxTime(uint32_t bytes) const
Calculate transmission time.
static const uint16_t DEFAULT_MTU
Default MTU.
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
Ptr< const AttributeAccessor > MakeMac48AddressAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
The trace source fired when a packet ends the transmission process on the medium.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
void AddHeader(const Header &header)
Add header to this packet.
virtual Address GetAddress(void) const =0
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool IsNull(void) const
Check for null implementation.
void ConnectWithoutContext(const CallbackBase &callback)
Append a Callback to the chain (without a context).
Ptr< const AttributeAccessor > MakeDataRateAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
static uint16_t EtherToPpp(uint16_t protocol)
Ethernet to PPP protocol number mapping.
Address GetRemote(void) const
@ READY
The transmitter is ready to begin transmission of a packet.
PointToPointNetDevice()
Construct a PointToPointNetDevice.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
uint32_t m_mtu
The Maximum Transmission Unit.
Ipv4 addresses are stored in host order in this class.
Describes an IPv6 address.
@ PACKET_HOST
Packet addressed oo us.
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
The trace source fired when a packet ends the reception process from the medium.
Hold objects of type Ptr<T>.
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
The trace source fired when the phy layer drops a packet before it tries to transmit it.
virtual void DoDispose(void)
Dispose of the object.
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
TxMachineState m_txMachineState
The state of the Net Device transmit state machine.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
AttributeValue implementation for Mac48Address.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Time m_tInterframeGap
The interframe gap that the Net Device uses to throttle packet transmission.
virtual bool NeedsArp(void) const
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
void TransmitComplete(void)
Stop Sending a Packet Down the Wire and Begin the Interframe Gap.
Ptr< Queue< Packet > > m_queue
The Queue which this PointToPointNetDevice uses as a packet source.
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
bool m_linkUp
Identify if the link is up or not.
@ BUSY
The transmitter is busy transmitting a packet.
Ptr< const AttributeChecker > MakeMac48AddressChecker(void)
Class for representing data rates.
void SetInterframeGap(Time t)
Set the interframe gap used to separate packets.
a polymophic address class
static Mac48Address ConvertFrom(const Address &address)
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium – when the simulate...
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
virtual bool IsLinkUp(void) const
NetDevice::ReceiveCallback m_rxCallback
Receive callback.
Simulation virtual time values and global simulation resolution.
virtual void AddLinkChangeCallback(Callback< void > callback)
Mac48Address m_address
Mac48Address of this NetDevice.
Ptr< Packet > m_currentPkt
Current packet processed.
bool Attach(Ptr< PointToPointChannel > ch)
Attach the device to a channel.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the PointToPointNetDevice.
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 Receive(Ptr< Packet > p)
Receive a packet from a connected PointToPointChannel.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
static TypeId GetTypeId(void)
Get the TypeId.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
virtual Address GetBroadcast(void) const
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
Ptr< Queue< Packet > > GetQueue(void) const
Get a copy of the attached Queue.
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...
virtual bool SetMtu(const uint16_t mtu)
virtual uint16_t GetMtu(void) const
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
virtual bool IsMulticast(void) const
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
virtual uint32_t GetIfIndex(void) const
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
DataRate m_bps
The data rate that the Net Device uses to simulate packet transmission timing.
virtual void SetAddress(Address address)
Set the address of this interface.
AttributeValue implementation for Time.
virtual void SetNode(Ptr< Node > node)
A Device for a Point to Point Network Link.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device.
uint32_t m_ifIndex
Index of the interface.
virtual bool IsBroadcast(void) const
void SetQueue(Ptr< Queue< Packet > > queue)
Attach a queue to the PointToPointNetDevice.
void DoMpiReceive(Ptr< Packet > p)
Handler for MPI receive event.
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...
Ptr< Node > m_node
Node owning this NetDevice.
Hold an unsigned integer type.
virtual Address GetAddress(void) const
virtual void SetIfIndex(const uint32_t index)
TracedCallback m_linkChangeCallbacks
Callback for the link change event.
Ptr< ErrorModel > m_receiveErrorModel
Error model for receive packet events.
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
virtual ~PointToPointNetDevice()
Destroy a PointToPointNetDevice.
void NotifyLinkUp(void)
Make the link up and running.
Ptr< PointToPointChannel > m_channel
The PointToPointChannel to which this PointToPointNetDevice has been attached.
bool TransmitStart(Ptr< Packet > p)
Start Sending a Packet Down the Wire.
virtual Ptr< Node > GetNode(void) const
virtual void DoDispose(void)
Destructor implementation.
virtual bool SupportsSendFrom(void) const
virtual Ptr< Channel > GetChannel(void) const
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 SetDataRate(DataRate bps)
Set the Data Rate used for transmission of packets.
Ptr< const AttributeChecker > MakeDataRateChecker(void)
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
uint64_t GetUid(void) const
Returns the packet's Uid.
Network layer to device interface.
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...