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" 35 #include "ns3/net-device-queue-interface.h" 48 .SetGroupName (
"Csma")
50 .AddAttribute (
"Address",
51 "The MAC address of this device.",
55 .AddAttribute (
"Mtu",
"The MAC-level Maximum Transmission Unit",
59 MakeUintegerChecker<uint16_t> ())
60 .AddAttribute (
"EncapsulationMode",
61 "The link-layer encapsulation type to use.",
66 .AddAttribute (
"SendEnable",
67 "Enable or disable the transmitter section of the device.",
71 .AddAttribute (
"ReceiveEnable",
72 "Enable or disable the receiver section of the device.",
76 .AddAttribute (
"ReceiveErrorModel",
77 "The receiver error model used to simulate packet loss",
80 MakePointerChecker<ErrorModel> ())
86 .AddAttribute (
"TxQueue",
87 "A queue to use as the transmit queue in the device.",
96 .AddTraceSource (
"MacTx",
97 "Trace source indicating a packet has " 98 "arrived for transmission by this device",
100 "ns3::Packet::TracedCallback")
101 .AddTraceSource (
"MacTxDrop",
102 "Trace source indicating a packet has been " 103 "dropped by the device before transmission",
105 "ns3::Packet::TracedCallback")
106 .AddTraceSource (
"MacPromiscRx",
107 "A packet has been received by this device, " 108 "has been passed up from the physical layer " 109 "and is being forwarded up the local protocol stack. " 110 "This is a promiscuous trace,",
112 "ns3::Packet::TracedCallback")
113 .AddTraceSource (
"MacRx",
114 "A packet has been received by this device, " 115 "has been passed up from the physical layer " 116 "and is being forwarded up the local protocol stack. " 117 "This is a non-promiscuous trace,",
119 "ns3::Packet::TracedCallback")
122 .AddTraceSource (
"MacRxDrop",
123 "Trace source indicating a packet was received, " 124 "but dropped before being forwarded up the stack",
126 "ns3::Packet::TracedCallback")
128 .AddTraceSource (
"MacTxBackoff",
129 "Trace source indicating a packet has been " 130 "delayed by the CSMA backoff process",
132 "ns3::Packet::TracedCallback")
137 .AddTraceSource (
"PhyTxBegin",
138 "Trace source indicating a packet has " 139 "begun transmitting over the channel",
141 "ns3::Packet::TracedCallback")
142 .AddTraceSource (
"PhyTxEnd",
143 "Trace source indicating a packet has been " 144 "completely transmitted over the channel",
146 "ns3::Packet::TracedCallback")
147 .AddTraceSource (
"PhyTxDrop",
148 "Trace source indicating a packet has been " 149 "dropped by the device during transmission",
151 "ns3::Packet::TracedCallback")
154 .AddTraceSource (
"PhyRxBegin",
155 "Trace source indicating a packet has " 156 "begun being received by the device",
158 "ns3::Packet::TracedCallback")
160 .AddTraceSource (
"PhyRxEnd",
161 "Trace source indicating a packet has been " 162 "completely received by the device",
164 "ns3::Packet::TracedCallback")
165 .AddTraceSource (
"PhyRxDrop",
166 "Trace source indicating a packet has been " 167 "dropped by the device during reception",
169 "ns3::Packet::TracedCallback")
173 .AddTraceSource (
"Sniffer",
174 "Trace source simulating a non-promiscuous " 175 "packet sniffer attached to the device",
177 "ns3::Packet::TracedCallback")
178 .AddTraceSource (
"PromiscSniffer",
179 "Trace source simulating a promiscuous " 180 "packet sniffer attached to the device",
182 "ns3::Packet::TracedCallback")
336 NS_LOG_FUNCTION (slotTime << minSlots << maxSlots << ceiling << maxRetries);
359 uint16_t lengthType = 0;
363 NS_LOG_LOGIC (
"Encapsulating packet as DIX (type interpretation)");
368 lengthType = protocolNumber;
379 memset (buffer, 0, 46);
386 NS_LOG_LOGIC (
"Encapsulating packet as LLC (length interpretation)");
408 memset (buffer, 0, 46);
414 "CsmaNetDevice::AddHeader(): 802.3 Length/Type field with LLC/SNAP: " 415 "length interpretation must not exceed device frame size minus overhead");
420 NS_FATAL_ERROR (
"CsmaNetDevice::AddHeader(): Unknown packet encapsulation mode");
424 NS_LOG_LOGIC (
"header.SetLengthType (" << lengthType <<
")");
438 CsmaNetDevice::ProcessHeader (
Ptr<Packet> p, uint16_t & param)
457 param = header.GetLengthType ();
463 param = llc.GetType ();
468 NS_FATAL_ERROR (
"CsmaNetDevice::ProcessHeader(): Unknown packet encapsulation mode");
547 NS_LOG_WARN (
"Channel TransmitStart returns an error");
605 NS_ASSERT_MSG (packet != 0,
"CsmaNetDevice::TransmitAbort(): IsEmpty false but no Packet on queue?");
674 NS_ASSERT_MSG (packet != 0,
"CsmaNetDevice::TransmitReadyEvent(): IsEmpty false but no Packet on queue?");
732 if (senderDevice ==
this)
772 bool crcGood = trailer.
CheckFcs (packet);
1002 AddHeader (packet, source, destination, protocolNumber);
1010 if (
m_queue->Enqueue (packet) ==
false)
1023 if (
m_queue->IsEmpty () ==
false)
1026 NS_ASSERT_MSG (packet != 0,
"CsmaNetDevice::SendFrom(): IsEmpty false but no Packet on queue?");
uint32_t m_ifIndex
The interface index (really net evice index) that has been assigned to this network device...
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium.
virtual void DoInitialize(void)
Initialize() implementation.
bool IsBroadcast(void) const
uint64_t GetUid(void) const
Returns the packet's Uid.
Simulation virtual time values and global simulation resolution.
void ResetBackoffTime(void)
Indicates to the backoff object that the last packet was successfully transmitted and that the number...
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
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.
virtual bool IsBroadcast(void) const
AttributeValue implementation for Boolean.
Packet addressed to someone else.
void SetEncapsulationMode(CsmaNetDevice::EncapsulationMode mode)
Set the encapsulation mode of this device.
virtual bool IsPointToPoint(void) const
Is this a point to point link?
virtual uint16_t GetMtu(void) const
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
CsmaNetDevice::EncapsulationMode GetEncapsulationMode(void)
Get the encapsulation mode of this device.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
void TransmitReadyEvent(void)
Cause the Transmitter to Become Ready to Send Another Packet.
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_macPromiscRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
Ptr< AttributeChecker > MakePointerChecker(void)
Create a PointerChecker for a type.
uint32_t m_maxSlots
Maximum number of backoff slots (when multiplied by m_slotTime, determines maximum backoff time) ...
CsmaNetDevice()
Construct a CsmaNetDevice.
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Ptr< const AttributeAccessor > MakeBooleanAccessor(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. ...
void CalcFcs(Ptr< const Packet > p)
Updates the Fcs Field to the correct FCS.
void Receive(Ptr< Packet > p, Ptr< CsmaNetDevice > sender)
Receive a packet from a connected CsmaChannel.
static bool ChecksumEnabled(void)
TracedCallback< Ptr< const Packet > > m_macRxTrace
The trace source fired for packets successfully received by the device immediately before being forwa...
virtual bool IsBridge(void) const
Is this a bridge?
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
The trace source fired when a packet ends the reception process from the medium.
Ptr< Packet > m_currentPkt
Next packet that will be transmitted (if transmitter is not currently transmitting) or packet that is...
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
void SetReceiveErrorModel(Ptr< ErrorModel > em)
Attach a receive ErrorModel to the CsmaNetDevice.
The transmitter is busy transmitting a packet.
Channel is IDLE, no packet is being transmitted.
void TransmitAbort(void)
Aborts the transmission of the current packet.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
uint32_t m_maxRetries
Maximum number of transmission retries before the packet is dropped.
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.
TracedCallback< Ptr< const Packet > > m_macRxDropTrace
The trace source fired for packets successfully received by the device but dropped before being forwa...
virtual Address GetBroadcast(void) const
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Ptr< const AttributeChecker > MakeMac48AddressChecker(void)
virtual void DoDispose(void)
Destructor implementation.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Ptr< const AttributeAccessor > MakeMac48AddressAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
virtual void SetIfIndex(const uint32_t index)
EncapsulationMode
Enumeration of the types of packets supported in the class.
virtual ~CsmaNetDevice()
Destroy a CsmaNetDevice.
TracedCallback< Ptr< const Packet > > m_promiscSnifferTrace
A trace source that emulates a promiscuous mode protocol sniffer connected to the device...
a polymophic address class
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
bool MaxRetriesReached(void)
Channel is BUSY, a packet is being written by a net device.
TracedCallback m_linkChangeCallbacks
List of callbacks to fire if the link changes state (up or down).
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
The transmitter is waiting for the channel to be free.
TracedCallback< Ptr< const Packet > > m_macTxBackoffTrace
The trace source fired when the mac layer is forced to begin the backoff process for a packet...
DataRate m_bps
The data rate that the Net Device uses to simulate packet transmission timing.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
TracedCallback< Ptr< const Packet > > m_snifferTrace
A trace source that emulates a non-promiscuous protocol sniffer connected to the device.
Hold variables of type enum.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Ptr< Queue< Packet > > GetQueue(void) const
Get a copy of the attached Queue.
static TypeId GetTypeId(void)
Get the type ID.
static Mac48Address GetMulticast(Ipv4Address address)
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
void TransmitCompleteEvent(void)
Stop Sending a Packet Down the Wire and Begin the Interframe Gap.
virtual bool IsMulticast(void) const
Hold an unsigned integer type.
bool IsReceiveEnabled(void)
Is the receive side of the network device enabled?
uint32_t m_deviceId
Device ID returned by the attached functions.
virtual bool SupportsSendFrom(void) const
virtual bool NeedsArp(void) const
Does this device need to use the address resolution protocol?
virtual Ptr< Node > GetNode(void) const
Get the node to which this device is attached.
bool m_sendEnable
Enable net device to send packets.
void NotifyLinkUp(void)
Notify any interested parties that the link has come up.
virtual Address GetAddress(void) const
void SetInterframeGap(Time t)
Set the interframe gap used to separate packets.
static Mac48Address ConvertFrom(const Address &address)
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
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.
Packet trailer for Ethernet.
Hold objects of type Ptr<T>.
void EnableFcs(bool enable)
Enable or disable FCS checking and calculations.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
bool m_receiveEnable
Enable net device to receive packets.
Ptr< ErrorModel > m_receiveErrorModel
Error model for receive packet events.
Ptr< NetDeviceQueueInterface > m_queueInterface
NetDevice queue interface.
void AddTrailer(const Trailer &trailer)
Add trailer to this packet.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Ptr< CsmaChannel > m_channel
The CsmaChannel to which this CsmaNetDevice has been attached.
void RemoveAtEnd(uint32_t size)
Remove size bytes from the end of the current packet.
Ptr< Queue< Packet > > m_queue
The Queue which this CsmaNetDevice uses as a packet source.
static const uint16_t DEFAULT_MTU
Default Maximum Transmission Unit (MTU) for the CsmaNetDevice.
uint32_t RemoveTrailer(Trailer &trailer)
Remove a deserialized trailer from the internal buffer.
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
Time m_tInterframeGap
The interframe gap that the Net Device uses insert time between packet transmission.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
virtual bool SetMtu(const uint16_t mtu)
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
Encapsulation mode not set.
bool m_linkUp
Flag indicating whether or not the link is up.
Mac48Address m_address
The MAC address which has been assigned to this device.
Ptr< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
Make an EnumChecker pre-configured with a set of allowed values by name.
Describes an IPv6 address.
Ipv4 addresses are stored in host order in this class.
EncapsulationMode m_encapMode
The type of packet that should be created by the AddHeader function and that should be processed by t...
NetDevice::ReceiveCallback m_rxCallback
The callback used to notify higher layers that a packet has been received.
uint32_t m_mtu
The Maximum Transmission Unit.
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...
void ConnectWithoutContext(const CallbackBase &callback)
Append a Callback to the chain (without a context).
Backoff m_backoff
Holds the backoff parameters and is used to calculate the next backoff time to use when the channel i...
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...
Network layer to device interface.
The transmitter is ready to begin transmission of a packet.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
AttributeValue implementation for Mac48Address.
void SetSendEnable(bool enable)
Enable or disable the send side of the network device.
Time Seconds(double value)
Construct a Time in the indicated unit.
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
Set the callback to be used to notify higher layers when a packet has been received.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
uint32_t m_minSlots
Minimum number of backoff slots (when multiplied by m_slotTime, determines minimum backoff time) ...
NetDevice::PromiscReceiveCallback m_promiscRxCallback
The callback used to notify higher layers that a packet has been received in promiscuous mode...
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...
virtual void DoInitialize(void)
Initialize() implementation.
virtual void SetAddress(Address address)
Set the address of this interface.
void SetQueue(Ptr< Queue< Packet > > queue)
Attach a queue to the CsmaNetDevice.
bool IsSendEnabled(void)
Is the send side of the network device enabled?
virtual Ptr< Channel > GetChannel(void) const
void TransmitStart()
Start Sending a Packet Down the Wire.
Ptr< Node > m_node
The Node to which this device is attached.
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
PacketType
Packet types are used as they are in Linux.
virtual void AddLinkChangeCallback(Callback< void > callback)
bool Attach(Ptr< CsmaChannel > ch)
Attach the device to a channel.
virtual void SetNode(Ptr< Node > node)
Set the node to which this device is being attached.
virtual bool IsLinkUp(void) const
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
bool IsNull(void) const
Check for null implementation.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Start sending a packet down the channel.
Packet addressed to multicast group.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
virtual void DoDispose(void)
Perform any object release functionality required to break reference cycles in reference counted obje...
a unique identifier for an interface.
Time CalculateBytesTxTime(uint32_t bytes) const
Calculate transmission time.
Time m_slotTime
Length of one slot.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
void AddHeader(const Header &header)
Add header to this packet.
DIX II / Ethernet II packet.
The transmitter is in the interframe gap time.
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 IncrNumRetries(void)
Increments the number of retries by 1.
virtual uint32_t GetIfIndex(void) const
uint32_t m_ceiling
Caps the exponential function when the number of retries reaches m_ceiling.