|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
22 #include "ns3/queue.h"
23 #include "ns3/simulator.h"
24 #include "ns3/ethernet-header.h"
25 #include "ns3/ethernet-trailer.h"
26 #include "ns3/llc-snap-header.h"
27 #include "ns3/error-model.h"
29 #include "ns3/boolean.h"
30 #include "ns3/uinteger.h"
31 #include "ns3/pointer.h"
32 #include "ns3/trace-source-accessor.h"
47 .SetGroupName (
"Csma")
49 .AddAttribute (
"Address",
50 "The MAC address of this device.",
54 .AddAttribute (
"Mtu",
"The MAC-level Maximum Transmission Unit",
58 MakeUintegerChecker<uint16_t> ())
59 .AddAttribute (
"EncapsulationMode",
60 "The link-layer encapsulation type to use.",
65 .AddAttribute (
"SendEnable",
66 "Enable or disable the transmitter section of the device.",
70 .AddAttribute (
"ReceiveEnable",
71 "Enable or disable the receiver section of the device.",
75 .AddAttribute (
"ReceiveErrorModel",
76 "The receiver error model used to simulate packet loss",
79 MakePointerChecker<ErrorModel> ())
85 .AddAttribute (
"TxQueue",
86 "A queue to use as the transmit queue in the device.",
89 MakePointerChecker<Queue<Packet> > ())
95 .AddTraceSource (
"MacTx",
96 "Trace source indicating a packet has "
97 "arrived for transmission by this device",
99 "ns3::Packet::TracedCallback")
100 .AddTraceSource (
"MacTxDrop",
101 "Trace source indicating a packet has been "
102 "dropped by the device before transmission",
104 "ns3::Packet::TracedCallback")
105 .AddTraceSource (
"MacPromiscRx",
106 "A packet has been received by this device, "
107 "has been passed up from the physical layer "
108 "and is being forwarded up the local protocol stack. "
109 "This is a promiscuous trace,",
111 "ns3::Packet::TracedCallback")
112 .AddTraceSource (
"MacRx",
113 "A packet has been received by this device, "
114 "has been passed up from the physical layer "
115 "and is being forwarded up the local protocol stack. "
116 "This is a non-promiscuous trace,",
118 "ns3::Packet::TracedCallback")
121 .AddTraceSource (
"MacRxDrop",
122 "Trace source indicating a packet was received, "
123 "but dropped before being forwarded up the stack",
125 "ns3::Packet::TracedCallback")
127 .AddTraceSource (
"MacTxBackoff",
128 "Trace source indicating a packet has been "
129 "delayed by the CSMA backoff process",
131 "ns3::Packet::TracedCallback")
136 .AddTraceSource (
"PhyTxBegin",
137 "Trace source indicating a packet has "
138 "begun transmitting over the channel",
140 "ns3::Packet::TracedCallback")
141 .AddTraceSource (
"PhyTxEnd",
142 "Trace source indicating a packet has been "
143 "completely transmitted over the channel",
145 "ns3::Packet::TracedCallback")
146 .AddTraceSource (
"PhyTxDrop",
147 "Trace source indicating a packet has been "
148 "dropped by the device during transmission",
150 "ns3::Packet::TracedCallback")
153 .AddTraceSource (
"PhyRxBegin",
154 "Trace source indicating a packet has "
155 "begun being received by the device",
157 "ns3::Packet::TracedCallback")
159 .AddTraceSource (
"PhyRxEnd",
160 "Trace source indicating a packet has been "
161 "completely received by the device",
163 "ns3::Packet::TracedCallback")
164 .AddTraceSource (
"PhyRxDrop",
165 "Trace source indicating a packet has been "
166 "dropped by the device during reception",
168 "ns3::Packet::TracedCallback")
172 .AddTraceSource (
"Sniffer",
173 "Trace source simulating a non-promiscuous "
174 "packet sniffer attached to the device",
176 "ns3::Packet::TracedCallback")
177 .AddTraceSource (
"PromiscSniffer",
178 "Trace source simulating a promiscuous "
179 "packet sniffer attached to the device",
181 "ns3::Packet::TracedCallback")
300 NS_LOG_FUNCTION (slotTime << minSlots << maxSlots << ceiling << maxRetries);
323 uint16_t lengthType = 0;
327 NS_LOG_LOGIC (
"Encapsulating packet as DIX (type interpretation)");
332 lengthType = protocolNumber;
343 memset (buffer, 0, 46);
350 NS_LOG_LOGIC (
"Encapsulating packet as LLC (length interpretation)");
372 memset (buffer, 0, 46);
378 "CsmaNetDevice::AddHeader(): 802.3 Length/Type field with LLC/SNAP: "
379 "length interpretation must not exceed device frame size minus overhead");
384 NS_FATAL_ERROR (
"CsmaNetDevice::AddHeader(): Unknown packet encapsulation mode");
388 NS_LOG_LOGIC (
"header.SetLengthType (" << lengthType <<
")");
402 CsmaNetDevice::ProcessHeader (
Ptr<Packet> p, uint16_t & param)
421 param = header.GetLengthType ();
427 param = llc.GetType ();
432 NS_FATAL_ERROR (
"CsmaNetDevice::ProcessHeader(): Unknown packet encapsulation mode");
511 NS_LOG_WARN (
"Channel TransmitStart returns an error");
569 NS_ASSERT_MSG (packet != 0,
"CsmaNetDevice::TransmitAbort(): IsEmpty false but no Packet on queue?");
638 NS_ASSERT_MSG (packet != 0,
"CsmaNetDevice::TransmitReadyEvent(): IsEmpty false but no Packet on queue?");
696 if (senderDevice ==
this)
736 bool crcGood = trailer.
CheckFcs (packet);
966 AddHeader (packet, source, destination, protocolNumber);
974 if (
m_queue->Enqueue (packet) ==
false)
987 if (
m_queue->IsEmpty () ==
false)
990 NS_ASSERT_MSG (packet != 0,
"CsmaNetDevice::SendFrom(): IsEmpty false but no Packet on queue?");
DataRate m_bps
The data rate that the Net Device uses to simulate packet transmission timing.
a unique identifier for an interface.
@ PACKET_BROADCAST
Packet addressed to all.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void TransmitStart()
Start Sending a Packet Down the Wire.
EncapsulationMode
Enumeration of the types of packets supported in the class.
Ptr< CsmaChannel > m_channel
The CsmaChannel to which this CsmaNetDevice has been attached.
Mac48Address m_address
The MAC address which has been assigned to this device.
virtual ~CsmaNetDevice()
Destroy a CsmaNetDevice.
Ptr< Queue< Packet > > m_queue
The Queue which this CsmaNetDevice uses as a packet source.
#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,...
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
AttributeValue implementation for Boolean.
static Mac48Address GetMulticast(Ipv4Address address)
Time CalculateBytesTxTime(uint32_t bytes) const
Calculate transmission time.
Ptr< const AttributeAccessor > MakeMac48AddressAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
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.
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
virtual bool SupportsSendFrom(void) const
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
The trace source fired when the phy layer drops a packet as it tries to transmit it.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool m_sendEnable
Enable net device to send packets.
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 IsNull(void) const
Check for null implementation.
void ConnectWithoutContext(const CallbackBase &callback)
Append a Callback to the chain (without a context).
Ptr< const AttributeChecker > MakeEnumChecker(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
@ BACKOFF
The transmitter is waiting for the channel to be free.
void EnableFcs(bool enable)
Enable or disable FCS checking and calculations.
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
EncapsulationMode m_encapMode
The type of packet that should be created by the AddHeader function and that should be processed by t...
uint32_t m_ifIndex
The interface index (really net evice index) that has been assigned to this network device.
uint32_t m_ceiling
Caps the exponential function when the number of retries reaches m_ceiling.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Start sending a packet down the channel.
Backoff m_backoff
Holds the backoff parameters and is used to calculate the next backoff time to use when the channel i...
uint32_t m_maxRetries
Maximum number of transmission retries before the packet is dropped.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
TxMachineState m_txMachineState
The state of the Net Device transmit state machine.
void SetReceiveEnable(bool enable)
Enable or disable the receive side of the network device.
Ipv4 addresses are stored in host order in this class.
virtual bool SetMtu(const uint16_t mtu)
Describes an IPv6 address.
virtual void SetNode(Ptr< Node > node)
Set the node to which this device is being attached.
virtual bool IsLinkUp(void) const
@ PACKET_HOST
Packet addressed oo us.
Hold objects of type Ptr<T>.
virtual uint32_t GetIfIndex(void) const
uint32_t m_deviceId
Device ID returned by the attached functions.
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
AttributeValue implementation for Mac48Address.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
virtual Ptr< Channel > GetChannel(void) const
bool IsSendEnabled(void)
Is the send side of the network device enabled?
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold variables of type enum.
void NotifyLinkUp(void)
Notify any interested parties that the link has come up.
bool Attach(Ptr< CsmaChannel > ch)
Attach the device to a channel.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Ptr< ErrorModel > m_receiveErrorModel
Error model for receive packet events.
virtual bool IsPointToPoint(void) const
Is this a point to point link?
CsmaNetDevice::EncapsulationMode GetEncapsulationMode(void)
Get the encapsulation mode of this device.
@ BUSY
The transmitter is busy transmitting a packet.
Ptr< const AttributeChecker > MakeMac48AddressChecker(void)
bool MaxRetriesReached(void)
TracedCallback< Ptr< const Packet > > m_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
uint32_t RemoveTrailer(Trailer &trailer)
Remove a deserialized trailer from the internal buffer.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the CsmaNetDevice.
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...
@ PACKET_OTHERHOST
Packet addressed to someone else.
virtual void SetIfIndex(const uint32_t index)
@ IDLE
Channel is IDLE, no packet is being transmitted.
uint32_t m_minSlots
Minimum number of backoff slots (when multiplied by m_slotTime, determines minimum backoff time)
void ResetBackoffTime(void)
Indicates to the backoff object that the last packet was successfully transmitted and that the number...
a polymophic address class
void SetSendEnable(bool enable)
Enable or disable the send side of the network device.
static Mac48Address ConvertFrom(const Address &address)
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
virtual bool IsBridge(void) const
Is this a bridge?
bool IsBroadcast(void) const
NetDevice::PromiscReceiveCallback m_promiscRxCallback
The callback used to notify higher layers that a packet has been received in promiscuous mode.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
void SetQueue(Ptr< Queue< Packet > > queue)
Attach a queue to the CsmaNetDevice.
void SetEncapsulationMode(CsmaNetDevice::EncapsulationMode mode)
Set the encapsulation mode of this device.
static bool ChecksumEnabled(void)
Ptr< const AttributeChecker > MakeBooleanChecker(void)
virtual Address GetBroadcast(void) const
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
Start sending a packet down the channel, with MAC spoofing.
Ptr< Node > m_node
The Node to which this device is attached.
Time m_slotTime
Length of one slot.
Simulation virtual time values and global simulation resolution.
@ READY
The transmitter is ready to begin transmission of a packet.
@ ILLEGAL
Encapsulation mode not set.
uint32_t m_mtu
The Maximum Transmission Unit.
#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 SetBackoffParams(Time slotTime, uint32_t minSlots, uint32_t maxSlots, uint32_t maxRetries, uint32_t ceiling)
Set the backoff parameters used to determine the wait to retry transmitting a packet when the channel...
virtual void SetAddress(Address address)
Set the address of this interface.
bool CheckFcs(Ptr< const Packet > p) const
Calculate an FCS on the provided packet and check this value against the FCS found when the trailer w...
TracedCallback< Ptr< const Packet > > m_macTxBackoffTrace
The trace source fired when the mac layer is forced to begin the backoff process for a packet.
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
virtual Ptr< Node > GetNode(void) const
Get the node to which this device is attached.
virtual bool NeedsArp(void) const
Does this device need to use the address resolution protocol?
#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.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
virtual void DoDispose(void)
Perform any object release functionality required to break reference cycles in reference counted obje...
void AddHeader(Ptr< Packet > p, Mac48Address source, Mac48Address dest, uint16_t protocolNumber)
Adds the necessary headers and trailers to a packet of data in order to respect the packet type.
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
The trace source fired when a packet ends the transmission process on the medium.
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
@ TRANSMITTING
Channel is BUSY, a packet is being written by a net device.
@ LLC
802.2 LLC/SNAP Packet
CsmaNetDevice()
Construct a CsmaNetDevice.
void Receive(Ptr< Packet > p, Ptr< CsmaNetDevice > sender)
Receive a packet from a connected CsmaChannel.
Ptr< Queue< Packet > > GetQueue(void) const
Get a copy of the attached Queue.
void TransmitCompleteEvent(void)
Stop Sending a Packet Down the Wire and Begin the Interframe Gap.
virtual void AddLinkChangeCallback(Callback< void > callback)
Ptr< Packet > m_currentPkt
Next packet that will be transmitted (if transmitter is not currently transmitting) or packet that is...
Time Seconds(double value)
Construct a Time in the indicated unit.
bool m_receiveEnable
Enable net device to receive packets.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
void IncrNumRetries(void)
Increments the number of retries by 1.
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
virtual Address GetAddress(void) const
void AddTrailer(const Trailer &trailer)
Add trailer to this packet.
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium.
void CalcFcs(Ptr< const Packet > p)
Updates the Fcs Field to the correct FCS.
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired for packets successfully received by the device but dropped before being forwa...
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
@ DIX
DIX II / Ethernet II packet.
virtual bool IsBroadcast(void) const
A Device for a Csma Network Link.
void SetInterframeGap(Time t)
Set the interframe gap used to separate packets.
PacketType
Packet types are used as they are in Linux.
Hold an unsigned integer type.
void TransmitReadyEvent(void)
Cause the Transmitter to Become Ready to Send Another Packet.
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
void RemoveAtEnd(uint32_t size)
Remove size bytes from the end of the current packet.
uint32_t m_maxSlots
Maximum number of backoff slots (when multiplied by m_slotTime, determines maximum backoff time)
NetDevice::ReceiveCallback m_rxCallback
The callback used to notify higher layers that a packet has been received.
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
@ GAP
The transmitter is in the interframe gap time.
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
The trace source fired when a packet ends the reception process from the medium.
TracedCallback m_linkChangeCallbacks
List of callbacks to fire if the link changes state (up or down).
void TransmitAbort(void)
Aborts the transmission of the current packet.
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
Set the callback to be used to notify higher layers when a packet has been received.
virtual uint16_t GetMtu(void) const
static TypeId GetTypeId(void)
Get the type ID.
virtual void DoDispose(void)
Destructor implementation.
Time m_tInterframeGap
The interframe gap that the Net Device uses insert time between packet transmission.
static const uint16_t DEFAULT_MTU
Default Maximum Transmission Unit (MTU) for the CsmaNetDevice.
Packet trailer for Ethernet.
virtual bool IsMulticast(void) const
bool IsReceiveEnabled(void)
Is the receive side of the network device enabled?
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device.
bool m_linkUp
Flag indicating whether or not the link is up.
uint64_t GetUid(void) const
Returns the packet's Uid.
Network layer to device interface.
@ PACKET_MULTICAST
Packet addressed to multicast group.